2
0

api.c 3.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222
  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. /* Test result constants and macros. */
  472. /* Test succeeded. */
  473. #define TEST_SUCCESS (1)
  474. /* Test failed. */
  475. #define TEST_FAIL (0)
  476. /* Test skipped - not run. */
  477. #define TEST_SKIPPED (-7777)
  478. /* Returns the result based on whether check is true.
  479. *
  480. * @param [in] check Condition for success.
  481. * @return When condition is true: TEST_SUCCESS.
  482. * @return When condition is false: TEST_FAIL.
  483. */
  484. #ifdef DEBUG_WOLFSSL_VERBOSE
  485. #define XSTRINGIFY(s) STRINGIFY(s)
  486. #define STRINGIFY(s) #s
  487. #define TEST_RES_CHECK(check) ({ \
  488. int _ret = (check) ? TEST_SUCCESS : TEST_FAIL; \
  489. if (_ret == TEST_FAIL) { \
  490. fprintf(stderr, " check \"%s\" at %d ", \
  491. XSTRINGIFY(check), __LINE__); \
  492. } \
  493. _ret; })
  494. #else
  495. #define TEST_RES_CHECK(check) \
  496. ((check) ? TEST_SUCCESS : TEST_FAIL)
  497. #endif /* DEBUG_WOLFSSL_VERBOSE */
  498. #define TEST_STRING "Everyone gets Friday off."
  499. #define TEST_STRING_SZ 25
  500. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  501. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  502. #define TEST_RSA_BITS 1024
  503. #else
  504. #define TEST_RSA_BITS 2048
  505. #endif
  506. #define TEST_RSA_BYTES (TEST_RSA_BITS/8)
  507. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  508. (!defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT))
  509. static const char* bogusFile =
  510. #ifdef _WIN32
  511. "NUL"
  512. #else
  513. "/dev/null"
  514. #endif
  515. ;
  516. #endif /* !NO_FILESYSTEM && !NO_CERTS && (!NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT) */
  517. enum {
  518. TESTING_RSA = 1,
  519. TESTING_ECC = 2
  520. };
  521. #ifdef WOLFSSL_QNX_CAAM
  522. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  523. static int testDevId = WOLFSSL_CAAM_DEVID;
  524. #else
  525. static int testDevId = INVALID_DEVID;
  526. #endif
  527. /*----------------------------------------------------------------------------*
  528. | BIO with fixed read/write size
  529. *----------------------------------------------------------------------------*/
  530. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  531. static int wolfssl_bio_s_fixed_mem_write(WOLFSSL_BIO* bio, const char* data,
  532. int len)
  533. {
  534. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  535. len = 0;
  536. }
  537. else {
  538. if (bio->wrSz - bio->wrIdx < len) {
  539. len = bio->wrSz - bio->wrIdx;
  540. }
  541. XMEMCPY(bio->ptr.mem_buf_data + bio->wrIdx, data, len);
  542. bio->wrIdx += len;
  543. }
  544. return len;
  545. }
  546. static int wolfssl_bio_s_fixed_mem_read(WOLFSSL_BIO* bio, char* data, int len)
  547. {
  548. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  549. len = 0;
  550. }
  551. else {
  552. if (bio->wrSz - bio->rdIdx < len) {
  553. len = bio->wrSz - bio->rdIdx;
  554. }
  555. XMEMCPY(data, bio->ptr.mem_buf_data + bio->rdIdx, len);
  556. bio->rdIdx += len;
  557. }
  558. return len;
  559. }
  560. static WOLFSSL_BIO_METHOD* wolfSSL_BIO_s_fixed_mem(void)
  561. {
  562. static WOLFSSL_BIO_METHOD meth;
  563. meth.type = WOLFSSL_BIO_BIO;
  564. XMEMCPY(meth.name, "Fixed Memory Size", 18);
  565. meth.writeCb = wolfssl_bio_s_fixed_mem_write;
  566. meth.readCb = wolfssl_bio_s_fixed_mem_read;
  567. return &meth;
  568. }
  569. #endif
  570. /*----------------------------------------------------------------------------*
  571. | Setup
  572. *----------------------------------------------------------------------------*/
  573. static int test_wolfSSL_Init(void)
  574. {
  575. EXPECT_DECLS;
  576. ExpectIntEQ(wolfSSL_Init(), WOLFSSL_SUCCESS);
  577. return EXPECT_RESULT();
  578. }
  579. static int test_wolfSSL_Cleanup(void)
  580. {
  581. EXPECT_DECLS;
  582. ExpectIntEQ(wolfSSL_Cleanup(), WOLFSSL_SUCCESS);
  583. return EXPECT_RESULT();
  584. }
  585. /* Initialize the wolfCrypt state.
  586. * POST: 0 success.
  587. */
  588. static int test_wolfCrypt_Init(void)
  589. {
  590. EXPECT_DECLS;
  591. ExpectIntEQ(wolfCrypt_Init(), 0);
  592. return EXPECT_RESULT();
  593. } /* END test_wolfCrypt_Init */
  594. static int test_wolfCrypt_Cleanup(void)
  595. {
  596. EXPECT_DECLS;
  597. ExpectIntEQ(wolfCrypt_Cleanup(), 0);
  598. return EXPECT_RESULT();
  599. }
  600. #ifdef WOLFSSL_STATIC_MEMORY
  601. #define TEST_LSM_STATIC_SIZE 440000
  602. /* Create new bucket list, using the default list, adding
  603. * one dang large buffer size. */
  604. #define TEST_LSM_DEF_BUCKETS (WOLFMEM_DEF_BUCKETS+1)
  605. #define TEST_LSM_BUCKETS WOLFMEM_BUCKETS,(LARGEST_MEM_BUCKET*2)
  606. #define TEST_LSM_DIST WOLFMEM_DIST,1
  607. #endif
  608. static int test_wc_LoadStaticMemory_ex(void)
  609. {
  610. EXPECT_DECLS;
  611. #ifdef WOLFSSL_STATIC_MEMORY
  612. byte staticMemory[TEST_LSM_STATIC_SIZE];
  613. word32 sizeList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_BUCKETS };
  614. word32 distList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_DIST };
  615. WOLFSSL_HEAP_HINT* heap;
  616. /* For this test, the size and dist lists will be the ones configured
  617. * for the build, or default. The value of WOLFMEM_DEF_BUCKETS is 9,
  618. * so these lists are 10 long. For most tests, the value of
  619. * WOLFMEM_DEF_BUCKETS is used. There's a test case where one is added
  620. * to that, to make sure the list size is larger than
  621. * WOLFMEM_MAX_BUCKETS. */
  622. /* Pass in zero everything. */
  623. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL, 0, NULL, NULL, NULL, 0, 0, 0),
  624. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  625. /* Set the heap pointer to NULL. */
  626. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL,
  627. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  628. staticMemory, (word32)sizeof(staticMemory),
  629. 0, 1),
  630. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  631. /* Set other pointer values to NULL one at a time. */
  632. heap = NULL;
  633. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  634. WOLFMEM_DEF_BUCKETS, NULL, distList,
  635. staticMemory, (word32)sizeof(staticMemory),
  636. 0, 1),
  637. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  638. heap = NULL;
  639. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  640. WOLFMEM_DEF_BUCKETS, sizeList, NULL,
  641. staticMemory, (word32)sizeof(staticMemory),
  642. 0, 1),
  643. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  644. heap = NULL;
  645. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  646. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  647. NULL, (word32)sizeof(staticMemory),
  648. 0, 1),
  649. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  650. /* Set the size of the static buffer to 0. */
  651. heap = NULL;
  652. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  653. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  654. staticMemory, 0,
  655. 0, 1),
  656. WC_NO_ERR_TRACE(BUFFER_E));
  657. /* Set the size of the static buffer to one less than minimum allowed. */
  658. heap = NULL;
  659. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  660. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  661. staticMemory,
  662. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) - 1,
  663. 0, 1),
  664. WC_NO_ERR_TRACE(BUFFER_E));
  665. /* Set the size of the static buffer to exactly the minimum size. */
  666. heap = NULL;
  667. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  668. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  669. staticMemory,
  670. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
  671. 0, 1),
  672. 0);
  673. wc_UnloadStaticMemory(heap);
  674. /* Use more buckets than able. Success case. */
  675. heap = NULL;
  676. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  677. WOLFMEM_DEF_BUCKETS*2, sizeList, distList,
  678. staticMemory, (word32)sizeof(staticMemory),
  679. 0, 1),
  680. 0);
  681. wc_UnloadStaticMemory(heap);
  682. /* Success case. */
  683. heap = NULL;
  684. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  685. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  686. staticMemory, (word32)sizeof(staticMemory),
  687. 0, 1),
  688. 0);
  689. wc_UnloadStaticMemory(heap);
  690. #endif /* WOLFSSL_STATIC_MEMORY */
  691. return EXPECT_RESULT();
  692. }
  693. /*----------------------------------------------------------------------------*
  694. | Platform dependent function test
  695. *----------------------------------------------------------------------------*/
  696. static int test_fileAccess(void)
  697. {
  698. EXPECT_DECLS;
  699. #if defined(WOLFSSL_TEST_PLATFORMDEPEND) && !defined(NO_FILESYSTEM)
  700. const char *fname[] = {
  701. svrCertFile, svrKeyFile, caCertFile,
  702. eccCertFile, eccKeyFile, eccRsaCertFile,
  703. cliCertFile, cliCertDerFile, cliKeyFile,
  704. dhParamFile,
  705. cliEccKeyFile, cliEccCertFile, caEccCertFile, edCertFile, edKeyFile,
  706. cliEdCertFile, cliEdKeyFile, caEdCertFile,
  707. NULL
  708. };
  709. const char derfile[] = "./certs/server-cert.der";
  710. XFILE f = XBADFILE;
  711. size_t sz;
  712. byte *buff = NULL;
  713. int i;
  714. ExpectTrue(XFOPEN("badfilename", "rb") == XBADFILE);
  715. for (i=0; EXPECT_SUCCESS() && fname[i] != NULL ; i++) {
  716. ExpectTrue((f = XFOPEN(fname[i], "rb")) != XBADFILE);
  717. XFCLOSE(f);
  718. }
  719. ExpectTrue((f = XFOPEN(derfile, "rb")) != XBADFILE);
  720. ExpectTrue(XFSEEK(f, 0, XSEEK_END) == 0);
  721. ExpectIntGE(sz = (size_t) XFTELL(f), sizeof_server_cert_der_2048);
  722. ExpectTrue(XFSEEK(f, 0, XSEEK_SET) == 0);
  723. ExpectTrue((buff = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE)) != NULL);
  724. ExpectTrue(XFREAD(buff, 1, sz, f) == sz);
  725. ExpectIntEQ(XMEMCMP(server_cert_der_2048, buff, sz), 0);
  726. XFREE(buff, NULL, DYNAMIC_TYPE_FILE);
  727. XFCLOSE(f);
  728. #endif
  729. return EXPECT_RESULT();
  730. }
  731. /*----------------------------------------------------------------------------*
  732. | Method Allocators
  733. *----------------------------------------------------------------------------*/
  734. static int test_wolfSSL_Method_Allocators(void)
  735. {
  736. EXPECT_DECLS;
  737. #define TEST_METHOD_ALLOCATOR(allocator, condition) \
  738. do { \
  739. WOLFSSL_METHOD *method = NULL; \
  740. condition(method = allocator()); \
  741. XFREE(method, 0, DYNAMIC_TYPE_METHOD); \
  742. } while (0)
  743. #define TEST_VALID_METHOD_ALLOCATOR(a) \
  744. TEST_METHOD_ALLOCATOR(a, ExpectNotNull)
  745. #define TEST_INVALID_METHOD_ALLOCATOR(a) \
  746. TEST_METHOD_ALLOCATOR(a, ExpectNull)
  747. #ifndef NO_OLD_TLS
  748. #ifdef WOLFSSL_ALLOW_SSLV3
  749. #ifndef NO_WOLFSSL_SERVER
  750. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_server_method);
  751. #endif
  752. #ifndef NO_WOLFSSL_CLIENT
  753. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_client_method);
  754. #endif
  755. #endif
  756. #ifdef WOLFSSL_ALLOW_TLSV10
  757. #ifndef NO_WOLFSSL_SERVER
  758. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_server_method);
  759. #endif
  760. #ifndef NO_WOLFSSL_CLIENT
  761. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_client_method);
  762. #endif
  763. #endif
  764. #ifndef NO_WOLFSSL_SERVER
  765. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_server_method);
  766. #endif
  767. #ifndef NO_WOLFSSL_CLIENT
  768. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_client_method);
  769. #endif
  770. #endif /* !NO_OLD_TLS */
  771. #ifndef WOLFSSL_NO_TLS12
  772. #ifndef NO_WOLFSSL_SERVER
  773. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_server_method);
  774. #endif
  775. #ifndef NO_WOLFSSL_CLIENT
  776. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_client_method);
  777. #endif
  778. #endif /* !WOLFSSL_NO_TLS12 */
  779. #ifdef WOLFSSL_TLS13
  780. #ifndef NO_WOLFSSL_SERVER
  781. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_server_method);
  782. #endif
  783. #ifndef NO_WOLFSSL_CLIENT
  784. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_client_method);
  785. #endif
  786. #endif /* WOLFSSL_TLS13 */
  787. #ifndef NO_WOLFSSL_SERVER
  788. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_server_method);
  789. #endif
  790. #ifndef NO_WOLFSSL_CLIENT
  791. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_client_method);
  792. #endif
  793. #ifdef WOLFSSL_DTLS
  794. #ifndef NO_OLD_TLS
  795. #ifndef NO_WOLFSSL_SERVER
  796. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_server_method);
  797. #endif
  798. #ifndef NO_WOLFSSL_CLIENT
  799. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_client_method);
  800. #endif
  801. #endif
  802. #ifndef WOLFSSL_NO_TLS12
  803. #ifndef NO_WOLFSSL_SERVER
  804. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_server_method);
  805. #endif
  806. #ifndef NO_WOLFSSL_CLIENT
  807. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_client_method);
  808. #endif
  809. #endif
  810. #endif /* WOLFSSL_DTLS */
  811. #if !defined(NO_OLD_TLS) && defined(OPENSSL_EXTRA)
  812. /* Stubs */
  813. #ifndef NO_WOLFSSL_SERVER
  814. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_server_method);
  815. #endif
  816. #ifndef NO_WOLFSSL_CLIENT
  817. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_client_method);
  818. #endif
  819. #endif
  820. /* Test Either Method (client or server) */
  821. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  822. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_method);
  823. #ifndef NO_OLD_TLS
  824. #ifdef WOLFSSL_ALLOW_TLSV10
  825. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_method);
  826. #endif
  827. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_method);
  828. #endif /* !NO_OLD_TLS */
  829. #ifndef WOLFSSL_NO_TLS12
  830. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_method);
  831. #endif /* !WOLFSSL_NO_TLS12 */
  832. #ifdef WOLFSSL_TLS13
  833. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_method);
  834. #endif /* WOLFSSL_TLS13 */
  835. #ifdef WOLFSSL_DTLS
  836. TEST_VALID_METHOD_ALLOCATOR(wolfDTLS_method);
  837. #ifndef NO_OLD_TLS
  838. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_method);
  839. #endif /* !NO_OLD_TLS */
  840. #ifndef WOLFSSL_NO_TLS12
  841. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_method);
  842. #endif /* !WOLFSSL_NO_TLS12 */
  843. #endif /* WOLFSSL_DTLS */
  844. #endif /* OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE */
  845. return EXPECT_RESULT();
  846. }
  847. #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_FILESYSTEM)
  848. /*----------------------------------------------------------------------------*
  849. | Dual algorithm Certificate Tests
  850. *----------------------------------------------------------------------------*/
  851. #define LARGE_TEMP_SZ 4096
  852. /* To better understand this, please see the X9.146 example in wolfssl-examples
  853. * repo. */
  854. static int do_dual_alg_root_certgen(byte **out, char *caKeyFile,
  855. char *sapkiFile, char *altPrivFile)
  856. {
  857. EXPECT_DECLS;
  858. FILE* file = NULL;
  859. Cert newCert;
  860. DecodedCert preTBS;
  861. byte caKeyBuf[LARGE_TEMP_SZ];
  862. word32 caKeySz = LARGE_TEMP_SZ;
  863. byte sapkiBuf[LARGE_TEMP_SZ];
  864. word32 sapkiSz = LARGE_TEMP_SZ;
  865. byte altPrivBuf[LARGE_TEMP_SZ];
  866. word32 altPrivSz = LARGE_TEMP_SZ;
  867. byte altSigAlgBuf[LARGE_TEMP_SZ];
  868. word32 altSigAlgSz = LARGE_TEMP_SZ;
  869. byte scratchBuf[LARGE_TEMP_SZ];
  870. word32 scratchSz = LARGE_TEMP_SZ;
  871. byte preTbsBuf[LARGE_TEMP_SZ];
  872. word32 preTbsSz = LARGE_TEMP_SZ;
  873. byte altSigValBuf[LARGE_TEMP_SZ];
  874. word32 altSigValSz = LARGE_TEMP_SZ;
  875. byte *outBuf = NULL;
  876. word32 outSz = LARGE_TEMP_SZ;
  877. WC_RNG rng;
  878. RsaKey caKey;
  879. ecc_key altCaKey;
  880. word32 idx = 0;
  881. XMEMSET(&rng, 0, sizeof(WC_RNG));
  882. XMEMSET(&caKey, 0, sizeof(RsaKey));
  883. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  884. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  885. DYNAMIC_TYPE_TMP_BUFFER));
  886. ExpectIntEQ(wc_InitRng(&rng), 0);
  887. XMEMSET(caKeyBuf, 0, caKeySz);
  888. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  889. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  890. if (file) {
  891. fclose(file);
  892. file = NULL;
  893. }
  894. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  895. idx = 0;
  896. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey, caKeySz),
  897. 0);
  898. XMEMSET(sapkiBuf, 0, sapkiSz);
  899. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  900. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  901. if (file) {
  902. fclose(file);
  903. file = NULL;
  904. }
  905. XMEMSET(altPrivBuf, 0, altPrivSz);
  906. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  907. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  908. if (file) {
  909. fclose(file);
  910. file = NULL;
  911. }
  912. wc_ecc_init(&altCaKey);
  913. idx = 0;
  914. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  915. (word32)altPrivSz), 0);
  916. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  917. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  918. oidSigType, 0), 0);
  919. wc_InitCert(&newCert);
  920. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  921. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  922. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  923. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  924. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  925. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  926. strncpy(newCert.subject.email, "root@wolfssl.com", CTC_NAME_SIZE);
  927. newCert.sigType = CTC_SHA256wRSA;
  928. newCert.isCA = 1;
  929. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "1.2.3.4.5",
  930. (const byte *)"This is NOT a critical extension", 32), 0);
  931. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  932. sapkiSz), 0);
  933. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  934. altSigAlgSz), 0);
  935. XMEMSET(scratchBuf, 0, scratchSz);
  936. ExpectIntGT(scratchSz = wc_MakeSelfCert(&newCert, scratchBuf, scratchSz,
  937. &caKey, &rng), 0);
  938. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  939. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  940. XMEMSET(preTbsBuf, 0, preTbsSz);
  941. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  942. XMEMSET(altSigValBuf, 0, altSigValSz);
  943. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  944. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  945. &rng), 0);
  946. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74", altSigValBuf,
  947. altSigValSz), 0);
  948. /* Finally, generate the new certificate. */
  949. if (outBuf != NULL) {
  950. XMEMSET(outBuf, 0, outSz);
  951. }
  952. ExpectIntGT(outSz = wc_MakeSelfCert(&newCert, outBuf, outSz, &caKey, &rng),
  953. 0);
  954. *out = outBuf;
  955. wc_FreeRsaKey(&caKey);
  956. wc_FreeRng(&rng);
  957. wc_FreeDecodedCert(&preTBS);
  958. return outSz;
  959. }
  960. static int do_dual_alg_server_certgen(byte **out, char *caKeyFile,
  961. char *sapkiFile, char *altPrivFile,
  962. char *serverKeyFile,
  963. byte *caCertBuf, int caCertSz)
  964. {
  965. EXPECT_DECLS;
  966. FILE* file = NULL;
  967. Cert newCert;
  968. DecodedCert preTBS;
  969. byte serverKeyBuf[LARGE_TEMP_SZ];
  970. word32 serverKeySz = LARGE_TEMP_SZ;
  971. byte caKeyBuf[LARGE_TEMP_SZ];
  972. word32 caKeySz = LARGE_TEMP_SZ;
  973. byte sapkiBuf[LARGE_TEMP_SZ];
  974. word32 sapkiSz = LARGE_TEMP_SZ;
  975. byte altPrivBuf[LARGE_TEMP_SZ];
  976. word32 altPrivSz = LARGE_TEMP_SZ;
  977. byte altSigAlgBuf[LARGE_TEMP_SZ];
  978. word32 altSigAlgSz = LARGE_TEMP_SZ;
  979. byte scratchBuf[LARGE_TEMP_SZ];
  980. word32 scratchSz = LARGE_TEMP_SZ;
  981. byte preTbsBuf[LARGE_TEMP_SZ];
  982. word32 preTbsSz = LARGE_TEMP_SZ;
  983. byte altSigValBuf[LARGE_TEMP_SZ];
  984. word32 altSigValSz = LARGE_TEMP_SZ;
  985. byte *outBuf = NULL;
  986. word32 outSz = LARGE_TEMP_SZ;
  987. WC_RNG rng;
  988. RsaKey caKey;
  989. RsaKey serverKey;
  990. ecc_key altCaKey;
  991. word32 idx = 0;
  992. XMEMSET(&rng, 0, sizeof(WC_RNG));
  993. XMEMSET(&caKey, 0, sizeof(RsaKey));
  994. XMEMSET(&serverKey, 0, sizeof(RsaKey));
  995. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  996. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  997. DYNAMIC_TYPE_TMP_BUFFER));
  998. ExpectIntEQ(wc_InitRng(&rng), 0);
  999. XMEMSET(serverKeyBuf, 0, serverKeySz);
  1000. ExpectNotNull(file = fopen(serverKeyFile, "rb"));
  1001. ExpectIntGT(serverKeySz = (word32)fread(serverKeyBuf, 1, serverKeySz, file),
  1002. 0);
  1003. if (file) {
  1004. fclose(file);
  1005. file = NULL;
  1006. }
  1007. ExpectIntEQ(wc_InitRsaKey_ex(&serverKey, NULL, INVALID_DEVID), 0);
  1008. idx = 0;
  1009. ExpectIntEQ(wc_RsaPrivateKeyDecode(serverKeyBuf, &idx, &serverKey,
  1010. (word32)serverKeySz), 0);
  1011. XMEMSET(caKeyBuf, 0, caKeySz);
  1012. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1013. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1014. if (file) {
  1015. fclose(file);
  1016. file = NULL;
  1017. }
  1018. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1019. idx = 0;
  1020. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey,
  1021. (word32)caKeySz), 0);
  1022. XMEMSET(sapkiBuf, 0, sapkiSz);
  1023. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1024. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1025. if (file) {
  1026. fclose(file);
  1027. file = NULL;
  1028. }
  1029. XMEMSET(altPrivBuf, 0, altPrivSz);
  1030. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1031. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1032. if (file) {
  1033. fclose(file);
  1034. file = NULL;
  1035. }
  1036. wc_ecc_init(&altCaKey);
  1037. idx = 0;
  1038. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1039. (word32)altPrivSz), 0);
  1040. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1041. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1042. oidSigType, 0), 0);
  1043. wc_InitCert(&newCert);
  1044. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1045. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1046. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1047. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1048. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1049. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1050. strncpy(newCert.subject.email, "server@wolfssl.com", CTC_NAME_SIZE);
  1051. newCert.sigType = CTC_SHA256wRSA;
  1052. newCert.isCA = 0;
  1053. ExpectIntEQ(wc_SetIssuerBuffer(&newCert, caCertBuf, caCertSz), 0);
  1054. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1055. sapkiSz), 0);
  1056. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1057. altSigAlgSz), 0);
  1058. XMEMSET(scratchBuf, 0, scratchSz);
  1059. ExpectIntGT(wc_MakeCert(&newCert, scratchBuf, scratchSz, &serverKey, NULL,
  1060. &rng), 0);
  1061. ExpectIntGT(scratchSz = wc_SignCert(newCert.bodySz, newCert.sigType,
  1062. scratchBuf, scratchSz, &caKey, NULL, &rng), 0);
  1063. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1064. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1065. XMEMSET(preTbsBuf, 0, preTbsSz);
  1066. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1067. XMEMSET(altSigValBuf, 0, altSigValSz);
  1068. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1069. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1070. &rng), 0);
  1071. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74",
  1072. altSigValBuf, altSigValSz), 0);
  1073. /* Finally, generate the new certificate. */
  1074. if (outBuf != NULL) {
  1075. XMEMSET(outBuf, 0, outSz);
  1076. }
  1077. ExpectIntGT(wc_MakeCert(&newCert, outBuf, outSz, &serverKey, NULL, &rng),
  1078. 0);
  1079. ExpectIntGT(outSz = wc_SignCert(newCert.bodySz, newCert.sigType, outBuf,
  1080. outSz, &caKey, NULL, &rng), 0);
  1081. *out = outBuf;
  1082. wc_FreeRsaKey(&caKey);
  1083. wc_FreeRsaKey(&serverKey);
  1084. wc_FreeRng(&rng);
  1085. wc_FreeDecodedCert(&preTBS);
  1086. return outSz;
  1087. }
  1088. static int do_dual_alg_tls13_connection(byte *caCert, word32 caCertSz,
  1089. byte *serverCert, word32 serverCertSz,
  1090. byte *serverKey, word32 serverKeySz,
  1091. int negative_test)
  1092. {
  1093. EXPECT_DECLS;
  1094. WOLFSSL_CTX *ctx_c = NULL;
  1095. WOLFSSL_CTX *ctx_s = NULL;
  1096. WOLFSSL *ssl_c = NULL;
  1097. WOLFSSL *ssl_s = NULL;
  1098. struct test_memio_ctx test_ctx;
  1099. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  1100. ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  1101. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  1102. caCert, caCertSz, serverCert, serverCertSz,
  1103. serverKey, serverKeySz), 0);
  1104. if (negative_test) {
  1105. ExpectTrue(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0);
  1106. }
  1107. else {
  1108. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  1109. }
  1110. wolfSSL_free(ssl_c);
  1111. wolfSSL_free(ssl_s);
  1112. wolfSSL_CTX_free(ctx_c);
  1113. wolfSSL_CTX_free(ctx_s);
  1114. return EXPECT_RESULT();
  1115. }
  1116. static int test_dual_alg_support(void)
  1117. {
  1118. EXPECT_DECLS;
  1119. /* Root CA and server keys will be the same. This is only appropriate for
  1120. * testing. */
  1121. char keyFile[] = "./certs/ca-key.der";
  1122. char sapkiFile[] = "./certs/ecc-keyPub.der";
  1123. char altPrivFile[] = "./certs/ecc-key.der";
  1124. char wrongPrivFile[] = "./certs/ecc-client-key.der";
  1125. byte *serverKey = NULL;
  1126. size_t serverKeySz = 0;
  1127. byte *root = NULL;
  1128. int rootSz = 0;
  1129. byte *server = NULL;
  1130. int serverSz = 0;
  1131. ExpectIntEQ(load_file(keyFile, &serverKey, &serverKeySz), 0);
  1132. /* Base normal case. */
  1133. if (EXPECT_SUCCESS()) {
  1134. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1135. altPrivFile);
  1136. }
  1137. ExpectNotNull(root);
  1138. ExpectIntGT(rootSz, 0);
  1139. if (EXPECT_SUCCESS()) {
  1140. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1141. altPrivFile, keyFile, root, rootSz);
  1142. }
  1143. ExpectNotNull(server);
  1144. ExpectIntGT(serverSz, 0);
  1145. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1146. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1147. TEST_SUCCESS);
  1148. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1149. root = NULL;
  1150. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1151. server = NULL;
  1152. /* Now we try a negative case. Note that we use wrongPrivFile to generate
  1153. * the alternative signature and then set negative_test to true for the
  1154. * call to do_dual_alg_tls13_connection(). Its expecting a failed connection
  1155. * because the signature won't verify. The exception is if
  1156. * WOLFSSL_TRUST_PEER_CERT is defined. In that case, no verification happens
  1157. * and this is no longer a negative test. */
  1158. if (EXPECT_SUCCESS()) {
  1159. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1160. wrongPrivFile);
  1161. }
  1162. ExpectNotNull(root);
  1163. ExpectIntGT(rootSz, 0);
  1164. if (EXPECT_SUCCESS()) {
  1165. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1166. wrongPrivFile, keyFile, root, rootSz);
  1167. }
  1168. ExpectNotNull(server);
  1169. ExpectIntGT(serverSz, 0);
  1170. #ifdef WOLFSSL_TRUST_PEER_CERT
  1171. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1172. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1173. TEST_SUCCESS);
  1174. #else
  1175. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1176. server, serverSz, serverKey, (word32)serverKeySz, 1),
  1177. TEST_SUCCESS);
  1178. #endif
  1179. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1180. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1181. free(serverKey);
  1182. return EXPECT_RESULT();
  1183. }
  1184. #else
  1185. static int test_dual_alg_support(void)
  1186. {
  1187. return TEST_SKIPPED;
  1188. }
  1189. #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_FILESYSTEM */
  1190. /*----------------------------------------------------------------------------*
  1191. | Context
  1192. *----------------------------------------------------------------------------*/
  1193. #ifndef NO_WOLFSSL_SERVER
  1194. static int test_wolfSSL_CTX_new(void)
  1195. {
  1196. EXPECT_DECLS;
  1197. WOLFSSL_CTX *ctx;
  1198. WOLFSSL_METHOD* method;
  1199. ExpectNull(ctx = wolfSSL_CTX_new(NULL));
  1200. ExpectNotNull(method = wolfSSLv23_server_method());
  1201. ExpectNotNull(ctx = wolfSSL_CTX_new(method));
  1202. wolfSSL_CTX_free(ctx);
  1203. return EXPECT_RESULT();
  1204. }
  1205. #endif
  1206. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1207. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1208. static int test_for_double_Free(void)
  1209. {
  1210. EXPECT_DECLS;
  1211. WOLFSSL_CTX* ctx = NULL;
  1212. WOLFSSL* ssl = NULL;
  1213. int skipTest = 0;
  1214. const char* testCertFile;
  1215. const char* testKeyFile;
  1216. char optionsCiphers[] = "RC4-SHA:RC4-MD5:DES-CBC3-SHA:AES128-SHA:AES256-SHA"
  1217. ":NULL-SHA:NULL-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-PSK-AES256-GCM"
  1218. "-SHA384:DHE-PSK-AES128-GCM-SHA256:PSK-AES256-GCM-SHA384:PSK-AES128-GCM-SHA256:"
  1219. "DHE-PSK-AES256-CBC-SHA384:DHE-PSK-AES128-CBC-SHA256:PSK-AES256-CBC-SHA384:PSK-"
  1220. "AES128-CBC-SHA256:PSK-AES128-CBC-SHA:PSK-AES256-CBC-SHA:DHE-PSK-AES128-CCM:DHE"
  1221. "-PSK-AES256-CCM:PSK-AES128-CCM:PSK-AES256-CCM:PSK-AES128-CCM-8:PSK-AES256-CCM-"
  1222. "8:DHE-PSK-NULL-SHA384:DHE-PSK-NULL-SHA256:PSK-NULL-SHA384:PSK-NULL-SHA256:PSK-"
  1223. "NULL-SHA:AES128-CCM-8:AES256-CCM-8:ECDHE-ECDSA-"
  1224. "AES128-CCM:ECDHE-ECDSA-AES128-CCM-8:ECDHE-ECDSA-AES256-CCM-8:ECDHE-RSA-AES128-"
  1225. "SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-R"
  1226. "SA-RC4-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-ECDSA-DES-CBC3-SHA"
  1227. ":AES128-SHA256:AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDH-"
  1228. "RSA-AES128-SHA:ECDH-RSA-AES256-SHA:ECDH-ECDSA-AES128-SHA:ECDH-ECDSA-AES256-SHA"
  1229. ":ECDH-RSA-RC4-SHA:ECDH-RSA-DES-CBC3-SHA:ECDH-ECDSA-RC4-SHA:ECDH-ECDSA-DES-CBC3"
  1230. "-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES"
  1231. "256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-E"
  1232. "CDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES128-GCM-SHA25"
  1233. "6:ECDH-RSA-AES256-GCM-SHA384:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES256-GC"
  1234. "M-SHA384:CAMELLIA128-SHA:DHE-RSA-CAMELLIA128-SHA:CAMELLIA256-SHA:DHE-RSA-CAMEL"
  1235. "LIA256-SHA:CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA256:CAMELLIA256-SHA256:DH"
  1236. "E-RSA-CAMELLIA256-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECD"
  1237. "H-RSA-AES128-SHA256:ECDH-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECD"
  1238. "SA-AES256-SHA384:ECDH-RSA-AES256-SHA384:ECDH-ECDSA-AES256-SHA384:ECDHE-RSA-CHA"
  1239. "CHA20-POLY1305:ECDHE-ECDSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-R"
  1240. "SA-CHACHA20-POLY1305-OLD:ECDHE-ECDSA-CHACHA20-POLY1305-OLD:DHE-RSA-CHACHA20-PO"
  1241. "LY1305-OLD:ECDHE-ECDSA-NULL-SHA:ECDHE-PSK-NULL-SHA256:ECDHE-PSK-A"
  1242. "ES128-CBC-SHA256:PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:DHE-PSK-CHA"
  1243. "CHA20-POLY1305:EDH-RSA-DES-CBC3-SHA:TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-S"
  1244. "HA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-CCM-SHA256:TLS13-AES128-CCM-"
  1245. "8-SHA256:TLS13-SHA256-SHA256:TLS13-SHA384-SHA384";
  1246. /* OpenVPN uses a "blacklist" method to specify which ciphers NOT to use */
  1247. #ifdef OPENSSL_EXTRA
  1248. char openvpnCiphers[] = "DEFAULT:!EXP:!LOW:!MEDIUM:!kDH:!kECDH:!DSS:!PSK:"
  1249. "!SRP:!kRSA:!aNULL:!eNULL";
  1250. #endif
  1251. #ifndef NO_RSA
  1252. testCertFile = svrCertFile;
  1253. testKeyFile = svrKeyFile;
  1254. #elif defined(HAVE_ECC)
  1255. testCertFile = eccCertFile;
  1256. testKeyFile = eccKeyFile;
  1257. #else
  1258. skipTest = 1;
  1259. #endif
  1260. if (skipTest != 1) {
  1261. #ifndef NO_WOLFSSL_SERVER
  1262. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1263. #else
  1264. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1265. #endif
  1266. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1267. WOLFSSL_FILETYPE_PEM));
  1268. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1269. WOLFSSL_FILETYPE_PEM));
  1270. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1271. /* First test freeing SSL, then CTX */
  1272. wolfSSL_free(ssl);
  1273. ssl = NULL;
  1274. wolfSSL_CTX_free(ctx);
  1275. ctx = NULL;
  1276. #ifndef NO_WOLFSSL_CLIENT
  1277. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1278. #else
  1279. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1280. #endif
  1281. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1282. WOLFSSL_FILETYPE_PEM));
  1283. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1284. WOLFSSL_FILETYPE_PEM));
  1285. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1286. /* Next test freeing CTX then SSL */
  1287. wolfSSL_CTX_free(ctx);
  1288. ctx = NULL;
  1289. wolfSSL_free(ssl);
  1290. ssl = NULL;
  1291. #ifndef NO_WOLFSSL_SERVER
  1292. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1293. #else
  1294. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1295. #endif
  1296. /* Test setting ciphers at ctx level */
  1297. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1298. WOLFSSL_FILETYPE_PEM));
  1299. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1300. WOLFSSL_FILETYPE_PEM));
  1301. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, optionsCiphers));
  1302. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1303. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1304. /* only update TLSv13 suites */
  1305. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384"));
  1306. #endif
  1307. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1308. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1309. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1310. /* only update pre-TLSv13 suites */
  1311. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx,
  1312. "ECDHE-RSA-AES128-GCM-SHA256"));
  1313. #endif
  1314. #ifdef OPENSSL_EXTRA
  1315. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, openvpnCiphers));
  1316. #endif
  1317. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1318. wolfSSL_CTX_free(ctx);
  1319. ctx = NULL;
  1320. wolfSSL_free(ssl);
  1321. ssl = NULL;
  1322. #ifndef NO_WOLFSSL_CLIENT
  1323. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1324. #else
  1325. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1326. #endif
  1327. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1328. WOLFSSL_FILETYPE_PEM));
  1329. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1330. WOLFSSL_FILETYPE_PEM));
  1331. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1332. /* test setting ciphers at SSL level */
  1333. ExpectTrue(wolfSSL_set_cipher_list(ssl, optionsCiphers));
  1334. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1335. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1336. /* only update TLSv13 suites */
  1337. ExpectTrue(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"));
  1338. #endif
  1339. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1340. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1341. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1342. /* only update pre-TLSv13 suites */
  1343. ExpectTrue(wolfSSL_set_cipher_list(ssl, "ECDHE-RSA-AES128-GCM-SHA256"));
  1344. #endif
  1345. wolfSSL_CTX_free(ctx);
  1346. ctx = NULL;
  1347. wolfSSL_free(ssl);
  1348. ssl = NULL;
  1349. }
  1350. return EXPECT_RESULT();
  1351. }
  1352. #endif
  1353. static int test_wolfSSL_CTX_set_cipher_list_bytes(void)
  1354. {
  1355. EXPECT_DECLS;
  1356. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)) && \
  1357. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1358. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1359. const char* testCertFile;
  1360. const char* testKeyFile;
  1361. WOLFSSL_CTX* ctx = NULL;
  1362. WOLFSSL* ssl = NULL;
  1363. const byte cipherList[] =
  1364. {
  1365. /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x16,
  1366. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x39,
  1367. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x33,
  1368. /* TLS_DH_anon_WITH_AES_128_CBC_SHA */ 0x00, 0x34,
  1369. /* TLS_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x35,
  1370. /* TLS_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x2F,
  1371. /* TLS_RSA_WITH_NULL_MD5 */ 0x00, 0x01,
  1372. /* TLS_RSA_WITH_NULL_SHA */ 0x00, 0x02,
  1373. /* TLS_PSK_WITH_AES_256_CBC_SHA */ 0x00, 0x8d,
  1374. /* TLS_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xae,
  1375. /* TLS_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xaf,
  1376. /* TLS_PSK_WITH_AES_128_CBC_SHA */ 0x00, 0x8c,
  1377. /* TLS_PSK_WITH_NULL_SHA256 */ 0x00, 0xb0,
  1378. /* TLS_PSK_WITH_NULL_SHA384 */ 0x00, 0xb1,
  1379. /* TLS_PSK_WITH_NULL_SHA */ 0x00, 0x2c,
  1380. /* SSL_RSA_WITH_RC4_128_SHA */ 0x00, 0x05,
  1381. /* SSL_RSA_WITH_RC4_128_MD5 */ 0x00, 0x04,
  1382. /* SSL_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x0A,
  1383. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  1384. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x14,
  1385. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x13,
  1386. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0A,
  1387. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x09,
  1388. /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */ 0xC0, 0x11,
  1389. /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x07,
  1390. /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x12,
  1391. /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x08,
  1392. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x27,
  1393. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256*/ 0xC0, 0x23,
  1394. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x28,
  1395. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384*/ 0xC0, 0x24,
  1396. /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */ 0xC0, 0x06,
  1397. /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */ 0xC0, 0x3a,
  1398. /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x37,
  1399. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  1400. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0F,
  1401. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x0E,
  1402. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x05,
  1403. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x04,
  1404. /* TLS_ECDH_RSA_WITH_RC4_128_SHA */ 0xC0, 0x0C,
  1405. /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x02,
  1406. /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x0D,
  1407. /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x03,
  1408. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x29,
  1409. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x25,
  1410. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x2A,
  1411. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x26,
  1412. /* WDM_WITH_NULL_SHA256 */ 0x00, 0xFE, /* wolfSSL DTLS Multicast */
  1413. /* SHA256 */
  1414. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x6b,
  1415. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x67,
  1416. /* TLS_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x3d,
  1417. /* TLS_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x3c,
  1418. /* TLS_RSA_WITH_NULL_SHA256 */ 0x00, 0x3b,
  1419. /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xb2,
  1420. /* TLS_DHE_PSK_WITH_NULL_SHA256 */ 0x00, 0xb4,
  1421. /* SHA384 */
  1422. /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xb3,
  1423. /* TLS_DHE_PSK_WITH_NULL_SHA384 */ 0x00, 0xb5,
  1424. /* AES-GCM */
  1425. /* TLS_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9c,
  1426. /* TLS_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9d,
  1427. /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9e,
  1428. /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9f,
  1429. /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa7,
  1430. /* TLS_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xa8,
  1431. /* TLS_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa9,
  1432. /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xaa,
  1433. /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xab,
  1434. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  1435. /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2b,
  1436. /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2c,
  1437. /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2d,
  1438. /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2e,
  1439. /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2f,
  1440. /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x30,
  1441. /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x31,
  1442. /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x32,
  1443. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  1444. * also, in some of the other AES-CCM suites
  1445. * there will be second byte number conflicts
  1446. * with non-ECC AES-GCM */
  1447. /* TLS_RSA_WITH_AES_128_CCM_8 */ 0xC0, 0xa0,
  1448. /* TLS_RSA_WITH_AES_256_CCM_8 */ 0xC0, 0xa1,
  1449. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */ 0xC0, 0xac,
  1450. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */ 0xC0, 0xae,
  1451. /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */ 0xC0, 0xaf,
  1452. /* TLS_PSK_WITH_AES_128_CCM */ 0xC0, 0xa4,
  1453. /* TLS_PSK_WITH_AES_256_CCM */ 0xC0, 0xa5,
  1454. /* TLS_PSK_WITH_AES_128_CCM_8 */ 0xC0, 0xa8,
  1455. /* TLS_PSK_WITH_AES_256_CCM_8 */ 0xC0, 0xa9,
  1456. /* TLS_DHE_PSK_WITH_AES_128_CCM */ 0xC0, 0xa6,
  1457. /* TLS_DHE_PSK_WITH_AES_256_CCM */ 0xC0, 0xa7,
  1458. /* Camellia */
  1459. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x41,
  1460. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x84,
  1461. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xba,
  1462. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc0,
  1463. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x45,
  1464. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x88,
  1465. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xbe,
  1466. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc4,
  1467. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  1468. /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa8,
  1469. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa9,
  1470. /* TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xaa,
  1471. /* TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xac,
  1472. /* TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xab,
  1473. /* TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xad,
  1474. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  1475. /* TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x13,
  1476. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x14,
  1477. /* TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x15,
  1478. /* ECDHE_PSK RFC8442, first byte is 0xD0 (ECDHE_PSK_BYTE) */
  1479. /* TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 */ 0xD0, 0x01,
  1480. /* TLS v1.3 cipher suites */
  1481. /* TLS_AES_128_GCM_SHA256 */ 0x13, 0x01,
  1482. /* TLS_AES_256_GCM_SHA384 */ 0x13, 0x02,
  1483. /* TLS_CHACHA20_POLY1305_SHA256 */ 0x13, 0x03,
  1484. /* TLS_AES_128_CCM_SHA256 */ 0x13, 0x04,
  1485. /* TLS_AES_128_CCM_8_SHA256 */ 0x13, 0x05,
  1486. /* TLS v1.3 Integrity only cipher suites - 0xC0 (ECC) first byte */
  1487. /* TLS_SHA256_SHA256 */ 0xC0, 0xB4,
  1488. /* TLS_SHA384_SHA384 */ 0xC0, 0xB5
  1489. };
  1490. #ifndef NO_RSA
  1491. testCertFile = svrCertFile;
  1492. testKeyFile = svrKeyFile;
  1493. #elif defined(HAVE_ECC)
  1494. testCertFile = eccCertFile;
  1495. testKeyFile = eccKeyFile;
  1496. #endif
  1497. #ifndef NO_WOLFSSL_SERVER
  1498. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1499. #else
  1500. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1501. #endif
  1502. ExpectTrue(wolfSSL_CTX_set_cipher_list_bytes(ctx, &cipherList[0U],
  1503. sizeof(cipherList)));
  1504. wolfSSL_CTX_free(ctx);
  1505. ctx = NULL;
  1506. #ifndef NO_WOLFSSL_SERVER
  1507. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1508. #else
  1509. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1510. #endif
  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. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1516. ExpectTrue(wolfSSL_set_cipher_list_bytes(ssl, &cipherList[0U],
  1517. sizeof(cipherList)));
  1518. wolfSSL_free(ssl);
  1519. wolfSSL_CTX_free(ctx);
  1520. #endif /* (OPENSSL_EXTRA || WOLFSSL_SET_CIPHER_BYTES) &&
  1521. (!NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER) && (!NO_RSA || HAVE_ECC) */
  1522. return EXPECT_RESULT();
  1523. }
  1524. static int test_wolfSSL_CTX_use_certificate(void)
  1525. {
  1526. EXPECT_DECLS;
  1527. #if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
  1528. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
  1529. defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
  1530. defined(WOLFSSL_HAPROXY)
  1531. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  1532. WOLFSSL_CTX* ctx = NULL;
  1533. X509* x509 = NULL;
  1534. #ifndef NO_WOLFSSL_SERVER
  1535. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1536. #else
  1537. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1538. #endif
  1539. ExpectNotNull(x509 = wolfSSL_X509_new());
  1540. /* Negative tests. */
  1541. ExpectIntEQ(SSL_CTX_use_certificate(NULL, NULL), 0);
  1542. ExpectIntEQ(SSL_CTX_use_certificate(ctx, NULL), 0);
  1543. ExpectIntEQ(SSL_CTX_use_certificate(NULL, x509), 0);
  1544. /* Empty certificate */
  1545. ExpectIntEQ(SSL_CTX_use_certificate(ctx, x509), 0);
  1546. wolfSSL_X509_free(x509);
  1547. wolfSSL_CTX_free(ctx);
  1548. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  1549. #endif
  1550. return EXPECT_RESULT();
  1551. }
  1552. static int test_wolfSSL_CTX_use_certificate_file(void)
  1553. {
  1554. EXPECT_DECLS;
  1555. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1556. WOLFSSL_CTX *ctx = NULL;
  1557. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1558. /* invalid context */
  1559. ExpectFalse(wolfSSL_CTX_use_certificate_file(NULL, svrCertFile,
  1560. WOLFSSL_FILETYPE_PEM));
  1561. /* invalid cert file */
  1562. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, bogusFile,
  1563. WOLFSSL_FILETYPE_PEM));
  1564. /* invalid cert type */
  1565. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, 9999));
  1566. #ifdef NO_RSA
  1567. /* rsa needed */
  1568. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1569. WOLFSSL_FILETYPE_PEM));
  1570. #else
  1571. /* success */
  1572. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1573. WOLFSSL_FILETYPE_PEM));
  1574. #endif
  1575. wolfSSL_CTX_free(ctx);
  1576. #endif
  1577. return EXPECT_RESULT();
  1578. }
  1579. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  1580. static int test_wolfSSL_CTX_use_certificate_ASN1(void)
  1581. {
  1582. EXPECT_DECLS;
  1583. #if !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_ASN)
  1584. WOLFSSL_CTX* ctx = NULL;
  1585. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1586. /* Failure cases. */
  1587. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, NULL ),
  1588. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1589. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, NULL ),
  1590. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1591. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, server_cert_der_2048),
  1592. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1593. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, server_cert_der_2048),
  1594. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1595. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx, sizeof_server_cert_der_2048,
  1596. server_cert_der_2048), WOLFSSL_SUCCESS);
  1597. wolfSSL_CTX_free(ctx);
  1598. #endif
  1599. return EXPECT_RESULT();
  1600. }
  1601. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  1602. /* Test function for wolfSSL_CTX_use_certificate_buffer. Load cert into
  1603. * context using buffer.
  1604. * PRE: NO_CERTS not defined; USE_CERT_BUFFERS_2048 defined; compile with
  1605. * --enable-testcert flag.
  1606. */
  1607. static int test_wolfSSL_CTX_use_certificate_buffer(void)
  1608. {
  1609. EXPECT_DECLS;
  1610. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1611. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  1612. WOLFSSL_CTX* ctx = NULL;
  1613. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1614. /* Invalid parameters. */
  1615. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, NULL, 0,
  1616. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1617. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, NULL, 0,
  1618. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1619. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, server_cert_der_2048,
  1620. 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1621. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048, 0,
  1622. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1623. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx,
  1624. server_cert_der_2048, sizeof_server_cert_der_2048,
  1625. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1626. wolfSSL_CTX_free(ctx);
  1627. #endif
  1628. return EXPECT_RESULT();
  1629. } /* END test_wolfSSL_CTX_use_certificate_buffer */
  1630. static int test_wolfSSL_use_certificate_buffer(void)
  1631. {
  1632. EXPECT_DECLS;
  1633. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1634. !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  1635. WOLFSSL_CTX* ctx = NULL;
  1636. WOLFSSL* ssl = NULL;
  1637. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1638. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1639. /* Invalid parameters. */
  1640. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, NULL, 0,
  1641. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1642. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, NULL, 0,
  1643. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1644. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, client_cert_der_2048, 0,
  1645. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1646. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, client_cert_der_2048, 0,
  1647. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1648. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl,
  1649. client_cert_der_2048, sizeof_client_cert_der_2048,
  1650. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1651. wolfSSL_free(ssl);
  1652. wolfSSL_CTX_free(ctx);
  1653. #endif
  1654. return EXPECT_RESULT();
  1655. }
  1656. static int test_wolfSSL_CTX_use_PrivateKey_file(void)
  1657. {
  1658. EXPECT_DECLS;
  1659. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1660. WOLFSSL_CTX *ctx = NULL;
  1661. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1662. /* invalid context */
  1663. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(NULL, svrKeyFile,
  1664. WOLFSSL_FILETYPE_PEM));
  1665. /* invalid key file */
  1666. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, bogusFile,
  1667. WOLFSSL_FILETYPE_PEM));
  1668. /* invalid key type */
  1669. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, 9999));
  1670. /* success */
  1671. #ifdef NO_RSA
  1672. /* rsa needed */
  1673. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1674. WOLFSSL_FILETYPE_PEM));
  1675. #else
  1676. /* success */
  1677. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1678. WOLFSSL_FILETYPE_PEM));
  1679. #endif
  1680. wolfSSL_CTX_free(ctx);
  1681. #endif
  1682. return EXPECT_RESULT();
  1683. }
  1684. static int test_wolfSSL_CTX_use_RSAPrivateKey_file(void)
  1685. {
  1686. EXPECT_DECLS;
  1687. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1688. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1689. WOLFSSL_CTX *ctx = NULL;
  1690. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1691. /* invalid context */
  1692. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1693. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1694. /* invalid key file */
  1695. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, bogusFile,
  1696. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1697. /* invalid key type */
  1698. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile, 9999),
  1699. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1700. /* success */
  1701. #ifdef NO_RSA
  1702. /* rsa needed */
  1703. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1704. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1705. #else
  1706. /* success */
  1707. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1708. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1709. #endif
  1710. wolfSSL_CTX_free(ctx);
  1711. #endif
  1712. return EXPECT_RESULT();
  1713. }
  1714. static int test_wolfSSL_use_RSAPrivateKey_file(void)
  1715. {
  1716. EXPECT_DECLS;
  1717. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1718. !defined(NO_WOLFSSL_CLIENT) && defined(OPENSSL_EXTRA)
  1719. WOLFSSL_CTX* ctx = NULL;
  1720. WOLFSSL* ssl = NULL;
  1721. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1722. ExpectNotNull(ssl = SSL_new(ctx));
  1723. /* invalid context */
  1724. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1725. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1726. /* invalid key file */
  1727. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, bogusFile,
  1728. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1729. /* invalid key type */
  1730. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile, 9999),
  1731. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1732. /* success */
  1733. #ifdef NO_RSA
  1734. /* rsa needed */
  1735. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1736. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1737. #else
  1738. /* success */
  1739. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1740. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1741. #endif
  1742. wolfSSL_free(ssl);
  1743. wolfSSL_CTX_free(ctx);
  1744. #endif
  1745. return EXPECT_RESULT();
  1746. }
  1747. static int test_wolfSSL_CTX_use_PrivateKey(void)
  1748. {
  1749. EXPECT_DECLS;
  1750. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1751. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1752. WOLFSSL_CTX *ctx = NULL;
  1753. WOLFSSL_EVP_PKEY* pkey = NULL;
  1754. const unsigned char* p;
  1755. (void)p;
  1756. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1757. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  1758. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1759. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1760. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1761. /* No data. */
  1762. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1763. wolfSSL_EVP_PKEY_free(pkey);
  1764. pkey = NULL;
  1765. #if defined(USE_CERT_BUFFERS_2048)
  1766. #if !defined(NO_RSA)
  1767. p = client_key_der_2048;
  1768. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p,
  1769. sizeof_client_key_der_2048));
  1770. #if defined(WOLFSSL_KEY_GEN)
  1771. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1772. #else
  1773. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1774. #endif
  1775. wolfSSL_EVP_PKEY_free(pkey);
  1776. pkey = NULL;
  1777. #endif
  1778. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  1779. #ifndef NO_DSA
  1780. p = dsa_key_der_2048;
  1781. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DSA, NULL, &p,
  1782. sizeof_dsa_key_der_2048));
  1783. #if !defined(HAVE_SELFTEST) && (defined(WOLFSSL_KEY_GEN) || \
  1784. defined(WOLFSSL_CERT_GEN))
  1785. /* Not supported in ProcessBuffer. */
  1786. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  1787. #else
  1788. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1789. #endif
  1790. wolfSSL_EVP_PKEY_free(pkey);
  1791. pkey = NULL;
  1792. #endif
  1793. #endif /* WOLFSSL_QT || OPENSSL_ALL || WOLFSSL_OPENSSH */
  1794. #if !defined(NO_DH) && defined(OPENSSL_ALL) && \
  1795. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  1796. p = dh_ffdhe_statickey_der_2048;
  1797. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &p,
  1798. sizeof_dh_ffdhe_statickey_der_2048));
  1799. /* Not supported. */
  1800. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1801. wolfSSL_EVP_PKEY_free(pkey);
  1802. pkey = NULL;
  1803. #endif
  1804. #endif /* USE_CERT_BUFFERS_2048 */
  1805. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  1806. p = ecc_clikey_der_256;
  1807. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p,
  1808. sizeof_ecc_clikey_der_256));
  1809. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1810. wolfSSL_EVP_PKEY_free(pkey);
  1811. pkey = NULL;
  1812. #endif
  1813. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  1814. (unsigned char*)"01234567012345670123456701234567", 32));
  1815. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1816. wolfSSL_EVP_PKEY_free(pkey);
  1817. pkey = NULL;
  1818. wolfSSL_CTX_free(ctx);
  1819. #endif
  1820. return EXPECT_RESULT();
  1821. }
  1822. /* test both file and buffer versions along with unloading trusted peer certs */
  1823. static int test_wolfSSL_CTX_trust_peer_cert(void)
  1824. {
  1825. EXPECT_DECLS;
  1826. #if !defined(NO_CERTS) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  1827. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_RSA)
  1828. WOLFSSL_CTX *ctx = NULL;
  1829. WOLFSSL* ssl = NULL;
  1830. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1831. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1832. #if !defined(NO_FILESYSTEM)
  1833. /* invalid file */
  1834. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, NULL,
  1835. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1836. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, bogusFile,
  1837. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1838. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  1839. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1840. /* success */
  1841. ExpectIntEQ(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  1842. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1843. /* unload cert */
  1844. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  1845. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  1846. /* invalid file */
  1847. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, NULL,
  1848. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1849. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, bogusFile,
  1850. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1851. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  1852. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1853. /* success */
  1854. ExpectIntEQ(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  1855. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1856. #ifdef WOLFSSL_LOCAL_X509_STORE
  1857. /* unload cert */
  1858. ExpectIntNE(wolfSSL_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  1859. ExpectIntEQ(wolfSSL_Unload_trust_peers(ssl), WOLFSSL_SUCCESS);
  1860. #endif
  1861. #endif
  1862. /* Test of loading certs from buffers */
  1863. /* invalid buffer */
  1864. ExpectIntNE(wolfSSL_CTX_trust_peer_buffer(ctx, NULL, -1,
  1865. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1866. /* success */
  1867. #ifdef USE_CERT_BUFFERS_1024
  1868. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_1024,
  1869. sizeof_client_cert_der_1024, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1870. #endif
  1871. #ifdef USE_CERT_BUFFERS_2048
  1872. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_2048,
  1873. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1874. #endif
  1875. /* unload cert */
  1876. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  1877. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  1878. wolfSSL_free(ssl);
  1879. wolfSSL_CTX_free(ctx);
  1880. #endif
  1881. return EXPECT_RESULT();
  1882. }
  1883. static int test_wolfSSL_CTX_load_verify_locations(void)
  1884. {
  1885. EXPECT_DECLS;
  1886. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT)
  1887. WOLFSSL_CTX *ctx = NULL;
  1888. #ifndef NO_RSA
  1889. WOLFSSL_CERT_MANAGER* cm = NULL;
  1890. #ifdef PERSIST_CERT_CACHE
  1891. int cacheSz = 0;
  1892. unsigned char* cache = NULL;
  1893. int used = 0;
  1894. #ifndef NO_FILESYSTEM
  1895. const char* cacheFile = "./tests/cert_cache.tmp";
  1896. #endif
  1897. int i;
  1898. int t;
  1899. int* p;
  1900. #endif
  1901. #endif
  1902. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  1903. const char* load_certs_path = "./certs/external";
  1904. const char* load_no_certs_path = "./examples";
  1905. const char* load_expired_path = "./certs/test/expired";
  1906. #endif
  1907. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1908. /* invalid arguments */
  1909. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(NULL, caCertFile, NULL),
  1910. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1911. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, NULL),
  1912. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1913. /* invalid ca file */
  1914. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL),
  1915. WS_RETURN_CODE(WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE),
  1916. WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  1917. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS) && \
  1918. ((defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)) && \
  1919. !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR))
  1920. /* invalid path */
  1921. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile),
  1922. WS_RETURN_CODE(WC_NO_ERR_TRACE(BAD_PATH_ERROR),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  1923. #endif
  1924. #if defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)
  1925. /* test ignoring the invalid path */
  1926. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, bogusFile,
  1927. WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR), WOLFSSL_SUCCESS);
  1928. #endif
  1929. /* load ca cert */
  1930. #ifdef NO_RSA
  1931. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  1932. WS_RETURN_CODE(WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  1933. #else /* Skip the following test without RSA certs. */
  1934. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  1935. WOLFSSL_SUCCESS);
  1936. #ifdef PERSIST_CERT_CACHE
  1937. /* Get cert cache size */
  1938. ExpectIntGT(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), 0);
  1939. ExpectNotNull(cache = (byte*)XMALLOC(cacheSz, NULL,
  1940. DYNAMIC_TYPE_TMP_BUFFER));
  1941. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, NULL),
  1942. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1943. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, -1, NULL),
  1944. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1945. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, -1, NULL),
  1946. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1947. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, cacheSz, NULL),
  1948. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1949. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, &used),
  1950. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1951. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, cacheSz, &used),
  1952. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1953. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, cacheSz, &used),
  1954. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1955. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, -1, &used),
  1956. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1957. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, NULL),
  1958. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1959. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz - 10, &used),
  1960. WC_NO_ERR_TRACE(BUFFER_E));
  1961. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, &used), 1);
  1962. ExpectIntEQ(cacheSz, used);
  1963. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, -1),
  1964. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1965. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, -1),
  1966. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1967. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, -1),
  1968. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1969. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, cacheSz),
  1970. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1971. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, cacheSz),
  1972. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1973. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, cacheSz),
  1974. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1975. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, -1),
  1976. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1977. /* Smaller than header. */
  1978. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, 1), WC_NO_ERR_TRACE(BUFFER_E));
  1979. for (i = 1; i < cacheSz; i++) {
  1980. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz - i),
  1981. WC_NO_ERR_TRACE(BUFFER_E));
  1982. }
  1983. if (EXPECT_SUCCESS()) {
  1984. /* Modify header for bad results! */
  1985. p = (int*)cache;
  1986. /* version */
  1987. t = p[0]; p[0] = 0xff;
  1988. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  1989. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  1990. p[0] = t; p++;
  1991. /* rows */
  1992. t = p[0]; p[0] = 0xff;
  1993. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  1994. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  1995. p[0] = t; p++;
  1996. /* columns[0] */
  1997. t = p[0]; p[0] = -1;
  1998. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  1999. WC_NO_ERR_TRACE(PARSE_ERROR));
  2000. p[0] = t; p += CA_TABLE_SIZE;
  2001. /* signerSz*/
  2002. t = p[0]; p[0] = 0xff;
  2003. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2004. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2005. p[0] = t;
  2006. }
  2007. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz), 1);
  2008. ExpectIntEQ(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), used);
  2009. #ifndef NO_FILESYSTEM
  2010. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2011. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2012. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2013. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, cacheFile), 1);
  2014. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2015. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2016. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2017. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "no-file"),
  2018. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2019. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, cacheFile), 1);
  2020. /* File contents is not a cache. */
  2021. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "./certs/ca-cert.pem"),
  2022. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2023. #endif
  2024. XFREE(cache, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  2025. #endif
  2026. /* Test unloading CA's */
  2027. ExpectIntEQ(wolfSSL_CTX_UnloadCAs(ctx), WOLFSSL_SUCCESS);
  2028. #ifdef PERSIST_CERT_CACHE
  2029. /* Verify no certs (result is less than cacheSz) */
  2030. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2031. #endif
  2032. /* load ca cert again */
  2033. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2034. WOLFSSL_SUCCESS);
  2035. /* Test getting CERT_MANAGER */
  2036. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(ctx));
  2037. /* Test unloading CA's using CM */
  2038. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  2039. #ifdef PERSIST_CERT_CACHE
  2040. /* Verify no certs (result is less than cacheSz) */
  2041. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2042. #endif
  2043. #endif
  2044. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2045. /* Test loading CA certificates using a path */
  2046. #ifdef NO_RSA
  2047. /* failure here okay since certs in external directory are RSA */
  2048. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2049. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2050. #else
  2051. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2052. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2053. #endif
  2054. /* Test loading path with no files */
  2055. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2056. load_no_certs_path, WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2057. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2058. /* Test loading expired CA certificates */
  2059. #ifdef NO_RSA
  2060. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2061. load_expired_path,
  2062. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2063. WOLFSSL_SUCCESS);
  2064. #else
  2065. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2066. load_expired_path,
  2067. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2068. WOLFSSL_SUCCESS);
  2069. #endif
  2070. /* Test loading CA certificates and ignoring all errors */
  2071. #ifdef NO_RSA
  2072. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2073. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2074. #else
  2075. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2076. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WOLFSSL_SUCCESS);
  2077. #endif
  2078. #endif
  2079. wolfSSL_CTX_free(ctx);
  2080. #endif
  2081. return EXPECT_RESULT();
  2082. }
  2083. static int test_wolfSSL_CTX_load_system_CA_certs(void)
  2084. {
  2085. int res = TEST_SKIPPED;
  2086. #if defined(WOLFSSL_SYS_CA_CERTS) && !defined(NO_WOLFSSL_CLIENT) && \
  2087. (!defined(NO_RSA) || defined(HAVE_ECC))
  2088. WOLFSSL_CTX* ctx;
  2089. byte dirValid = 0;
  2090. int ret = 0;
  2091. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  2092. if (ctx == NULL) {
  2093. fprintf(stderr, "wolfSSL_CTX_new failed.\n");
  2094. ret = -1;
  2095. }
  2096. if (ret == 0) {
  2097. #if defined(USE_WINDOWS_API) || defined(__APPLE__)
  2098. dirValid = 1;
  2099. #else
  2100. word32 numDirs;
  2101. const char** caDirs = wolfSSL_get_system_CA_dirs(&numDirs);
  2102. if (caDirs == NULL || numDirs == 0) {
  2103. fprintf(stderr, "wolfSSL_get_system_CA_dirs failed.\n");
  2104. ret = -1;
  2105. }
  2106. else {
  2107. ReadDirCtx dirCtx;
  2108. word32 i;
  2109. for (i = 0; i < numDirs; ++i) {
  2110. if (wc_ReadDirFirst(&dirCtx, caDirs[i], NULL) == 0) {
  2111. /* Directory isn't empty. */
  2112. dirValid = 1;
  2113. wc_ReadDirClose(&dirCtx);
  2114. break;
  2115. }
  2116. }
  2117. }
  2118. #endif
  2119. }
  2120. /*
  2121. * If the directory isn't empty, we should be able to load CA
  2122. * certs from it. On Windows/Mac, we assume the CA cert stores are
  2123. * usable.
  2124. */
  2125. if (ret == 0 && dirValid && wolfSSL_CTX_load_system_CA_certs(ctx) !=
  2126. WOLFSSL_SUCCESS) {
  2127. fprintf(stderr, "wolfSSL_CTX_load_system_CA_certs failed.\n");
  2128. ret = -1;
  2129. }
  2130. #ifdef OPENSSL_EXTRA
  2131. if (ret == 0 &&
  2132. wolfSSL_CTX_set_default_verify_paths(ctx) != WOLFSSL_SUCCESS) {
  2133. fprintf(stderr, "wolfSSL_CTX_set_default_verify_paths failed.\n");
  2134. ret = -1;
  2135. }
  2136. #endif /* OPENSSL_EXTRA */
  2137. wolfSSL_CTX_free(ctx);
  2138. res = TEST_RES_CHECK(ret == 0);
  2139. #endif /* WOLFSSL_SYS_CA_CERTS && !NO_WOLFSSL_CLIENT */
  2140. return res;
  2141. }
  2142. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2143. static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz,
  2144. int file_type)
  2145. {
  2146. int ret;
  2147. WOLFSSL_CERT_MANAGER* cm;
  2148. cm = wolfSSL_CertManagerNew();
  2149. if (cm == NULL) {
  2150. fprintf(stderr, "test_cm_load_ca failed\n");
  2151. return -1;
  2152. }
  2153. ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, cert_sz, file_type);
  2154. wolfSSL_CertManagerFree(cm);
  2155. return ret;
  2156. }
  2157. static int test_cm_load_ca_file(const char* ca_cert_file)
  2158. {
  2159. int ret = 0;
  2160. byte* cert_buf = NULL;
  2161. size_t cert_sz = 0;
  2162. #if defined(WOLFSSL_PEM_TO_DER)
  2163. DerBuffer* pDer = NULL;
  2164. #endif
  2165. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2166. if (ret == 0) {
  2167. /* normal test */
  2168. ret = test_cm_load_ca_buffer(cert_buf, cert_sz, WOLFSSL_FILETYPE_PEM);
  2169. if (ret == WOLFSSL_SUCCESS) {
  2170. /* test including null terminator in length */
  2171. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2172. if (tmp == NULL) {
  2173. ret = MEMORY_E;
  2174. }
  2175. else {
  2176. cert_buf = tmp;
  2177. cert_buf[cert_sz] = '\0';
  2178. ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1,
  2179. WOLFSSL_FILETYPE_PEM);
  2180. }
  2181. }
  2182. #if defined(WOLFSSL_PEM_TO_DER)
  2183. if (ret == WOLFSSL_SUCCESS) {
  2184. /* test loading DER */
  2185. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2186. if (ret == 0 && pDer != NULL) {
  2187. ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length,
  2188. WOLFSSL_FILETYPE_ASN1);
  2189. wc_FreeDer(&pDer);
  2190. }
  2191. }
  2192. #endif
  2193. }
  2194. free(cert_buf);
  2195. return ret;
  2196. }
  2197. static int test_cm_load_ca_buffer_ex(const byte* cert_buf, size_t cert_sz,
  2198. int file_type, word32 flags)
  2199. {
  2200. int ret;
  2201. WOLFSSL_CERT_MANAGER* cm;
  2202. cm = wolfSSL_CertManagerNew();
  2203. if (cm == NULL) {
  2204. fprintf(stderr, "test_cm_load_ca failed\n");
  2205. return -1;
  2206. }
  2207. ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, cert_sz, file_type,
  2208. 0, flags);
  2209. wolfSSL_CertManagerFree(cm);
  2210. return ret;
  2211. }
  2212. static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
  2213. {
  2214. int ret = 0;
  2215. byte* cert_buf = NULL;
  2216. size_t cert_sz = 0;
  2217. #if defined(WOLFSSL_PEM_TO_DER)
  2218. DerBuffer* pDer = NULL;
  2219. #endif
  2220. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2221. if (ret == 0) {
  2222. /* normal test */
  2223. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz,
  2224. WOLFSSL_FILETYPE_PEM, flags);
  2225. if (ret == WOLFSSL_SUCCESS) {
  2226. /* test including null terminator in length */
  2227. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2228. if (tmp == NULL) {
  2229. ret = MEMORY_E;
  2230. }
  2231. else {
  2232. cert_buf = tmp;
  2233. cert_buf[cert_sz] = '\0';
  2234. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1,
  2235. WOLFSSL_FILETYPE_PEM, flags);
  2236. }
  2237. }
  2238. #if defined(WOLFSSL_PEM_TO_DER)
  2239. if (ret == WOLFSSL_SUCCESS) {
  2240. /* test loading DER */
  2241. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2242. if (ret == 0 && pDer != NULL) {
  2243. ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length,
  2244. WOLFSSL_FILETYPE_ASN1, flags);
  2245. wc_FreeDer(&pDer);
  2246. }
  2247. }
  2248. #endif
  2249. }
  2250. free(cert_buf);
  2251. return ret;
  2252. }
  2253. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  2254. static int test_wolfSSL_CertManagerAPI(void)
  2255. {
  2256. EXPECT_DECLS;
  2257. #ifndef NO_CERTS
  2258. WOLFSSL_CERT_MANAGER* cm = NULL;
  2259. unsigned char c;
  2260. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2261. wolfSSL_CertManagerFree(NULL);
  2262. ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0);
  2263. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2264. #ifdef WOLFSSL_TRUST_PEER_CERT
  2265. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2266. #endif
  2267. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1,
  2268. WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2269. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2270. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1,
  2271. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2272. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1,
  2273. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2274. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1,
  2275. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2276. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, 1,
  2277. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2278. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, 1,
  2279. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2280. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, 1,
  2281. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2282. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1,
  2283. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2284. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1),
  2285. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2286. #endif
  2287. #if !defined(NO_FILESYSTEM)
  2288. {
  2289. const char* ca_cert = "./certs/ca-cert.pem";
  2290. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2291. const char* ca_cert_der = "./certs/ca-cert.der";
  2292. #endif
  2293. const char* ca_path = "./certs";
  2294. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2295. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1),
  2296. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2297. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  2298. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2299. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert,
  2300. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2301. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1),
  2302. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2303. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file",
  2304. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2305. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der,
  2306. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  2307. #endif
  2308. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL),
  2309. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2310. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL),
  2311. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2312. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path),
  2313. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2314. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path),
  2315. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2316. }
  2317. #endif
  2318. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  2319. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1);
  2320. #elif !defined(HAVE_CRL)
  2321. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2322. #endif
  2323. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2324. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1);
  2325. #ifdef HAVE_CRL
  2326. /* Test APIs when CRL is disabled. */
  2327. #ifdef HAVE_CRL_IO
  2328. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  2329. #endif
  2330. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  2331. sizeof_server_cert_der_2048), 1);
  2332. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  2333. #endif
  2334. /* OCSP */
  2335. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2336. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2337. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2338. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2339. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2340. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2341. #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  2342. !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2343. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2344. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2345. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2346. #endif
  2347. #ifdef HAVE_OCSP
  2348. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2349. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2350. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2351. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2352. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2353. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2354. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2355. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0,
  2356. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2357. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1,
  2358. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2359. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1,
  2360. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2361. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL),
  2362. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2363. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""),
  2364. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2365. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1);
  2366. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL),
  2367. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2368. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1);
  2369. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1);
  2370. /* Test APIs when OCSP is disabled. */
  2371. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1,
  2372. NULL, NULL, NULL, NULL), 1);
  2373. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1);
  2374. #endif
  2375. ExpectIntEQ(wolfSSL_CertManager_up_ref(cm), 1);
  2376. if (EXPECT_SUCCESS()) {
  2377. wolfSSL_CertManagerFree(cm);
  2378. }
  2379. wolfSSL_CertManagerFree(cm);
  2380. cm = NULL;
  2381. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2382. #ifdef HAVE_OCSP
  2383. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE |
  2384. WOLFSSL_OCSP_CHECKALL), 1);
  2385. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  2386. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2387. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2388. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2389. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), 1);
  2390. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2391. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), 1);
  2392. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), 1);
  2393. #endif
  2394. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2395. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2396. #endif
  2397. #ifdef WOLFSSL_TRUST_PEER_CERT
  2398. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(cm), 1);
  2399. #endif
  2400. wolfSSL_CertManagerFree(cm);
  2401. #endif
  2402. return EXPECT_RESULT();
  2403. }
  2404. static int test_wolfSSL_CertManagerLoadCABuffer(void)
  2405. {
  2406. EXPECT_DECLS;
  2407. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2408. const char* ca_cert = "./certs/ca-cert.pem";
  2409. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2410. int ret;
  2411. ExpectIntLE(ret = test_cm_load_ca_file(ca_cert), 1);
  2412. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2413. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2414. #elif defined(NO_RSA)
  2415. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2416. #else
  2417. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2418. #endif
  2419. ExpectIntLE(ret = test_cm_load_ca_file(ca_expired_cert), 1);
  2420. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2421. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2422. #elif defined(NO_RSA)
  2423. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2424. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2425. !defined(NO_ASN_TIME)
  2426. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2427. #else
  2428. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2429. #endif
  2430. #endif
  2431. return EXPECT_RESULT();
  2432. }
  2433. static int test_wolfSSL_CertManagerLoadCABuffer_ex(void)
  2434. {
  2435. EXPECT_DECLS;
  2436. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2437. const char* ca_cert = "./certs/ca-cert.pem";
  2438. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2439. int ret;
  2440. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE),
  2441. 1);
  2442. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2443. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2444. #elif defined(NO_RSA)
  2445. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2446. #else
  2447. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2448. #endif
  2449. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert,
  2450. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1);
  2451. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2452. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2453. #elif defined(NO_RSA)
  2454. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2455. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2456. !defined(NO_ASN_TIME) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2457. defined(OPENSSL_COMPATIBLE_DEFAULTS)
  2458. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2459. #else
  2460. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2461. #endif
  2462. #endif
  2463. return EXPECT_RESULT();
  2464. }
  2465. static int test_wolfSSL_CertManagerGetCerts(void)
  2466. {
  2467. EXPECT_DECLS;
  2468. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2469. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2470. defined(WOLFSSL_SIGNER_DER_CERT)
  2471. WOLFSSL_CERT_MANAGER* cm = NULL;
  2472. WOLFSSL_STACK* sk = NULL;
  2473. X509* x509 = NULL;
  2474. X509* cert1 = NULL;
  2475. FILE* file1 = NULL;
  2476. #ifdef DEBUG_WOLFSSL_VERBOSE
  2477. WOLFSSL_BIO* bio = NULL;
  2478. #endif
  2479. int i = 0;
  2480. int ret = 0;
  2481. const byte* der = NULL;
  2482. int derSz = 0;
  2483. ExpectNotNull(file1 = fopen("./certs/ca-cert.pem", "rb"));
  2484. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  2485. if (file1 != NULL) {
  2486. fclose(file1);
  2487. }
  2488. ExpectNull(sk = wolfSSL_CertManagerGetCerts(NULL));
  2489. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2490. ExpectNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2491. ExpectNotNull(der = wolfSSL_X509_get_der(cert1, &derSz));
  2492. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  2493. /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT
  2494. * and full OpenSSL compatibility */
  2495. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2496. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  2497. #else
  2498. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2499. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  2500. #endif
  2501. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  2502. "./certs/ca-cert.pem", NULL));
  2503. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2504. for (i = 0; EXPECT_SUCCESS() && i < sk_X509_num(sk); i++) {
  2505. ExpectNotNull(x509 = sk_X509_value(sk, i));
  2506. ExpectIntEQ(0, wolfSSL_X509_cmp(x509, cert1));
  2507. #ifdef DEBUG_WOLFSSL_VERBOSE
  2508. bio = BIO_new(wolfSSL_BIO_s_file());
  2509. if (bio != NULL) {
  2510. BIO_set_fp(bio, stderr, BIO_NOCLOSE);
  2511. X509_print(bio, x509);
  2512. BIO_free(bio);
  2513. }
  2514. #endif /* DEBUG_WOLFSSL_VERBOSE */
  2515. }
  2516. wolfSSL_X509_free(cert1);
  2517. sk_X509_pop_free(sk, NULL);
  2518. wolfSSL_CertManagerFree(cm);
  2519. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2520. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2521. defined(WOLFSSL_SIGNER_DER_CERT) */
  2522. return EXPECT_RESULT();
  2523. }
  2524. static int test_wolfSSL_CertManagerSetVerify(void)
  2525. {
  2526. EXPECT_DECLS;
  2527. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2528. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2529. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  2530. WOLFSSL_CERT_MANAGER* cm = NULL;
  2531. int tmp = myVerifyAction;
  2532. const char* ca_cert = "./certs/ca-cert.pem";
  2533. const char* expiredCert = "./certs/test/expired/expired-cert.pem";
  2534. wolfSSL_CertManagerSetVerify(NULL, NULL);
  2535. wolfSSL_CertManagerSetVerify(NULL, myVerify);
  2536. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2537. wolfSSL_CertManagerSetVerify(cm, myVerify);
  2538. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2539. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL), -1);
  2540. #else
  2541. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL),
  2542. WOLFSSL_SUCCESS);
  2543. #endif
  2544. /* Use the test CB that always accepts certs */
  2545. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  2546. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert,
  2547. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2548. #ifdef WOLFSSL_ALWAYS_VERIFY_CB
  2549. {
  2550. const char* verifyCert = "./certs/server-cert.der";
  2551. /* Use the test CB that always fails certs */
  2552. myVerifyAction = VERIFY_FORCE_FAIL;
  2553. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert,
  2554. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR));
  2555. }
  2556. #endif
  2557. wolfSSL_CertManagerFree(cm);
  2558. myVerifyAction = tmp;
  2559. #endif
  2560. return EXPECT_RESULT();
  2561. }
  2562. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  2563. defined(DEBUG_UNIT_TEST_CERTS)
  2564. /* Used when debugging name constraint tests. Not static to allow use in
  2565. * multiple locations with complex define guards. */
  2566. void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName)
  2567. {
  2568. BIO* out = BIO_new_file(fileName, "wb");
  2569. if (out != NULL) {
  2570. PEM_write_bio_X509(out, x509);
  2571. BIO_free(out);
  2572. }
  2573. }
  2574. void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName)
  2575. {
  2576. BIO* out = BIO_new_file(fileName, "wb");
  2577. if (out != NULL) {
  2578. BIO_write(out, der, derSz);
  2579. BIO_free(out);
  2580. }
  2581. }
  2582. #else
  2583. #define DEBUG_WRITE_CERT_X509(x509, fileName) WC_DO_NOTHING
  2584. #define DEBUG_WRITE_DER(der, derSz, fileName) WC_DO_NOTHING
  2585. #endif
  2586. static int test_wolfSSL_CertManagerNameConstraint(void)
  2587. {
  2588. EXPECT_DECLS;
  2589. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2590. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2591. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2592. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2593. !defined(NO_SHA256)
  2594. WOLFSSL_CERT_MANAGER* cm = NULL;
  2595. WOLFSSL_EVP_PKEY *priv = NULL;
  2596. WOLFSSL_X509_NAME* name = NULL;
  2597. const char* ca_cert = "./certs/test/cert-ext-nc.der";
  2598. const char* server_cert = "./certs/test/server-goodcn.pem";
  2599. int i = 0;
  2600. static const byte extNameConsOid[] = {85, 29, 30};
  2601. RsaKey key;
  2602. WC_RNG rng;
  2603. byte *der = NULL;
  2604. int derSz = 0;
  2605. word32 idx = 0;
  2606. byte *pt;
  2607. WOLFSSL_X509 *x509 = NULL;
  2608. WOLFSSL_X509 *ca = NULL;
  2609. wc_InitRng(&rng);
  2610. /* load in CA private key for signing */
  2611. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0);
  2612. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  2613. sizeof_server_key_der_2048), 0);
  2614. /* get ca certificate then alter it */
  2615. ExpectNotNull(der =
  2616. (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  2617. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert,
  2618. WOLFSSL_FILETYPE_ASN1));
  2619. ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz));
  2620. if (EXPECT_SUCCESS() && (der != NULL)) {
  2621. XMEMCPY(der, pt, derSz);
  2622. /* find the name constraint extension and alter it */
  2623. pt = der;
  2624. for (i = 0; i < derSz - 3; i++) {
  2625. if (XMEMCMP(pt, extNameConsOid, 3) == 0) {
  2626. pt += 3;
  2627. break;
  2628. }
  2629. pt++;
  2630. }
  2631. ExpectIntNE(i, derSz - 3); /* did not find OID if this case is hit */
  2632. /* go to the length value and set it to 0 */
  2633. while (i < derSz && *pt != 0x81) {
  2634. pt++;
  2635. i++;
  2636. }
  2637. ExpectIntNE(i, derSz); /* did not place to alter */
  2638. pt++;
  2639. *pt = 0x00;
  2640. }
  2641. /* resign the altered certificate */
  2642. ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der,
  2643. FOURK_BUF, &key, NULL, &rng)), 0);
  2644. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2645. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2646. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  2647. wolfSSL_CertManagerFree(cm);
  2648. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2649. wolfSSL_X509_free(x509);
  2650. wc_FreeRsaKey(&key);
  2651. wc_FreeRng(&rng);
  2652. /* add email alt name to satisfy constraint */
  2653. pt = (byte*)server_key_der_2048;
  2654. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2655. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2656. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2657. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2658. WOLFSSL_FILETYPE_ASN1));
  2659. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2660. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2661. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2662. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2663. /* Good cert test with proper alt email name */
  2664. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2665. WOLFSSL_FILETYPE_PEM));
  2666. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2667. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2668. name = NULL;
  2669. ExpectNotNull(name = X509_NAME_new());
  2670. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2671. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2672. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2673. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2674. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2675. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2676. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2677. X509_NAME_free(name);
  2678. name = NULL;
  2679. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2680. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2681. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  2682. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2683. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2684. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2685. wolfSSL_X509_free(x509);
  2686. x509 = NULL;
  2687. /* Cert with bad alt name list */
  2688. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2689. WOLFSSL_FILETYPE_PEM));
  2690. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2691. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2692. name = NULL;
  2693. ExpectNotNull(name = X509_NAME_new());
  2694. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2695. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2696. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2697. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2698. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2699. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2700. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2701. X509_NAME_free(name);
  2702. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2703. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2704. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2705. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2706. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2707. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2708. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2709. wolfSSL_CertManagerFree(cm);
  2710. wolfSSL_X509_free(x509);
  2711. wolfSSL_X509_free(ca);
  2712. wolfSSL_EVP_PKEY_free(priv);
  2713. #endif
  2714. return EXPECT_RESULT();
  2715. }
  2716. static int test_wolfSSL_CertManagerNameConstraint2(void)
  2717. {
  2718. EXPECT_DECLS;
  2719. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2720. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2721. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2722. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES)
  2723. const char* ca_cert = "./certs/test/cert-ext-ndir.der";
  2724. const char* ca_cert2 = "./certs/test/cert-ext-ndir-exc.der";
  2725. const char* server_cert = "./certs/server-cert.pem";
  2726. WOLFSSL_CERT_MANAGER* cm = NULL;
  2727. WOLFSSL_X509 *x509 = NULL;
  2728. WOLFSSL_X509 *ca = NULL;
  2729. const unsigned char *der = NULL;
  2730. const unsigned char *pt;
  2731. WOLFSSL_EVP_PKEY *priv = NULL;
  2732. WOLFSSL_X509_NAME* name = NULL;
  2733. int derSz = 0;
  2734. /* C=US*/
  2735. char altName[] = {
  2736. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2737. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53
  2738. };
  2739. /* C=ID */
  2740. char altNameFail[] = {
  2741. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2742. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x44
  2743. };
  2744. /* C=US ST=California*/
  2745. char altNameExc[] = {
  2746. 0x30, 0x22,
  2747. 0x31, 0x0B,
  2748. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  2749. 0x31, 0x13,
  2750. 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A,
  2751. 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61
  2752. };
  2753. /* load in CA private key for signing */
  2754. pt = ca_key_der_2048;
  2755. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  2756. sizeof_ca_key_der_2048));
  2757. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2758. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2759. WOLFSSL_FILETYPE_ASN1));
  2760. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2761. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2762. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2763. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2764. WOLFSSL_FILETYPE_PEM));
  2765. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2766. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2767. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2768. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2769. #else
  2770. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2771. #endif
  2772. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2773. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2774. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2775. /* add in matching DIR alt name and resign */
  2776. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2777. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2778. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2779. #else
  2780. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2781. #endif
  2782. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2783. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2784. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2785. wolfSSL_X509_free(x509);
  2786. x509 = NULL;
  2787. /* check verify fail */
  2788. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2789. WOLFSSL_FILETYPE_PEM));
  2790. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2791. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2792. /* add in miss matching DIR alt name and resign */
  2793. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  2794. ASN_DIR_TYPE);
  2795. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2796. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2797. #else
  2798. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2799. #endif
  2800. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2801. #ifndef WOLFSSL_NO_ASN_STRICT
  2802. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2803. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2804. #else
  2805. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2806. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2807. #endif
  2808. /* check that it still fails if one bad altname and one good altname is in
  2809. * the certificate */
  2810. wolfSSL_X509_free(x509);
  2811. x509 = NULL;
  2812. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2813. WOLFSSL_FILETYPE_PEM));
  2814. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2815. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2816. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2817. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  2818. ASN_DIR_TYPE);
  2819. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2820. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2821. #else
  2822. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2823. #endif
  2824. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2825. #ifndef WOLFSSL_NO_ASN_STRICT
  2826. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2827. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2828. #else
  2829. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2830. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2831. #endif
  2832. /* check it fails with switching position of bad altname */
  2833. wolfSSL_X509_free(x509);
  2834. x509 = NULL;
  2835. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2836. WOLFSSL_FILETYPE_PEM));
  2837. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2838. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2839. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  2840. ASN_DIR_TYPE);
  2841. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2842. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2843. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2844. #else
  2845. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2846. #endif
  2847. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2848. #ifndef WOLFSSL_NO_ASN_STRICT
  2849. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2850. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2851. #else
  2852. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2853. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2854. #endif
  2855. wolfSSL_CertManagerFree(cm);
  2856. wolfSSL_X509_free(x509);
  2857. x509 = NULL;
  2858. wolfSSL_X509_free(ca);
  2859. ca = NULL;
  2860. /* now test with excluded name constraint */
  2861. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2862. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2,
  2863. WOLFSSL_FILETYPE_ASN1));
  2864. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2865. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2866. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2867. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2868. WOLFSSL_FILETYPE_PEM));
  2869. wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc),
  2870. ASN_DIR_TYPE);
  2871. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2872. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2873. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2874. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2875. #else
  2876. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2877. #endif
  2878. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2879. #ifndef WOLFSSL_NO_ASN_STRICT
  2880. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2881. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2882. #else
  2883. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2884. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2885. #endif
  2886. wolfSSL_CertManagerFree(cm);
  2887. wolfSSL_X509_free(x509);
  2888. wolfSSL_X509_free(ca);
  2889. wolfSSL_EVP_PKEY_free(priv);
  2890. #endif
  2891. return EXPECT_RESULT();
  2892. }
  2893. static int test_wolfSSL_CertManagerNameConstraint3(void)
  2894. {
  2895. EXPECT_DECLS;
  2896. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2897. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2898. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2899. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2900. !defined(NO_SHA256)
  2901. WOLFSSL_CERT_MANAGER* cm = NULL;
  2902. WOLFSSL_EVP_PKEY *priv = NULL;
  2903. WOLFSSL_X509_NAME* name = NULL;
  2904. const char* ca_cert = "./certs/test/cert-ext-mnc.der";
  2905. const char* server_cert = "./certs/test/server-goodcn.pem";
  2906. byte *der = NULL;
  2907. int derSz = 0;
  2908. byte *pt;
  2909. WOLFSSL_X509 *x509 = NULL;
  2910. WOLFSSL_X509 *ca = NULL;
  2911. pt = (byte*)server_key_der_2048;
  2912. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2913. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2914. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2915. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2916. WOLFSSL_FILETYPE_ASN1));
  2917. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2918. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2919. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2920. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2921. /* check satisfying .wolfssl.com constraint passes */
  2922. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2923. WOLFSSL_FILETYPE_PEM));
  2924. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2925. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2926. name = NULL;
  2927. ExpectNotNull(name = X509_NAME_new());
  2928. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2929. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2930. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2931. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2932. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2933. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2934. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2935. X509_NAME_free(name);
  2936. name = NULL;
  2937. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2938. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2939. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  2940. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2941. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2942. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2943. wolfSSL_X509_free(x509);
  2944. x509 = NULL;
  2945. /* check satisfying .random.com constraint passes */
  2946. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2947. WOLFSSL_FILETYPE_PEM));
  2948. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2949. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2950. name = NULL;
  2951. ExpectNotNull(name = X509_NAME_new());
  2952. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2953. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2954. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2955. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2956. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2957. (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS);
  2958. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2959. X509_NAME_free(name);
  2960. name = NULL;
  2961. wolfSSL_X509_add_altname(x509, "wolfssl@info.example.com", ASN_RFC822_TYPE);
  2962. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2963. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  2964. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2965. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2966. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2967. wolfSSL_X509_free(x509);
  2968. x509 = NULL;
  2969. /* check fail case when neither constraint is matched */
  2970. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2971. WOLFSSL_FILETYPE_PEM));
  2972. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2973. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2974. name = NULL;
  2975. ExpectNotNull(name = X509_NAME_new());
  2976. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2977. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2978. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2979. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2980. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2981. (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS);
  2982. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2983. X509_NAME_free(name);
  2984. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2985. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2986. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2987. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2988. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2989. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2990. wolfSSL_CertManagerFree(cm);
  2991. wolfSSL_X509_free(x509);
  2992. wolfSSL_X509_free(ca);
  2993. wolfSSL_EVP_PKEY_free(priv);
  2994. #endif
  2995. return EXPECT_RESULT();
  2996. }
  2997. static int test_wolfSSL_CertManagerNameConstraint4(void)
  2998. {
  2999. EXPECT_DECLS;
  3000. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3001. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3002. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3003. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3004. !defined(NO_SHA256)
  3005. WOLFSSL_CERT_MANAGER* cm = NULL;
  3006. WOLFSSL_EVP_PKEY *priv = NULL;
  3007. WOLFSSL_X509_NAME* name = NULL;
  3008. const char* ca_cert = "./certs/test/cert-ext-ncdns.der";
  3009. const char* server_cert = "./certs/test/server-goodcn.pem";
  3010. byte *der = NULL;
  3011. int derSz;
  3012. byte *pt;
  3013. WOLFSSL_X509 *x509 = NULL;
  3014. WOLFSSL_X509 *ca = NULL;
  3015. pt = (byte*)server_key_der_2048;
  3016. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3017. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3018. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3019. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3020. WOLFSSL_FILETYPE_ASN1));
  3021. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3022. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3023. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3024. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3025. /* check satisfying wolfssl.com constraint passes */
  3026. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3027. WOLFSSL_FILETYPE_PEM));
  3028. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3029. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3030. name = NULL;
  3031. ExpectNotNull(name = X509_NAME_new());
  3032. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3033. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3034. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3035. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3036. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3037. X509_NAME_free(name);
  3038. name = NULL;
  3039. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3040. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3041. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3042. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3043. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3044. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3045. wolfSSL_X509_free(x509);
  3046. x509 = NULL;
  3047. /* check satisfying example.com constraint passes */
  3048. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3049. WOLFSSL_FILETYPE_PEM));
  3050. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3051. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3052. name = NULL;
  3053. ExpectNotNull(name = X509_NAME_new());
  3054. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3055. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3056. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3057. (byte*)"example.com", 11, -1, 0), SSL_SUCCESS);
  3058. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3059. X509_NAME_free(name);
  3060. name = NULL;
  3061. wolfSSL_X509_add_altname(x509, "www.example.com", ASN_DNS_TYPE);
  3062. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3063. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3064. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3065. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3066. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3067. wolfSSL_X509_free(x509);
  3068. x509 = NULL;
  3069. /* check satisfying wolfssl.com constraint passes with list of DNS's */
  3070. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3071. WOLFSSL_FILETYPE_PEM));
  3072. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3073. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3074. name = NULL;
  3075. ExpectNotNull(name = X509_NAME_new());
  3076. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3077. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3078. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3079. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3080. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3081. X509_NAME_free(name);
  3082. name = NULL;
  3083. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3084. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3085. wolfSSL_X509_add_altname(x509, "extra.wolfssl.com", ASN_DNS_TYPE);
  3086. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3087. DEBUG_WRITE_CERT_X509(x509, "good-multiple-constraint-cert.pem");
  3088. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3089. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3090. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3091. wolfSSL_X509_free(x509);
  3092. x509 = NULL;
  3093. /* check fail when one DNS in the list is bad */
  3094. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3095. WOLFSSL_FILETYPE_PEM));
  3096. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3097. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3098. name = NULL;
  3099. ExpectNotNull(name = X509_NAME_new());
  3100. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3101. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3102. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3103. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3104. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3105. X509_NAME_free(name);
  3106. name = NULL;
  3107. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3108. wolfSSL_X509_add_altname(x509, "www.nomatch.com", ASN_DNS_TYPE);
  3109. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3110. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3111. DEBUG_WRITE_CERT_X509(x509, "bad-multiple-constraint-cert.pem");
  3112. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3113. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3114. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3115. wolfSSL_X509_free(x509);
  3116. x509 = NULL;
  3117. /* check fail case when neither constraint is matched */
  3118. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3119. WOLFSSL_FILETYPE_PEM));
  3120. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3121. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3122. name = NULL;
  3123. ExpectNotNull(name = X509_NAME_new());
  3124. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3125. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3126. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3127. (byte*)"common", 6, -1, 0), SSL_SUCCESS);
  3128. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3129. X509_NAME_free(name);
  3130. wolfSSL_X509_add_altname(x509, "www.random.com", ASN_DNS_TYPE);
  3131. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3132. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3133. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3134. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3135. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3136. wolfSSL_CertManagerFree(cm);
  3137. wolfSSL_X509_free(x509);
  3138. wolfSSL_X509_free(ca);
  3139. wolfSSL_EVP_PKEY_free(priv);
  3140. #endif
  3141. return EXPECT_RESULT();
  3142. }
  3143. static int test_wolfSSL_CertManagerNameConstraint5(void)
  3144. {
  3145. EXPECT_DECLS;
  3146. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3147. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3148. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3149. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3150. !defined(NO_SHA256)
  3151. WOLFSSL_CERT_MANAGER* cm = NULL;
  3152. WOLFSSL_EVP_PKEY *priv = NULL;
  3153. WOLFSSL_X509_NAME* name = NULL;
  3154. const char* ca_cert = "./certs/test/cert-ext-ncmixed.der";
  3155. const char* server_cert = "./certs/test/server-goodcn.pem";
  3156. byte *der = NULL;
  3157. int derSz;
  3158. byte *pt;
  3159. WOLFSSL_X509 *x509 = NULL;
  3160. WOLFSSL_X509 *ca = NULL;
  3161. pt = (byte*)server_key_der_2048;
  3162. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3163. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3164. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3165. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3166. WOLFSSL_FILETYPE_ASN1));
  3167. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3168. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3169. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3170. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3171. /* check satisfying wolfssl.com constraint passes */
  3172. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3173. WOLFSSL_FILETYPE_PEM));
  3174. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3175. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3176. name = NULL;
  3177. ExpectNotNull(name = X509_NAME_new());
  3178. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3179. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3180. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3181. (byte*)"example", 7, -1, 0), SSL_SUCCESS);
  3182. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3183. X509_NAME_free(name);
  3184. name = NULL;
  3185. wolfSSL_X509_add_altname(x509, "good.example", ASN_DNS_TYPE);
  3186. wolfSSL_X509_add_altname(x509, "facts@into.wolfssl.com", ASN_RFC822_TYPE);
  3187. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3188. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  3189. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3190. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3191. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3192. wolfSSL_X509_free(x509);
  3193. x509 = NULL;
  3194. /* fail with DNS check because of common name */
  3195. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3196. WOLFSSL_FILETYPE_PEM));
  3197. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3198. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3199. name = NULL;
  3200. ExpectNotNull(name = X509_NAME_new());
  3201. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3202. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3203. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3204. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3205. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3206. X509_NAME_free(name);
  3207. name = NULL;
  3208. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3209. wolfSSL_X509_add_altname(x509, "facts@wolfssl.com", ASN_RFC822_TYPE);
  3210. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3211. DEBUG_WRITE_CERT_X509(x509, "bad-cn-cert.pem");
  3212. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3213. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3214. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3215. wolfSSL_X509_free(x509);
  3216. x509 = NULL;
  3217. /* fail on permitted DNS name constraint */
  3218. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3219. WOLFSSL_FILETYPE_PEM));
  3220. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3221. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3222. name = NULL;
  3223. ExpectNotNull(name = X509_NAME_new());
  3224. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3225. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3226. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3227. X509_NAME_free(name);
  3228. name = NULL;
  3229. wolfSSL_X509_add_altname(x509, "www.example", ASN_DNS_TYPE);
  3230. wolfSSL_X509_add_altname(x509, "www.wolfssl", ASN_DNS_TYPE);
  3231. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3232. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3233. DEBUG_WRITE_CERT_X509(x509, "bad-1st-constraint-cert.pem");
  3234. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3235. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3236. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3237. wolfSSL_X509_free(x509);
  3238. x509 = NULL;
  3239. /* fail on permitted email name constraint */
  3240. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3241. WOLFSSL_FILETYPE_PEM));
  3242. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3243. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3244. name = NULL;
  3245. ExpectNotNull(name = X509_NAME_new());
  3246. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3247. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3248. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3249. X509_NAME_free(name);
  3250. name = NULL;
  3251. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3252. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3253. wolfSSL_X509_add_altname(x509, "info@example.com", ASN_RFC822_TYPE);
  3254. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3255. DEBUG_WRITE_CERT_X509(x509, "bad-2nd-constraint-cert.pem");
  3256. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3257. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3258. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3259. wolfSSL_X509_free(x509);
  3260. x509 = NULL;
  3261. /* success with empty email name */
  3262. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3263. WOLFSSL_FILETYPE_PEM));
  3264. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3265. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3266. name = NULL;
  3267. ExpectNotNull(name = X509_NAME_new());
  3268. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3269. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3270. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3271. X509_NAME_free(name);
  3272. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3273. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3274. DEBUG_WRITE_CERT_X509(x509, "good-missing-constraint-cert.pem");
  3275. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3276. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3277. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3278. wolfSSL_X509_free(x509);
  3279. wolfSSL_CertManagerFree(cm);
  3280. wolfSSL_X509_free(ca);
  3281. wolfSSL_EVP_PKEY_free(priv);
  3282. #endif
  3283. return EXPECT_RESULT();
  3284. }
  3285. static int test_wolfSSL_CertManagerCRL(void)
  3286. {
  3287. EXPECT_DECLS;
  3288. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
  3289. !defined(NO_RSA)
  3290. const char* ca_cert = "./certs/ca-cert.pem";
  3291. const char* crl1 = "./certs/crl/crl.pem";
  3292. const char* crl2 = "./certs/crl/crl2.pem";
  3293. #ifdef WC_RSA_PSS
  3294. const char* crl_rsapss = "./certs/crl/crl_rsapss.pem";
  3295. const char* ca_rsapss = "./certs/rsapss/ca-rsapss.pem";
  3296. #endif
  3297. const unsigned char crl_buff[] = {
  3298. 0x30, 0x82, 0x02, 0x04, 0x30, 0x81, 0xed, 0x02,
  3299. 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  3300. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  3301. 0x00, 0x30, 0x81, 0x94, 0x31, 0x0b, 0x30, 0x09,
  3302. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  3303. 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  3304. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74,
  3305. 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e, 0x06,
  3306. 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  3307. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x11, 0x30,
  3308. 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08,
  3309. 0x53, 0x61, 0x77, 0x74, 0x6f, 0x6f, 0x74, 0x68,
  3310. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
  3311. 0x0b, 0x0c, 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x75,
  3312. 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30,
  3313. 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  3314. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66,
  3315. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x31,
  3316. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  3317. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10,
  3318. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  3319. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  3320. 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, 0x36,
  3321. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x17,
  3322. 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, 0x32,
  3323. 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, 0x14,
  3324. 0x30, 0x12, 0x02, 0x01, 0x02, 0x17, 0x0d, 0x32,
  3325. 0x32, 0x31, 0x32, 0x31, 0x36, 0x32, 0x31, 0x31,
  3326. 0x37, 0x35, 0x30, 0x5a, 0xa0, 0x0e, 0x30, 0x0c,
  3327. 0x30, 0x0a, 0x06, 0x03, 0x55, 0x1d, 0x14, 0x04,
  3328. 0x03, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09,
  3329. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  3330. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
  3331. 0x39, 0x44, 0xff, 0x39, 0xf4, 0x04, 0x45, 0x79,
  3332. 0x7e, 0x73, 0xe2, 0x42, 0x48, 0xdb, 0x85, 0x66,
  3333. 0xfd, 0x99, 0x76, 0x94, 0x7c, 0xb5, 0x79, 0x5d,
  3334. 0x15, 0x71, 0x36, 0xa9, 0x87, 0xf0, 0x73, 0x05,
  3335. 0x50, 0x08, 0x6b, 0x1c, 0x6e, 0xde, 0x96, 0x45,
  3336. 0x31, 0xc3, 0xc0, 0xba, 0xba, 0xf5, 0x08, 0x1d,
  3337. 0x05, 0x4a, 0x52, 0x39, 0xe9, 0x03, 0xef, 0x59,
  3338. 0xc8, 0x1d, 0x4a, 0xf2, 0x86, 0x05, 0x99, 0x7b,
  3339. 0x4b, 0x74, 0xf6, 0xd3, 0x75, 0x8d, 0xb2, 0x57,
  3340. 0xba, 0xac, 0xa7, 0x11, 0x14, 0xd6, 0x6c, 0x71,
  3341. 0xc4, 0x4c, 0x1c, 0x68, 0xbc, 0x49, 0x78, 0xf0,
  3342. 0xc9, 0x52, 0x8a, 0xe7, 0x8b, 0x54, 0xe6, 0x20,
  3343. 0x58, 0x20, 0x60, 0x66, 0xf5, 0x14, 0xd8, 0xcb,
  3344. 0xff, 0xe0, 0xa0, 0x45, 0xbc, 0xb4, 0x81, 0xad,
  3345. 0x1d, 0xbc, 0xcf, 0xf8, 0x8e, 0xa8, 0x87, 0x24,
  3346. 0x55, 0x99, 0xd9, 0xce, 0x47, 0xf7, 0x5b, 0x4a,
  3347. 0x33, 0x6d, 0xdb, 0xbf, 0x93, 0x64, 0x1a, 0xa6,
  3348. 0x46, 0x5f, 0x27, 0xdc, 0xd8, 0xd4, 0xf9, 0xc2,
  3349. 0x42, 0x2a, 0x7e, 0xb2, 0x7c, 0xdd, 0x98, 0x77,
  3350. 0xf5, 0x88, 0x7d, 0x15, 0x25, 0x08, 0xbc, 0xe0,
  3351. 0xd0, 0x8d, 0xf4, 0xc3, 0xc3, 0x04, 0x41, 0xa4,
  3352. 0xd1, 0xb1, 0x39, 0x4a, 0x6b, 0x2c, 0xb5, 0x2e,
  3353. 0x9a, 0x65, 0x43, 0x0d, 0x0e, 0x73, 0xf4, 0x06,
  3354. 0xe1, 0xb3, 0x49, 0x34, 0x94, 0xb0, 0xb7, 0xff,
  3355. 0xc0, 0x27, 0xc1, 0xb5, 0xea, 0x06, 0xf7, 0x71,
  3356. 0x71, 0x97, 0xbb, 0xbc, 0xc7, 0x1a, 0x9f, 0xeb,
  3357. 0xf6, 0x3d, 0xa5, 0x7b, 0x55, 0xa7, 0xbf, 0xdd,
  3358. 0xd7, 0xee, 0x97, 0xb8, 0x9d, 0xdc, 0xcd, 0xe3,
  3359. 0x06, 0xdb, 0x9a, 0x2c, 0x60, 0xbf, 0x70, 0x84,
  3360. 0xfa, 0x6b, 0x8d, 0x70, 0x7d, 0xde, 0xe8, 0xb7,
  3361. 0xab, 0xb0, 0x38, 0x68, 0x6c, 0xc0, 0xb1, 0xe1,
  3362. 0xba, 0x45, 0xe0, 0xd7, 0x12, 0x3d, 0x71, 0x5b
  3363. };
  3364. WOLFSSL_CERT_MANAGER* cm = NULL;
  3365. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3366. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3367. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3368. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1);
  3369. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm,
  3370. WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1);
  3371. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1);
  3372. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3373. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3374. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3375. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1),
  3376. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3377. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3378. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1),
  3379. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3380. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3381. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1),
  3382. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3383. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3384. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3385. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3386. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1);
  3387. #ifdef HAVE_CRL_IO
  3388. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3389. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  3390. #endif
  3391. #ifndef NO_FILESYSTEM
  3392. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1,
  3393. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3394. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1,
  3395. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3396. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3397. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1);
  3398. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL,
  3399. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3400. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  3401. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3402. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3403. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1),
  3404. WC_NO_ERR_TRACE(ASN_PARSE_E));
  3405. #endif
  3406. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1,
  3407. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3408. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1,
  3409. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3410. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1,
  3411. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3412. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, 1,
  3413. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3414. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, 1,
  3415. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3416. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, 1,
  3417. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3418. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1,
  3419. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3420. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3421. DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  3422. ExpectIntEQ(WOLFSSL_SUCCESS,
  3423. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3424. ExpectIntEQ(WOLFSSL_SUCCESS,
  3425. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3426. ExpectIntEQ(WOLFSSL_SUCCESS,
  3427. wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0));
  3428. wolfSSL_CertManagerFreeCRL(cm);
  3429. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  3430. ExpectIntEQ(WOLFSSL_SUCCESS,
  3431. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3432. ExpectIntEQ(WOLFSSL_SUCCESS,
  3433. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3434. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3435. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING));
  3436. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048,
  3437. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(CRL_MISSING));
  3438. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  3439. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff),
  3440. WOLFSSL_FILETYPE_ASN1), 1);
  3441. #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS)
  3442. /* loading should fail without the CA set */
  3443. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3444. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E));
  3445. /* now successfully load the RSA-PSS crl once loading in it's CA */
  3446. ExpectIntEQ(WOLFSSL_SUCCESS,
  3447. wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL));
  3448. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3449. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  3450. #endif
  3451. wolfSSL_CertManagerFree(cm);
  3452. #endif
  3453. return EXPECT_RESULT();
  3454. }
  3455. static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
  3456. {
  3457. EXPECT_DECLS;
  3458. #if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA)
  3459. /* Need one of these for wolfSSL_OCSP_REQUEST_new. */
  3460. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  3461. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
  3462. defined(HAVE_LIGHTY)
  3463. WOLFSSL_CERT_MANAGER* cm = NULL;
  3464. /* Raw OCSP response bytes captured using the following setup:
  3465. * - Run responder with
  3466. * openssl ocsp -port 9999 -ndays 9999
  3467. * -index certs/ocsp/index-intermediate1-ca-issued-certs.txt
  3468. * -rsigner certs/ocsp/ocsp-responder-cert.pem
  3469. * -rkey certs/ocsp/ocsp-responder-key.pem
  3470. * -CA certs/ocsp/intermediate1-ca-cert.pem
  3471. * - Run client with
  3472. * openssl ocsp -host 127.0.0.1:9999 -respout resp.out
  3473. * -issuer certs/ocsp/intermediate1-ca-cert.pem
  3474. * -cert certs/ocsp/server1-cert.pem
  3475. * -CAfile certs/ocsp/root-ca-cert.pem -noverify
  3476. * - Select the response packet in Wireshark, and export it using
  3477. * "File->Export Packet Dissection->As "C" Arrays". Select "Selected
  3478. * packets only". After importing into the editor, remove the initial
  3479. * ~148 bytes of header, ending with the Content-Length and the \r\n\r\n.
  3480. */
  3481. static const byte response[] = {
  3482. 0x30, 0x82, 0x07, 0x40, /* ....0..@ */
  3483. 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x39, 0x30, /* ......90 */
  3484. 0x82, 0x07, 0x35, 0x06, 0x09, 0x2b, 0x06, 0x01, /* ..5..+.. */
  3485. 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, /* ...0.... */
  3486. 0x07, 0x26, 0x30, 0x82, 0x07, 0x22, 0x30, 0x82, /* .&0.."0. */
  3487. 0x01, 0x40, 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, /* .@...0.. */
  3488. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3489. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3490. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3491. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3492. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3493. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3494. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3495. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3496. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3497. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3498. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3499. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, /* ring1.0. */
  3500. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x77, /* ..U....w */
  3501. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, /* olfSSL O */
  3502. 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, /* CSP Resp */
  3503. 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f, 0x30, /* onder1.0 */
  3504. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, /* ...*.H.. */
  3505. 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, /* ......in */
  3506. 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, /* fo@wolfs */
  3507. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, /* sl.com.. */
  3508. 0x32, 0x30, 0x32, 0x33, 0x31, 0x31, 0x30, 0x38, /* 20231108 */
  3509. 0x30, 0x30, 0x32, 0x36, 0x33, 0x37, 0x5a, 0x30, /* 002637Z0 */
  3510. 0x64, 0x30, 0x62, 0x30, 0x3a, 0x30, 0x09, 0x06, /* d0b0:0.. */
  3511. 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, /* .+...... */
  3512. 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, /* ..qM.#@Y */
  3513. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, /* ...7C.1. */
  3514. 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04, 0x04, 0x14, /* ..C..... */
  3515. 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, /* ..:.,... */
  3516. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, /* ..L.*.q. */
  3517. 0x64, 0x44, 0xda, 0x0e, 0x02, 0x01, 0x05, 0x80, /* dD...... */
  3518. 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x33, 0x31, /* ...20231 */
  3519. 0x31, 0x30, 0x38, 0x30, 0x30, 0x32, 0x36, 0x33, /* 10800263 */
  3520. 0x37, 0x5a, 0xa0, 0x11, 0x18, 0x0f, 0x32, 0x30, /* 7Z....20 */
  3521. 0x35, 0x31, 0x30, 0x33, 0x32, 0x35, 0x30, 0x30, /* 51032500 */
  3522. 0x32, 0x36, 0x33, 0x37, 0x5a, 0xa1, 0x23, 0x30, /* 2637Z.#0 */
  3523. 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2b, 0x06, 0x01, /* !0...+.. */
  3524. 0x05, 0x05, 0x07, 0x30, 0x01, 0x02, 0x04, 0x12, /* ...0.... */
  3525. 0x04, 0x10, 0xdb, 0xbc, 0x2a, 0x76, 0xa0, 0xb4, /* ....*v.. */
  3526. 0x1e, 0x5d, 0xf6, 0x2b, 0x8e, 0x38, 0x62, 0xdb, /* .].+.8b. */
  3527. 0x90, 0xed, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, /* ..0...*. */
  3528. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, /* H....... */
  3529. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x87, 0xde, /* ........ */
  3530. 0xfb, 0xf9, 0x3a, 0x90, 0x1f, 0x90, 0xde, 0xcf, /* ..:..... */
  3531. 0xfe, 0xad, 0x64, 0x19, 0x34, 0x17, 0xf8, 0x15, /* ..d.4... */
  3532. 0x01, 0x22, 0x5f, 0x67, 0x41, 0xa4, 0x18, 0xf7, /* ."_gA... */
  3533. 0x16, 0xb7, 0xc9, 0xf3, 0xe1, 0x9f, 0xcd, 0x40, /* .......@ */
  3534. 0x56, 0x77, 0x6e, 0x6a, 0xfb, 0x92, 0x6a, 0x6f, /* Vwnj..jo */
  3535. 0x28, 0x3e, 0x22, 0x48, 0xa1, 0xc2, 0xd8, 0x1d, /* (>"H.... */
  3536. 0xc7, 0xe6, 0x78, 0x7f, 0xb6, 0x09, 0xfe, 0x2c, /* ..x...., */
  3537. 0xb5, 0xef, 0x29, 0x7c, 0xc5, 0x51, 0x16, 0x7b, /* ..)|.Q.{ */
  3538. 0x8f, 0xfb, 0x44, 0xa8, 0xcd, 0xf5, 0x5c, 0x0f, /* ..D...\. */
  3539. 0x46, 0x0e, 0xb1, 0xa4, 0xeb, 0x5b, 0xf5, 0x86, /* F....[.. */
  3540. 0x11, 0x0f, 0xcd, 0xe2, 0xe5, 0x3c, 0x91, 0x72, /* .....<.r */
  3541. 0x0d, 0x6a, 0xcb, 0x95, 0x99, 0x39, 0x91, 0x48, /* .j...9.H */
  3542. 0x65, 0x97, 0xb9, 0x78, 0xb5, 0x88, 0x7f, 0x76, /* e..x...v */
  3543. 0xa1, 0x43, 0x2f, 0xf6, 0x1f, 0x49, 0xb7, 0x08, /* .C/..I.. */
  3544. 0x36, 0xe4, 0x2e, 0x34, 0x25, 0xda, 0x16, 0x74, /* 6..4%..t */
  3545. 0x47, 0x62, 0x56, 0xff, 0x2f, 0x02, 0x03, 0x44, /* GbV./..D */
  3546. 0x89, 0x04, 0xe7, 0xb8, 0xde, 0x0a, 0x35, 0x43, /* ......5C */
  3547. 0xae, 0xd7, 0x54, 0xbe, 0xc3, 0x7c, 0x95, 0xa5, /* ..T..|.. */
  3548. 0xc8, 0xe0, 0x2e, 0x52, 0xb6, 0xea, 0x99, 0x45, /* ...R...E */
  3549. 0xfd, 0xda, 0x4b, 0xd5, 0x79, 0x07, 0x64, 0xca, /* ..K.y.d. */
  3550. 0x64, 0xba, 0x52, 0x12, 0x62, 0x8c, 0x08, 0x9a, /* d.R.b... */
  3551. 0x32, 0xeb, 0x85, 0x65, 0x05, 0x39, 0x07, 0x5d, /* 2..e.9.] */
  3552. 0x39, 0x4a, 0xcf, 0xa5, 0x30, 0xf6, 0xd1, 0xf7, /* 9J..0... */
  3553. 0x29, 0xaa, 0x23, 0x42, 0xc6, 0x85, 0x16, 0x7f, /* ).#B.... */
  3554. 0x64, 0x16, 0xb1, 0xb0, 0x5d, 0xcd, 0x88, 0x2d, /* d...]..- */
  3555. 0x06, 0xb0, 0xa9, 0xdf, 0xa3, 0x9f, 0x25, 0x41, /* ......%A */
  3556. 0x89, 0x9a, 0x19, 0xe1, 0xaa, 0xcd, 0xdf, 0x51, /* .......Q */
  3557. 0xcb, 0xa9, 0xc3, 0x7e, 0x27, 0xbc, 0x7d, 0x9b, /* ...~'.}. */
  3558. 0x6f, 0x4d, 0x79, 0x87, 0x09, 0x3f, 0xac, 0xd2, /* oMy..?.. */
  3559. 0x4a, 0x3b, 0xbe, 0xf8, 0x7a, 0xa4, 0x93, 0x45, /* J;..z..E */
  3560. 0x11, 0x64, 0x40, 0xc5, 0x03, 0xc9, 0x24, 0x5b, /* .d@...$[ */
  3561. 0xe9, 0x6d, 0xfc, 0x94, 0x08, 0xbe, 0xa0, 0x82, /* .m...... */
  3562. 0x04, 0xc6, 0x30, 0x82, 0x04, 0xc2, 0x30, 0x82, /* ..0...0. */
  3563. 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, /* ..0..... */
  3564. 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, /* ......0. */
  3565. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, /* ..*.H... */
  3566. 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, /* .....0.. */
  3567. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3568. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3569. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3570. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3571. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3572. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3573. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3574. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3575. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3576. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3577. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3578. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, /* ring1.0. */
  3579. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, /* ..U....w */
  3580. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x72, /* olfSSL r */
  3581. 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, /* oot CA1. */
  3582. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, /* 0...*.H. */
  3583. 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, /* .......i */
  3584. 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, /* nfo@wolf */
  3585. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, /* ssl.com0 */
  3586. 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, /* ...22121 */
  3587. 0x36, 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, /* 6211750Z */
  3588. 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, /* ..250911 */
  3589. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, /* 211750Z0 */
  3590. 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, /* ..1.0... */
  3591. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, /* U....US1 */
  3592. 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, /* .0...U.. */
  3593. 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, /* ..Washin */
  3594. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, /* gton1.0. */
  3595. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, /* ..U....S */
  3596. 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, /* eattle1. */
  3597. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, /* 0...U... */
  3598. 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3599. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3600. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, /* ...Engin */
  3601. 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, /* eering1. */
  3602. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, /* 0...U... */
  3603. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3604. 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, /* OCSP Re */
  3605. 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, /* sponder1 */
  3606. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, /* .0...*.H */
  3607. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, /* ........ */
  3608. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, /* info@wol */
  3609. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, /* fssl.com */
  3610. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, /* 0.."0... */
  3611. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3612. 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, /* ........ */
  3613. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, /* 0....... */
  3614. 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, /* ...#...{ */
  3615. 0x14, 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, /* .....a.. */
  3616. 0x1e, 0x63, 0xb9, 0x85, 0x23, 0x34, 0x50, 0x6d, /* .c..#4Pm */
  3617. 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, /* .|.....u */
  3618. 0x5c, 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, /* \-.c...z */
  3619. 0xea, 0x0b, 0x45, 0x35, 0x2b, 0xeb, 0x1f, 0xb1, /* ..E5+... */
  3620. 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, /* "..A8..t */
  3621. 0xd6, 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, /* ..0".Q.. */
  3622. 0xca, 0x3f, 0x46, 0x2b, 0xfe, 0xe5, 0x5a, 0x3f, /* .?F+..Z? */
  3623. 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, /* Atgu.... */
  3624. 0xc3, 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, /* ..B..... */
  3625. 0xe1, 0xd9, 0x65, 0xb7, 0x43, 0xc4, 0x18, 0xde, /* ..e.C... */
  3626. 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, /* ....$5!. */
  3627. 0x55, 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, /* U.ZQ..-. */
  3628. 0x0a, 0x5a, 0x4f, 0x4a, 0x73, 0x31, 0x50, 0xee, /* .ZOJs1P. */
  3629. 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, /* J..9...H */
  3630. 0x87, 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, /* .......r */
  3631. 0x67, 0xca, 0x5c, 0xd1, 0x97, 0xbd, 0xc8, 0xf1, /* g.\..... */
  3632. 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, /* v..J.... */
  3633. 0x66, 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, /* fL(q..f. */
  3634. 0xb4, 0x90, 0x30, 0xbb, 0x17, 0xb0, 0xfe, 0x97, /* ..0..... */
  3635. 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, /* ....]... */
  3636. 0x19, 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, /* ..<..qx. */
  3637. 0xae, 0x3f, 0x32, 0xb2, 0x08, 0x71, 0xb2, 0x1b, /* .?2..q.. */
  3638. 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, /* .'....CI */
  3639. 0xcf, 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, /* ..p..... */
  3640. 0x24, 0x87, 0x17, 0x3b, 0xd8, 0x04, 0x65, 0x6c, /* $..;..el */
  3641. 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, /* .vP..... */
  3642. 0x73, 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, /* sh&...._ */
  3643. 0x6e, 0x61, 0xb8, 0x87, 0x84, 0xfa, 0x80, 0x1a, /* na...... */
  3644. 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, /* ......ND */
  3645. 0x1c, 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, /* .et|qTe. */
  3646. 0x39, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, /* 9....... */
  3647. 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, /* ..0...0. */
  3648. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, /* ..U....0 */
  3649. 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, /* .0...U.. */
  3650. 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, /* ....2g.. */
  3651. 0x79, 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, /* y....#.p */
  3652. 0x40, 0x50, 0xb5, 0x46, 0x56, 0xb8, 0x30, 0x36, /* @P.FV.06 */
  3653. 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, /* 0....U.# */
  3654. 0x04, 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, /* ...0.... */
  3655. 0x73, 0xb0, 0x1c, 0xa4, 0x2f, 0x82, 0xcb, 0xcf, /* s.../... */
  3656. 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, /* G.8....: */
  3657. 0x7e, 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, /* ~r.!.... */
  3658. 0x81, 0x9a, 0x30, 0x81, 0x97, 0x31, 0x0b, 0x30, /* ..0..1.0 */
  3659. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, /* ...U.... */
  3660. 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, /* US1.0... */
  3661. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, /* U....Was */
  3662. 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, /* hington1 */
  3663. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, /* .0...U.. */
  3664. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, /* ..Seattl */
  3665. 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, /* e1.0...U */
  3666. 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3667. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, /* SSL1.0.. */
  3668. 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, /* .U....En */
  3669. 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, /* gineerin */
  3670. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, /* g1.0...U */
  3671. 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3672. 0x53, 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, /* SSL root */
  3673. 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30, 0x1d, 0x06, /* CA1.0.. */
  3674. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, /* .*.H.... */
  3675. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, /* ....info */
  3676. 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, /* @wolfssl */
  3677. 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, /* .com..c0 */
  3678. 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, /* ...U.%.. */
  3679. 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, /* 0...+... */
  3680. 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, /* ....0... */
  3681. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3682. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, /* ........ */
  3683. 0x2f, 0xb7, 0x6b, 0xec, 0xb7, 0x12, 0x63, 0xb9, /* /.k...c. */
  3684. 0x57, 0xdc, 0x04, 0x4d, 0x9c, 0x67, 0x74, 0x98, /* W..M.gt. */
  3685. 0x06, 0x28, 0x68, 0x37, 0x34, 0xc2, 0x50, 0xe9, /* .(h74.P. */
  3686. 0x2a, 0xd4, 0x1a, 0xb2, 0x32, 0x1a, 0x9d, 0x2b, /* *...2..+ */
  3687. 0x4f, 0x23, 0x50, 0xea, 0xb4, 0x95, 0x86, 0xc3, /* O#P..... */
  3688. 0xb9, 0x5f, 0x34, 0x3e, 0x99, 0x91, 0xa7, 0x80, /* ._4>.... */
  3689. 0x5f, 0x6e, 0x1b, 0x6e, 0xdb, 0xe9, 0x02, 0x38, /* _n.n...8 */
  3690. 0x6f, 0xdf, 0xc5, 0x9b, 0x0d, 0xa3, 0x1c, 0xa9, /* o....... */
  3691. 0x15, 0x76, 0x16, 0x66, 0xa8, 0x4e, 0xfb, 0xd3, /* .v.f.N.. */
  3692. 0x43, 0x76, 0xf1, 0x72, 0xb7, 0xd1, 0xfa, 0xee, /* Cv.r.... */
  3693. 0x39, 0xa6, 0x96, 0xc1, 0xa2, 0x93, 0xa4, 0x9b, /* 9....... */
  3694. 0x1e, 0x9f, 0xba, 0x71, 0x8f, 0xba, 0xbd, 0x67, /* ...q...g */
  3695. 0x6a, 0xf2, 0x15, 0x5f, 0xf1, 0x64, 0xe7, 0xcf, /* j.._.d.. */
  3696. 0x26, 0xb8, 0x4c, 0xc0, 0xeb, 0x85, 0x04, 0x58, /* &.L....X */
  3697. 0xd9, 0x4a, 0x6b, 0xd9, 0x86, 0xf5, 0x80, 0x21, /* .Jk....! */
  3698. 0xbf, 0x91, 0xc8, 0x4b, 0x9f, 0x04, 0xed, 0x57, /* ...K...W */
  3699. 0x7a, 0xd2, 0x58, 0xac, 0x5b, 0x47, 0xaf, 0x4d, /* z.X.[G.M */
  3700. 0x7f, 0x5b, 0x1d, 0x6d, 0x68, 0x9b, 0x84, 0x98, /* .[.mh... */
  3701. 0x2a, 0x31, 0x02, 0x2c, 0xe9, 0x1b, 0xaf, 0x11, /* *1.,.... */
  3702. 0x0b, 0x78, 0x49, 0xbe, 0x68, 0x68, 0xcb, 0x9c, /* .xI.hh.. */
  3703. 0x41, 0x56, 0xe8, 0xb5, 0x59, 0xda, 0xff, 0xca, /* AV..Y... */
  3704. 0x59, 0x99, 0x17, 0x3e, 0x11, 0x0a, 0x8f, 0x49, /* Y..>...I */
  3705. 0x24, 0x0b, 0x81, 0x42, 0x63, 0xcd, 0x4f, 0xf6, /* $..Bc.O. */
  3706. 0x2b, 0x9d, 0xd1, 0x79, 0x75, 0xd7, 0x4a, 0xcc, /* +..yu.J. */
  3707. 0x4c, 0xb7, 0x2b, 0xd7, 0xe8, 0xe7, 0xd4, 0x48, /* L.+....H */
  3708. 0x3c, 0x14, 0x3b, 0x1c, 0x28, 0xe8, 0x46, 0x7a, /* <.;.(.Fz */
  3709. 0xdc, 0x11, 0x9d, 0x7f, 0x1c, 0xab, 0x10, 0x95, /* ........ */
  3710. 0x17, 0xb2, 0xc7, 0x7a, 0xbb, 0x17, 0x44, 0x59, /* ...z..DY */
  3711. 0x69, 0x8e, 0x16, 0x05, 0x94, 0x8c, 0x88, 0xd9, /* i....... */
  3712. 0xdc, 0x9a, 0xfd, 0xf2, 0x93, 0xbe, 0x68, 0xba, /* ......h. */
  3713. 0x3c, 0xd6, 0x2b, 0x61, 0x3a, 0x8b, 0xf7, 0x66, /* <.+a:..f */
  3714. 0xcb, 0x54, 0xe8, 0xe4, 0xdb, 0x9f, 0xcc, 0x9e /* .T...... */
  3715. };
  3716. OcspEntry entry[1];
  3717. CertStatus status[1];
  3718. OcspRequest* request = NULL;
  3719. #ifndef NO_FILESYSTEM
  3720. const char* ca_cert = "./certs/ca-cert.pem";
  3721. #endif
  3722. byte serial[] = {0x05};
  3723. byte issuerHash[] = {0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04};
  3724. byte issuerKeyHash[] = {0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e};
  3725. XMEMSET(entry, 0, sizeof(OcspEntry));
  3726. XMEMSET(status, 0, sizeof(CertStatus));
  3727. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3728. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3729. DYNAMIC_TYPE_OCSP_REQUEST));
  3730. if ((request != NULL) && (request->serial != NULL)) {
  3731. request->serialSz = sizeof(serial);
  3732. XMEMCPY(request->serial, serial, sizeof(serial));
  3733. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3734. XMEMCPY(request->issuerKeyHash, issuerKeyHash, sizeof(issuerKeyHash));
  3735. }
  3736. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3737. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3738. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm,
  3739. "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  3740. /* Response should be valid. */
  3741. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3742. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3743. /* Flip a byte in the request serial number, response should be invalid
  3744. * now. */
  3745. if ((request != NULL) && (request->serial != NULL))
  3746. request->serial[0] ^= request->serial[0];
  3747. ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3748. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3749. #ifndef NO_FILESYSTEM
  3750. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3751. sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3752. ExpectIntEQ(WOLFSSL_SUCCESS,
  3753. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3754. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3755. sizeof(server_cert_der_2048)), 1);
  3756. #endif
  3757. wolfSSL_OCSP_REQUEST_free(request);
  3758. wolfSSL_CertManagerFree(cm);
  3759. #endif /* OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY ||
  3760. * WOLFSSL_APACHE_HTTPD || HAVE_LIGHTY */
  3761. #endif /* HAVE_OCSP */
  3762. return EXPECT_RESULT();
  3763. }
  3764. static int test_wolfSSL_CheckOCSPResponse(void)
  3765. {
  3766. EXPECT_DECLS;
  3767. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  3768. !defined(NO_RSA) && !defined(NO_SHA)
  3769. const char* responseFile = "./certs/ocsp/test-response.der";
  3770. const char* responseMultiFile = "./certs/ocsp/test-multi-response.der";
  3771. const char* responseNoInternFile =
  3772. "./certs/ocsp/test-response-nointern.der";
  3773. const char* caFile = "./certs/ocsp/root-ca-cert.pem";
  3774. OcspResponse* res = NULL;
  3775. byte data[4096];
  3776. const unsigned char* pt;
  3777. int dataSz = 0; /* initialize to mitigate spurious maybe-uninitialized from
  3778. * gcc sanitizer with --enable-heapmath.
  3779. */
  3780. XFILE f = XBADFILE;
  3781. WOLFSSL_OCSP_BASICRESP* bs = NULL;
  3782. WOLFSSL_X509_STORE* st = NULL;
  3783. WOLFSSL_X509* issuer = NULL;
  3784. ExpectTrue((f = XFOPEN(responseFile, "rb")) != XBADFILE);
  3785. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3786. if (f != XBADFILE) {
  3787. XFCLOSE(f);
  3788. f = XBADFILE;
  3789. }
  3790. pt = data;
  3791. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  3792. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  3793. SSL_FILETYPE_PEM));
  3794. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  3795. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  3796. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  3797. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0), WOLFSSL_SUCCESS);
  3798. wolfSSL_OCSP_BASICRESP_free(bs);
  3799. bs = NULL;
  3800. wolfSSL_OCSP_RESPONSE_free(res);
  3801. res = NULL;
  3802. wolfSSL_X509_STORE_free(st);
  3803. st = NULL;
  3804. wolfSSL_X509_free(issuer);
  3805. issuer = NULL;
  3806. /* check loading a response with optional certs */
  3807. ExpectTrue((f = XFOPEN(responseNoInternFile, "rb")) != XBADFILE);
  3808. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3809. if (f != XBADFILE)
  3810. XFCLOSE(f);
  3811. f = XBADFILE;
  3812. pt = data;
  3813. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  3814. wolfSSL_OCSP_RESPONSE_free(res);
  3815. res = NULL;
  3816. /* check loading a response with multiple certs */
  3817. {
  3818. WOLFSSL_CERT_MANAGER* cm = NULL;
  3819. OcspEntry *entry = NULL;
  3820. CertStatus* status = NULL;
  3821. OcspRequest* request = NULL;
  3822. byte serial1[] = {0x01};
  3823. byte serial[] = {0x02};
  3824. byte issuerHash[] = {
  3825. 0x44, 0xA8, 0xDB, 0xD1, 0xBC, 0x97, 0x0A, 0x83,
  3826. 0x3B, 0x5B, 0x31, 0x9A, 0x4C, 0xB8, 0xD2, 0x52,
  3827. 0x37, 0x15, 0x8A, 0x88
  3828. };
  3829. byte issuerKeyHash[] = {
  3830. 0x73, 0xB0, 0x1C, 0xA4, 0x2F, 0x82, 0xCB, 0xCF,
  3831. 0x47, 0xA5, 0x38, 0xD7, 0xB0, 0x04, 0x82, 0x3A,
  3832. 0x7E, 0x72, 0x15, 0x21
  3833. };
  3834. ExpectNotNull(entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL,
  3835. DYNAMIC_TYPE_OPENSSL));
  3836. ExpectNotNull(status = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL,
  3837. DYNAMIC_TYPE_OPENSSL));
  3838. if (entry != NULL)
  3839. XMEMSET(entry, 0, sizeof(OcspEntry));
  3840. if (status != NULL)
  3841. XMEMSET(status, 0, sizeof(CertStatus));
  3842. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3843. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3844. DYNAMIC_TYPE_OCSP_REQUEST));
  3845. if (request != NULL && request->serial != NULL) {
  3846. request->serialSz = sizeof(serial);
  3847. XMEMCPY(request->serial, serial, sizeof(serial));
  3848. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3849. XMEMCPY(request->issuerKeyHash, issuerKeyHash,
  3850. sizeof(issuerKeyHash));
  3851. }
  3852. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3853. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3854. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caFile, NULL),
  3855. WOLFSSL_SUCCESS);
  3856. ExpectTrue((f = XFOPEN(responseMultiFile, "rb")) != XBADFILE);
  3857. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3858. if (f != XBADFILE)
  3859. XFCLOSE(f);
  3860. f = XBADFILE;
  3861. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3862. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  3863. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3864. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  3865. ExpectNotNull(entry->status);
  3866. if (request != NULL && request->serial != NULL)
  3867. XMEMCPY(request->serial, serial1, sizeof(serial1));
  3868. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3869. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  3870. /* store both status's in the entry to check that "next" is not
  3871. * overwritten */
  3872. if (EXPECT_SUCCESS() && status != NULL && entry != NULL) {
  3873. status->next = entry->status;
  3874. entry->status = status;
  3875. }
  3876. if (request != NULL && request->serial != NULL)
  3877. XMEMCPY(request->serial, serial, sizeof(serial));
  3878. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3879. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  3880. ExpectNotNull(entry->status->next);
  3881. /* compare the status found */
  3882. ExpectIntEQ(status->serialSz, entry->status->serialSz);
  3883. ExpectIntEQ(XMEMCMP(status->serial, entry->status->serial,
  3884. status->serialSz), 0);
  3885. if (status != NULL && entry != NULL && entry->status != status) {
  3886. XFREE(status, NULL, DYNAMIC_TYPE_OPENSSL);
  3887. }
  3888. wolfSSL_OCSP_CERTID_free(entry);
  3889. wolfSSL_OCSP_REQUEST_free(request);
  3890. wolfSSL_CertManagerFree(cm);
  3891. }
  3892. #if defined(WC_RSA_PSS)
  3893. {
  3894. const char* responsePssFile = "./certs/ocsp/test-response-rsapss.der";
  3895. /* check loading a response with RSA-PSS signature */
  3896. ExpectTrue((f = XFOPEN(responsePssFile, "rb")) != XBADFILE);
  3897. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3898. if (f != XBADFILE)
  3899. XFCLOSE(f);
  3900. pt = data;
  3901. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  3902. /* try to verify the response */
  3903. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  3904. SSL_FILETYPE_PEM));
  3905. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  3906. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  3907. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  3908. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0),
  3909. WOLFSSL_SUCCESS);
  3910. wolfSSL_OCSP_BASICRESP_free(bs);
  3911. wolfSSL_OCSP_RESPONSE_free(res);
  3912. wolfSSL_X509_STORE_free(st);
  3913. wolfSSL_X509_free(issuer);
  3914. }
  3915. #endif
  3916. #endif /* HAVE_OCSP */
  3917. return EXPECT_RESULT();
  3918. }
  3919. static int test_wolfSSL_FPKI(void)
  3920. {
  3921. EXPECT_DECLS;
  3922. #if defined(WOLFSSL_FPKI) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  3923. XFILE f = XBADFILE;
  3924. const char* fpkiCert = "./certs/fpki-cert.der";
  3925. DecodedCert cert;
  3926. byte buf[4096];
  3927. byte* uuid = NULL;
  3928. byte* fascn = NULL;
  3929. word32 fascnSz;
  3930. word32 uuidSz;
  3931. int bytes = 0;
  3932. ExpectTrue((f = XFOPEN(fpkiCert, "rb")) != XBADFILE);
  3933. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  3934. if (f != XBADFILE)
  3935. XFCLOSE(f);
  3936. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  3937. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  3938. ExpectIntEQ(wc_GetFASCNFromCert(&cert, NULL, &fascnSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  3939. ExpectNotNull(fascn = (byte*)XMALLOC(fascnSz, NULL,
  3940. DYNAMIC_TYPE_TMP_BUFFER));
  3941. ExpectIntEQ(wc_GetFASCNFromCert(&cert, fascn, &fascnSz), 0);
  3942. XFREE(fascn, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  3943. ExpectIntEQ(wc_GetUUIDFromCert(&cert, NULL, &uuidSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  3944. ExpectNotNull(uuid = (byte*)XMALLOC(uuidSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  3945. ExpectIntEQ(wc_GetUUIDFromCert(&cert, uuid, &uuidSz), 0);
  3946. XFREE(uuid, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  3947. wc_FreeDecodedCert(&cert);
  3948. #endif
  3949. return EXPECT_RESULT();
  3950. }
  3951. /* use RID in confuncture with other names to test parsing of unknown other
  3952. * names */
  3953. static int test_wolfSSL_OtherName(void)
  3954. {
  3955. EXPECT_DECLS;
  3956. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  3957. XFILE f = XBADFILE;
  3958. const char* ridCert = "./certs/rid-cert.der";
  3959. DecodedCert cert;
  3960. byte buf[4096];
  3961. int bytes = 0;
  3962. ExpectTrue((f = XFOPEN(ridCert, "rb")) != XBADFILE);
  3963. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  3964. if (f != XBADFILE)
  3965. XFCLOSE(f);
  3966. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  3967. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  3968. wc_FreeDecodedCert(&cert);
  3969. #endif
  3970. return EXPECT_RESULT();
  3971. }
  3972. #ifdef HAVE_CERT_CHAIN_VALIDATION
  3973. static int test_wolfSSL_CertRsaPss(void)
  3974. {
  3975. EXPECT_DECLS;
  3976. /* FIPS v2 and below don't support long salts. */
  3977. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && \
  3978. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  3979. (HAVE_FIPS_VERSION > 2))) && (!defined(HAVE_SELFTEST) || \
  3980. (defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION > 2)))
  3981. XFILE f = XBADFILE;
  3982. const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der";
  3983. const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem";
  3984. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  3985. RSA_MAX_SIZE >= 3072
  3986. const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der";
  3987. #endif
  3988. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  3989. const char* rsaPssRootSha384Cert = "./certs/rsapss/root-3072-rsapss.pem";
  3990. #endif
  3991. DecodedCert cert;
  3992. byte buf[4096];
  3993. int bytes = 0;
  3994. WOLFSSL_CERT_MANAGER* cm = NULL;
  3995. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3996. ExpectIntEQ(WOLFSSL_SUCCESS,
  3997. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL));
  3998. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  3999. ExpectIntEQ(WOLFSSL_SUCCESS,
  4000. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL));
  4001. #endif
  4002. ExpectTrue((f = XFOPEN(rsaPssSha256Cert, "rb")) != XBADFILE);
  4003. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4004. if (f != XBADFILE) {
  4005. XFCLOSE(f);
  4006. f = XBADFILE;
  4007. }
  4008. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4009. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4010. wc_FreeDecodedCert(&cert);
  4011. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4012. RSA_MAX_SIZE >= 3072
  4013. ExpectTrue((f = XFOPEN(rsaPssSha384Cert, "rb")) != XBADFILE);
  4014. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4015. if (f != XBADFILE)
  4016. XFCLOSE(f);
  4017. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4018. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4019. wc_FreeDecodedCert(&cert);
  4020. #endif
  4021. wolfSSL_CertManagerFree(cm);
  4022. #endif
  4023. return EXPECT_RESULT();
  4024. }
  4025. #endif
  4026. static int test_wolfSSL_CTX_load_verify_locations_ex(void)
  4027. {
  4028. EXPECT_DECLS;
  4029. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4030. !defined(NO_WOLFSSL_CLIENT)
  4031. WOLFSSL_CTX* ctx = NULL;
  4032. const char* ca_cert = "./certs/ca-cert.pem";
  4033. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  4034. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4035. /* test good CA */
  4036. ExpectTrue(WOLFSSL_SUCCESS ==
  4037. wolfSSL_CTX_load_verify_locations_ex(ctx, ca_cert, NULL,
  4038. WOLFSSL_LOAD_FLAG_NONE));
  4039. /* test expired CA */
  4040. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4041. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4042. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4043. #else
  4044. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4045. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4046. #endif
  4047. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4048. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4049. wolfSSL_CTX_free(ctx);
  4050. #endif
  4051. return EXPECT_RESULT();
  4052. }
  4053. static int test_wolfSSL_CTX_load_verify_buffer_ex(void)
  4054. {
  4055. EXPECT_DECLS;
  4056. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  4057. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4058. WOLFSSL_CTX* ctx;
  4059. const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
  4060. byte ca_expired_cert[TWOK_BUF];
  4061. word32 sizeof_ca_expired_cert = 0;
  4062. XFILE fp = XBADFILE;
  4063. #ifndef NO_WOLFSSL_CLIENT
  4064. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4065. #else
  4066. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4067. #endif
  4068. ExpectNotNull(ctx);
  4069. #if defined(USE_CERT_BUFFERS_2048)
  4070. /* test good CA */
  4071. ExpectTrue(WOLFSSL_SUCCESS ==
  4072. wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_cert_der_2048,
  4073. sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1, 0,
  4074. WOLFSSL_LOAD_FLAG_NONE));
  4075. #endif
  4076. /* load expired CA */
  4077. XMEMSET(ca_expired_cert, 0, sizeof(ca_expired_cert));
  4078. ExpectTrue((fp = XFOPEN(ca_expired_cert_file, "rb")) != XBADFILE);
  4079. ExpectIntGT(sizeof_ca_expired_cert = (word32)XFREAD(ca_expired_cert, 1,
  4080. sizeof(ca_expired_cert), fp), 0);
  4081. if (fp != XBADFILE)
  4082. XFCLOSE(fp);
  4083. /* test expired CA failure */
  4084. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4085. ExpectIntNE(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4086. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4087. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4088. #else
  4089. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4090. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4091. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4092. #endif
  4093. /* test expired CA success */
  4094. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4095. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4096. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4097. /* Fail when ctx is NULL. */
  4098. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(NULL, ca_expired_cert,
  4099. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4100. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4101. /* Load as modified cert - bad initial length. */
  4102. ca_expired_cert[2] = 0x7f;
  4103. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4104. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 1,
  4105. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4106. wolfSSL_CTX_free(ctx);
  4107. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4108. #endif
  4109. return EXPECT_RESULT();
  4110. }
  4111. static int test_wolfSSL_CTX_load_verify_chain_buffer_format(void)
  4112. {
  4113. EXPECT_DECLS;
  4114. #if !defined(NO_CERTS) && !defined(NO_RSA) && defined(OPENSSL_EXTRA) && \
  4115. defined(USE_CERT_BUFFERS_2048) && (WOLFSSL_MIN_RSA_BITS <= 1024) && \
  4116. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4117. WOLFSSL_CTX* ctx = NULL;
  4118. #ifndef NO_WOLFSSL_CLIENT
  4119. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4120. #else
  4121. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4122. #endif
  4123. /* Public key 140 bytes??? */
  4124. ExpectIntEQ(wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  4125. ca_cert_chain_der, sizeof_ca_cert_chain_der, WOLFSSL_FILETYPE_ASN1),
  4126. WOLFSSL_SUCCESS);
  4127. wolfSSL_CTX_free(ctx);
  4128. #endif
  4129. return EXPECT_RESULT();
  4130. }
  4131. static int test_wolfSSL_CTX_add1_chain_cert(void)
  4132. {
  4133. EXPECT_DECLS;
  4134. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \
  4135. defined(KEEP_OUR_CERT) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  4136. WOLFSSL_CTX* ctx;
  4137. WOLFSSL* ssl = NULL;
  4138. const char *certChain[] = {
  4139. "./certs/intermediate/client-int-cert.pem",
  4140. "./certs/intermediate/ca-int2-cert.pem",
  4141. "./certs/intermediate/ca-int-cert.pem",
  4142. "./certs/ca-cert.pem",
  4143. NULL
  4144. };
  4145. const char** cert;
  4146. WOLFSSL_X509* x509 = NULL;
  4147. WOLF_STACK_OF(X509)* chain = NULL;
  4148. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4149. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4150. ExpectNotNull(x509 = wolfSSL_X509_new());
  4151. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 0);
  4152. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, x509), 0);
  4153. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 0);
  4154. ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 0);
  4155. wolfSSL_X509_free(x509);
  4156. x509 = NULL;
  4157. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4158. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4159. WOLFSSL_FILETYPE_PEM));
  4160. /* Do negative tests once */
  4161. if (cert == certChain) {
  4162. /* Negative tests. */
  4163. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, NULL), 0);
  4164. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, NULL), 0);
  4165. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, x509), 0);
  4166. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, NULL), 0);
  4167. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, NULL), 0);
  4168. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, x509), 0);
  4169. }
  4170. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
  4171. X509_free(x509);
  4172. x509 = NULL;
  4173. }
  4174. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4175. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4176. WOLFSSL_FILETYPE_PEM));
  4177. /* Do negative tests once */
  4178. if (cert == certChain) {
  4179. /* Negative tests. */
  4180. ExpectIntEQ(SSL_add1_chain_cert(NULL, NULL), 0);
  4181. ExpectIntEQ(SSL_add1_chain_cert(ssl, NULL), 0);
  4182. ExpectIntEQ(SSL_add1_chain_cert(NULL, x509), 0);
  4183. ExpectIntEQ(SSL_add0_chain_cert(NULL, NULL), 0);
  4184. ExpectIntEQ(SSL_add0_chain_cert(ssl, NULL), 0);
  4185. ExpectIntEQ(SSL_add0_chain_cert(NULL, x509), 0);
  4186. }
  4187. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
  4188. X509_free(x509);
  4189. x509 = NULL;
  4190. }
  4191. ExpectIntEQ(SSL_CTX_get0_chain_certs(ctx, &chain), 1);
  4192. ExpectIntEQ(sk_X509_num(chain), 3);
  4193. ExpectIntEQ(SSL_get0_chain_certs(ssl, &chain), 1);
  4194. ExpectIntEQ(sk_X509_num(chain), 3);
  4195. SSL_free(ssl);
  4196. SSL_CTX_free(ctx);
  4197. #endif
  4198. return EXPECT_RESULT();
  4199. }
  4200. static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
  4201. {
  4202. EXPECT_DECLS;
  4203. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4204. !defined(NO_WOLFSSL_CLIENT) && defined(USE_CERT_BUFFERS_2048)
  4205. WOLFSSL_CTX* ctx = NULL;
  4206. WOLFSSL* ssl = NULL;
  4207. const char* cert = "./certs/server-cert.pem";
  4208. unsigned char* buf = NULL;
  4209. size_t len;
  4210. ExpectIntEQ(load_file(cert, &buf, &len), 0);
  4211. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4212. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4213. /* Invalid parameters. */
  4214. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4215. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4216. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4217. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4218. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4219. server_cert_der_2048, sizeof_server_cert_der_2048,
  4220. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4221. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, NULL, 0),
  4222. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4223. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, NULL, 0),
  4224. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4225. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (long)len),
  4226. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4227. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, NULL, 0),
  4228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4229. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, NULL, 0),
  4230. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4231. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (long)len),
  4232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4233. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4234. server_cert_der_2048, sizeof_server_cert_der_2048,
  4235. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4236. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buf,
  4237. (long)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4238. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (long)len),
  4239. WOLFSSL_SUCCESS);
  4240. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx,
  4241. server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4242. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (long)len),
  4243. WOLFSSL_SUCCESS);
  4244. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, server_cert_der_2048,
  4245. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4246. wolfSSL_free(ssl);
  4247. wolfSSL_CTX_free(ctx);
  4248. if (buf != NULL) {
  4249. free(buf);
  4250. }
  4251. #endif
  4252. return EXPECT_RESULT();
  4253. }
  4254. static int test_wolfSSL_CTX_use_certificate_chain_file_format(void)
  4255. {
  4256. EXPECT_DECLS;
  4257. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4258. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4259. const char* server_chain_der = "./certs/server-cert-chain.der";
  4260. const char* client_single_pem = "./certs/client-cert.pem";
  4261. WOLFSSL_CTX* ctx = NULL;
  4262. (void)server_chain_der;
  4263. (void)client_single_pem;
  4264. (void)ctx;
  4265. #ifndef NO_WOLFSSL_CLIENT
  4266. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4267. #else
  4268. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4269. #endif
  4270. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4271. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4272. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4273. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4274. wolfSSL_CTX_free(ctx);
  4275. #endif
  4276. return EXPECT_RESULT();
  4277. }
  4278. static int test_wolfSSL_use_certificate_chain_file(void)
  4279. {
  4280. EXPECT_DECLS;
  4281. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4282. !defined(NO_WOLFSSL_CLIENT)
  4283. const char* server_chain_der = "./certs/server-cert-chain.der";
  4284. const char* client_single_pem = "./certs/client-cert.pem";
  4285. WOLFSSL_CTX* ctx = NULL;
  4286. WOLFSSL* ssl = NULL;
  4287. (void)server_chain_der;
  4288. (void)client_single_pem;
  4289. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4290. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4291. /* Invalid parameters. */
  4292. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL, NULL,
  4293. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4294. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl, NULL,
  4295. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4296. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL,
  4297. server_chain_der, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4298. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4299. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, NULL),
  4300. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4301. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, client_single_pem),
  4302. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4303. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, server_chain_der),
  4304. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4305. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4306. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4307. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4308. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4309. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, client_single_pem),
  4310. WOLFSSL_SUCCESS);
  4311. wolfSSL_free(ssl);
  4312. wolfSSL_CTX_free(ctx);
  4313. #endif
  4314. return EXPECT_RESULT();
  4315. }
  4316. static int test_wolfSSL_CTX_SetTmpDH_file(void)
  4317. {
  4318. EXPECT_DECLS;
  4319. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4320. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4321. WOLFSSL_CTX *ctx = NULL;
  4322. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4323. const char* dsaParamFile = "./certs/dsaparams.pem";
  4324. #endif
  4325. (void)ctx;
  4326. #ifndef NO_WOLFSSL_CLIENT
  4327. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4328. #else
  4329. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4330. #endif
  4331. /* invalid context */
  4332. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL,
  4333. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4334. /* invalid dhParamFile file */
  4335. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4336. NULL, WOLFSSL_FILETYPE_PEM));
  4337. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4338. bogusFile, WOLFSSL_FILETYPE_PEM));
  4339. /* success */
  4340. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  4341. WOLFSSL_FILETYPE_PEM));
  4342. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4343. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4344. WOLFSSL_FILETYPE_PEM));
  4345. #endif
  4346. wolfSSL_CTX_free(ctx);
  4347. #endif
  4348. return EXPECT_RESULT();
  4349. }
  4350. static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
  4351. {
  4352. EXPECT_DECLS;
  4353. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4354. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4355. WOLFSSL_CTX *ctx = NULL;
  4356. #ifndef NO_WOLFSSL_CLIENT
  4357. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4358. #else
  4359. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4360. #endif
  4361. /* invalid context */
  4362. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL,
  4363. dh_key_der_2048, sizeof_dh_key_der_2048,
  4364. WOLFSSL_FILETYPE_ASN1));
  4365. /* invalid dhParamFile file */
  4366. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL, NULL,
  4367. 0, WOLFSSL_FILETYPE_ASN1));
  4368. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx, NULL,
  4369. 0, WOLFSSL_FILETYPE_ASN1));
  4370. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4371. dsa_key_der_2048, sizeof_dsa_key_der_2048,
  4372. WOLFSSL_FILETYPE_ASN1));
  4373. /* invalid file format */
  4374. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4375. dh_key_der_2048, sizeof_dh_key_der_2048, -1));
  4376. /* success */
  4377. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4378. dh_key_der_2048, sizeof_dh_key_der_2048,
  4379. WOLFSSL_FILETYPE_ASN1));
  4380. wolfSSL_CTX_free(ctx);
  4381. #endif
  4382. return EXPECT_RESULT();
  4383. }
  4384. static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
  4385. {
  4386. EXPECT_DECLS;
  4387. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4388. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4389. WOLFSSL_CTX *ctx;
  4390. (void)ctx;
  4391. #ifndef NO_WOLFSSL_CLIENT
  4392. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4393. #else
  4394. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4395. #endif
  4396. ExpectNotNull(ctx);
  4397. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4398. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx, dh_key_der_2048,
  4399. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4400. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 2048));
  4401. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4402. dh_key_der_2048, sizeof_dh_key_der_2048,
  4403. WOLFSSL_FILETYPE_ASN1));
  4404. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4405. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4406. dh_key_der_2048, sizeof_dh_key_der_2048,
  4407. WOLFSSL_FILETYPE_ASN1));
  4408. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 2048));
  4409. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4410. dh_key_der_2048, sizeof_dh_key_der_2048,
  4411. WOLFSSL_FILETYPE_ASN1));
  4412. wolfSSL_CTX_free(ctx);
  4413. #endif
  4414. return EXPECT_RESULT();
  4415. }
  4416. static int test_wolfSSL_CTX_der_load_verify_locations(void)
  4417. {
  4418. EXPECT_DECLS;
  4419. #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_DER_LOAD) && \
  4420. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4421. WOLFSSL_CTX* ctx = NULL;
  4422. const char* derCert = "./certs/server-cert.der";
  4423. const char* nullPath = NULL;
  4424. const char* invalidPath = "./certs/this-cert-does-not-exist.der";
  4425. const char* emptyPath = "";
  4426. /* der load Case 1 ctx NULL */
  4427. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4428. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4429. #ifndef NO_WOLFSSL_CLIENT
  4430. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4431. #else
  4432. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4433. #endif
  4434. /* Case 2 filePath NULL */
  4435. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, nullPath,
  4436. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4437. /* Case 3 invalid format */
  4438. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4439. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4440. /* Case 4 filePath not valid */
  4441. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, invalidPath,
  4442. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4443. /* Case 5 filePath empty */
  4444. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, emptyPath,
  4445. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4446. #ifndef NO_RSA
  4447. /* Case 6 success case */
  4448. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4449. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4450. #endif
  4451. wolfSSL_CTX_free(ctx);
  4452. #endif
  4453. return EXPECT_RESULT();
  4454. }
  4455. static int test_wolfSSL_CTX_enable_disable(void)
  4456. {
  4457. EXPECT_DECLS;
  4458. #ifndef NO_CERTS
  4459. WOLFSSL_CTX* ctx = NULL;
  4460. #ifdef HAVE_CRL
  4461. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4462. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4463. #endif
  4464. #ifdef HAVE_OCSP
  4465. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4466. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4467. #endif
  4468. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4469. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4470. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4471. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4472. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4473. ExpectIntEQ(wolfSSL_CTX_EnableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4474. #endif
  4475. #ifndef NO_WOLFSSL_CLIENT
  4476. #ifdef HAVE_EXTENDED_MASTER
  4477. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4478. #endif
  4479. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4480. #ifdef HAVE_EXTENDED_MASTER
  4481. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS);
  4482. #endif
  4483. #elif !defined(NO_WOLFSSL_SERVER)
  4484. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4485. #endif
  4486. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4487. #ifdef HAVE_CRL
  4488. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WOLFSSL_SUCCESS);
  4489. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WOLFSSL_SUCCESS);
  4490. #endif
  4491. #ifdef HAVE_OCSP
  4492. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WOLFSSL_SUCCESS);
  4493. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_URL_OVERRIDE),
  4494. WOLFSSL_SUCCESS);
  4495. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE),
  4496. WOLFSSL_SUCCESS);
  4497. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL),
  4498. WOLFSSL_SUCCESS);
  4499. #endif
  4500. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4501. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4502. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4503. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4504. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4505. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4506. #endif
  4507. wolfSSL_CTX_free(ctx);
  4508. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4509. #endif /* NO_CERTS */
  4510. return EXPECT_RESULT();
  4511. }
  4512. static int test_wolfSSL_CTX_ticket_API(void)
  4513. {
  4514. EXPECT_DECLS;
  4515. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  4516. WOLFSSL_CTX* ctx = NULL;
  4517. void *userCtx = (void*)"this is my ctx";
  4518. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4519. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(ctx, userCtx));
  4520. ExpectTrue(userCtx == wolfSSL_CTX_get_TicketEncCtx(ctx));
  4521. wolfSSL_CTX_free(ctx);
  4522. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(NULL, userCtx));
  4523. ExpectNull(wolfSSL_CTX_get_TicketEncCtx(NULL));
  4524. #endif /* HAVE_SESSION_TICKET && !NO_WOLFSSL_SERVER */
  4525. return EXPECT_RESULT();
  4526. }
  4527. static int test_wolfSSL_set_minmax_proto_version(void)
  4528. {
  4529. EXPECT_DECLS;
  4530. #ifdef OPENSSL_EXTRA
  4531. WOLFSSL_CTX *ctx = NULL;
  4532. WOLFSSL *ssl = NULL;
  4533. (void)ssl;
  4534. #ifndef NO_WOLFSSL_CLIENT
  4535. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4536. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4537. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4538. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4539. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4540. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4541. ExpectIntEQ(wolfSSL_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4542. ExpectIntEQ(wolfSSL_set_min_proto_version(ssl, 0), SSL_SUCCESS);
  4543. ExpectIntEQ(wolfSSL_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4544. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl, 0), SSL_SUCCESS);
  4545. wolfSSL_free(ssl);
  4546. wolfSSL_CTX_free(ctx);
  4547. ctx = NULL;
  4548. #endif
  4549. #ifndef NO_WOLFSSL_SERVER
  4550. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4551. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4552. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4553. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4554. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4555. wolfSSL_CTX_free(ctx);
  4556. #endif
  4557. #endif
  4558. return EXPECT_RESULT();
  4559. }
  4560. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  4561. defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  4562. static int test_wolfSSL_CTX_set_max_proto_version_on_result(WOLFSSL* ssl)
  4563. {
  4564. EXPECT_DECLS;
  4565. ExpectStrEQ(wolfSSL_get_version(ssl), "TLSv1.2");
  4566. return EXPECT_RESULT();
  4567. }
  4568. static int test_wolfSSL_CTX_set_max_proto_version_ctx_ready(WOLFSSL_CTX* ctx)
  4569. {
  4570. EXPECT_DECLS;
  4571. /* Set TLS 1.2 */
  4572. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  4573. WOLFSSL_SUCCESS);
  4574. return EXPECT_RESULT();
  4575. }
  4576. /* Test using wolfSSL_CTX_set_max_proto_version to limit the version below
  4577. * what was set at ctx creation. */
  4578. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4579. {
  4580. EXPECT_DECLS;
  4581. test_ssl_cbf client_cbs;
  4582. test_ssl_cbf server_cbs;
  4583. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  4584. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  4585. client_cbs.method = wolfTLS_client_method;
  4586. server_cbs.method = wolfTLS_server_method;
  4587. server_cbs.ctx_ready = test_wolfSSL_CTX_set_max_proto_version_ctx_ready;
  4588. client_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4589. server_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4590. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  4591. &server_cbs, NULL), TEST_SUCCESS);
  4592. return EXPECT_RESULT();
  4593. }
  4594. #else
  4595. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4596. {
  4597. return TEST_SKIPPED;
  4598. }
  4599. #endif
  4600. /*----------------------------------------------------------------------------*
  4601. | SSL
  4602. *----------------------------------------------------------------------------*/
  4603. static int test_server_wolfSSL_new(void)
  4604. {
  4605. EXPECT_DECLS;
  4606. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4607. !defined(NO_WOLFSSL_SERVER)
  4608. WOLFSSL_CTX *ctx = NULL;
  4609. WOLFSSL_CTX *ctx_nocert = NULL;
  4610. WOLFSSL *ssl = NULL;
  4611. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4612. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4613. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4614. WOLFSSL_FILETYPE_PEM));
  4615. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4616. WOLFSSL_FILETYPE_PEM));
  4617. /* invalid context */
  4618. ExpectNull(ssl = wolfSSL_new(NULL));
  4619. #if !defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_QT) && \
  4620. !defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_INIT_CTX_KEY)
  4621. ExpectNull(ssl = wolfSSL_new(ctx_nocert));
  4622. #endif
  4623. /* success */
  4624. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4625. wolfSSL_free(ssl);
  4626. wolfSSL_CTX_free(ctx);
  4627. wolfSSL_CTX_free(ctx_nocert);
  4628. #endif
  4629. return EXPECT_RESULT();
  4630. }
  4631. static int test_client_wolfSSL_new(void)
  4632. {
  4633. EXPECT_DECLS;
  4634. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4635. !defined(NO_WOLFSSL_CLIENT)
  4636. WOLFSSL_CTX *ctx = NULL;
  4637. WOLFSSL_CTX *ctx_nocert = NULL;
  4638. WOLFSSL *ssl = NULL;
  4639. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4640. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4641. ExpectTrue(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  4642. /* invalid context */
  4643. ExpectNull(ssl = wolfSSL_new(NULL));
  4644. /* success */
  4645. ExpectNotNull(ssl = wolfSSL_new(ctx_nocert));
  4646. wolfSSL_free(ssl);
  4647. ssl = NULL;
  4648. /* success */
  4649. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4650. wolfSSL_free(ssl);
  4651. wolfSSL_CTX_free(ctx);
  4652. wolfSSL_CTX_free(ctx_nocert);
  4653. #endif
  4654. return EXPECT_RESULT();
  4655. }
  4656. static int test_wolfSSL_SetTmpDH_file(void)
  4657. {
  4658. EXPECT_DECLS;
  4659. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4660. !defined(NO_WOLFSSL_SERVER)
  4661. WOLFSSL_CTX *ctx = NULL;
  4662. WOLFSSL *ssl = NULL;
  4663. const char* dhX942ParamFile = "./certs/x942dh2048.pem";
  4664. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4665. const char* dsaParamFile = "./certs/dsaparams.pem";
  4666. #endif
  4667. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4668. #ifndef NO_RSA
  4669. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4670. WOLFSSL_FILETYPE_PEM));
  4671. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4672. WOLFSSL_FILETYPE_PEM));
  4673. #elif defined(HAVE_ECC)
  4674. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  4675. WOLFSSL_FILETYPE_PEM));
  4676. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  4677. WOLFSSL_FILETYPE_PEM));
  4678. #elif defined(HAVE_ED25519)
  4679. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, edCertFile,
  4680. WOLFSSL_FILETYPE_PEM));
  4681. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  4682. WOLFSSL_FILETYPE_PEM));
  4683. #elif defined(HAVE_ED448)
  4684. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, ed448CertFile,
  4685. WOLFSSL_FILETYPE_PEM));
  4686. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  4687. WOLFSSL_FILETYPE_PEM));
  4688. #endif
  4689. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4690. /* invalid ssl */
  4691. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(NULL,
  4692. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4693. /* invalid dhParamFile file */
  4694. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4695. NULL, WOLFSSL_FILETYPE_PEM));
  4696. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4697. bogusFile, WOLFSSL_FILETYPE_PEM));
  4698. /* success */
  4699. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhParamFile,
  4700. WOLFSSL_FILETYPE_PEM));
  4701. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhX942ParamFile,
  4702. WOLFSSL_FILETYPE_PEM));
  4703. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4704. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4705. WOLFSSL_FILETYPE_PEM));
  4706. #endif
  4707. wolfSSL_free(ssl);
  4708. wolfSSL_CTX_free(ctx);
  4709. #endif
  4710. return EXPECT_RESULT();
  4711. }
  4712. static int test_wolfSSL_SetTmpDH_buffer(void)
  4713. {
  4714. EXPECT_DECLS;
  4715. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4716. WOLFSSL_CTX *ctx = NULL;
  4717. WOLFSSL *ssl = NULL;
  4718. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4719. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4720. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4721. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4722. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4723. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4724. /* invalid ssl */
  4725. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, dh_key_der_2048,
  4726. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4727. /* invalid dhParamFile file */
  4728. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, NULL,
  4729. 0, WOLFSSL_FILETYPE_ASN1));
  4730. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, NULL, 0,
  4731. WOLFSSL_FILETYPE_ASN1));
  4732. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dsa_key_der_2048,
  4733. sizeof_dsa_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4734. /* success */
  4735. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4736. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4737. wolfSSL_free(ssl);
  4738. wolfSSL_CTX_free(ctx);
  4739. #endif
  4740. return EXPECT_RESULT();
  4741. }
  4742. static int test_wolfSSL_SetMinMaxDhKey_Sz(void)
  4743. {
  4744. EXPECT_DECLS;
  4745. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4746. WOLFSSL_CTX *ctx = NULL;
  4747. WOLFSSL_CTX *ctx2 = NULL;
  4748. WOLFSSL *ssl = NULL;
  4749. WOLFSSL *ssl2 = NULL;
  4750. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4751. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4752. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4753. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4754. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4755. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4756. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4757. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4758. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx2, server_cert_der_2048,
  4759. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4760. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx2, server_key_der_2048,
  4761. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4762. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4763. ExpectNotNull(ssl2 = wolfSSL_new(ctx2));
  4764. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4765. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4766. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 2048));
  4767. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4768. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4769. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 3072));
  4770. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4771. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4772. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4773. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4774. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 2048));
  4775. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4776. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4777. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 1024));
  4778. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4779. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4780. wolfSSL_free(ssl2);
  4781. wolfSSL_CTX_free(ctx2);
  4782. wolfSSL_free(ssl);
  4783. wolfSSL_CTX_free(ctx);
  4784. #endif
  4785. return EXPECT_RESULT();
  4786. }
  4787. /* Test function for wolfSSL_SetMinVersion. Sets the minimum downgrade version
  4788. * allowed.
  4789. * POST: return 1 on success.
  4790. */
  4791. static int test_wolfSSL_SetMinVersion(void)
  4792. {
  4793. int res = TEST_SKIPPED;
  4794. #ifndef NO_WOLFSSL_CLIENT
  4795. int failFlag = WOLFSSL_SUCCESS;
  4796. WOLFSSL_CTX* ctx = NULL;
  4797. WOLFSSL* ssl = NULL;
  4798. int itr;
  4799. #ifndef NO_OLD_TLS
  4800. const int versions[] = {
  4801. #ifdef WOLFSSL_ALLOW_TLSV10
  4802. WOLFSSL_TLSV1,
  4803. #endif
  4804. WOLFSSL_TLSV1_1,
  4805. WOLFSSL_TLSV1_2};
  4806. #elif !defined(WOLFSSL_NO_TLS12)
  4807. const int versions[] = { WOLFSSL_TLSV1_2 };
  4808. #else
  4809. const int versions[] = { WOLFSSL_TLSV1_3 };
  4810. #endif
  4811. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4812. ssl = wolfSSL_new(ctx);
  4813. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  4814. if (wolfSSL_SetMinVersion(ssl, *(versions + itr)) != WOLFSSL_SUCCESS) {
  4815. failFlag = WOLFSSL_FAILURE;
  4816. }
  4817. }
  4818. wolfSSL_free(ssl);
  4819. wolfSSL_CTX_free(ctx);
  4820. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  4821. #endif
  4822. return res;
  4823. } /* END test_wolfSSL_SetMinVersion */
  4824. #ifdef OPENSSL_EXTRA
  4825. static int test_EC25519(void)
  4826. {
  4827. EXPECT_DECLS;
  4828. #if defined(HAVE_CURVE25519) && defined(WOLFSSL_KEY_GEN)
  4829. byte priv[CURVE25519_KEYSIZE];
  4830. unsigned int privSz = CURVE25519_KEYSIZE;
  4831. byte pub[CURVE25519_KEYSIZE];
  4832. unsigned int pubSz = CURVE25519_KEYSIZE;
  4833. byte priv2[CURVE25519_KEYSIZE];
  4834. unsigned int priv2Sz = CURVE25519_KEYSIZE;
  4835. byte pub2[CURVE25519_KEYSIZE];
  4836. unsigned int pub2Sz = CURVE25519_KEYSIZE;
  4837. byte shared[CURVE25519_KEYSIZE];
  4838. unsigned int sharedSz = CURVE25519_KEYSIZE;
  4839. byte shared2[CURVE25519_KEYSIZE];
  4840. unsigned int shared2Sz = CURVE25519_KEYSIZE;
  4841. /* Bad parameter testing of key generation. */
  4842. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, NULL, NULL, NULL), 0);
  4843. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  4844. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  4845. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, NULL, pub, &pubSz), 0);
  4846. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  4847. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, NULL), 0);
  4848. /* Bad length */
  4849. privSz = 1;
  4850. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4851. privSz = CURVE25519_KEYSIZE;
  4852. pubSz = 1;
  4853. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4854. pubSz = CURVE25519_KEYSIZE;
  4855. /* Good case of generating key. */
  4856. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 1);
  4857. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv2, &priv2Sz, pub2, &pub2Sz),
  4858. 1);
  4859. ExpectIntEQ(privSz, CURVE25519_KEYSIZE);
  4860. ExpectIntEQ(pubSz, CURVE25519_KEYSIZE);
  4861. /* Bad parameter testing of shared key. */
  4862. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, NULL, NULL, privSz,
  4863. NULL, pubSz), 0);
  4864. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, NULL, privSz,
  4865. NULL, pubSz), 0);
  4866. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  4867. pub, pubSz), 0);
  4868. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  4869. pub, pubSz), 0);
  4870. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4871. NULL, pubSz), 0);
  4872. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  4873. pub, pubSz), 0);
  4874. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, NULL, priv, privSz,
  4875. pub, pubSz), 0);
  4876. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  4877. pub, pubSz), 0);
  4878. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4879. NULL, pubSz), 0);
  4880. /* Bad length. */
  4881. sharedSz = 1;
  4882. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4883. pub, pubSz), 0);
  4884. sharedSz = CURVE25519_KEYSIZE;
  4885. privSz = 1;
  4886. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4887. pub, pubSz), 0);
  4888. privSz = CURVE25519_KEYSIZE;
  4889. pubSz = 1;
  4890. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4891. pub, pubSz), 0);
  4892. pubSz = CURVE25519_KEYSIZE;
  4893. /* Good case of shared key. */
  4894. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4895. pub2, pub2Sz), 1);
  4896. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  4897. pub, pubSz), 1);
  4898. ExpectIntEQ(sharedSz, CURVE25519_KEYSIZE);
  4899. ExpectIntEQ(shared2Sz, CURVE25519_KEYSIZE);
  4900. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  4901. #endif /* HAVE_CURVE25519 && WOLFSSL_KEY_GEN */
  4902. return EXPECT_RESULT();
  4903. }
  4904. static int test_ED25519(void)
  4905. {
  4906. EXPECT_DECLS;
  4907. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  4908. defined(WOLFSSL_KEY_GEN)
  4909. byte priv[ED25519_PRV_KEY_SIZE];
  4910. unsigned int privSz = (unsigned int)sizeof(priv);
  4911. byte pub[ED25519_PUB_KEY_SIZE];
  4912. unsigned int pubSz = (unsigned int)sizeof(pub);
  4913. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  4914. const char* msg = TEST_STRING;
  4915. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  4916. byte sig[ED25519_SIG_SIZE];
  4917. unsigned int sigSz = (unsigned int)sizeof(sig);
  4918. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  4919. /* Bad parameter testing of key generation. */
  4920. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, NULL), 0);
  4921. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, NULL, NULL), 0);
  4922. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, NULL, NULL), 0);
  4923. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, pub, NULL), 0);
  4924. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, &pubSz), 0);
  4925. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  4926. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, pub, &pubSz), 0);
  4927. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  4928. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, NULL), 0);
  4929. /* Bad length. */
  4930. privSz = 1;
  4931. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4932. privSz = ED25519_PRV_KEY_SIZE;
  4933. pubSz = 1;
  4934. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4935. pubSz = ED25519_PUB_KEY_SIZE;
  4936. /* Good case of generating key. */
  4937. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz),
  4938. 1);
  4939. ExpectIntEQ(privSz, ED25519_PRV_KEY_SIZE);
  4940. ExpectIntEQ(pubSz, ED25519_PUB_KEY_SIZE);
  4941. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  4942. /* Bad parameter testing of signing. */
  4943. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  4944. NULL), 0);
  4945. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, NULL,
  4946. NULL), 0);
  4947. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, NULL,
  4948. NULL), 0);
  4949. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, sig,
  4950. NULL), 0);
  4951. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  4952. &sigSz), 0);
  4953. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, sig,
  4954. &sigSz), 0);
  4955. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, sig,
  4956. &sigSz), 0);
  4957. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, NULL,
  4958. &sigSz), 0);
  4959. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4960. NULL), 0);
  4961. /* Bad length. */
  4962. privSz = 1;
  4963. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4964. &sigSz), 0);
  4965. privSz = ED25519_PRV_KEY_SIZE;
  4966. sigSz = 1;
  4967. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4968. &sigSz), 0);
  4969. sigSz = ED25519_SIG_SIZE;
  4970. /* Good case of signing. */
  4971. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4972. &sigSz), 1);
  4973. ExpectIntEQ(sigSz, ED25519_SIG_SIZE);
  4974. #ifdef HAVE_ED25519_VERIFY
  4975. /* Bad parameter testing of verification. */
  4976. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, NULL,
  4977. sigSz), 0);
  4978. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  4979. sigSz), 0);
  4980. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, NULL,
  4981. sigSz), 0);
  4982. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, sig,
  4983. sigSz), 0);
  4984. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, sig,
  4985. sigSz), 0);
  4986. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, sig,
  4987. sigSz), 0);
  4988. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, NULL,
  4989. sigSz), 0);
  4990. /* Bad length. */
  4991. pubSz = 1;
  4992. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  4993. sigSz), 0);
  4994. pubSz = ED25519_PUB_KEY_SIZE;
  4995. sigSz = 1;
  4996. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  4997. sigSz), 0);
  4998. sigSz = ED25519_SIG_SIZE;
  4999. /* Good case of verification. */
  5000. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5001. sigSz), 1);
  5002. /* Bad signature. */
  5003. if (EXPECT_SUCCESS()) {
  5004. sig[1] ^= 0x80;
  5005. }
  5006. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5007. sigSz), 0);
  5008. #endif /* HAVE_ED25519_VERIFY */
  5009. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5010. #endif /* HAVE_ED25519 && HAVE_ED25519_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5011. return EXPECT_RESULT();
  5012. }
  5013. static int test_EC448(void)
  5014. {
  5015. EXPECT_DECLS;
  5016. #if defined(HAVE_CURVE448) && defined(WOLFSSL_KEY_GEN)
  5017. byte priv[CURVE448_KEY_SIZE];
  5018. unsigned int privSz = CURVE448_KEY_SIZE;
  5019. byte pub[CURVE448_KEY_SIZE];
  5020. unsigned int pubSz = CURVE448_KEY_SIZE;
  5021. byte priv2[CURVE448_KEY_SIZE];
  5022. unsigned int priv2Sz = CURVE448_KEY_SIZE;
  5023. byte pub2[CURVE448_KEY_SIZE];
  5024. unsigned int pub2Sz = CURVE448_KEY_SIZE;
  5025. byte shared[CURVE448_KEY_SIZE];
  5026. unsigned int sharedSz = CURVE448_KEY_SIZE;
  5027. byte shared2[CURVE448_KEY_SIZE];
  5028. unsigned int shared2Sz = CURVE448_KEY_SIZE;
  5029. /* Bad parameter testing of key generation. */
  5030. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, NULL, NULL, NULL), 0);
  5031. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5032. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5033. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, NULL, pub, &pubSz), 0);
  5034. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5035. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, NULL), 0);
  5036. /* Bad length. */
  5037. privSz = 1;
  5038. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5039. privSz = CURVE448_KEY_SIZE;
  5040. pubSz = 1;
  5041. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5042. pubSz = CURVE448_KEY_SIZE;
  5043. /* Good case of generating key. */
  5044. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5045. ExpectIntEQ(wolfSSL_EC448_generate_key(priv2, &priv2Sz, pub2, &pub2Sz), 1);
  5046. ExpectIntEQ(privSz, CURVE448_KEY_SIZE);
  5047. ExpectIntEQ(pubSz, CURVE448_KEY_SIZE);
  5048. /* Bad parameter testing of shared key. */
  5049. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, NULL, NULL, privSz,
  5050. NULL, pubSz), 0);
  5051. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, NULL, privSz,
  5052. NULL, pubSz), 0);
  5053. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5054. pub, pubSz), 0);
  5055. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5056. pub, pubSz), 0);
  5057. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5058. NULL, pubSz), 0);
  5059. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5060. pub, pubSz), 0);
  5061. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, NULL, priv, privSz,
  5062. pub, pubSz), 0);
  5063. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5064. pub, pubSz), 0);
  5065. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5066. NULL, pubSz), 0);
  5067. /* Bad length. */
  5068. sharedSz = 1;
  5069. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5070. pub, pubSz), 0);
  5071. sharedSz = CURVE448_KEY_SIZE;
  5072. privSz = 1;
  5073. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5074. pub, pubSz), 0);
  5075. privSz = CURVE448_KEY_SIZE;
  5076. pubSz = 1;
  5077. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5078. pub, pubSz), 0);
  5079. pubSz = CURVE448_KEY_SIZE;
  5080. /* Good case of shared key. */
  5081. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5082. pub2, pub2Sz), 1);
  5083. ExpectIntEQ(wolfSSL_EC448_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5084. pub, pubSz), 1);
  5085. ExpectIntEQ(sharedSz, CURVE448_KEY_SIZE);
  5086. ExpectIntEQ(shared2Sz, CURVE448_KEY_SIZE);
  5087. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5088. #endif /* HAVE_CURVE448 && WOLFSSL_KEY_GEN */
  5089. return EXPECT_RESULT();
  5090. }
  5091. static int test_ED448(void)
  5092. {
  5093. EXPECT_DECLS;
  5094. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  5095. defined(WOLFSSL_KEY_GEN)
  5096. byte priv[ED448_PRV_KEY_SIZE];
  5097. unsigned int privSz = (unsigned int)sizeof(priv);
  5098. byte pub[ED448_PUB_KEY_SIZE];
  5099. unsigned int pubSz = (unsigned int)sizeof(pub);
  5100. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5101. const char* msg = TEST_STRING;
  5102. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5103. byte sig[ED448_SIG_SIZE];
  5104. unsigned int sigSz = (unsigned int)sizeof(sig);
  5105. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5106. /* Bad parameter testing of key generation. */
  5107. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, NULL), 0);
  5108. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, NULL, NULL), 0);
  5109. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, NULL, NULL), 0);
  5110. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, pub, NULL), 0);
  5111. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5112. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5113. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, pub, &pubSz), 0);
  5114. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5115. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, NULL), 0);
  5116. /* Bad length. */
  5117. privSz = 1;
  5118. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5119. privSz = ED448_PRV_KEY_SIZE;
  5120. pubSz = 1;
  5121. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5122. pubSz = ED448_PUB_KEY_SIZE;
  5123. /* Good case of generating key. */
  5124. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5125. ExpectIntEQ(privSz, ED448_PRV_KEY_SIZE);
  5126. ExpectIntEQ(pubSz, ED448_PUB_KEY_SIZE);
  5127. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5128. /* Bad parameter testing of signing. */
  5129. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5130. NULL), 0);
  5131. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5132. NULL), 0);
  5133. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, NULL,
  5134. NULL), 0);
  5135. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, sig,
  5136. NULL), 0);
  5137. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5138. &sigSz), 0);
  5139. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, sig,
  5140. &sigSz), 0);
  5141. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, sig,
  5142. &sigSz), 0);
  5143. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, NULL,
  5144. &sigSz), 0);
  5145. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5146. NULL), 0);
  5147. /* Bad length. */
  5148. privSz = 1;
  5149. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5150. &sigSz), 0);
  5151. privSz = ED448_PRV_KEY_SIZE;
  5152. sigSz = 1;
  5153. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5154. &sigSz), 0);
  5155. sigSz = ED448_SIG_SIZE;
  5156. /* Good case of signing. */
  5157. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5158. &sigSz), 1);
  5159. ExpectIntEQ(sigSz, ED448_SIG_SIZE);
  5160. #ifdef HAVE_ED448_VERIFY
  5161. /* Bad parameter testing of verification. */
  5162. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, NULL,
  5163. sigSz), 0);
  5164. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5165. sigSz), 0);
  5166. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, NULL,
  5167. sigSz), 0);
  5168. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, sig,
  5169. sigSz), 0);
  5170. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, sig,
  5171. sigSz), 0);
  5172. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5173. sigSz), 0);
  5174. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5175. sigSz), 0);
  5176. /* Bad length. */
  5177. pubSz = 1;
  5178. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5179. sigSz), 0);
  5180. pubSz = ED448_PUB_KEY_SIZE;
  5181. sigSz = 1;
  5182. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5183. sigSz), 0);
  5184. sigSz = ED448_SIG_SIZE;
  5185. /* Good case of verification. */
  5186. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5187. sigSz), 1);
  5188. /* Bad signature. */
  5189. if (EXPECT_SUCCESS()) {
  5190. sig[1] ^= 0x80;
  5191. }
  5192. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5193. sigSz), 0);
  5194. #endif /* HAVE_ED448_VERIFY */
  5195. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5196. #endif /* HAVE_ED448 && HAVE_ED448_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5197. return EXPECT_RESULT();
  5198. }
  5199. #endif /* OPENSSL_EXTRA */
  5200. #include <wolfssl/openssl/pem.h>
  5201. /*----------------------------------------------------------------------------*
  5202. | EVP
  5203. *----------------------------------------------------------------------------*/
  5204. static int test_wolfSSL_EVP_PKEY_print_public(void)
  5205. {
  5206. EXPECT_DECLS;
  5207. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  5208. WOLFSSL_BIO* rbio = NULL;
  5209. WOLFSSL_BIO* wbio = NULL;
  5210. WOLFSSL_EVP_PKEY* pkey = NULL;
  5211. char line[256] = { 0 };
  5212. char line1[256] = { 0 };
  5213. int i = 0;
  5214. /* test error cases */
  5215. ExpectIntEQ( EVP_PKEY_print_public(NULL,NULL,0,NULL),0L);
  5216. /*
  5217. * test RSA public key print
  5218. * in this test, pass '3' for indent
  5219. */
  5220. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_1024)
  5221. ExpectNotNull(rbio = BIO_new_mem_buf( client_keypub_der_1024,
  5222. sizeof_client_keypub_der_1024));
  5223. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5224. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5225. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,3,NULL),1);
  5226. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5227. strcpy(line1, " RSA Public-Key: (1024 bit)\n");
  5228. ExpectIntEQ(XSTRNCMP(line, line1, XSTRLEN(line1)), 0);
  5229. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5230. strcpy(line1, " Modulus:\n");
  5231. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5232. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5233. strcpy(line1, " 00:bc:73:0e:a8:49:f3:74:a2:a9:ef:18:a5:da:55:\n");
  5234. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5235. /* skip to the end of modulus element*/
  5236. for (i = 0; i < 8 ;i++) {
  5237. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5238. }
  5239. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5240. strcpy(line1, " Exponent: 65537 (0x010001)\n");
  5241. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5242. /* should reach EOF */
  5243. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5244. EVP_PKEY_free(pkey);
  5245. pkey = NULL;
  5246. BIO_free(rbio);
  5247. BIO_free(wbio);
  5248. rbio = NULL;
  5249. wbio = NULL;
  5250. #endif /* !NO_RSA && USE_CERT_BUFFERS_1024*/
  5251. /*
  5252. * test DSA public key print
  5253. */
  5254. #if !defined(NO_DSA) && defined(USE_CERT_BUFFERS_2048)
  5255. ExpectNotNull(rbio = BIO_new_mem_buf( dsa_pub_key_der_2048,
  5256. sizeof_dsa_pub_key_der_2048));
  5257. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5258. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5259. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5260. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5261. strcpy(line1, "DSA Public-Key: (2048 bit)\n");
  5262. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5263. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5264. strcpy(line1, "pub:\n");
  5265. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5266. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5267. strcpy(line1,
  5268. " 00:C2:35:2D:EC:83:83:6C:73:13:9E:52:7C:74:C8:\n");
  5269. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5270. /* skip to the end of pub element*/
  5271. for (i = 0; i < 17 ;i++) {
  5272. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5273. }
  5274. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5275. strcpy(line1, "P:\n");
  5276. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5277. /* skip to the end of P element*/
  5278. for (i = 0; i < 18 ;i++) {
  5279. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5280. }
  5281. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5282. strcpy(line1, "Q:\n");
  5283. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5284. /* skip to the end of Q element*/
  5285. for (i = 0; i < 3 ;i++) {
  5286. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5287. }
  5288. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5289. strcpy(line1, "G:\n");
  5290. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5291. /* skip to the end of G element*/
  5292. for (i = 0; i < 18 ;i++) {
  5293. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5294. }
  5295. /* should reach EOF */
  5296. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5297. EVP_PKEY_free(pkey);
  5298. pkey = NULL;
  5299. BIO_free(rbio);
  5300. BIO_free(wbio);
  5301. rbio = NULL;
  5302. wbio = NULL;
  5303. #endif /* !NO_DSA && USE_CERT_BUFFERS_2048 */
  5304. /*
  5305. * test ECC public key print
  5306. */
  5307. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  5308. ExpectNotNull(rbio = BIO_new_mem_buf( ecc_clikeypub_der_256,
  5309. sizeof_ecc_clikeypub_der_256));
  5310. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5311. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5312. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5313. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5314. strcpy(line1, "Public-Key: (256 bit)\n");
  5315. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5316. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5317. strcpy(line1, "pub:\n");
  5318. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5319. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5320. strcpy(line1,
  5321. " 04:55:BF:F4:0F:44:50:9A:3D:CE:9B:B7:F0:C5:4D:\n");
  5322. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5323. /* skip to the end of pub element*/
  5324. for (i = 0; i < 4 ;i++) {
  5325. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5326. }
  5327. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5328. strcpy(line1, "ASN1 OID: prime256v1\n");
  5329. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5330. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5331. strcpy(line1, "NIST CURVE: P-256\n");
  5332. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5333. /* should reach EOF */
  5334. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5335. EVP_PKEY_free(pkey);
  5336. pkey = NULL;
  5337. BIO_free(rbio);
  5338. BIO_free(wbio);
  5339. rbio = NULL;
  5340. wbio = NULL;
  5341. #endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */
  5342. /*
  5343. * test DH public key print
  5344. */
  5345. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  5346. ExpectNotNull(rbio = BIO_new_mem_buf( dh_pub_key_der_2048,
  5347. sizeof_dh_pub_key_der_2048));
  5348. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5349. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5350. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL), 1);
  5351. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5352. strcpy(line1, "DH Public-Key: (2048 bit)\n");
  5353. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5354. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5355. strcpy(line1, "public-key:\n");
  5356. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5357. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5358. strcpy(line1,
  5359. " 34:41:BF:E9:F2:11:BF:05:DB:B2:72:A8:29:CC:BD:\n");
  5360. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5361. /* skip to the end of public-key element*/
  5362. for (i = 0; i < 17 ;i++) {
  5363. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5364. }
  5365. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5366. strcpy(line1, "prime:\n");
  5367. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5368. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5369. strcpy(line1,
  5370. " 00:D3:B2:99:84:5C:0A:4C:E7:37:CC:FC:18:37:01:\n");
  5371. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5372. /* skip to the end of prime element*/
  5373. for (i = 0; i < 17 ;i++) {
  5374. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5375. }
  5376. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5377. strcpy(line1, "generator: 2 (0x02)\n");
  5378. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5379. /* should reach EOF */
  5380. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5381. EVP_PKEY_free(pkey);
  5382. pkey = NULL;
  5383. BIO_free(rbio);
  5384. BIO_free(wbio);
  5385. rbio = NULL;
  5386. wbio = NULL;
  5387. #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
  5388. /* to prevent "unused variable" warning */
  5389. (void)pkey;
  5390. (void)wbio;
  5391. (void)rbio;
  5392. (void)line;
  5393. (void)line1;
  5394. (void)i;
  5395. #endif /* OPENSSL_EXTRA */
  5396. return EXPECT_RESULT();
  5397. }
  5398. /* Test functions for base64 encode/decode */
  5399. static int test_wolfSSL_EVP_ENCODE_CTX_new(void)
  5400. {
  5401. EXPECT_DECLS;
  5402. #if defined(OPENSSL_EXTRA) && \
  5403. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5404. EVP_ENCODE_CTX* ctx = NULL;
  5405. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5406. ExpectIntEQ(ctx->remaining,0);
  5407. ExpectIntEQ(ctx->data[0],0);
  5408. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1],0);
  5409. EVP_ENCODE_CTX_free(ctx);
  5410. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5411. return EXPECT_RESULT();
  5412. }
  5413. static int test_wolfSSL_EVP_ENCODE_CTX_free(void)
  5414. {
  5415. EXPECT_DECLS;
  5416. #if defined(OPENSSL_EXTRA) && \
  5417. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5418. EVP_ENCODE_CTX* ctx = NULL;
  5419. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5420. EVP_ENCODE_CTX_free(ctx);
  5421. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5422. return EXPECT_RESULT();
  5423. }
  5424. static int test_wolfSSL_EVP_EncodeInit(void)
  5425. {
  5426. EXPECT_DECLS;
  5427. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5428. EVP_ENCODE_CTX* ctx = NULL;
  5429. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5430. ExpectIntEQ(ctx->remaining, 0);
  5431. ExpectIntEQ(ctx->data[0], 0);
  5432. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5433. if (ctx != NULL) {
  5434. /* make ctx dirty */
  5435. ctx->remaining = 10;
  5436. XMEMSET(ctx->data, 0x77, sizeof(ctx->data));
  5437. }
  5438. EVP_EncodeInit(ctx);
  5439. ExpectIntEQ(ctx->remaining, 0);
  5440. ExpectIntEQ(ctx->data[0], 0);
  5441. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5442. EVP_ENCODE_CTX_free(ctx);
  5443. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5444. return EXPECT_RESULT();
  5445. }
  5446. static int test_wolfSSL_EVP_EncodeUpdate(void)
  5447. {
  5448. EXPECT_DECLS;
  5449. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5450. int outl;
  5451. int total;
  5452. const unsigned char plain0[] = {"Th"};
  5453. const unsigned char plain1[] = {"This is a base64 encodeing test."};
  5454. const unsigned char plain2[] = {"This is additional data."};
  5455. const unsigned char encBlock0[] = {"VGg="};
  5456. const unsigned char enc0[] = {"VGg=\n"};
  5457. /* expected encoded result for the first output 64 chars plus trailing LF*/
  5458. const unsigned char enc1[] = {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\n"};
  5459. const unsigned char enc2[] =
  5460. {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\nYWwgZGF0YS4=\n"};
  5461. unsigned char encOutBuff[300];
  5462. EVP_ENCODE_CTX* ctx = NULL;
  5463. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5464. EVP_EncodeInit(ctx);
  5465. /* illegal parameter test */
  5466. ExpectIntEQ(
  5467. EVP_EncodeUpdate(
  5468. NULL, /* pass NULL as ctx */
  5469. encOutBuff,
  5470. &outl,
  5471. plain1,
  5472. sizeof(plain1)-1),
  5473. 0 /* expected result code 0: fail */
  5474. );
  5475. ExpectIntEQ(
  5476. EVP_EncodeUpdate(
  5477. ctx,
  5478. NULL, /* pass NULL as out buff */
  5479. &outl,
  5480. plain1,
  5481. sizeof(plain1)-1),
  5482. 0 /* expected result code 0: fail */
  5483. );
  5484. ExpectIntEQ(
  5485. EVP_EncodeUpdate(
  5486. ctx,
  5487. encOutBuff,
  5488. NULL, /* pass NULL as outl */
  5489. plain1,
  5490. sizeof(plain1)-1),
  5491. 0 /* expected result code 0: fail */
  5492. );
  5493. ExpectIntEQ(
  5494. EVP_EncodeUpdate(
  5495. ctx,
  5496. encOutBuff,
  5497. &outl,
  5498. NULL, /* pass NULL as in */
  5499. sizeof(plain1)-1),
  5500. 0 /* expected result code 0: fail */
  5501. );
  5502. ExpectIntEQ(EVP_EncodeBlock(NULL, NULL, 0), -1);
  5503. /* meaningless parameter test */
  5504. ExpectIntEQ(
  5505. EVP_EncodeUpdate(
  5506. ctx,
  5507. encOutBuff,
  5508. &outl,
  5509. plain1,
  5510. 0), /* pass zero input */
  5511. 1 /* expected result code 1: success */
  5512. );
  5513. /* very small data encoding test */
  5514. EVP_EncodeInit(ctx);
  5515. ExpectIntEQ(
  5516. EVP_EncodeUpdate(
  5517. ctx,
  5518. encOutBuff,
  5519. &outl,
  5520. plain0,
  5521. sizeof(plain0)-1),
  5522. 1 /* expected result code 1: success */
  5523. );
  5524. ExpectIntEQ(outl,0);
  5525. if (EXPECT_SUCCESS()) {
  5526. EVP_EncodeFinal(
  5527. ctx,
  5528. encOutBuff + outl,
  5529. &outl);
  5530. }
  5531. ExpectIntEQ( outl, sizeof(enc0)-1);
  5532. ExpectIntEQ(
  5533. XSTRNCMP(
  5534. (const char*)encOutBuff,
  5535. (const char*)enc0,sizeof(enc0) ),
  5536. 0);
  5537. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5538. ExpectIntEQ(EVP_EncodeBlock(encOutBuff, plain0, sizeof(plain0)-1),
  5539. sizeof(encBlock0)-1);
  5540. ExpectStrEQ(encOutBuff, encBlock0);
  5541. /* pass small size( < 48bytes ) input, then make sure they are not
  5542. * encoded and just stored in ctx
  5543. */
  5544. EVP_EncodeInit(ctx);
  5545. total = 0;
  5546. outl = 0;
  5547. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5548. ExpectIntEQ(
  5549. EVP_EncodeUpdate(
  5550. ctx,
  5551. encOutBuff, /* buffer for output */
  5552. &outl, /* size of output */
  5553. plain1, /* input */
  5554. sizeof(plain1)-1), /* size of input */
  5555. 1); /* expected result code 1:success */
  5556. total += outl;
  5557. ExpectIntEQ(outl, 0); /* no output expected */
  5558. ExpectIntEQ(ctx->remaining, sizeof(plain1) -1);
  5559. ExpectTrue(
  5560. XSTRNCMP((const char*)(ctx->data),
  5561. (const char*)plain1,
  5562. ctx->remaining) ==0 );
  5563. ExpectTrue(encOutBuff[0] == 0);
  5564. /* call wolfSSL_EVP_EncodeUpdate again to make it encode
  5565. * the stored data and the new input together
  5566. */
  5567. ExpectIntEQ(
  5568. EVP_EncodeUpdate(
  5569. ctx,
  5570. encOutBuff + outl, /* buffer for output */
  5571. &outl, /* size of output */
  5572. plain2, /* additional input */
  5573. sizeof(plain2) -1), /* size of additional input */
  5574. 1); /* expected result code 1:success */
  5575. total += outl;
  5576. ExpectIntNE(outl, 0); /* some output is expected this time*/
  5577. ExpectIntEQ(outl, BASE64_ENCODE_RESULT_BLOCK_SIZE +1); /* 64 bytes and LF */
  5578. ExpectIntEQ(
  5579. XSTRNCMP((const char*)encOutBuff,(const char*)enc1,sizeof(enc1) ),0);
  5580. /* call wolfSSL_EVP_EncodeFinal to flush all the unprocessed input */
  5581. EVP_EncodeFinal(
  5582. ctx,
  5583. encOutBuff + outl,
  5584. &outl);
  5585. total += outl;
  5586. ExpectIntNE(total,0);
  5587. ExpectIntNE(outl,0);
  5588. ExpectIntEQ(XSTRNCMP(
  5589. (const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0);
  5590. /* test with illeagal parameters */
  5591. outl = 1;
  5592. EVP_EncodeFinal(NULL, encOutBuff + outl, &outl);
  5593. ExpectIntEQ(outl, 0);
  5594. outl = 1;
  5595. EVP_EncodeFinal(ctx, NULL, &outl);
  5596. ExpectIntEQ(outl, 0);
  5597. EVP_EncodeFinal(ctx, encOutBuff + outl, NULL);
  5598. EVP_EncodeFinal(NULL, NULL, NULL);
  5599. EVP_ENCODE_CTX_free(ctx);
  5600. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5601. return EXPECT_RESULT();
  5602. }
  5603. static int test_wolfSSL_EVP_EncodeFinal(void)
  5604. {
  5605. int res = TEST_SKIPPED;
  5606. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5607. /* tests for wolfSSL_EVP_EncodeFinal are included in
  5608. * test_wolfSSL_EVP_EncodeUpdate
  5609. */
  5610. res = TEST_SUCCESS;
  5611. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5612. return res;
  5613. }
  5614. static int test_wolfSSL_EVP_DecodeInit(void)
  5615. {
  5616. EXPECT_DECLS;
  5617. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5618. EVP_ENCODE_CTX* ctx = NULL;
  5619. ExpectNotNull( ctx = EVP_ENCODE_CTX_new());
  5620. ExpectIntEQ( ctx->remaining,0);
  5621. ExpectIntEQ( ctx->data[0],0);
  5622. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5623. if (ctx != NULL) {
  5624. /* make ctx dirty */
  5625. ctx->remaining = 10;
  5626. XMEMSET( ctx->data, 0x77, sizeof(ctx->data));
  5627. }
  5628. EVP_DecodeInit(ctx);
  5629. ExpectIntEQ( ctx->remaining,0);
  5630. ExpectIntEQ( ctx->data[0],0);
  5631. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5632. EVP_ENCODE_CTX_free(ctx);
  5633. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5634. return EXPECT_RESULT();
  5635. }
  5636. static int test_wolfSSL_EVP_DecodeUpdate(void)
  5637. {
  5638. EXPECT_DECLS;
  5639. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5640. int outl;
  5641. unsigned char decOutBuff[300];
  5642. EVP_ENCODE_CTX* ctx = NULL;
  5643. static const unsigned char enc1[] =
  5644. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5645. /* const unsigned char plain1[] =
  5646. {"This is a base64 decoding test."} */
  5647. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5648. EVP_DecodeInit(ctx);
  5649. /* illegal parameter tests */
  5650. /* pass NULL as ctx */
  5651. ExpectIntEQ(
  5652. EVP_DecodeUpdate(
  5653. NULL, /* pass NULL as ctx */
  5654. decOutBuff,
  5655. &outl,
  5656. enc1,
  5657. sizeof(enc1)-1),
  5658. -1 /* expected result code -1: fail */
  5659. );
  5660. ExpectIntEQ( outl, 0);
  5661. /* pass NULL as output */
  5662. ExpectIntEQ(
  5663. EVP_DecodeUpdate(
  5664. ctx,
  5665. NULL, /* pass NULL as out buff */
  5666. &outl,
  5667. enc1,
  5668. sizeof(enc1)-1),
  5669. -1 /* expected result code -1: fail */
  5670. );
  5671. ExpectIntEQ( outl, 0);
  5672. /* pass NULL as outl */
  5673. ExpectIntEQ(
  5674. EVP_DecodeUpdate(
  5675. ctx,
  5676. decOutBuff,
  5677. NULL, /* pass NULL as outl */
  5678. enc1,
  5679. sizeof(enc1)-1),
  5680. -1 /* expected result code -1: fail */
  5681. );
  5682. /* pass NULL as input */
  5683. ExpectIntEQ(
  5684. EVP_DecodeUpdate(
  5685. ctx,
  5686. decOutBuff,
  5687. &outl,
  5688. NULL, /* pass NULL as in */
  5689. sizeof(enc1)-1),
  5690. -1 /* expected result code -1: fail */
  5691. );
  5692. ExpectIntEQ( outl, 0);
  5693. ExpectIntEQ(EVP_DecodeBlock(NULL, NULL, 0), -1);
  5694. /* pass zero length input */
  5695. ExpectIntEQ(
  5696. EVP_DecodeUpdate(
  5697. ctx,
  5698. decOutBuff,
  5699. &outl,
  5700. enc1,
  5701. 0), /* pass zero as input len */
  5702. 1 /* expected result code 1: success */
  5703. );
  5704. /* decode correct base64 string */
  5705. {
  5706. static const unsigned char enc2[] =
  5707. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5708. static const unsigned char plain2[] =
  5709. {"This is a base64 decoding test."};
  5710. EVP_EncodeInit(ctx);
  5711. ExpectIntEQ(
  5712. EVP_DecodeUpdate(
  5713. ctx,
  5714. decOutBuff,
  5715. &outl,
  5716. enc2,
  5717. sizeof(enc2)-1),
  5718. 0 /* expected result code 0: success */
  5719. );
  5720. ExpectIntEQ(outl,sizeof(plain2) -1);
  5721. ExpectIntEQ(
  5722. EVP_DecodeFinal(
  5723. ctx,
  5724. decOutBuff + outl,
  5725. &outl),
  5726. 1 /* expected result code 1: success */
  5727. );
  5728. ExpectIntEQ(outl, 0); /* expected DecodeFinal output no data */
  5729. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5730. sizeof(plain2) -1 ),0);
  5731. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc2, sizeof(enc2)),
  5732. sizeof(plain2)-1);
  5733. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5734. sizeof(plain2) -1 ),0);
  5735. }
  5736. /* decode correct base64 string which does not have '\n' in its last*/
  5737. {
  5738. static const unsigned char enc3[] =
  5739. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg=="}; /* 44 chars */
  5740. static const unsigned char plain3[] =
  5741. {"This is a base64 decoding test."}; /* 31 chars */
  5742. EVP_EncodeInit(ctx);
  5743. ExpectIntEQ(
  5744. EVP_DecodeUpdate(
  5745. ctx,
  5746. decOutBuff,
  5747. &outl,
  5748. enc3,
  5749. sizeof(enc3)-1),
  5750. 0 /* expected result code 0: success */
  5751. );
  5752. ExpectIntEQ(outl,sizeof(plain3)-1); /* 31 chars should be output */
  5753. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5754. sizeof(plain3) -1 ),0);
  5755. ExpectIntEQ(
  5756. EVP_DecodeFinal(
  5757. ctx,
  5758. decOutBuff + outl,
  5759. &outl),
  5760. 1 /* expected result code 1: success */
  5761. );
  5762. ExpectIntEQ(outl,0 );
  5763. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc3, sizeof(enc3)-1),
  5764. sizeof(plain3)-1);
  5765. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5766. sizeof(plain3) -1 ),0);
  5767. }
  5768. /* decode string which has a padding char ('=') in the illegal position*/
  5769. {
  5770. static const unsigned char enc4[] =
  5771. {"VGhpcyBpcyBhIGJhc2U2N=CBkZWNvZGluZyB0ZXN0Lg==\n"};
  5772. EVP_EncodeInit(ctx);
  5773. ExpectIntEQ(
  5774. EVP_DecodeUpdate(
  5775. ctx,
  5776. decOutBuff,
  5777. &outl,
  5778. enc4,
  5779. sizeof(enc4)-1),
  5780. -1 /* expected result code -1: error */
  5781. );
  5782. ExpectIntEQ(outl,0);
  5783. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc4, sizeof(enc4)-1), -1);
  5784. }
  5785. /* small data decode test */
  5786. {
  5787. static const unsigned char enc00[] = {"VG"};
  5788. static const unsigned char enc01[] = {"g=\n"};
  5789. static const unsigned char plain4[] = {"Th"};
  5790. EVP_EncodeInit(ctx);
  5791. ExpectIntEQ(
  5792. EVP_DecodeUpdate(
  5793. ctx,
  5794. decOutBuff,
  5795. &outl,
  5796. enc00,
  5797. sizeof(enc00)-1),
  5798. 1 /* expected result code 1: success */
  5799. );
  5800. ExpectIntEQ(outl,0);
  5801. ExpectIntEQ(
  5802. EVP_DecodeUpdate(
  5803. ctx,
  5804. decOutBuff + outl,
  5805. &outl,
  5806. enc01,
  5807. sizeof(enc01)-1),
  5808. 0 /* expected result code 0: success */
  5809. );
  5810. ExpectIntEQ(outl,sizeof(plain4)-1);
  5811. /* test with illegal parameters */
  5812. ExpectIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1);
  5813. ExpectIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1);
  5814. ExpectIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1);
  5815. ExpectIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1);
  5816. if (EXPECT_SUCCESS()) {
  5817. EVP_DecodeFinal(
  5818. ctx,
  5819. decOutBuff + outl,
  5820. &outl);
  5821. }
  5822. ExpectIntEQ( outl, 0);
  5823. ExpectIntEQ(
  5824. XSTRNCMP(
  5825. (const char*)decOutBuff,
  5826. (const char*)plain4,sizeof(plain4)-1 ),
  5827. 0);
  5828. }
  5829. EVP_ENCODE_CTX_free(ctx);
  5830. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5831. return EXPECT_RESULT();
  5832. }
  5833. static int test_wolfSSL_EVP_DecodeFinal(void)
  5834. {
  5835. int res = TEST_SKIPPED;
  5836. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5837. /* tests for wolfSSL_EVP_DecodeFinal are included in
  5838. * test_wolfSSL_EVP_DecodeUpdate
  5839. */
  5840. res = TEST_SUCCESS;
  5841. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5842. return res;
  5843. }
  5844. /* Test function for wolfSSL_EVP_get_cipherbynid.
  5845. */
  5846. #ifdef OPENSSL_EXTRA
  5847. static int test_wolfSSL_EVP_get_cipherbynid(void)
  5848. {
  5849. EXPECT_DECLS;
  5850. #ifndef NO_AES
  5851. const WOLFSSL_EVP_CIPHER* c;
  5852. c = wolfSSL_EVP_get_cipherbynid(419);
  5853. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  5854. defined(WOLFSSL_AES_128)
  5855. ExpectNotNull(c);
  5856. ExpectNotNull(XSTRCMP("EVP_AES_128_CBC", c));
  5857. #else
  5858. ExpectNull(c);
  5859. #endif
  5860. c = wolfSSL_EVP_get_cipherbynid(423);
  5861. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  5862. defined(WOLFSSL_AES_192)
  5863. ExpectNotNull(c);
  5864. ExpectNotNull(XSTRCMP("EVP_AES_192_CBC", c));
  5865. #else
  5866. ExpectNull(c);
  5867. #endif
  5868. c = wolfSSL_EVP_get_cipherbynid(427);
  5869. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  5870. defined(WOLFSSL_AES_256)
  5871. ExpectNotNull(c);
  5872. ExpectNotNull(XSTRCMP("EVP_AES_256_CBC", c));
  5873. #else
  5874. ExpectNull(c);
  5875. #endif
  5876. c = wolfSSL_EVP_get_cipherbynid(904);
  5877. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_128)
  5878. ExpectNotNull(c);
  5879. ExpectNotNull(XSTRCMP("EVP_AES_128_CTR", c));
  5880. #else
  5881. ExpectNull(c);
  5882. #endif
  5883. c = wolfSSL_EVP_get_cipherbynid(905);
  5884. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_192)
  5885. ExpectNotNull(c);
  5886. ExpectNotNull(XSTRCMP("EVP_AES_192_CTR", c));
  5887. #else
  5888. ExpectNull(c);
  5889. #endif
  5890. c = wolfSSL_EVP_get_cipherbynid(906);
  5891. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  5892. ExpectNotNull(c);
  5893. ExpectNotNull(XSTRCMP("EVP_AES_256_CTR", c));
  5894. #else
  5895. ExpectNull(c);
  5896. #endif
  5897. c = wolfSSL_EVP_get_cipherbynid(418);
  5898. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_128)
  5899. ExpectNotNull(c);
  5900. ExpectNotNull(XSTRCMP("EVP_AES_128_ECB", c));
  5901. #else
  5902. ExpectNull(c);
  5903. #endif
  5904. c = wolfSSL_EVP_get_cipherbynid(422);
  5905. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_192)
  5906. ExpectNotNull(c);
  5907. ExpectNotNull(XSTRCMP("EVP_AES_192_ECB", c));
  5908. #else
  5909. ExpectNull(c);
  5910. #endif
  5911. c = wolfSSL_EVP_get_cipherbynid(426);
  5912. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  5913. ExpectNotNull(c);
  5914. ExpectNotNull(XSTRCMP("EVP_AES_256_ECB", c));
  5915. #else
  5916. ExpectNull(c);
  5917. #endif
  5918. #endif /* !NO_AES */
  5919. #ifndef NO_DES3
  5920. ExpectNotNull(XSTRCMP("EVP_DES_CBC", wolfSSL_EVP_get_cipherbynid(31)));
  5921. #ifdef WOLFSSL_DES_ECB
  5922. ExpectNotNull(XSTRCMP("EVP_DES_ECB", wolfSSL_EVP_get_cipherbynid(29)));
  5923. #endif
  5924. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_CBC", wolfSSL_EVP_get_cipherbynid(44)));
  5925. #ifdef WOLFSSL_DES_ECB
  5926. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_ECB", wolfSSL_EVP_get_cipherbynid(33)));
  5927. #endif
  5928. #endif /* !NO_DES3 */
  5929. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5930. ExpectNotNull(XSTRCMP("EVP_CHACHA20_POLY13O5", EVP_get_cipherbynid(1018)));
  5931. #endif
  5932. /* test for nid is out of range */
  5933. ExpectNull(wolfSSL_EVP_get_cipherbynid(1));
  5934. return EXPECT_RESULT();
  5935. }
  5936. static int test_wolfSSL_EVP_CIPHER_CTX(void)
  5937. {
  5938. EXPECT_DECLS;
  5939. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  5940. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  5941. const EVP_CIPHER *init = EVP_aes_128_cbc();
  5942. const EVP_CIPHER *test;
  5943. byte key[AES_BLOCK_SIZE] = {0};
  5944. byte iv[AES_BLOCK_SIZE] = {0};
  5945. ExpectNotNull(ctx);
  5946. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  5947. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  5948. test = EVP_CIPHER_CTX_cipher(ctx);
  5949. ExpectTrue(init == test);
  5950. ExpectIntEQ(EVP_CIPHER_nid(test), NID_aes_128_cbc);
  5951. ExpectIntEQ(EVP_CIPHER_CTX_reset(ctx), WOLFSSL_SUCCESS);
  5952. ExpectIntEQ(EVP_CIPHER_CTX_reset(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  5953. EVP_CIPHER_CTX_free(ctx);
  5954. /* test EVP_CIPHER_CTX_cleanup with NULL */
  5955. ExpectIntEQ(EVP_CIPHER_CTX_cleanup(NULL), WOLFSSL_SUCCESS);
  5956. #endif /* !NO_AES && HAVE_AES_CBC && WOLFSSL_AES_128 */
  5957. return EXPECT_RESULT();
  5958. }
  5959. #endif /* OPENSSL_EXTRA */
  5960. /*----------------------------------------------------------------------------*
  5961. | IO
  5962. *----------------------------------------------------------------------------*/
  5963. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) || \
  5964. defined(HAVE_IO_TESTS_DEPENDENCIES)
  5965. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  5966. #ifdef WC_SHA512_DIGEST_SIZE
  5967. #define MD_MAX_SIZE WC_SHA512_DIGEST_SIZE
  5968. #else
  5969. #define MD_MAX_SIZE WC_SHA256_DIGEST_SIZE
  5970. #endif
  5971. byte server_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by server */
  5972. byte server_side_msg2[MD_MAX_SIZE] = {0};/* msg received from client */
  5973. byte client_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by client */
  5974. byte client_side_msg2[MD_MAX_SIZE] = {0};/* msg received from server */
  5975. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  5976. /* TODO: Expand and enable this when EVP_chacha20_poly1305 is supported */
  5977. #if defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  5978. defined(HAVE_AES_CBC)
  5979. typedef struct openssl_key_ctx {
  5980. byte name[WOLFSSL_TICKET_NAME_SZ]; /* server name */
  5981. byte key[WOLFSSL_TICKET_KEY_SZ]; /* cipher key */
  5982. byte hmacKey[WOLFSSL_TICKET_NAME_SZ]; /* hmac key */
  5983. byte iv[WOLFSSL_TICKET_IV_SZ]; /* cipher iv */
  5984. } openssl_key_ctx;
  5985. static THREAD_LS_T openssl_key_ctx myOpenSSLKey_ctx;
  5986. static THREAD_LS_T WC_RNG myOpenSSLKey_rng;
  5987. static WC_INLINE int OpenSSLTicketInit(void)
  5988. {
  5989. int ret = wc_InitRng(&myOpenSSLKey_rng);
  5990. if (ret != 0) return ret;
  5991. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.name,
  5992. sizeof(myOpenSSLKey_ctx.name));
  5993. if (ret != 0) return ret;
  5994. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.key,
  5995. sizeof(myOpenSSLKey_ctx.key));
  5996. if (ret != 0) return ret;
  5997. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.hmacKey,
  5998. sizeof(myOpenSSLKey_ctx.hmacKey));
  5999. if (ret != 0) return ret;
  6000. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.iv,
  6001. sizeof(myOpenSSLKey_ctx.iv));
  6002. if (ret != 0) return ret;
  6003. return 0;
  6004. }
  6005. static int myTicketEncCbOpenSSL(WOLFSSL* ssl,
  6006. byte name[WOLFSSL_TICKET_NAME_SZ],
  6007. byte iv[WOLFSSL_TICKET_IV_SZ],
  6008. WOLFSSL_EVP_CIPHER_CTX *ectx,
  6009. WOLFSSL_HMAC_CTX *hctx, int enc) {
  6010. (void)ssl;
  6011. if (enc) {
  6012. XMEMCPY(name, myOpenSSLKey_ctx.name, sizeof(myOpenSSLKey_ctx.name));
  6013. XMEMCPY(iv, myOpenSSLKey_ctx.iv, sizeof(myOpenSSLKey_ctx.iv));
  6014. }
  6015. else if (XMEMCMP(name, myOpenSSLKey_ctx.name,
  6016. sizeof(myOpenSSLKey_ctx.name)) != 0 ||
  6017. XMEMCMP(iv, myOpenSSLKey_ctx.iv,
  6018. sizeof(myOpenSSLKey_ctx.iv)) != 0) {
  6019. return 0;
  6020. }
  6021. HMAC_Init_ex(hctx, myOpenSSLKey_ctx.hmacKey, WOLFSSL_TICKET_NAME_SZ, EVP_sha256(), NULL);
  6022. if (enc)
  6023. EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6024. else
  6025. EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6026. return 1;
  6027. }
  6028. static WC_INLINE void OpenSSLTicketCleanup(void)
  6029. {
  6030. wc_FreeRng(&myOpenSSLKey_rng);
  6031. }
  6032. #endif
  6033. #endif
  6034. /* helper functions */
  6035. #ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  6036. static WC_INLINE int test_ssl_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  6037. void *ctx)
  6038. {
  6039. struct test_ssl_memio_ctx *test_ctx;
  6040. byte *buf;
  6041. int *len;
  6042. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6043. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6044. buf = test_ctx->c_buff;
  6045. len = &test_ctx->c_len;
  6046. }
  6047. else {
  6048. buf = test_ctx->s_buff;
  6049. len = &test_ctx->s_len;
  6050. }
  6051. if ((unsigned)(*len + sz) > TEST_SSL_MEMIO_BUF_SZ)
  6052. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  6053. XMEMCPY(buf + *len, data, sz);
  6054. *len += sz;
  6055. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  6056. {
  6057. /* This can be imported into Wireshark by transforming the file with
  6058. * od -Ax -tx1 -v test_output.dump > test_output.dump.hex
  6059. * And then loading test_output.dump.hex into Wireshark using the
  6060. * "Import from Hex Dump..." option ion and selecting the TCP
  6061. * encapsulation option. */
  6062. char dump_file_name[64];
  6063. WOLFSSL_BIO *dump_file;
  6064. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  6065. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  6066. if (dump_file != NULL) {
  6067. (void)wolfSSL_BIO_write(dump_file, data, sz);
  6068. wolfSSL_BIO_free(dump_file);
  6069. }
  6070. }
  6071. #endif
  6072. return sz;
  6073. }
  6074. static WC_INLINE int test_ssl_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  6075. void *ctx)
  6076. {
  6077. struct test_ssl_memio_ctx *test_ctx;
  6078. int read_sz;
  6079. byte *buf;
  6080. int *len;
  6081. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6082. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6083. buf = test_ctx->s_buff;
  6084. len = &test_ctx->s_len;
  6085. }
  6086. else {
  6087. buf = test_ctx->c_buff;
  6088. len = &test_ctx->c_len;
  6089. }
  6090. if (*len == 0)
  6091. return WOLFSSL_CBIO_ERR_WANT_READ;
  6092. read_sz = sz < *len ? sz : *len;
  6093. XMEMCPY(data, buf, read_sz);
  6094. XMEMMOVE(buf, buf + read_sz, *len - read_sz);
  6095. *len -= read_sz;
  6096. return read_sz;
  6097. }
  6098. static WC_INLINE int test_ssl_memio_setup(test_ssl_memio_ctx *ctx)
  6099. {
  6100. EXPECT_DECLS;
  6101. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6102. int c_sharedCtx = 0;
  6103. int s_sharedCtx = 0;
  6104. #endif
  6105. const char* clientCertFile = cliCertFile;
  6106. const char* clientKeyFile = cliKeyFile;
  6107. const char* serverCertFile = svrCertFile;
  6108. const char* serverKeyFile = svrKeyFile;
  6109. /********************************
  6110. * Create WOLFSSL_CTX for client.
  6111. ********************************/
  6112. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6113. if (ctx->c_ctx != NULL) {
  6114. c_sharedCtx = ctx->c_cb.isSharedCtx;
  6115. }
  6116. else
  6117. #endif
  6118. {
  6119. WOLFSSL_METHOD* method = NULL;
  6120. if (ctx->c_cb.method != NULL) {
  6121. method = ctx->c_cb.method();
  6122. }
  6123. else {
  6124. method = wolfSSLv23_client_method();
  6125. }
  6126. ExpectNotNull(ctx->c_ctx = wolfSSL_CTX_new(method));
  6127. }
  6128. wolfSSL_SetIORecv(ctx->c_ctx, test_ssl_memio_read_cb);
  6129. wolfSSL_SetIOSend(ctx->c_ctx, test_ssl_memio_write_cb);
  6130. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6131. wolfSSL_CTX_set_default_passwd_cb(ctx->c_ctx, PasswordCallBack);
  6132. #endif
  6133. if (ctx->c_cb.caPemFile != NULL)
  6134. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6135. ctx->c_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6136. else
  6137. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6138. caCertFile, 0), WOLFSSL_SUCCESS);
  6139. if (ctx->c_cb.certPemFile != NULL) {
  6140. clientCertFile = ctx->c_cb.certPemFile;
  6141. }
  6142. if (ctx->c_cb.keyPemFile != NULL) {
  6143. clientKeyFile = ctx->c_cb.keyPemFile;
  6144. }
  6145. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6146. if (!c_sharedCtx)
  6147. #endif
  6148. {
  6149. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->c_ctx,
  6150. clientCertFile), WOLFSSL_SUCCESS);
  6151. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->c_ctx, clientKeyFile,
  6152. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6153. }
  6154. #ifdef HAVE_CRL
  6155. if (ctx->c_cb.crlPemFile != NULL) {
  6156. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx->c_ctx, WOLFSSL_CRL_CHECKALL),
  6157. WOLFSSL_SUCCESS);
  6158. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx->c_ctx, ctx->c_cb.crlPemFile,
  6159. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6160. }
  6161. #endif
  6162. if (ctx->c_ciphers != NULL) {
  6163. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->c_ctx, ctx->c_ciphers),
  6164. WOLFSSL_SUCCESS);
  6165. }
  6166. if (ctx->c_cb.ctx_ready != NULL) {
  6167. ExpectIntEQ(ctx->c_cb.ctx_ready(ctx->c_ctx), TEST_SUCCESS);
  6168. }
  6169. /********************************
  6170. * Create WOLFSSL_CTX for server.
  6171. ********************************/
  6172. if (ctx->s_ctx != NULL) {
  6173. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6174. s_sharedCtx = 1;
  6175. #endif
  6176. ctx->s_cb.isSharedCtx = 1;
  6177. }
  6178. else
  6179. {
  6180. WOLFSSL_METHOD* method = NULL;
  6181. if (ctx->s_cb.method != NULL) {
  6182. method = ctx->s_cb.method();
  6183. }
  6184. else {
  6185. method = wolfSSLv23_server_method();
  6186. }
  6187. ExpectNotNull(ctx->s_ctx = wolfSSL_CTX_new(method));
  6188. ctx->s_cb.isSharedCtx = 0;
  6189. }
  6190. if (!ctx->s_cb.ticNoInit && (ctx->s_ctx != NULL)) {
  6191. #if defined(HAVE_SESSION_TICKET) && \
  6192. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6193. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6194. OpenSSLTicketInit();
  6195. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx->s_ctx, myTicketEncCbOpenSSL);
  6196. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6197. TicketInit();
  6198. wolfSSL_CTX_set_TicketEncCb(ctx->s_ctx, myTicketEncCb);
  6199. #endif
  6200. #endif
  6201. }
  6202. wolfSSL_SetIORecv(ctx->s_ctx, test_ssl_memio_read_cb);
  6203. wolfSSL_SetIOSend(ctx->s_ctx, test_ssl_memio_write_cb);
  6204. wolfSSL_CTX_set_verify(ctx->s_ctx, WOLFSSL_VERIFY_PEER |
  6205. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6206. if (ctx->s_cb.caPemFile != NULL)
  6207. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6208. ctx->s_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6209. else
  6210. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6211. cliCertFile, 0), WOLFSSL_SUCCESS);
  6212. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6213. wolfSSL_CTX_set_default_passwd_cb(ctx->s_ctx, PasswordCallBack);
  6214. #endif
  6215. if (ctx->s_cb.certPemFile != NULL) {
  6216. serverCertFile = ctx->s_cb.certPemFile;
  6217. }
  6218. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6219. if (!s_sharedCtx)
  6220. #endif
  6221. {
  6222. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->s_ctx,
  6223. serverCertFile), WOLFSSL_SUCCESS);
  6224. }
  6225. if (ctx->s_cb.keyPemFile != NULL) {
  6226. serverKeyFile = ctx->s_cb.keyPemFile;
  6227. }
  6228. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6229. if (!s_sharedCtx)
  6230. #endif
  6231. {
  6232. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->s_ctx, serverKeyFile,
  6233. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6234. }
  6235. if (ctx->s_ciphers != NULL) {
  6236. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->s_ctx, ctx->s_ciphers),
  6237. WOLFSSL_SUCCESS);
  6238. }
  6239. if (ctx->s_cb.ctx_ready != NULL) {
  6240. ExpectIntEQ(ctx->s_cb.ctx_ready(ctx->s_ctx), TEST_SUCCESS);
  6241. }
  6242. /****************************
  6243. * Create WOLFSSL for client.
  6244. ****************************/
  6245. ExpectNotNull(ctx->c_ssl = wolfSSL_new(ctx->c_ctx));
  6246. wolfSSL_SetIOWriteCtx(ctx->c_ssl, ctx);
  6247. wolfSSL_SetIOReadCtx(ctx->c_ssl, ctx);
  6248. if (0
  6249. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6250. || c_sharedCtx
  6251. #endif
  6252. )
  6253. {
  6254. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->c_ssl,
  6255. clientCertFile), WOLFSSL_SUCCESS);
  6256. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->c_ssl, clientKeyFile,
  6257. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6258. }
  6259. if (ctx->c_cb.ssl_ready != NULL) {
  6260. ExpectIntEQ(ctx->c_cb.ssl_ready(ctx->c_ssl), TEST_SUCCESS);
  6261. }
  6262. /****************************
  6263. * Create WOLFSSL for server.
  6264. ****************************/
  6265. ExpectNotNull(ctx->s_ssl = wolfSSL_new(ctx->s_ctx));
  6266. wolfSSL_SetIOWriteCtx(ctx->s_ssl, ctx);
  6267. wolfSSL_SetIOReadCtx(ctx->s_ssl, ctx);
  6268. if (0
  6269. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6270. || s_sharedCtx
  6271. #endif
  6272. )
  6273. {
  6274. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->s_ssl,
  6275. serverCertFile), WOLFSSL_SUCCESS);
  6276. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->s_ssl, serverKeyFile,
  6277. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6278. }
  6279. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6280. wolfSSL_SetTmpDH_file(ctx->s_ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6281. #elif !defined(NO_DH)
  6282. /* will repick suites with DHE, higher priority than PSK */
  6283. SetDH(ctx->s_ssl);
  6284. #endif
  6285. if (ctx->s_cb.ssl_ready != NULL) {
  6286. ExpectIntEQ(ctx->s_cb.ssl_ready(ctx->s_ssl), TEST_SUCCESS);
  6287. }
  6288. return EXPECT_RESULT();
  6289. }
  6290. static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
  6291. int* rounds)
  6292. {
  6293. int handshake_complete = 0;
  6294. int hs_c = 0;
  6295. int hs_s = 0;
  6296. int failing_s = 0;
  6297. int failing_c = 0;
  6298. int ret;
  6299. int err;
  6300. if (rounds != NULL) {
  6301. *rounds = 0;
  6302. }
  6303. while ((!handshake_complete) && (max_rounds > 0)) {
  6304. if (!hs_c) {
  6305. wolfSSL_SetLoggingPrefix("client");
  6306. ret = wolfSSL_connect(ctx->c_ssl);
  6307. wolfSSL_SetLoggingPrefix(NULL);
  6308. if (ret == WOLFSSL_SUCCESS) {
  6309. hs_c = 1;
  6310. }
  6311. else {
  6312. err = wolfSSL_get_error(ctx->c_ssl, ret);
  6313. if (err != WOLFSSL_ERROR_WANT_READ &&
  6314. err != WOLFSSL_ERROR_WANT_WRITE) {
  6315. char buff[WOLFSSL_MAX_ERROR_SZ];
  6316. fprintf(stderr, "error = %d, %s\n", err,
  6317. wolfSSL_ERR_error_string(err, buff));
  6318. failing_c = 1;
  6319. hs_c = 1;
  6320. if (failing_c && failing_s) {
  6321. break;
  6322. }
  6323. }
  6324. }
  6325. }
  6326. if (!hs_s) {
  6327. wolfSSL_SetLoggingPrefix("server");
  6328. ret = wolfSSL_accept(ctx->s_ssl);
  6329. wolfSSL_SetLoggingPrefix(NULL);
  6330. if (ret == WOLFSSL_SUCCESS) {
  6331. hs_s = 1;
  6332. }
  6333. else {
  6334. err = wolfSSL_get_error(ctx->s_ssl, ret);
  6335. if (err != WOLFSSL_ERROR_WANT_READ &&
  6336. err != WOLFSSL_ERROR_WANT_WRITE) {
  6337. char buff[WOLFSSL_MAX_ERROR_SZ];
  6338. fprintf(stderr, "error = %d, %s\n", err,
  6339. wolfSSL_ERR_error_string(err, buff));
  6340. failing_s = 1;
  6341. hs_s = 1;
  6342. if (failing_c && failing_s) {
  6343. break;
  6344. }
  6345. }
  6346. }
  6347. }
  6348. handshake_complete = hs_c && hs_s;
  6349. max_rounds--;
  6350. if (rounds != NULL) {
  6351. *rounds += 1;
  6352. }
  6353. }
  6354. if (!handshake_complete || failing_c || failing_s) {
  6355. return TEST_FAIL;
  6356. }
  6357. return TEST_SUCCESS;
  6358. }
  6359. static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
  6360. {
  6361. EXPECT_DECLS;
  6362. char input[1024];
  6363. int idx = 0;
  6364. const char* msg_c = "hello wolfssl!";
  6365. int msglen_c = (int)XSTRLEN(msg_c);
  6366. const char* msg_s = "I hear you fa shizzle!";
  6367. int msglen_s = (int)XSTRLEN(msg_s);
  6368. if (ctx->c_msg != NULL) {
  6369. msg_c = ctx->c_msg;
  6370. msglen_c = ctx->c_msglen;
  6371. }
  6372. if (ctx->s_msg != NULL) {
  6373. msg_s = ctx->s_msg;
  6374. msglen_s = ctx->s_msglen;
  6375. }
  6376. wolfSSL_SetLoggingPrefix("client");
  6377. ExpectIntEQ(wolfSSL_write(ctx->c_ssl, msg_c, msglen_c), msglen_c);
  6378. wolfSSL_SetLoggingPrefix("server");
  6379. ExpectIntGT(idx = wolfSSL_read(ctx->s_ssl, input, sizeof(input) - 1), 0);
  6380. if (idx >= 0) {
  6381. input[idx] = '\0';
  6382. }
  6383. ExpectIntGT(fprintf(stderr, "Client message: %s\n", input), 0);
  6384. ExpectIntEQ(wolfSSL_write(ctx->s_ssl, msg_s, msglen_s), msglen_s);
  6385. ctx->s_cb.return_code = EXPECT_RESULT();
  6386. wolfSSL_SetLoggingPrefix("client");
  6387. ExpectIntGT(idx = wolfSSL_read(ctx->c_ssl, input, sizeof(input) - 1), 0);
  6388. wolfSSL_SetLoggingPrefix(NULL);
  6389. if (idx >= 0) {
  6390. input[idx] = '\0';
  6391. }
  6392. ExpectIntGT(fprintf(stderr, "Server response: %s\n", input), 0);
  6393. ctx->c_cb.return_code = EXPECT_RESULT();
  6394. if (ctx->c_cb.on_result != NULL) {
  6395. ExpectIntEQ(ctx->c_cb.on_result(ctx->c_ssl), TEST_SUCCESS);
  6396. }
  6397. if (ctx->s_cb.on_result != NULL) {
  6398. ExpectIntEQ(ctx->s_cb.on_result(ctx->s_ssl), TEST_SUCCESS);
  6399. }
  6400. return EXPECT_RESULT();
  6401. }
  6402. static void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx)
  6403. {
  6404. ctx->c_cb.last_err = wolfSSL_get_error(ctx->c_ssl, 0);
  6405. ctx->s_cb.last_err = wolfSSL_get_error(ctx->s_ssl, 0);
  6406. if (ctx->c_cb.on_cleanup != NULL) {
  6407. ctx->c_cb.on_cleanup(ctx->c_ssl);
  6408. }
  6409. if (ctx->s_cb.on_cleanup != NULL) {
  6410. ctx->s_cb.on_cleanup(ctx->s_ssl);
  6411. }
  6412. wolfSSL_shutdown(ctx->s_ssl);
  6413. wolfSSL_shutdown(ctx->c_ssl);
  6414. wolfSSL_free(ctx->s_ssl);
  6415. wolfSSL_free(ctx->c_ssl);
  6416. if (ctx->c_cb.on_ctx_cleanup != NULL) {
  6417. ctx->c_cb.on_ctx_cleanup(ctx->c_ctx);
  6418. }
  6419. if (!ctx->c_cb.isSharedCtx) {
  6420. wolfSSL_CTX_free(ctx->c_ctx);
  6421. ctx->c_ctx = NULL;
  6422. }
  6423. if (ctx->s_cb.on_ctx_cleanup != NULL) {
  6424. ctx->s_cb.on_ctx_cleanup(ctx->s_ctx);
  6425. }
  6426. if (!ctx->s_cb.isSharedCtx) {
  6427. wolfSSL_CTX_free(ctx->s_ctx);
  6428. ctx->s_ctx = NULL;
  6429. }
  6430. if (!ctx->s_cb.ticNoInit) {
  6431. #if defined(HAVE_SESSION_TICKET) && \
  6432. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6433. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6434. OpenSSLTicketCleanup();
  6435. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6436. TicketCleanup();
  6437. #endif
  6438. #endif
  6439. }
  6440. }
  6441. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  6442. test_ssl_cbf* server_cb, cbType client_on_handshake)
  6443. {
  6444. EXPECT_DECLS;
  6445. struct test_ssl_memio_ctx test_ctx;
  6446. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6447. size_t msg_len;
  6448. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6449. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  6450. XMEMCPY(&test_ctx.c_cb, client_cb, sizeof(test_ssl_cbf));
  6451. XMEMCPY(&test_ctx.s_cb, server_cb, sizeof(test_ssl_cbf));
  6452. test_ctx.c_ctx = client_cb->ctx;
  6453. test_ctx.s_ctx = server_cb->ctx;
  6454. test_ctx.c_cb.return_code = TEST_FAIL;
  6455. test_ctx.s_cb.return_code = TEST_FAIL;
  6456. ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
  6457. ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
  6458. if (client_on_handshake != NULL) {
  6459. ExpectIntEQ(client_on_handshake(test_ctx.c_ctx, test_ctx.c_ssl),
  6460. TEST_SUCCESS);
  6461. }
  6462. if (client_cb->on_handshake != NULL) {
  6463. ExpectIntEQ(client_cb->on_handshake(&test_ctx.c_ctx, &test_ctx.c_ssl),
  6464. TEST_SUCCESS);
  6465. }
  6466. if (server_cb->on_handshake != NULL) {
  6467. ExpectIntEQ(server_cb->on_handshake(&test_ctx.s_ctx, &test_ctx.s_ssl),
  6468. TEST_SUCCESS);
  6469. }
  6470. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6471. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6472. msg_len = wolfSSL_get_peer_finished(test_ctx.s_ssl, server_side_msg2,
  6473. MD_MAX_SIZE);
  6474. ExpectIntGE(msg_len, 0);
  6475. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6476. msg_len = wolfSSL_get_finished(test_ctx.s_ssl, server_side_msg1,
  6477. MD_MAX_SIZE);
  6478. ExpectIntGE(msg_len, 0);
  6479. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6480. ExpectIntEQ(test_ssl_memio_read_write(&test_ctx), TEST_SUCCESS);
  6481. test_ssl_memio_cleanup(&test_ctx);
  6482. client_cb->return_code = test_ctx.c_cb.return_code;
  6483. client_cb->last_err = test_ctx.c_cb.last_err;
  6484. server_cb->return_code = test_ctx.s_cb.return_code;
  6485. server_cb->last_err = test_ctx.s_cb.last_err;
  6486. return EXPECT_RESULT();
  6487. }
  6488. #endif
  6489. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  6490. #ifdef WOLFSSL_SESSION_EXPORT
  6491. #ifdef WOLFSSL_DTLS
  6492. /* set up function for sending session information */
  6493. static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
  6494. {
  6495. WOLFSSL_CTX* ctx = NULL;
  6496. WOLFSSL* ssl = NULL;
  6497. AssertNotNull(inSsl);
  6498. AssertNotNull(buf);
  6499. AssertIntNE(0, sz);
  6500. /* Set ctx to DTLS 1.2 */
  6501. ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  6502. AssertNotNull(ctx);
  6503. ssl = wolfSSL_new(ctx);
  6504. AssertNotNull(ssl);
  6505. AssertIntGE(wolfSSL_dtls_import(ssl, buf, sz), 0);
  6506. wolfSSL_free(ssl);
  6507. wolfSSL_CTX_free(ctx);
  6508. (void)userCtx;
  6509. return 0;
  6510. }
  6511. #endif
  6512. /* returns negative value on fail and positive (including 0) on success */
  6513. static int nonblocking_accept_read(void* args, WOLFSSL* ssl, SOCKET_T* sockfd)
  6514. {
  6515. int ret, err, loop_count, count, timeout = 10;
  6516. char msg[] = "I hear you fa shizzle!";
  6517. char input[1024];
  6518. loop_count = ((func_args*)args)->argc;
  6519. #ifdef WOLFSSL_ASYNC_CRYPT
  6520. err = 0; /* Reset error */
  6521. #endif
  6522. do {
  6523. #ifdef WOLFSSL_ASYNC_CRYPT
  6524. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6525. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6526. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6527. }
  6528. #endif
  6529. ret = wolfSSL_accept(ssl);
  6530. err = wolfSSL_get_error(ssl, 0);
  6531. if (err == WOLFSSL_ERROR_WANT_READ ||
  6532. err == WOLFSSL_ERROR_WANT_WRITE) {
  6533. int select_ret;
  6534. err = WC_PENDING_E;
  6535. select_ret = tcp_select(*sockfd, timeout);
  6536. if (select_ret == TEST_TIMEOUT) {
  6537. return WOLFSSL_FATAL_ERROR;
  6538. }
  6539. }
  6540. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6541. if (ret != WOLFSSL_SUCCESS) {
  6542. char buff[WOLFSSL_MAX_ERROR_SZ];
  6543. fprintf(stderr, "error = %d, %s\n", err,
  6544. wolfSSL_ERR_error_string(err, buff));
  6545. return ret;
  6546. }
  6547. for (count = 0; count < loop_count; count++) {
  6548. int select_ret;
  6549. select_ret = tcp_select(*sockfd, timeout);
  6550. if (select_ret == TEST_TIMEOUT) {
  6551. ret = WOLFSSL_FATAL_ERROR;
  6552. break;
  6553. }
  6554. do {
  6555. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  6556. if (ret > 0) {
  6557. input[ret] = '\0';
  6558. fprintf(stderr, "Client message: %s\n", input);
  6559. }
  6560. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6561. do {
  6562. if ((ret = wolfSSL_write(ssl, msg, sizeof(msg))) != sizeof(msg)) {
  6563. return WOLFSSL_FATAL_ERROR;
  6564. }
  6565. err = wolfSSL_get_error(ssl, ret);
  6566. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6567. }
  6568. return ret;
  6569. }
  6570. #endif /* WOLFSSL_SESSION_EXPORT */
  6571. static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
  6572. {
  6573. SOCKET_T sockfd = 0;
  6574. SOCKET_T clientfd = 0;
  6575. word16 port;
  6576. callback_functions* cbf;
  6577. WOLFSSL_CTX* ctx = NULL;
  6578. WOLFSSL* ssl = NULL;
  6579. func_args* opts = (func_args*)args;
  6580. char msg[] = "I hear you fa shizzle!";
  6581. char input[1024];
  6582. int idx;
  6583. int ret, err = 0;
  6584. int sharedCtx = 0;
  6585. int doUdp = 0;
  6586. SOCKADDR_IN_T cliAddr;
  6587. socklen_t cliLen;
  6588. const char* certFile = svrCertFile;
  6589. const char* keyFile = svrKeyFile;
  6590. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6591. size_t msg_len = 0;
  6592. #endif
  6593. wolfSSL_SetLoggingPrefix("server");
  6594. #ifdef WOLFSSL_TIRTOS
  6595. fdOpenSession(Task_self());
  6596. #endif
  6597. opts->return_code = TEST_FAIL;
  6598. cbf = opts->callbacks;
  6599. if (cbf != NULL && cbf->ctx) {
  6600. ctx = cbf->ctx;
  6601. sharedCtx = 1;
  6602. }
  6603. else
  6604. {
  6605. WOLFSSL_METHOD* method = NULL;
  6606. if (cbf != NULL && cbf->method != NULL) {
  6607. method = cbf->method();
  6608. }
  6609. else {
  6610. method = wolfSSLv23_server_method();
  6611. }
  6612. ctx = wolfSSL_CTX_new(method);
  6613. }
  6614. if (ctx == NULL) {
  6615. /* Release the wait for TCP ready. */
  6616. signal_ready(opts->signal);
  6617. goto done;
  6618. }
  6619. if (cbf == NULL || !cbf->ticNoInit) {
  6620. #if defined(HAVE_SESSION_TICKET) && \
  6621. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6622. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6623. OpenSSLTicketInit();
  6624. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx, myTicketEncCbOpenSSL);
  6625. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6626. TicketInit();
  6627. wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
  6628. #endif
  6629. #endif
  6630. }
  6631. #if defined(USE_WINDOWS_API)
  6632. port = opts->signal->port;
  6633. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6634. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6635. /* Let tcp_listen assign port */
  6636. port = 0;
  6637. #else
  6638. /* Use default port */
  6639. port = wolfSSLPort;
  6640. #endif
  6641. if (cbf != NULL)
  6642. doUdp = cbf->doUdp;
  6643. /* do it here to detect failure */
  6644. tcp_accept(
  6645. &sockfd, &clientfd, opts, port, 0, doUdp, 0, 0, 1, 0, 0);
  6646. if (doUdp) {
  6647. cliLen = sizeof(cliAddr);
  6648. idx = (int)recvfrom(sockfd, input, sizeof(input), MSG_PEEK,
  6649. (struct sockaddr*)&cliAddr, &cliLen);
  6650. AssertIntGT(idx, 0);
  6651. }
  6652. else {
  6653. CloseSocket(sockfd);
  6654. }
  6655. wolfSSL_CTX_set_verify(ctx,
  6656. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6657. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6658. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6659. #endif
  6660. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6661. != WOLFSSL_SUCCESS) {
  6662. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6663. goto done;
  6664. }
  6665. if (cbf != NULL && cbf->certPemFile != NULL)
  6666. certFile = cbf->certPemFile;
  6667. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6668. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6669. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6670. #else
  6671. if (wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6672. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6673. #endif
  6674. /*err_sys("can't load server cert chain file, "
  6675. "Please run from wolfSSL home dir");*/
  6676. goto done;
  6677. }
  6678. if (cbf != NULL && cbf->keyPemFile != NULL)
  6679. keyFile = cbf->keyPemFile;
  6680. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6681. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6682. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6683. #else
  6684. if (wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6685. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6686. #endif
  6687. /*err_sys("can't load server key file, "
  6688. "Please run from wolfSSL home dir");*/
  6689. goto done;
  6690. }
  6691. #ifdef HAVE_CRL
  6692. if (cbf != NULL && cbf->crlPemFile != NULL) {
  6693. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  6694. goto done;
  6695. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  6696. != WOLFSSL_SUCCESS)
  6697. goto done;
  6698. }
  6699. #endif
  6700. /* call ctx setup callback */
  6701. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6702. cbf->ctx_ready(ctx);
  6703. }
  6704. ssl = wolfSSL_new(ctx);
  6705. if (ssl == NULL) {
  6706. goto done;
  6707. }
  6708. if (doUdp) {
  6709. err = wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  6710. if (err != WOLFSSL_SUCCESS)
  6711. goto done;
  6712. }
  6713. #ifdef WOLFSSL_SESSION_EXPORT
  6714. /* only add in more complex nonblocking case with session export tests */
  6715. if (args && opts->argc > 0) {
  6716. /* set as nonblock and time out for waiting on read/write */
  6717. tcp_set_nonblocking(&clientfd);
  6718. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  6719. }
  6720. #endif
  6721. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6722. if (sharedCtx && wolfSSL_use_certificate_file(ssl, certFile,
  6723. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6724. #else
  6725. if (wolfSSL_use_certificate_file(ssl, certFile,
  6726. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6727. #endif
  6728. /*err_sys("can't load server cert chain file, "
  6729. "Please run from wolfSSL home dir");*/
  6730. goto done;
  6731. }
  6732. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6733. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6734. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6735. #else
  6736. if (wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6737. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6738. #endif
  6739. /*err_sys("can't load server key file, "
  6740. "Please run from wolfSSL home dir");*/
  6741. goto done;
  6742. }
  6743. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6744. /*err_sys("SSL_set_fd failed");*/
  6745. goto done;
  6746. }
  6747. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6748. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6749. #elif !defined(NO_DH)
  6750. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6751. #endif
  6752. /* call ssl setup callback */
  6753. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6754. cbf->ssl_ready(ssl);
  6755. }
  6756. #ifdef WOLFSSL_SESSION_EXPORT
  6757. /* only add in more complex nonblocking case with session export tests */
  6758. if (opts->argc > 0) {
  6759. ret = nonblocking_accept_read(args, ssl, &clientfd);
  6760. if (ret >= 0) {
  6761. opts->return_code = TEST_SUCCESS;
  6762. }
  6763. #ifdef WOLFSSL_TIRTOS
  6764. Task_yield();
  6765. #endif
  6766. goto done;
  6767. }
  6768. #endif
  6769. #ifdef WOLFSSL_ASYNC_CRYPT
  6770. err = 0; /* Reset error */
  6771. #endif
  6772. do {
  6773. #ifdef WOLFSSL_ASYNC_CRYPT
  6774. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6775. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6776. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6777. }
  6778. #endif
  6779. ret = wolfSSL_negotiate(ssl);
  6780. err = wolfSSL_get_error(ssl, 0);
  6781. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6782. if (ret != WOLFSSL_SUCCESS) {
  6783. char buff[WOLFSSL_MAX_ERROR_SZ];
  6784. fprintf(stderr, "error = %d, %s\n", err,
  6785. wolfSSL_ERR_error_string(err, buff));
  6786. /*err_sys("SSL_accept failed");*/
  6787. goto done;
  6788. }
  6789. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6790. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6791. msg_len = wolfSSL_get_peer_finished(ssl, server_side_msg2, MD_MAX_SIZE);
  6792. AssertIntGE(msg_len, 0);
  6793. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6794. msg_len = wolfSSL_get_finished(ssl, server_side_msg1, MD_MAX_SIZE);
  6795. AssertIntGE(msg_len, 0);
  6796. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6797. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  6798. if (idx > 0) {
  6799. input[idx] = '\0';
  6800. fprintf(stderr, "Client message: %s\n", input);
  6801. }
  6802. else if (idx < 0) {
  6803. goto done;
  6804. }
  6805. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  6806. /*err_sys("SSL_write failed");*/
  6807. goto done;
  6808. }
  6809. if (cbf != NULL && cbf->on_result != NULL)
  6810. cbf->on_result(ssl);
  6811. #ifdef WOLFSSL_TIRTOS
  6812. Task_yield();
  6813. #endif
  6814. opts->return_code = TEST_SUCCESS;
  6815. done:
  6816. if (cbf != NULL)
  6817. cbf->last_err = err;
  6818. if (cbf != NULL && cbf->on_cleanup != NULL)
  6819. cbf->on_cleanup(ssl);
  6820. wolfSSL_shutdown(ssl);
  6821. wolfSSL_free(ssl);
  6822. if (!sharedCtx)
  6823. wolfSSL_CTX_free(ctx);
  6824. CloseSocket(clientfd);
  6825. #ifdef WOLFSSL_TIRTOS
  6826. fdCloseSession(Task_self());
  6827. #endif
  6828. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  6829. && defined(HAVE_THREAD_LS)
  6830. wc_ecc_fp_free(); /* free per thread cache */
  6831. #endif
  6832. if (cbf == NULL || !cbf->ticNoInit) {
  6833. #if defined(HAVE_SESSION_TICKET) && \
  6834. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6835. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6836. OpenSSLTicketCleanup();
  6837. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6838. TicketCleanup();
  6839. #endif
  6840. #endif
  6841. }
  6842. wolfSSL_SetLoggingPrefix(NULL);
  6843. WOLFSSL_RETURN_FROM_THREAD(0);
  6844. }
  6845. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  6846. !defined(WOLFSSL_NO_TLS12)
  6847. static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args)
  6848. {
  6849. SOCKET_T sockfd;
  6850. SOCKET_T clientfd = -1;
  6851. word16 port;
  6852. callback_functions* cbf;
  6853. WOLFSSL_CTX* ctx = 0;
  6854. WOLFSSL* ssl = 0;
  6855. char msg[] = "I hear you fa shizzle!";
  6856. char input[1024];
  6857. int idx;
  6858. int ret, err = 0;
  6859. int sharedCtx = 0;
  6860. func_args* opts = (func_args*)args;
  6861. int loop_count = opts->argc;
  6862. int count = 0;
  6863. #ifdef WOLFSSL_TIRTOS
  6864. fdOpenSession(Task_self());
  6865. #endif
  6866. opts->return_code = TEST_FAIL;
  6867. cbf = opts->callbacks;
  6868. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6869. if (cbf != NULL && cbf->ctx) {
  6870. ctx = cbf->ctx;
  6871. sharedCtx = 1;
  6872. }
  6873. else
  6874. #endif
  6875. {
  6876. WOLFSSL_METHOD* method = NULL;
  6877. if (cbf != NULL && cbf->method != NULL) {
  6878. method = cbf->method();
  6879. }
  6880. else {
  6881. method = wolfSSLv23_server_method();
  6882. }
  6883. ctx = wolfSSL_CTX_new(method);
  6884. }
  6885. #if defined(USE_WINDOWS_API)
  6886. port = opts->signal->port;
  6887. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6888. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6889. /* Let tcp_listen assign port */
  6890. port = 0;
  6891. #else
  6892. /* Use default port */
  6893. port = wolfSSLPort;
  6894. #endif
  6895. wolfSSL_CTX_set_verify(ctx,
  6896. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6897. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6898. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6899. #endif
  6900. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6901. != WOLFSSL_SUCCESS) {
  6902. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6903. /* Release the wait for TCP ready. */
  6904. signal_ready(opts->signal);
  6905. goto done;
  6906. }
  6907. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  6908. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6909. /*err_sys("can't load server cert chain file, "
  6910. "Please run from wolfSSL home dir");*/
  6911. /* Release the wait for TCP ready. */
  6912. signal_ready(opts->signal);
  6913. goto done;
  6914. }
  6915. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  6916. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6917. /*err_sys("can't load server key file, "
  6918. "Please run from wolfSSL home dir");*/
  6919. /* Release the wait for TCP ready. */
  6920. signal_ready(opts->signal);
  6921. goto done;
  6922. }
  6923. /* call ctx setup callback */
  6924. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6925. cbf->ctx_ready(ctx);
  6926. }
  6927. while (count != loop_count) {
  6928. ssl = wolfSSL_new(ctx);
  6929. if (ssl == NULL) {
  6930. signal_ready(opts->signal);
  6931. goto done;
  6932. }
  6933. if (sharedCtx && wolfSSL_use_certificate_file(ssl, svrCertFile,
  6934. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6935. /*err_sys("can't load server cert chain file, "
  6936. "Please run from wolfSSL home dir");*/
  6937. /* Release the wait for TCP ready. */
  6938. signal_ready(opts->signal);
  6939. goto done;
  6940. }
  6941. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  6942. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6943. /*err_sys("can't load server key file, "
  6944. "Please run from wolfSSL home dir");*/
  6945. /* Release the wait for TCP ready. */
  6946. signal_ready(opts->signal);
  6947. goto done;
  6948. }
  6949. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6950. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6951. #elif !defined(NO_DH)
  6952. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6953. #endif
  6954. /* call ssl setup callback */
  6955. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6956. cbf->ssl_ready(ssl);
  6957. }
  6958. /* do it here to detect failure */
  6959. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0,
  6960. 0);
  6961. CloseSocket(sockfd);
  6962. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6963. /*err_sys("SSL_set_fd failed");*/
  6964. goto done;
  6965. }
  6966. #ifdef WOLFSSL_ASYNC_CRYPT
  6967. err = 0; /* Reset error */
  6968. #endif
  6969. do {
  6970. #ifdef WOLFSSL_ASYNC_CRYPT
  6971. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6972. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6973. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6974. }
  6975. #endif
  6976. ret = wolfSSL_accept(ssl);
  6977. err = wolfSSL_get_error(ssl, 0);
  6978. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6979. if (ret != WOLFSSL_SUCCESS) {
  6980. char buff[WOLFSSL_MAX_ERROR_SZ];
  6981. fprintf(stderr, "error = %d, %s\n", err,
  6982. wolfSSL_ERR_error_string(err, buff));
  6983. /*err_sys("SSL_accept failed");*/
  6984. goto done;
  6985. }
  6986. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  6987. if (idx > 0) {
  6988. input[idx] = '\0';
  6989. fprintf(stderr, "Client message: %s\n", input);
  6990. }
  6991. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  6992. /*err_sys("SSL_write failed");*/
  6993. goto done;
  6994. }
  6995. /* free ssl for this connection */
  6996. wolfSSL_shutdown(ssl);
  6997. wolfSSL_free(ssl); ssl = NULL;
  6998. CloseSocket(clientfd);
  6999. clientfd = -1;
  7000. count++;
  7001. }
  7002. #ifdef WOLFSSL_TIRTOS
  7003. Task_yield();
  7004. #endif
  7005. opts->return_code = TEST_SUCCESS;
  7006. done:
  7007. if (ssl != NULL) {
  7008. wolfSSL_shutdown(ssl);
  7009. wolfSSL_free(ssl);
  7010. }
  7011. if (!sharedCtx)
  7012. wolfSSL_CTX_free(ctx);
  7013. if (clientfd >= 0)
  7014. CloseSocket(clientfd);
  7015. #ifdef WOLFSSL_TIRTOS
  7016. fdCloseSession(Task_self());
  7017. #endif
  7018. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7019. && defined(HAVE_THREAD_LS)
  7020. wc_ecc_fp_free(); /* free per thread cache */
  7021. #endif
  7022. WOLFSSL_RETURN_FROM_THREAD(0);
  7023. }
  7024. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && !defined(WOLFSSL_TLS13) */
  7025. static int test_client_nofail(void* args, cbType cb)
  7026. {
  7027. #if !defined(NO_WOLFSSL_CLIENT)
  7028. SOCKET_T sockfd = 0;
  7029. callback_functions* cbf;
  7030. WOLFSSL_CTX* ctx = 0;
  7031. WOLFSSL* ssl = 0;
  7032. WOLFSSL_CIPHER* cipher;
  7033. char msg[64] = "hello wolfssl!";
  7034. char reply[1024];
  7035. int input;
  7036. int msgSz = (int)XSTRLEN(msg);
  7037. int ret, err = 0;
  7038. int cipherSuite;
  7039. int sharedCtx = 0;
  7040. int doUdp = 0;
  7041. const char* cipherName1, *cipherName2;
  7042. wolfSSL_SetLoggingPrefix("client");
  7043. #ifdef WOLFSSL_TIRTOS
  7044. fdOpenSession(Task_self());
  7045. #endif
  7046. ((func_args*)args)->return_code = TEST_FAIL;
  7047. cbf = ((func_args*)args)->callbacks;
  7048. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7049. if (cbf != NULL && cbf->ctx) {
  7050. ctx = cbf->ctx;
  7051. sharedCtx = cbf->isSharedCtx;
  7052. }
  7053. else
  7054. #endif
  7055. {
  7056. WOLFSSL_METHOD* method = NULL;
  7057. if (cbf != NULL && cbf->method != NULL) {
  7058. method = cbf->method();
  7059. }
  7060. else {
  7061. method = wolfSSLv23_client_method();
  7062. }
  7063. ctx = wolfSSL_CTX_new(method);
  7064. }
  7065. if (cbf != NULL)
  7066. doUdp = cbf->doUdp;
  7067. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7068. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7069. #endif
  7070. /* Do connect here so server detects failures */
  7071. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7072. doUdp, 0, NULL);
  7073. /* Connect the socket so that we don't have to set the peer later on */
  7074. if (doUdp)
  7075. udp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port);
  7076. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) != WOLFSSL_SUCCESS)
  7077. {
  7078. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7079. goto done;
  7080. }
  7081. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7082. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7083. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7084. #else
  7085. if (wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7086. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7087. #endif
  7088. /*err_sys("can't load client cert file, "
  7089. "Please run from wolfSSL home dir");*/
  7090. goto done;
  7091. }
  7092. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7093. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7094. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7095. #else
  7096. if (wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7097. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7098. #endif
  7099. /*err_sys("can't load client key file, "
  7100. "Please run from wolfSSL home dir");*/
  7101. goto done;
  7102. }
  7103. #ifdef HAVE_CRL
  7104. if (cbf != NULL && cbf->crlPemFile != NULL) {
  7105. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  7106. goto done;
  7107. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  7108. != WOLFSSL_SUCCESS)
  7109. goto done;
  7110. }
  7111. #endif
  7112. /* call ctx setup callback */
  7113. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7114. cbf->ctx_ready(ctx);
  7115. }
  7116. ssl = wolfSSL_new(ctx);
  7117. if (ssl == NULL) {
  7118. goto done;
  7119. }
  7120. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7121. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7122. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7123. #else
  7124. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  7125. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7126. #endif
  7127. /*err_sys("can't load client cert file, "
  7128. "Please run from wolfSSL home dir");*/
  7129. goto done;
  7130. }
  7131. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7132. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7133. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7134. #else
  7135. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7136. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7137. #endif
  7138. /*err_sys("can't load client key file, "
  7139. "Please run from wolfSSL home dir");*/
  7140. goto done;
  7141. }
  7142. if (!doUdp) {
  7143. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7144. /*err_sys("SSL_set_fd failed");*/
  7145. goto done;
  7146. }
  7147. }
  7148. else {
  7149. #ifdef WOLFSSL_DTLS
  7150. if (wolfSSL_set_dtls_fd_connected(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7151. /*err_sys("SSL_set_fd failed");*/
  7152. goto done;
  7153. }
  7154. #else
  7155. goto done;
  7156. #endif
  7157. }
  7158. /* call ssl setup callback */
  7159. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7160. cbf->ssl_ready(ssl);
  7161. }
  7162. #ifdef WOLFSSL_ASYNC_CRYPT
  7163. err = 0; /* Reset error */
  7164. #endif
  7165. do {
  7166. #ifdef WOLFSSL_ASYNC_CRYPT
  7167. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7168. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7169. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7170. }
  7171. #endif
  7172. ret = wolfSSL_negotiate(ssl);
  7173. err = wolfSSL_get_error(ssl, 0);
  7174. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7175. if (ret != WOLFSSL_SUCCESS) {
  7176. char buff[WOLFSSL_MAX_ERROR_SZ];
  7177. fprintf(stderr, "error = %d, %s\n", err,
  7178. wolfSSL_ERR_error_string(err, buff));
  7179. /*err_sys("SSL_connect failed");*/
  7180. goto done;
  7181. }
  7182. /* test the various get cipher methods */
  7183. /* Internal cipher suite names */
  7184. cipherSuite = wolfSSL_get_current_cipher_suite(ssl);
  7185. cipherName1 = wolfSSL_get_cipher_name(ssl);
  7186. cipherName2 = wolfSSL_get_cipher_name_from_suite(
  7187. (cipherSuite >> 8), cipherSuite & 0xFF);
  7188. AssertStrEQ(cipherName1, cipherName2);
  7189. /* IANA Cipher Suites Names */
  7190. /* Unless WOLFSSL_CIPHER_INTERNALNAME or NO_ERROR_STRINGS,
  7191. then it's the internal cipher suite name */
  7192. cipher = wolfSSL_get_current_cipher(ssl);
  7193. cipherName1 = wolfSSL_CIPHER_get_name(cipher);
  7194. cipherName2 = wolfSSL_get_cipher(ssl);
  7195. AssertStrEQ(cipherName1, cipherName2);
  7196. #if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
  7197. !defined(WOLFSSL_QT)
  7198. cipherName1 = wolfSSL_get_cipher_name_iana_from_suite(
  7199. (cipherSuite >> 8), cipherSuite & 0xFF);
  7200. AssertStrEQ(cipherName1, cipherName2);
  7201. #endif
  7202. if (cb != NULL)
  7203. (cb)(ctx, ssl);
  7204. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7205. /*err_sys("SSL_write failed");*/
  7206. goto done;
  7207. }
  7208. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7209. if (input > 0) {
  7210. reply[input] = '\0';
  7211. fprintf(stderr, "Server response: %s\n", reply);
  7212. }
  7213. if (cbf != NULL && cbf->on_result != NULL)
  7214. cbf->on_result(ssl);
  7215. ((func_args*)args)->return_code = TEST_SUCCESS;
  7216. done:
  7217. if (cbf != NULL)
  7218. cbf->last_err = err;
  7219. if (cbf != NULL && cbf->on_cleanup != NULL)
  7220. cbf->on_cleanup(ssl);
  7221. wolfSSL_free(ssl);
  7222. if (!sharedCtx)
  7223. wolfSSL_CTX_free(ctx);
  7224. CloseSocket(sockfd);
  7225. #ifdef WOLFSSL_TIRTOS
  7226. fdCloseSession(Task_self());
  7227. #endif
  7228. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7229. && defined(HAVE_THREAD_LS)
  7230. wc_ecc_fp_free(); /* free per thread cache */
  7231. #endif
  7232. #else
  7233. (void)args;
  7234. (void)cb;
  7235. #endif /* !NO_WOLFSSL_CLIENT */
  7236. wolfSSL_SetLoggingPrefix(NULL);
  7237. return 0;
  7238. }
  7239. void test_wolfSSL_client_server_nofail_ex(callback_functions* client_cb,
  7240. callback_functions* server_cb, cbType client_on_handshake)
  7241. {
  7242. func_args client_args;
  7243. func_args server_args;
  7244. tcp_ready ready;
  7245. THREAD_TYPE serverThread;
  7246. XMEMSET(&client_args, 0, sizeof(func_args));
  7247. XMEMSET(&server_args, 0, sizeof(func_args));
  7248. #ifdef WOLFSSL_TIRTOS
  7249. fdOpenSession(Task_self());
  7250. #endif
  7251. StartTCP();
  7252. InitTcpReady(&ready);
  7253. #if defined(USE_WINDOWS_API)
  7254. /* use RNG to get random port if using windows */
  7255. ready.port = GetRandomPort();
  7256. #endif
  7257. server_args.signal = &ready;
  7258. server_args.callbacks = server_cb;
  7259. client_args.signal = &ready;
  7260. client_args.callbacks = client_cb;
  7261. start_thread(test_server_nofail, &server_args, &serverThread);
  7262. wait_tcp_ready(&server_args);
  7263. test_client_nofail(&client_args, client_on_handshake);
  7264. join_thread(serverThread);
  7265. client_cb->return_code = client_args.return_code;
  7266. server_cb->return_code = server_args.return_code;
  7267. FreeTcpReady(&ready);
  7268. #ifdef WOLFSSL_TIRTOS
  7269. fdOpenSession(Task_self());
  7270. #endif
  7271. }
  7272. void test_wolfSSL_client_server_nofail(callback_functions* client_cb,
  7273. callback_functions* server_cb)
  7274. {
  7275. test_wolfSSL_client_server_nofail_ex(client_cb, server_cb, NULL);
  7276. }
  7277. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7278. !defined(WOLFSSL_NO_TLS12) && !defined(NO_WOLFSSL_CLIENT)
  7279. static void test_client_reuse_WOLFSSLobj(void* args, cbType cb,
  7280. void* server_args)
  7281. {
  7282. SOCKET_T sockfd = 0;
  7283. callback_functions* cbf;
  7284. WOLFSSL_CTX* ctx = 0;
  7285. WOLFSSL* ssl = 0;
  7286. WOLFSSL_SESSION* session = NULL;
  7287. char msg[64] = "hello wolfssl!";
  7288. char reply[1024];
  7289. int input;
  7290. int msgSz = (int)XSTRLEN(msg);
  7291. int ret, err = 0;
  7292. int sharedCtx = 0;
  7293. #ifdef WOLFSSL_TIRTOS
  7294. fdOpenSession(Task_self());
  7295. #endif
  7296. ((func_args*)args)->return_code = TEST_FAIL;
  7297. cbf = ((func_args*)args)->callbacks;
  7298. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7299. if (cbf != NULL && cbf->ctx) {
  7300. ctx = cbf->ctx;
  7301. sharedCtx = 1;
  7302. }
  7303. else
  7304. #endif
  7305. {
  7306. WOLFSSL_METHOD* method = NULL;
  7307. if (cbf != NULL && cbf->method != NULL) {
  7308. method = cbf->method();
  7309. }
  7310. else {
  7311. method = wolfSSLv23_client_method();
  7312. }
  7313. ctx = wolfSSL_CTX_new(method);
  7314. }
  7315. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7316. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7317. #endif
  7318. /* Do connect here so server detects failures */
  7319. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7320. 0, 0, NULL);
  7321. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) !=
  7322. WOLFSSL_SUCCESS) {
  7323. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7324. goto done;
  7325. }
  7326. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7327. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7328. /*err_sys("can't load client cert file, "
  7329. "Please run from wolfSSL home dir");*/
  7330. goto done;
  7331. }
  7332. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7333. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7334. /*err_sys("can't load client key file, "
  7335. "Please run from wolfSSL home dir");*/
  7336. goto done;
  7337. }
  7338. /* call ctx setup callback */
  7339. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7340. cbf->ctx_ready(ctx);
  7341. }
  7342. ssl = wolfSSL_new(ctx);
  7343. if (ssl == NULL) {
  7344. goto done;
  7345. }
  7346. /* keep handshake resources for re-using WOLFSSL obj */
  7347. wolfSSL_KeepArrays(ssl);
  7348. if (wolfSSL_KeepHandshakeResources(ssl)) {
  7349. /* err_sys("SSL_KeepHandshakeResources failed"); */
  7350. goto done;
  7351. }
  7352. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7353. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7354. /*err_sys("can't load client cert file, "
  7355. "Please run from wolfSSL home dir");*/
  7356. goto done;
  7357. }
  7358. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7359. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7360. /*err_sys("can't load client key file, "
  7361. "Please run from wolfSSL home dir");*/
  7362. goto done;
  7363. }
  7364. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7365. /*err_sys("SSL_set_fd failed");*/
  7366. goto done;
  7367. }
  7368. /* call ssl setup callback */
  7369. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7370. cbf->ssl_ready(ssl);
  7371. }
  7372. #ifdef WOLFSSL_ASYNC_CRYPT
  7373. err = 0; /* Reset error */
  7374. #endif
  7375. do {
  7376. #ifdef WOLFSSL_ASYNC_CRYPT
  7377. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7378. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7379. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7380. }
  7381. #endif
  7382. ret = wolfSSL_connect(ssl);
  7383. err = wolfSSL_get_error(ssl, 0);
  7384. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7385. if (ret != WOLFSSL_SUCCESS) {
  7386. char buff[WOLFSSL_MAX_ERROR_SZ];
  7387. fprintf(stderr, "error = %d, %s\n", err,
  7388. wolfSSL_ERR_error_string(err, buff));
  7389. /*err_sys("SSL_connect failed");*/
  7390. goto done;
  7391. }
  7392. /* Build first session */
  7393. if (cb != NULL)
  7394. cb(ctx, ssl);
  7395. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7396. /*err_sys("SSL_write failed");*/
  7397. goto done;
  7398. }
  7399. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7400. if (input > 0) {
  7401. reply[input] = '\0';
  7402. fprintf(stderr, "Server response: %s\n", reply);
  7403. }
  7404. /* Session Resumption by re-using WOLFSSL object */
  7405. wolfSSL_set_quiet_shutdown(ssl, 1);
  7406. if (wolfSSL_shutdown(ssl) != WOLFSSL_SUCCESS) {
  7407. /* err_sys ("SSL shutdown failed"); */
  7408. goto done;
  7409. }
  7410. session = wolfSSL_get1_session(ssl);
  7411. if (wolfSSL_clear(ssl) != WOLFSSL_SUCCESS) {
  7412. wolfSSL_SESSION_free(session);
  7413. /* err_sys ("SSL_clear failed"); */
  7414. goto done;
  7415. }
  7416. wolfSSL_set_session(ssl, session);
  7417. wolfSSL_SESSION_free(session);
  7418. session = NULL;
  7419. /* close socket once */
  7420. CloseSocket(sockfd);
  7421. sockfd = 0;
  7422. /* wait until server ready */
  7423. wait_tcp_ready((func_args*)server_args);
  7424. fprintf(stderr, "session resumption\n");
  7425. /* Do re-connect */
  7426. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7427. 0, 0, NULL);
  7428. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7429. /*err_sys("SSL_set_fd failed");*/
  7430. goto done;
  7431. }
  7432. #ifdef WOLFSSL_ASYNC_CRYPT
  7433. err = 0; /* Reset error */
  7434. #endif
  7435. do {
  7436. #ifdef WOLFSSL_ASYNC_CRYPT
  7437. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7438. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7439. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7440. }
  7441. #endif
  7442. ret = wolfSSL_connect(ssl);
  7443. err = wolfSSL_get_error(ssl, 0);
  7444. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7445. if (ret != WOLFSSL_SUCCESS) {
  7446. char buff[WOLFSSL_MAX_ERROR_SZ];
  7447. fprintf(stderr, "error = %d, %s\n", err,
  7448. wolfSSL_ERR_error_string(err, buff));
  7449. /*err_sys("SSL_connect failed");*/
  7450. goto done;
  7451. }
  7452. /* Build first session */
  7453. if (cb != NULL)
  7454. cb(ctx, ssl);
  7455. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7456. /*err_sys("SSL_write failed");*/
  7457. goto done;
  7458. }
  7459. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7460. if (input > 0) {
  7461. reply[input] = '\0';
  7462. fprintf(stderr, "Server response: %s\n", reply);
  7463. }
  7464. ((func_args*)args)->return_code = TEST_SUCCESS;
  7465. done:
  7466. wolfSSL_free(ssl);
  7467. if (!sharedCtx)
  7468. wolfSSL_CTX_free(ctx);
  7469. CloseSocket(sockfd);
  7470. #ifdef WOLFSSL_TIRTOS
  7471. fdCloseSession(Task_self());
  7472. #endif
  7473. return;
  7474. }
  7475. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  7476. !defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) */
  7477. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  7478. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)) && \
  7479. defined(HAVE_ALPN) && defined(HAVE_SNI) && \
  7480. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_BIO)
  7481. #define HAVE_ALPN_PROTOS_SUPPORT
  7482. #endif
  7483. /* Generic TLS client / server with callbacks for API unit tests
  7484. * Used by SNI / ALPN / crypto callback helper functions */
  7485. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  7486. (defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLF_CRYPTO_CB) || \
  7487. defined(HAVE_ALPN_PROTOS_SUPPORT)) || defined(WOLFSSL_STATIC_MEMORY)
  7488. #define ENABLE_TLS_CALLBACK_TEST
  7489. #endif
  7490. #if defined(ENABLE_TLS_CALLBACK_TEST) || \
  7491. (defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT))
  7492. /* TLS server for API unit testing - generic */
  7493. static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
  7494. {
  7495. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7496. WOLFSSL_CTX* ctx = NULL;
  7497. WOLFSSL* ssl = NULL;
  7498. SOCKET_T sfd = 0;
  7499. SOCKET_T cfd = 0;
  7500. word16 port;
  7501. char msg[] = "I hear you fa shizzle!";
  7502. int len = (int) XSTRLEN(msg);
  7503. char input[1024];
  7504. int idx;
  7505. int ret, err = 0;
  7506. ((func_args*)args)->return_code = TEST_FAIL;
  7507. #if defined(USE_WINDOWS_API)
  7508. port = ((func_args*)args)->signal->port;
  7509. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7510. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7511. /* Let tcp_listen assign port */
  7512. port = 0;
  7513. #else
  7514. /* Use default port */
  7515. port = wolfSSLPort;
  7516. #endif
  7517. #ifdef WOLFSSL_DTLS
  7518. if (callbacks->method == wolfDTLS_server_method
  7519. #ifdef WOLFSSL_STATIC_MEMORY
  7520. || callbacks->method_ex == wolfDTLS_server_method_ex
  7521. #endif
  7522. #ifndef NO_OLD_TLS
  7523. || callbacks->method == wolfDTLSv1_server_method
  7524. #ifdef WOLFSSL_STATIC_MEMORY
  7525. || callbacks->method_ex == wolfDTLSv1_server_method_ex
  7526. #endif
  7527. #endif
  7528. #ifndef WOLFSSL_NO_TLS12
  7529. || callbacks->method == wolfDTLSv1_2_server_method
  7530. #ifdef WOLFSSL_STATIC_MEMORY
  7531. || callbacks->method_ex == wolfDTLSv1_2_server_method_ex
  7532. #endif
  7533. #endif
  7534. #ifdef WOLFSSL_DTLS13
  7535. || callbacks->method == wolfDTLSv1_3_server_method
  7536. #ifdef WOLFSSL_STATIC_MEMORY
  7537. || callbacks->method_ex == wolfDTLSv1_3_server_method_ex
  7538. #endif
  7539. #endif
  7540. ) {
  7541. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 1, 0, 0, 0, 0, 0);
  7542. }
  7543. else
  7544. #endif
  7545. {
  7546. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  7547. }
  7548. #ifdef WOLFSSL_STATIC_MEMORY
  7549. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7550. callbacks->memSz > 0) {
  7551. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7552. callbacks->mem, callbacks->memSz, 0, 1);
  7553. if (ret != WOLFSSL_SUCCESS) {
  7554. fprintf(stderr, "CTX static new failed %d\n", ret);
  7555. goto cleanup;
  7556. }
  7557. }
  7558. #else
  7559. ctx = wolfSSL_CTX_new(callbacks->method());
  7560. #endif
  7561. if (ctx == NULL) {
  7562. fprintf(stderr, "CTX new failed\n");
  7563. goto cleanup;
  7564. }
  7565. /* set defaults */
  7566. if (callbacks->caPemFile == NULL)
  7567. callbacks->caPemFile = cliCertFile;
  7568. if (callbacks->certPemFile == NULL)
  7569. callbacks->certPemFile = svrCertFile;
  7570. if (callbacks->keyPemFile == NULL)
  7571. callbacks->keyPemFile = svrKeyFile;
  7572. #ifdef WOLFSSL_TIRTOS
  7573. fdOpenSession(Task_self());
  7574. #endif
  7575. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7576. wolfSSL_CTX_set_verify(ctx,
  7577. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7578. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7579. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7580. #endif
  7581. #if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
  7582. if (callbacks->method == wolfDTLSv1_2_server_method) {
  7583. if (wolfSSL_CTX_dtls_set_export(ctx, test_export) != WOLFSSL_SUCCESS)
  7584. goto cleanup;
  7585. }
  7586. #endif
  7587. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7588. WOLFSSL_SUCCESS) {
  7589. goto cleanup;
  7590. }
  7591. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7592. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7593. goto cleanup;
  7594. }
  7595. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7596. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7597. goto cleanup;
  7598. }
  7599. #ifdef HAVE_CRL
  7600. if (callbacks->crlPemFile != NULL) {
  7601. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7602. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7603. goto cleanup;
  7604. }
  7605. }
  7606. #endif
  7607. if (callbacks->ctx_ready)
  7608. callbacks->ctx_ready(ctx);
  7609. ssl = wolfSSL_new(ctx);
  7610. if (ssl == NULL) {
  7611. fprintf(stderr, "SSL new failed\n");
  7612. goto cleanup;
  7613. }
  7614. if (wolfSSL_dtls(ssl)) {
  7615. SOCKADDR_IN_T cliAddr;
  7616. socklen_t cliLen;
  7617. cliLen = sizeof(cliAddr);
  7618. idx = (int)recvfrom(sfd, input, sizeof(input), MSG_PEEK,
  7619. (struct sockaddr*)&cliAddr, &cliLen);
  7620. if (idx <= 0) {
  7621. goto cleanup;
  7622. }
  7623. wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  7624. }
  7625. else {
  7626. CloseSocket(sfd);
  7627. }
  7628. if (wolfSSL_set_fd(ssl, cfd) != WOLFSSL_SUCCESS) {
  7629. goto cleanup;
  7630. }
  7631. if (callbacks->loadToSSL) {
  7632. wolfSSL_SetDevId(ssl, callbacks->devId);
  7633. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7634. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7635. goto cleanup;
  7636. }
  7637. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7638. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7639. goto cleanup;
  7640. }
  7641. }
  7642. #ifdef NO_PSK
  7643. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7644. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7645. #elif !defined(NO_DH)
  7646. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7647. #endif
  7648. #endif
  7649. if (callbacks->ssl_ready)
  7650. callbacks->ssl_ready(ssl);
  7651. #ifdef WOLFSSL_ASYNC_CRYPT
  7652. err = 0; /* Reset error */
  7653. #endif
  7654. do {
  7655. #ifdef WOLFSSL_ASYNC_CRYPT
  7656. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7657. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7658. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7659. }
  7660. #endif
  7661. ret = wolfSSL_accept(ssl);
  7662. err = wolfSSL_get_error(ssl, ret);
  7663. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7664. if (ret != WOLFSSL_SUCCESS) {
  7665. char buff[WOLFSSL_MAX_ERROR_SZ];
  7666. fprintf(stderr, "accept error = %d, %s\n", err,
  7667. wolfSSL_ERR_error_string(err, buff));
  7668. /*err_sys("SSL_accept failed");*/
  7669. }
  7670. else {
  7671. #ifdef WOLFSSL_ASYNC_CRYPT
  7672. err = 0; /* Reset error */
  7673. #endif
  7674. do {
  7675. #ifdef WOLFSSL_ASYNC_CRYPT
  7676. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7677. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7678. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7679. }
  7680. #endif
  7681. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7682. err = wolfSSL_get_error(ssl, idx);
  7683. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7684. if (idx > 0) {
  7685. input[idx] = 0;
  7686. fprintf(stderr, "Client message: %s\n", input);
  7687. }
  7688. #ifdef WOLFSSL_ASYNC_CRYPT
  7689. err = 0; /* Reset error */
  7690. #endif
  7691. do {
  7692. #ifdef WOLFSSL_ASYNC_CRYPT
  7693. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7694. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7695. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7696. }
  7697. #endif
  7698. ret = wolfSSL_write(ssl, msg, len);
  7699. err = wolfSSL_get_error(ssl, ret);
  7700. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7701. if (len != ret) {
  7702. goto cleanup;
  7703. }
  7704. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL) && \
  7705. defined(WOLFSSL_DTLS)
  7706. if (wolfSSL_dtls(ssl)) {
  7707. byte* import;
  7708. word32 sz;
  7709. wolfSSL_dtls_export(ssl, NULL, &sz);
  7710. import = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7711. if (import == NULL) {
  7712. goto cleanup;
  7713. }
  7714. idx = wolfSSL_dtls_export(ssl, import, &sz);
  7715. if (idx < 0) {
  7716. goto cleanup;
  7717. }
  7718. if (wolfSSL_dtls_import(ssl, import, idx) < 0) {
  7719. goto cleanup;
  7720. }
  7721. XFREE(import, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7722. }
  7723. #endif
  7724. #ifdef WOLFSSL_TIRTOS
  7725. Task_yield();
  7726. #endif
  7727. ((func_args*)args)->return_code = TEST_SUCCESS;
  7728. }
  7729. if (callbacks->on_result)
  7730. callbacks->on_result(ssl);
  7731. wolfSSL_shutdown(ssl);
  7732. cleanup:
  7733. wolfSSL_free(ssl);
  7734. wolfSSL_CTX_free(ctx);
  7735. CloseSocket(cfd);
  7736. #ifdef WOLFSSL_TIRTOS
  7737. fdCloseSession(Task_self());
  7738. #endif
  7739. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7740. && defined(HAVE_THREAD_LS)
  7741. wc_ecc_fp_free(); /* free per thread cache */
  7742. #endif
  7743. WOLFSSL_RETURN_FROM_THREAD(0);
  7744. }
  7745. /* TLS Client for API unit testing - generic */
  7746. static void run_wolfssl_client(void* args)
  7747. {
  7748. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7749. WOLFSSL_CTX* ctx = NULL;
  7750. WOLFSSL* ssl = NULL;
  7751. SOCKET_T sfd = 0;
  7752. char msg[] = "hello wolfssl server!";
  7753. int len = (int) XSTRLEN(msg);
  7754. char input[1024];
  7755. int ret, err = 0;
  7756. ((func_args*)args)->return_code = TEST_FAIL;
  7757. /* set defaults */
  7758. if (callbacks->caPemFile == NULL)
  7759. callbacks->caPemFile = caCertFile;
  7760. if (callbacks->certPemFile == NULL)
  7761. callbacks->certPemFile = cliCertFile;
  7762. if (callbacks->keyPemFile == NULL)
  7763. callbacks->keyPemFile = cliKeyFile;
  7764. #ifdef WOLFSSL_STATIC_MEMORY
  7765. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7766. callbacks->memSz > 0) {
  7767. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7768. callbacks->mem, callbacks->memSz, 0, 1);
  7769. if (ret != WOLFSSL_SUCCESS) {
  7770. fprintf(stderr, "CTX static new failed %d\n", ret);
  7771. goto cleanup;
  7772. }
  7773. }
  7774. #else
  7775. ctx = wolfSSL_CTX_new(callbacks->method());
  7776. #endif
  7777. if (ctx == NULL) {
  7778. fprintf(stderr, "CTX new failed\n");
  7779. goto cleanup;
  7780. }
  7781. #ifdef WOLFSSL_TIRTOS
  7782. fdOpenSession(Task_self());
  7783. #endif
  7784. if (!callbacks->loadToSSL) {
  7785. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7786. }
  7787. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7788. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7789. #endif
  7790. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7791. WOLFSSL_SUCCESS) {
  7792. goto cleanup;
  7793. }
  7794. if (!callbacks->loadToSSL) {
  7795. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7796. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7797. goto cleanup;
  7798. }
  7799. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7800. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7801. goto cleanup;
  7802. }
  7803. }
  7804. #ifdef HAVE_CRL
  7805. if (callbacks->crlPemFile != NULL) {
  7806. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7807. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7808. goto cleanup;
  7809. }
  7810. }
  7811. #endif
  7812. if (callbacks->ctx_ready)
  7813. callbacks->ctx_ready(ctx);
  7814. ssl = wolfSSL_new(ctx);
  7815. if (wolfSSL_dtls(ssl)) {
  7816. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7817. 1, 0, ssl);
  7818. }
  7819. else {
  7820. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7821. 0, 0, ssl);
  7822. }
  7823. if (wolfSSL_set_fd(ssl, sfd) != WOLFSSL_SUCCESS) {
  7824. goto cleanup;
  7825. }
  7826. if (callbacks->loadToSSL) {
  7827. wolfSSL_SetDevId(ssl, callbacks->devId);
  7828. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7829. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7830. goto cleanup;
  7831. }
  7832. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7833. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7834. goto cleanup;
  7835. }
  7836. }
  7837. if (callbacks->ssl_ready)
  7838. callbacks->ssl_ready(ssl);
  7839. #ifdef WOLFSSL_ASYNC_CRYPT
  7840. err = 0; /* Reset error */
  7841. #endif
  7842. do {
  7843. #ifdef WOLFSSL_ASYNC_CRYPT
  7844. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7845. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7846. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7847. }
  7848. #endif
  7849. ret = wolfSSL_connect(ssl);
  7850. err = wolfSSL_get_error(ssl, ret);
  7851. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7852. if (ret != WOLFSSL_SUCCESS) {
  7853. char buff[WOLFSSL_MAX_ERROR_SZ];
  7854. fprintf(stderr, "error = %d, %s\n", err,
  7855. wolfSSL_ERR_error_string(err, buff));
  7856. /*err_sys("SSL_connect failed");*/
  7857. }
  7858. else {
  7859. #ifdef WOLFSSL_ASYNC_CRYPT
  7860. err = 0; /* Reset error */
  7861. #endif
  7862. do {
  7863. #ifdef WOLFSSL_ASYNC_CRYPT
  7864. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7865. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7866. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7867. }
  7868. #endif
  7869. ret = wolfSSL_write(ssl, msg, len);
  7870. err = wolfSSL_get_error(ssl, ret);
  7871. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7872. if (len != ret)
  7873. goto cleanup;
  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_read(ssl, input, sizeof(input)-1);
  7885. err = wolfSSL_get_error(ssl, ret);
  7886. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7887. if (ret > 0) {
  7888. input[ret] = '\0'; /* null term */
  7889. fprintf(stderr, "Server response: %s\n", input);
  7890. }
  7891. ((func_args*)args)->return_code = TEST_SUCCESS;
  7892. }
  7893. if (callbacks->on_result)
  7894. callbacks->on_result(ssl);
  7895. cleanup:
  7896. wolfSSL_free(ssl);
  7897. wolfSSL_CTX_free(ctx);
  7898. CloseSocket(sfd);
  7899. #ifdef WOLFSSL_TIRTOS
  7900. fdCloseSession(Task_self());
  7901. #endif
  7902. }
  7903. #endif /* ENABLE_TLS_CALLBACK_TEST */
  7904. static int test_wolfSSL_read_write(void)
  7905. {
  7906. /* The unit testing for read and write shall happen simultaneously, since
  7907. * one can't do anything with one without the other. (Except for a failure
  7908. * test case.) This function will call all the others that will set up,
  7909. * execute, and report their test findings.
  7910. *
  7911. * Set up the success case first. This function will become the template
  7912. * for the other tests. This should eventually be renamed
  7913. *
  7914. * The success case isn't interesting, how can this fail?
  7915. * - Do not give the client context a CA certificate. The connect should
  7916. * fail. Do not need server for this?
  7917. * - Using NULL for the ssl object on server. Do not need client for this.
  7918. * - Using NULL for the ssl object on client. Do not need server for this.
  7919. * - Good ssl objects for client and server. Client write() without server
  7920. * read().
  7921. * - Good ssl objects for client and server. Server write() without client
  7922. * read().
  7923. * - Forgetting the password callback?
  7924. */
  7925. tcp_ready ready;
  7926. func_args client_args;
  7927. func_args server_args;
  7928. THREAD_TYPE serverThread;
  7929. EXPECT_DECLS;
  7930. XMEMSET(&client_args, 0, sizeof(func_args));
  7931. XMEMSET(&server_args, 0, sizeof(func_args));
  7932. #ifdef WOLFSSL_TIRTOS
  7933. fdOpenSession(Task_self());
  7934. #endif
  7935. StartTCP();
  7936. InitTcpReady(&ready);
  7937. #if defined(USE_WINDOWS_API)
  7938. /* use RNG to get random port if using windows */
  7939. ready.port = GetRandomPort();
  7940. #endif
  7941. server_args.signal = &ready;
  7942. client_args.signal = &ready;
  7943. start_thread(test_server_nofail, &server_args, &serverThread);
  7944. wait_tcp_ready(&server_args);
  7945. test_client_nofail(&client_args, NULL);
  7946. join_thread(serverThread);
  7947. ExpectTrue(client_args.return_code);
  7948. ExpectTrue(server_args.return_code);
  7949. FreeTcpReady(&ready);
  7950. #ifdef WOLFSSL_TIRTOS
  7951. fdOpenSession(Task_self());
  7952. #endif
  7953. return EXPECT_RESULT();
  7954. }
  7955. static int test_wolfSSL_reuse_WOLFSSLobj(void)
  7956. {
  7957. EXPECT_DECLS;
  7958. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7959. !defined(WOLFSSL_NO_TLS12)
  7960. /* The unit test for session resumption by re-using WOLFSSL object.
  7961. * WOLFSSL object is not cleared after first session. It reuse the object
  7962. * for second connection.
  7963. */
  7964. tcp_ready ready;
  7965. func_args client_args;
  7966. func_args server_args;
  7967. THREAD_TYPE serverThread;
  7968. callback_functions client_cbf;
  7969. callback_functions server_cbf;
  7970. XMEMSET(&client_args, 0, sizeof(func_args));
  7971. XMEMSET(&server_args, 0, sizeof(func_args));
  7972. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  7973. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  7974. #ifdef WOLFSSL_TIRTOS
  7975. fdOpenSession(Task_self());
  7976. #endif
  7977. StartTCP();
  7978. InitTcpReady(&ready);
  7979. #if defined(USE_WINDOWS_API)
  7980. /* use RNG to get random port if using windows */
  7981. ready.port = GetRandomPort();
  7982. #endif
  7983. client_cbf.method = wolfTLSv1_2_client_method;
  7984. server_cbf.method = wolfTLSv1_2_server_method;
  7985. client_args.callbacks = &client_cbf;
  7986. server_args.callbacks = &server_cbf;
  7987. server_args.signal = &ready;
  7988. client_args.signal = &ready;
  7989. /* the var is used for loop number */
  7990. server_args.argc = 2;
  7991. start_thread(test_server_loop, &server_args, &serverThread);
  7992. wait_tcp_ready(&server_args);
  7993. test_client_reuse_WOLFSSLobj(&client_args, NULL, &server_args);
  7994. join_thread(serverThread);
  7995. ExpectTrue(client_args.return_code);
  7996. ExpectTrue(server_args.return_code);
  7997. FreeTcpReady(&ready);
  7998. #ifdef WOLFSSL_TIRTOS
  7999. fdOpenSession(Task_self());
  8000. #endif
  8001. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  8002. * !defined(WOLFSSL_TLS13) */
  8003. return EXPECT_RESULT();
  8004. }
  8005. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8006. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready(
  8007. WOLFSSL_CTX* ctx)
  8008. {
  8009. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8010. myVerifyAction = VERIFY_USE_PREVERFIY;
  8011. wolfSSL_CTX_set_verify_depth(ctx, 2);
  8012. return TEST_SUCCESS;
  8013. }
  8014. #endif
  8015. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1(void)
  8016. {
  8017. EXPECT_DECLS;
  8018. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8019. test_ssl_cbf client_cbf;
  8020. test_ssl_cbf server_cbf;
  8021. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8022. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8023. #ifdef WOLFSSL_TLS13
  8024. client_cbf.method = wolfTLSv1_3_client_method;
  8025. #endif /* WOLFSSL_TLS13 */
  8026. client_cbf.ctx_ready =
  8027. test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready;
  8028. /* test case 1 verify depth is equal to peer chain */
  8029. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8030. &server_cbf, NULL), TEST_SUCCESS);
  8031. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8032. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8033. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8034. return EXPECT_RESULT();
  8035. }
  8036. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8037. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready(
  8038. WOLFSSL_CTX* ctx)
  8039. {
  8040. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8041. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  8042. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8043. return TEST_SUCCESS;
  8044. }
  8045. #endif
  8046. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2(void)
  8047. {
  8048. EXPECT_DECLS;
  8049. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8050. test_ssl_cbf client_cbf;
  8051. test_ssl_cbf server_cbf;
  8052. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8053. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8054. #ifdef WOLFSSL_TLS13
  8055. client_cbf.method = wolfTLSv1_3_client_method;
  8056. #endif /* WOLFSSL_TLS13 */
  8057. client_cbf.ctx_ready =
  8058. test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready;
  8059. /* test case 2
  8060. * verify depth is zero, number of peer's chain is 2.
  8061. * verify result becomes MAX_CHAIN_ERROR, but it is overridden in
  8062. * callback.
  8063. */
  8064. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8065. &server_cbf, NULL), TEST_SUCCESS);
  8066. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8067. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8068. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8069. return EXPECT_RESULT();
  8070. }
  8071. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8072. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready(
  8073. WOLFSSL_CTX* ctx)
  8074. {
  8075. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8076. myVerifyAction = VERIFY_USE_PREVERFIY;
  8077. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8078. return TEST_SUCCESS;
  8079. }
  8080. #endif
  8081. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3(void)
  8082. {
  8083. EXPECT_DECLS;
  8084. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8085. test_ssl_cbf client_cbf;
  8086. test_ssl_cbf server_cbf;
  8087. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8088. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8089. #ifdef WOLFSSL_TLS13
  8090. client_cbf.method = wolfTLSv1_3_client_method;
  8091. #endif /* WOLFSSL_TLS13 */
  8092. client_cbf.ctx_ready =
  8093. test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready;
  8094. /* test case 3
  8095. * verify depth is zero, number of peer's chain is 2
  8096. * verify result becomes MAX_CHAIN_ERRO. call-back returns failure.
  8097. * therefore, handshake becomes failure.
  8098. */
  8099. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8100. &server_cbf, NULL), TEST_FAIL);
  8101. ExpectIntEQ(client_cbf.return_code, TEST_FAIL);
  8102. ExpectIntEQ(server_cbf.return_code, TEST_FAIL);
  8103. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(MAX_CHAIN_ERROR));
  8104. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  8105. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8106. return EXPECT_RESULT();
  8107. }
  8108. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8109. !defined(WOLFSSL_NO_TLS12) && \
  8110. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8111. static int test_wolfSSL_CTX_set_cipher_list_server_ctx_ready(WOLFSSL_CTX* ctx)
  8112. {
  8113. EXPECT_DECLS;
  8114. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "DEFAULT:!NULL"));
  8115. return EXPECT_RESULT();
  8116. }
  8117. static int test_wolfSSL_CTX_set_cipher_list_client_ctx_ready(WOLFSSL_CTX* ctx)
  8118. {
  8119. EXPECT_DECLS;
  8120. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256"));
  8121. return EXPECT_RESULT();
  8122. }
  8123. #endif
  8124. static int test_wolfSSL_CTX_set_cipher_list(void)
  8125. {
  8126. EXPECT_DECLS;
  8127. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8128. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8129. #if !defined(WOLFSSL_NO_TLS12)
  8130. WOLFSSL_CTX* ctxClient = NULL;
  8131. WOLFSSL* sslClient = NULL;
  8132. test_ssl_cbf client_cbf;
  8133. test_ssl_cbf server_cbf;
  8134. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8135. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8136. server_cbf.method = wolfTLSv1_2_server_method;
  8137. server_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_server_ctx_ready;
  8138. client_cbf.method = wolfTLSv1_2_client_method;
  8139. client_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_client_ctx_ready;
  8140. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8141. &server_cbf, NULL), TEST_SUCCESS);
  8142. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8143. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8144. /* check with cipher string that has '+' */
  8145. ExpectNotNull((ctxClient = wolfSSL_CTX_new(wolfTLSv1_2_client_method())));
  8146. /* Use trailing : with nothing to test for ASAN */
  8147. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctxClient, "ECDHE+AESGCM:"));
  8148. ExpectNotNull((sslClient = wolfSSL_new(ctxClient)));
  8149. /* check for the existence of an ECDHE ECDSA cipher suite */
  8150. if (EXPECT_SUCCESS()) {
  8151. int i = 0;
  8152. int found = 0;
  8153. const char* suite;
  8154. WOLF_STACK_OF(WOLFSSL_CIPHER)* sk = NULL;
  8155. WOLFSSL_CIPHER* current;
  8156. ExpectNotNull((sk = wolfSSL_get_ciphers_compat(sslClient)));
  8157. do {
  8158. current = wolfSSL_sk_SSL_CIPHER_value(sk, i++);
  8159. if (current) {
  8160. suite = wolfSSL_CIPHER_get_name(current);
  8161. if (suite && XSTRSTR(suite, "ECDSA")) {
  8162. found = 1;
  8163. break;
  8164. }
  8165. }
  8166. } while (current);
  8167. ExpectIntEQ(found, 1);
  8168. }
  8169. wolfSSL_free(sslClient);
  8170. wolfSSL_CTX_free(ctxClient);
  8171. #endif /* !WOLFSSL_NO_TLS12 */
  8172. #endif
  8173. return EXPECT_RESULT();
  8174. }
  8175. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8176. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8177. static int test_wolfSSL_get_finished_client_on_handshake(WOLFSSL_CTX* ctx,
  8178. WOLFSSL* ssl)
  8179. {
  8180. EXPECT_DECLS;
  8181. size_t msg_len;
  8182. (void)ctx;
  8183. /* get_finished test */
  8184. /* 1. get own sent message */
  8185. XMEMSET(client_side_msg1, 0, MD_MAX_SIZE);
  8186. msg_len = wolfSSL_get_finished(ssl, client_side_msg1, MD_MAX_SIZE);
  8187. ExpectIntGE(msg_len, 0);
  8188. /* 2. get peer message */
  8189. XMEMSET(client_side_msg2, 0, MD_MAX_SIZE);
  8190. msg_len = wolfSSL_get_peer_finished(ssl, client_side_msg2, MD_MAX_SIZE);
  8191. ExpectIntGE(msg_len, 0);
  8192. return EXPECT_RESULT();
  8193. }
  8194. #endif
  8195. static int test_wolfSSL_get_finished(void)
  8196. {
  8197. EXPECT_DECLS;
  8198. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8199. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8200. test_ssl_cbf client_cbf;
  8201. test_ssl_cbf server_cbf;
  8202. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8203. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8204. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8205. &server_cbf, test_wolfSSL_get_finished_client_on_handshake),
  8206. TEST_SUCCESS);
  8207. /* test received msg vs sent msg */
  8208. ExpectIntEQ(0, XMEMCMP(client_side_msg1, server_side_msg2, MD_MAX_SIZE));
  8209. ExpectIntEQ(0, XMEMCMP(client_side_msg2, server_side_msg1, MD_MAX_SIZE));
  8210. #endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE */
  8211. return EXPECT_RESULT();
  8212. }
  8213. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8214. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8215. !defined(NO_SESSION_CACHE)
  8216. /* Sessions to restore/store */
  8217. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess;
  8218. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess;
  8219. static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx;
  8220. static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx)
  8221. {
  8222. /* Don't store sessions. Lookup is still enabled. */
  8223. AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8224. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8225. #ifdef OPENSSL_EXTRA
  8226. AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8227. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8228. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8229. #endif
  8230. /* Require both peers to provide certs */
  8231. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8232. }
  8233. static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl)
  8234. {
  8235. WOLFSSL_SESSION** sess;
  8236. if (wolfSSL_is_server(ssl))
  8237. sess = &test_wolfSSL_CTX_add_session_server_sess;
  8238. else
  8239. sess = &test_wolfSSL_CTX_add_session_client_sess;
  8240. if (*sess == NULL) {
  8241. #ifdef NO_SESSION_CACHE_REF
  8242. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8243. #else
  8244. /* Test for backwards compatibility */
  8245. if (wolfSSL_is_server(ssl)) {
  8246. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8247. }
  8248. else {
  8249. AssertNotNull(*sess = wolfSSL_get_session(ssl));
  8250. }
  8251. #endif
  8252. /* Now save the session in the internal store to make it available
  8253. * for lookup. For TLS 1.3, we can't save the session without
  8254. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8255. * session from cache. */
  8256. if (wolfSSL_is_server(ssl)
  8257. #ifndef WOLFSSL_TICKET_HAVE_ID
  8258. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8259. #endif
  8260. )
  8261. AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8262. *sess), WOLFSSL_SUCCESS);
  8263. }
  8264. else {
  8265. /* If we have a session retrieved then remaining connections should be
  8266. * resuming on that session */
  8267. AssertIntEQ(wolfSSL_session_reused(ssl), 1);
  8268. }
  8269. /* Save CTX to be able to decrypt tickets */
  8270. if (wolfSSL_is_server(ssl) &&
  8271. test_wolfSSL_CTX_add_session_server_ctx == NULL) {
  8272. AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx
  8273. = wolfSSL_get_SSL_CTX(ssl));
  8274. AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8275. WOLFSSL_SUCCESS);
  8276. }
  8277. #ifdef SESSION_CERTS
  8278. #ifndef WOLFSSL_TICKET_HAVE_ID
  8279. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8280. wolfSSL_session_reused(ssl))
  8281. #endif
  8282. {
  8283. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8284. * for all connections. TLS 1.3 only has tickets so if we don't
  8285. * include the session id in the ticket then the certificates
  8286. * will not be available on resumption. */
  8287. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8288. AssertNotNull(peer);
  8289. wolfSSL_X509_free(peer);
  8290. AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8291. #ifdef OPENSSL_EXTRA
  8292. AssertNotNull(SSL_SESSION_get0_peer(*sess));
  8293. #endif
  8294. }
  8295. #endif /* SESSION_CERTS */
  8296. }
  8297. static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl)
  8298. {
  8299. /* Set the session to reuse for the client */
  8300. AssertIntEQ(wolfSSL_set_session(ssl,
  8301. test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS);
  8302. }
  8303. #endif
  8304. static int test_wolfSSL_CTX_add_session(void)
  8305. {
  8306. EXPECT_DECLS;
  8307. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8308. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8309. !defined(NO_SESSION_CACHE)
  8310. tcp_ready ready;
  8311. func_args client_args;
  8312. func_args server_args;
  8313. THREAD_TYPE serverThread;
  8314. callback_functions client_cb;
  8315. callback_functions server_cb;
  8316. method_provider methods[][2] = {
  8317. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  8318. !defined(NO_DES3))
  8319. /* Without AES there are almost no ciphersuites available. This leads
  8320. * to no ciphersuites being available and an error. */
  8321. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method },
  8322. #endif
  8323. #ifndef WOLFSSL_NO_TLS12
  8324. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method },
  8325. #endif
  8326. /* Needs the default ticket callback since it is tied to the
  8327. * connection context and this makes it easy to carry over the ticket
  8328. * crypto context between connections */
  8329. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8330. defined(HAVE_SESSION_TICKET)
  8331. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method },
  8332. #endif
  8333. };
  8334. const size_t methodsLen = sizeof(methods)/sizeof(*methods);
  8335. size_t i, j;
  8336. for (i = 0; i < methodsLen; i++) {
  8337. /* First run creates a connection while the second+ run will attempt
  8338. * to resume the connection. The trick is that the internal cache
  8339. * is turned off. wolfSSL_CTX_add_session should put the session in
  8340. * the cache anyway. */
  8341. test_wolfSSL_CTX_add_session_client_sess = NULL;
  8342. test_wolfSSL_CTX_add_session_server_sess = NULL;
  8343. test_wolfSSL_CTX_add_session_server_ctx = NULL;
  8344. #ifdef NO_SESSION_CACHE_REF
  8345. for (j = 0; j < 4; j++) {
  8346. #else
  8347. /* The session may be overwritten in this case. Do only one resumption
  8348. * to stop this test from failing intermittently. */
  8349. for (j = 0; j < 2; j++) {
  8350. #endif
  8351. #ifdef WOLFSSL_TIRTOS
  8352. fdOpenSession(Task_self());
  8353. #endif
  8354. StartTCP();
  8355. InitTcpReady(&ready);
  8356. XMEMSET(&client_args, 0, sizeof(func_args));
  8357. XMEMSET(&server_args, 0, sizeof(func_args));
  8358. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  8359. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  8360. client_cb.method = methods[i][0];
  8361. server_cb.method = methods[i][1];
  8362. server_args.signal = &ready;
  8363. server_args.callbacks = &server_cb;
  8364. client_args.signal = &ready;
  8365. client_args.callbacks = &client_cb;
  8366. if (test_wolfSSL_CTX_add_session_server_ctx != NULL) {
  8367. server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx;
  8368. server_cb.isSharedCtx = 1;
  8369. }
  8370. server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8371. client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8372. if (j != 0)
  8373. client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready;
  8374. server_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8375. client_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8376. server_cb.ticNoInit = 1; /* Use default builtin */
  8377. start_thread(test_server_nofail, &server_args, &serverThread);
  8378. wait_tcp_ready(&server_args);
  8379. test_client_nofail(&client_args, NULL);
  8380. join_thread(serverThread);
  8381. ExpectTrue(client_args.return_code);
  8382. ExpectTrue(server_args.return_code);
  8383. FreeTcpReady(&ready);
  8384. if (EXPECT_FAIL())
  8385. break;
  8386. }
  8387. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess);
  8388. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess);
  8389. wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx);
  8390. if (EXPECT_FAIL())
  8391. break;
  8392. }
  8393. #endif
  8394. return EXPECT_RESULT();
  8395. }
  8396. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8397. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8398. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8399. defined(HAVE_SESSION_TICKET) && \
  8400. !defined(TITAN_SESSION_CACHE) && \
  8401. !defined(HUGE_SESSION_CACHE) && \
  8402. !defined(BIG_SESSION_CACHE) && \
  8403. !defined(MEDIUM_SESSION_CACHE)
  8404. /* twcase - prefix for test_wolfSSL_CTX_add_session_ext */
  8405. /* Sessions to restore/store */
  8406. static WOLFSSL_SESSION* twcase_server_first_session_ptr;
  8407. static WOLFSSL_SESSION* twcase_client_first_session_ptr;
  8408. static WOLFSSL_CTX* twcase_server_current_ctx_ptr;
  8409. static int twcase_new_session_called = 0;
  8410. static int twcase_remove_session_called = 0;
  8411. static int twcase_get_session_called = 0;
  8412. /* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */
  8413. #define SESSION_CACHE_SIZE 33
  8414. typedef struct {
  8415. const byte* key; /* key, altSessionID, session ID, NULL if empty */
  8416. WOLFSSL_SESSION* value;
  8417. } hashTable_entry;
  8418. typedef struct {
  8419. hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */
  8420. size_t capacity; /* size of entries */
  8421. size_t length; /* number of items in the hash table */
  8422. wolfSSL_Mutex htLock; /* lock */
  8423. }hashTable;
  8424. static hashTable server_sessionCache;
  8425. static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess)
  8426. {
  8427. int i;
  8428. unsigned int len;
  8429. (void)ssl;
  8430. /*
  8431. * This example uses a hash table.
  8432. * Steps you should take for a non-demo code:
  8433. * - acquire a lock for the file named according to the session id
  8434. * - open the file
  8435. * - encrypt and write the SSL_SESSION object to the file
  8436. * - release the lock
  8437. *
  8438. * Return:
  8439. * 0: The callback does not wish to hold a reference of the sess
  8440. * 1: The callback wants to hold a reference of the sess. The callback is
  8441. * now also responsible for calling wolfSSL_SESSION_free() on sess.
  8442. */
  8443. if (sess == NULL)
  8444. return 0;
  8445. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8446. return 0;
  8447. }
  8448. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8449. if (server_sessionCache.entries[i].value == NULL) {
  8450. server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len);
  8451. server_sessionCache.entries[i].value = sess;
  8452. server_sessionCache.length++;
  8453. break;
  8454. }
  8455. }
  8456. ++twcase_new_session_called;
  8457. wc_UnLockMutex(&server_sessionCache.htLock);
  8458. fprintf(stderr, "\t\ttwcase_new_session_called %d\n",
  8459. twcase_new_session_called);
  8460. return 1;
  8461. }
  8462. static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  8463. {
  8464. int i;
  8465. (void)ctx;
  8466. (void)sess;
  8467. if (sess == NULL)
  8468. return;
  8469. /*
  8470. * This example uses a hash table.
  8471. * Steps you should take for a non-demo code:
  8472. * - acquire a lock for the file named according to the session id
  8473. * - remove the file
  8474. * - release the lock
  8475. */
  8476. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8477. return;
  8478. }
  8479. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8480. if (server_sessionCache.entries[i].key != NULL &&
  8481. XMEMCMP(server_sessionCache.entries[i].key,
  8482. sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8483. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8484. server_sessionCache.entries[i].value = NULL;
  8485. server_sessionCache.entries[i].key = NULL;
  8486. server_sessionCache.length--;
  8487. break;
  8488. }
  8489. }
  8490. ++twcase_remove_session_called;
  8491. wc_UnLockMutex(&server_sessionCache.htLock);
  8492. fprintf(stderr, "\t\ttwcase_remove_session_called %d\n",
  8493. twcase_remove_session_called);
  8494. }
  8495. static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl,
  8496. const unsigned char *id, int len, int *ref)
  8497. {
  8498. int i;
  8499. (void)ssl;
  8500. (void)id;
  8501. (void)len;
  8502. /*
  8503. * This example uses a hash table.
  8504. * Steps you should take for a non-demo code:
  8505. * - acquire a lock for the file named according to the session id in the
  8506. * 2nd arg
  8507. * - read and decrypt contents of file and create a new SSL_SESSION
  8508. * - object release the lock
  8509. * - return the new session object
  8510. */
  8511. fprintf(stderr, "\t\ttwcase_get_session_called %d\n",
  8512. ++twcase_get_session_called);
  8513. /* This callback want to retain a copy of the object. If we want wolfSSL to
  8514. * be responsible for the pointer then set to 0. */
  8515. *ref = 1;
  8516. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8517. if (server_sessionCache.entries[i].key != NULL &&
  8518. XMEMCMP(server_sessionCache.entries[i].key, id,
  8519. SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8520. return server_sessionCache.entries[i].value;
  8521. }
  8522. }
  8523. return NULL;
  8524. }
  8525. static int twcase_get_sessionCb_cleanup(void)
  8526. {
  8527. int i;
  8528. int cnt = 0;
  8529. /* If twcase_get_sessionCb sets *ref = 1, the application is responsible
  8530. * for freeing sessions */
  8531. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8532. if (server_sessionCache.entries[i].value != NULL) {
  8533. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8534. cnt++;
  8535. }
  8536. }
  8537. fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n",
  8538. cnt);
  8539. return TEST_SUCCESS;
  8540. }
  8541. static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx)
  8542. {
  8543. EXPECT_DECLS;
  8544. /* off - Disable internal cache */
  8545. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8546. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8547. #ifdef OPENSSL_EXTRA
  8548. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8549. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8550. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8551. #endif
  8552. /* off - Do not setup external cache */
  8553. /* Require both peers to provide certs */
  8554. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8555. return EXPECT_RESULT();
  8556. }
  8557. static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx)
  8558. {
  8559. /* on - internal cache is on by default */
  8560. /* off - Do not setup external cache */
  8561. /* Require both peers to provide certs */
  8562. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8563. return TEST_SUCCESS;
  8564. }
  8565. static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx)
  8566. {
  8567. EXPECT_DECLS;
  8568. /* off - Disable internal cache */
  8569. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8570. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8571. #ifdef OPENSSL_EXTRA
  8572. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8573. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8574. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8575. #endif
  8576. /* on - Enable external cache */
  8577. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8578. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8579. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8580. /* Require both peers to provide certs */
  8581. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8582. return EXPECT_RESULT();
  8583. }
  8584. static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx)
  8585. {
  8586. /* on - internal cache is on by default */
  8587. /* on - Enable external cache */
  8588. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8589. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8590. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8591. /* Require both peers to provide certs */
  8592. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8593. return TEST_SUCCESS;
  8594. }
  8595. static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx)
  8596. {
  8597. /* on - internal cache is on by default */
  8598. /* on - Enable external cache */
  8599. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8600. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8601. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8602. wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET);
  8603. /* Require both peers to provide certs */
  8604. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8605. return TEST_SUCCESS;
  8606. }
  8607. static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8608. {
  8609. EXPECT_DECLS;
  8610. WOLFSSL_SESSION** sess;
  8611. if (wolfSSL_is_server(ssl))
  8612. sess = &twcase_server_first_session_ptr;
  8613. else
  8614. return TEST_SUCCESS;
  8615. if (*sess == NULL) {
  8616. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8617. /* Now save the session in the internal store to make it available
  8618. * for lookup. For TLS 1.3, we can't save the session without
  8619. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8620. * session from cache. */
  8621. if (wolfSSL_is_server(ssl)
  8622. #ifndef WOLFSSL_TICKET_HAVE_ID
  8623. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8624. && wolfSSL_version(ssl) != DTLS1_3_VERSION
  8625. #endif
  8626. ) {
  8627. ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8628. *sess), WOLFSSL_SUCCESS);
  8629. }
  8630. }
  8631. /* Save CTX to be able to decrypt tickets */
  8632. if (twcase_server_current_ctx_ptr == NULL) {
  8633. ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl));
  8634. ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8635. WOLFSSL_SUCCESS);
  8636. }
  8637. #ifdef SESSION_CERTS
  8638. #ifndef WOLFSSL_TICKET_HAVE_ID
  8639. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8640. wolfSSL_session_reused(ssl))
  8641. #endif
  8642. {
  8643. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8644. * for all connections. TLS 1.3 only has tickets so if we don't
  8645. * include the session id in the ticket then the certificates
  8646. * will not be available on resumption. */
  8647. WOLFSSL_X509* peer = NULL;
  8648. ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl));
  8649. wolfSSL_X509_free(peer);
  8650. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8651. }
  8652. #endif
  8653. return EXPECT_RESULT();
  8654. }
  8655. static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8656. {
  8657. EXPECT_DECLS;
  8658. WOLFSSL_SESSION** sess;
  8659. sess = &twcase_client_first_session_ptr;
  8660. if (*sess == NULL) {
  8661. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8662. }
  8663. else {
  8664. /* If we have a session retrieved then remaining connections should be
  8665. * resuming on that session */
  8666. ExpectIntEQ(wolfSSL_session_reused(ssl), 1);
  8667. }
  8668. #ifdef SESSION_CERTS
  8669. #ifndef WOLFSSL_TICKET_HAVE_ID
  8670. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8671. wolfSSL_session_reused(ssl))
  8672. #endif
  8673. {
  8674. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8675. ExpectNotNull(peer);
  8676. wolfSSL_X509_free(peer);
  8677. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8678. #ifdef OPENSSL_EXTRA
  8679. ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess));
  8680. #endif
  8681. }
  8682. #endif
  8683. return EXPECT_RESULT();
  8684. }
  8685. static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl)
  8686. {
  8687. EXPECT_DECLS;
  8688. /* Set the session to reuse for the client */
  8689. ExpectNotNull(ssl);
  8690. ExpectNotNull(twcase_client_first_session_ptr);
  8691. ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr),
  8692. WOLFSSL_SUCCESS);
  8693. return EXPECT_RESULT();
  8694. }
  8695. struct test_add_session_ext_params {
  8696. method_provider client_meth;
  8697. method_provider server_meth;
  8698. const char* tls_version;
  8699. };
  8700. static int test_wolfSSL_CTX_add_session_ext(
  8701. struct test_add_session_ext_params* param)
  8702. {
  8703. EXPECT_DECLS;
  8704. /* Test the default 33 sessions */
  8705. int j;
  8706. /* Clear cache before starting */
  8707. wolfSSL_CTX_flush_sessions(NULL, -1);
  8708. XMEMSET(&server_sessionCache, 0, sizeof(hashTable));
  8709. if (wc_InitMutex(&server_sessionCache.htLock) != 0)
  8710. return BAD_MUTEX_E;
  8711. server_sessionCache.capacity = SESSION_CACHE_SIZE;
  8712. fprintf(stderr, "\tBegin %s\n", param->tls_version);
  8713. for (j = 0; j < 5; j++) {
  8714. int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL;
  8715. int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL;
  8716. test_ssl_cbf client_cb;
  8717. test_ssl_cbf server_cb;
  8718. (void)dtls;
  8719. /* Test five cache configurations */
  8720. twcase_client_first_session_ptr = NULL;
  8721. twcase_server_first_session_ptr = NULL;
  8722. twcase_server_current_ctx_ptr = NULL;
  8723. twcase_new_session_called = 0;
  8724. twcase_remove_session_called = 0;
  8725. twcase_get_session_called = 0;
  8726. /* connection 1 - first connection */
  8727. fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j);
  8728. XMEMSET(&client_cb, 0, sizeof(client_cb));
  8729. XMEMSET(&server_cb, 0, sizeof(server_cb));
  8730. client_cb.method = param->client_meth;
  8731. server_cb.method = param->server_meth;
  8732. if (dtls)
  8733. client_cb.doUdp = server_cb.doUdp = 1;
  8734. /* Setup internal and external cache */
  8735. switch (j) {
  8736. case 0:
  8737. /* SSL_OP_NO_TICKET stateful ticket case */
  8738. server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket;
  8739. break;
  8740. case 1:
  8741. server_cb.ctx_ready = twcase_cache_intOn_extOn;
  8742. break;
  8743. case 2:
  8744. server_cb.ctx_ready = twcase_cache_intOff_extOn;
  8745. break;
  8746. case 3:
  8747. server_cb.ctx_ready = twcase_cache_intOn_extOff;
  8748. break;
  8749. case 4:
  8750. server_cb.ctx_ready = twcase_cache_intOff_extOff;
  8751. break;
  8752. }
  8753. client_cb.ctx_ready = twcase_cache_intOff_extOff;
  8754. /* Add session to internal cache and save SSL session for testing */
  8755. server_cb.on_result = twcase_server_sess_ctx_pre_shutdown;
  8756. /* Save client SSL session for testing */
  8757. client_cb.on_result = twcase_client_sess_ctx_pre_shutdown;
  8758. server_cb.ticNoInit = 1; /* Use default builtin */
  8759. /* Don't free/release ctx */
  8760. server_cb.ctx = twcase_server_current_ctx_ptr;
  8761. server_cb.isSharedCtx = 1;
  8762. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8763. &server_cb, NULL), TEST_SUCCESS);
  8764. ExpectIntEQ(twcase_get_session_called, 0);
  8765. if (EXPECT_FAIL()) {
  8766. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8767. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8768. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8769. break;
  8770. }
  8771. switch (j) {
  8772. case 0:
  8773. case 1:
  8774. case 2:
  8775. /* cache cannot be searched with out a connection */
  8776. /* Add a new session */
  8777. ExpectIntEQ(twcase_new_session_called, 1);
  8778. /* In twcase_server_sess_ctx_pre_shutdown
  8779. * wolfSSL_CTX_add_session which evicts the existing session
  8780. * in cache and adds it back in */
  8781. ExpectIntLE(twcase_remove_session_called, 1);
  8782. break;
  8783. case 3:
  8784. case 4:
  8785. /* no external cache */
  8786. ExpectIntEQ(twcase_new_session_called, 0);
  8787. ExpectIntEQ(twcase_remove_session_called, 0);
  8788. break;
  8789. }
  8790. /* connection 2 - session resume */
  8791. fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j);
  8792. twcase_new_session_called = 0;
  8793. twcase_remove_session_called = 0;
  8794. twcase_get_session_called = 0;
  8795. server_cb.on_result = 0;
  8796. client_cb.on_result = 0;
  8797. server_cb.ticNoInit = 1; /* Use default builtin */
  8798. server_cb.ctx = twcase_server_current_ctx_ptr;
  8799. /* try session resumption */
  8800. client_cb.ssl_ready = twcase_client_set_sess_ssl_ready;
  8801. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8802. &server_cb, NULL), TEST_SUCCESS);
  8803. /* Clear cache before checking */
  8804. wolfSSL_CTX_flush_sessions(NULL, -1);
  8805. switch (j) {
  8806. case 0:
  8807. if (tls13) {
  8808. /* (D)TLSv1.3 stateful case */
  8809. /* cache hit */
  8810. /* DTLS accesses cache once for stateless parsing and
  8811. * once for stateful parsing */
  8812. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8813. /* (D)TLSv1.3 creates a new ticket,
  8814. * updates both internal and external cache */
  8815. ExpectIntEQ(twcase_new_session_called, 1);
  8816. /* A new session ID is created for a new ticket */
  8817. ExpectIntEQ(twcase_remove_session_called, 2);
  8818. }
  8819. else {
  8820. /* non (D)TLSv1.3 case, no update */
  8821. /* DTLS accesses cache once for stateless parsing and
  8822. * once for stateful parsing */
  8823. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  8824. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8825. #else
  8826. ExpectIntEQ(twcase_get_session_called, 1);
  8827. #endif
  8828. ExpectIntEQ(twcase_new_session_called, 0);
  8829. /* Called on session added in
  8830. * twcase_server_sess_ctx_pre_shutdown */
  8831. ExpectIntEQ(twcase_remove_session_called, 1);
  8832. }
  8833. break;
  8834. case 1:
  8835. if (tls13) {
  8836. /* (D)TLSv1.3 case */
  8837. /* cache hit */
  8838. ExpectIntEQ(twcase_get_session_called, 1);
  8839. /* (D)TLSv1.3 creates a new ticket,
  8840. * updates both internal and external cache */
  8841. ExpectIntEQ(twcase_new_session_called, 1);
  8842. /* Called on session added in
  8843. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  8844. ExpectIntEQ(twcase_remove_session_called, 1);
  8845. }
  8846. else {
  8847. /* non (D)TLSv1.3 case */
  8848. /* cache hit */
  8849. /* DTLS accesses cache once for stateless parsing and
  8850. * once for stateful parsing */
  8851. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  8852. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8853. #else
  8854. ExpectIntEQ(twcase_get_session_called, 1);
  8855. #endif
  8856. ExpectIntEQ(twcase_new_session_called, 0);
  8857. /* Called on session added in
  8858. * twcase_server_sess_ctx_pre_shutdown */
  8859. ExpectIntEQ(twcase_remove_session_called, 1);
  8860. }
  8861. break;
  8862. case 2:
  8863. if (tls13) {
  8864. /* (D)TLSv1.3 case */
  8865. /* cache hit */
  8866. ExpectIntEQ(twcase_get_session_called, 1);
  8867. /* (D)TLSv1.3 creates a new ticket,
  8868. * updates both internal and external cache */
  8869. ExpectIntEQ(twcase_new_session_called, 1);
  8870. /* Called on session added in
  8871. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  8872. ExpectIntEQ(twcase_remove_session_called, 1);
  8873. }
  8874. else {
  8875. /* non (D)TLSv1.3 case */
  8876. /* cache hit */
  8877. /* DTLS accesses cache once for stateless parsing and
  8878. * once for stateful parsing */
  8879. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  8880. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8881. #else
  8882. ExpectIntEQ(twcase_get_session_called, 1);
  8883. #endif
  8884. ExpectIntEQ(twcase_new_session_called, 0);
  8885. /* Called on session added in
  8886. * twcase_server_sess_ctx_pre_shutdown */
  8887. ExpectIntEQ(twcase_remove_session_called, 1);
  8888. }
  8889. break;
  8890. case 3:
  8891. case 4:
  8892. /* no external cache */
  8893. ExpectIntEQ(twcase_get_session_called, 0);
  8894. ExpectIntEQ(twcase_new_session_called, 0);
  8895. ExpectIntEQ(twcase_remove_session_called, 0);
  8896. break;
  8897. }
  8898. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8899. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8900. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8901. if (EXPECT_FAIL())
  8902. break;
  8903. }
  8904. twcase_get_sessionCb_cleanup();
  8905. XMEMSET(&server_sessionCache.entries, 0,
  8906. sizeof(server_sessionCache.entries));
  8907. fprintf(stderr, "\tEnd %s\n", param->tls_version);
  8908. wc_FreeMutex(&server_sessionCache.htLock);
  8909. return EXPECT_RESULT();
  8910. }
  8911. #endif
  8912. static int test_wolfSSL_CTX_add_session_ext_tls13(void)
  8913. {
  8914. EXPECT_DECLS;
  8915. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8916. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8917. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8918. defined(HAVE_SESSION_TICKET) && \
  8919. !defined(TITAN_SESSION_CACHE) && \
  8920. !defined(HUGE_SESSION_CACHE) && \
  8921. !defined(BIG_SESSION_CACHE) && \
  8922. !defined(MEDIUM_SESSION_CACHE)
  8923. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8924. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  8925. struct test_add_session_ext_params param[1] = {
  8926. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" }
  8927. };
  8928. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8929. #endif
  8930. #endif
  8931. return EXPECT_RESULT();
  8932. }
  8933. static int test_wolfSSL_CTX_add_session_ext_dtls13(void)
  8934. {
  8935. EXPECT_DECLS;
  8936. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8937. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8938. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8939. defined(HAVE_SESSION_TICKET) && \
  8940. !defined(TITAN_SESSION_CACHE) && \
  8941. !defined(HUGE_SESSION_CACHE) && \
  8942. !defined(BIG_SESSION_CACHE) && \
  8943. !defined(MEDIUM_SESSION_CACHE)
  8944. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8945. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  8946. #ifdef WOLFSSL_DTLS13
  8947. struct test_add_session_ext_params param[1] = {
  8948. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" }
  8949. };
  8950. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8951. #endif
  8952. #endif
  8953. #endif
  8954. return EXPECT_RESULT();
  8955. }
  8956. static int test_wolfSSL_CTX_add_session_ext_tls12(void)
  8957. {
  8958. EXPECT_DECLS;
  8959. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8960. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8961. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8962. defined(HAVE_SESSION_TICKET) && \
  8963. !defined(TITAN_SESSION_CACHE) && \
  8964. !defined(HUGE_SESSION_CACHE) && \
  8965. !defined(BIG_SESSION_CACHE) && \
  8966. !defined(MEDIUM_SESSION_CACHE)
  8967. #ifndef WOLFSSL_NO_TLS12
  8968. struct test_add_session_ext_params param[1] = {
  8969. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" }
  8970. };
  8971. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8972. #endif
  8973. #endif
  8974. return EXPECT_RESULT();
  8975. }
  8976. static int test_wolfSSL_CTX_add_session_ext_dtls12(void)
  8977. {
  8978. EXPECT_DECLS;
  8979. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8980. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8981. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8982. defined(HAVE_SESSION_TICKET) && \
  8983. !defined(TITAN_SESSION_CACHE) && \
  8984. !defined(HUGE_SESSION_CACHE) && \
  8985. !defined(BIG_SESSION_CACHE) && \
  8986. !defined(MEDIUM_SESSION_CACHE)
  8987. #ifndef WOLFSSL_NO_TLS12
  8988. #ifdef WOLFSSL_DTLS
  8989. struct test_add_session_ext_params param[1] = {
  8990. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" }
  8991. };
  8992. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8993. #endif
  8994. #endif
  8995. #endif
  8996. return EXPECT_RESULT();
  8997. }
  8998. static int test_wolfSSL_CTX_add_session_ext_tls11(void)
  8999. {
  9000. EXPECT_DECLS;
  9001. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9002. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9003. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9004. defined(HAVE_SESSION_TICKET) && \
  9005. !defined(TITAN_SESSION_CACHE) && \
  9006. !defined(HUGE_SESSION_CACHE) && \
  9007. !defined(BIG_SESSION_CACHE) && \
  9008. !defined(MEDIUM_SESSION_CACHE)
  9009. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9010. !defined(NO_DES3))
  9011. struct test_add_session_ext_params param[1] = {
  9012. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" }
  9013. };
  9014. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9015. #endif
  9016. #endif
  9017. return EXPECT_RESULT();
  9018. }
  9019. static int test_wolfSSL_CTX_add_session_ext_dtls1(void)
  9020. {
  9021. EXPECT_DECLS;
  9022. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9023. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9024. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9025. defined(HAVE_SESSION_TICKET) && \
  9026. !defined(TITAN_SESSION_CACHE) && \
  9027. !defined(HUGE_SESSION_CACHE) && \
  9028. !defined(BIG_SESSION_CACHE) && \
  9029. !defined(MEDIUM_SESSION_CACHE)
  9030. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9031. !defined(NO_DES3))
  9032. #ifdef WOLFSSL_DTLS
  9033. struct test_add_session_ext_params param[1] = {
  9034. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" }
  9035. };
  9036. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9037. #endif
  9038. #endif
  9039. #endif
  9040. return EXPECT_RESULT();
  9041. }
  9042. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9043. /* canned export of a session using older version 3 */
  9044. static unsigned char version_3[] = {
  9045. 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01,
  9046. 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00,
  9047. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9048. 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  9049. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9050. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9051. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30,
  9052. 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05,
  9053. 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00,
  9054. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9055. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9056. 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
  9057. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9058. 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00,
  9059. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  9060. 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00,
  9061. 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01,
  9062. 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9063. 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F,
  9064. 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  9065. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9066. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9067. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9068. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9069. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9070. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9071. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9072. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9073. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9074. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9075. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9076. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x05,
  9077. 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D,
  9078. 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B,
  9079. 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98,
  9080. 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0,
  9081. 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74,
  9082. 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26,
  9083. 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9,
  9084. 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04,
  9085. 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80,
  9086. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9087. 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00,
  9088. 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D,
  9089. 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9090. 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00,
  9091. 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01,
  9092. 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00,
  9093. 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30,
  9094. 0x2E, 0x31, 0xED, 0x4F
  9095. };
  9096. #endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */
  9097. static int test_wolfSSL_dtls_export(void)
  9098. {
  9099. EXPECT_DECLS;
  9100. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9101. tcp_ready ready;
  9102. func_args client_args;
  9103. func_args server_args;
  9104. THREAD_TYPE serverThread;
  9105. callback_functions server_cbf;
  9106. callback_functions client_cbf;
  9107. #ifdef WOLFSSL_TIRTOS
  9108. fdOpenSession(Task_self());
  9109. #endif
  9110. InitTcpReady(&ready);
  9111. #if defined(USE_WINDOWS_API)
  9112. /* use RNG to get random port if using windows */
  9113. ready.port = GetRandomPort();
  9114. #endif
  9115. /* set using dtls */
  9116. XMEMSET(&client_args, 0, sizeof(func_args));
  9117. XMEMSET(&server_args, 0, sizeof(func_args));
  9118. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9119. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  9120. server_cbf.method = wolfDTLSv1_2_server_method;
  9121. client_cbf.method = wolfDTLSv1_2_client_method;
  9122. server_args.callbacks = &server_cbf;
  9123. client_args.callbacks = &client_cbf;
  9124. server_args.signal = &ready;
  9125. client_args.signal = &ready;
  9126. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9127. wait_tcp_ready(&server_args);
  9128. run_wolfssl_client(&client_args);
  9129. join_thread(serverThread);
  9130. ExpectTrue(client_args.return_code);
  9131. ExpectTrue(server_args.return_code);
  9132. FreeTcpReady(&ready);
  9133. #ifdef WOLFSSL_TIRTOS
  9134. fdOpenSession(Task_self());
  9135. #endif
  9136. if (EXPECT_SUCCESS()) {
  9137. SOCKET_T sockfd = 0;
  9138. WOLFSSL_CTX* ctx = NULL;
  9139. WOLFSSL* ssl = NULL;
  9140. char msg[64] = "hello wolfssl!";
  9141. char reply[1024];
  9142. int msgSz = (int)XSTRLEN(msg);
  9143. byte *session, *window;
  9144. unsigned int sessionSz = 0;
  9145. unsigned int windowSz = 0;
  9146. #ifndef TEST_IPV6
  9147. struct sockaddr_in peerAddr;
  9148. #else
  9149. struct sockaddr_in6 peerAddr;
  9150. #endif /* TEST_IPV6 */
  9151. int i;
  9152. /* Set ctx to DTLS 1.2 */
  9153. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  9154. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9155. /* test importing version 3 */
  9156. ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9157. /* test importing bad length and bad version */
  9158. version_3[2] += 1;
  9159. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9160. version_3[2] -= 1; version_3[1] = 0XA0;
  9161. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9162. wolfSSL_free(ssl);
  9163. wolfSSL_CTX_free(ctx);
  9164. /* check storing client state after connection and storing window only */
  9165. #ifdef WOLFSSL_TIRTOS
  9166. fdOpenSession(Task_self());
  9167. #endif
  9168. InitTcpReady(&ready);
  9169. #if defined(USE_WINDOWS_API)
  9170. /* use RNG to get random port if using windows */
  9171. ready.port = GetRandomPort();
  9172. #endif
  9173. /* set using dtls */
  9174. XMEMSET(&server_args, 0, sizeof(func_args));
  9175. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9176. server_cbf.method = wolfDTLSv1_2_server_method;
  9177. server_cbf.doUdp = 1;
  9178. server_args.callbacks = &server_cbf;
  9179. server_args.argc = 3; /* set loop_count to 3 */
  9180. server_args.signal = &ready;
  9181. start_thread(test_server_nofail, &server_args, &serverThread);
  9182. wait_tcp_ready(&server_args);
  9183. /* create and connect with client */
  9184. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  9185. ExpectIntEQ(WOLFSSL_SUCCESS,
  9186. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  9187. ExpectIntEQ(WOLFSSL_SUCCESS,
  9188. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  9189. ExpectIntEQ(WOLFSSL_SUCCESS,
  9190. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  9191. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL);
  9192. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9193. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9194. /* store server information connected too */
  9195. XMEMSET(&peerAddr, 0, sizeof(peerAddr));
  9196. #ifndef TEST_IPV6
  9197. peerAddr.sin_family = AF_INET;
  9198. ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1);
  9199. peerAddr.sin_port = XHTONS(server_args.signal->port);
  9200. #else
  9201. peerAddr.sin6_family = AF_INET6;
  9202. ExpectIntEQ(
  9203. XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1);
  9204. peerAddr.sin6_port = XHTONS(server_args.signal->port);
  9205. #endif
  9206. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9207. WOLFSSL_SUCCESS);
  9208. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  9209. ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0);
  9210. session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9211. ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0);
  9212. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9213. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9214. ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0);
  9215. window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9216. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9217. wolfSSL_free(ssl);
  9218. for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) {
  9219. /* restore state */
  9220. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9221. ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0);
  9222. ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0);
  9223. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9224. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9225. WOLFSSL_SUCCESS);
  9226. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9227. ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9228. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9229. wolfSSL_free(ssl);
  9230. }
  9231. XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9232. XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9233. wolfSSL_CTX_free(ctx);
  9234. fprintf(stderr, "done and waiting for server\n");
  9235. join_thread(serverThread);
  9236. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9237. FreeTcpReady(&ready);
  9238. #ifdef WOLFSSL_TIRTOS
  9239. fdOpenSession(Task_self());
  9240. #endif
  9241. }
  9242. #endif
  9243. return EXPECT_RESULT();
  9244. }
  9245. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9246. #ifdef WOLFSSL_TLS13
  9247. static const byte canned_client_tls13_session[] = {
  9248. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
  9249. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9250. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
  9251. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9252. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9253. 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9254. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9255. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x09, 0x00,
  9256. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9257. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9258. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9259. 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  9260. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9261. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9262. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9263. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9264. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9265. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9266. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9267. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9268. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9269. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9270. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9271. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9272. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9273. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9274. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9275. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9276. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9277. 0x35, 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0,
  9278. 0x6F, 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A,
  9279. 0xA0, 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06,
  9280. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9281. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9282. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9283. 0x00, 0x03
  9284. };
  9285. static const byte canned_server_tls13_session[] = {
  9286. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
  9287. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9288. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00,
  9289. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9290. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9291. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9292. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9293. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x00, 0x0F,
  9294. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9295. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9296. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9297. 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  9298. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9299. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9300. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9301. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9302. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9303. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9304. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9305. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9306. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9307. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9308. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9309. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9310. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9311. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9312. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9313. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9314. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9315. 0xD3, 0xB7, 0xEE, 0x3A, 0xA0, 0x8E, 0xA1, 0x4D,
  9316. 0xC3, 0x2E, 0x5E, 0x06, 0x35, 0x41, 0xCD, 0xF3,
  9317. 0x49, 0x31, 0x08, 0xD0, 0x6F, 0x02, 0x3D, 0xC1,
  9318. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9319. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9320. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9321. 0x00, 0x04
  9322. };
  9323. #endif /* WOLFSSL_TLS13 */
  9324. static const byte canned_client_session[] = {
  9325. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9326. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9327. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
  9328. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9329. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9330. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9331. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9332. 0x27, 0x0A, 0x0D, 0x10, 0x01, 0x01, 0x0A, 0x00,
  9333. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9334. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9335. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9336. 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
  9337. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9338. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9339. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9340. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9341. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9342. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9343. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9344. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9345. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9346. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9347. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9348. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9349. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9350. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9351. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9352. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9353. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9354. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9355. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9356. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9357. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9358. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9359. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9360. 0x28, 0x00, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9361. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9362. 0x43, 0xF3, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9363. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9364. 0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9365. 0x00, 0x03
  9366. };
  9367. static const byte canned_server_session[] = {
  9368. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9369. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9370. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9371. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9372. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9373. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9374. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9375. 0x27, 0x08, 0x0F, 0x10, 0x01, 0x01, 0x00, 0x11,
  9376. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9377. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9378. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9379. 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  9380. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9381. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9382. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9383. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9384. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9385. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9386. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9387. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9388. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9389. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9390. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9391. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9392. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9393. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9394. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9395. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9396. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9397. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9398. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9399. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9400. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9401. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9402. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9403. 0x28, 0x00, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9404. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9405. 0x14, 0x63, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9406. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9407. 0x43, 0xF3, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9408. 0x00, 0x04
  9409. };
  9410. static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
  9411. {
  9412. SOCKET_T sockfd = 0;
  9413. SOCKET_T clientfd = 0;
  9414. word16 port;
  9415. callback_functions* cbf;
  9416. WOLFSSL_CTX* ctx = 0;
  9417. WOLFSSL* ssl = 0;
  9418. char msg[] = "I hear you fa shizzle!";
  9419. char input[1024];
  9420. int idx;
  9421. #ifdef WOLFSSL_TIRTOS
  9422. fdOpenSession(Task_self());
  9423. #endif
  9424. ((func_args*)args)->return_code = TEST_FAIL;
  9425. cbf = ((func_args*)args)->callbacks;
  9426. #if defined(USE_WINDOWS_API)
  9427. port = ((func_args*)args)->signal->port;
  9428. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  9429. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  9430. /* Let tcp_listen assign port */
  9431. port = 0;
  9432. #else
  9433. /* Use default port */
  9434. port = wolfSSLPort;
  9435. #endif
  9436. /* do it here to detect failure */
  9437. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  9438. CloseSocket(sockfd);
  9439. {
  9440. WOLFSSL_METHOD* method = NULL;
  9441. if (cbf != NULL && cbf->method != NULL) {
  9442. method = cbf->method();
  9443. }
  9444. else {
  9445. method = wolfTLSv1_2_server_method();
  9446. }
  9447. ctx = wolfSSL_CTX_new(method);
  9448. }
  9449. if (ctx == NULL) {
  9450. goto done;
  9451. }
  9452. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9453. /* call ctx setup callback */
  9454. if (cbf != NULL && cbf->ctx_ready != NULL) {
  9455. cbf->ctx_ready(ctx);
  9456. }
  9457. ssl = wolfSSL_new(ctx);
  9458. if (ssl == NULL) {
  9459. goto done;
  9460. }
  9461. wolfSSL_set_fd(ssl, clientfd);
  9462. /* call ssl setup callback */
  9463. if (cbf != NULL && cbf->ssl_ready != NULL) {
  9464. cbf->ssl_ready(ssl);
  9465. }
  9466. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  9467. if (idx > 0) {
  9468. input[idx] = '\0';
  9469. fprintf(stderr, "Client message export/import: %s\n", input);
  9470. }
  9471. else {
  9472. fprintf(stderr, "ret = %d error = %d\n", idx,
  9473. wolfSSL_get_error(ssl, idx));
  9474. goto done;
  9475. }
  9476. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  9477. /*err_sys("SSL_write failed");*/
  9478. WOLFSSL_RETURN_FROM_THREAD(0);
  9479. }
  9480. #ifdef WOLFSSL_TIRTOS
  9481. Task_yield();
  9482. #endif
  9483. ((func_args*)args)->return_code = TEST_SUCCESS;
  9484. done:
  9485. wolfSSL_shutdown(ssl);
  9486. wolfSSL_free(ssl);
  9487. wolfSSL_CTX_free(ctx);
  9488. CloseSocket(clientfd);
  9489. #ifdef WOLFSSL_TIRTOS
  9490. fdCloseSession(Task_self());
  9491. #endif
  9492. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9493. && defined(HAVE_THREAD_LS)
  9494. wc_ecc_fp_free(); /* free per thread cache */
  9495. #endif
  9496. #if defined(HAVE_SESSION_TICKET) && \
  9497. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  9498. #if defined(OPENSSL_EXTRA) && defined(HAVE_AESGCM)
  9499. OpenSSLTicketCleanup();
  9500. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  9501. TicketCleanup();
  9502. #endif
  9503. #endif
  9504. WOLFSSL_RETURN_FROM_THREAD(0);
  9505. }
  9506. static void load_tls12_canned_server(WOLFSSL* ssl)
  9507. {
  9508. int clientfd = wolfSSL_get_fd(ssl);
  9509. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_session,
  9510. sizeof(canned_server_session)), sizeof(canned_server_session));
  9511. wolfSSL_set_fd(ssl, clientfd);
  9512. }
  9513. #ifdef WOLFSSL_TLS13
  9514. static void load_tls13_canned_server(WOLFSSL* ssl)
  9515. {
  9516. int clientfd = wolfSSL_get_fd(ssl);
  9517. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_tls13_session,
  9518. sizeof(canned_server_tls13_session)),
  9519. sizeof(canned_server_tls13_session));
  9520. wolfSSL_set_fd(ssl, clientfd);
  9521. }
  9522. #endif
  9523. /* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  9524. static int test_wolfSSL_tls_export_run(int v)
  9525. {
  9526. EXPECT_DECLS;
  9527. SOCKET_T sockfd = 0;
  9528. WOLFSSL_CTX* ctx = 0;
  9529. WOLFSSL* ssl = 0;
  9530. char msg[64] = "hello wolfssl!";
  9531. char reply[1024];
  9532. word32 replySz;
  9533. int msgSz = (int)XSTRLEN(msg);
  9534. const byte* clientSession = NULL;
  9535. int clientSessionSz = 0;
  9536. tcp_ready ready;
  9537. func_args server_args;
  9538. THREAD_TYPE serverThread;
  9539. callback_functions server_cbf;
  9540. #ifdef WOLFSSL_TIRTOS
  9541. fdOpenSession(Task_self());
  9542. #endif
  9543. InitTcpReady(&ready);
  9544. #if defined(USE_WINDOWS_API)
  9545. /* use RNG to get random port if using windows */
  9546. ready.port = GetRandomPort();
  9547. #endif
  9548. XMEMSET(&server_args, 0, sizeof(func_args));
  9549. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9550. switch (v) {
  9551. case WOLFSSL_TLSV1_2:
  9552. server_cbf.method = wolfTLSv1_2_server_method;
  9553. server_cbf.ssl_ready = load_tls12_canned_server;
  9554. /* setup the client side */
  9555. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  9556. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9557. clientSession = canned_client_session;
  9558. clientSessionSz = sizeof(canned_client_session);
  9559. break;
  9560. #ifdef WOLFSSL_TLS13
  9561. case WOLFSSL_TLSV1_3:
  9562. server_cbf.method = wolfTLSv1_3_server_method;
  9563. server_cbf.ssl_ready = load_tls13_canned_server;
  9564. /* setup the client side */
  9565. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  9566. clientSession = canned_client_tls13_session;
  9567. clientSessionSz = sizeof(canned_client_tls13_session);
  9568. break;
  9569. #endif
  9570. }
  9571. server_args.callbacks = &server_cbf;
  9572. server_args.signal = &ready;
  9573. start_thread(tls_export_server, &server_args, &serverThread);
  9574. wait_tcp_ready(&server_args);
  9575. #ifdef WOLFSSL_TIRTOS
  9576. fdOpenSession(Task_self());
  9577. #endif
  9578. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9579. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  9580. ExpectIntEQ(wolfSSL_tls_import(ssl, clientSession, clientSessionSz),
  9581. clientSessionSz);
  9582. replySz = sizeof(reply);
  9583. ExpectIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
  9584. #if !defined(NO_PSK) && defined(HAVE_ANON)
  9585. /* index 20 has is setting if PSK was on and 49 is if anon is allowed */
  9586. ExpectIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
  9587. #endif
  9588. wolfSSL_set_fd(ssl, sockfd);
  9589. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9590. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)-1), 0);
  9591. wolfSSL_free(ssl);
  9592. wolfSSL_CTX_free(ctx);
  9593. CloseSocket(sockfd);
  9594. #ifdef WOLFSSL_TIRTOS
  9595. fdCloseSession(Task_self());
  9596. #endif
  9597. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9598. && defined(HAVE_THREAD_LS)
  9599. wc_ecc_fp_free(); /* free per thread cache */
  9600. #endif
  9601. join_thread(serverThread);
  9602. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9603. FreeTcpReady(&ready);
  9604. #ifdef WOLFSSL_TIRTOS
  9605. fdOpenSession(Task_self());
  9606. #endif
  9607. return EXPECT_RESULT();
  9608. }
  9609. #endif
  9610. static int test_wolfSSL_tls_export(void)
  9611. {
  9612. int res = TEST_SKIPPED;
  9613. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9614. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
  9615. #ifdef WOLFSSL_TLS13
  9616. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
  9617. #endif
  9618. res = TEST_RES_CHECK(1);
  9619. #endif
  9620. return res;
  9621. }
  9622. /*----------------------------------------------------------------------------*
  9623. | TLS extensions tests
  9624. *----------------------------------------------------------------------------*/
  9625. #ifdef ENABLE_TLS_CALLBACK_TEST
  9626. /* Connection test runner - generic */
  9627. static void test_wolfSSL_client_server(callback_functions* client_callbacks,
  9628. callback_functions* server_callbacks)
  9629. {
  9630. tcp_ready ready;
  9631. func_args client_args;
  9632. func_args server_args;
  9633. THREAD_TYPE serverThread;
  9634. XMEMSET(&client_args, 0, sizeof(func_args));
  9635. XMEMSET(&server_args, 0, sizeof(func_args));
  9636. StartTCP();
  9637. client_args.callbacks = client_callbacks;
  9638. server_args.callbacks = server_callbacks;
  9639. #ifdef WOLFSSL_TIRTOS
  9640. fdOpenSession(Task_self());
  9641. #endif
  9642. /* RUN Server side */
  9643. InitTcpReady(&ready);
  9644. #if defined(USE_WINDOWS_API)
  9645. /* use RNG to get random port if using windows */
  9646. ready.port = GetRandomPort();
  9647. #endif
  9648. server_args.signal = &ready;
  9649. client_args.signal = &ready;
  9650. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9651. wait_tcp_ready(&server_args);
  9652. /* RUN Client side */
  9653. run_wolfssl_client(&client_args);
  9654. join_thread(serverThread);
  9655. FreeTcpReady(&ready);
  9656. #ifdef WOLFSSL_TIRTOS
  9657. fdCloseSession(Task_self());
  9658. #endif
  9659. client_callbacks->return_code = client_args.return_code;
  9660. server_callbacks->return_code = server_args.return_code;
  9661. }
  9662. #endif /* ENABLE_TLS_CALLBACK_TEST */
  9663. #ifdef HAVE_SNI
  9664. static int test_wolfSSL_UseSNI_params(void)
  9665. {
  9666. EXPECT_DECLS;
  9667. #if !defined(NO_WOLFSSL_CLIENT)
  9668. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  9669. WOLFSSL *ssl = wolfSSL_new(ctx);
  9670. ExpectNotNull(ctx);
  9671. ExpectNotNull(ssl);
  9672. /* invalid [ctx|ssl] */
  9673. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
  9674. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
  9675. /* invalid type */
  9676. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, -1, "ctx", 3));
  9677. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, -1, "ssl", 3));
  9678. /* invalid data */
  9679. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
  9680. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
  9681. /* success case */
  9682. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
  9683. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
  9684. wolfSSL_free(ssl);
  9685. wolfSSL_CTX_free(ctx);
  9686. #endif /* !NO_WOLFSSL_CLIENT */
  9687. return EXPECT_RESULT();
  9688. }
  9689. /* BEGIN of connection tests callbacks */
  9690. static void use_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9691. {
  9692. AssertIntEQ(WOLFSSL_SUCCESS,
  9693. wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9694. }
  9695. static void use_SNI_at_ssl(WOLFSSL* ssl)
  9696. {
  9697. AssertIntEQ(WOLFSSL_SUCCESS,
  9698. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9699. }
  9700. static void different_SNI_at_ssl(WOLFSSL* ssl)
  9701. {
  9702. AssertIntEQ(WOLFSSL_SUCCESS,
  9703. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "ww2.wolfssl.com", 15));
  9704. }
  9705. static void use_SNI_WITH_CONTINUE_at_ssl(WOLFSSL* ssl)
  9706. {
  9707. use_SNI_at_ssl(ssl);
  9708. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9709. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  9710. }
  9711. static void use_SNI_WITH_FAKE_ANSWER_at_ssl(WOLFSSL* ssl)
  9712. {
  9713. use_SNI_at_ssl(ssl);
  9714. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9715. WOLFSSL_SNI_ANSWER_ON_MISMATCH);
  9716. }
  9717. static void use_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9718. {
  9719. use_SNI_at_ctx(ctx);
  9720. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9721. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9722. }
  9723. static void use_MANDATORY_SNI_at_ssl(WOLFSSL* ssl)
  9724. {
  9725. use_SNI_at_ssl(ssl);
  9726. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9727. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9728. }
  9729. static void use_PSEUDO_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9730. {
  9731. use_SNI_at_ctx(ctx);
  9732. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9733. WOLFSSL_SNI_ANSWER_ON_MISMATCH | WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9734. }
  9735. static void verify_UNKNOWN_SNI_on_server(WOLFSSL* ssl)
  9736. {
  9737. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_SNI_HOST_NAME_E),
  9738. wolfSSL_get_error(ssl, 0));
  9739. }
  9740. static void verify_SNI_ABSENT_on_server(WOLFSSL* ssl)
  9741. {
  9742. AssertIntEQ(WC_NO_ERR_TRACE(SNI_ABSENT_ERROR), wolfSSL_get_error(ssl, 0));
  9743. }
  9744. static void verify_SNI_no_matching(WOLFSSL* ssl)
  9745. {
  9746. byte type = WOLFSSL_SNI_HOST_NAME;
  9747. void* request = (void*) &type; /* to be overwritten */
  9748. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  9749. AssertNotNull(request);
  9750. AssertIntEQ(0, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9751. AssertNull(request);
  9752. }
  9753. static void verify_SNI_real_matching(WOLFSSL* ssl)
  9754. {
  9755. byte type = WOLFSSL_SNI_HOST_NAME;
  9756. void* request = NULL;
  9757. AssertIntEQ(WOLFSSL_SNI_REAL_MATCH, wolfSSL_SNI_Status(ssl, type));
  9758. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9759. AssertNotNull(request);
  9760. AssertStrEQ("www.wolfssl.com", (char*)request);
  9761. }
  9762. static void verify_SNI_fake_matching(WOLFSSL* ssl)
  9763. {
  9764. byte type = WOLFSSL_SNI_HOST_NAME;
  9765. void* request = NULL;
  9766. AssertIntEQ(WOLFSSL_SNI_FAKE_MATCH, wolfSSL_SNI_Status(ssl, type));
  9767. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9768. AssertNotNull(request);
  9769. AssertStrEQ("ww2.wolfssl.com", (char*)request);
  9770. }
  9771. static void verify_FATAL_ERROR_on_client(WOLFSSL* ssl)
  9772. {
  9773. AssertIntEQ(WC_NO_ERR_TRACE(FATAL_ERROR), wolfSSL_get_error(ssl, 0));
  9774. }
  9775. /* END of connection tests callbacks */
  9776. static int test_wolfSSL_UseSNI_connection(void)
  9777. {
  9778. int res = TEST_SKIPPED;
  9779. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  9780. callback_functions client_cb;
  9781. callback_functions server_cb;
  9782. size_t i;
  9783. #ifdef WOLFSSL_STATIC_MEMORY
  9784. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  9785. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  9786. #endif
  9787. struct {
  9788. method_provider client_meth;
  9789. method_provider server_meth;
  9790. #ifdef WOLFSSL_STATIC_MEMORY
  9791. wolfSSL_method_func client_meth_ex;
  9792. wolfSSL_method_func server_meth_ex;
  9793. #endif
  9794. } methods[] = {
  9795. #if defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_TLS13)
  9796. {wolfSSLv23_client_method, wolfSSLv23_server_method
  9797. #ifdef WOLFSSL_STATIC_MEMORY
  9798. ,wolfSSLv23_client_method_ex, wolfSSLv23_server_method_ex
  9799. #endif
  9800. },
  9801. #endif
  9802. #ifndef WOLFSSL_NO_TLS12
  9803. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method
  9804. #ifdef WOLFSSL_STATIC_MEMORY
  9805. ,wolfTLSv1_2_client_method_ex, wolfTLSv1_2_server_method_ex
  9806. #endif
  9807. },
  9808. #endif
  9809. #ifdef WOLFSSL_TLS13
  9810. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method
  9811. #ifdef WOLFSSL_STATIC_MEMORY
  9812. ,wolfTLSv1_3_client_method_ex, wolfTLSv1_3_server_method_ex
  9813. #endif
  9814. },
  9815. #endif
  9816. };
  9817. size_t methodsSz = sizeof(methods) / sizeof(*methods);
  9818. for (i = 0; i < methodsSz; i++) {
  9819. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  9820. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  9821. client_cb.method = methods[i].client_meth;
  9822. server_cb.method = methods[i].server_meth;
  9823. client_cb.devId = testDevId;
  9824. server_cb.devId = testDevId;
  9825. #ifdef WOLFSSL_STATIC_MEMORY
  9826. client_cb.method_ex = methods[i].client_meth_ex;
  9827. server_cb.method_ex = methods[i].server_meth_ex;
  9828. client_cb.mem = cliMem;
  9829. client_cb.memSz = (word32)sizeof(cliMem);
  9830. server_cb.mem = svrMem;
  9831. server_cb.memSz = (word32)sizeof(svrMem);;
  9832. #endif
  9833. /* success case at ctx */
  9834. fprintf(stderr, "\n\tsuccess case at ctx\n");
  9835. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  9836. server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  9837. test_wolfSSL_client_server(&client_cb, &server_cb);
  9838. /* success case at ssl */
  9839. fprintf(stderr, "\tsuccess case at ssl\n");
  9840. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching;
  9841. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching;
  9842. test_wolfSSL_client_server(&client_cb, &server_cb);
  9843. /* default mismatch behavior */
  9844. fprintf(stderr, "\tdefault mismatch behavior\n");
  9845. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client;
  9846. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server;
  9847. test_wolfSSL_client_server(&client_cb, &server_cb);
  9848. /* continue on mismatch */
  9849. fprintf(stderr, "\tcontinue on mismatch\n");
  9850. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  9851. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  9852. test_wolfSSL_client_server(&client_cb, &server_cb);
  9853. /* fake answer on mismatch */
  9854. fprintf(stderr, "\tfake answer on mismatch\n");
  9855. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  9856. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching;
  9857. test_wolfSSL_client_server(&client_cb, &server_cb);
  9858. /* sni abort - success */
  9859. fprintf(stderr, "\tsni abort - success\n");
  9860. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  9861. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  9862. test_wolfSSL_client_server(&client_cb, &server_cb);
  9863. /* sni abort - abort when absent (ctx) */
  9864. fprintf(stderr, "\tsni abort - abort when absent (ctx)\n");
  9865. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  9866. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server;
  9867. test_wolfSSL_client_server(&client_cb, &server_cb);
  9868. /* sni abort - abort when absent (ssl) */
  9869. fprintf(stderr, "\tsni abort - abort when absent (ssl)\n");
  9870. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  9871. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server;
  9872. test_wolfSSL_client_server(&client_cb, &server_cb);
  9873. /* sni abort - success when overwritten */
  9874. fprintf(stderr, "\tsni abort - success when overwritten\n");
  9875. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  9876. 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;
  9877. test_wolfSSL_client_server(&client_cb, &server_cb);
  9878. /* sni abort - success when allowing mismatches */
  9879. fprintf(stderr, "\tsni abort - success when allowing mismatches\n");
  9880. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  9881. server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching;
  9882. test_wolfSSL_client_server(&client_cb, &server_cb);
  9883. }
  9884. res = TEST_RES_CHECK(1);
  9885. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  9886. return res;
  9887. }
  9888. static int test_wolfSSL_SNI_GetFromBuffer(void)
  9889. {
  9890. EXPECT_DECLS;
  9891. byte buff[] = { /* www.paypal.com */
  9892. 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x60, 0x03, 0x03, 0x5c,
  9893. 0xc4, 0xb3, 0x8c, 0x87, 0xef, 0xa4, 0x09, 0xe0, 0x02, 0xab, 0x86, 0xca,
  9894. 0x76, 0xf0, 0x9e, 0x01, 0x65, 0xf6, 0xa6, 0x06, 0x13, 0x1d, 0x0f, 0xa5,
  9895. 0x79, 0xb0, 0xd4, 0x77, 0x22, 0xeb, 0x1a, 0x00, 0x00, 0x16, 0x00, 0x6b,
  9896. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  9897. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x21,
  9898. 0x00, 0x00, 0x00, 0x13, 0x00, 0x11, 0x00, 0x00, 0x0e, 0x77, 0x77, 0x77,
  9899. 0x2e, 0x70, 0x61, 0x79, 0x70, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x00,
  9900. 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  9901. };
  9902. byte buff2[] = { /* api.textmate.org */
  9903. 0x16, 0x03, 0x01, 0x00, 0xc6, 0x01, 0x00, 0x00, 0xc2, 0x03, 0x03, 0x52,
  9904. 0x8b, 0x7b, 0xca, 0x69, 0xec, 0x97, 0xd5, 0x08, 0x03, 0x50, 0xfe, 0x3b,
  9905. 0x99, 0xc3, 0x20, 0xce, 0xa5, 0xf6, 0x99, 0xa5, 0x71, 0xf9, 0x57, 0x7f,
  9906. 0x04, 0x38, 0xf6, 0x11, 0x0b, 0xb8, 0xd3, 0x00, 0x00, 0x5e, 0x00, 0xff,
  9907. 0xc0, 0x24, 0xc0, 0x23, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x07, 0xc0, 0x08,
  9908. 0xc0, 0x28, 0xc0, 0x27, 0xc0, 0x14, 0xc0, 0x13, 0xc0, 0x11, 0xc0, 0x12,
  9909. 0xc0, 0x26, 0xc0, 0x25, 0xc0, 0x2a, 0xc0, 0x29, 0xc0, 0x05, 0xc0, 0x04,
  9910. 0xc0, 0x02, 0xc0, 0x03, 0xc0, 0x0f, 0xc0, 0x0e, 0xc0, 0x0c, 0xc0, 0x0d,
  9911. 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x35,
  9912. 0x00, 0x0a, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x33, 0x00, 0x39, 0x00, 0x16,
  9913. 0x00, 0xaf, 0x00, 0xae, 0x00, 0x8d, 0x00, 0x8c, 0x00, 0x8a, 0x00, 0x8b,
  9914. 0x00, 0xb1, 0x00, 0xb0, 0x00, 0x2c, 0x00, 0x3b, 0x01, 0x00, 0x00, 0x3b,
  9915. 0x00, 0x00, 0x00, 0x15, 0x00, 0x13, 0x00, 0x00, 0x10, 0x61, 0x70, 0x69,
  9916. 0x2e, 0x74, 0x65, 0x78, 0x74, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x6f, 0x72,
  9917. 0x67, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00,
  9918. 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x0c, 0x00,
  9919. 0x0a, 0x05, 0x01, 0x04, 0x01, 0x02, 0x01, 0x04, 0x03, 0x02, 0x03
  9920. };
  9921. byte buff3[] = { /* no sni extension */
  9922. 0x16, 0x03, 0x03, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x49, 0x03, 0x03, 0xea,
  9923. 0xa1, 0x9f, 0x60, 0xdd, 0x52, 0x12, 0x13, 0xbd, 0x84, 0x34, 0xd5, 0x1c,
  9924. 0x38, 0x25, 0xa8, 0x97, 0xd2, 0xd5, 0xc6, 0x45, 0xaf, 0x1b, 0x08, 0xe4,
  9925. 0x1e, 0xbb, 0xdf, 0x9d, 0x39, 0xf0, 0x65, 0x00, 0x00, 0x16, 0x00, 0x6b,
  9926. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  9927. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x0a,
  9928. 0x00, 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  9929. };
  9930. byte buff4[] = { /* last extension has zero size */
  9931. 0x16, 0x03, 0x01, 0x00, 0xba, 0x01, 0x00, 0x00,
  9932. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  9933. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  9934. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  9935. 0x00, 0x28, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
  9936. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x13, 0xc0, 0x14, 0xc0, 0x07, 0xc0, 0x11,
  9937. 0x00, 0x33, 0x00, 0x32, 0x00, 0x39, 0x00, 0x9c, 0x00, 0x2f, 0x00, 0x35,
  9938. 0x00, 0x0a, 0x00, 0x05, 0x00, 0x04, 0x01, 0x00, 0x00, 0x65, 0xff, 0x01,
  9939. 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00,
  9940. 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, 0x00,
  9941. 0x00, 0x33, 0x74, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1b, 0x00, 0x19, 0x06,
  9942. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33, 0x08, 0x73, 0x70, 0x64, 0x79, 0x2f,
  9943. 0x33, 0x2e, 0x31, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31,
  9944. 0x75, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
  9945. 0x00, 0x00, 0x0d, 0x00, 0x12, 0x00, 0x10, 0x04, 0x01, 0x05, 0x01, 0x02,
  9946. 0x01, 0x04, 0x03, 0x05, 0x03, 0x02, 0x03, 0x04, 0x02, 0x02, 0x02, 0x00,
  9947. 0x12, 0x00, 0x00
  9948. };
  9949. byte buff5[] = { /* SSL v2.0 client hello */
  9950. 0x00, 0x2b, 0x01, 0x03, 0x01, 0x00, 0x09, 0x00, 0x00,
  9951. /* dummy bytes below, just to pass size check */
  9952. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  9953. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  9954. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  9955. };
  9956. byte result[32] = {0};
  9957. word32 length = 32;
  9958. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff4, sizeof(buff4),
  9959. 0, result, &length));
  9960. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff3, sizeof(buff3),
  9961. 0, result, &length));
  9962. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  9963. 1, result, &length));
  9964. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  9965. 0, result, &length));
  9966. buff[0] = 0x16;
  9967. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  9968. 0, result, &length));
  9969. buff[1] = 0x03;
  9970. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff,
  9971. sizeof(buff), 0, result, &length));
  9972. buff[2] = 0x03;
  9973. ExpectIntEQ(WC_NO_ERR_TRACE(INCOMPLETE_DATA), wolfSSL_SNI_GetFromBuffer(buff,
  9974. sizeof(buff), 0, result, &length));
  9975. buff[4] = 0x64;
  9976. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  9977. 0, result, &length));
  9978. if (EXPECT_SUCCESS())
  9979. result[length] = 0;
  9980. ExpectStrEQ("www.paypal.com", (const char*) result);
  9981. length = 32;
  9982. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  9983. 0, result, &length));
  9984. if (EXPECT_SUCCESS())
  9985. result[length] = 0;
  9986. ExpectStrEQ("api.textmate.org", (const char*) result);
  9987. /* SSL v2.0 tests */
  9988. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff5,
  9989. sizeof(buff5), 0, result, &length));
  9990. buff5[2] = 0x02;
  9991. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  9992. sizeof(buff5), 0, result, &length));
  9993. buff5[2] = 0x01; buff5[6] = 0x08;
  9994. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  9995. sizeof(buff5), 0, result, &length));
  9996. buff5[6] = 0x09; buff5[8] = 0x01;
  9997. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  9998. sizeof(buff5), 0, result, &length));
  9999. return EXPECT_RESULT();
  10000. }
  10001. #endif /* HAVE_SNI */
  10002. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  10003. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10004. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10005. /* Dummy peer functions to satisfy the exporter/importer */
  10006. static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip,
  10007. int* ipSz, unsigned short* port, int* fam)
  10008. {
  10009. (void)ssl;
  10010. ip[0] = -1;
  10011. *ipSz = 1;
  10012. *port = 1;
  10013. *fam = 2;
  10014. return 1;
  10015. }
  10016. static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip,
  10017. int ipSz, unsigned short port, int fam)
  10018. {
  10019. (void)ssl;
  10020. if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2)
  10021. return 0;
  10022. return 1;
  10023. }
  10024. static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx,
  10025. WOLFSSL **ssl)
  10026. {
  10027. EXPECT_DECLS;
  10028. unsigned char* sessionBuf = NULL;
  10029. unsigned int sessionSz = 0;
  10030. void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl);
  10031. void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl);
  10032. wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer);
  10033. wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer);
  10034. ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0);
  10035. ExpectNotNull(sessionBuf =
  10036. (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  10037. ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0);
  10038. wolfSSL_free(*ssl);
  10039. *ssl = NULL;
  10040. ExpectNotNull(*ssl = wolfSSL_new(*ctx));
  10041. ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0);
  10042. wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx);
  10043. wolfSSL_SetIOReadCtx(*ssl, ioReadCtx);
  10044. XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10045. return EXPECT_RESULT();
  10046. }
  10047. #endif
  10048. static int test_wolfSSL_dtls_export_peers(void)
  10049. {
  10050. EXPECT_DECLS;
  10051. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10052. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10053. test_ssl_cbf client_cbf;
  10054. test_ssl_cbf server_cbf;
  10055. size_t i, j;
  10056. struct test_params {
  10057. method_provider client_meth;
  10058. method_provider server_meth;
  10059. const char* dtls_version;
  10060. } params[] = {
  10061. #ifndef NO_OLD_TLS
  10062. {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"},
  10063. #endif
  10064. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"},
  10065. /* TODO DTLS 1.3 exporting not supported
  10066. #ifdef WOLFSSL_DTLS13
  10067. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"},
  10068. #endif
  10069. */
  10070. };
  10071. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  10072. for (j = 0; j <= 0b11; j++) {
  10073. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  10074. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  10075. printf("\n\tTesting DTLS %s connection;", params[i].dtls_version);
  10076. client_cbf.method = params[i].client_meth;
  10077. server_cbf.method = params[i].server_meth;
  10078. if (j & 0b01) {
  10079. client_cbf.on_handshake =
  10080. test_wolfSSL_dtls_export_peers_on_handshake;
  10081. printf(" With client export;");
  10082. }
  10083. if (j & 0b10) {
  10084. server_cbf.on_handshake =
  10085. test_wolfSSL_dtls_export_peers_on_handshake;
  10086. printf(" With server export;");
  10087. }
  10088. printf("\n");
  10089. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  10090. &server_cbf, NULL), TEST_SUCCESS);
  10091. if (!EXPECT_SUCCESS())
  10092. break;
  10093. }
  10094. }
  10095. #endif
  10096. return EXPECT_RESULT();
  10097. }
  10098. static int test_wolfSSL_UseTrustedCA(void)
  10099. {
  10100. EXPECT_DECLS;
  10101. #if defined(HAVE_TRUSTED_CA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  10102. && !defined(NO_RSA)
  10103. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10104. WOLFSSL_CTX *ctx = NULL;
  10105. WOLFSSL *ssl = NULL;
  10106. byte id[20];
  10107. #ifndef NO_WOLFSSL_SERVER
  10108. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())));
  10109. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10110. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10111. #else
  10112. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())));
  10113. #endif
  10114. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  10115. XMEMSET(id, 0, sizeof(id));
  10116. /* error cases */
  10117. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(NULL, 0, NULL, 0));
  10118. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10119. WOLFSSL_TRUSTED_CA_CERT_SHA1+1, NULL, 0));
  10120. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10121. WOLFSSL_TRUSTED_CA_CERT_SHA1, NULL, 0));
  10122. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10123. WOLFSSL_TRUSTED_CA_CERT_SHA1, id, 5));
  10124. #ifdef NO_SHA
  10125. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10126. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10127. #endif
  10128. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10129. WOLFSSL_TRUSTED_CA_X509_NAME, id, 0));
  10130. /* success cases */
  10131. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10132. WOLFSSL_TRUSTED_CA_PRE_AGREED, NULL, 0));
  10133. #ifndef NO_SHA
  10134. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10135. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10136. #endif
  10137. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10138. WOLFSSL_TRUSTED_CA_X509_NAME, id, 5));
  10139. wolfSSL_free(ssl);
  10140. wolfSSL_CTX_free(ctx);
  10141. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10142. #endif /* HAVE_TRUSTED_CA */
  10143. return EXPECT_RESULT();
  10144. }
  10145. static int test_wolfSSL_UseMaxFragment(void)
  10146. {
  10147. EXPECT_DECLS;
  10148. #if defined(HAVE_MAX_FRAGMENT) && !defined(NO_CERTS) && \
  10149. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10150. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10151. #ifndef NO_WOLFSSL_SERVER
  10152. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10153. #else
  10154. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10155. #endif
  10156. WOLFSSL *ssl = NULL;
  10157. #ifdef OPENSSL_EXTRA
  10158. int (*UseMaxFragment)(SSL *s, unsigned char mode);
  10159. int (*CTX_UseMaxFragment)(SSL_CTX *c, unsigned char mode);
  10160. #else
  10161. int (*UseMaxFragment)(WOLFSSL *s, unsigned char mode);
  10162. int (*CTX_UseMaxFragment)(WOLFSSL_CTX *c, unsigned char mode);
  10163. #endif
  10164. #ifndef NO_WOLFSSL_SERVER
  10165. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10166. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10167. #endif
  10168. ExpectNotNull(ctx);
  10169. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10170. #ifdef OPENSSL_EXTRA
  10171. CTX_UseMaxFragment = SSL_CTX_set_tlsext_max_fragment_length;
  10172. UseMaxFragment = SSL_set_tlsext_max_fragment_length;
  10173. #else
  10174. UseMaxFragment = wolfSSL_UseMaxFragment;
  10175. CTX_UseMaxFragment = wolfSSL_CTX_UseMaxFragment;
  10176. #endif
  10177. /* error cases */
  10178. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9));
  10179. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment( NULL, WOLFSSL_MFL_2_9));
  10180. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MIN-1));
  10181. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MAX+1));
  10182. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MIN-1));
  10183. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MAX+1));
  10184. /* success case */
  10185. #ifdef OPENSSL_EXTRA
  10186. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10187. #else
  10188. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10189. #endif
  10190. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9));
  10191. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_10));
  10192. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11));
  10193. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12));
  10194. #ifdef OPENSSL_EXTRA
  10195. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10196. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10197. #else
  10198. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10199. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10200. #endif
  10201. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_9));
  10202. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_10));
  10203. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_11));
  10204. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_12));
  10205. #ifdef OPENSSL_EXTRA
  10206. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10207. #else
  10208. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10209. #endif
  10210. wolfSSL_free(ssl);
  10211. wolfSSL_CTX_free(ctx);
  10212. #if defined(OPENSSL_EXTRA) && defined(HAVE_MAX_FRAGMENT) && \
  10213. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10214. /* check negotiated max fragment size */
  10215. {
  10216. WOLFSSL *ssl_c = NULL;
  10217. WOLFSSL *ssl_s = NULL;
  10218. struct test_memio_ctx test_ctx;
  10219. WOLFSSL_CTX *ctx_c = NULL;
  10220. WOLFSSL_CTX *ctx_s = NULL;
  10221. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10222. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10223. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10224. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
  10225. WOLFSSL_SUCCESS);
  10226. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10227. #ifndef NO_SESSION_CACHE
  10228. ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
  10229. wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
  10230. #endif
  10231. wolfSSL_free(ssl_c);
  10232. wolfSSL_free(ssl_s);
  10233. wolfSSL_CTX_free(ctx_c);
  10234. wolfSSL_CTX_free(ctx_s);
  10235. }
  10236. #endif
  10237. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10238. #endif
  10239. return EXPECT_RESULT();
  10240. }
  10241. static int test_wolfSSL_UseTruncatedHMAC(void)
  10242. {
  10243. EXPECT_DECLS;
  10244. #if defined(HAVE_TRUNCATED_HMAC) && !defined(NO_CERTS) && \
  10245. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10246. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10247. #ifndef NO_WOLFSSL_SERVER
  10248. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10249. #else
  10250. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10251. #endif
  10252. WOLFSSL *ssl = NULL;
  10253. ExpectNotNull(ctx);
  10254. #ifndef NO_WOLFSSL_SERVER
  10255. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10256. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10257. #endif
  10258. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10259. /* error cases */
  10260. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(NULL));
  10261. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(NULL));
  10262. /* success case */
  10263. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(ctx));
  10264. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(ssl));
  10265. wolfSSL_free(ssl);
  10266. wolfSSL_CTX_free(ctx);
  10267. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10268. #endif
  10269. return EXPECT_RESULT();
  10270. }
  10271. static int test_wolfSSL_UseSupportedCurve(void)
  10272. {
  10273. EXPECT_DECLS;
  10274. #if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_WOLFSSL_CLIENT) && \
  10275. !defined(NO_TLS)
  10276. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10277. WOLFSSL *ssl = wolfSSL_new(ctx);
  10278. ExpectNotNull(ctx);
  10279. ExpectNotNull(ssl);
  10280. /* error cases */
  10281. ExpectIntNE(WOLFSSL_SUCCESS,
  10282. wolfSSL_CTX_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10283. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSupportedCurve(ctx, 0));
  10284. ExpectIntNE(WOLFSSL_SUCCESS,
  10285. wolfSSL_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10286. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSupportedCurve(ssl, 0));
  10287. /* success case */
  10288. ExpectIntEQ(WOLFSSL_SUCCESS,
  10289. wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1));
  10290. ExpectIntEQ(WOLFSSL_SUCCESS,
  10291. wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1));
  10292. wolfSSL_free(ssl);
  10293. wolfSSL_CTX_free(ctx);
  10294. #endif
  10295. return EXPECT_RESULT();
  10296. }
  10297. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  10298. static void verify_ALPN_FATAL_ERROR_on_client(WOLFSSL* ssl)
  10299. {
  10300. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_ALPN_PROTOCOL_NAME_E), wolfSSL_get_error(ssl, 0));
  10301. }
  10302. static void use_ALPN_all(WOLFSSL* ssl)
  10303. {
  10304. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10305. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10306. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10307. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10308. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10309. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10310. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10311. }
  10312. static void use_ALPN_all_continue(WOLFSSL* ssl)
  10313. {
  10314. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10315. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10316. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10317. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10318. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10319. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10320. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10321. }
  10322. static void use_ALPN_one(WOLFSSL* ssl)
  10323. {
  10324. /* spdy/2 */
  10325. char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10326. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10327. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10328. }
  10329. static void use_ALPN_unknown(WOLFSSL* ssl)
  10330. {
  10331. /* http/2.0 */
  10332. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10333. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10334. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10335. }
  10336. static void use_ALPN_unknown_continue(WOLFSSL* ssl)
  10337. {
  10338. /* http/2.0 */
  10339. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10340. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10341. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10342. }
  10343. static void verify_ALPN_not_matching_spdy3(WOLFSSL* ssl)
  10344. {
  10345. /* spdy/3 */
  10346. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10347. char *proto = NULL;
  10348. word16 protoSz = 0;
  10349. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10350. /* check value */
  10351. AssertIntNE(1, sizeof(nego_proto) == protoSz);
  10352. if (proto) {
  10353. AssertIntNE(0, XMEMCMP(nego_proto, proto, sizeof(nego_proto)));
  10354. }
  10355. }
  10356. static void verify_ALPN_not_matching_continue(WOLFSSL* ssl)
  10357. {
  10358. char *proto = NULL;
  10359. word16 protoSz = 0;
  10360. AssertIntEQ(WC_NO_ERR_TRACE(WOLFSSL_ALPN_NOT_FOUND),
  10361. wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10362. /* check value */
  10363. AssertIntEQ(1, (0 == protoSz));
  10364. AssertIntEQ(1, (NULL == proto));
  10365. }
  10366. static void verify_ALPN_matching_http1(WOLFSSL* ssl)
  10367. {
  10368. /* http/1.1 */
  10369. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10370. char *proto;
  10371. word16 protoSz = 0;
  10372. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10373. /* check value */
  10374. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10375. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10376. }
  10377. static void verify_ALPN_matching_spdy2(WOLFSSL* ssl)
  10378. {
  10379. /* spdy/2 */
  10380. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10381. char *proto;
  10382. word16 protoSz = 0;
  10383. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10384. /* check value */
  10385. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10386. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10387. }
  10388. static void verify_ALPN_client_list(WOLFSSL* ssl)
  10389. {
  10390. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10391. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10392. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10393. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10394. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10395. char *clist = NULL;
  10396. word16 clistSz = 0;
  10397. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetPeerProtocol(ssl, &clist,
  10398. &clistSz));
  10399. /* check value */
  10400. AssertIntEQ(1, sizeof(alpn_list) == clistSz);
  10401. AssertIntEQ(0, XMEMCMP(alpn_list, clist, clistSz));
  10402. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
  10403. }
  10404. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10405. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10406. /* ALPN select callback, success with spdy/2 */
  10407. static int select_ALPN_spdy2(WOLFSSL *ssl, const unsigned char **out,
  10408. unsigned char *outlen, const unsigned char *in,
  10409. unsigned int inlen, void *arg)
  10410. {
  10411. /* spdy/2 */
  10412. const char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10413. (void)ssl;
  10414. (void)arg;
  10415. /* adding +1 since LEN byte comes first */
  10416. if (inlen < sizeof(proto) + 1) {
  10417. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10418. }
  10419. if (XMEMCMP(in + 1, proto, sizeof(proto)) == 0) {
  10420. *out = in + 1;
  10421. *outlen = (unsigned char)sizeof(proto);
  10422. return SSL_TLSEXT_ERR_OK;
  10423. }
  10424. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10425. }
  10426. /* ALPN select callback, force failure */
  10427. static int select_ALPN_failure(WOLFSSL *ssl, const unsigned char **out,
  10428. unsigned char *outlen, const unsigned char *in,
  10429. unsigned int inlen, void *arg)
  10430. {
  10431. (void)ssl;
  10432. (void)out;
  10433. (void)outlen;
  10434. (void)in;
  10435. (void)inlen;
  10436. (void)arg;
  10437. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10438. }
  10439. static void use_ALPN_spdy2_callback(WOLFSSL* ssl)
  10440. {
  10441. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_spdy2, NULL);
  10442. }
  10443. static void use_ALPN_failure_callback(WOLFSSL* ssl)
  10444. {
  10445. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_failure, NULL);
  10446. }
  10447. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY | QUIC */
  10448. static int test_wolfSSL_UseALPN_connection(void)
  10449. {
  10450. int res = TEST_SKIPPED;
  10451. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10452. callback_functions client_cb;
  10453. callback_functions server_cb;
  10454. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10455. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10456. client_cb.method = wolfSSLv23_client_method;
  10457. server_cb.method = wolfSSLv23_server_method;
  10458. client_cb.devId = testDevId;
  10459. server_cb.devId = testDevId;
  10460. /* success case same list */
  10461. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10462. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_http1;
  10463. test_wolfSSL_client_server(&client_cb, &server_cb);
  10464. /* success case only one for server */
  10465. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10466. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_matching_spdy2;
  10467. test_wolfSSL_client_server(&client_cb, &server_cb);
  10468. /* success case only one for client */
  10469. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_one; client_cb.on_result = NULL;
  10470. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_spdy2;
  10471. test_wolfSSL_client_server(&client_cb, &server_cb);
  10472. /* success case none for client */
  10473. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10474. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = NULL;
  10475. test_wolfSSL_client_server(&client_cb, &server_cb);
  10476. /* success case mismatch behavior but option 'continue' set */
  10477. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all_continue; client_cb.on_result = verify_ALPN_not_matching_continue;
  10478. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown_continue; server_cb.on_result = NULL;
  10479. test_wolfSSL_client_server(&client_cb, &server_cb);
  10480. /* success case read protocol send by client */
  10481. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10482. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_client_list;
  10483. test_wolfSSL_client_server(&client_cb, &server_cb);
  10484. /* mismatch behavior with same list
  10485. * the first and only this one must be taken */
  10486. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10487. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_not_matching_spdy3;
  10488. test_wolfSSL_client_server(&client_cb, &server_cb);
  10489. /* default mismatch behavior */
  10490. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10491. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown; server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10492. test_wolfSSL_client_server(&client_cb, &server_cb);
  10493. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10494. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10495. /* WOLFSSL-level ALPN select callback tests */
  10496. /* Callback: success (one protocol, spdy/2) */
  10497. client_cb.ctx_ready = NULL;
  10498. client_cb.ssl_ready = use_ALPN_one;
  10499. client_cb.on_result = verify_ALPN_matching_spdy2;
  10500. server_cb.ctx_ready = NULL;
  10501. server_cb.ssl_ready = use_ALPN_spdy2_callback;
  10502. server_cb.on_result = verify_ALPN_matching_spdy2;
  10503. test_wolfSSL_client_server(&client_cb, &server_cb);
  10504. /* Callback: failure (one client protocol, spdy/2) */
  10505. client_cb.ctx_ready = NULL;
  10506. client_cb.ssl_ready = use_ALPN_one;
  10507. client_cb.on_result = NULL;
  10508. server_cb.ctx_ready = NULL;
  10509. server_cb.ssl_ready = use_ALPN_failure_callback;
  10510. server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10511. test_wolfSSL_client_server(&client_cb, &server_cb);
  10512. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY */
  10513. res = TEST_RES_CHECK(1);
  10514. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10515. return res;
  10516. }
  10517. static int test_wolfSSL_UseALPN_params(void)
  10518. {
  10519. EXPECT_DECLS;
  10520. #ifndef NO_WOLFSSL_CLIENT
  10521. /* "http/1.1" */
  10522. char http1[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10523. /* "spdy/1" */
  10524. char spdy1[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x31};
  10525. /* "spdy/2" */
  10526. char spdy2[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10527. /* "spdy/3" */
  10528. char spdy3[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10529. char buff[256];
  10530. word32 idx;
  10531. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10532. WOLFSSL *ssl = wolfSSL_new(ctx);
  10533. ExpectNotNull(ctx);
  10534. ExpectNotNull(ssl);
  10535. /* error cases */
  10536. ExpectIntNE(WOLFSSL_SUCCESS,
  10537. wolfSSL_UseALPN(NULL, http1, sizeof(http1),
  10538. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10539. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, NULL, 0,
  10540. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10541. /* success case */
  10542. /* http1 only */
  10543. ExpectIntEQ(WOLFSSL_SUCCESS,
  10544. wolfSSL_UseALPN(ssl, http1, sizeof(http1),
  10545. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10546. /* http1, spdy1 */
  10547. XMEMCPY(buff, http1, sizeof(http1));
  10548. idx = sizeof(http1);
  10549. buff[idx++] = ',';
  10550. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10551. idx += sizeof(spdy1);
  10552. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10553. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10554. /* http1, spdy2, spdy1 */
  10555. XMEMCPY(buff, http1, sizeof(http1));
  10556. idx = sizeof(http1);
  10557. buff[idx++] = ',';
  10558. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10559. idx += sizeof(spdy2);
  10560. buff[idx++] = ',';
  10561. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10562. idx += sizeof(spdy1);
  10563. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10564. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10565. /* spdy3, http1, spdy2, spdy1 */
  10566. XMEMCPY(buff, spdy3, sizeof(spdy3));
  10567. idx = sizeof(spdy3);
  10568. buff[idx++] = ',';
  10569. XMEMCPY(buff+idx, http1, sizeof(http1));
  10570. idx += sizeof(http1);
  10571. buff[idx++] = ',';
  10572. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10573. idx += sizeof(spdy2);
  10574. buff[idx++] = ',';
  10575. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10576. idx += sizeof(spdy1);
  10577. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10578. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10579. wolfSSL_free(ssl);
  10580. wolfSSL_CTX_free(ctx);
  10581. #endif
  10582. return EXPECT_RESULT();
  10583. }
  10584. #endif /* HAVE_ALPN */
  10585. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  10586. static void CTX_set_alpn_protos(SSL_CTX *ctx)
  10587. {
  10588. unsigned char p[] = {
  10589. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10590. 6, 's', 'p', 'd', 'y', '/', '2',
  10591. 6, 's', 'p', 'd', 'y', '/', '1',
  10592. };
  10593. unsigned char p_len = sizeof(p);
  10594. int ret;
  10595. ret = SSL_CTX_set_alpn_protos(ctx, p, p_len);
  10596. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10597. AssertIntEQ(ret, 0);
  10598. #else
  10599. AssertIntEQ(ret, SSL_SUCCESS);
  10600. #endif
  10601. }
  10602. static void set_alpn_protos(SSL* ssl)
  10603. {
  10604. unsigned char p[] = {
  10605. 6, 's', 'p', 'd', 'y', '/', '3',
  10606. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10607. 6, 's', 'p', 'd', 'y', '/', '2',
  10608. 6, 's', 'p', 'd', 'y', '/', '1',
  10609. };
  10610. unsigned char p_len = sizeof(p);
  10611. int ret;
  10612. ret = SSL_set_alpn_protos(ssl, p, p_len);
  10613. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10614. AssertIntEQ(ret, 0);
  10615. #else
  10616. AssertIntEQ(ret, SSL_SUCCESS);
  10617. #endif
  10618. }
  10619. static void verify_alpn_matching_spdy3(WOLFSSL* ssl)
  10620. {
  10621. /* "spdy/3" */
  10622. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10623. const unsigned char *proto;
  10624. unsigned int protoSz = 0;
  10625. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10626. /* check value */
  10627. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10628. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10629. }
  10630. static void verify_alpn_matching_http1(WOLFSSL* ssl)
  10631. {
  10632. /* "http/1.1" */
  10633. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10634. const unsigned char *proto;
  10635. unsigned int protoSz = 0;
  10636. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10637. /* check value */
  10638. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10639. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10640. }
  10641. static int test_wolfSSL_set_alpn_protos(void)
  10642. {
  10643. int res = TEST_SKIPPED;
  10644. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10645. callback_functions client_cb;
  10646. callback_functions server_cb;
  10647. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10648. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10649. client_cb.method = wolfSSLv23_client_method;
  10650. server_cb.method = wolfSSLv23_server_method;
  10651. client_cb.devId = testDevId;
  10652. server_cb.devId = testDevId;
  10653. /* use CTX_alpn_protos */
  10654. client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10655. server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
  10656. test_wolfSSL_client_server(&client_cb, &server_cb);
  10657. /* use set_alpn_protos */
  10658. client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
  10659. server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
  10660. test_wolfSSL_client_server(&client_cb, &server_cb);
  10661. res = TEST_SUCCESS;
  10662. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10663. return res;
  10664. }
  10665. #endif /* HAVE_ALPN_PROTOS_SUPPORT */
  10666. static int test_wolfSSL_DisableExtendedMasterSecret(void)
  10667. {
  10668. EXPECT_DECLS;
  10669. #if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
  10670. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10671. WOLFSSL *ssl = wolfSSL_new(ctx);
  10672. ExpectNotNull(ctx);
  10673. ExpectNotNull(ssl);
  10674. /* error cases */
  10675. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(NULL));
  10676. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(NULL));
  10677. /* success cases */
  10678. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(ctx));
  10679. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(ssl));
  10680. wolfSSL_free(ssl);
  10681. wolfSSL_CTX_free(ctx);
  10682. #endif
  10683. return EXPECT_RESULT();
  10684. }
  10685. static int test_wolfSSL_wolfSSL_UseSecureRenegotiation(void)
  10686. {
  10687. EXPECT_DECLS;
  10688. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(NO_WOLFSSL_CLIENT)
  10689. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10690. WOLFSSL *ssl = wolfSSL_new(ctx);
  10691. ExpectNotNull(ctx);
  10692. ExpectNotNull(ssl);
  10693. /* error cases */
  10694. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(NULL));
  10695. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(NULL));
  10696. /* success cases */
  10697. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx));
  10698. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl));
  10699. wolfSSL_free(ssl);
  10700. wolfSSL_CTX_free(ctx);
  10701. #endif
  10702. return EXPECT_RESULT();
  10703. }
  10704. /* Test reconnecting with a different ciphersuite after a renegotiation. */
  10705. static int test_wolfSSL_SCR_Reconnect(void)
  10706. {
  10707. EXPECT_DECLS;
  10708. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  10709. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) && \
  10710. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) && \
  10711. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10712. struct test_memio_ctx test_ctx;
  10713. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  10714. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  10715. byte data;
  10716. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10717. test_ctx.c_ciphers = "ECDHE-RSA-AES256-GCM-SHA384";
  10718. test_ctx.s_ciphers =
  10719. "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305";
  10720. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10721. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10722. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_c));
  10723. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_s));
  10724. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_c));
  10725. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_s));
  10726. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10727. /* WOLFSSL_FATAL_ERROR since it will block */
  10728. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10729. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10730. WOLFSSL_ERROR_WANT_READ);
  10731. ExpectIntEQ(wolfSSL_read(ssl_c, &data, 1), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10732. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10733. WOLFSSL_ERROR_WANT_READ);
  10734. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10735. wolfSSL_free(ssl_c);
  10736. ssl_c = NULL;
  10737. wolfSSL_free(ssl_s);
  10738. ssl_s = NULL;
  10739. wolfSSL_CTX_free(ctx_c);
  10740. ctx_c = NULL;
  10741. test_ctx.c_ciphers = "ECDHE-RSA-CHACHA20-POLY1305";
  10742. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10743. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10744. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10745. wolfSSL_free(ssl_s);
  10746. wolfSSL_free(ssl_c);
  10747. wolfSSL_CTX_free(ctx_s);
  10748. wolfSSL_CTX_free(ctx_c);
  10749. #endif
  10750. return EXPECT_RESULT();
  10751. }
  10752. #if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_SERVER) && \
  10753. (!defined(NO_RSA) || defined(HAVE_ECC))
  10754. /* Called when writing. */
  10755. static int DummySend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10756. {
  10757. (void)ssl;
  10758. (void)buf;
  10759. (void)sz;
  10760. (void)ctx;
  10761. /* Force error return from wolfSSL_accept_TLSv13(). */
  10762. return WANT_WRITE;
  10763. }
  10764. /* Called when reading. */
  10765. static int BufferInfoRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10766. {
  10767. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  10768. int len = (int)msg->length;
  10769. (void)ssl;
  10770. (void)sz;
  10771. /* Pass back as much of message as will fit in buffer. */
  10772. if (len > sz)
  10773. len = sz;
  10774. XMEMCPY(buf, msg->buffer, len);
  10775. /* Move over returned data. */
  10776. msg->buffer += len;
  10777. msg->length -= len;
  10778. /* Amount actually copied. */
  10779. return len;
  10780. }
  10781. #endif
  10782. /* Test the detection of duplicate known TLS extensions.
  10783. * Specifically in a ClientHello.
  10784. */
  10785. static int test_tls_ext_duplicate(void)
  10786. {
  10787. EXPECT_DECLS;
  10788. #if !defined(NO_WOLFSSL_SERVER) && (!defined(NO_RSA) || defined(HAVE_ECC)) && \
  10789. !defined(NO_FILESYSTEM)
  10790. const unsigned char clientHelloDupTlsExt[] = {
  10791. 0x16, 0x03, 0x03, 0x00, 0x6a, 0x01, 0x00, 0x00,
  10792. 0x66, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  10793. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  10794. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  10795. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  10796. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  10797. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  10798. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  10799. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  10800. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x13, 0x01,
  10801. 0x00, 0x9e, 0x01, 0x00,
  10802. /* Extensions - duplicate signature algorithms. */
  10803. 0x00, 0x19, 0x00, 0x0d,
  10804. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x0d,
  10805. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01,
  10806. /* Supported Versions extension for TLS 1.3. */
  10807. 0x00, 0x2b,
  10808. 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03
  10809. };
  10810. WOLFSSL_BUFFER_INFO msg;
  10811. const char* testCertFile;
  10812. const char* testKeyFile;
  10813. WOLFSSL_CTX *ctx = NULL;
  10814. WOLFSSL *ssl = NULL;
  10815. #ifndef NO_RSA
  10816. testCertFile = svrCertFile;
  10817. testKeyFile = svrKeyFile;
  10818. #elif defined(HAVE_ECC)
  10819. testCertFile = eccCertFile;
  10820. testKeyFile = eccKeyFile;
  10821. #endif
  10822. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  10823. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  10824. WOLFSSL_FILETYPE_PEM));
  10825. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  10826. WOLFSSL_FILETYPE_PEM));
  10827. /* Read from 'msg'. */
  10828. wolfSSL_SetIORecv(ctx, BufferInfoRecv);
  10829. /* No where to send to - dummy sender. */
  10830. wolfSSL_SetIOSend(ctx, DummySend);
  10831. ssl = wolfSSL_new(ctx);
  10832. ExpectNotNull(ssl);
  10833. msg.buffer = (unsigned char*)clientHelloDupTlsExt;
  10834. msg.length = (unsigned int)sizeof(clientHelloDupTlsExt);
  10835. wolfSSL_SetIOReadCtx(ssl, &msg);
  10836. ExpectIntNE(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  10837. /* can return duplicate ext error or socket error if the peer closed down
  10838. * while sending alert */
  10839. if (wolfSSL_get_error(ssl, 0) != WC_NO_ERR_TRACE(SOCKET_ERROR_E)) {
  10840. ExpectIntEQ(wolfSSL_get_error(ssl, 0), WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
  10841. }
  10842. wolfSSL_free(ssl);
  10843. wolfSSL_CTX_free(ctx);
  10844. #endif
  10845. return EXPECT_RESULT();
  10846. }
  10847. /*----------------------------------------------------------------------------*
  10848. | X509 Tests
  10849. *----------------------------------------------------------------------------*/
  10850. static int test_wolfSSL_X509_NAME_get_entry(void)
  10851. {
  10852. EXPECT_DECLS;
  10853. #if !defined(NO_CERTS) && !defined(NO_RSA)
  10854. #if defined(OPENSSL_ALL) || \
  10855. (defined(OPENSSL_EXTRA) && \
  10856. (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS)))
  10857. /* use openssl like name to test mapping */
  10858. X509_NAME_ENTRY* ne = NULL;
  10859. X509_NAME* name = NULL;
  10860. X509* x509 = NULL;
  10861. #ifndef NO_FILESYSTEM
  10862. ASN1_STRING* asn = NULL;
  10863. char* subCN = NULL;
  10864. #endif
  10865. int idx = 0;
  10866. ASN1_OBJECT *object = NULL;
  10867. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  10868. defined(WOLFSSL_NGINX)
  10869. #ifndef NO_BIO
  10870. BIO* bio = NULL;
  10871. #endif
  10872. #endif
  10873. #ifndef NO_FILESYSTEM
  10874. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  10875. WOLFSSL_FILETYPE_PEM));
  10876. ExpectNotNull(name = X509_get_subject_name(x509));
  10877. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  10878. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  10879. ExpectNotNull(asn = X509_NAME_ENTRY_get_data(ne));
  10880. ExpectNotNull(subCN = (char*)ASN1_STRING_data(asn));
  10881. wolfSSL_FreeX509(x509);
  10882. x509 = NULL;
  10883. #endif
  10884. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  10885. WOLFSSL_FILETYPE_PEM));
  10886. ExpectNotNull(name = X509_get_subject_name(x509));
  10887. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  10888. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  10889. defined(WOLFSSL_NGINX)
  10890. #ifndef NO_BIO
  10891. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  10892. ExpectIntEQ(X509_NAME_print_ex(bio, name, 4,
  10893. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  10894. ExpectIntEQ(X509_NAME_print_ex_fp(stderr, name, 4,
  10895. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  10896. BIO_free(bio);
  10897. #endif
  10898. #endif
  10899. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  10900. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  10901. wolfSSL_FreeX509(x509);
  10902. #endif /* OPENSSL_ALL || (OPENSSL_EXTRA && (KEEP_PEER_CERT || SESSION_CERTS) */
  10903. #endif /* !NO_CERTS && !NO_RSA */
  10904. return EXPECT_RESULT();
  10905. }
  10906. /* Testing functions dealing with PKCS12 parsing out X509 certs */
  10907. static int test_wolfSSL_PKCS12(void)
  10908. {
  10909. EXPECT_DECLS;
  10910. /* .p12 file is encrypted with DES3 */
  10911. #ifndef HAVE_FIPS /* Password used in cert "wolfSSL test" is only 12-bytes
  10912. * (96-bit) FIPS mode requires Minimum of 14-byte (112-bit)
  10913. * Password Key
  10914. */
  10915. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \
  10916. !defined(NO_STDIO_FILESYSTEM) && \
  10917. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \
  10918. !defined(NO_SHA) && defined(HAVE_PKCS12) && !defined(NO_BIO)
  10919. byte buf[6000];
  10920. char file[] = "./certs/test-servercert.p12";
  10921. char order[] = "./certs/ecc-rsa-server.p12";
  10922. #ifdef WC_RC2
  10923. char rc2p12[] = "./certs/test-servercert-rc2.p12";
  10924. #endif
  10925. char pass[] = "a password";
  10926. const char goodPsw[] = "wolfSSL test";
  10927. const char badPsw[] = "bad";
  10928. #ifdef HAVE_ECC
  10929. WOLFSSL_X509_NAME *subject = NULL;
  10930. WOLFSSL_X509 *x509 = NULL;
  10931. #endif
  10932. XFILE f = XBADFILE;
  10933. int bytes = 0, ret = 0, goodPswLen = 0, badPswLen = 0;
  10934. WOLFSSL_BIO *bio = NULL;
  10935. WOLFSSL_EVP_PKEY *pkey = NULL;
  10936. WC_PKCS12 *pkcs12 = NULL;
  10937. WC_PKCS12 *pkcs12_2 = NULL;
  10938. WOLFSSL_X509 *cert = NULL;
  10939. WOLFSSL_X509 *tmp = NULL;
  10940. WOLF_STACK_OF(WOLFSSL_X509) *ca = NULL;
  10941. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  10942. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  10943. WOLFSSL_CTX *ctx = NULL;
  10944. WOLFSSL *ssl = NULL;
  10945. WOLF_STACK_OF(WOLFSSL_X509) *tmp_ca = NULL;
  10946. #endif
  10947. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  10948. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  10949. if (f != XBADFILE) {
  10950. XFCLOSE(f);
  10951. f = XBADFILE;
  10952. }
  10953. goodPswLen = (int)XSTRLEN(goodPsw);
  10954. badPswLen = (int)XSTRLEN(badPsw);
  10955. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  10956. ExpectIntEQ(BIO_write(bio, buf, bytes), bytes); /* d2i consumes BIO */
  10957. ExpectNotNull(d2i_PKCS12_bio(bio, &pkcs12));
  10958. ExpectNotNull(pkcs12);
  10959. BIO_free(bio);
  10960. bio = NULL;
  10961. /* check verify MAC directly */
  10962. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, goodPsw, goodPswLen), 1);
  10963. /* check verify MAC fail case directly */
  10964. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, badPsw, badPswLen), 0);
  10965. /* check verify MAC fail case */
  10966. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  10967. ExpectNull(pkey);
  10968. ExpectNull(cert);
  10969. /* check parse with no extra certs kept */
  10970. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  10971. 1);
  10972. ExpectNotNull(pkey);
  10973. ExpectNotNull(cert);
  10974. wolfSSL_EVP_PKEY_free(pkey);
  10975. pkey = NULL;
  10976. wolfSSL_X509_free(cert);
  10977. cert = NULL;
  10978. /* check parse with extra certs kept */
  10979. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  10980. 1);
  10981. ExpectNotNull(pkey);
  10982. ExpectNotNull(cert);
  10983. ExpectNotNull(ca);
  10984. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  10985. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  10986. /* Check that SSL_CTX_set0_chain correctly sets the certChain buffer */
  10987. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10988. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  10989. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  10990. #else
  10991. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  10992. #endif
  10993. /* Copy stack structure */
  10994. ExpectNotNull(tmp_ca = X509_chain_up_ref(ca));
  10995. ExpectIntEQ(SSL_CTX_set0_chain(ctx, tmp_ca), 1);
  10996. /* CTX now owns the tmp_ca stack structure */
  10997. tmp_ca = NULL;
  10998. ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &tmp_ca), 1);
  10999. ExpectNotNull(tmp_ca);
  11000. ExpectIntEQ(sk_X509_num(tmp_ca), sk_X509_num(ca));
  11001. /* Check that the main cert is also set */
  11002. ExpectNotNull(SSL_CTX_get0_certificate(ctx));
  11003. ExpectNotNull(ssl = SSL_new(ctx));
  11004. ExpectNotNull(SSL_get_certificate(ssl));
  11005. SSL_free(ssl);
  11006. SSL_CTX_free(ctx);
  11007. ctx = NULL;
  11008. #endif
  11009. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11010. /* should be 2 other certs on stack */
  11011. ExpectNotNull(tmp = sk_X509_pop(ca));
  11012. X509_free(tmp);
  11013. ExpectNotNull(tmp = sk_X509_pop(ca));
  11014. X509_free(tmp);
  11015. ExpectNull(sk_X509_pop(ca));
  11016. EVP_PKEY_free(pkey);
  11017. pkey = NULL;
  11018. X509_free(cert);
  11019. cert = NULL;
  11020. sk_X509_pop_free(ca, X509_free);
  11021. ca = NULL;
  11022. /* check PKCS12_create */
  11023. ExpectNull(PKCS12_create(pass, NULL, NULL, NULL, NULL, -1, -1, -1, -1,0));
  11024. ExpectIntEQ(PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11025. SSL_SUCCESS);
  11026. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11027. -1, -1, 100, -1, 0)));
  11028. EVP_PKEY_free(pkey);
  11029. pkey = NULL;
  11030. X509_free(cert);
  11031. cert = NULL;
  11032. sk_X509_pop_free(ca, NULL);
  11033. ca = NULL;
  11034. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11035. SSL_SUCCESS);
  11036. PKCS12_free(pkcs12_2);
  11037. pkcs12_2 = NULL;
  11038. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11039. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11040. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11041. 2000, 1, 0)));
  11042. EVP_PKEY_free(pkey);
  11043. pkey = NULL;
  11044. X509_free(cert);
  11045. cert = NULL;
  11046. sk_X509_pop_free(ca, NULL);
  11047. ca = NULL;
  11048. /* convert to DER then back and parse */
  11049. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11050. ExpectIntEQ(i2d_PKCS12_bio(bio, pkcs12_2), SSL_SUCCESS);
  11051. PKCS12_free(pkcs12_2);
  11052. pkcs12_2 = NULL;
  11053. ExpectNotNull(pkcs12_2 = d2i_PKCS12_bio(bio, NULL));
  11054. BIO_free(bio);
  11055. bio = NULL;
  11056. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11057. SSL_SUCCESS);
  11058. /* should be 2 other certs on stack */
  11059. ExpectNotNull(tmp = sk_X509_pop(ca));
  11060. X509_free(tmp);
  11061. ExpectNotNull(tmp = sk_X509_pop(ca));
  11062. X509_free(tmp);
  11063. ExpectNull(sk_X509_pop(ca));
  11064. #ifndef NO_RC4
  11065. PKCS12_free(pkcs12_2);
  11066. pkcs12_2 = NULL;
  11067. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, NULL,
  11068. NID_pbe_WithSHA1And128BitRC4,
  11069. NID_pbe_WithSHA1And128BitRC4,
  11070. 2000, 1, 0)));
  11071. EVP_PKEY_free(pkey);
  11072. pkey = NULL;
  11073. X509_free(cert);
  11074. cert = NULL;
  11075. sk_X509_pop_free(ca, NULL);
  11076. ca = NULL;
  11077. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11078. SSL_SUCCESS);
  11079. #endif /* NO_RC4 */
  11080. EVP_PKEY_free(pkey);
  11081. pkey = NULL;
  11082. X509_free(cert);
  11083. cert = NULL;
  11084. PKCS12_free(pkcs12);
  11085. pkcs12 = NULL;
  11086. PKCS12_free(pkcs12_2);
  11087. pkcs12_2 = NULL;
  11088. sk_X509_pop_free(ca, NULL);
  11089. ca = NULL;
  11090. #ifdef HAVE_ECC
  11091. /* test order of parsing */
  11092. ExpectTrue((f = XFOPEN(order, "rb")) != XBADFILE);
  11093. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11094. if (f != XBADFILE) {
  11095. XFCLOSE(f);
  11096. f = XBADFILE;
  11097. }
  11098. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11099. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11100. ExpectIntEQ((ret = PKCS12_parse(pkcs12, "", &pkey, &cert, &ca)),
  11101. WOLFSSL_SUCCESS);
  11102. /* check use of pkey after parse */
  11103. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11104. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11105. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11106. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11107. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11108. #else
  11109. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11110. #endif
  11111. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  11112. SSL_CTX_free(ctx);
  11113. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11114. #endif
  11115. ExpectNotNull(pkey);
  11116. ExpectNotNull(cert);
  11117. ExpectNotNull(ca);
  11118. /* compare subject lines of certificates */
  11119. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11120. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccRsaCertFile,
  11121. SSL_FILETYPE_PEM));
  11122. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11123. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11124. X509_free(x509);
  11125. x509 = NULL;
  11126. /* test expected fail case */
  11127. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11128. SSL_FILETYPE_PEM));
  11129. ExpectIntNE(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11130. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11131. X509_free(x509);
  11132. x509 = NULL;
  11133. X509_free(cert);
  11134. cert = NULL;
  11135. /* get subject line from ca stack */
  11136. ExpectNotNull(cert = sk_X509_pop(ca));
  11137. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11138. /* compare subject from certificate in ca to expected */
  11139. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11140. SSL_FILETYPE_PEM));
  11141. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11142. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11143. /* modify case and compare subject from certificate in ca to expected.
  11144. * The first bit of the name is:
  11145. * /C=US/ST=Washington
  11146. * So we'll change subject->name[1] to 'c' (lower case) */
  11147. if (subject != NULL) {
  11148. subject->name[1] = 'c';
  11149. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11150. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11151. }
  11152. EVP_PKEY_free(pkey);
  11153. pkey = NULL;
  11154. X509_free(x509);
  11155. x509 = NULL;
  11156. X509_free(cert);
  11157. cert = NULL;
  11158. BIO_free(bio);
  11159. bio = NULL;
  11160. PKCS12_free(pkcs12);
  11161. pkcs12 = NULL;
  11162. sk_X509_pop_free(ca, NULL); /* TEST d2i_PKCS12_fp */
  11163. ca = NULL;
  11164. /* test order of parsing */
  11165. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11166. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11167. if (f != XBADFILE) {
  11168. XFCLOSE(f);
  11169. f = XBADFILE;
  11170. }
  11171. /* check verify MAC fail case */
  11172. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11173. ExpectNull(pkey);
  11174. ExpectNull(cert);
  11175. /* check parse with no extra certs kept */
  11176. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11177. 1);
  11178. ExpectNotNull(pkey);
  11179. ExpectNotNull(cert);
  11180. wolfSSL_EVP_PKEY_free(pkey);
  11181. pkey = NULL;
  11182. wolfSSL_X509_free(cert);
  11183. cert = NULL;
  11184. /* check parse with extra certs kept */
  11185. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11186. 1);
  11187. ExpectNotNull(pkey);
  11188. ExpectNotNull(cert);
  11189. ExpectNotNull(ca);
  11190. wolfSSL_EVP_PKEY_free(pkey);
  11191. pkey = NULL;
  11192. wolfSSL_X509_free(cert);
  11193. cert = NULL;
  11194. sk_X509_pop_free(ca, NULL);
  11195. ca = NULL;
  11196. PKCS12_free(pkcs12);
  11197. pkcs12 = NULL;
  11198. #endif /* HAVE_ECC */
  11199. #ifdef WC_RC2
  11200. /* test PKCS#12 with RC2 encryption */
  11201. ExpectTrue((f = XFOPEN(rc2p12, "rb")) != XBADFILE);
  11202. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11203. if (f != XBADFILE) {
  11204. XFCLOSE(f);
  11205. f = XBADFILE;
  11206. }
  11207. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11208. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11209. /* check verify MAC fail case */
  11210. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11211. ExpectNull(pkey);
  11212. ExpectNull(cert);
  11213. /* check parse with not extra certs kept */
  11214. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11215. WOLFSSL_SUCCESS);
  11216. ExpectNotNull(pkey);
  11217. ExpectNotNull(cert);
  11218. wolfSSL_EVP_PKEY_free(pkey);
  11219. pkey = NULL;
  11220. wolfSSL_X509_free(cert);
  11221. cert = NULL;
  11222. /* check parse with extra certs kept */
  11223. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11224. WOLFSSL_SUCCESS);
  11225. ExpectNotNull(pkey);
  11226. ExpectNotNull(cert);
  11227. ExpectNotNull(ca);
  11228. wolfSSL_EVP_PKEY_free(pkey);
  11229. wolfSSL_X509_free(cert);
  11230. sk_X509_pop_free(ca, NULL);
  11231. BIO_free(bio);
  11232. bio = NULL;
  11233. PKCS12_free(pkcs12);
  11234. pkcs12 = NULL;
  11235. #endif /* WC_RC2 */
  11236. /* Test i2d_PKCS12_bio */
  11237. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11238. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11239. if (f != XBADFILE)
  11240. XFCLOSE(f);
  11241. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11242. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, pkcs12), 1);
  11243. ExpectIntEQ(ret = i2d_PKCS12_bio(NULL, pkcs12), 0);
  11244. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, NULL), 0);
  11245. PKCS12_free(pkcs12);
  11246. BIO_free(bio);
  11247. (void)order;
  11248. #endif /* OPENSSL_EXTRA */
  11249. #endif /* HAVE_FIPS */
  11250. return EXPECT_RESULT();
  11251. }
  11252. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11253. defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_PWDBASED) && \
  11254. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_MD5)
  11255. #define TEST_PKCS8_ENC
  11256. #endif
  11257. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11258. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11259. /* used to keep track if FailTestCallback was called */
  11260. static int failTestCallbackCalled = 0;
  11261. static WC_INLINE int FailTestCallBack(char* passwd, int sz, int rw, void* userdata)
  11262. {
  11263. (void)passwd;
  11264. (void)sz;
  11265. (void)rw;
  11266. (void)userdata;
  11267. /* mark called, test_wolfSSL_no_password_cb() will check and fail if set */
  11268. failTestCallbackCalled = 1;
  11269. return -1;
  11270. }
  11271. #endif
  11272. static int test_wolfSSL_no_password_cb(void)
  11273. {
  11274. EXPECT_DECLS;
  11275. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11276. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11277. WOLFSSL_CTX* ctx = NULL;
  11278. byte buff[FOURK_BUF];
  11279. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11280. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11281. XFILE f = XBADFILE;
  11282. int bytes = 0;
  11283. #ifndef NO_WOLFSSL_CLIENT
  11284. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
  11285. #else
  11286. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_server_method()));
  11287. #endif
  11288. wolfSSL_CTX_set_default_passwd_cb(ctx, FailTestCallBack);
  11289. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11290. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11291. if (f != XBADFILE) {
  11292. XFCLOSE(f);
  11293. f = XBADFILE;
  11294. }
  11295. ExpectIntLE(bytes, sizeof(buff));
  11296. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11297. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11298. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11299. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11300. if (f != XBADFILE)
  11301. XFCLOSE(f);
  11302. ExpectIntLE(bytes, sizeof(buff));
  11303. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11304. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11305. wolfSSL_CTX_free(ctx);
  11306. /* Password callback should not be called by default */
  11307. ExpectIntEQ(failTestCallbackCalled, 0);
  11308. #endif
  11309. return EXPECT_RESULT();
  11310. }
  11311. #ifdef TEST_PKCS8_ENC
  11312. /* for PKCS8 test case */
  11313. static int PKCS8TestCallBack(char* passwd, int sz, int rw, void* userdata)
  11314. {
  11315. int flag = 0;
  11316. (void)rw;
  11317. if (userdata != NULL) {
  11318. flag = *((int*)userdata); /* user set data */
  11319. }
  11320. switch (flag) {
  11321. case 1: /* flag set for specific WOLFSSL_CTX structure, note userdata
  11322. * can be anything the user wishes to be passed to the callback
  11323. * associated with the WOLFSSL_CTX */
  11324. XSTRNCPY(passwd, "yassl123", sz);
  11325. return 8;
  11326. default:
  11327. return BAD_FUNC_ARG;
  11328. }
  11329. }
  11330. #endif /* TEST_PKCS8_ENC */
  11331. /* Testing functions dealing with PKCS8 */
  11332. static int test_wolfSSL_PKCS8(void)
  11333. {
  11334. EXPECT_DECLS;
  11335. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11336. !defined(WOLFCRYPT_ONLY)
  11337. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11338. byte buff[FOURK_BUF];
  11339. byte der[FOURK_BUF];
  11340. #ifndef NO_RSA
  11341. const char serverKeyPkcs8PemFile[] = "./certs/server-keyPkcs8.pem";
  11342. const char serverKeyPkcs8DerFile[] = "./certs/server-keyPkcs8.der";
  11343. #endif
  11344. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11345. #ifdef HAVE_ECC
  11346. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11347. #endif
  11348. XFILE f = XBADFILE;
  11349. int bytes = 0;
  11350. WOLFSSL_CTX* ctx = NULL;
  11351. #if defined(HAVE_ECC) && !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11352. int ret;
  11353. ecc_key key;
  11354. word32 x = 0;
  11355. #endif
  11356. #ifdef TEST_PKCS8_ENC
  11357. #if !defined(NO_RSA) && !defined(NO_SHA)
  11358. const char serverKeyPkcs8EncPemFile[] = "./certs/server-keyPkcs8Enc.pem";
  11359. const char serverKeyPkcs8EncDerFile[] = "./certs/server-keyPkcs8Enc.der";
  11360. #endif
  11361. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11362. const char eccPkcs8EncPrivKeyPemFile[] = "./certs/ecc-keyPkcs8Enc.pem";
  11363. const char eccPkcs8EncPrivKeyDerFile[] = "./certs/ecc-keyPkcs8Enc.der";
  11364. #endif
  11365. int flag;
  11366. #endif
  11367. (void)der;
  11368. #ifndef NO_WOLFSSL_CLIENT
  11369. #ifndef WOLFSSL_NO_TLS12
  11370. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11371. #else
  11372. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11373. #endif
  11374. #else
  11375. #ifndef WOLFSSL_NO_TLS12
  11376. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11377. #else
  11378. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11379. #endif
  11380. #endif
  11381. #ifdef TEST_PKCS8_ENC
  11382. wolfSSL_CTX_set_default_passwd_cb(ctx, PKCS8TestCallBack);
  11383. wolfSSL_CTX_set_default_passwd_cb_userdata(ctx, (void*)&flag);
  11384. flag = 1; /* used by password callback as return code */
  11385. #if !defined(NO_RSA) && !defined(NO_SHA)
  11386. /* test loading PEM PKCS8 encrypted file */
  11387. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncPemFile, "rb")) != XBADFILE);
  11388. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11389. if (f != XBADFILE) {
  11390. XFCLOSE(f);
  11391. f = XBADFILE;
  11392. }
  11393. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11394. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11395. /* this next case should fail because of password callback return code */
  11396. flag = 0; /* used by password callback as return code */
  11397. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11398. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11399. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11400. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11401. "yassl123"), 0);
  11402. /* test that error value is returned with a bad password */
  11403. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11404. "bad"), 0);
  11405. /* test loading PEM PKCS8 encrypted file */
  11406. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncDerFile, "rb")) != XBADFILE);
  11407. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11408. if (f != XBADFILE) {
  11409. XFCLOSE(f);
  11410. f = XBADFILE;
  11411. }
  11412. flag = 1; /* used by password callback as return code */
  11413. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11414. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11415. /* this next case should fail because of password callback return code */
  11416. flag = 0; /* used by password callback as return code */
  11417. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11418. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11419. #endif /* !NO_RSA && !NO_SHA */
  11420. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11421. /* test loading PEM PKCS8 encrypted ECC Key file */
  11422. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyPemFile, "rb")) != XBADFILE);
  11423. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11424. if (f != XBADFILE) {
  11425. XFCLOSE(f);
  11426. f = XBADFILE;
  11427. }
  11428. flag = 1; /* used by password callback as return code */
  11429. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11430. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11431. /* this next case should fail because of password callback return code */
  11432. flag = 0; /* used by password callback as return code */
  11433. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11434. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11435. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11436. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11437. "yassl123"), 0);
  11438. /* test that error value is returned with a bad password */
  11439. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11440. "bad"), 0);
  11441. /* test loading DER PKCS8 encrypted ECC Key file */
  11442. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyDerFile, "rb")) != XBADFILE);
  11443. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11444. if (f != XBADFILE) {
  11445. XFCLOSE(f);
  11446. f = XBADFILE;
  11447. }
  11448. flag = 1; /* used by password callback as return code */
  11449. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11450. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11451. /* this next case should fail because of password callback return code */
  11452. flag = 0; /* used by password callback as return code */
  11453. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11454. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11455. /* leave flag as "okay" */
  11456. flag = 1;
  11457. #endif /* HAVE_ECC && !NO_SHA */
  11458. #endif /* TEST_PKCS8_ENC */
  11459. #ifndef NO_RSA
  11460. /* test loading ASN.1 (DER) PKCS8 private key file (not encrypted) */
  11461. ExpectTrue((f = XFOPEN(serverKeyPkcs8DerFile, "rb")) != XBADFILE);
  11462. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11463. if (f != XBADFILE) {
  11464. XFCLOSE(f);
  11465. f = XBADFILE;
  11466. }
  11467. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11468. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11469. /* test loading PEM PKCS8 private key file (not encrypted) */
  11470. ExpectTrue((f = XFOPEN(serverKeyPkcs8PemFile, "rb")) != XBADFILE);
  11471. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11472. if (f != XBADFILE) {
  11473. XFCLOSE(f);
  11474. f = XBADFILE;
  11475. }
  11476. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11477. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11478. #endif /* !NO_RSA */
  11479. /* Test PKCS8 PEM ECC key no crypt */
  11480. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11481. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11482. if (f != XBADFILE) {
  11483. XFCLOSE(f);
  11484. f = XBADFILE;
  11485. }
  11486. #ifdef HAVE_ECC
  11487. /* Test PKCS8 PEM ECC key no crypt */
  11488. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11489. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11490. #if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11491. /* decrypt PKCS8 PEM to key in DER format */
  11492. ExpectIntGT((bytes = wc_KeyPemToDer(buff, bytes, der,
  11493. (word32)sizeof(der), NULL)), 0);
  11494. ret = wc_ecc_init(&key);
  11495. if (ret == 0) {
  11496. ret = wc_EccPrivateKeyDecode(der, &x, &key, (word32)bytes);
  11497. wc_ecc_free(&key);
  11498. }
  11499. ExpectIntEQ(ret, 0);
  11500. #endif
  11501. /* Test PKCS8 DER ECC key no crypt */
  11502. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11503. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11504. if (f != XBADFILE)
  11505. XFCLOSE(f);
  11506. /* Test using a PKCS8 ECC PEM */
  11507. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11508. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11509. #else
  11510. /* if HAVE_ECC is not defined then BEGIN EC PRIVATE KEY is not found */
  11511. ExpectIntEQ((bytes = wc_KeyPemToDer(buff, bytes, der,
  11512. (word32)sizeof(der), NULL)), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  11513. #endif /* HAVE_ECC */
  11514. wolfSSL_CTX_free(ctx);
  11515. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11516. #endif /* !NO_FILESYSTEM && !NO_ASN && HAVE_PKCS8 */
  11517. return EXPECT_RESULT();
  11518. }
  11519. static int test_wolfSSL_PKCS8_ED25519(void)
  11520. {
  11521. EXPECT_DECLS;
  11522. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11523. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED25519) && \
  11524. defined(HAVE_ED25519_KEY_IMPORT)
  11525. const byte encPrivKey[] = \
  11526. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11527. "MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAheCGLmWGh7+AICCAAw\n"
  11528. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEC4L5P6GappsTyhOOoQfvh8EQJMX\n"
  11529. "OAdlsYKCOcFo4djg6AI1lRdeBRwVFWkha7gBdoCJOzS8wDvTbYcJMPvANu5ft3nl\n"
  11530. "2L9W4v7swXkV+X+a1ww=\n"
  11531. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11532. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11533. byte der[FOURK_BUF];
  11534. WOLFSSL_CTX* ctx = NULL;
  11535. int bytes;
  11536. XMEMSET(der, 0, sizeof(der));
  11537. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11538. (word32)sizeof(der), password)), 0);
  11539. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11540. #ifndef NO_WOLFSSL_SERVER
  11541. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11542. #else
  11543. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11544. #endif
  11545. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11546. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11547. wolfSSL_CTX_free(ctx);
  11548. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11549. #endif
  11550. return EXPECT_RESULT();
  11551. }
  11552. static int test_wolfSSL_PKCS8_ED448(void)
  11553. {
  11554. EXPECT_DECLS;
  11555. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11556. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED448) && \
  11557. defined(HAVE_ED448_KEY_IMPORT)
  11558. const byte encPrivKey[] = \
  11559. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11560. "MIGrMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjSbZKnG4EPggICCAAw\n"
  11561. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFvCFWBBHBlJBsYleBJlJWcEUNC7\n"
  11562. "Tf5pZviT5Btar4D/MNg6BsQHSDf5KW4ix871EsgDY2Zz+euaoWspiMntz7gU+PQu\n"
  11563. "T/JJcbD2Ly8BbE3l5WHMifAQqNLxJBfXrHkfYtAo\n"
  11564. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11565. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11566. byte der[FOURK_BUF];
  11567. WOLFSSL_CTX* ctx = NULL;
  11568. int bytes;
  11569. XMEMSET(der, 0, sizeof(der));
  11570. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11571. (word32)sizeof(der), password)), 0);
  11572. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11573. #ifndef NO_WOLFSSL_SERVER
  11574. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11575. #else
  11576. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11577. #endif
  11578. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11579. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11580. wolfSSL_CTX_free(ctx);
  11581. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11582. #endif
  11583. return EXPECT_RESULT();
  11584. }
  11585. /* Testing functions dealing with PKCS5 */
  11586. static int test_wolfSSL_PKCS5(void)
  11587. {
  11588. EXPECT_DECLS;
  11589. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA) && !defined(NO_PWDBASED)
  11590. #ifdef HAVE_FIPS /* Password minimum length is 14 (112-bit) in FIPS MODE */
  11591. const char* passwd = "myfipsPa$$W0rd";
  11592. #else
  11593. const char *passwd = "pass1234";
  11594. #endif
  11595. const unsigned char *salt = (unsigned char *)"salt1234";
  11596. unsigned char *out = (unsigned char *)XMALLOC(WC_SHA_DIGEST_SIZE, NULL,
  11597. DYNAMIC_TYPE_TMP_BUFFER);
  11598. int ret = 0;
  11599. ExpectNotNull(out);
  11600. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC_SHA1(passwd,(int)XSTRLEN(passwd), salt,
  11601. (int)XSTRLEN((const char *) salt), 10, WC_SHA_DIGEST_SIZE,out),
  11602. WOLFSSL_SUCCESS);
  11603. #ifdef WOLFSSL_SHA512
  11604. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC(passwd,(int)XSTRLEN(passwd), salt,
  11605. (int)XSTRLEN((const char *) salt), 10, wolfSSL_EVP_sha512(),
  11606. WC_SHA_DIGEST_SIZE, out), SSL_SUCCESS);
  11607. #endif
  11608. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11609. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SHA) */
  11610. return EXPECT_RESULT();
  11611. }
  11612. /* test parsing URI from certificate */
  11613. static int test_wolfSSL_URI(void)
  11614. {
  11615. EXPECT_DECLS;
  11616. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11617. && (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) || \
  11618. defined(OPENSSL_EXTRA))
  11619. WOLFSSL_X509* x509 = NULL;
  11620. const char uri[] = "./certs/client-uri-cert.pem";
  11621. const char urn[] = "./certs/client-absolute-urn.pem";
  11622. const char badUri[] = "./certs/client-relative-uri.pem";
  11623. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(uri,
  11624. WOLFSSL_FILETYPE_PEM));
  11625. wolfSSL_FreeX509(x509);
  11626. x509 = NULL;
  11627. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(urn,
  11628. WOLFSSL_FILETYPE_PEM));
  11629. wolfSSL_FreeX509(x509);
  11630. x509 = NULL;
  11631. #if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) \
  11632. && !defined(WOLFSSL_FPKI)
  11633. ExpectNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11634. WOLFSSL_FILETYPE_PEM));
  11635. #else
  11636. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11637. WOLFSSL_FILETYPE_PEM));
  11638. #endif
  11639. wolfSSL_FreeX509(x509);
  11640. #endif
  11641. return EXPECT_RESULT();
  11642. }
  11643. static int test_wolfSSL_TBS(void)
  11644. {
  11645. EXPECT_DECLS;
  11646. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11647. && defined(OPENSSL_EXTRA)
  11648. WOLFSSL_X509* x509 = NULL;
  11649. const unsigned char* tbs;
  11650. int tbsSz;
  11651. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile,
  11652. WOLFSSL_FILETYPE_PEM));
  11653. ExpectNull(tbs = wolfSSL_X509_get_tbs(NULL, &tbsSz));
  11654. ExpectNull(tbs = wolfSSL_X509_get_tbs(x509, NULL));
  11655. ExpectNotNull(tbs = wolfSSL_X509_get_tbs(x509, &tbsSz));
  11656. ExpectIntEQ(tbsSz, 1003);
  11657. wolfSSL_FreeX509(x509);
  11658. #endif
  11659. return EXPECT_RESULT();
  11660. }
  11661. static int test_wolfSSL_X509_verify(void)
  11662. {
  11663. EXPECT_DECLS;
  11664. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  11665. defined(OPENSSL_EXTRA)
  11666. WOLFSSL_X509* ca = NULL;
  11667. WOLFSSL_X509* serv = NULL;
  11668. WOLFSSL_EVP_PKEY* pkey = NULL;
  11669. unsigned char buf[2048];
  11670. const unsigned char* pt = NULL;
  11671. int bufSz;
  11672. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
  11673. WOLFSSL_FILETYPE_PEM));
  11674. ExpectIntNE(wolfSSL_X509_get_pubkey_buffer(NULL, buf, &bufSz),
  11675. WOLFSSL_SUCCESS);
  11676. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, NULL, &bufSz),
  11677. WOLFSSL_SUCCESS);
  11678. ExpectIntEQ(bufSz, 294);
  11679. bufSz = 2048;
  11680. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, buf, &bufSz),
  11681. WOLFSSL_SUCCESS);
  11682. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11683. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(ca), RSAk);
  11684. ExpectNotNull(serv = wolfSSL_X509_load_certificate_file(svrCertFile,
  11685. WOLFSSL_FILETYPE_PEM));
  11686. /* success case */
  11687. pt = buf;
  11688. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11689. ExpectIntEQ(i2d_PUBKEY(pkey, NULL), bufSz);
  11690. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WOLFSSL_SUCCESS);
  11691. wolfSSL_EVP_PKEY_free(pkey);
  11692. pkey = NULL;
  11693. /* fail case */
  11694. bufSz = 2048;
  11695. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(serv, buf, &bufSz),
  11696. WOLFSSL_SUCCESS);
  11697. pt = buf;
  11698. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11699. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11700. ExpectIntEQ(wolfSSL_X509_verify(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11701. ExpectIntEQ(wolfSSL_X509_verify(serv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11702. wolfSSL_EVP_PKEY_free(pkey);
  11703. wolfSSL_FreeX509(ca);
  11704. wolfSSL_FreeX509(serv);
  11705. #endif
  11706. return EXPECT_RESULT();
  11707. }
  11708. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  11709. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  11710. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  11711. /* create certificate with version 2 */
  11712. static int test_set_x509_badversion(WOLFSSL_CTX* ctx)
  11713. {
  11714. EXPECT_DECLS;
  11715. WOLFSSL_X509 *x509 = NULL, *x509v2 = NULL;
  11716. WOLFSSL_EVP_PKEY *priv = NULL, *pub = NULL;
  11717. unsigned char *der = NULL, *key = NULL, *pt;
  11718. char *header = NULL, *name = NULL;
  11719. int derSz;
  11720. long keySz;
  11721. XFILE fp = XBADFILE;
  11722. WOLFSSL_ASN1_TIME *notBefore = NULL, *notAfter = NULL;
  11723. time_t t;
  11724. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11725. WOLFSSL_FILETYPE_PEM));
  11726. ExpectTrue((fp = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  11727. ExpectIntEQ(wolfSSL_PEM_read(fp, &name, &header, &key, &keySz),
  11728. WOLFSSL_SUCCESS);
  11729. if (fp != XBADFILE)
  11730. XFCLOSE(fp);
  11731. pt = key;
  11732. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  11733. (const unsigned char**)&pt, keySz));
  11734. /* create the version 2 certificate */
  11735. ExpectNotNull(x509v2 = X509_new());
  11736. ExpectIntEQ(wolfSSL_X509_set_version(x509v2, 1), WOLFSSL_SUCCESS);
  11737. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509v2,
  11738. wolfSSL_X509_get_subject_name(x509)), WOLFSSL_SUCCESS);
  11739. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509v2,
  11740. wolfSSL_X509_get_issuer_name(x509)), WOLFSSL_SUCCESS);
  11741. ExpectNotNull(pub = wolfSSL_X509_get_pubkey(x509));
  11742. ExpectIntEQ(X509_set_pubkey(x509v2, pub), WOLFSSL_SUCCESS);
  11743. t = time(NULL);
  11744. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  11745. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  11746. ExpectTrue(wolfSSL_X509_set_notBefore(x509v2, notBefore));
  11747. ExpectTrue(wolfSSL_X509_set_notAfter(x509v2, notAfter));
  11748. ExpectIntGT(wolfSSL_X509_sign(x509v2, priv, EVP_sha256()), 0);
  11749. derSz = wolfSSL_i2d_X509(x509v2, &der);
  11750. ExpectIntGT(derSz, 0);
  11751. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, der, derSz,
  11752. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11753. /* TODO: Replace with API call */
  11754. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  11755. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11756. XFREE(name, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11757. XFREE(header, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11758. wolfSSL_X509_free(x509);
  11759. wolfSSL_X509_free(x509v2);
  11760. wolfSSL_EVP_PKEY_free(priv);
  11761. wolfSSL_EVP_PKEY_free(pub);
  11762. wolfSSL_ASN1_TIME_free(notBefore);
  11763. wolfSSL_ASN1_TIME_free(notAfter);
  11764. return EXPECT_RESULT();
  11765. }
  11766. /* override certificate version error */
  11767. static int test_override_x509(int preverify, WOLFSSL_X509_STORE_CTX* store)
  11768. {
  11769. EXPECT_DECLS;
  11770. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  11771. ExpectIntEQ(store->error, WC_NO_ERR_TRACE(ASN_VERSION_E));
  11772. #else
  11773. ExpectIntEQ(store->error, 0);
  11774. #endif
  11775. ExpectIntEQ((int)wolfSSL_X509_get_version(store->current_cert), 1);
  11776. (void)preverify;
  11777. return EXPECT_RESULT() == TEST_SUCCESS;
  11778. }
  11779. /* set verify callback that will override bad certificate version */
  11780. static int test_set_override_x509(WOLFSSL_CTX* ctx)
  11781. {
  11782. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, test_override_x509);
  11783. return TEST_SUCCESS;
  11784. }
  11785. #endif
  11786. static int test_wolfSSL_X509_TLS_version_test_1(void)
  11787. {
  11788. EXPECT_DECLS;
  11789. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  11790. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  11791. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  11792. test_ssl_cbf func_cb_client;
  11793. test_ssl_cbf func_cb_server;
  11794. /* test server rejects a client certificate that is not version 3 */
  11795. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  11796. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  11797. func_cb_client.ctx_ready = &test_set_x509_badversion;
  11798. #ifndef WOLFSSL_NO_TLS12
  11799. func_cb_client.method = wolfTLSv1_2_client_method;
  11800. #else
  11801. func_cb_client.method = wolfTLSv1_3_client_method;
  11802. #endif
  11803. #ifndef WOLFSSL_NO_TLS12
  11804. func_cb_server.method = wolfTLSv1_2_server_method;
  11805. #else
  11806. func_cb_server.method = wolfTLSv1_3_server_method;
  11807. #endif
  11808. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  11809. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  11810. &func_cb_server, NULL), TEST_FAIL);
  11811. #else
  11812. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  11813. &func_cb_server, NULL), TEST_SUCCESS);
  11814. #endif
  11815. #endif
  11816. return EXPECT_RESULT();
  11817. }
  11818. static int test_wolfSSL_X509_TLS_version_test_2(void)
  11819. {
  11820. EXPECT_DECLS;
  11821. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  11822. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  11823. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  11824. test_ssl_cbf func_cb_client;
  11825. test_ssl_cbf func_cb_server;
  11826. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  11827. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  11828. func_cb_client.ctx_ready = &test_set_x509_badversion;
  11829. func_cb_server.ctx_ready = &test_set_override_x509;
  11830. #ifndef WOLFSSL_NO_TLS12
  11831. func_cb_client.method = wolfTLSv1_2_client_method;
  11832. #else
  11833. func_cb_client.method = wolfTLSv1_3_client_method;
  11834. #endif
  11835. #ifndef WOLFSSL_NO_TLS12
  11836. func_cb_server.method = wolfTLSv1_2_server_method;
  11837. #else
  11838. func_cb_server.method = wolfTLSv1_3_server_method;
  11839. #endif
  11840. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  11841. &func_cb_server, NULL), TEST_SUCCESS);
  11842. #endif
  11843. return EXPECT_RESULT();
  11844. }
  11845. /* Testing function wolfSSL_CTX_SetMinVersion; sets the minimum downgrade
  11846. * version allowed.
  11847. * POST: 1 on success.
  11848. */
  11849. static int test_wolfSSL_CTX_SetMinVersion(void)
  11850. {
  11851. int res = TEST_SKIPPED;
  11852. #ifndef NO_WOLFSSL_CLIENT
  11853. int failFlag = WOLFSSL_SUCCESS;
  11854. WOLFSSL_CTX* ctx;
  11855. int itr;
  11856. #ifndef NO_OLD_TLS
  11857. const int versions[] = {
  11858. #ifdef WOLFSSL_ALLOW_TLSV10
  11859. WOLFSSL_TLSV1,
  11860. #endif
  11861. WOLFSSL_TLSV1_1,
  11862. WOLFSSL_TLSV1_2 };
  11863. #elif !defined(WOLFSSL_NO_TLS12)
  11864. const int versions[] = { WOLFSSL_TLSV1_2 };
  11865. #elif defined(WOLFSSL_TLS13)
  11866. const int versions[] = { WOLFSSL_TLSV1_3 };
  11867. #else
  11868. const int versions[0];
  11869. #endif
  11870. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  11871. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  11872. if (wolfSSL_CTX_SetMinVersion(ctx, *(versions + itr))
  11873. != WOLFSSL_SUCCESS) {
  11874. failFlag = WOLFSSL_FAILURE;
  11875. }
  11876. }
  11877. wolfSSL_CTX_free(ctx);
  11878. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  11879. #endif
  11880. return res;
  11881. } /* END test_wolfSSL_CTX_SetMinVersion */
  11882. /*----------------------------------------------------------------------------*
  11883. | OCSP Stapling
  11884. *----------------------------------------------------------------------------*/
  11885. /* Testing wolfSSL_UseOCSPStapling function. OCSP stapling eliminates the need
  11886. * need to contact the CA, lowering the cost of cert revocation checking.
  11887. * PRE: HAVE_OCSP and HAVE_CERTIFICATE_STATUS_REQUEST
  11888. * POST: 1 returned for success.
  11889. */
  11890. static int test_wolfSSL_UseOCSPStapling(void)
  11891. {
  11892. EXPECT_DECLS;
  11893. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && defined(HAVE_OCSP) && \
  11894. !defined(NO_WOLFSSL_CLIENT)
  11895. WOLFSSL_CTX* ctx = NULL;
  11896. WOLFSSL* ssl = NULL;
  11897. #ifndef NO_WOLFSSL_CLIENT
  11898. #ifndef WOLFSSL_NO_TLS12
  11899. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11900. #else
  11901. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11902. #endif
  11903. #else
  11904. #ifndef WOLFSSL_NO_TLS12
  11905. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11906. #else
  11907. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11908. #endif
  11909. #endif
  11910. ExpectNotNull(ssl = wolfSSL_new(ctx));
  11911. ExpectIntEQ(wolfSSL_UseOCSPStapling(NULL, WOLFSSL_CSR2_OCSP,
  11912. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  11913. #ifndef NO_WOLFSSL_CLIENT
  11914. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  11915. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  11916. #else
  11917. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  11918. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  11919. #endif
  11920. wolfSSL_free(ssl);
  11921. wolfSSL_CTX_free(ctx);
  11922. #endif
  11923. return EXPECT_RESULT();
  11924. } /* END test_wolfSSL_UseOCSPStapling */
  11925. /* Testing OCSP stapling version 2, wolfSSL_UseOCSPStaplingV2 function. OCSP
  11926. * stapling eliminates the need to contact the CA and lowers cert revocation
  11927. * check.
  11928. * PRE: HAVE_CERTIFICATE_STATUS_REQUEST_V2 and HAVE_OCSP defined.
  11929. */
  11930. static int test_wolfSSL_UseOCSPStaplingV2(void)
  11931. {
  11932. EXPECT_DECLS;
  11933. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && defined(HAVE_OCSP) && \
  11934. !defined(NO_WOLFSSL_CLIENT)
  11935. WOLFSSL_CTX* ctx = NULL;
  11936. WOLFSSL* ssl = NULL;
  11937. #ifndef NO_WOLFSSL_CLIENT
  11938. #ifndef WOLFSSL_NO_TLS12
  11939. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11940. #else
  11941. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11942. #endif
  11943. #else
  11944. #ifndef WOLFSSL_NO_TLS12
  11945. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11946. #else
  11947. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11948. #endif
  11949. #endif
  11950. ExpectNotNull(ssl = wolfSSL_new(ctx));
  11951. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(NULL, WOLFSSL_CSR2_OCSP,
  11952. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  11953. #ifndef NO_WOLFSSL_CLIENT
  11954. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  11955. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  11956. #else
  11957. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  11958. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  11959. #endif
  11960. wolfSSL_free(ssl);
  11961. wolfSSL_CTX_free(ctx);
  11962. #endif
  11963. return EXPECT_RESULT();
  11964. } /* END test_wolfSSL_UseOCSPStaplingV2 */
  11965. /*----------------------------------------------------------------------------*
  11966. | Multicast Tests
  11967. *----------------------------------------------------------------------------*/
  11968. static int test_wolfSSL_mcast(void)
  11969. {
  11970. EXPECT_DECLS;
  11971. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_MULTICAST) && \
  11972. (defined(WOLFSSL_TLS13) || defined(WOLFSSL_SNIFFER))
  11973. WOLFSSL_CTX* ctx = NULL;
  11974. WOLFSSL* ssl = NULL;
  11975. byte preMasterSecret[512];
  11976. byte clientRandom[32];
  11977. byte serverRandom[32];
  11978. byte suite[2] = {0, 0xfe}; /* WDM_WITH_NULL_SHA256 */
  11979. byte buf[256];
  11980. word16 newId;
  11981. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  11982. ExpectIntEQ(wolfSSL_CTX_mcast_set_member_id(ctx, 0), WOLFSSL_SUCCESS);
  11983. ExpectNotNull(ssl = wolfSSL_new(ctx));
  11984. XMEMSET(preMasterSecret, 0x23, sizeof(preMasterSecret));
  11985. XMEMSET(clientRandom, 0xA5, sizeof(clientRandom));
  11986. XMEMSET(serverRandom, 0x5A, sizeof(serverRandom));
  11987. ExpectIntEQ(wolfSSL_set_secret(ssl, 23, preMasterSecret,
  11988. sizeof(preMasterSecret), clientRandom, serverRandom, suite),
  11989. WOLFSSL_SUCCESS);
  11990. ExpectIntLE(wolfSSL_mcast_read(ssl, &newId, buf, sizeof(buf)), 0);
  11991. ExpectIntLE(newId, 100);
  11992. wolfSSL_free(ssl);
  11993. wolfSSL_CTX_free(ctx);
  11994. #endif /* WOLFSSL_DTLS && WOLFSSL_MULTICAST && (WOLFSSL_TLS13 ||
  11995. * WOLFSSL_SNIFFER) */
  11996. return EXPECT_RESULT();
  11997. }
  11998. /*----------------------------------------------------------------------------*
  11999. | Wolfcrypt
  12000. *----------------------------------------------------------------------------*/
  12001. /*
  12002. * Unit test for the wc_InitBlake2b()
  12003. */
  12004. static int test_wc_InitBlake2b(void)
  12005. {
  12006. EXPECT_DECLS;
  12007. #ifdef HAVE_BLAKE2
  12008. Blake2b blake;
  12009. /* Test good arg. */
  12010. ExpectIntEQ(wc_InitBlake2b(&blake, 64), 0);
  12011. /* Test bad arg. */
  12012. ExpectIntEQ(wc_InitBlake2b(NULL, 64), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12013. ExpectIntEQ(wc_InitBlake2b(NULL, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12014. ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12015. ExpectIntEQ(wc_InitBlake2b(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12016. ExpectIntEQ(wc_InitBlake2b(&blake, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12017. #endif
  12018. return EXPECT_RESULT();
  12019. } /* END test_wc_InitBlake2b*/
  12020. /*
  12021. * Unit test for the wc_InitBlake2b_WithKey()
  12022. */
  12023. static int test_wc_InitBlake2b_WithKey(void)
  12024. {
  12025. EXPECT_DECLS;
  12026. #ifdef HAVE_BLAKE2
  12027. Blake2b blake;
  12028. word32 digestSz = BLAKE2B_KEYBYTES;
  12029. byte key[BLAKE2B_KEYBYTES];
  12030. word32 keylen = BLAKE2B_KEYBYTES;
  12031. XMEMSET(key, 0, sizeof(key));
  12032. /* Test good arg. */
  12033. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0);
  12034. /* Test bad args. */
  12035. ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen),
  12036. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12037. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, 256),
  12038. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12039. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0);
  12040. #endif
  12041. return EXPECT_RESULT();
  12042. } /* END wc_InitBlake2b_WithKey*/
  12043. /*
  12044. * Unit test for the wc_InitBlake2s_WithKey()
  12045. */
  12046. static int test_wc_InitBlake2s_WithKey(void)
  12047. {
  12048. EXPECT_DECLS;
  12049. #ifdef HAVE_BLAKE2S
  12050. Blake2s blake;
  12051. word32 digestSz = BLAKE2S_KEYBYTES;
  12052. byte *key = (byte*)"01234567890123456789012345678901";
  12053. word32 keylen = BLAKE2S_KEYBYTES;
  12054. /* Test good arg. */
  12055. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0);
  12056. /* Test bad args. */
  12057. ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen),
  12058. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12059. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, 256),
  12060. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12061. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0);
  12062. #endif
  12063. return EXPECT_RESULT();
  12064. } /* END wc_InitBlake2s_WithKey*/
  12065. /*
  12066. * Unit test for the wc_InitMd5()
  12067. */
  12068. static int test_wc_InitMd5(void)
  12069. {
  12070. EXPECT_DECLS;
  12071. #ifndef NO_MD5
  12072. wc_Md5 md5;
  12073. /* Test good arg. */
  12074. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12075. /* Test bad arg. */
  12076. ExpectIntEQ(wc_InitMd5(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12077. wc_Md5Free(&md5);
  12078. #endif
  12079. return EXPECT_RESULT();
  12080. } /* END test_wc_InitMd5 */
  12081. /*
  12082. * Testing wc_UpdateMd5()
  12083. */
  12084. static int test_wc_Md5Update(void)
  12085. {
  12086. EXPECT_DECLS;
  12087. #ifndef NO_MD5
  12088. wc_Md5 md5;
  12089. byte hash[WC_MD5_DIGEST_SIZE];
  12090. testVector a, b, c;
  12091. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12092. /* Input */
  12093. a.input = "a";
  12094. a.inLen = XSTRLEN(a.input);
  12095. ExpectIntEQ(wc_Md5Update(&md5, (byte*)a.input, (word32)a.inLen), 0);
  12096. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12097. /* Update input. */
  12098. a.input = "abc";
  12099. a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  12100. "\x72";
  12101. a.inLen = XSTRLEN(a.input);
  12102. a.outLen = XSTRLEN(a.output);
  12103. ExpectIntEQ(wc_Md5Update(&md5, (byte*) a.input, (word32) a.inLen), 0);
  12104. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12105. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  12106. /* Pass in bad values. */
  12107. b.input = NULL;
  12108. b.inLen = 0;
  12109. ExpectIntEQ(wc_Md5Update(&md5, (byte*)b.input, (word32)b.inLen), 0);
  12110. c.input = NULL;
  12111. c.inLen = WC_MD5_DIGEST_SIZE;
  12112. ExpectIntEQ(wc_Md5Update(&md5, (byte*)c.input, (word32)c.inLen),
  12113. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12114. ExpectIntEQ(wc_Md5Update(NULL, (byte*)a.input, (word32)a.inLen),
  12115. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12116. wc_Md5Free(&md5);
  12117. #endif
  12118. return EXPECT_RESULT();
  12119. } /* END test_wc_Md5Update() */
  12120. /*
  12121. * Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
  12122. */
  12123. static int test_wc_Md5Final(void)
  12124. {
  12125. EXPECT_DECLS;
  12126. #ifndef NO_MD5
  12127. /* Instantiate */
  12128. wc_Md5 md5;
  12129. byte* hash_test[3];
  12130. byte hash1[WC_MD5_DIGEST_SIZE];
  12131. byte hash2[2*WC_MD5_DIGEST_SIZE];
  12132. byte hash3[5*WC_MD5_DIGEST_SIZE];
  12133. int times, i;
  12134. /* Initialize */
  12135. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12136. hash_test[0] = hash1;
  12137. hash_test[1] = hash2;
  12138. hash_test[2] = hash3;
  12139. times = sizeof(hash_test)/sizeof(byte*);
  12140. for (i = 0; i < times; i++) {
  12141. ExpectIntEQ(wc_Md5Final(&md5, hash_test[i]), 0);
  12142. }
  12143. /* Test bad args. */
  12144. ExpectIntEQ(wc_Md5Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12145. ExpectIntEQ(wc_Md5Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12146. ExpectIntEQ(wc_Md5Final(&md5, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12147. wc_Md5Free(&md5);
  12148. #endif
  12149. return EXPECT_RESULT();
  12150. }
  12151. /*
  12152. * Unit test for the wc_InitSha()
  12153. */
  12154. static int test_wc_InitSha(void)
  12155. {
  12156. EXPECT_DECLS;
  12157. #ifndef NO_SHA
  12158. wc_Sha sha;
  12159. /* Test good arg. */
  12160. ExpectIntEQ(wc_InitSha(&sha), 0);
  12161. /* Test bad arg. */
  12162. ExpectIntEQ(wc_InitSha(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12163. wc_ShaFree(&sha);
  12164. #endif
  12165. return EXPECT_RESULT();
  12166. } /* END test_wc_InitSha */
  12167. /*
  12168. * Tesing wc_ShaUpdate()
  12169. */
  12170. static int test_wc_ShaUpdate(void)
  12171. {
  12172. EXPECT_DECLS;
  12173. #ifndef NO_SHA
  12174. wc_Sha sha;
  12175. byte hash[WC_SHA_DIGEST_SIZE];
  12176. testVector a, b, c;
  12177. ExpectIntEQ(wc_InitSha(&sha), 0);
  12178. /* Input. */
  12179. a.input = "a";
  12180. a.inLen = XSTRLEN(a.input);
  12181. ExpectIntEQ(wc_ShaUpdate(&sha, NULL, 0), 0);
  12182. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, 0), 0);
  12183. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12184. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12185. /* Update input. */
  12186. a.input = "abc";
  12187. a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  12188. "\x6C\x9C\xD0\xD8\x9D";
  12189. a.inLen = XSTRLEN(a.input);
  12190. a.outLen = XSTRLEN(a.output);
  12191. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12192. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12193. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  12194. /* Try passing in bad values. */
  12195. b.input = NULL;
  12196. b.inLen = 0;
  12197. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)b.input, (word32)b.inLen), 0);
  12198. c.input = NULL;
  12199. c.inLen = WC_SHA_DIGEST_SIZE;
  12200. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)c.input, (word32)c.inLen),
  12201. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12202. ExpectIntEQ(wc_ShaUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  12203. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12204. wc_ShaFree(&sha);
  12205. #endif
  12206. return EXPECT_RESULT();
  12207. } /* END test_wc_ShaUpdate() */
  12208. /*
  12209. * Unit test on wc_ShaFinal
  12210. */
  12211. static int test_wc_ShaFinal(void)
  12212. {
  12213. EXPECT_DECLS;
  12214. #ifndef NO_SHA
  12215. wc_Sha sha;
  12216. byte* hash_test[3];
  12217. byte hash1[WC_SHA_DIGEST_SIZE];
  12218. byte hash2[2*WC_SHA_DIGEST_SIZE];
  12219. byte hash3[5*WC_SHA_DIGEST_SIZE];
  12220. int times, i;
  12221. /* Initialize*/
  12222. ExpectIntEQ(wc_InitSha(&sha), 0);
  12223. hash_test[0] = hash1;
  12224. hash_test[1] = hash2;
  12225. hash_test[2] = hash3;
  12226. times = sizeof(hash_test)/sizeof(byte*);
  12227. for (i = 0; i < times; i++) {
  12228. ExpectIntEQ(wc_ShaFinal(&sha, hash_test[i]), 0);
  12229. }
  12230. /* Test bad args. */
  12231. ExpectIntEQ(wc_ShaFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12232. ExpectIntEQ(wc_ShaFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12233. ExpectIntEQ(wc_ShaFinal(&sha, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12234. wc_ShaFree(&sha);
  12235. #endif
  12236. return EXPECT_RESULT();
  12237. } /* END test_wc_ShaFinal */
  12238. /*
  12239. * Unit test for wc_InitSha256()
  12240. */
  12241. static int test_wc_InitSha256(void)
  12242. {
  12243. EXPECT_DECLS;
  12244. #ifndef NO_SHA256
  12245. wc_Sha256 sha256;
  12246. /* Test good arg. */
  12247. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12248. /* Test bad arg. */
  12249. ExpectIntEQ(wc_InitSha256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12250. wc_Sha256Free(&sha256);
  12251. #endif
  12252. return EXPECT_RESULT();
  12253. } /* END test_wc_InitSha256 */
  12254. /*
  12255. * Unit test for wc_Sha256Update()
  12256. */
  12257. static int test_wc_Sha256Update(void)
  12258. {
  12259. EXPECT_DECLS;
  12260. #ifndef NO_SHA256
  12261. wc_Sha256 sha256;
  12262. byte hash[WC_SHA256_DIGEST_SIZE];
  12263. byte hash_unaligned[WC_SHA256_DIGEST_SIZE+1];
  12264. testVector a, b, c;
  12265. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12266. /* Input. */
  12267. a.input = "a";
  12268. a.inLen = XSTRLEN(a.input);
  12269. ExpectIntEQ(wc_Sha256Update(&sha256, NULL, 0), 0);
  12270. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, 0), 0);
  12271. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12272. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12273. /* Update input. */
  12274. a.input = "abc";
  12275. a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  12276. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  12277. "\x15\xAD";
  12278. a.inLen = XSTRLEN(a.input);
  12279. a.outLen = XSTRLEN(a.output);
  12280. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12281. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12282. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  12283. /* Unaligned check. */
  12284. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input+1, (word32)a.inLen-1),
  12285. 0);
  12286. ExpectIntEQ(wc_Sha256Final(&sha256, hash_unaligned + 1), 0);
  12287. /* Try passing in bad values */
  12288. b.input = NULL;
  12289. b.inLen = 0;
  12290. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)b.input, (word32)b.inLen), 0);
  12291. c.input = NULL;
  12292. c.inLen = WC_SHA256_DIGEST_SIZE;
  12293. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)c.input, (word32)c.inLen),
  12294. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12295. ExpectIntEQ(wc_Sha256Update(NULL, (byte*)a.input, (word32)a.inLen),
  12296. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12297. wc_Sha256Free(&sha256);
  12298. #endif
  12299. return EXPECT_RESULT();
  12300. } /* END test_wc_Sha256Update */
  12301. /*
  12302. * Unit test function for wc_Sha256Final()
  12303. */
  12304. static int test_wc_Sha256Final(void)
  12305. {
  12306. EXPECT_DECLS;
  12307. #ifndef NO_SHA256
  12308. wc_Sha256 sha256;
  12309. byte* hash_test[3];
  12310. byte hash1[WC_SHA256_DIGEST_SIZE];
  12311. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12312. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12313. int times, i;
  12314. /* Initialize */
  12315. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12316. hash_test[0] = hash1;
  12317. hash_test[1] = hash2;
  12318. hash_test[2] = hash3;
  12319. times = sizeof(hash_test) / sizeof(byte*);
  12320. for (i = 0; i < times; i++) {
  12321. ExpectIntEQ(wc_Sha256Final(&sha256, hash_test[i]), 0);
  12322. }
  12323. /* Test bad args. */
  12324. ExpectIntEQ(wc_Sha256Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12325. ExpectIntEQ(wc_Sha256Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12326. ExpectIntEQ(wc_Sha256Final(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12327. wc_Sha256Free(&sha256);
  12328. #endif
  12329. return EXPECT_RESULT();
  12330. } /* END test_wc_Sha256Final */
  12331. /*
  12332. * Unit test function for wc_Sha256FinalRaw()
  12333. */
  12334. static int test_wc_Sha256FinalRaw(void)
  12335. {
  12336. EXPECT_DECLS;
  12337. #if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  12338. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  12339. !defined(WOLFSSL_NO_HASH_RAW)
  12340. wc_Sha256 sha256;
  12341. byte* hash_test[3];
  12342. byte hash1[WC_SHA256_DIGEST_SIZE];
  12343. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12344. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12345. int times, i;
  12346. /* Initialize */
  12347. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12348. hash_test[0] = hash1;
  12349. hash_test[1] = hash2;
  12350. hash_test[2] = hash3;
  12351. times = sizeof(hash_test) / sizeof(byte*);
  12352. for (i = 0; i < times; i++) {
  12353. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, hash_test[i]), 0);
  12354. }
  12355. /* Test bad args. */
  12356. ExpectIntEQ(wc_Sha256FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12357. ExpectIntEQ(wc_Sha256FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12358. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12359. wc_Sha256Free(&sha256);
  12360. #endif
  12361. return EXPECT_RESULT();
  12362. } /* END test_wc_Sha256FinalRaw */
  12363. /*
  12364. * Unit test function for wc_Sha256GetFlags()
  12365. */
  12366. static int test_wc_Sha256GetFlags(void)
  12367. {
  12368. EXPECT_DECLS;
  12369. #if !defined(NO_SHA256) && defined(WOLFSSL_HASH_FLAGS)
  12370. wc_Sha256 sha256;
  12371. word32 flags = 0;
  12372. /* Initialize */
  12373. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12374. ExpectIntEQ(wc_Sha256GetFlags(&sha256, &flags), 0);
  12375. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12376. wc_Sha256Free(&sha256);
  12377. #endif
  12378. return EXPECT_RESULT();
  12379. } /* END test_wc_Sha256GetFlags */
  12380. /*
  12381. * Unit test function for wc_Sha256Free()
  12382. */
  12383. static int test_wc_Sha256Free(void)
  12384. {
  12385. EXPECT_DECLS;
  12386. #ifndef NO_SHA256
  12387. wc_Sha256Free(NULL);
  12388. /* Set result to SUCCESS. */
  12389. ExpectTrue(1);
  12390. #endif
  12391. return EXPECT_RESULT();
  12392. } /* END test_wc_Sha256Free */
  12393. /*
  12394. * Unit test function for wc_Sha256GetHash()
  12395. */
  12396. static int test_wc_Sha256GetHash(void)
  12397. {
  12398. EXPECT_DECLS;
  12399. #ifndef NO_SHA256
  12400. wc_Sha256 sha256;
  12401. byte hash1[WC_SHA256_DIGEST_SIZE];
  12402. /* Initialize */
  12403. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12404. ExpectIntEQ(wc_Sha256GetHash(&sha256, hash1), 0);
  12405. /* test bad arguments*/
  12406. ExpectIntEQ(wc_Sha256GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12407. ExpectIntEQ(wc_Sha256GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12408. ExpectIntEQ(wc_Sha256GetHash(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12409. wc_Sha256Free(&sha256);
  12410. #endif
  12411. return EXPECT_RESULT();
  12412. } /* END test_wc_Sha256GetHash */
  12413. /*
  12414. * Unit test function for wc_Sha256Copy()
  12415. */
  12416. static int test_wc_Sha256Copy(void)
  12417. {
  12418. EXPECT_DECLS;
  12419. #ifndef NO_SHA256
  12420. wc_Sha256 sha256;
  12421. wc_Sha256 temp;
  12422. XMEMSET(&sha256, 0, sizeof(sha256));
  12423. XMEMSET(&temp, 0, sizeof(temp));
  12424. /* Initialize */
  12425. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12426. ExpectIntEQ(wc_InitSha256(&temp), 0);
  12427. ExpectIntEQ(wc_Sha256Copy(&sha256, &temp), 0);
  12428. /* test bad arguments*/
  12429. ExpectIntEQ(wc_Sha256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12430. ExpectIntEQ(wc_Sha256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12431. ExpectIntEQ(wc_Sha256Copy(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12432. wc_Sha256Free(&sha256);
  12433. wc_Sha256Free(&temp);
  12434. #endif
  12435. return EXPECT_RESULT();
  12436. } /* END test_wc_Sha256Copy */
  12437. /*
  12438. * Testing wc_InitSha512()
  12439. */
  12440. static int test_wc_InitSha512(void)
  12441. {
  12442. EXPECT_DECLS;
  12443. #ifdef WOLFSSL_SHA512
  12444. wc_Sha512 sha512;
  12445. /* Test good arg. */
  12446. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12447. /* Test bad arg. */
  12448. ExpectIntEQ(wc_InitSha512(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12449. wc_Sha512Free(&sha512);
  12450. #endif
  12451. return EXPECT_RESULT();
  12452. } /* END test_wc_InitSha512 */
  12453. /*
  12454. * wc_Sha512Update() test.
  12455. */
  12456. static int test_wc_Sha512Update(void)
  12457. {
  12458. EXPECT_DECLS;
  12459. #ifdef WOLFSSL_SHA512
  12460. wc_Sha512 sha512;
  12461. byte hash[WC_SHA512_DIGEST_SIZE];
  12462. byte hash_unaligned[WC_SHA512_DIGEST_SIZE + 1];
  12463. testVector a, b, c;
  12464. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12465. /* Input. */
  12466. a.input = "a";
  12467. a.inLen = XSTRLEN(a.input);
  12468. ExpectIntEQ(wc_Sha512Update(&sha512, NULL, 0), 0);
  12469. ExpectIntEQ(wc_Sha512Update(&sha512,(byte*)a.input, 0), 0);
  12470. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input, (word32)a.inLen), 0);
  12471. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12472. /* Update input. */
  12473. a.input = "abc";
  12474. a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  12475. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b"
  12476. "\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c"
  12477. "\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a"
  12478. "\x9a\xc9\x4f\xa5\x4c\xa4\x9f";
  12479. a.inLen = XSTRLEN(a.input);
  12480. a.outLen = XSTRLEN(a.output);
  12481. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*) a.input, (word32) a.inLen), 0);
  12482. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12483. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_DIGEST_SIZE), 0);
  12484. /* Unaligned check. */
  12485. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input+1, (word32)a.inLen-1),
  12486. 0);
  12487. ExpectIntEQ(wc_Sha512Final(&sha512, hash_unaligned+1), 0);
  12488. /* Try passing in bad values */
  12489. b.input = NULL;
  12490. b.inLen = 0;
  12491. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)b.input, (word32)b.inLen), 0);
  12492. c.input = NULL;
  12493. c.inLen = WC_SHA512_DIGEST_SIZE;
  12494. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)c.input, (word32)c.inLen),
  12495. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12496. ExpectIntEQ(wc_Sha512Update(NULL, (byte*)a.input, (word32)a.inLen),
  12497. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12498. wc_Sha512Free(&sha512);
  12499. #endif
  12500. return EXPECT_RESULT();
  12501. } /* END test_wc_Sha512Update */
  12502. #ifdef WOLFSSL_SHA512
  12503. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12504. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  12505. /* Performs test for
  12506. * - wc_Sha512Final/wc_Sha512FinalRaw
  12507. * - wc_Sha512_224Final/wc_Sha512_224Final
  12508. * - wc_Sha512_256Final/wc_Sha512_256Final
  12509. * parameter:
  12510. * - type : must be one of WC_HASH_TYPE_SHA512, WC_HASH_TYPE_SHA512_224 or
  12511. * WC_HASH_TYPE_SHA512_256
  12512. * - isRaw: if is non-zero, xxxFinalRaw function will be tested
  12513. *return 0 on success
  12514. */
  12515. static int test_Sha512_Family_Final(int type, int isRaw)
  12516. {
  12517. EXPECT_DECLS;
  12518. wc_Sha512 sha512;
  12519. byte* hash_test[3];
  12520. byte hash1[WC_SHA512_DIGEST_SIZE];
  12521. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12522. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12523. int times, i;
  12524. int(*initFp)(wc_Sha512*);
  12525. int(*finalFp)(wc_Sha512*, byte*);
  12526. void(*freeFp)(wc_Sha512*);
  12527. if (type == WC_HASH_TYPE_SHA512) {
  12528. initFp = wc_InitSha512;
  12529. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12530. !defined(WOLFSSL_NO_HASH_RAW)
  12531. finalFp = (isRaw)? wc_Sha512FinalRaw : wc_Sha512Final;
  12532. #else
  12533. finalFp = (isRaw)? NULL : wc_Sha512Final;
  12534. #endif
  12535. freeFp = wc_Sha512Free;
  12536. }
  12537. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12538. #if !defined(WOLFSSL_NOSHA512_224)
  12539. else if (type == WC_HASH_TYPE_SHA512_224) {
  12540. initFp = wc_InitSha512_224;
  12541. #if !defined(WOLFSSL_NO_HASH_RAW)
  12542. finalFp = (isRaw)? wc_Sha512_224FinalRaw : wc_Sha512_224Final;
  12543. #else
  12544. finalFp = (isRaw)? NULL : wc_Sha512_224Final;
  12545. #endif
  12546. freeFp = wc_Sha512_224Free;
  12547. }
  12548. #endif
  12549. #if !defined(WOLFSSL_NOSHA512_256)
  12550. else if (type == WC_HASH_TYPE_SHA512_256) {
  12551. initFp = wc_InitSha512_256;
  12552. #if !defined(WOLFSSL_NO_HASH_RAW)
  12553. finalFp = (isRaw)? wc_Sha512_256FinalRaw : wc_Sha512_256Final;
  12554. #else
  12555. finalFp = (isRaw)? NULL : wc_Sha512_256Final;
  12556. #endif
  12557. freeFp = wc_Sha512_256Free;
  12558. }
  12559. #endif
  12560. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12561. else
  12562. return TEST_FAIL;
  12563. /* Initialize */
  12564. ExpectIntEQ(initFp(&sha512), 0);
  12565. hash_test[0] = hash1;
  12566. hash_test[1] = hash2;
  12567. hash_test[2] = hash3;
  12568. times = sizeof(hash_test) / sizeof(byte *);
  12569. /* Good test args. */
  12570. for (i = 0; i < times; i++) {
  12571. ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
  12572. }
  12573. /* Test bad args. */
  12574. ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12575. ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12576. ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12577. freeFp(&sha512);
  12578. return EXPECT_RESULT();
  12579. }
  12580. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  12581. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  12582. #endif /* WOLFSSL_SHA512 */
  12583. /*
  12584. * Unit test function for wc_Sha512Final()
  12585. */
  12586. static int test_wc_Sha512Final(void)
  12587. {
  12588. EXPECT_DECLS;
  12589. #ifdef WOLFSSL_SHA512
  12590. wc_Sha512 sha512;
  12591. byte* hash_test[3];
  12592. byte hash1[WC_SHA512_DIGEST_SIZE];
  12593. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12594. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12595. int times, i;
  12596. /* Initialize */
  12597. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12598. hash_test[0] = hash1;
  12599. hash_test[1] = hash2;
  12600. hash_test[2] = hash3;
  12601. times = sizeof(hash_test) / sizeof(byte *);
  12602. for (i = 0; i < times; i++) {
  12603. ExpectIntEQ(wc_Sha512Final(&sha512, hash_test[i]), 0);
  12604. }
  12605. /* Test bad args. */
  12606. ExpectIntEQ(wc_Sha512Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12607. ExpectIntEQ(wc_Sha512Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12608. ExpectIntEQ(wc_Sha512Final(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12609. wc_Sha512Free(&sha512);
  12610. #endif
  12611. return EXPECT_RESULT();
  12612. } /* END test_wc_Sha512Final */
  12613. /*
  12614. * Unit test function for wc_Sha512GetFlags()
  12615. */
  12616. static int test_wc_Sha512GetFlags(void)
  12617. {
  12618. EXPECT_DECLS;
  12619. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_HASH_FLAGS)
  12620. wc_Sha512 sha512;
  12621. word32 flags = 0;
  12622. /* Initialize */
  12623. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12624. ExpectIntEQ(wc_Sha512GetFlags(&sha512, &flags), 0);
  12625. ExpectIntEQ((flags & WC_HASH_FLAG_ISCOPY), 0);
  12626. wc_Sha512Free(&sha512);
  12627. #endif
  12628. return EXPECT_RESULT();
  12629. } /* END test_wc_Sha512GetFlags */
  12630. /*
  12631. * Unit test function for wc_Sha512FinalRaw()
  12632. */
  12633. static int test_wc_Sha512FinalRaw(void)
  12634. {
  12635. EXPECT_DECLS;
  12636. #if (defined(WOLFSSL_SHA512) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  12637. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  12638. !defined(WOLFSSL_NO_HASH_RAW)
  12639. wc_Sha512 sha512;
  12640. byte* hash_test[3];
  12641. byte hash1[WC_SHA512_DIGEST_SIZE];
  12642. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12643. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12644. int times, i;
  12645. /* Initialize */
  12646. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12647. hash_test[0] = hash1;
  12648. hash_test[1] = hash2;
  12649. hash_test[2] = hash3;
  12650. times = sizeof(hash_test) / sizeof(byte*);
  12651. /* Good test args. */
  12652. for (i = 0; i < times; i++) {
  12653. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, hash_test[i]), 0);
  12654. }
  12655. /* Test bad args. */
  12656. ExpectIntEQ(wc_Sha512FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12657. ExpectIntEQ(wc_Sha512FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12658. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12659. wc_Sha512Free(&sha512);
  12660. #endif
  12661. return EXPECT_RESULT();
  12662. } /* END test_wc_Sha512FinalRaw */
  12663. /*
  12664. * Unit test function for wc_Sha512Free()
  12665. */
  12666. static int test_wc_Sha512Free(void)
  12667. {
  12668. EXPECT_DECLS;
  12669. #ifdef WOLFSSL_SHA512
  12670. wc_Sha512Free(NULL);
  12671. /* Set result to SUCCESS. */
  12672. ExpectTrue(1);
  12673. #endif
  12674. return EXPECT_RESULT();
  12675. } /* END test_wc_Sha512Free */
  12676. #ifdef WOLFSSL_SHA512
  12677. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12678. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  12679. static int test_Sha512_Family_GetHash(int type )
  12680. {
  12681. EXPECT_DECLS;
  12682. int(*initFp)(wc_Sha512*);
  12683. int(*ghashFp)(wc_Sha512*, byte*);
  12684. wc_Sha512 sha512;
  12685. byte hash1[WC_SHA512_DIGEST_SIZE];
  12686. if (type == WC_HASH_TYPE_SHA512) {
  12687. initFp = wc_InitSha512;
  12688. ghashFp = wc_Sha512GetHash;
  12689. }
  12690. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12691. #if !defined(WOLFSSL_NOSHA512_224)
  12692. else if (type == WC_HASH_TYPE_SHA512_224) {
  12693. initFp = wc_InitSha512_224;
  12694. ghashFp = wc_Sha512_224GetHash;
  12695. }
  12696. #endif
  12697. #if !defined(WOLFSSL_NOSHA512_256)
  12698. else if (type == WC_HASH_TYPE_SHA512_256) {
  12699. initFp = wc_InitSha512_256;
  12700. ghashFp = wc_Sha512_256GetHash;
  12701. }
  12702. #endif
  12703. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12704. else {
  12705. initFp = NULL;
  12706. ghashFp = NULL;
  12707. }
  12708. if (initFp == NULL || ghashFp == NULL)
  12709. return TEST_FAIL;
  12710. ExpectIntEQ(initFp(&sha512), 0);
  12711. ExpectIntEQ(ghashFp(&sha512, hash1), 0);
  12712. /* test bad arguments*/
  12713. ExpectIntEQ(ghashFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12714. ExpectIntEQ(ghashFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12715. ExpectIntEQ(ghashFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12716. wc_Sha512Free(&sha512);
  12717. return EXPECT_RESULT();
  12718. }
  12719. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  12720. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  12721. #endif /* WOLFSSL_SHA512 */
  12722. /*
  12723. * Unit test function for wc_Sha512GetHash()
  12724. */
  12725. static int test_wc_Sha512GetHash(void)
  12726. {
  12727. EXPECT_DECLS;
  12728. #ifdef WOLFSSL_SHA512
  12729. wc_Sha512 sha512;
  12730. byte hash1[WC_SHA512_DIGEST_SIZE];
  12731. /* Initialize */
  12732. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12733. ExpectIntEQ(wc_Sha512GetHash(&sha512, hash1), 0);
  12734. /* test bad arguments*/
  12735. ExpectIntEQ(wc_Sha512GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12736. ExpectIntEQ(wc_Sha512GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12737. ExpectIntEQ(wc_Sha512GetHash(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12738. wc_Sha512Free(&sha512);
  12739. #endif
  12740. return EXPECT_RESULT();
  12741. } /* END test_wc_Sha512GetHash */
  12742. /*
  12743. * Unit test function for wc_Sha512Copy()
  12744. */
  12745. static int test_wc_Sha512Copy(void)
  12746. {
  12747. EXPECT_DECLS;
  12748. #ifdef WOLFSSL_SHA512
  12749. wc_Sha512 sha512;
  12750. wc_Sha512 temp;
  12751. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  12752. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  12753. /* Initialize */
  12754. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12755. ExpectIntEQ(wc_InitSha512(&temp), 0);
  12756. ExpectIntEQ(wc_Sha512Copy(&sha512, &temp), 0);
  12757. /* test bad arguments*/
  12758. ExpectIntEQ(wc_Sha512Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12759. ExpectIntEQ(wc_Sha512Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12760. ExpectIntEQ(wc_Sha512Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12761. wc_Sha512Free(&sha512);
  12762. wc_Sha512Free(&temp);
  12763. #endif
  12764. return EXPECT_RESULT();
  12765. } /* END test_wc_Sha512Copy */
  12766. static int test_wc_InitSha512_224(void)
  12767. {
  12768. EXPECT_DECLS;
  12769. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12770. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  12771. wc_Sha512 sha512;
  12772. /* Test good arg. */
  12773. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  12774. /* Test bad arg. */
  12775. ExpectIntEQ(wc_InitSha512_224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12776. wc_Sha512_224Free(&sha512);
  12777. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  12778. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12779. return EXPECT_RESULT();
  12780. }
  12781. static int test_wc_Sha512_224Update(void)
  12782. {
  12783. EXPECT_DECLS;
  12784. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12785. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  12786. wc_Sha512 sha512;
  12787. byte hash[WC_SHA512_DIGEST_SIZE];
  12788. testVector a, c;
  12789. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  12790. /* Input. */
  12791. a.input = "a";
  12792. a.inLen = XSTRLEN(a.input);
  12793. ExpectIntEQ(wc_Sha512_224Update(&sha512, NULL, 0), 0);
  12794. ExpectIntEQ(wc_Sha512_224Update(&sha512,(byte*)a.input, 0), 0);
  12795. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)a.input, (word32)a.inLen),
  12796. 0);
  12797. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  12798. /* Update input. */
  12799. a.input = "abc";
  12800. a.output = "\x46\x34\x27\x0f\x70\x7b\x6a\x54\xda\xae\x75\x30\x46\x08"
  12801. "\x42\xe2\x0e\x37\xed\x26\x5c\xee\xe9\xa4\x3e\x89\x24\xaa";
  12802. a.inLen = XSTRLEN(a.input);
  12803. a.outLen = XSTRLEN(a.output);
  12804. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*) a.input, (word32) a.inLen),
  12805. 0);
  12806. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  12807. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_224_DIGEST_SIZE), 0);
  12808. c.input = NULL;
  12809. c.inLen = WC_SHA512_224_DIGEST_SIZE;
  12810. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)c.input, (word32)c.inLen),
  12811. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12812. ExpectIntEQ(wc_Sha512_224Update(NULL, (byte*)a.input, (word32)a.inLen),
  12813. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12814. wc_Sha512_224Free(&sha512);
  12815. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  12816. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12817. return EXPECT_RESULT();
  12818. }
  12819. static int test_wc_Sha512_224Final(void)
  12820. {
  12821. EXPECT_DECLS;
  12822. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12823. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  12824. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 0),
  12825. TEST_SUCCESS);
  12826. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  12827. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12828. return EXPECT_RESULT();
  12829. }
  12830. static int test_wc_Sha512_224GetFlags(void)
  12831. {
  12832. EXPECT_DECLS;
  12833. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12834. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && defined(WOLFSSL_HASH_FLAGS)
  12835. wc_Sha512 sha512;
  12836. wc_Sha512 copy;
  12837. word32 flags = 0;
  12838. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  12839. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  12840. /* Initialize */
  12841. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  12842. ExpectIntEQ(wc_InitSha512_224(&copy), 0);
  12843. ExpectIntEQ(wc_Sha512_224GetFlags(&sha512, &flags), 0);
  12844. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12845. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &copy), 0);
  12846. ExpectIntEQ(wc_Sha512_224GetFlags(&copy, &flags), 0);
  12847. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  12848. wc_Sha512_224Free(&copy);
  12849. wc_Sha512_224Free(&sha512);
  12850. #endif
  12851. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12852. return EXPECT_RESULT();
  12853. }
  12854. static int test_wc_Sha512_224FinalRaw(void)
  12855. {
  12856. EXPECT_DECLS;
  12857. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12858. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \
  12859. !defined(WOLFSSL_NO_HASH_RAW)
  12860. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 1),
  12861. TEST_SUCCESS);
  12862. #endif
  12863. return EXPECT_RESULT();
  12864. }
  12865. static int test_wc_Sha512_224Free(void)
  12866. {
  12867. EXPECT_DECLS;
  12868. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12869. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  12870. wc_Sha512_224Free(NULL);
  12871. /* Set result to SUCCESS. */
  12872. ExpectTrue(1);
  12873. #endif
  12874. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12875. return EXPECT_RESULT();
  12876. }
  12877. static int test_wc_Sha512_224GetHash(void)
  12878. {
  12879. EXPECT_DECLS;
  12880. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12881. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  12882. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_224),
  12883. TEST_SUCCESS);
  12884. #endif
  12885. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12886. return EXPECT_RESULT();
  12887. }
  12888. static int test_wc_Sha512_224Copy(void)
  12889. {
  12890. EXPECT_DECLS;
  12891. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12892. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  12893. wc_Sha512 sha512;
  12894. wc_Sha512 temp;
  12895. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  12896. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  12897. /* Initialize */
  12898. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  12899. ExpectIntEQ(wc_InitSha512_224(&temp), 0);
  12900. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &temp), 0);
  12901. /* test bad arguments*/
  12902. ExpectIntEQ(wc_Sha512_224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12903. ExpectIntEQ(wc_Sha512_224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12904. ExpectIntEQ(wc_Sha512_224Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12905. wc_Sha512_224Free(&sha512);
  12906. wc_Sha512_224Free(&temp);
  12907. #endif
  12908. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12909. return EXPECT_RESULT();
  12910. }
  12911. static int test_wc_InitSha512_256(void)
  12912. {
  12913. EXPECT_DECLS;
  12914. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12915. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  12916. wc_Sha512 sha512;
  12917. /* Test good arg. */
  12918. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  12919. /* Test bad arg. */
  12920. ExpectIntEQ(wc_InitSha512_256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12921. wc_Sha512_256Free(&sha512);
  12922. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  12923. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12924. return EXPECT_RESULT();
  12925. }
  12926. static int test_wc_Sha512_256Update(void)
  12927. {
  12928. EXPECT_DECLS;
  12929. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12930. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  12931. wc_Sha512 sha512;
  12932. byte hash[WC_SHA512_DIGEST_SIZE];
  12933. testVector a, c;
  12934. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  12935. /* Input. */
  12936. a.input = "a";
  12937. a.inLen = XSTRLEN(a.input);
  12938. ExpectIntEQ(wc_Sha512_256Update(&sha512, NULL, 0), 0);
  12939. ExpectIntEQ(wc_Sha512_256Update(&sha512,(byte*)a.input, 0), 0);
  12940. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)a.input, (word32)a.inLen),
  12941. 0);
  12942. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  12943. /* Update input. */
  12944. a.input = "abc";
  12945. a.output = "\x53\x04\x8e\x26\x81\x94\x1e\xf9\x9b\x2e\x29\xb7\x6b\x4c"
  12946. "\x7d\xab\xe4\xc2\xd0\xc6\x34\xfc\x6d\x46\xe0\xe2\xf1\x31"
  12947. "\x07\xe7\xaf\x23";
  12948. a.inLen = XSTRLEN(a.input);
  12949. a.outLen = XSTRLEN(a.output);
  12950. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*) a.input, (word32) a.inLen),
  12951. 0);
  12952. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  12953. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_256_DIGEST_SIZE), 0);
  12954. c.input = NULL;
  12955. c.inLen = WC_SHA512_256_DIGEST_SIZE;
  12956. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)c.input, (word32)c.inLen),
  12957. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12958. ExpectIntEQ(wc_Sha512_256Update(NULL, (byte*)a.input, (word32)a.inLen),
  12959. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12960. wc_Sha512_256Free(&sha512);
  12961. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  12962. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12963. return EXPECT_RESULT();
  12964. }
  12965. static int test_wc_Sha512_256Final(void)
  12966. {
  12967. EXPECT_DECLS;
  12968. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12969. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  12970. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 0),
  12971. TEST_SUCCESS);
  12972. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  12973. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12974. return EXPECT_RESULT();
  12975. }
  12976. static int test_wc_Sha512_256GetFlags(void)
  12977. {
  12978. EXPECT_DECLS;
  12979. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12980. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && defined(WOLFSSL_HASH_FLAGS)
  12981. wc_Sha512 sha512, copy;
  12982. word32 flags = 0;
  12983. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  12984. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  12985. /* Initialize */
  12986. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  12987. ExpectIntEQ(wc_InitSha512_256(&copy), 0);
  12988. ExpectIntEQ(wc_Sha512_256GetFlags(&sha512, &flags), 0);
  12989. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12990. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &copy), 0);
  12991. ExpectIntEQ(wc_Sha512_256GetFlags(&copy, &flags), 0);
  12992. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  12993. wc_Sha512_256Free(&sha512);
  12994. #endif
  12995. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12996. return EXPECT_RESULT();
  12997. }
  12998. static int test_wc_Sha512_256FinalRaw(void)
  12999. {
  13000. EXPECT_DECLS;
  13001. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13002. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \
  13003. !defined(WOLFSSL_NO_HASH_RAW)
  13004. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 1),
  13005. TEST_SUCCESS);
  13006. #endif
  13007. return EXPECT_RESULT();
  13008. }
  13009. static int test_wc_Sha512_256Free(void)
  13010. {
  13011. EXPECT_DECLS;
  13012. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13013. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13014. wc_Sha512_256Free(NULL);
  13015. /* Set result to SUCCESS. */
  13016. ExpectTrue(1);
  13017. #endif
  13018. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13019. return EXPECT_RESULT();
  13020. }
  13021. static int test_wc_Sha512_256GetHash(void)
  13022. {
  13023. EXPECT_DECLS;
  13024. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13025. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13026. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_256),
  13027. TEST_SUCCESS);
  13028. #endif
  13029. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13030. return EXPECT_RESULT();
  13031. }
  13032. static int test_wc_Sha512_256Copy(void)
  13033. {
  13034. EXPECT_DECLS;
  13035. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13036. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13037. wc_Sha512 sha512;
  13038. wc_Sha512 temp;
  13039. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13040. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13041. /* Initialize */
  13042. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13043. ExpectIntEQ(wc_InitSha512_256(&temp), 0);
  13044. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &temp), 0);
  13045. /* test bad arguments*/
  13046. ExpectIntEQ(wc_Sha512_256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13047. ExpectIntEQ(wc_Sha512_256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13048. ExpectIntEQ(wc_Sha512_256Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13049. wc_Sha512_256Free(&sha512);
  13050. wc_Sha512_256Free(&temp);
  13051. #endif
  13052. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13053. return EXPECT_RESULT();
  13054. }
  13055. /*
  13056. * Testing wc_InitSha384()
  13057. */
  13058. static int test_wc_InitSha384(void)
  13059. {
  13060. EXPECT_DECLS;
  13061. #ifdef WOLFSSL_SHA384
  13062. wc_Sha384 sha384;
  13063. /* Test good arg. */
  13064. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13065. /* Test bad arg. */
  13066. ExpectIntEQ(wc_InitSha384(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13067. wc_Sha384Free(&sha384);
  13068. #endif
  13069. return EXPECT_RESULT();
  13070. } /* END test_wc_InitSha384 */
  13071. /*
  13072. * test wc_Sha384Update()
  13073. */
  13074. static int test_wc_Sha384Update(void)
  13075. {
  13076. EXPECT_DECLS;
  13077. #ifdef WOLFSSL_SHA384
  13078. wc_Sha384 sha384;
  13079. byte hash[WC_SHA384_DIGEST_SIZE];
  13080. testVector a, b, c;
  13081. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13082. /* Input */
  13083. a.input = "a";
  13084. a.inLen = XSTRLEN(a.input);
  13085. ExpectIntEQ(wc_Sha384Update(&sha384, NULL, 0), 0);
  13086. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, 0), 0);
  13087. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13088. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13089. /* Update input. */
  13090. a.input = "abc";
  13091. a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  13092. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  13093. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  13094. "\xc8\x25\xa7";
  13095. a.inLen = XSTRLEN(a.input);
  13096. a.outLen = XSTRLEN(a.output);
  13097. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13098. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13099. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  13100. /* Pass in bad values. */
  13101. b.input = NULL;
  13102. b.inLen = 0;
  13103. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)b.input, (word32)b.inLen), 0);
  13104. c.input = NULL;
  13105. c.inLen = WC_SHA384_DIGEST_SIZE;
  13106. ExpectIntEQ( wc_Sha384Update(&sha384, (byte*)c.input, (word32)c.inLen),
  13107. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13108. ExpectIntEQ(wc_Sha384Update(NULL, (byte*)a.input, (word32)a.inLen),
  13109. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13110. wc_Sha384Free(&sha384);
  13111. #endif
  13112. return EXPECT_RESULT();
  13113. } /* END test_wc_Sha384Update */
  13114. /*
  13115. * Unit test function for wc_Sha384Final();
  13116. */
  13117. static int test_wc_Sha384Final(void)
  13118. {
  13119. EXPECT_DECLS;
  13120. #ifdef WOLFSSL_SHA384
  13121. wc_Sha384 sha384;
  13122. byte* hash_test[3];
  13123. byte hash1[WC_SHA384_DIGEST_SIZE];
  13124. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13125. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13126. int times, i;
  13127. /* Initialize */
  13128. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13129. hash_test[0] = hash1;
  13130. hash_test[1] = hash2;
  13131. hash_test[2] = hash3;
  13132. times = sizeof(hash_test) / sizeof(byte*);
  13133. /* Good test args. */
  13134. for (i = 0; i < times; i++) {
  13135. ExpectIntEQ(wc_Sha384Final(&sha384, hash_test[i]), 0);
  13136. }
  13137. /* Test bad args. */
  13138. ExpectIntEQ(wc_Sha384Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13139. ExpectIntEQ(wc_Sha384Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13140. ExpectIntEQ(wc_Sha384Final(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13141. wc_Sha384Free(&sha384);
  13142. #endif
  13143. return EXPECT_RESULT();
  13144. } /* END test_wc_Sha384Final */
  13145. /*
  13146. * Unit test function for wc_Sha384GetFlags()
  13147. */
  13148. static int test_wc_Sha384GetFlags(void)
  13149. {
  13150. EXPECT_DECLS;
  13151. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_HASH_FLAGS)
  13152. wc_Sha384 sha384;
  13153. word32 flags = 0;
  13154. /* Initialize */
  13155. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13156. ExpectIntEQ(wc_Sha384GetFlags(&sha384, &flags), 0);
  13157. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13158. wc_Sha384Free(&sha384);
  13159. #endif
  13160. return EXPECT_RESULT();
  13161. } /* END test_wc_Sha384GetFlags */
  13162. /*
  13163. * Unit test function for wc_Sha384FinalRaw()
  13164. */
  13165. static int test_wc_Sha384FinalRaw(void)
  13166. {
  13167. EXPECT_DECLS;
  13168. #if (defined(WOLFSSL_SHA384) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13169. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13170. !defined(WOLFSSL_NO_HASH_RAW)
  13171. wc_Sha384 sha384;
  13172. byte* hash_test[3];
  13173. byte hash1[WC_SHA384_DIGEST_SIZE];
  13174. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13175. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13176. int times, i;
  13177. /* Initialize */
  13178. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13179. hash_test[0] = hash1;
  13180. hash_test[1] = hash2;
  13181. hash_test[2] = hash3;
  13182. times = sizeof(hash_test) / sizeof(byte*);
  13183. /* Good test args. */
  13184. for (i = 0; i < times; i++) {
  13185. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, hash_test[i]), 0);
  13186. }
  13187. /* Test bad args. */
  13188. ExpectIntEQ(wc_Sha384FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13189. ExpectIntEQ(wc_Sha384FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13190. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13191. wc_Sha384Free(&sha384);
  13192. #endif
  13193. return EXPECT_RESULT();
  13194. } /* END test_wc_Sha384FinalRaw */
  13195. /*
  13196. * Unit test function for wc_Sha384Free()
  13197. */
  13198. static int test_wc_Sha384Free(void)
  13199. {
  13200. EXPECT_DECLS;
  13201. #ifdef WOLFSSL_SHA384
  13202. wc_Sha384Free(NULL);
  13203. /* Set result to SUCCESS. */
  13204. ExpectTrue(1);
  13205. #endif
  13206. return EXPECT_RESULT();
  13207. } /* END test_wc_Sha384Free */
  13208. /*
  13209. * Unit test function for wc_Sha384GetHash()
  13210. */
  13211. static int test_wc_Sha384GetHash(void)
  13212. {
  13213. EXPECT_DECLS;
  13214. #ifdef WOLFSSL_SHA384
  13215. wc_Sha384 sha384;
  13216. byte hash1[WC_SHA384_DIGEST_SIZE];
  13217. /* Initialize */
  13218. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13219. ExpectIntEQ(wc_Sha384GetHash(&sha384, hash1), 0);
  13220. /* test bad arguments*/
  13221. ExpectIntEQ(wc_Sha384GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13222. ExpectIntEQ(wc_Sha384GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13223. ExpectIntEQ(wc_Sha384GetHash(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13224. wc_Sha384Free(&sha384);
  13225. #endif
  13226. return EXPECT_RESULT();
  13227. } /* END test_wc_Sha384GetHash */
  13228. /*
  13229. * Unit test function for wc_Sha384Copy()
  13230. */
  13231. static int test_wc_Sha384Copy(void)
  13232. {
  13233. EXPECT_DECLS;
  13234. #ifdef WOLFSSL_SHA384
  13235. wc_Sha384 sha384;
  13236. wc_Sha384 temp;
  13237. XMEMSET(&sha384, 0, sizeof(wc_Sha384));
  13238. XMEMSET(&temp, 0, sizeof(wc_Sha384));
  13239. /* Initialize */
  13240. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13241. ExpectIntEQ(wc_InitSha384(&temp), 0);
  13242. ExpectIntEQ(wc_Sha384Copy(&sha384, &temp), 0);
  13243. /* test bad arguments*/
  13244. ExpectIntEQ(wc_Sha384Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13245. ExpectIntEQ(wc_Sha384Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13246. ExpectIntEQ(wc_Sha384Copy(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13247. wc_Sha384Free(&sha384);
  13248. wc_Sha384Free(&temp);
  13249. #endif
  13250. return EXPECT_RESULT();
  13251. } /* END test_wc_Sha384Copy */
  13252. /*
  13253. * Testing wc_InitSha224();
  13254. */
  13255. static int test_wc_InitSha224(void)
  13256. {
  13257. EXPECT_DECLS;
  13258. #ifdef WOLFSSL_SHA224
  13259. wc_Sha224 sha224;
  13260. /* Test good arg. */
  13261. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13262. /* Test bad arg. */
  13263. ExpectIntEQ(wc_InitSha224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13264. wc_Sha224Free(&sha224);
  13265. #endif
  13266. return EXPECT_RESULT();
  13267. } /* END test_wc_InitSha224 */
  13268. /*
  13269. * Unit test on wc_Sha224Update
  13270. */
  13271. static int test_wc_Sha224Update(void)
  13272. {
  13273. EXPECT_DECLS;
  13274. #ifdef WOLFSSL_SHA224
  13275. wc_Sha224 sha224;
  13276. byte hash[WC_SHA224_DIGEST_SIZE];
  13277. testVector a, b, c;
  13278. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13279. /* Input. */
  13280. a.input = "a";
  13281. a.inLen = XSTRLEN(a.input);
  13282. ExpectIntEQ(wc_Sha224Update(&sha224, NULL, 0), 0);
  13283. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, 0), 0);
  13284. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13285. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13286. /* Update input. */
  13287. a.input = "abc";
  13288. a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2"
  13289. "\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  13290. a.inLen = XSTRLEN(a.input);
  13291. a.outLen = XSTRLEN(a.output);
  13292. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13293. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13294. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  13295. /* Pass in bad values. */
  13296. b.input = NULL;
  13297. b.inLen = 0;
  13298. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen), 0);
  13299. c.input = NULL;
  13300. c.inLen = WC_SHA224_DIGEST_SIZE;
  13301. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen),
  13302. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13303. ExpectIntEQ(wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13304. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13305. wc_Sha224Free(&sha224);
  13306. #endif
  13307. return EXPECT_RESULT();
  13308. } /* END test_wc_Sha224Update */
  13309. /*
  13310. * Unit test for wc_Sha224Final();
  13311. */
  13312. static int test_wc_Sha224Final(void)
  13313. {
  13314. EXPECT_DECLS;
  13315. #ifdef WOLFSSL_SHA224
  13316. wc_Sha224 sha224;
  13317. byte* hash_test[3];
  13318. byte hash1[WC_SHA224_DIGEST_SIZE];
  13319. byte hash2[2*WC_SHA224_DIGEST_SIZE];
  13320. byte hash3[5*WC_SHA224_DIGEST_SIZE];
  13321. int times, i;
  13322. /* Initialize */
  13323. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13324. hash_test[0] = hash1;
  13325. hash_test[1] = hash2;
  13326. hash_test[2] = hash3;
  13327. times = sizeof(hash_test) / sizeof(byte*);
  13328. /* Good test args. */
  13329. /* Testing oversized buffers. */
  13330. for (i = 0; i < times; i++) {
  13331. ExpectIntEQ(wc_Sha224Final(&sha224, hash_test[i]), 0);
  13332. }
  13333. /* Test bad args. */
  13334. ExpectIntEQ(wc_Sha224Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13335. ExpectIntEQ(wc_Sha224Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13336. ExpectIntEQ(wc_Sha224Final(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13337. wc_Sha224Free(&sha224);
  13338. #endif
  13339. return EXPECT_RESULT();
  13340. } /* END test_wc_Sha224Final */
  13341. /*
  13342. * Unit test function for wc_Sha224SetFlags()
  13343. */
  13344. static int test_wc_Sha224SetFlags(void)
  13345. {
  13346. EXPECT_DECLS;
  13347. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13348. wc_Sha224 sha224;
  13349. word32 flags = WC_HASH_FLAG_WILLCOPY;
  13350. /* Initialize */
  13351. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13352. ExpectIntEQ(wc_Sha224SetFlags(&sha224, flags), 0);
  13353. flags = 0;
  13354. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13355. ExpectTrue(flags == WC_HASH_FLAG_WILLCOPY);
  13356. wc_Sha224Free(&sha224);
  13357. #endif
  13358. return EXPECT_RESULT();
  13359. } /* END test_wc_Sha224SetFlags */
  13360. /*
  13361. * Unit test function for wc_Sha224GetFlags()
  13362. */
  13363. static int test_wc_Sha224GetFlags(void)
  13364. {
  13365. EXPECT_DECLS;
  13366. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13367. wc_Sha224 sha224;
  13368. word32 flags = 0;
  13369. /* Initialize */
  13370. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13371. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13372. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13373. wc_Sha224Free(&sha224);
  13374. #endif
  13375. return EXPECT_RESULT();
  13376. } /* END test_wc_Sha224GetFlags */
  13377. /*
  13378. * Unit test function for wc_Sha224Free()
  13379. */
  13380. static int test_wc_Sha224Free(void)
  13381. {
  13382. EXPECT_DECLS;
  13383. #ifdef WOLFSSL_SHA224
  13384. wc_Sha224Free(NULL);
  13385. /* Set result to SUCCESS. */
  13386. ExpectTrue(1);
  13387. #endif
  13388. return EXPECT_RESULT();
  13389. } /* END test_wc_Sha224Free */
  13390. /*
  13391. * Unit test function for wc_Sha224GetHash()
  13392. */
  13393. static int test_wc_Sha224GetHash(void)
  13394. {
  13395. EXPECT_DECLS;
  13396. #ifdef WOLFSSL_SHA224
  13397. wc_Sha224 sha224;
  13398. byte hash1[WC_SHA224_DIGEST_SIZE];
  13399. /* Initialize */
  13400. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13401. ExpectIntEQ(wc_Sha224GetHash(&sha224, hash1), 0);
  13402. /* test bad arguments*/
  13403. ExpectIntEQ(wc_Sha224GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13404. ExpectIntEQ(wc_Sha224GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13405. ExpectIntEQ(wc_Sha224GetHash(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13406. wc_Sha224Free(&sha224);
  13407. #endif
  13408. return EXPECT_RESULT();
  13409. } /* END test_wc_Sha224GetHash */
  13410. /*
  13411. * Unit test function for wc_Sha224Copy()
  13412. */
  13413. static int test_wc_Sha224Copy(void)
  13414. {
  13415. EXPECT_DECLS;
  13416. #ifdef WOLFSSL_SHA224
  13417. wc_Sha224 sha224;
  13418. wc_Sha224 temp;
  13419. XMEMSET(&sha224, 0, sizeof(wc_Sha224));
  13420. XMEMSET(&temp, 0, sizeof(wc_Sha224));
  13421. /* Initialize */
  13422. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13423. ExpectIntEQ(wc_InitSha224(&temp), 0);
  13424. ExpectIntEQ(wc_Sha224Copy(&sha224, &temp), 0);
  13425. /* test bad arguments*/
  13426. ExpectIntEQ(wc_Sha224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13427. ExpectIntEQ(wc_Sha224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13428. ExpectIntEQ(wc_Sha224Copy(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13429. wc_Sha224Free(&sha224);
  13430. wc_Sha224Free(&temp);
  13431. #endif
  13432. return EXPECT_RESULT();
  13433. } /* END test_wc_Sha224Copy */
  13434. /*
  13435. * Testing wc_InitRipeMd()
  13436. */
  13437. static int test_wc_InitRipeMd(void)
  13438. {
  13439. EXPECT_DECLS;
  13440. #ifdef WOLFSSL_RIPEMD
  13441. RipeMd ripemd;
  13442. /* Test good arg. */
  13443. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13444. /* Test bad arg. */
  13445. ExpectIntEQ(wc_InitRipeMd(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13446. #endif
  13447. return EXPECT_RESULT();
  13448. } /* END test_wc_InitRipeMd */
  13449. /*
  13450. * Testing wc_RipeMdUpdate()
  13451. */
  13452. static int test_wc_RipeMdUpdate(void)
  13453. {
  13454. EXPECT_DECLS;
  13455. #ifdef WOLFSSL_RIPEMD
  13456. RipeMd ripemd;
  13457. byte hash[RIPEMD_DIGEST_SIZE];
  13458. testVector a, b, c;
  13459. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13460. /* Input */
  13461. a.input = "a";
  13462. a.inLen = XSTRLEN(a.input);
  13463. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13464. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13465. /* Update input. */
  13466. a.input = "abc";
  13467. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  13468. "\xb0\x87\xf1\x5a\x0b\xfc";
  13469. a.inLen = XSTRLEN(a.input);
  13470. a.outLen = XSTRLEN(a.output);
  13471. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13472. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13473. ExpectIntEQ(XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE), 0);
  13474. /* Pass in bad values. */
  13475. b.input = NULL;
  13476. b.inLen = 0;
  13477. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen), 0);
  13478. c.input = NULL;
  13479. c.inLen = RIPEMD_DIGEST_SIZE;
  13480. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen),
  13481. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13482. ExpectIntEQ(wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  13483. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13484. #endif
  13485. return EXPECT_RESULT();
  13486. } /* END test_wc_RipeMdUdpate */
  13487. /*
  13488. * Unit test function for wc_RipeMdFinal()
  13489. */
  13490. static int test_wc_RipeMdFinal(void)
  13491. {
  13492. EXPECT_DECLS;
  13493. #ifdef WOLFSSL_RIPEMD
  13494. RipeMd ripemd;
  13495. byte* hash_test[3];
  13496. byte hash1[RIPEMD_DIGEST_SIZE];
  13497. byte hash2[2*RIPEMD_DIGEST_SIZE];
  13498. byte hash3[5*RIPEMD_DIGEST_SIZE];
  13499. int times, i;
  13500. /* Initialize */
  13501. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13502. hash_test[0] = hash1;
  13503. hash_test[1] = hash2;
  13504. hash_test[2] = hash3;
  13505. times = sizeof(hash_test) / sizeof(byte*);
  13506. /* Testing oversized buffers. */
  13507. for (i = 0; i < times; i++) {
  13508. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash_test[i]), 0);
  13509. }
  13510. /* Test bad args. */
  13511. ExpectIntEQ(wc_RipeMdFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13512. ExpectIntEQ(wc_RipeMdFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13513. ExpectIntEQ(wc_RipeMdFinal(&ripemd, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13514. #endif
  13515. return EXPECT_RESULT();
  13516. } /* END test_wc_RipeMdFinal */
  13517. /*
  13518. * Testing wc_InitSha3_224, wc_InitSha3_256, wc_InitSha3_384, and
  13519. * wc_InitSha3_512
  13520. */
  13521. static int test_wc_InitSha3(void)
  13522. {
  13523. EXPECT_DECLS;
  13524. #if defined(WOLFSSL_SHA3)
  13525. wc_Sha3 sha3;
  13526. (void)sha3;
  13527. #if !defined(WOLFSSL_NOSHA3_224)
  13528. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13529. /* Test bad args. */
  13530. ExpectIntEQ(wc_InitSha3_224(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13531. wc_Sha3_224_Free(&sha3);
  13532. #endif /* NOSHA3_224 */
  13533. #if !defined(WOLFSSL_NOSHA3_256)
  13534. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13535. /* Test bad args. */
  13536. ExpectIntEQ(wc_InitSha3_256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13537. wc_Sha3_256_Free(&sha3);
  13538. #endif /* NOSHA3_256 */
  13539. #if !defined(WOLFSSL_NOSHA3_384)
  13540. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13541. /* Test bad args. */
  13542. ExpectIntEQ(wc_InitSha3_384(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13543. wc_Sha3_384_Free(&sha3);
  13544. #endif /* NOSHA3_384 */
  13545. #if !defined(WOLFSSL_NOSHA3_512)
  13546. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13547. /* Test bad args. */
  13548. ExpectIntEQ(wc_InitSha3_512(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13549. wc_Sha3_512_Free(&sha3);
  13550. #endif /* NOSHA3_512 */
  13551. #endif
  13552. return EXPECT_RESULT();
  13553. } /* END test_wc_InitSha3 */
  13554. /*
  13555. * Testing wc_Sha3_Update()
  13556. */
  13557. static int testing_wc_Sha3_Update(void)
  13558. {
  13559. EXPECT_DECLS;
  13560. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_XILINX_CRYPT) && \
  13561. !defined(WOLFSSL_AFALG_XILINX)
  13562. wc_Sha3 sha3;
  13563. byte msg[] = "Everybody's working for the weekend.";
  13564. byte msg2[] = "Everybody gets Friday off.";
  13565. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  13566. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  13567. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  13568. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  13569. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  13570. word32 msglen = sizeof(msg) - 1;
  13571. word32 msg2len = sizeof(msg2);
  13572. word32 msgCmplen = sizeof(msgCmp);
  13573. #if !defined(WOLFSSL_NOSHA3_224)
  13574. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13575. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg, msglen), 0);
  13576. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13577. ExpectTrue(sha3.i == msglen);
  13578. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  13579. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13580. /* Pass bad args. */
  13581. ExpectIntEQ(wc_Sha3_224_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13582. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13583. wc_Sha3_224_Free(&sha3);
  13584. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13585. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 0), 0);
  13586. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  13587. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13588. wc_Sha3_224_Free(&sha3);
  13589. #endif /* SHA3_224 */
  13590. #if !defined(WOLFSSL_NOSHA3_256)
  13591. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13592. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg, msglen), 0);
  13593. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13594. ExpectTrue(sha3.i == msglen);
  13595. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  13596. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13597. /* Pass bad args. */
  13598. ExpectIntEQ(wc_Sha3_256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13599. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13600. wc_Sha3_256_Free(&sha3);
  13601. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13602. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 0), 0);
  13603. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  13604. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13605. wc_Sha3_256_Free(&sha3);
  13606. #endif /* SHA3_256 */
  13607. #if !defined(WOLFSSL_NOSHA3_384)
  13608. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13609. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg, msglen), 0);
  13610. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13611. ExpectTrue(sha3.i == msglen);
  13612. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  13613. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13614. /* Pass bad args. */
  13615. ExpectIntEQ(wc_Sha3_384_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13616. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13617. wc_Sha3_384_Free(&sha3);
  13618. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13619. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 0), 0);
  13620. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  13621. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13622. wc_Sha3_384_Free(&sha3);
  13623. #endif /* SHA3_384 */
  13624. #if !defined(WOLFSSL_NOSHA3_512)
  13625. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13626. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg, msglen), 0);
  13627. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13628. ExpectTrue(sha3.i == msglen);
  13629. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  13630. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13631. /* Pass bad args. */
  13632. ExpectIntEQ(wc_Sha3_512_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13633. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13634. wc_Sha3_512_Free(&sha3);
  13635. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13636. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 0), 0);
  13637. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  13638. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13639. wc_Sha3_512_Free(&sha3);
  13640. #endif /* SHA3_512 */
  13641. #endif /* WOLFSSL_SHA3 */
  13642. return EXPECT_RESULT();
  13643. } /* END testing_wc_Sha3_Update */
  13644. /*
  13645. * Testing wc_Sha3_224_Final()
  13646. */
  13647. static int test_wc_Sha3_224_Final(void)
  13648. {
  13649. EXPECT_DECLS;
  13650. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  13651. wc_Sha3 sha3;
  13652. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13653. "nopnopq";
  13654. const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55"
  13655. "\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2"
  13656. "\x64\xea\xd0\xfc\xce\x33";
  13657. byte hash[WC_SHA3_224_DIGEST_SIZE];
  13658. byte hashRet[WC_SHA3_224_DIGEST_SIZE];
  13659. /* Init stack variables. */
  13660. XMEMSET(hash, 0, sizeof(hash));
  13661. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13662. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13663. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  13664. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE), 0);
  13665. /* Test bad args. */
  13666. ExpectIntEQ(wc_Sha3_224_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13667. ExpectIntEQ(wc_Sha3_224_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13668. wc_Sha3_224_Free(&sha3);
  13669. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13670. /* Init stack variables. */
  13671. XMEMSET(hash, 0, sizeof(hash));
  13672. XMEMSET(hashRet, 0, sizeof(hashRet));
  13673. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13674. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, hashRet), 0);
  13675. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  13676. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE), 0);
  13677. /* Test bad args. */
  13678. ExpectIntEQ(wc_Sha3_224_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13679. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13680. wc_Sha3_224_Free(&sha3);
  13681. #endif
  13682. return EXPECT_RESULT();
  13683. } /* END test_wc_Sha3_224_Final */
  13684. /*
  13685. * Testing wc_Sha3_256_Final()
  13686. */
  13687. static int test_wc_Sha3_256_Final(void)
  13688. {
  13689. EXPECT_DECLS;
  13690. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  13691. wc_Sha3 sha3;
  13692. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13693. "nopnopq";
  13694. const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8"
  13695. "\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32"
  13696. "\xdd\x97\x49\x6d\x33\x76";
  13697. byte hash[WC_SHA3_256_DIGEST_SIZE];
  13698. byte hashRet[WC_SHA3_256_DIGEST_SIZE];
  13699. /* Init stack variables. */
  13700. XMEMSET(hash, 0, sizeof(hash));
  13701. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13702. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13703. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  13704. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE), 0);
  13705. /* Test bad args. */
  13706. ExpectIntEQ(wc_Sha3_256_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13707. ExpectIntEQ(wc_Sha3_256_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13708. wc_Sha3_256_Free(&sha3);
  13709. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13710. /* Init stack variables. */
  13711. XMEMSET(hash, 0, sizeof(hash));
  13712. XMEMSET(hashRet, 0, sizeof(hashRet));
  13713. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13714. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, hashRet), 0);
  13715. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  13716. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE), 0);
  13717. /* Test bad args. */
  13718. ExpectIntEQ(wc_Sha3_256_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13719. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13720. wc_Sha3_256_Free(&sha3);
  13721. #endif
  13722. return EXPECT_RESULT();
  13723. } /* END test_wc_Sha3_256_Final */
  13724. /*
  13725. * Testing wc_Sha3_384_Final()
  13726. */
  13727. static int test_wc_Sha3_384_Final(void)
  13728. {
  13729. EXPECT_DECLS;
  13730. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  13731. wc_Sha3 sha3;
  13732. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13733. "nopnopq";
  13734. const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7"
  13735. "\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd"
  13736. "\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe"
  13737. "\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22";
  13738. byte hash[WC_SHA3_384_DIGEST_SIZE];
  13739. byte hashRet[WC_SHA3_384_DIGEST_SIZE];
  13740. /* Init stack variables. */
  13741. XMEMSET(hash, 0, sizeof(hash));
  13742. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13743. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13744. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  13745. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE), 0);
  13746. /* Test bad args. */
  13747. ExpectIntEQ(wc_Sha3_384_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13748. ExpectIntEQ(wc_Sha3_384_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13749. wc_Sha3_384_Free(&sha3);
  13750. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13751. /* Init stack variables. */
  13752. XMEMSET(hash, 0, sizeof(hash));
  13753. XMEMSET(hashRet, 0, sizeof(hashRet));
  13754. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13755. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, hashRet), 0);
  13756. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  13757. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE), 0);
  13758. /* Test bad args. */
  13759. ExpectIntEQ(wc_Sha3_384_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13760. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13761. wc_Sha3_384_Free(&sha3);
  13762. #endif
  13763. return EXPECT_RESULT();
  13764. } /* END test_wc_Sha3_384_Final */
  13765. /*
  13766. * Testing wc_Sha3_512_Final()
  13767. */
  13768. static int test_wc_Sha3_512_Final(void)
  13769. {
  13770. EXPECT_DECLS;
  13771. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) && \
  13772. !defined(WOLFSSL_NOSHA3_384)
  13773. wc_Sha3 sha3;
  13774. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13775. "nopnopq";
  13776. const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10"
  13777. "\xfc\xa8\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7"
  13778. "\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53"
  13779. "\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4"
  13780. "\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e";
  13781. byte hash[WC_SHA3_512_DIGEST_SIZE];
  13782. byte hashRet[WC_SHA3_512_DIGEST_SIZE];
  13783. /* Init stack variables. */
  13784. XMEMSET(hash, 0, sizeof(hash));
  13785. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13786. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13787. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  13788. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE), 0);
  13789. /* Test bad args. */
  13790. ExpectIntEQ(wc_Sha3_512_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13791. ExpectIntEQ(wc_Sha3_512_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13792. wc_Sha3_512_Free(&sha3);
  13793. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13794. /* Init stack variables. */
  13795. XMEMSET(hash, 0, sizeof(hash));
  13796. XMEMSET(hashRet, 0, sizeof(hashRet));
  13797. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13798. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, hashRet), 0);
  13799. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  13800. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE), 0);
  13801. /* Test bad args. */
  13802. ExpectIntEQ(wc_Sha3_512_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13803. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13804. wc_Sha3_512_Free(&sha3);
  13805. #endif
  13806. return EXPECT_RESULT();
  13807. } /* END test_wc_Sha3_512_Final */
  13808. /*
  13809. * Testing wc_Sha3_224_Copy()
  13810. */
  13811. static int test_wc_Sha3_224_Copy(void)
  13812. {
  13813. EXPECT_DECLS;
  13814. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  13815. wc_Sha3 sha3, sha3Cpy;
  13816. const char* msg = TEST_STRING;
  13817. word32 msglen = (word32)TEST_STRING_SZ;
  13818. byte hash[WC_SHA3_224_DIGEST_SIZE];
  13819. byte hashCpy[WC_SHA3_224_DIGEST_SIZE];
  13820. XMEMSET(hash, 0, sizeof(hash));
  13821. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  13822. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  13823. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  13824. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13825. ExpectIntEQ(wc_InitSha3_224(&sha3Cpy, HEAP_HINT, testDevId), 0);
  13826. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, msglen), 0);
  13827. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, &sha3), 0);
  13828. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  13829. ExpectIntEQ(wc_Sha3_224_Final(&sha3Cpy, hashCpy), 0);
  13830. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  13831. /* Test bad args. */
  13832. ExpectIntEQ(wc_Sha3_224_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13833. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13834. wc_Sha3_224_Free(&sha3);
  13835. wc_Sha3_224_Free(&sha3Cpy);
  13836. #endif
  13837. return EXPECT_RESULT();
  13838. } /* END test_wc_Sha3_224_Copy */
  13839. /*
  13840. * Testing wc_Sha3_256_Copy()
  13841. */
  13842. static int test_wc_Sha3_256_Copy(void)
  13843. {
  13844. EXPECT_DECLS;
  13845. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  13846. wc_Sha3 sha3, sha3Cpy;
  13847. const char* msg = TEST_STRING;
  13848. word32 msglen = (word32)TEST_STRING_SZ;
  13849. byte hash[WC_SHA3_256_DIGEST_SIZE];
  13850. byte hashCpy[WC_SHA3_256_DIGEST_SIZE];
  13851. XMEMSET(hash, 0, sizeof(hash));
  13852. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  13853. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  13854. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  13855. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13856. ExpectIntEQ(wc_InitSha3_256(&sha3Cpy, HEAP_HINT, testDevId), 0);
  13857. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, msglen), 0);
  13858. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, &sha3), 0);
  13859. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  13860. ExpectIntEQ(wc_Sha3_256_Final(&sha3Cpy, hashCpy), 0);
  13861. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  13862. /* Test bad args. */
  13863. ExpectIntEQ(wc_Sha3_256_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13864. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13865. wc_Sha3_256_Free(&sha3);
  13866. wc_Sha3_256_Free(&sha3Cpy);
  13867. #endif
  13868. return EXPECT_RESULT();
  13869. } /* END test_wc_Sha3_256_Copy */
  13870. /*
  13871. * Testing wc_Sha3_384_Copy()
  13872. */
  13873. static int test_wc_Sha3_384_Copy(void)
  13874. {
  13875. EXPECT_DECLS;
  13876. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  13877. wc_Sha3 sha3, sha3Cpy;
  13878. const char* msg = TEST_STRING;
  13879. word32 msglen = (word32)TEST_STRING_SZ;
  13880. byte hash[WC_SHA3_384_DIGEST_SIZE];
  13881. byte hashCpy[WC_SHA3_384_DIGEST_SIZE];
  13882. XMEMSET(hash, 0, sizeof(hash));
  13883. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  13884. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  13885. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  13886. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13887. ExpectIntEQ(wc_InitSha3_384(&sha3Cpy, HEAP_HINT, testDevId), 0);
  13888. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, msglen), 0);
  13889. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, &sha3), 0);
  13890. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  13891. ExpectIntEQ(wc_Sha3_384_Final(&sha3Cpy, hashCpy), 0);
  13892. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  13893. /* Test bad args. */
  13894. ExpectIntEQ(wc_Sha3_384_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13895. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13896. wc_Sha3_384_Free(&sha3);
  13897. wc_Sha3_384_Free(&sha3Cpy);
  13898. #endif
  13899. return EXPECT_RESULT();
  13900. } /* END test_wc_Sha3_384_Copy */
  13901. /*
  13902. * Testing wc_Sha3_512_Copy()
  13903. */
  13904. static int test_wc_Sha3_512_Copy(void)
  13905. {
  13906. EXPECT_DECLS;
  13907. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
  13908. wc_Sha3 sha3, sha3Cpy;
  13909. const char* msg = TEST_STRING;
  13910. word32 msglen = (word32)TEST_STRING_SZ;
  13911. byte hash[WC_SHA3_512_DIGEST_SIZE];
  13912. byte hashCpy[WC_SHA3_512_DIGEST_SIZE];
  13913. XMEMSET(hash, 0, sizeof(hash));
  13914. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  13915. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  13916. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  13917. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13918. ExpectIntEQ(wc_InitSha3_512(&sha3Cpy, HEAP_HINT, testDevId), 0);
  13919. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, msglen), 0);
  13920. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, &sha3), 0);
  13921. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  13922. ExpectIntEQ(wc_Sha3_512_Final(&sha3Cpy, hashCpy), 0);
  13923. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  13924. /* Test bad args. */
  13925. ExpectIntEQ(wc_Sha3_512_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13926. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13927. wc_Sha3_512_Free(&sha3);
  13928. wc_Sha3_512_Free(&sha3Cpy);
  13929. #endif
  13930. return EXPECT_RESULT();
  13931. } /* END test_wc_Sha3_512_Copy */
  13932. /*
  13933. * Unit test function for wc_Sha3_GetFlags()
  13934. */
  13935. static int test_wc_Sha3_GetFlags(void)
  13936. {
  13937. EXPECT_DECLS;
  13938. #if defined(WOLFSSL_SHA3) && defined(WOLFSSL_HASH_FLAGS)
  13939. wc_Sha3 sha3;
  13940. word32 flags = 0;
  13941. /* Initialize */
  13942. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13943. ExpectIntEQ(wc_Sha3_GetFlags(&sha3, &flags), 0);
  13944. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13945. wc_Sha3_224_Free(&sha3);
  13946. #endif
  13947. return EXPECT_RESULT();
  13948. } /* END test_wc_Sha3_GetFlags */
  13949. static int test_wc_InitShake256(void)
  13950. {
  13951. EXPECT_DECLS;
  13952. #ifdef WOLFSSL_SHAKE256
  13953. wc_Shake shake;
  13954. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  13955. /* Test bad args. */
  13956. ExpectIntEQ(wc_InitShake256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13957. wc_Shake256_Free(&shake);
  13958. #endif
  13959. return EXPECT_RESULT();
  13960. }
  13961. static int testing_wc_Shake256_Update(void)
  13962. {
  13963. EXPECT_DECLS;
  13964. #ifdef WOLFSSL_SHAKE256
  13965. wc_Shake shake;
  13966. byte msg[] = "Everybody's working for the weekend.";
  13967. byte msg2[] = "Everybody gets Friday off.";
  13968. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  13969. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  13970. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  13971. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  13972. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  13973. word32 msglen = sizeof(msg) - 1;
  13974. word32 msg2len = sizeof(msg2);
  13975. word32 msgCmplen = sizeof(msgCmp);
  13976. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  13977. ExpectIntEQ(wc_Shake256_Update(&shake, msg, msglen), 0);
  13978. ExpectIntEQ(XMEMCMP(msg, shake.t, msglen), 0);
  13979. ExpectTrue(shake.i == msglen);
  13980. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  13981. ExpectIntEQ(XMEMCMP(shake.t, msgCmp, msgCmplen), 0);
  13982. /* Pass bad args. */
  13983. ExpectIntEQ(wc_Shake256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13984. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13985. wc_Shake256_Free(&shake);
  13986. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  13987. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 0), 0);
  13988. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  13989. ExpectIntEQ(XMEMCMP(msg2, shake.t, msg2len), 0);
  13990. wc_Shake256_Free(&shake);
  13991. #endif /* WOLFSSL_SHAKE256 */
  13992. return EXPECT_RESULT();
  13993. }
  13994. static int test_wc_Shake256_Final(void)
  13995. {
  13996. EXPECT_DECLS;
  13997. #ifdef WOLFSSL_SHAKE256
  13998. wc_Shake shake;
  13999. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14000. "nopnopq";
  14001. const char* expOut = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f"
  14002. "\x6f\x87\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b"
  14003. "\xe5\xd4\xfd\x2e\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59"
  14004. "\xaa\x80\x60\xf1\xf9\xbc\x99\x6c\x05\xac\xa3\xc6\x96"
  14005. "\xa8\xb6\x62\x79\xdc\x67\x2c\x74\x0b\xb2\x24\xec\x37"
  14006. "\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55\xf5\x1d\x97"
  14007. "\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a\xf2"
  14008. "\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67"
  14009. "\x60\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  14010. byte hash[114];
  14011. /* Init stack variables. */
  14012. XMEMSET(hash, 0, sizeof(hash));
  14013. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14014. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, (word32)XSTRLEN(msg)),
  14015. 0);
  14016. ExpectIntEQ(wc_Shake256_Final(&shake, hash, (word32)sizeof(hash)), 0);
  14017. ExpectIntEQ(XMEMCMP(expOut, hash, (word32)sizeof(hash)), 0);
  14018. /* Test bad args. */
  14019. ExpectIntEQ(wc_Shake256_Final(NULL, hash, (word32)sizeof(hash)),
  14020. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14021. ExpectIntEQ(wc_Shake256_Final(&shake, NULL, (word32)sizeof(hash)),
  14022. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14023. wc_Shake256_Free(&shake);
  14024. #endif
  14025. return EXPECT_RESULT();
  14026. }
  14027. /*
  14028. * Testing wc_Shake256_Copy()
  14029. */
  14030. static int test_wc_Shake256_Copy(void)
  14031. {
  14032. EXPECT_DECLS;
  14033. #ifdef WOLFSSL_SHAKE256
  14034. wc_Shake shake, shakeCpy;
  14035. const char* msg = TEST_STRING;
  14036. word32 msglen = (word32)TEST_STRING_SZ;
  14037. byte hash[144];
  14038. byte hashCpy[144];
  14039. word32 hashLen = sizeof(hash);
  14040. word32 hashLenCpy = sizeof(hashCpy);
  14041. XMEMSET(hash, 0, sizeof(hash));
  14042. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14043. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14044. ExpectIntEQ(wc_InitShake256(&shakeCpy, HEAP_HINT, testDevId), 0);
  14045. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, msglen), 0);
  14046. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, &shake), 0);
  14047. ExpectIntEQ(wc_Shake256_Final(&shake, hash, hashLen), 0);
  14048. ExpectIntEQ(wc_Shake256_Final(&shakeCpy, hashCpy, hashLenCpy), 0);
  14049. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14050. /* Test bad args. */
  14051. ExpectIntEQ(wc_Shake256_Copy(NULL, &shake), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14052. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14053. wc_Shake256_Free(&shake);
  14054. wc_Shake256_Free(&shakeCpy);
  14055. #endif
  14056. return EXPECT_RESULT();
  14057. } /* END test_wc_Shake256_Copy */
  14058. /*
  14059. * Unit test function for wc_Shake256Hash()
  14060. */
  14061. static int test_wc_Shake256Hash(void)
  14062. {
  14063. EXPECT_DECLS;
  14064. #ifdef WOLFSSL_SHAKE256
  14065. const byte data[] = { /* Hello World */
  14066. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  14067. 0x72,0x6c,0x64
  14068. };
  14069. word32 len = sizeof(data);
  14070. byte hash[144];
  14071. word32 hashLen = sizeof(hash);
  14072. ExpectIntEQ(wc_Shake256Hash(data, len, hash, hashLen), 0);
  14073. #endif
  14074. return EXPECT_RESULT();
  14075. } /* END test_wc_Shake256Hash */
  14076. /*
  14077. * Testing wc_InitSm3(), wc_Sm3Free()
  14078. */
  14079. static int test_wc_InitSm3Free(void)
  14080. {
  14081. EXPECT_DECLS;
  14082. #ifdef WOLFSSL_SM3
  14083. wc_Sm3 sm3;
  14084. /* Invalid Parameters */
  14085. ExpectIntEQ(wc_InitSm3(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14086. /* Valid Parameters */
  14087. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14088. wc_Sm3Free(NULL);
  14089. wc_Sm3Free(&sm3);
  14090. #endif
  14091. return EXPECT_RESULT();
  14092. } /* END test_wc_InitSm3 */
  14093. /*
  14094. * Testing wc_Sm3Update(), wc_Sm3Final()
  14095. */
  14096. static int test_wc_Sm3UpdateFinal(void)
  14097. {
  14098. EXPECT_DECLS;
  14099. #ifdef WOLFSSL_SM3
  14100. wc_Sm3 sm3;
  14101. byte data[WC_SM3_BLOCK_SIZE * 4];
  14102. byte hash[WC_SM3_DIGEST_SIZE];
  14103. byte calcHash[WC_SM3_DIGEST_SIZE];
  14104. byte expHash[WC_SM3_DIGEST_SIZE] = {
  14105. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  14106. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  14107. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  14108. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  14109. };
  14110. word32 chunk;
  14111. word32 i;
  14112. XMEMSET(data, 0, sizeof(data));
  14113. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14114. /* Invalid Parameters */
  14115. ExpectIntEQ(wc_Sm3Update(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14116. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14117. ExpectIntEQ(wc_Sm3Update(NULL, data, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14118. /* Valid Parameters */
  14119. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 0), 0);
  14120. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14121. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14122. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE), 0);
  14123. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE - 2), 0);
  14124. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE * 2), 0);
  14125. /* Ensure too many bytes for lengths. */
  14126. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_PAD_SIZE), 0);
  14127. /* Invalid Parameters */
  14128. ExpectIntEQ(wc_Sm3Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14129. ExpectIntEQ(wc_Sm3Final(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14130. ExpectIntEQ(wc_Sm3Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14131. /* Valid Parameters */
  14132. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14133. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  14134. /* Chunk tests. */
  14135. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14136. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14137. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  14138. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  14139. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, chunk), 0);
  14140. }
  14141. if (i < (word32)sizeof(data)) {
  14142. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, (word32)sizeof(data) - i),
  14143. 0);
  14144. }
  14145. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14146. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14147. }
  14148. /* Not testing when the low 32-bit length overflows. */
  14149. wc_Sm3Free(&sm3);
  14150. #endif
  14151. return EXPECT_RESULT();
  14152. } /* END test_wc_Sm3Update */
  14153. /*
  14154. * Testing wc_Sm3GetHash()
  14155. */
  14156. static int test_wc_Sm3GetHash(void)
  14157. {
  14158. EXPECT_DECLS;
  14159. #ifdef WOLFSSL_SM3
  14160. wc_Sm3 sm3;
  14161. byte hash[WC_SM3_DIGEST_SIZE];
  14162. byte calcHash[WC_SM3_DIGEST_SIZE];
  14163. byte data[WC_SM3_BLOCK_SIZE];
  14164. XMEMSET(data, 0, sizeof(data));
  14165. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14166. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14167. /* Invalid Parameters */
  14168. ExpectIntEQ(wc_Sm3GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14169. ExpectIntEQ(wc_Sm3GetHash(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14170. ExpectIntEQ(wc_Sm3GetHash(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14171. /* Valid Parameters */
  14172. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14173. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14174. /* With update. */
  14175. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14176. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14177. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14178. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14179. wc_Sm3Free(&sm3);
  14180. #endif
  14181. return EXPECT_RESULT();
  14182. } /* END test_wc_Sm3Update */
  14183. /*
  14184. * Testing wc_Sm3Copy()
  14185. */
  14186. static int test_wc_Sm3Copy(void)
  14187. {
  14188. EXPECT_DECLS;
  14189. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14190. wc_Sm3 sm3;
  14191. wc_Sm3 sm3Copy;
  14192. byte hash[WC_SM3_DIGEST_SIZE];
  14193. byte hashCopy[WC_SM3_DIGEST_SIZE];
  14194. byte data[WC_SM3_BLOCK_SIZE + 1];
  14195. int i;
  14196. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14197. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14198. /* Invalid Parameters */
  14199. ExpectIntEQ(wc_Sm3Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14200. ExpectIntEQ(wc_Sm3Copy(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14201. ExpectIntEQ(wc_Sm3Copy(NULL, &sm3Copy), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14202. /* Valid Parameters */
  14203. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14204. /* Ensure all parts of data updated during hashing are copied. */
  14205. for (i = 0; i < WC_SM3_BLOCK_SIZE + 1; i++) {
  14206. ExpectIntEQ(wc_Sm3Update(&sm3, data, i), 0);
  14207. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14208. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14209. ExpectIntEQ(wc_Sm3Update(&sm3Copy, data, 1), 0);
  14210. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14211. ExpectIntEQ(wc_Sm3Final(&sm3Copy, hashCopy), 0);
  14212. ExpectBufEQ(hash, hashCopy, WC_SM3_DIGEST_SIZE);
  14213. }
  14214. wc_Sm3Free(&sm3Copy);
  14215. wc_Sm3Free(&sm3);
  14216. #endif
  14217. return EXPECT_RESULT();
  14218. } /* END test_wc_Sm3Copy */
  14219. /*
  14220. * Testing wc_Sm3FinalRaw()
  14221. */
  14222. static int test_wc_Sm3FinalRaw(void)
  14223. {
  14224. EXPECT_DECLS;
  14225. #if defined(WOLFSSL_SM3) && !defined(HAVE_SELFTEST) && \
  14226. !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  14227. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  14228. !defined(WOLFSSL_NO_HASH_RAW)
  14229. wc_Sm3 sm3;
  14230. byte hash1[WC_SM3_DIGEST_SIZE];
  14231. byte hash2[WC_SM3_DIGEST_SIZE];
  14232. byte hash3[WC_SM3_DIGEST_SIZE];
  14233. byte* hash_test[3] = { hash1, hash2, hash3 };
  14234. int times;
  14235. int i;
  14236. XMEMSET(&sm3, 0, sizeof(sm3));
  14237. /* Initialize */
  14238. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14239. /* Invalid Parameters */
  14240. ExpectIntEQ(wc_Sm3FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14241. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14242. ExpectIntEQ(wc_Sm3FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14243. times = sizeof(hash_test) / sizeof(byte*);
  14244. for (i = 0; i < times; i++) {
  14245. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, hash_test[i]), 0);
  14246. }
  14247. wc_Sm3Free(&sm3);
  14248. #endif
  14249. return EXPECT_RESULT();
  14250. } /* END test_wc_Sm3FinalRaw */
  14251. /*
  14252. * Testing wc_Sm3GetFlags, wc_Sm3SetFlags()
  14253. */
  14254. static int test_wc_Sm3GetSetFlags(void)
  14255. {
  14256. EXPECT_DECLS;
  14257. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14258. wc_Sm3 sm3;
  14259. wc_Sm3 sm3Copy;
  14260. word32 flags = 0;
  14261. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14262. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14263. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14264. ExpectIntEQ(flags, 0);
  14265. ExpectIntEQ(wc_Sm3SetFlags(NULL, WC_HASH_FLAG_WILLCOPY), 0);
  14266. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14267. ExpectIntEQ(flags, 0);
  14268. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14269. ExpectIntEQ(flags, 0);
  14270. ExpectIntEQ(wc_Sm3SetFlags(&sm3, WC_HASH_FLAG_WILLCOPY), 0);
  14271. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14272. ExpectIntEQ(flags, WC_HASH_FLAG_WILLCOPY);
  14273. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14274. ExpectIntEQ(wc_Sm3GetFlags(&sm3Copy, &flags), 0);
  14275. ExpectIntEQ(flags, WC_HASH_FLAG_ISCOPY | WC_HASH_FLAG_WILLCOPY);
  14276. wc_Sm3Free(&sm3Copy);
  14277. wc_Sm3Free(&sm3);
  14278. #endif
  14279. return EXPECT_RESULT();
  14280. } /* END test_wc_Sm3Update */
  14281. /*
  14282. * Testing wc_Sm3Hash()
  14283. */
  14284. static int test_wc_Sm3Hash(void)
  14285. {
  14286. EXPECT_DECLS;
  14287. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14288. byte data[WC_SM3_BLOCK_SIZE];
  14289. byte hash[WC_SM3_DIGEST_SIZE];
  14290. /* Invalid parameters. */
  14291. ExpectIntEQ(wc_Sm3Hash(NULL, sizeof(data), hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14292. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14293. /* Valid parameters. */
  14294. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), hash), 0);
  14295. #endif
  14296. return EXPECT_RESULT();
  14297. } /* END test_wc_Sm3Hash */
  14298. /*
  14299. * Test function for wc_HmacSetKey
  14300. */
  14301. static int test_wc_Md5HmacSetKey(void)
  14302. {
  14303. EXPECT_DECLS;
  14304. #if !defined(NO_HMAC) && !defined(NO_MD5)
  14305. Hmac hmac;
  14306. int ret, times, itr;
  14307. const char* keys[]=
  14308. {
  14309. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  14310. #ifndef HAVE_FIPS
  14311. "Jefe", /* smaller than minimum FIPS key size */
  14312. #endif
  14313. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14314. };
  14315. times = sizeof(keys) / sizeof(char*);
  14316. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14317. for (itr = 0; itr < times; itr++) {
  14318. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[itr],
  14319. (word32)XSTRLEN(keys[itr]));
  14320. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14321. wc_HmacFree(&hmac);
  14322. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14323. #else
  14324. ExpectIntEQ(ret, 0);
  14325. #endif
  14326. }
  14327. /* Bad args. */
  14328. ExpectIntEQ(wc_HmacSetKey(NULL, WC_MD5, (byte*)keys[0],
  14329. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14330. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, NULL, (word32)XSTRLEN(keys[0])),
  14331. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14332. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14333. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14334. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[0], 0);
  14335. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14336. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14337. #elif defined(HAVE_FIPS)
  14338. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14339. #else
  14340. ExpectIntEQ(ret, 0);
  14341. #endif
  14342. wc_HmacFree(&hmac);
  14343. #endif
  14344. return EXPECT_RESULT();
  14345. } /* END test_wc_Md5HmacSetKey */
  14346. /*
  14347. * testing wc_HmacSetKey() on wc_Sha hash.
  14348. */
  14349. static int test_wc_ShaHmacSetKey(void)
  14350. {
  14351. EXPECT_DECLS;
  14352. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14353. Hmac hmac;
  14354. int ret, times, itr;
  14355. const char* keys[]=
  14356. {
  14357. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14358. "\x0b\x0b\x0b",
  14359. #ifndef HAVE_FIPS
  14360. "Jefe", /* smaller than minimum FIPS key size */
  14361. #endif
  14362. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14363. "\xAA\xAA\xAA"
  14364. };
  14365. times = sizeof(keys) / sizeof(char*);
  14366. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14367. for (itr = 0; itr < times; itr++) {
  14368. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[itr],
  14369. (word32)XSTRLEN(keys[itr])), 0);
  14370. }
  14371. /* Bad args. */
  14372. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA, (byte*)keys[0],
  14373. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14374. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, NULL, (word32)XSTRLEN(keys[0])),
  14375. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14376. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14377. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14378. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[0], 0);
  14379. #ifdef HAVE_FIPS
  14380. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14381. #else
  14382. ExpectIntEQ(ret, 0);
  14383. #endif
  14384. wc_HmacFree(&hmac);
  14385. #endif
  14386. return EXPECT_RESULT();
  14387. } /* END test_wc_ShaHmacSetKey() */
  14388. /*
  14389. * testing wc_HmacSetKey() on Sha224 hash.
  14390. */
  14391. static int test_wc_Sha224HmacSetKey(void)
  14392. {
  14393. EXPECT_DECLS;
  14394. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14395. Hmac hmac;
  14396. int ret, times, itr;
  14397. const char* keys[]=
  14398. {
  14399. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14400. "\x0b\x0b\x0b",
  14401. #ifndef HAVE_FIPS
  14402. "Jefe", /* smaller than minimum FIPS key size */
  14403. #endif
  14404. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14405. "\xAA\xAA\xAA"
  14406. };
  14407. times = sizeof(keys) / sizeof(char*);
  14408. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14409. for (itr = 0; itr < times; itr++) {
  14410. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[itr],
  14411. (word32)XSTRLEN(keys[itr])), 0);
  14412. }
  14413. /* Bad args. */
  14414. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA224, (byte*)keys[0],
  14415. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14416. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, NULL, (word32)XSTRLEN(keys[0])),
  14417. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14418. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14419. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14420. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[0], 0);
  14421. #ifdef HAVE_FIPS
  14422. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14423. #else
  14424. ExpectIntEQ(ret, 0);
  14425. #endif
  14426. wc_HmacFree(&hmac);
  14427. #endif
  14428. return EXPECT_RESULT();
  14429. } /* END test_wc_Sha224HmacSetKey() */
  14430. /*
  14431. * testing wc_HmacSetKey() on Sha256 hash
  14432. */
  14433. static int test_wc_Sha256HmacSetKey(void)
  14434. {
  14435. EXPECT_DECLS;
  14436. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14437. Hmac hmac;
  14438. int ret, times, itr;
  14439. const char* keys[]=
  14440. {
  14441. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14442. "\x0b\x0b\x0b",
  14443. #ifndef HAVE_FIPS
  14444. "Jefe", /* smaller than minimum FIPS key size */
  14445. #endif
  14446. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14447. "\xAA\xAA\xAA"
  14448. };
  14449. times = sizeof(keys) / sizeof(char*);
  14450. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14451. for (itr = 0; itr < times; itr++) {
  14452. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[itr],
  14453. (word32)XSTRLEN(keys[itr])), 0);
  14454. }
  14455. /* Bad args. */
  14456. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA256, (byte*)keys[0],
  14457. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14458. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, (word32)XSTRLEN(keys[0])),
  14459. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14460. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14461. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14462. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[0], 0);
  14463. #ifdef HAVE_FIPS
  14464. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14465. #else
  14466. ExpectIntEQ(ret, 0);
  14467. #endif
  14468. wc_HmacFree(&hmac);
  14469. #endif
  14470. return EXPECT_RESULT();
  14471. } /* END test_wc_Sha256HmacSetKey() */
  14472. /*
  14473. * testing wc_HmacSetKey on Sha384 hash.
  14474. */
  14475. static int test_wc_Sha384HmacSetKey(void)
  14476. {
  14477. EXPECT_DECLS;
  14478. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14479. Hmac hmac;
  14480. int ret, times, itr;
  14481. const char* keys[]=
  14482. {
  14483. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14484. "\x0b\x0b\x0b",
  14485. #ifndef HAVE_FIPS
  14486. "Jefe", /* smaller than minimum FIPS key size */
  14487. #endif
  14488. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14489. "\xAA\xAA\xAA"
  14490. };
  14491. times = sizeof(keys) / sizeof(char*);
  14492. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14493. for (itr = 0; itr < times; itr++) {
  14494. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[itr],
  14495. (word32)XSTRLEN(keys[itr])), 0);
  14496. }
  14497. /* Bad args. */
  14498. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA384, (byte*)keys[0],
  14499. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14500. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, NULL, (word32)XSTRLEN(keys[0])),
  14501. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14502. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14503. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14504. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[0], 0);
  14505. #ifdef HAVE_FIPS
  14506. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14507. #else
  14508. ExpectIntEQ(ret, 0);
  14509. #endif
  14510. wc_HmacFree(&hmac);
  14511. #endif
  14512. return EXPECT_RESULT();
  14513. } /* END test_wc_Sha384HmacSetKey() */
  14514. /*
  14515. * testing wc_HmacUpdate on wc_Md5 hash.
  14516. */
  14517. static int test_wc_Md5HmacUpdate(void)
  14518. {
  14519. EXPECT_DECLS;
  14520. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  14521. Hmac hmac;
  14522. testVector a, b;
  14523. #ifdef HAVE_FIPS
  14524. const char* keys =
  14525. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14526. #else
  14527. const char* keys = "Jefe";
  14528. #endif
  14529. a.input = "what do ya want for nothing?";
  14530. a.inLen = XSTRLEN(a.input);
  14531. b.input = "Hi There";
  14532. b.inLen = XSTRLEN(b.input);
  14533. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14534. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys,
  14535. (word32)XSTRLEN(keys)), 0);
  14536. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14537. /* Update Hmac. */
  14538. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14539. /* Test bad args. */
  14540. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14541. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14542. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14543. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14544. wc_HmacFree(&hmac);
  14545. #endif
  14546. return EXPECT_RESULT();
  14547. } /* END test_wc_Md5HmacUpdate */
  14548. /*
  14549. * testing wc_HmacUpdate on SHA hash.
  14550. */
  14551. static int test_wc_ShaHmacUpdate(void)
  14552. {
  14553. EXPECT_DECLS;
  14554. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14555. Hmac hmac;
  14556. testVector a, b;
  14557. #ifdef HAVE_FIPS
  14558. const char* keys =
  14559. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14560. #else
  14561. const char* keys = "Jefe";
  14562. #endif
  14563. a.input = "what do ya want for nothing?";
  14564. a.inLen = XSTRLEN(a.input);
  14565. b.input = "Hi There";
  14566. b.inLen = XSTRLEN(b.input);
  14567. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14568. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys,
  14569. (word32)XSTRLEN(keys)), 0);
  14570. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14571. /* Update Hmac. */
  14572. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14573. /* Test bad args. */
  14574. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14575. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14576. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14577. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14578. wc_HmacFree(&hmac);
  14579. #endif
  14580. return EXPECT_RESULT();
  14581. } /* END test_wc_ShaHmacUpdate */
  14582. /*
  14583. * testing wc_HmacUpdate on SHA224 hash.
  14584. */
  14585. static int test_wc_Sha224HmacUpdate(void)
  14586. {
  14587. EXPECT_DECLS;
  14588. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14589. Hmac hmac;
  14590. testVector a, b;
  14591. #ifdef HAVE_FIPS
  14592. const char* keys =
  14593. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14594. #else
  14595. const char* keys = "Jefe";
  14596. #endif
  14597. a.input = "what do ya want for nothing?";
  14598. a.inLen = XSTRLEN(a.input);
  14599. b.input = "Hi There";
  14600. b.inLen = XSTRLEN(b.input);
  14601. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14602. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys,
  14603. (word32)XSTRLEN(keys)), 0);
  14604. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14605. /* Update Hmac. */
  14606. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14607. /* Test bad args. */
  14608. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14609. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14610. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14611. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14612. wc_HmacFree(&hmac);
  14613. #endif
  14614. return EXPECT_RESULT();
  14615. } /* END test_wc_Sha224HmacUpdate */
  14616. /*
  14617. * testing wc_HmacUpdate on SHA256 hash.
  14618. */
  14619. static int test_wc_Sha256HmacUpdate(void)
  14620. {
  14621. EXPECT_DECLS;
  14622. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14623. Hmac hmac;
  14624. testVector a, b;
  14625. #ifdef HAVE_FIPS
  14626. const char* keys =
  14627. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14628. #else
  14629. const char* keys = "Jefe";
  14630. #endif
  14631. a.input = "what do ya want for nothing?";
  14632. a.inLen = XSTRLEN(a.input);
  14633. b.input = "Hi There";
  14634. b.inLen = XSTRLEN(b.input);
  14635. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14636. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys,
  14637. (word32)XSTRLEN(keys)), 0);
  14638. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14639. /* Update Hmac. */
  14640. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14641. /* Test bad args. */
  14642. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14643. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14644. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14645. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14646. wc_HmacFree(&hmac);
  14647. #endif
  14648. return EXPECT_RESULT();
  14649. } /* END test_wc_Sha256HmacUpdate */
  14650. /*
  14651. * testing wc_HmacUpdate on SHA384 hash.
  14652. */
  14653. static int test_wc_Sha384HmacUpdate(void)
  14654. {
  14655. EXPECT_DECLS;
  14656. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14657. Hmac hmac;
  14658. testVector a, b;
  14659. #ifdef HAVE_FIPS
  14660. const char* keys =
  14661. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14662. #else
  14663. const char* keys = "Jefe";
  14664. #endif
  14665. a.input = "what do ya want for nothing?";
  14666. a.inLen = XSTRLEN(a.input);
  14667. b.input = "Hi There";
  14668. b.inLen = XSTRLEN(b.input);
  14669. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14670. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys,
  14671. (word32)XSTRLEN(keys)), 0);
  14672. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14673. /* Update Hmac. */
  14674. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14675. /* Test bad args. */
  14676. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14677. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14678. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14679. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14680. wc_HmacFree(&hmac);
  14681. #endif
  14682. return EXPECT_RESULT();
  14683. } /* END test_wc_Sha384HmacUpdate */
  14684. /*
  14685. * Testing wc_HmacFinal() with MD5
  14686. */
  14687. static int test_wc_Md5HmacFinal(void)
  14688. {
  14689. EXPECT_DECLS;
  14690. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  14691. Hmac hmac;
  14692. byte hash[WC_MD5_DIGEST_SIZE];
  14693. testVector a;
  14694. const char* key;
  14695. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14696. a.input = "Hi There";
  14697. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  14698. "\x9d";
  14699. a.inLen = XSTRLEN(a.input);
  14700. a.outLen = XSTRLEN(a.output);
  14701. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14702. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)key, (word32)XSTRLEN(key)),
  14703. 0);
  14704. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14705. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14706. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  14707. /* Try bad parameters. */
  14708. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14709. #ifndef HAVE_FIPS
  14710. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14711. #endif
  14712. wc_HmacFree(&hmac);
  14713. #endif
  14714. return EXPECT_RESULT();
  14715. } /* END test_wc_Md5HmacFinal */
  14716. /*
  14717. * Testing wc_HmacFinal() with SHA
  14718. */
  14719. static int test_wc_ShaHmacFinal(void)
  14720. {
  14721. EXPECT_DECLS;
  14722. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14723. Hmac hmac;
  14724. byte hash[WC_SHA_DIGEST_SIZE];
  14725. testVector a;
  14726. const char* key;
  14727. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14728. "\x0b\x0b\x0b";
  14729. a.input = "Hi There";
  14730. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  14731. "\x8e\xf1\x46\xbe\x00";
  14732. a.inLen = XSTRLEN(a.input);
  14733. a.outLen = XSTRLEN(a.output);
  14734. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14735. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)key, (word32)XSTRLEN(key)),
  14736. 0);
  14737. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14738. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14739. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  14740. /* Try bad parameters. */
  14741. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14742. #ifndef HAVE_FIPS
  14743. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14744. #endif
  14745. wc_HmacFree(&hmac);
  14746. #endif
  14747. return EXPECT_RESULT();
  14748. } /* END test_wc_ShaHmacFinal */
  14749. /*
  14750. * Testing wc_HmacFinal() with SHA224
  14751. */
  14752. static int test_wc_Sha224HmacFinal(void)
  14753. {
  14754. EXPECT_DECLS;
  14755. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14756. Hmac hmac;
  14757. byte hash[WC_SHA224_DIGEST_SIZE];
  14758. testVector a;
  14759. const char* key;
  14760. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14761. "\x0b\x0b\x0b";
  14762. a.input = "Hi There";
  14763. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  14764. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  14765. a.inLen = XSTRLEN(a.input);
  14766. a.outLen = XSTRLEN(a.output);
  14767. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14768. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)key,
  14769. (word32)XSTRLEN(key)), 0);
  14770. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14771. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14772. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  14773. /* Try bad parameters. */
  14774. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14775. #ifndef HAVE_FIPS
  14776. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14777. #endif
  14778. wc_HmacFree(&hmac);
  14779. #endif
  14780. return EXPECT_RESULT();
  14781. } /* END test_wc_Sha224HmacFinal */
  14782. /*
  14783. * Testing wc_HmacFinal() with SHA256
  14784. */
  14785. static int test_wc_Sha256HmacFinal(void)
  14786. {
  14787. EXPECT_DECLS;
  14788. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14789. Hmac hmac;
  14790. byte hash[WC_SHA256_DIGEST_SIZE];
  14791. testVector a;
  14792. const char* key;
  14793. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14794. "\x0b\x0b\x0b";
  14795. a.input = "Hi There";
  14796. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  14797. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  14798. "\xcf\xf7";
  14799. a.inLen = XSTRLEN(a.input);
  14800. a.outLen = XSTRLEN(a.output);
  14801. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14802. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)key,
  14803. (word32)XSTRLEN(key)), 0);
  14804. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14805. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14806. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  14807. /* Try bad parameters. */
  14808. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14809. #ifndef HAVE_FIPS
  14810. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14811. #endif
  14812. wc_HmacFree(&hmac);
  14813. #endif
  14814. return EXPECT_RESULT();
  14815. } /* END test_wc_Sha256HmacFinal */
  14816. /*
  14817. * Testing wc_HmacFinal() with SHA384
  14818. */
  14819. static int test_wc_Sha384HmacFinal(void)
  14820. {
  14821. EXPECT_DECLS;
  14822. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14823. Hmac hmac;
  14824. byte hash[WC_SHA384_DIGEST_SIZE];
  14825. testVector a;
  14826. const char* key;
  14827. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14828. "\x0b\x0b\x0b";
  14829. a.input = "Hi There";
  14830. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  14831. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  14832. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  14833. "\xfa\x9c\xb6";
  14834. a.inLen = XSTRLEN(a.input);
  14835. a.outLen = XSTRLEN(a.output);
  14836. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14837. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)key,
  14838. (word32)XSTRLEN(key)), 0);
  14839. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14840. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14841. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  14842. /* Try bad parameters. */
  14843. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14844. #ifndef HAVE_FIPS
  14845. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14846. #endif
  14847. wc_HmacFree(&hmac);
  14848. #endif
  14849. return EXPECT_RESULT();
  14850. } /* END test_wc_Sha384HmacFinal */
  14851. /*
  14852. * Testing wc_InitCmac()
  14853. */
  14854. static int test_wc_InitCmac(void)
  14855. {
  14856. EXPECT_DECLS;
  14857. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  14858. Cmac cmac1;
  14859. Cmac cmac2;
  14860. Cmac cmac3;
  14861. /* AES 128 key. */
  14862. byte key1[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  14863. "\x09\x10\x11\x12\x13\x14\x15\x16";
  14864. /* AES 192 key. */
  14865. byte key2[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  14866. "\x09\x01\x11\x12\x13\x14\x15\x16"
  14867. "\x01\x02\x03\x04\x05\x06\x07\x08";
  14868. /* AES 256 key. */
  14869. byte key3[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  14870. "\x09\x01\x11\x12\x13\x14\x15\x16"
  14871. "\x01\x02\x03\x04\x05\x06\x07\x08"
  14872. "\x09\x01\x11\x12\x13\x14\x15\x16";
  14873. word32 key1Sz = (word32)sizeof(key1) - 1;
  14874. word32 key2Sz = (word32)sizeof(key2) - 1;
  14875. word32 key3Sz = (word32)sizeof(key3) - 1;
  14876. int type = WC_CMAC_AES;
  14877. (void)key1;
  14878. (void)key1Sz;
  14879. (void)key2;
  14880. (void)key2Sz;
  14881. XMEMSET(&cmac1, 0, sizeof(Cmac));
  14882. XMEMSET(&cmac2, 0, sizeof(Cmac));
  14883. XMEMSET(&cmac3, 0, sizeof(Cmac));
  14884. #ifdef WOLFSSL_AES_128
  14885. ExpectIntEQ(wc_InitCmac(&cmac1, key1, key1Sz, type, NULL), 0);
  14886. #endif
  14887. #ifdef WOLFSSL_AES_192
  14888. wc_AesFree(&cmac1.aes);
  14889. ExpectIntEQ(wc_InitCmac(&cmac2, key2, key2Sz, type, NULL), 0);
  14890. #endif
  14891. #ifdef WOLFSSL_AES_256
  14892. wc_AesFree(&cmac2.aes);
  14893. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, type, NULL), 0);
  14894. #endif
  14895. wc_AesFree(&cmac3.aes);
  14896. /* Test bad args. */
  14897. ExpectIntEQ(wc_InitCmac(NULL, key3, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14898. ExpectIntEQ(wc_InitCmac(&cmac3, NULL, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14899. ExpectIntEQ(wc_InitCmac(&cmac3, key3, 0, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14900. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14901. #endif
  14902. return EXPECT_RESULT();
  14903. } /* END test_wc_InitCmac */
  14904. /*
  14905. * Testing wc_CmacUpdate()
  14906. */
  14907. static int test_wc_CmacUpdate(void)
  14908. {
  14909. EXPECT_DECLS;
  14910. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  14911. Cmac cmac;
  14912. byte key[] = {
  14913. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  14914. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  14915. };
  14916. byte in[] = "\xe2\xb4\xb6\xf9\x48\x44\x02\x64"
  14917. "\x5c\x47\x80\x9e\xd5\xa8\x3a\x17"
  14918. "\xb3\x78\xcf\x85\x22\x41\x74\xd9"
  14919. "\xa0\x97\x39\x71\x62\xf1\x8e\x8f"
  14920. "\xf4";
  14921. word32 inSz = (word32)sizeof(in) - 1;
  14922. word32 keySz = (word32)sizeof(key);
  14923. int type = WC_CMAC_AES;
  14924. XMEMSET(&cmac, 0, sizeof(Cmac));
  14925. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  14926. ExpectIntEQ(wc_CmacUpdate(&cmac, in, inSz), 0);
  14927. /* Test bad args. */
  14928. ExpectIntEQ(wc_CmacUpdate(NULL, in, inSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14929. ExpectIntEQ(wc_CmacUpdate(&cmac, NULL, 30), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14930. wc_AesFree(&cmac.aes);
  14931. #endif
  14932. return EXPECT_RESULT();
  14933. } /* END test_wc_CmacUpdate */
  14934. /*
  14935. * Testing wc_CmacFinal()
  14936. */
  14937. static int test_wc_CmacFinal(void)
  14938. {
  14939. EXPECT_DECLS;
  14940. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  14941. Cmac cmac;
  14942. byte key[] = {
  14943. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  14944. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  14945. };
  14946. byte msg[] = {
  14947. 0xe2, 0xb4, 0xb6, 0xf9, 0x48, 0x44, 0x02, 0x64,
  14948. 0x5c, 0x47, 0x80, 0x9e, 0xd5, 0xa8, 0x3a, 0x17,
  14949. 0xb3, 0x78, 0xcf, 0x85, 0x22, 0x41, 0x74, 0xd9,
  14950. 0xa0, 0x97, 0x39, 0x71, 0x62, 0xf1, 0x8e, 0x8f,
  14951. 0xf4
  14952. };
  14953. /* Test vectors from CMACGenAES128.rsp from
  14954. * http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html#cmac
  14955. * Per RFC4493 truncation of lsb is possible.
  14956. */
  14957. byte expMac[] = {
  14958. 0x4e, 0x6e, 0xc5, 0x6f, 0xf9, 0x5d, 0x0e, 0xae,
  14959. 0x1c, 0xf8, 0x3e, 0xfc, 0xf4, 0x4b, 0xeb
  14960. };
  14961. byte mac[AES_BLOCK_SIZE];
  14962. word32 msgSz = (word32)sizeof(msg);
  14963. word32 keySz = (word32)sizeof(key);
  14964. word32 macSz = sizeof(mac);
  14965. word32 badMacSz = 17;
  14966. int expMacSz = sizeof(expMac);
  14967. int type = WC_CMAC_AES;
  14968. XMEMSET(&cmac, 0, sizeof(Cmac));
  14969. XMEMSET(mac, 0, macSz);
  14970. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  14971. ExpectIntEQ(wc_CmacUpdate(&cmac, msg, msgSz), 0);
  14972. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14973. /* Pass in bad args. */
  14974. ExpectIntEQ(wc_CmacFinalNoFree(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14975. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14976. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  14977. /* For the last call, use the API with implicit wc_CmacFree(). */
  14978. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  14979. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  14980. #else /* !HAVE_FIPS || FIPS>=5.3 */
  14981. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  14982. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  14983. /* Pass in bad args. */
  14984. ExpectIntEQ(wc_CmacFinal(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14985. ExpectIntEQ(wc_CmacFinal(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14986. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  14987. #endif /* !HAVE_FIPS || FIPS>=5.3 */
  14988. #endif
  14989. return EXPECT_RESULT();
  14990. } /* END test_wc_CmacFinal */
  14991. /*
  14992. * Testing wc_AesCmacGenerate() && wc_AesCmacVerify()
  14993. */
  14994. static int test_wc_AesCmacGenerate(void)
  14995. {
  14996. EXPECT_DECLS;
  14997. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  14998. byte key[] = {
  14999. 0x26, 0xef, 0x8b, 0x40, 0x34, 0x11, 0x7d, 0x9e,
  15000. 0xbe, 0xc0, 0xc7, 0xfc, 0x31, 0x08, 0x54, 0x69
  15001. };
  15002. byte msg[] = "\x18\x90\x49\xef\xfd\x7c\xf9\xc8"
  15003. "\xf3\x59\x65\xbc\xb0\x97\x8f\xd4";
  15004. byte expMac[] = "\x29\x5f\x2f\x71\xfc\x58\xe6\xf6"
  15005. "\x3d\x32\x65\x4c\x66\x23\xc5";
  15006. byte mac[AES_BLOCK_SIZE];
  15007. word32 keySz = sizeof(key);
  15008. word32 macSz = sizeof(mac);
  15009. word32 msgSz = sizeof(msg) - 1;
  15010. word32 expMacSz = sizeof(expMac) - 1;
  15011. XMEMSET(mac, 0, macSz);
  15012. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz), 0);
  15013. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15014. /* Pass in bad args. */
  15015. ExpectIntEQ(wc_AesCmacGenerate(NULL, &macSz, msg, msgSz, key, keySz),
  15016. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15017. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, NULL, keySz),
  15018. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15019. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, 0),
  15020. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15021. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, NULL, msgSz, key, keySz),
  15022. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15023. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz), 0);
  15024. /* Test bad args. */
  15025. ExpectIntEQ(wc_AesCmacVerify(NULL, macSz, msg, msgSz, key, keySz),
  15026. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15027. ExpectIntEQ(wc_AesCmacVerify(mac, 0, msg, msgSz, key, keySz),
  15028. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15029. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, NULL, keySz),
  15030. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15031. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, 0),
  15032. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15033. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, NULL, msgSz, key, keySz),
  15034. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15035. #endif
  15036. return EXPECT_RESULT();
  15037. } /* END test_wc_AesCmacGenerate */
  15038. /*
  15039. * Testing streaming AES-GCM API.
  15040. */
  15041. static int test_wc_AesGcmStream(void)
  15042. {
  15043. EXPECT_DECLS;
  15044. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM) && \
  15045. defined(WOLFSSL_AESGCM_STREAM)
  15046. int i;
  15047. WC_RNG rng[1];
  15048. Aes aesEnc[1];
  15049. Aes aesDec[1];
  15050. byte tag[AES_BLOCK_SIZE];
  15051. byte in[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15052. byte out[AES_BLOCK_SIZE * 3 + 2];
  15053. byte plain[AES_BLOCK_SIZE * 3 + 2];
  15054. byte aad[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15055. byte key[AES_128_KEY_SIZE] = { 0, };
  15056. byte iv[AES_IV_SIZE] = { 1, };
  15057. byte ivOut[AES_IV_SIZE];
  15058. static const byte expTagAAD1[AES_BLOCK_SIZE] = {
  15059. 0x6c, 0x35, 0xe6, 0x7f, 0x59, 0x9e, 0xa9, 0x2f,
  15060. 0x27, 0x2d, 0x5f, 0x8e, 0x7e, 0x42, 0xd3, 0x05
  15061. };
  15062. static const byte expTagPlain1[AES_BLOCK_SIZE] = {
  15063. 0x24, 0xba, 0x57, 0x95, 0xd0, 0x27, 0x9e, 0x78,
  15064. 0x3a, 0x88, 0x4c, 0x0a, 0x5d, 0x50, 0x23, 0xd1
  15065. };
  15066. static const byte expTag[AES_BLOCK_SIZE] = {
  15067. 0x22, 0x91, 0x70, 0xad, 0x42, 0xc3, 0xad, 0x96,
  15068. 0xe0, 0x31, 0x57, 0x60, 0xb7, 0x92, 0xa3, 0x6d
  15069. };
  15070. XMEMSET(&rng, 0, sizeof(WC_RNG));
  15071. XMEMSET(&aesEnc, 0, sizeof(Aes));
  15072. XMEMSET(&aesDec, 0, sizeof(Aes));
  15073. /* Create a random for generating IV/nonce. */
  15074. ExpectIntEQ(wc_InitRng(rng), 0);
  15075. /* Initialize data structures. */
  15076. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15077. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15078. /* BadParameters to streaming init. */
  15079. ExpectIntEQ(wc_AesGcmEncryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15080. ExpectIntEQ(wc_AesGcmDecryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15081. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, AES_128_KEY_SIZE, NULL, 0),
  15082. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15083. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, 0, NULL, GCM_NONCE_MID_SZ),
  15084. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15085. /* Bad parameters to encrypt update. */
  15086. ExpectIntEQ(wc_AesGcmEncryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15087. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15088. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 1, NULL, 0),
  15089. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15090. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, in, 1, NULL, 0),
  15091. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15092. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, NULL, 1, NULL, 0),
  15093. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15094. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, NULL, 1),
  15095. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15096. /* Bad parameters to decrypt update. */
  15097. ExpectIntEQ(wc_AesGcmDecryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15098. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15099. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 1, NULL, 0),
  15100. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15101. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, in, 1, NULL, 0),
  15102. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15103. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, out, NULL, 1, NULL, 0),
  15104. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15105. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, NULL, 1),
  15106. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15107. /* Bad parameters to encrypt final. */
  15108. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15109. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15110. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15111. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15112. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15113. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, NULL, AES_BLOCK_SIZE),
  15114. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15115. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE + 1),
  15116. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15117. /* Bad parameters to decrypt final. */
  15118. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15119. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15120. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15121. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15122. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15123. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, NULL, AES_BLOCK_SIZE),
  15124. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15125. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE + 1),
  15126. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15127. /* Check calling final before setting key fails. */
  15128. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15129. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15130. /* Check calling update before setting key else fails. */
  15131. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15132. WC_NO_ERR_TRACE(MISSING_KEY));
  15133. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15134. WC_NO_ERR_TRACE(MISSING_KEY));
  15135. /* Set key but not IV. */
  15136. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), NULL, 0), 0);
  15137. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), NULL, 0), 0);
  15138. /* Check calling final before setting IV fails. */
  15139. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15140. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15141. /* Check calling update before setting IV else fails. */
  15142. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15143. WC_NO_ERR_TRACE(MISSING_IV));
  15144. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15145. WC_NO_ERR_TRACE(MISSING_IV));
  15146. /* Set IV using fixed part IV and external IV APIs. */
  15147. ExpectIntEQ(wc_AesGcmSetIV(aesEnc, GCM_NONCE_MID_SZ, iv, AES_IV_FIXED_SZ,
  15148. rng), 0);
  15149. ExpectIntEQ(wc_AesGcmEncryptInit_ex(aesEnc, NULL, 0, ivOut,
  15150. GCM_NONCE_MID_SZ), 0);
  15151. ExpectIntEQ(wc_AesGcmSetExtIV(aesDec, ivOut, GCM_NONCE_MID_SZ), 0);
  15152. ExpectIntEQ(wc_AesGcmInit(aesDec, NULL, 0, NULL, 0), 0);
  15153. /* Encrypt and decrypt data. */
  15154. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, aad, 1), 0);
  15155. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, aad, 1), 0);
  15156. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15157. /* Finalize and check tag matches. */
  15158. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15159. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15160. /* Set key and IV through streaming init API. */
  15161. wc_AesFree(aesEnc);
  15162. wc_AesFree(aesDec);
  15163. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15164. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15165. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15166. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15167. /* Encrypt/decrypt one block and AAD of one block. */
  15168. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, AES_BLOCK_SIZE, aad,
  15169. AES_BLOCK_SIZE), 0);
  15170. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, AES_BLOCK_SIZE, aad,
  15171. AES_BLOCK_SIZE), 0);
  15172. ExpectIntEQ(XMEMCMP(plain, in, AES_BLOCK_SIZE), 0);
  15173. /* Finalize and check tag matches. */
  15174. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15175. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15176. /* Set key and IV through streaming init API. */
  15177. wc_AesFree(aesEnc);
  15178. wc_AesFree(aesDec);
  15179. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15180. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15181. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15182. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15183. /* No data to encrypt/decrypt one byte of AAD. */
  15184. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1), 0);
  15185. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1), 0);
  15186. /* Finalize and check tag matches. */
  15187. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15188. ExpectIntEQ(XMEMCMP(tag, expTagAAD1, AES_BLOCK_SIZE), 0);
  15189. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15190. /* Set key and IV through streaming init API. */
  15191. wc_AesFree(aesEnc);
  15192. wc_AesFree(aesDec);
  15193. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15194. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15195. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15196. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15197. /* Encrypt/decrypt one byte and no AAD. */
  15198. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, NULL, 0), 0);
  15199. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, NULL, 0), 0);
  15200. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15201. /* Finalize and check tag matches. */
  15202. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15203. ExpectIntEQ(XMEMCMP(tag, expTagPlain1, AES_BLOCK_SIZE), 0);
  15204. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15205. /* Set key and IV through streaming init API. */
  15206. wc_AesFree(aesEnc);
  15207. wc_AesFree(aesDec);
  15208. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15209. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15210. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15211. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15212. /* Encryption AES is one byte at a time */
  15213. for (i = 0; i < (int)sizeof(aad); i++) {
  15214. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad + i, 1),
  15215. 0);
  15216. }
  15217. for (i = 0; i < (int)sizeof(in); i++) {
  15218. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out + i, in + i, 1, NULL, 0),
  15219. 0);
  15220. }
  15221. /* Decryption AES is two bytes at a time */
  15222. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15223. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad + i, 2),
  15224. 0);
  15225. }
  15226. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15227. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain + i, out + i, 2, NULL,
  15228. 0), 0);
  15229. }
  15230. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15231. /* Finalize and check tag matches. */
  15232. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15233. ExpectIntEQ(XMEMCMP(tag, expTag, AES_BLOCK_SIZE), 0);
  15234. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15235. /* Check streaming encryption can be decrypted with one shot. */
  15236. wc_AesFree(aesDec);
  15237. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15238. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15239. ExpectIntEQ(wc_AesGcmSetKey(aesDec, key, sizeof(key)), 0);
  15240. ExpectIntEQ(wc_AesGcmDecrypt(aesDec, plain, out, sizeof(in), iv,
  15241. AES_IV_SIZE, tag, AES_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15242. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15243. wc_AesFree(aesEnc);
  15244. wc_AesFree(aesDec);
  15245. wc_FreeRng(rng);
  15246. #endif
  15247. return EXPECT_RESULT();
  15248. } /* END test_wc_AesGcmStream */
  15249. /*
  15250. * Testing streaming SM4 API.
  15251. */
  15252. static int test_wc_Sm4(void)
  15253. {
  15254. int res = TEST_SKIPPED;
  15255. #ifdef WOLFSSL_SM4
  15256. EXPECT_DECLS;
  15257. wc_Sm4 sm4;
  15258. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15259. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15260. unsigned char key[SM4_KEY_SIZE];
  15261. #endif
  15262. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15263. unsigned char iv[SM4_IV_SIZE];
  15264. #endif
  15265. /* Invalid parameters - wc_Sm4Init */
  15266. ExpectIntEQ(wc_Sm4Init(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15267. /* Valid cases - wc_Sm4Init */
  15268. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15269. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15270. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15271. XMEMSET(key, 0, sizeof(key));
  15272. /* Invalid parameters - wc_Sm4SetKey. */
  15273. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15274. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15275. ExpectIntEQ(wc_Sm4SetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15276. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15277. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15278. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15279. ExpectIntEQ(wc_Sm4SetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15280. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE-1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15281. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE+1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15282. /* Valid cases - wc_Sm4SetKey. */
  15283. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15284. #endif
  15285. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15286. XMEMSET(iv, 0, sizeof(iv));
  15287. /* Invalid parameters - wc_Sm4SetIV. */
  15288. ExpectIntEQ(wc_Sm4SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15289. ExpectIntEQ(wc_Sm4SetIV(&sm4, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15290. ExpectIntEQ(wc_Sm4SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15291. /* Valid cases - wc_Sm4SetIV. */
  15292. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15293. #endif
  15294. /* Valid cases - wc_Sm4Free */
  15295. wc_Sm4Free(NULL);
  15296. wc_Sm4Free(&sm4);
  15297. res = EXPECT_RESULT();
  15298. #endif
  15299. return res;
  15300. } /* END test_wc_Sm4 */
  15301. /*
  15302. * Testing block based SM4-ECB API.
  15303. */
  15304. static int test_wc_Sm4Ecb(void)
  15305. {
  15306. int res = TEST_SKIPPED;
  15307. #ifdef WOLFSSL_SM4_ECB
  15308. EXPECT_DECLS;
  15309. wc_Sm4 sm4;
  15310. unsigned char key[SM4_KEY_SIZE];
  15311. unsigned char in[SM4_BLOCK_SIZE * 2];
  15312. unsigned char out[SM4_BLOCK_SIZE * 2];
  15313. unsigned char out2[SM4_BLOCK_SIZE];
  15314. XMEMSET(key, 0, sizeof(key));
  15315. XMEMSET(in, 0, sizeof(in));
  15316. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15317. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15318. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15319. /* Tested in test_wc_Sm4. */
  15320. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15321. /* Invalid parameters - wc_Sm4EcbEncrypt. */
  15322. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15323. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15324. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15325. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15326. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15327. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15328. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15329. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15330. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15331. /* Valid cases - wc_Sm4EcbEncrypt. */
  15332. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), 0);
  15333. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15334. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15335. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15336. /* In and out are same pointer. */
  15337. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15338. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15339. /* Invalid parameters - wc_Sm4EcbDecrypt. */
  15340. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15341. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15342. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15343. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15344. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15345. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15346. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15347. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15348. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15349. /* Valid cases - wc_Sm4EcbDecrypt. */
  15350. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), 0);
  15351. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15352. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15353. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15354. /* In and out are same pointer. */
  15355. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15356. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15357. wc_Sm4Free(&sm4);
  15358. res = EXPECT_RESULT();
  15359. #endif
  15360. return res;
  15361. } /* END test_wc_Sm4Ecb */
  15362. /*
  15363. * Testing block based SM4-CBC API.
  15364. */
  15365. static int test_wc_Sm4Cbc(void)
  15366. {
  15367. int res = TEST_SKIPPED;
  15368. #ifdef WOLFSSL_SM4_CBC
  15369. EXPECT_DECLS;
  15370. wc_Sm4 sm4;
  15371. unsigned char key[SM4_KEY_SIZE];
  15372. unsigned char iv[SM4_IV_SIZE];
  15373. unsigned char in[SM4_BLOCK_SIZE * 2];
  15374. unsigned char out[SM4_BLOCK_SIZE * 2];
  15375. unsigned char out2[SM4_BLOCK_SIZE];
  15376. XMEMSET(key, 0, sizeof(key));
  15377. XMEMSET(iv, 0, sizeof(iv));
  15378. XMEMSET(in, 0, sizeof(in));
  15379. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15380. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15381. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15382. /* Tested in test_wc_Sm4. */
  15383. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15384. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15385. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15386. /* Tested in test_wc_Sm4. */
  15387. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15388. /* Invalid parameters - wc_Sm4CbcEncrypt. */
  15389. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15390. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15391. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15392. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15393. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15394. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15395. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15396. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15397. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15398. /* Valid cases - wc_Sm4CbcEncrypt. */
  15399. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), 0);
  15400. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15401. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15402. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15403. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15404. /* In and out are same pointer. */
  15405. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15406. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15407. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15408. /* Invalid parameters - wc_Sm4CbcDecrypt. */
  15409. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15410. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15411. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15412. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15413. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15414. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15415. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15416. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15417. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15418. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15419. /* Valid cases - wc_Sm4CbcDecrypt. */
  15420. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), 0);
  15421. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15422. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15423. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15424. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15425. /* In and out are same pointer. */
  15426. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15427. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15428. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15429. wc_Sm4Free(&sm4);
  15430. res = EXPECT_RESULT();
  15431. #endif
  15432. return res;
  15433. } /* END test_wc_Sm4Cbc */
  15434. /*
  15435. * Testing streaming SM4-CTR API.
  15436. */
  15437. static int test_wc_Sm4Ctr(void)
  15438. {
  15439. int res = TEST_SKIPPED;
  15440. #ifdef WOLFSSL_SM4_CTR
  15441. EXPECT_DECLS;
  15442. wc_Sm4 sm4;
  15443. unsigned char key[SM4_KEY_SIZE];
  15444. unsigned char iv[SM4_IV_SIZE];
  15445. unsigned char in[SM4_BLOCK_SIZE * 4];
  15446. unsigned char out[SM4_BLOCK_SIZE * 4];
  15447. unsigned char out2[SM4_BLOCK_SIZE * 4];
  15448. word32 chunk;
  15449. word32 i;
  15450. XMEMSET(key, 0, sizeof(key));
  15451. XMEMSET(iv, 0, sizeof(iv));
  15452. XMEMSET(in, 0, sizeof(in));
  15453. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15454. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15455. /* Tested in test_wc_Sm4. */
  15456. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15457. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15458. /* Tested in test_wc_Sm4. */
  15459. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15460. /* Invalid parameters - wc_Sm4CtrEncrypt. */
  15461. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15462. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15463. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15464. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15465. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15466. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15467. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15468. /* Valid cases - wc_Sm4CtrEncrypt. */
  15469. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), 0);
  15470. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, 1), 0);
  15471. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15472. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 2), 0);
  15473. ExpectIntEQ(XMEMCMP(out, out2, 1), 0);
  15474. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15475. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15476. ExpectIntEQ(XMEMCMP(out2, out, 2), 0);
  15477. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15478. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15479. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15480. /* In and out are same pointer. Also check encrypt of cipher text produces
  15481. * plaintext.
  15482. */
  15483. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15484. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, out, SM4_BLOCK_SIZE * 2), 0);
  15485. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15486. /* Chunking tests. */
  15487. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15488. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, (word32)sizeof(in)), 0);
  15489. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15490. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15491. for (i = 0; i + chunk <= (word32)sizeof(in); i += chunk) {
  15492. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i, chunk), 0);
  15493. }
  15494. if (i < (word32)sizeof(in)) {
  15495. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i,
  15496. (word32)sizeof(in) - i), 0);
  15497. }
  15498. ExpectIntEQ(XMEMCMP(out, out2, (word32)sizeof(out)), 0);
  15499. }
  15500. for (i = 0; i < (word32)sizeof(iv); i++) {
  15501. iv[i] = 0xff;
  15502. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15503. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15504. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15505. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, out, SM4_BLOCK_SIZE * 2), 0);
  15506. ExpectIntEQ(XMEMCMP(out2, in, SM4_BLOCK_SIZE * 2), 0);
  15507. }
  15508. wc_Sm4Free(&sm4);
  15509. res = EXPECT_RESULT();
  15510. #endif
  15511. return res;
  15512. } /* END test_wc_Sm4Ctr */
  15513. /*
  15514. * Testing stream SM4-GCM API.
  15515. */
  15516. static int test_wc_Sm4Gcm(void)
  15517. {
  15518. int res = TEST_SKIPPED;
  15519. #ifdef WOLFSSL_SM4_GCM
  15520. EXPECT_DECLS;
  15521. wc_Sm4 sm4;
  15522. unsigned char key[SM4_KEY_SIZE];
  15523. unsigned char nonce[GCM_NONCE_MAX_SZ];
  15524. unsigned char in[SM4_BLOCK_SIZE * 2];
  15525. unsigned char in2[SM4_BLOCK_SIZE * 2];
  15526. unsigned char out[SM4_BLOCK_SIZE * 2];
  15527. unsigned char out2[SM4_BLOCK_SIZE * 2];
  15528. unsigned char dec[SM4_BLOCK_SIZE * 2];
  15529. unsigned char tag[SM4_BLOCK_SIZE];
  15530. unsigned char aad[SM4_BLOCK_SIZE * 2];
  15531. word32 i;
  15532. XMEMSET(key, 0, sizeof(key));
  15533. XMEMSET(nonce, 0, sizeof(nonce));
  15534. XMEMSET(in, 0, sizeof(in));
  15535. XMEMSET(in2, 0, sizeof(in2));
  15536. XMEMSET(aad, 0, sizeof(aad));
  15537. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15538. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15539. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15540. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15541. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15542. /* Invalid parameters - wc_Sm4GcmSetKey. */
  15543. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15544. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15545. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15546. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15547. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15548. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15549. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15550. /* Valid parameters - wc_Sm4GcmSetKey. */
  15551. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15552. /* Invalid parameters - wc_Sm4GcmEncrypt. */
  15553. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15554. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15555. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15556. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15557. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15558. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15559. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15560. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15561. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15562. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15563. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15564. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15565. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15566. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15567. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  15568. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15569. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15570. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15571. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  15572. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15573. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  15574. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15575. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  15576. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15577. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15578. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15579. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15580. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15581. /* Invalid parameters - wc_Sm4GcmDecrypt. */
  15582. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15583. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15584. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15585. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15586. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15587. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15588. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15589. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15590. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15591. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15592. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15593. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15594. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15595. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15596. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  15597. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15598. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15599. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15600. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  15601. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15602. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  15603. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15604. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  15605. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15606. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15607. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15608. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15609. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15610. /* Valid cases - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  15611. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15612. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15613. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15614. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15615. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15616. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15617. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15618. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15619. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15620. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15621. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15622. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15623. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15624. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  15625. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15626. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  15627. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  15628. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15629. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  15630. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15631. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  15632. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15633. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  15634. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  15635. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15636. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  15637. /* Check vald values of nonce - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  15638. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15639. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15640. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15641. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15642. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  15643. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15644. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  15645. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15646. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  15647. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  15648. WC_NO_ERR_TRACE(SM4_GCM_AUTH_E));
  15649. /* Check valid values of tag size - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  15650. for (i = WOLFSSL_MIN_AUTH_TAG_SZ; i < SM4_BLOCK_SIZE; i++) {
  15651. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15652. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  15653. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15654. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  15655. }
  15656. /* Check different in/out sizes. */
  15657. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce,
  15658. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15659. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce,
  15660. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15661. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce,
  15662. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15663. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  15664. XMEMCPY(out2, out, i - 1);
  15665. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, i, nonce, GCM_NONCE_MID_SZ,
  15666. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15667. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  15668. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, dec, out, i, nonce, GCM_NONCE_MID_SZ,
  15669. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15670. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  15671. }
  15672. /* Force the counter to roll over in first byte. */
  15673. {
  15674. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  15675. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  15676. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  15677. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15678. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  15679. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15680. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  15681. }
  15682. wc_Sm4Free(&sm4);
  15683. res = EXPECT_RESULT();
  15684. #endif
  15685. return res;
  15686. } /* END test_wc_Sm4Gcm */
  15687. /*
  15688. * Testing stream SM4-CCM API.
  15689. */
  15690. static int test_wc_Sm4Ccm(void)
  15691. {
  15692. int res = TEST_SKIPPED;
  15693. #ifdef WOLFSSL_SM4_CCM
  15694. EXPECT_DECLS;
  15695. wc_Sm4 sm4;
  15696. unsigned char key[SM4_KEY_SIZE];
  15697. unsigned char nonce[CCM_NONCE_MAX_SZ];
  15698. unsigned char in[SM4_BLOCK_SIZE * 2];
  15699. unsigned char in2[SM4_BLOCK_SIZE * 2];
  15700. unsigned char out[SM4_BLOCK_SIZE * 2];
  15701. unsigned char out2[SM4_BLOCK_SIZE * 2];
  15702. unsigned char dec[SM4_BLOCK_SIZE * 2];
  15703. unsigned char tag[SM4_BLOCK_SIZE];
  15704. unsigned char aad[SM4_BLOCK_SIZE * 2];
  15705. word32 i;
  15706. XMEMSET(key, 0, sizeof(key));
  15707. XMEMSET(nonce, 0, sizeof(nonce));
  15708. XMEMSET(in, 0, sizeof(in));
  15709. XMEMSET(in2, 0, sizeof(in2));
  15710. XMEMSET(aad, 0, sizeof(aad));
  15711. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15712. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  15713. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15714. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  15715. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15716. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15717. /* Invalid parameters - wc_Sm4CcmEncrypt. */
  15718. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15719. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15720. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15721. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15722. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15723. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15724. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15725. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15726. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15727. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15728. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15729. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15730. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15731. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15732. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15733. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15734. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15735. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15736. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  15737. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15738. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  15739. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15740. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15741. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15742. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15743. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15744. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15745. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15746. /* Invalid parameters - wc_Sm4CcmDecrypt. */
  15747. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15748. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15749. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15750. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15751. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15752. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15753. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15754. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15755. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15756. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15757. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15758. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15759. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15760. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15761. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15762. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15763. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15764. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15765. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  15766. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15767. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  15768. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15769. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15770. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15771. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15772. WOLFSSL_MIN_AUTH_TAG_SZ - 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15773. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15774. SM4_BLOCK_SIZE + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15775. /* Valid cases - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  15776. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  15777. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15778. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  15779. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15780. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  15781. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15782. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  15783. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15784. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15785. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15786. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15787. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15788. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15789. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  15790. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15791. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  15792. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  15793. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15794. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  15795. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15796. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  15797. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15798. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  15799. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  15800. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15801. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  15802. /* Check vald values of nonce - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  15803. for (i = CCM_NONCE_MIN_SZ; i <= CCM_NONCE_MAX_SZ; i++) {
  15804. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15805. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15806. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15807. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15808. }
  15809. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15810. CCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  15811. WC_NO_ERR_TRACE(SM4_CCM_AUTH_E));
  15812. /* Check invalid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  15813. for (i = 0; i < 4; i++) {
  15814. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15815. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15816. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15817. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15818. }
  15819. /* Odd values in range 4..SM4_BLOCK_SIZE. */
  15820. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  15821. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15822. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15823. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15824. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15825. }
  15826. /* Check valid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt.
  15827. * Even values in range 4..SM4_BLOCK_SIZE.
  15828. */
  15829. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  15830. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15831. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  15832. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15833. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  15834. }
  15835. /* Check different in/out sizes. */
  15836. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce,
  15837. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15838. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce,
  15839. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15840. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce,
  15841. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15842. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  15843. XMEMCPY(out2, out, i - 1);
  15844. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, i, nonce, CCM_NONCE_MAX_SZ,
  15845. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15846. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  15847. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, dec, out, i, nonce, CCM_NONCE_MAX_SZ,
  15848. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15849. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  15850. }
  15851. /* Force the counter to roll over in first byte. */
  15852. {
  15853. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  15854. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  15855. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  15856. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15857. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  15858. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15859. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  15860. }
  15861. wc_Sm4Free(&sm4);
  15862. res = EXPECT_RESULT();
  15863. #endif
  15864. return res;
  15865. } /* END test_wc_Sm4Ccm */
  15866. /*
  15867. * unit test for wc_Des3_SetIV()
  15868. */
  15869. static int test_wc_Des3_SetIV(void)
  15870. {
  15871. EXPECT_DECLS;
  15872. #ifndef NO_DES3
  15873. Des3 des;
  15874. const byte key[] = {
  15875. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  15876. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  15877. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  15878. };
  15879. const byte iv[] = {
  15880. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  15881. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  15882. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  15883. };
  15884. XMEMSET(&des, 0, sizeof(Des3));
  15885. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  15886. /* DES_ENCRYPTION or DES_DECRYPTION */
  15887. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  15888. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  15889. #ifndef HAVE_FIPS /* no sanity checks with FIPS wrapper */
  15890. /* Test explicitly wc_Des3_SetIV() */
  15891. ExpectIntEQ(wc_Des3_SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15892. ExpectIntEQ(wc_Des3_SetIV(&des, NULL), 0);
  15893. #endif
  15894. wc_Des3Free(&des);
  15895. #endif
  15896. return EXPECT_RESULT();
  15897. } /* END test_wc_Des3_SetIV */
  15898. /*
  15899. * unit test for wc_Des3_SetKey()
  15900. */
  15901. static int test_wc_Des3_SetKey(void)
  15902. {
  15903. EXPECT_DECLS;
  15904. #ifndef NO_DES3
  15905. Des3 des;
  15906. const byte key[] = {
  15907. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  15908. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  15909. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  15910. };
  15911. const byte iv[] = {
  15912. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  15913. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  15914. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  15915. };
  15916. XMEMSET(&des, 0, sizeof(Des3));
  15917. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  15918. /* DES_ENCRYPTION or DES_DECRYPTION */
  15919. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  15920. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  15921. /* Test bad args. */
  15922. ExpectIntEQ(wc_Des3_SetKey(NULL, key, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15923. ExpectIntEQ(wc_Des3_SetKey(&des, NULL, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15924. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15925. /* Default case. Should return 0. */
  15926. ExpectIntEQ(wc_Des3_SetKey(&des, key, NULL, DES_ENCRYPTION), 0);
  15927. wc_Des3Free(&des);
  15928. #endif
  15929. return EXPECT_RESULT();
  15930. } /* END test_wc_Des3_SetKey */
  15931. /*
  15932. * Test function for wc_Des3_CbcEncrypt and wc_Des3_CbcDecrypt
  15933. */
  15934. static int test_wc_Des3_CbcEncryptDecrypt(void)
  15935. {
  15936. EXPECT_DECLS;
  15937. #ifndef NO_DES3
  15938. Des3 des;
  15939. byte cipher[24];
  15940. byte plain[24];
  15941. const byte key[] = {
  15942. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  15943. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  15944. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  15945. };
  15946. const byte iv[] = {
  15947. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  15948. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  15949. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  15950. };
  15951. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  15952. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  15953. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  15954. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  15955. };
  15956. XMEMSET(&des, 0, sizeof(Des3));
  15957. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  15958. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  15959. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, vector, 24), 0);
  15960. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_DECRYPTION), 0);
  15961. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, cipher, 24), 0);
  15962. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  15963. /* Pass in bad args. */
  15964. ExpectIntEQ(wc_Des3_CbcEncrypt(NULL, cipher, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15965. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, NULL, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15966. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, NULL, sizeof(vector)),
  15967. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15968. ExpectIntEQ(wc_Des3_CbcDecrypt(NULL, plain, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15969. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, NULL, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15970. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, NULL, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15971. wc_Des3Free(&des);
  15972. #endif
  15973. return EXPECT_RESULT();
  15974. } /* END wc_Des3_CbcEncrypt */
  15975. /*
  15976. * Unit test for wc_Des3_CbcEncryptWithKey and wc_Des3_CbcDecryptWithKey
  15977. */
  15978. static int test_wc_Des3_CbcEncryptDecryptWithKey(void)
  15979. {
  15980. EXPECT_DECLS;
  15981. #ifndef NO_DES3
  15982. word32 vectorSz, cipherSz;
  15983. byte cipher[24];
  15984. byte plain[24];
  15985. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  15986. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  15987. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  15988. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  15989. };
  15990. byte key[] = {
  15991. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  15992. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  15993. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  15994. };
  15995. byte iv[] = {
  15996. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  15997. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  15998. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  15999. };
  16000. vectorSz = sizeof(byte) * 24;
  16001. cipherSz = sizeof(byte) * 24;
  16002. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, iv),
  16003. 0);
  16004. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, iv), 0);
  16005. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16006. /* pass in bad args. */
  16007. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(NULL, vector, vectorSz, key, iv),
  16008. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16009. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, NULL, vectorSz, key, iv),
  16010. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16011. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, NULL, iv),
  16012. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16013. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, NULL),
  16014. 0);
  16015. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(NULL, cipher, cipherSz, key, iv),
  16016. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16017. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, NULL, cipherSz, key, iv),
  16018. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16019. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, NULL, iv),
  16020. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16021. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, NULL),
  16022. 0);
  16023. #endif
  16024. return EXPECT_RESULT();
  16025. } /* END test_wc_Des3_CbcEncryptDecryptWithKey */
  16026. /*
  16027. * Unit test for wc_Des3_EcbEncrypt
  16028. */
  16029. static int test_wc_Des3_EcbEncrypt(void)
  16030. {
  16031. EXPECT_DECLS;
  16032. #if !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  16033. Des3 des;
  16034. byte cipher[24];
  16035. word32 cipherSz = sizeof(cipher);
  16036. const byte key[] = {
  16037. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16038. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16039. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16040. };
  16041. const byte iv[] = {
  16042. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16043. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16044. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16045. };
  16046. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16047. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16048. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16049. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16050. };
  16051. XMEMSET(&des, 0, sizeof(Des3));
  16052. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16053. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16054. /* Bad Cases */
  16055. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16056. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, cipher, vector, cipherSz),
  16057. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16058. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, 0, vector, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16059. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, NULL, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16060. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, 0), 0);
  16061. /* Good Cases */
  16062. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, cipherSz), 0);
  16063. wc_Des3Free(&des);
  16064. #endif
  16065. return EXPECT_RESULT();
  16066. } /* END test_wc_Des3_EcbEncrypt */
  16067. /*
  16068. * Testing wc_Chacha_SetKey() and wc_Chacha_SetIV()
  16069. */
  16070. static int test_wc_Chacha_SetKey(void)
  16071. {
  16072. EXPECT_DECLS;
  16073. #ifdef HAVE_CHACHA
  16074. ChaCha ctx;
  16075. const byte key[] = {
  16076. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16077. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16078. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16079. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16080. };
  16081. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16082. byte cipher[128];
  16083. XMEMSET(cipher, 0, sizeof(cipher));
  16084. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, keySz), 0);
  16085. /* Test bad args. */
  16086. ExpectIntEQ(wc_Chacha_SetKey(NULL, key, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16087. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16088. ExpectIntEQ(wc_Chacha_SetIV(&ctx, cipher, 0), 0);
  16089. /* Test bad args. */
  16090. ExpectIntEQ(wc_Chacha_SetIV(NULL, cipher, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16091. #endif
  16092. return EXPECT_RESULT();
  16093. } /* END test_wc_Chacha_SetKey */
  16094. /*
  16095. * unit test for wc_Poly1305SetKey()
  16096. */
  16097. static int test_wc_Poly1305SetKey(void)
  16098. {
  16099. EXPECT_DECLS;
  16100. #ifdef HAVE_POLY1305
  16101. Poly1305 ctx;
  16102. const byte key[] =
  16103. {
  16104. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16105. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16106. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16107. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16108. };
  16109. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16110. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, keySz), 0);
  16111. /* Test bad args. */
  16112. ExpectIntEQ(wc_Poly1305SetKey(NULL, key,keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16113. ExpectIntEQ(wc_Poly1305SetKey(&ctx, NULL, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16114. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16115. #endif
  16116. return EXPECT_RESULT();
  16117. } /* END test_wc_Poly1305_SetKey() */
  16118. /*
  16119. * Testing wc_Chacha_Process()
  16120. */
  16121. static int test_wc_Chacha_Process(void)
  16122. {
  16123. EXPECT_DECLS;
  16124. #ifdef HAVE_CHACHA
  16125. ChaCha enc, dec;
  16126. byte cipher[128];
  16127. byte plain[128];
  16128. const byte key[] =
  16129. {
  16130. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16131. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16132. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16133. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16134. };
  16135. const char* input = "Everybody gets Friday off.";
  16136. word32 keySz = sizeof(key)/sizeof(byte);
  16137. unsigned long int inlen = XSTRLEN(input);
  16138. /* Initialize stack variables. */
  16139. XMEMSET(cipher, 0, 128);
  16140. XMEMSET(plain, 0, 128);
  16141. ExpectIntEQ(wc_Chacha_SetKey(&enc, key, keySz), 0);
  16142. ExpectIntEQ(wc_Chacha_SetKey(&dec, key, keySz), 0);
  16143. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16144. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16145. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen),
  16146. 0);
  16147. ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (word32)inlen), 0);
  16148. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16149. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  16150. /* test checking and using leftovers, currently just in C code */
  16151. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16152. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16153. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input,
  16154. (word32)inlen - 2), 0);
  16155. ExpectIntEQ(wc_Chacha_Process(&enc, cipher + (inlen - 2),
  16156. (byte*)input + (inlen - 2), 2), 0);
  16157. ExpectIntEQ(wc_Chacha_Process(&dec, plain, (byte*)cipher,
  16158. (word32)inlen - 2), 0);
  16159. ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2),
  16160. (byte*)input + (inlen - 2), 2), 0);
  16161. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16162. /* check edge cases with counter increment */
  16163. {
  16164. /* expected results collected from wolfSSL 4.3.0 encrypted in one call*/
  16165. const byte expected[] = {
  16166. 0x54,0xB1,0xE2,0xD4,0xA2,0x4D,0x52,0x5F,
  16167. 0x42,0x04,0x89,0x7C,0x6E,0x2D,0xFC,0x2D,
  16168. 0x10,0x25,0xB6,0x92,0x71,0xD5,0xC3,0x20,
  16169. 0xE3,0x0E,0xEC,0xF4,0xD8,0x10,0x70,0x29,
  16170. 0x2D,0x4C,0x2A,0x56,0x21,0xE1,0xC7,0x37,
  16171. 0x0B,0x86,0xF5,0x02,0x8C,0xB8,0xB8,0x38,
  16172. 0x41,0xFD,0xDF,0xD9,0xC3,0xE6,0xC8,0x88,
  16173. 0x06,0x82,0xD4,0x80,0x6A,0x50,0x69,0xD5,
  16174. 0xB9,0xB0,0x2F,0x44,0x36,0x5D,0xDA,0x5E,
  16175. 0xDE,0xF6,0xF5,0xFC,0x44,0xDC,0x07,0x51,
  16176. 0xA7,0x32,0x42,0xDB,0xCC,0xBD,0xE2,0xE5,
  16177. 0x0B,0xB1,0x14,0xFF,0x12,0x80,0x16,0x43,
  16178. 0xE7,0x40,0xD5,0xEA,0xC7,0x3F,0x69,0x07,
  16179. 0x64,0xD4,0x86,0x6C,0xE2,0x1F,0x8F,0x6E,
  16180. 0x35,0x41,0xE7,0xD3,0xB5,0x5D,0xD6,0xD4,
  16181. 0x9F,0x00,0xA9,0xAE,0x3D,0x28,0xA5,0x37,
  16182. 0x80,0x3D,0x11,0x25,0xE2,0xB6,0x99,0xD9,
  16183. 0x9B,0x98,0xE9,0x37,0xB9,0xF8,0xA0,0x04,
  16184. 0xDF,0x13,0x49,0x3F,0x19,0x6A,0x45,0x06,
  16185. 0x21,0xB4,0xC7,0x3B,0x49,0x45,0xB4,0xC8,
  16186. 0x03,0x5B,0x43,0x89,0xBD,0xB3,0x96,0x4B,
  16187. 0x17,0x6F,0x85,0xC6,0xCF,0xA6,0x05,0x35,
  16188. 0x1E,0x25,0x03,0xBB,0x55,0x0A,0xD5,0x54,
  16189. 0x41,0xEA,0xEB,0x50,0x40,0x1B,0x43,0x19,
  16190. 0x59,0x1B,0x0E,0x12,0x3E,0xA2,0x71,0xC3,
  16191. 0x1A,0xA7,0x11,0x50,0x43,0x9D,0x56,0x3B,
  16192. 0x63,0x2F,0x63,0xF1,0x8D,0xAE,0xF3,0x23,
  16193. 0xFA,0x1E,0xD8,0x6A,0xE1,0xB2,0x4B,0xF3,
  16194. 0xB9,0x13,0x7A,0x72,0x2B,0x6D,0xCC,0x41,
  16195. 0x1C,0x69,0x7C,0xCD,0x43,0x6F,0xE4,0xE2,
  16196. 0x38,0x99,0xFB,0xC3,0x38,0x92,0x62,0x35,
  16197. 0xC0,0x1D,0x60,0xE4,0x4B,0xDD,0x0C,0x14
  16198. };
  16199. const byte iv2[] = {
  16200. 0x9D,0xED,0xE7,0x0F,0xEC,0x81,0x51,0xD9,
  16201. 0x77,0x39,0x71,0xA6,0x21,0xDF,0xB8,0x93
  16202. };
  16203. byte input2[256];
  16204. int i;
  16205. for (i = 0; i < 256; i++)
  16206. input2[i] = i;
  16207. ExpectIntEQ(wc_Chacha_SetIV(&enc, iv2, 0), 0);
  16208. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2, 64), 0);
  16209. ExpectIntEQ(XMEMCMP(expected, cipher, 64), 0);
  16210. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 64, 128), 0);
  16211. ExpectIntEQ(XMEMCMP(expected + 64, cipher, 128), 0);
  16212. /* partial */
  16213. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 192, 32), 0);
  16214. ExpectIntEQ(XMEMCMP(expected + 192, cipher, 32), 0);
  16215. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 224, 32), 0);
  16216. ExpectIntEQ(XMEMCMP(expected + 224, cipher, 32), 0);
  16217. }
  16218. #endif
  16219. /* Test bad args. */
  16220. ExpectIntEQ(wc_Chacha_Process(NULL, cipher, (byte*)input, (word32)inlen),
  16221. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16222. #endif
  16223. return EXPECT_RESULT();
  16224. } /* END test_wc_Chacha_Process */
  16225. /*
  16226. * Testing wc_ChaCha20Poly1305_Encrypt() and wc_ChaCha20Poly1305_Decrypt()
  16227. */
  16228. static int test_wc_ChaCha20Poly1305_aead(void)
  16229. {
  16230. EXPECT_DECLS;
  16231. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  16232. const byte key[] = {
  16233. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  16234. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  16235. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  16236. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  16237. };
  16238. const byte plaintext[] = {
  16239. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  16240. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  16241. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  16242. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  16243. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  16244. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  16245. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  16246. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  16247. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  16248. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  16249. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  16250. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  16251. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  16252. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  16253. 0x74, 0x2e
  16254. };
  16255. const byte iv[] = {
  16256. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  16257. 0x44, 0x45, 0x46, 0x47
  16258. };
  16259. const byte aad[] = { /* additional data */
  16260. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  16261. 0xc4, 0xc5, 0xc6, 0xc7
  16262. };
  16263. const byte cipher[] = { /* expected output from operation */
  16264. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  16265. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  16266. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  16267. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  16268. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  16269. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  16270. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  16271. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  16272. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  16273. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  16274. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  16275. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  16276. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  16277. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  16278. 0x61, 0x16
  16279. };
  16280. const byte authTag[] = { /* expected output from operation */
  16281. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  16282. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  16283. };
  16284. byte generatedCiphertext[272];
  16285. byte generatedPlaintext[272];
  16286. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  16287. /* Initialize stack variables. */
  16288. XMEMSET(generatedCiphertext, 0, 272);
  16289. XMEMSET(generatedPlaintext, 0, 272);
  16290. /* Test Encrypt */
  16291. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16292. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16293. 0);
  16294. ExpectIntEQ(XMEMCMP(generatedCiphertext, cipher,
  16295. sizeof(cipher)/sizeof(byte)), 0);
  16296. /* Test bad args. */
  16297. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(NULL, iv, aad, sizeof(aad),
  16298. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16299. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16300. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, NULL, aad, sizeof(aad),
  16301. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16302. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16303. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad), NULL,
  16304. sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16305. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16306. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16307. NULL, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16308. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16309. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16310. plaintext, sizeof(plaintext), NULL, generatedAuthTag), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16311. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16312. plaintext, sizeof(plaintext), generatedCiphertext, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16313. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16314. sizeof(cipher), authTag, generatedPlaintext), 0);
  16315. ExpectIntEQ(XMEMCMP(generatedPlaintext, plaintext,
  16316. sizeof(plaintext)/sizeof(byte)), 0);
  16317. /* Test bad args. */
  16318. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(NULL, iv, aad, sizeof(aad), cipher,
  16319. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16320. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, NULL, aad, sizeof(aad),
  16321. cipher, sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16322. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16323. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16324. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16325. sizeof(cipher), NULL, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16326. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16327. sizeof(cipher), authTag, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16328. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16329. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16330. #endif
  16331. return EXPECT_RESULT();
  16332. } /* END test_wc_ChaCha20Poly1305_aead */
  16333. /*
  16334. * Testing function for wc_Rc2SetKey().
  16335. */
  16336. static int test_wc_Rc2SetKey(void)
  16337. {
  16338. EXPECT_DECLS;
  16339. #ifdef WC_RC2
  16340. Rc2 rc2;
  16341. byte key40[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  16342. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16343. /* valid key and IV */
  16344. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16345. iv, 40), 0);
  16346. /* valid key, no IV */
  16347. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16348. NULL, 40), 0);
  16349. /* bad arguments */
  16350. /* null Rc2 struct */
  16351. ExpectIntEQ(wc_Rc2SetKey(NULL, key40, (word32) sizeof(key40) / sizeof(byte),
  16352. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16353. /* null key */
  16354. ExpectIntEQ(wc_Rc2SetKey(&rc2, NULL, (word32) sizeof(key40) / sizeof(byte),
  16355. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16356. /* key size == 0 */
  16357. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 0, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16358. /* key size > 128 */
  16359. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 129, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16360. /* effective bits == 0 */
  16361. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16362. iv, 0), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16363. /* effective bits > 1024 */
  16364. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16365. iv, 1025), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16366. #endif
  16367. return EXPECT_RESULT();
  16368. } /* END test_wc_Rc2SetKey */
  16369. /*
  16370. * Testing function for wc_Rc2SetIV().
  16371. */
  16372. static int test_wc_Rc2SetIV(void)
  16373. {
  16374. EXPECT_DECLS;
  16375. #ifdef WC_RC2
  16376. Rc2 rc2;
  16377. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16378. /* valid IV */
  16379. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16380. /* valid NULL IV */
  16381. ExpectIntEQ(wc_Rc2SetIV(&rc2, NULL), 0);
  16382. /* bad arguments */
  16383. ExpectIntEQ(wc_Rc2SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16384. ExpectIntEQ(wc_Rc2SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16385. #endif
  16386. return EXPECT_RESULT();
  16387. } /* END test_wc_Rc2SetIV */
  16388. /*
  16389. * Testing function for wc_Rc2EcbEncrypt() and wc_Rc2EcbDecrypt().
  16390. */
  16391. static int test_wc_Rc2EcbEncryptDecrypt(void)
  16392. {
  16393. EXPECT_DECLS;
  16394. #ifdef WC_RC2
  16395. Rc2 rc2;
  16396. int effectiveKeyBits = 63;
  16397. byte cipher[RC2_BLOCK_SIZE];
  16398. byte plain[RC2_BLOCK_SIZE];
  16399. byte key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16400. byte input[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16401. byte output[] = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };
  16402. XMEMSET(cipher, 0, sizeof(cipher));
  16403. XMEMSET(plain, 0, sizeof(plain));
  16404. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16405. NULL, effectiveKeyBits), 0);
  16406. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, RC2_BLOCK_SIZE), 0);
  16407. ExpectIntEQ(XMEMCMP(cipher, output, RC2_BLOCK_SIZE), 0);
  16408. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, cipher, RC2_BLOCK_SIZE), 0);
  16409. ExpectIntEQ(XMEMCMP(plain, input, RC2_BLOCK_SIZE), 0);
  16410. /* Rc2EcbEncrypt bad arguments */
  16411. /* null Rc2 struct */
  16412. ExpectIntEQ(wc_Rc2EcbEncrypt(NULL, cipher, input, RC2_BLOCK_SIZE),
  16413. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16414. /* null out buffer */
  16415. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, NULL, input, RC2_BLOCK_SIZE),
  16416. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16417. /* null input buffer */
  16418. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, NULL, RC2_BLOCK_SIZE),
  16419. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16420. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16421. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16422. /* Rc2EcbDecrypt bad arguments */
  16423. /* null Rc2 struct */
  16424. ExpectIntEQ(wc_Rc2EcbDecrypt(NULL, plain, output, RC2_BLOCK_SIZE),
  16425. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16426. /* null out buffer */
  16427. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, NULL, output, RC2_BLOCK_SIZE),
  16428. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16429. /* null input buffer */
  16430. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, NULL, RC2_BLOCK_SIZE),
  16431. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16432. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16433. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, output, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16434. #endif
  16435. return EXPECT_RESULT();
  16436. } /* END test_wc_Rc2EcbEncryptDecrypt */
  16437. /*
  16438. * Testing function for wc_Rc2CbcEncrypt() and wc_Rc2CbcDecrypt().
  16439. */
  16440. static int test_wc_Rc2CbcEncryptDecrypt(void)
  16441. {
  16442. EXPECT_DECLS;
  16443. #ifdef WC_RC2
  16444. Rc2 rc2;
  16445. int effectiveKeyBits = 63;
  16446. byte cipher[RC2_BLOCK_SIZE*2];
  16447. byte plain[RC2_BLOCK_SIZE*2];
  16448. /* vector taken from test.c */
  16449. byte key[] = {
  16450. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16451. };
  16452. byte iv[] = {
  16453. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16454. };
  16455. byte input[] = {
  16456. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  16457. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16458. };
  16459. byte output[] = {
  16460. 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
  16461. 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57
  16462. };
  16463. XMEMSET(cipher, 0, sizeof(cipher));
  16464. XMEMSET(plain, 0, sizeof(plain));
  16465. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16466. iv, effectiveKeyBits), 0);
  16467. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, input, sizeof(input)), 0);
  16468. ExpectIntEQ(XMEMCMP(cipher, output, sizeof(output)), 0);
  16469. /* reset IV for decrypt */
  16470. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16471. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, cipher, sizeof(cipher)), 0);
  16472. ExpectIntEQ(XMEMCMP(plain, input, sizeof(input)), 0);
  16473. /* Rc2CbcEncrypt bad arguments */
  16474. /* null Rc2 struct */
  16475. ExpectIntEQ(wc_Rc2CbcEncrypt(NULL, cipher, input, sizeof(input)),
  16476. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16477. /* null out buffer */
  16478. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, NULL, input, sizeof(input)),
  16479. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16480. /* null input buffer */
  16481. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, NULL, sizeof(input)),
  16482. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16483. /* Rc2CbcDecrypt bad arguments */
  16484. /* in size is 0 */
  16485. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, output, 0), 0);
  16486. /* null Rc2 struct */
  16487. ExpectIntEQ(wc_Rc2CbcDecrypt(NULL, plain, output, sizeof(output)),
  16488. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16489. /* null out buffer */
  16490. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, NULL, output, sizeof(output)),
  16491. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16492. /* null input buffer */
  16493. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, NULL, sizeof(output)),
  16494. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16495. #endif
  16496. return EXPECT_RESULT();
  16497. } /* END test_wc_Rc2CbcEncryptDecrypt */
  16498. /*
  16499. * Testing function for wc_AesSetIV
  16500. */
  16501. static int test_wc_AesSetIV(void)
  16502. {
  16503. int res = TEST_SKIPPED;
  16504. #if !defined(NO_AES) && defined(WOLFSSL_AES_128)
  16505. Aes aes;
  16506. int ret = 0;
  16507. byte key16[] =
  16508. {
  16509. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16510. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16511. };
  16512. byte iv1[] = "1234567890abcdef";
  16513. byte iv2[] = "0987654321fedcba";
  16514. ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
  16515. if (ret != 0)
  16516. return ret;
  16517. ret = wc_AesSetKey(&aes, key16, (word32) sizeof(key16) / sizeof(byte),
  16518. iv1, AES_ENCRYPTION);
  16519. if (ret == 0) {
  16520. ret = wc_AesSetIV(&aes, iv2);
  16521. }
  16522. /* Test bad args. */
  16523. if (ret == 0) {
  16524. ret = wc_AesSetIV(NULL, iv1);
  16525. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  16526. /* NULL iv should return 0. */
  16527. ret = wc_AesSetIV(&aes, NULL);
  16528. }
  16529. else {
  16530. ret = WOLFSSL_FATAL_ERROR;
  16531. }
  16532. }
  16533. wc_AesFree(&aes);
  16534. res = TEST_RES_CHECK(ret == 0);
  16535. #endif
  16536. return res;
  16537. } /* test_wc_AesSetIV */
  16538. /*
  16539. * Testing function for wc_AesSetKey().
  16540. */
  16541. static int test_wc_AesSetKey(void)
  16542. {
  16543. EXPECT_DECLS;
  16544. #ifndef NO_AES
  16545. Aes aes;
  16546. byte key16[] = {
  16547. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16548. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16549. };
  16550. #ifdef WOLFSSL_AES_192
  16551. byte key24[] = {
  16552. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16553. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16554. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  16555. };
  16556. #endif
  16557. #ifdef WOLFSSL_AES_256
  16558. byte key32[] = {
  16559. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16560. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16561. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16562. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16563. };
  16564. #endif
  16565. byte badKey16[] = {
  16566. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16567. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  16568. };
  16569. byte iv[] = "1234567890abcdef";
  16570. XMEMSET(&aes, 0, sizeof(Aes));
  16571. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  16572. #ifdef WOLFSSL_AES_128
  16573. ExpectIntEQ(wc_AesSetKey(&aes, key16, (word32)sizeof(key16) / sizeof(byte),
  16574. iv, AES_ENCRYPTION), 0);
  16575. #endif
  16576. #ifdef WOLFSSL_AES_192
  16577. ExpectIntEQ(wc_AesSetKey(&aes, key24, (word32)sizeof(key24) / sizeof(byte),
  16578. iv, AES_ENCRYPTION), 0);
  16579. #endif
  16580. #ifdef WOLFSSL_AES_256
  16581. ExpectIntEQ(wc_AesSetKey(&aes, key32, (word32)sizeof(key32) / sizeof(byte),
  16582. iv, AES_ENCRYPTION), 0);
  16583. #endif
  16584. /* Pass in bad args. */
  16585. ExpectIntEQ(wc_AesSetKey(NULL, key16, (word32)sizeof(key16) / sizeof(byte),
  16586. iv, AES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16587. ExpectIntEQ(wc_AesSetKey(&aes, badKey16,
  16588. (word32)sizeof(badKey16) / sizeof(byte), iv, AES_ENCRYPTION),
  16589. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16590. wc_AesFree(&aes);
  16591. #endif
  16592. return EXPECT_RESULT();
  16593. } /* END test_wc_AesSetKey */
  16594. /*
  16595. * test function for wc_AesCbcEncrypt(), wc_AesCbcDecrypt(),
  16596. * and wc_AesCbcDecryptWithKey()
  16597. */
  16598. static int test_wc_AesCbcEncryptDecrypt(void)
  16599. {
  16600. EXPECT_DECLS;
  16601. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT)&& \
  16602. defined(WOLFSSL_AES_256)
  16603. Aes aes;
  16604. byte key32[] = {
  16605. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16606. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16607. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16608. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16609. };
  16610. byte vector[] = { /* Now is the time for all good men w/o trailing 0 */
  16611. 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  16612. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
  16613. 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
  16614. 0x67, 0x6f, 0x6f, 0x64, 0x20, 0x6d, 0x65, 0x6e
  16615. };
  16616. byte iv[] = "1234567890abcdef";
  16617. byte enc[sizeof(vector)];
  16618. byte dec[sizeof(vector)];
  16619. byte dec2[sizeof(vector)];
  16620. /* Init stack variables. */
  16621. XMEMSET(&aes, 0, sizeof(Aes));
  16622. XMEMSET(enc, 0, sizeof(enc));
  16623. XMEMSET(dec, 0, sizeof(vector));
  16624. XMEMSET(dec2, 0, sizeof(vector));
  16625. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  16626. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  16627. AES_ENCRYPTION), 0);
  16628. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector)), 0);
  16629. /* Re init for decrypt and set flag. */
  16630. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  16631. AES_DECRYPTION), 0);
  16632. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, sizeof(vector)), 0);
  16633. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  16634. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE, key32,
  16635. sizeof(key32)/sizeof(byte), iv), 0);
  16636. ExpectIntEQ(XMEMCMP(vector, dec2, AES_BLOCK_SIZE), 0);
  16637. /* Pass in bad args */
  16638. ExpectIntEQ(wc_AesCbcEncrypt(NULL, enc, vector, sizeof(vector)),
  16639. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16640. ExpectIntEQ(wc_AesCbcEncrypt(&aes, NULL, vector, sizeof(vector)),
  16641. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16642. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, NULL, sizeof(vector)),
  16643. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16644. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  16645. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector) - 1),
  16646. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  16647. #endif
  16648. #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  16649. (HAVE_FIPS_VERSION == 2) && defined(WOLFSSL_AESNI)
  16650. fprintf(stderr, "Zero length inputs not supported with AESNI in FIPS "
  16651. "mode (v2), skip test");
  16652. #else
  16653. /* Test passing in size of 0 */
  16654. XMEMSET(enc, 0, sizeof(enc));
  16655. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, 0), 0);
  16656. /* Check enc was not modified */
  16657. {
  16658. int i;
  16659. for (i = 0; i < (int)sizeof(enc); i++)
  16660. ExpectIntEQ(enc[i], 0);
  16661. }
  16662. #endif
  16663. ExpectIntEQ(wc_AesCbcDecrypt(NULL, dec, enc, AES_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16664. ExpectIntEQ(wc_AesCbcDecrypt(&aes, NULL, enc, AES_BLOCK_SIZE),
  16665. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16666. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, NULL, AES_BLOCK_SIZE),
  16667. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16668. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  16669. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  16670. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  16671. #else
  16672. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  16673. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16674. #endif
  16675. /* Test passing in size of 0 */
  16676. XMEMSET(dec, 0, sizeof(dec));
  16677. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, 0), 0);
  16678. /* Check dec was not modified */
  16679. {
  16680. int i;
  16681. for (i = 0; i < (int)sizeof(dec); i++)
  16682. ExpectIntEQ(dec[i], 0);
  16683. }
  16684. ExpectIntEQ(wc_AesCbcDecryptWithKey(NULL, enc, AES_BLOCK_SIZE,
  16685. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16686. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, NULL, AES_BLOCK_SIZE,
  16687. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16688. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  16689. NULL, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16690. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  16691. key32, sizeof(key32)/sizeof(byte), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16692. wc_AesFree(&aes);
  16693. #endif
  16694. return EXPECT_RESULT();
  16695. } /* END test_wc_AesCbcEncryptDecrypt */
  16696. /*
  16697. * Testing wc_AesCtrEncrypt and wc_AesCtrDecrypt
  16698. */
  16699. static int test_wc_AesCtrEncryptDecrypt(void)
  16700. {
  16701. EXPECT_DECLS;
  16702. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  16703. Aes aesEnc;
  16704. Aes aesDec;
  16705. byte key32[] = {
  16706. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16707. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16708. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16709. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16710. };
  16711. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16712. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16713. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16714. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16715. };
  16716. byte iv[] = "1234567890abcdef";
  16717. byte enc[AES_BLOCK_SIZE * 2];
  16718. byte dec[AES_BLOCK_SIZE * 2];
  16719. /* Init stack variables. */
  16720. XMEMSET(&aesEnc, 0, sizeof(Aes));
  16721. XMEMSET(&aesDec, 0, sizeof(Aes));
  16722. XMEMSET(enc, 0, AES_BLOCK_SIZE * 2);
  16723. XMEMSET(dec, 0, AES_BLOCK_SIZE * 2);
  16724. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  16725. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  16726. ExpectIntEQ(wc_AesSetKey(&aesEnc, key32, AES_BLOCK_SIZE * 2, iv,
  16727. AES_ENCRYPTION), 0);
  16728. ExpectIntEQ(wc_AesCtrEncrypt(&aesEnc, enc, vector,
  16729. sizeof(vector)/sizeof(byte)), 0);
  16730. /* Decrypt with wc_AesCtrEncrypt() */
  16731. ExpectIntEQ(wc_AesSetKey(&aesDec, key32, AES_BLOCK_SIZE * 2, iv,
  16732. AES_ENCRYPTION), 0);
  16733. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, enc, sizeof(enc)/sizeof(byte)),
  16734. 0);
  16735. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  16736. /* Test bad args. */
  16737. ExpectIntEQ(wc_AesCtrEncrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte)),
  16738. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16739. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, NULL, enc, sizeof(enc)/sizeof(byte)),
  16740. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16741. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, NULL, sizeof(enc)/sizeof(byte)),
  16742. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16743. wc_AesFree(&aesEnc);
  16744. wc_AesFree(&aesDec);
  16745. #endif
  16746. return EXPECT_RESULT();
  16747. } /* END test_wc_AesCtrEncryptDecrypt */
  16748. /*
  16749. * test function for wc_AesGcmSetKey()
  16750. */
  16751. static int test_wc_AesGcmSetKey(void)
  16752. {
  16753. EXPECT_DECLS;
  16754. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  16755. Aes aes;
  16756. #ifdef WOLFSSL_AES_128
  16757. byte key16[] = {
  16758. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16759. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16760. };
  16761. #endif
  16762. #ifdef WOLFSSL_AES_192
  16763. byte key24[] = {
  16764. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16765. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16766. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  16767. };
  16768. #endif
  16769. #ifdef WOLFSSL_AES_256
  16770. byte key32[] = {
  16771. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16772. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16773. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16774. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16775. };
  16776. #endif
  16777. byte badKey16[] = {
  16778. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16779. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  16780. };
  16781. byte badKey24[] = {
  16782. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16783. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16784. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
  16785. };
  16786. byte badKey32[] = {
  16787. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x37, 0x37,
  16788. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16789. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16790. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  16791. };
  16792. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  16793. #ifdef WOLFSSL_AES_128
  16794. ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)/sizeof(byte)), 0);
  16795. #endif
  16796. #ifdef WOLFSSL_AES_192
  16797. ExpectIntEQ(wc_AesGcmSetKey(&aes, key24, sizeof(key24)/sizeof(byte)), 0);
  16798. #endif
  16799. #ifdef WOLFSSL_AES_256
  16800. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  16801. #endif
  16802. /* Pass in bad args. */
  16803. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey16, sizeof(badKey16)/sizeof(byte)),
  16804. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16805. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey24, sizeof(badKey24)/sizeof(byte)),
  16806. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16807. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey32, sizeof(badKey32)/sizeof(byte)),
  16808. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16809. wc_AesFree(&aes);
  16810. #endif
  16811. return EXPECT_RESULT();
  16812. } /* END test_wc_AesGcmSetKey */
  16813. /*
  16814. * test function for wc_AesGcmEncrypt and wc_AesGcmDecrypt
  16815. */
  16816. static int test_wc_AesGcmEncryptDecrypt(void)
  16817. {
  16818. EXPECT_DECLS;
  16819. /* WOLFSSL_AFALG requires 12 byte IV */
  16820. #if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_256) && \
  16821. !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO_AES)
  16822. Aes aes;
  16823. byte key32[] = {
  16824. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16825. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16826. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16827. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16828. };
  16829. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16830. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16831. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16832. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16833. };
  16834. const byte a[] = {
  16835. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  16836. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  16837. 0xab, 0xad, 0xda, 0xd2
  16838. };
  16839. byte iv[] = "1234567890a";
  16840. byte longIV[] = "1234567890abcdefghij";
  16841. byte enc[sizeof(vector)];
  16842. byte resultT[AES_BLOCK_SIZE];
  16843. byte dec[sizeof(vector)];
  16844. /* Init stack variables. */
  16845. XMEMSET(&aes, 0, sizeof(Aes));
  16846. XMEMSET(enc, 0, sizeof(vector));
  16847. XMEMSET(dec, 0, sizeof(vector));
  16848. XMEMSET(resultT, 0, AES_BLOCK_SIZE);
  16849. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  16850. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  16851. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  16852. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  16853. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(vector), iv,
  16854. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  16855. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  16856. /* Test bad args for wc_AesGcmEncrypt and wc_AesGcmDecrypt */
  16857. ExpectIntEQ(wc_AesGcmEncrypt(NULL, enc, vector, sizeof(vector), iv,
  16858. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  16859. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16860. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  16861. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  16862. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16863. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  16864. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) - 5, a, sizeof(a)),
  16865. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16866. #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  16867. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST) || \
  16868. defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  16869. /* FIPS does not check the lower bound of ivSz */
  16870. #else
  16871. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv, 0,
  16872. resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16873. #endif
  16874. /* This case is now considered good. Long IVs are now allowed.
  16875. * Except for the original FIPS release, it still has an upper
  16876. * bound on the IV length. */
  16877. #if (!defined(HAVE_FIPS) || \
  16878. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  16879. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  16880. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), longIV,
  16881. sizeof(longIV)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  16882. 0);
  16883. #else
  16884. (void)longIV;
  16885. #endif /* Old FIPS */
  16886. /* END wc_AesGcmEncrypt */
  16887. #ifdef HAVE_AES_DECRYPT
  16888. ExpectIntEQ(wc_AesGcmDecrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte), iv,
  16889. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  16890. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16891. ExpectIntEQ(wc_AesGcmDecrypt(&aes, NULL, enc, sizeof(enc)/sizeof(byte), iv,
  16892. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  16893. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16894. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, NULL, sizeof(enc)/sizeof(byte), iv,
  16895. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  16896. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16897. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), NULL,
  16898. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  16899. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16900. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  16901. sizeof(iv)/sizeof(byte), NULL, sizeof(resultT), a, sizeof(a)),
  16902. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16903. #if (defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0) && defined(WOLFSSL_ARMASM))
  16904. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  16905. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  16906. WC_NO_ERR_TRACE(AES_GCM_AUTH_E));
  16907. #else
  16908. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  16909. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  16910. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16911. #endif
  16912. #if ((defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  16913. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST)) && \
  16914. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  16915. /* FIPS does not check the lower bound of ivSz */
  16916. #else
  16917. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte),
  16918. iv, 0, resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16919. #endif
  16920. #endif /* HAVE_AES_DECRYPT */
  16921. wc_AesFree(&aes);
  16922. #endif
  16923. return EXPECT_RESULT();
  16924. } /* END test_wc_AesGcmEncryptDecrypt */
  16925. /*
  16926. * test function for mixed (one-shot encrpytion + stream decryption) AES GCM
  16927. * using a long IV (older FIPS does NOT support long IVs). Relates to zd15423
  16928. */
  16929. static int test_wc_AesGcmMixedEncDecLongIV(void)
  16930. {
  16931. EXPECT_DECLS;
  16932. #if (!defined(HAVE_FIPS) || \
  16933. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  16934. !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)
  16935. const byte key[] = {
  16936. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16937. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16938. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16939. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16940. };
  16941. const byte in[] = {
  16942. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16943. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16944. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16945. };
  16946. const byte aad[] = {
  16947. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  16948. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  16949. 0xab, 0xad, 0xda, 0xd2
  16950. };
  16951. Aes aesEnc;
  16952. Aes aesDec;
  16953. byte iv[] = "1234567890abcdefghij";
  16954. byte out[sizeof(in)];
  16955. byte plain[sizeof(in)];
  16956. byte tag[AES_BLOCK_SIZE];
  16957. XMEMSET(&aesEnc, 0, sizeof(Aes));
  16958. XMEMSET(&aesDec, 0, sizeof(Aes));
  16959. XMEMSET(out, 0, sizeof(out));
  16960. XMEMSET(plain, 0, sizeof(plain));
  16961. XMEMSET(tag, 0, sizeof(tag));
  16962. /* Perform one-shot encryption using long IV */
  16963. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  16964. ExpectIntEQ(wc_AesGcmSetKey(&aesEnc, key, sizeof(key)), 0);
  16965. ExpectIntEQ(wc_AesGcmEncrypt(&aesEnc, out, in, sizeof(in), iv, sizeof(iv),
  16966. tag, sizeof(tag), aad, sizeof(aad)), 0);
  16967. /* Perform streaming decryption using long IV */
  16968. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  16969. ExpectIntEQ(wc_AesGcmInit(&aesDec, key, sizeof(key), iv, sizeof(iv)), 0);
  16970. ExpectIntEQ(wc_AesGcmDecryptUpdate(&aesDec, plain, out, sizeof(out), aad,
  16971. sizeof(aad)), 0);
  16972. ExpectIntEQ(wc_AesGcmDecryptFinal(&aesDec, tag, sizeof(tag)), 0);
  16973. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  16974. /* Free resources */
  16975. wc_AesFree(&aesEnc);
  16976. wc_AesFree(&aesDec);
  16977. #endif
  16978. return EXPECT_RESULT();
  16979. } /* END wc_AesGcmMixedEncDecLongIV */
  16980. /*
  16981. * unit test for wc_GmacSetKey()
  16982. */
  16983. static int test_wc_GmacSetKey(void)
  16984. {
  16985. EXPECT_DECLS;
  16986. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  16987. Gmac gmac;
  16988. byte key16[] = {
  16989. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16990. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16991. };
  16992. #ifdef WOLFSSL_AES_192
  16993. byte key24[] = {
  16994. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16995. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16996. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  16997. };
  16998. #endif
  16999. #ifdef WOLFSSL_AES_256
  17000. byte key32[] = {
  17001. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17002. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17003. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17004. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17005. };
  17006. #endif
  17007. byte badKey16[] = {
  17008. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17009. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x66
  17010. };
  17011. byte badKey24[] = {
  17012. 0x30, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37,
  17013. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17014. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17015. };
  17016. byte badKey32[] = {
  17017. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17018. 0x38, 0x39, 0x61, 0x62, 0x64, 0x65, 0x66,
  17019. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17020. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17021. };
  17022. XMEMSET(&gmac, 0, sizeof(Gmac));
  17023. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17024. #ifdef WOLFSSL_AES_128
  17025. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)/sizeof(byte)), 0);
  17026. #endif
  17027. #ifdef WOLFSSL_AES_192
  17028. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17029. #endif
  17030. #ifdef WOLFSSL_AES_256
  17031. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17032. #endif
  17033. /* Pass in bad args. */
  17034. ExpectIntEQ(wc_GmacSetKey(NULL, key16, sizeof(key16)/sizeof(byte)),
  17035. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17036. ExpectIntEQ(wc_GmacSetKey(&gmac, NULL, sizeof(key16)/sizeof(byte)),
  17037. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17038. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey16, sizeof(badKey16)/sizeof(byte)),
  17039. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17040. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey24, sizeof(badKey24)/sizeof(byte)),
  17041. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17042. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey32, sizeof(badKey32)/sizeof(byte)),
  17043. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17044. wc_AesFree(&gmac.aes);
  17045. #endif
  17046. return EXPECT_RESULT();
  17047. } /* END test_wc_GmacSetKey */
  17048. /*
  17049. * unit test for wc_GmacUpdate
  17050. */
  17051. static int test_wc_GmacUpdate(void)
  17052. {
  17053. EXPECT_DECLS;
  17054. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17055. Gmac gmac;
  17056. #ifdef WOLFSSL_AES_128
  17057. const byte key16[] = {
  17058. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  17059. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  17060. };
  17061. #endif
  17062. #ifdef WOLFSSL_AES_192
  17063. byte key24[] = {
  17064. 0x41, 0xc5, 0xda, 0x86, 0x67, 0xef, 0x72, 0x52,
  17065. 0x20, 0xff, 0xe3, 0x9a, 0xe0, 0xac, 0x59, 0x0a,
  17066. 0xc9, 0xfc, 0xa7, 0x29, 0xab, 0x60, 0xad, 0xa0
  17067. };
  17068. #endif
  17069. #ifdef WOLFSSL_AES_256
  17070. byte key32[] = {
  17071. 0x78, 0xdc, 0x4e, 0x0a, 0xaf, 0x52, 0xd9, 0x35,
  17072. 0xc3, 0xc0, 0x1e, 0xea, 0x57, 0x42, 0x8f, 0x00,
  17073. 0xca, 0x1f, 0xd4, 0x75, 0xf5, 0xda, 0x86, 0xa4,
  17074. 0x9c, 0x8d, 0xd7, 0x3d, 0x68, 0xc8, 0xe2, 0x23
  17075. };
  17076. #endif
  17077. #ifdef WOLFSSL_AES_128
  17078. const byte authIn[] = {
  17079. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  17080. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  17081. };
  17082. #endif
  17083. #ifdef WOLFSSL_AES_192
  17084. const byte authIn2[] = {
  17085. 0x8b, 0x5c, 0x12, 0x4b, 0xef, 0x6e, 0x2f, 0x0f,
  17086. 0xe4, 0xd8, 0xc9, 0x5c, 0xd5, 0xfa, 0x4c, 0xf1
  17087. };
  17088. #endif
  17089. const byte authIn3[] = {
  17090. 0xb9, 0x6b, 0xaa, 0x8c, 0x1c, 0x75, 0xa6, 0x71,
  17091. 0xbf, 0xb2, 0xd0, 0x8d, 0x06, 0xbe, 0x5f, 0x36
  17092. };
  17093. #ifdef WOLFSSL_AES_128
  17094. const byte tag1[] = { /* Known. */
  17095. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  17096. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  17097. };
  17098. #endif
  17099. #ifdef WOLFSSL_AES_192
  17100. const byte tag2[] = { /* Known */
  17101. 0x20, 0x4b, 0xdb, 0x1b, 0xd6, 0x21, 0x54, 0xbf,
  17102. 0x08, 0x92, 0x2a, 0xaa, 0x54, 0xee, 0xd7, 0x05
  17103. };
  17104. #endif
  17105. const byte tag3[] = { /* Known */
  17106. 0x3e, 0x5d, 0x48, 0x6a, 0xa2, 0xe3, 0x0b, 0x22,
  17107. 0xe0, 0x40, 0xb8, 0x57, 0x23, 0xa0, 0x6e, 0x76
  17108. };
  17109. #ifdef WOLFSSL_AES_128
  17110. const byte iv[] = {
  17111. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  17112. 0xe2, 0x8c, 0x8f, 0x16
  17113. };
  17114. #endif
  17115. #ifdef WOLFSSL_AES_192
  17116. const byte iv2[] = {
  17117. 0x05, 0xad, 0x13, 0xa5, 0xe2, 0xc2, 0xab, 0x66,
  17118. 0x7e, 0x1a, 0x6f, 0xbc
  17119. };
  17120. #endif
  17121. const byte iv3[] = {
  17122. 0xd7, 0x9c, 0xf2, 0x2d, 0x50, 0x4c, 0xc7, 0x93,
  17123. 0xc3, 0xfb, 0x6c, 0x8a
  17124. };
  17125. byte tagOut[16];
  17126. byte tagOut2[24];
  17127. byte tagOut3[32];
  17128. /* Init stack variables. */
  17129. XMEMSET(&gmac, 0, sizeof(Gmac));
  17130. XMEMSET(tagOut, 0, sizeof(tagOut));
  17131. XMEMSET(tagOut2, 0, sizeof(tagOut2));
  17132. XMEMSET(tagOut3, 0, sizeof(tagOut3));
  17133. #ifdef WOLFSSL_AES_128
  17134. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17135. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)), 0);
  17136. ExpectIntEQ(wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn),
  17137. tagOut, sizeof(tag1)), 0);
  17138. ExpectIntEQ(XMEMCMP(tag1, tagOut, sizeof(tag1)), 0);
  17139. wc_AesFree(&gmac.aes);
  17140. #endif
  17141. #ifdef WOLFSSL_AES_192
  17142. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17143. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17144. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17145. ExpectIntEQ(wc_GmacUpdate(&gmac, iv2, sizeof(iv2), authIn2, sizeof(authIn2),
  17146. tagOut2, sizeof(tag2)), 0);
  17147. ExpectIntEQ(XMEMCMP(tagOut2, tag2, sizeof(tag2)), 0);
  17148. wc_AesFree(&gmac.aes);
  17149. #endif
  17150. #ifdef WOLFSSL_AES_256
  17151. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17152. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17153. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17154. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17155. tagOut3, sizeof(tag3)), 0);
  17156. ExpectIntEQ(XMEMCMP(tag3, tagOut3, sizeof(tag3)), 0);
  17157. wc_AesFree(&gmac.aes);
  17158. #endif
  17159. /* Pass bad args. */
  17160. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17161. ExpectIntEQ(wc_GmacUpdate(NULL, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17162. tagOut3, sizeof(tag3)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17163. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17164. tagOut3, sizeof(tag3) - 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17165. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17166. tagOut3, sizeof(tag3) + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17167. wc_AesFree(&gmac.aes);
  17168. #endif
  17169. return EXPECT_RESULT();
  17170. } /* END test_wc_GmacUpdate */
  17171. /*
  17172. * testing wc_CamelliaSetKey
  17173. */
  17174. static int test_wc_CamelliaSetKey(void)
  17175. {
  17176. EXPECT_DECLS;
  17177. #ifdef HAVE_CAMELLIA
  17178. Camellia camellia;
  17179. /*128-bit key*/
  17180. static const byte key16[] = {
  17181. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17182. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  17183. };
  17184. /* 192-bit key */
  17185. static const byte key24[] = {
  17186. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17187. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17188. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17189. };
  17190. /* 256-bit key */
  17191. static const byte key32[] = {
  17192. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17193. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17194. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  17195. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  17196. };
  17197. static const byte iv[] = {
  17198. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17199. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17200. };
  17201. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16), iv),
  17202. 0);
  17203. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16),
  17204. NULL), 0);
  17205. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17206. 0);
  17207. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17208. NULL), 0);
  17209. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32), iv),
  17210. 0);
  17211. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32),
  17212. NULL), 0);
  17213. /* Bad args. */
  17214. ExpectIntEQ(wc_CamelliaSetKey(NULL, key32, (word32)sizeof(key32), iv),
  17215. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17216. #endif
  17217. return EXPECT_RESULT();
  17218. } /* END test_wc_CammeliaSetKey */
  17219. /*
  17220. * Testing wc_CamelliaSetIV()
  17221. */
  17222. static int test_wc_CamelliaSetIV(void)
  17223. {
  17224. EXPECT_DECLS;
  17225. #ifdef HAVE_CAMELLIA
  17226. Camellia camellia;
  17227. static const byte iv[] = {
  17228. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17229. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17230. };
  17231. ExpectIntEQ(wc_CamelliaSetIV(&camellia, iv), 0);
  17232. ExpectIntEQ(wc_CamelliaSetIV(&camellia, NULL), 0);
  17233. /* Bad args. */
  17234. ExpectIntEQ(wc_CamelliaSetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17235. ExpectIntEQ(wc_CamelliaSetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17236. #endif
  17237. return EXPECT_RESULT();
  17238. } /* END test_wc_CamelliaSetIV*/
  17239. /*
  17240. * Test wc_CamelliaEncryptDirect and wc_CamelliaDecryptDirect
  17241. */
  17242. static int test_wc_CamelliaEncryptDecryptDirect(void)
  17243. {
  17244. EXPECT_DECLS;
  17245. #ifdef HAVE_CAMELLIA
  17246. Camellia camellia;
  17247. static const byte key24[] = {
  17248. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17249. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17250. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17251. };
  17252. static const byte iv[] = {
  17253. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17254. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17255. };
  17256. static const byte plainT[] = {
  17257. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17258. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17259. };
  17260. byte enc[sizeof(plainT)];
  17261. byte dec[sizeof(enc)];
  17262. /* Init stack variables.*/
  17263. XMEMSET(enc, 0, 16);
  17264. XMEMSET(enc, 0, 16);
  17265. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17266. 0);
  17267. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, plainT), 0);
  17268. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, enc), 0);
  17269. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17270. /* Pass bad args. */
  17271. ExpectIntEQ(wc_CamelliaEncryptDirect(NULL, enc, plainT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17272. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, NULL, plainT),
  17273. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17274. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17275. ExpectIntEQ(wc_CamelliaDecryptDirect(NULL, dec, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17276. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, NULL, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17277. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17278. #endif
  17279. return EXPECT_RESULT();
  17280. } /* END test-wc_CamelliaEncryptDecryptDirect */
  17281. /*
  17282. * Testing wc_CamelliaCbcEncrypt and wc_CamelliaCbcDecrypt
  17283. */
  17284. static int test_wc_CamelliaCbcEncryptDecrypt(void)
  17285. {
  17286. EXPECT_DECLS;
  17287. #ifdef HAVE_CAMELLIA
  17288. Camellia camellia;
  17289. static const byte key24[] = {
  17290. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17291. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17292. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17293. };
  17294. static const byte plainT[] = {
  17295. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17296. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17297. };
  17298. byte enc[CAMELLIA_BLOCK_SIZE];
  17299. byte dec[CAMELLIA_BLOCK_SIZE];
  17300. /* Init stack variables. */
  17301. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17302. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17303. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17304. NULL), 0);
  17305. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, plainT,
  17306. CAMELLIA_BLOCK_SIZE), 0);
  17307. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17308. NULL), 0);
  17309. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, enc, CAMELLIA_BLOCK_SIZE),
  17310. 0);
  17311. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17312. /* Pass in bad args. */
  17313. ExpectIntEQ(wc_CamelliaCbcEncrypt(NULL, enc, plainT, CAMELLIA_BLOCK_SIZE),
  17314. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17315. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, NULL, plainT,
  17316. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17317. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, NULL,
  17318. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17319. ExpectIntEQ(wc_CamelliaCbcDecrypt(NULL, dec, enc, CAMELLIA_BLOCK_SIZE),
  17320. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17321. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, NULL, enc,
  17322. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17323. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, NULL,
  17324. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17325. #endif
  17326. return EXPECT_RESULT();
  17327. } /* END test_wc_CamelliaCbcEncryptDecrypt */
  17328. /*
  17329. * Testing wc_Arc4SetKey()
  17330. */
  17331. static int test_wc_Arc4SetKey(void)
  17332. {
  17333. EXPECT_DECLS;
  17334. #ifndef NO_RC4
  17335. Arc4 arc;
  17336. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17337. int keyLen = 8;
  17338. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, (word32)keyLen), 0);
  17339. /* Test bad args. */
  17340. ExpectIntEQ(wc_Arc4SetKey(NULL, (byte*)key, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17341. ExpectIntEQ(wc_Arc4SetKey(&arc, NULL , (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17342. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17343. #endif
  17344. return EXPECT_RESULT();
  17345. } /* END test_wc_Arc4SetKey */
  17346. /*
  17347. * Testing wc_Arc4Process for ENC/DEC.
  17348. */
  17349. static int test_wc_Arc4Process(void)
  17350. {
  17351. EXPECT_DECLS;
  17352. #ifndef NO_RC4
  17353. Arc4 enc;
  17354. Arc4 dec;
  17355. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17356. int keyLen = 8;
  17357. const char* input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17358. byte cipher[8];
  17359. byte plain[8];
  17360. /* Init stack variables */
  17361. XMEMSET(&enc, 0, sizeof(Arc4));
  17362. XMEMSET(&dec, 0, sizeof(Arc4));
  17363. XMEMSET(cipher, 0, sizeof(cipher));
  17364. XMEMSET(plain, 0, sizeof(plain));
  17365. /* Use for async. */
  17366. ExpectIntEQ(wc_Arc4Init(&enc, NULL, INVALID_DEVID), 0);
  17367. ExpectIntEQ(wc_Arc4Init(&dec, NULL, INVALID_DEVID), 0);
  17368. ExpectIntEQ(wc_Arc4SetKey(&enc, (byte*)key, (word32)keyLen), 0);
  17369. ExpectIntEQ(wc_Arc4SetKey(&dec, (byte*)key, (word32)keyLen), 0);
  17370. ExpectIntEQ(wc_Arc4Process(&enc, cipher, (byte*)input, (word32)keyLen), 0);
  17371. ExpectIntEQ(wc_Arc4Process(&dec, plain, cipher, (word32)keyLen), 0);
  17372. ExpectIntEQ(XMEMCMP(plain, input, keyLen), 0);
  17373. /* Bad args. */
  17374. ExpectIntEQ(wc_Arc4Process(NULL, plain, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17375. ExpectIntEQ(wc_Arc4Process(&dec, NULL, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17376. ExpectIntEQ(wc_Arc4Process(&dec, plain, NULL, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17377. wc_Arc4Free(&enc);
  17378. wc_Arc4Free(&dec);
  17379. #endif
  17380. return EXPECT_RESULT();
  17381. } /* END test_wc_Arc4Process */
  17382. /*
  17383. * Testing wc_Init RsaKey()
  17384. */
  17385. static int test_wc_InitRsaKey(void)
  17386. {
  17387. EXPECT_DECLS;
  17388. #ifndef NO_RSA
  17389. RsaKey key;
  17390. XMEMSET(&key, 0, sizeof(RsaKey));
  17391. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17392. /* Test bad args. */
  17393. ExpectIntEQ(wc_InitRsaKey(NULL, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17394. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17395. #endif
  17396. return EXPECT_RESULT();
  17397. } /* END test_wc_InitRsaKey */
  17398. /*
  17399. * Testing wc_RsaPrivateKeyDecode()
  17400. */
  17401. static int test_wc_RsaPrivateKeyDecode(void)
  17402. {
  17403. EXPECT_DECLS;
  17404. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17405. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17406. RsaKey key;
  17407. byte* tmp = NULL;
  17408. word32 idx = 0;
  17409. int bytes = 0;
  17410. XMEMSET(&key, 0, sizeof(RsaKey));
  17411. ExpectNotNull(tmp = (byte*)XMALLOC(FOURK_BUF, NULL,
  17412. DYNAMIC_TYPE_TMP_BUFFER));
  17413. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17414. if (tmp != NULL) {
  17415. #ifdef USE_CERT_BUFFERS_1024
  17416. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  17417. bytes = sizeof_client_key_der_1024;
  17418. #else
  17419. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  17420. bytes = sizeof_client_key_der_2048;
  17421. #endif /* Use cert buffers. */
  17422. }
  17423. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes), 0);
  17424. /* Test bad args. */
  17425. ExpectIntEQ(wc_RsaPrivateKeyDecode(NULL, &idx, &key, (word32)bytes),
  17426. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17427. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, NULL, &key, (word32)bytes),
  17428. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17429. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17430. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17431. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17432. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17433. #endif
  17434. return EXPECT_RESULT();
  17435. } /* END test_wc_RsaPrivateKeyDecode */
  17436. /*
  17437. * Testing wc_RsaPublicKeyDecode()
  17438. */
  17439. static int test_wc_RsaPublicKeyDecode(void)
  17440. {
  17441. EXPECT_DECLS;
  17442. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17443. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17444. RsaKey keyPub;
  17445. byte* tmp = NULL;
  17446. word32 idx = 0;
  17447. int bytes = 0;
  17448. word32 keySz = 0;
  17449. word32 tstKeySz = 0;
  17450. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17451. XFILE f = XBADFILE;
  17452. const char* rsaPssPubKey = "./certs/rsapss/ca-rsapss-key.der";
  17453. const char* rsaPssPubKeyNoParams = "./certs/rsapss/ca-3072-rsapss-key.der";
  17454. byte buf[4096];
  17455. #endif
  17456. XMEMSET(&keyPub, 0, sizeof(RsaKey));
  17457. ExpectNotNull(tmp = (byte*)XMALLOC(GEN_BUF, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  17458. ExpectIntEQ(wc_InitRsaKey(&keyPub, HEAP_HINT), 0);
  17459. if (tmp != NULL) {
  17460. #ifdef USE_CERT_BUFFERS_1024
  17461. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  17462. bytes = sizeof_client_keypub_der_1024;
  17463. keySz = 1024;
  17464. #else
  17465. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  17466. bytes = sizeof_client_keypub_der_2048;
  17467. keySz = 2048;
  17468. #endif
  17469. }
  17470. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, &keyPub, (word32)bytes), 0);
  17471. /* Pass in bad args. */
  17472. ExpectIntEQ(wc_RsaPublicKeyDecode(NULL, &idx, &keyPub, (word32)bytes),
  17473. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17474. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, NULL, &keyPub, (word32)bytes),
  17475. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17476. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17477. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17478. DoExpectIntEQ(wc_FreeRsaKey(&keyPub), 0);
  17479. /* Test for getting modulus key size */
  17480. idx = 0;
  17481. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(tmp, &idx, (word32)bytes, NULL,
  17482. &tstKeySz, NULL, NULL), 0);
  17483. ExpectIntEQ(tstKeySz, keySz/8);
  17484. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17485. ExpectTrue((f = XFOPEN(rsaPssPubKey, "rb")) != XBADFILE);
  17486. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17487. if (f != XBADFILE) {
  17488. XFCLOSE(f);
  17489. f = XBADFILE;
  17490. }
  17491. idx = 0;
  17492. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17493. NULL), 0);
  17494. ExpectTrue((f = XFOPEN(rsaPssPubKeyNoParams, "rb")) != XBADFILE);
  17495. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17496. if (f != XBADFILE)
  17497. XFCLOSE(f);
  17498. idx = 0;
  17499. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17500. NULL), 0);
  17501. #endif
  17502. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17503. #endif
  17504. return EXPECT_RESULT();
  17505. } /* END test_wc_RsaPublicKeyDecode */
  17506. /*
  17507. * Testing wc_RsaPublicKeyDecodeRaw()
  17508. */
  17509. static int test_wc_RsaPublicKeyDecodeRaw(void)
  17510. {
  17511. EXPECT_DECLS;
  17512. #if !defined(NO_RSA)
  17513. RsaKey key;
  17514. const byte n = 0x23;
  17515. const byte e = 0x03;
  17516. int nSz = sizeof(n);
  17517. int eSz = sizeof(e);
  17518. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17519. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 0);
  17520. /* Pass in bad args. */
  17521. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(NULL, nSz, &e, eSz, &key),
  17522. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17523. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, NULL, eSz, &key),
  17524. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17525. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, NULL),
  17526. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17527. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17528. #endif
  17529. return EXPECT_RESULT();
  17530. } /* END test_wc_RsaPublicKeyDecodeRaw */
  17531. /*
  17532. * Testing wc_RsaPrivateKeyDecodeRaw()
  17533. */
  17534. static int test_wc_RsaPrivateKeyDecodeRaw(void)
  17535. {
  17536. EXPECT_DECLS;
  17537. #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) \
  17538. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  17539. RsaKey key;
  17540. const byte n = 33;
  17541. const byte e = 3;
  17542. const byte d = 7;
  17543. const byte u = 2;
  17544. const byte p = 3;
  17545. const byte q = 11;
  17546. const byte dp = 1;
  17547. const byte dq = 7;
  17548. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17549. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17550. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17551. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  17552. NULL, 0, &key), 0);
  17553. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17554. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17555. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17556. NULL, 0, &key), 0);
  17557. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17558. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17559. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  17560. &dq, sizeof(dq), &key), 0);
  17561. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17562. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17563. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17564. &dq, sizeof(dq), &key), 0);
  17565. /* Pass in bad args. */
  17566. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(NULL, sizeof(n),
  17567. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17568. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17569. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17570. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, 0,
  17571. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17572. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17573. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17574. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17575. NULL, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17576. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17577. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17578. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17579. &e, 0, &d, sizeof(d), &u, sizeof(u),
  17580. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17581. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17582. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17583. &e, sizeof(e), NULL, sizeof(d), &u, sizeof(u),
  17584. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17585. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17586. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17587. &e, sizeof(e), &d, 0, &u, sizeof(u),
  17588. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17589. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17590. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17591. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17592. NULL, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17593. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17594. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17595. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17596. &p, 0, &q, sizeof(q), &dp, sizeof(dp),
  17597. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17598. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17599. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17600. &p, sizeof(p), NULL, sizeof(q), &dp, sizeof(dp),
  17601. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17602. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17603. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17604. &p, sizeof(p), &q, 0, &dp, sizeof(dp),
  17605. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17606. #if defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || !defined(RSA_LOW_MEM)
  17607. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17608. &e, sizeof(e), &d, sizeof(d), &u, 0,
  17609. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17610. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17611. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17612. &e, sizeof(e), &d, sizeof(d), NULL, sizeof(u),
  17613. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17614. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17615. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17616. &e, sizeof(e), &d, sizeof(d), &u, 0,
  17617. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17618. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17619. #endif
  17620. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17621. #endif
  17622. return EXPECT_RESULT();
  17623. } /* END test_wc_RsaPrivateKeyDecodeRaw */
  17624. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  17625. /* In FIPS builds, wc_MakeRsaKey() will return an error if it cannot find
  17626. * a probable prime in 5*(modLen/2) attempts. In non-FIPS builds, it keeps
  17627. * trying until it gets a probable prime. */
  17628. #ifdef HAVE_FIPS
  17629. static int MakeRsaKeyRetry(RsaKey* key, int size, long e, WC_RNG* rng)
  17630. {
  17631. int ret;
  17632. for (;;) {
  17633. ret = wc_MakeRsaKey(key, size, e, rng);
  17634. if (ret != WC_NO_ERR_TRACE(PRIME_GEN_E)) break;
  17635. fprintf(stderr, "MakeRsaKey couldn't find prime; "
  17636. "trying again.\n");
  17637. }
  17638. return ret;
  17639. }
  17640. #define MAKE_RSA_KEY(a, b, c, d) MakeRsaKeyRetry(a, b, c, d)
  17641. #else
  17642. #define MAKE_RSA_KEY(a, b, c, d) wc_MakeRsaKey(a, b, c, d)
  17643. #endif
  17644. #endif
  17645. /*
  17646. * Testing wc_MakeRsaKey()
  17647. */
  17648. static int test_wc_MakeRsaKey(void)
  17649. {
  17650. EXPECT_DECLS;
  17651. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  17652. RsaKey genKey;
  17653. WC_RNG rng;
  17654. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  17655. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  17656. int bits = 1024;
  17657. #else
  17658. int bits = 2048;
  17659. #endif
  17660. XMEMSET(&genKey, 0, sizeof(RsaKey));
  17661. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17662. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  17663. ExpectIntEQ(wc_InitRng(&rng), 0);
  17664. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  17665. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  17666. /* Test bad args. */
  17667. ExpectIntEQ(MAKE_RSA_KEY(NULL, bits, WC_RSA_EXPONENT, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17668. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, NULL),
  17669. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17670. /* e < 3 */
  17671. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 2, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17672. /* e & 1 == 0 */
  17673. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 6, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17674. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  17675. #endif
  17676. return EXPECT_RESULT();
  17677. } /* END test_wc_MakeRsaKey */
  17678. /*
  17679. * Test the bounds checking on the cipher text versus the key modulus.
  17680. * 1. Make a new RSA key.
  17681. * 2. Set c to 1.
  17682. * 3. Decrypt c into k. (error)
  17683. * 4. Copy the key modulus to c and sub 1 from the copy.
  17684. * 5. Decrypt c into k. (error)
  17685. * Valid bounds test cases are covered by all the other RSA tests.
  17686. */
  17687. static int test_RsaDecryptBoundsCheck(void)
  17688. {
  17689. EXPECT_DECLS;
  17690. #if !defined(NO_RSA) && defined(WC_RSA_NO_PADDING) && \
  17691. (defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)) && \
  17692. defined(WOLFSSL_PUBLIC_MP) && !defined(NO_RSA_BOUNDS_CHECK)
  17693. WC_RNG rng;
  17694. RsaKey key;
  17695. byte flatC[256];
  17696. word32 flatCSz;
  17697. byte out[256];
  17698. word32 outSz = sizeof(out);
  17699. XMEMSET(&key, 0, sizeof(RsaKey));
  17700. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17701. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17702. ExpectIntEQ(wc_InitRng(&rng), 0);
  17703. if (EXPECT_SUCCESS()) {
  17704. const byte* derKey;
  17705. word32 derKeySz;
  17706. word32 idx = 0;
  17707. #ifdef USE_CERT_BUFFERS_1024
  17708. derKey = server_key_der_1024;
  17709. derKeySz = (word32)sizeof_server_key_der_1024;
  17710. flatCSz = 128;
  17711. #else
  17712. derKey = server_key_der_2048;
  17713. derKeySz = (word32)sizeof_server_key_der_2048;
  17714. flatCSz = 256;
  17715. #endif
  17716. ExpectIntEQ(wc_RsaPrivateKeyDecode(derKey, &idx, &key, derKeySz), 0);
  17717. }
  17718. if (EXPECT_SUCCESS()) {
  17719. XMEMSET(flatC, 0, flatCSz);
  17720. flatC[flatCSz-1] = 1;
  17721. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  17722. RSA_PRIVATE_DECRYPT, &rng), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  17723. if (EXPECT_SUCCESS()) {
  17724. mp_int c;
  17725. ExpectIntEQ(mp_init_copy(&c, &key.n), 0);
  17726. ExpectIntEQ(mp_sub_d(&c, 1, &c), 0);
  17727. ExpectIntEQ(mp_to_unsigned_bin(&c, flatC), 0);
  17728. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  17729. RSA_PRIVATE_DECRYPT, NULL), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  17730. mp_clear(&c);
  17731. }
  17732. }
  17733. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17734. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  17735. #endif
  17736. return EXPECT_RESULT();
  17737. } /* END test_wc_RsaDecryptBoundsCheck */
  17738. /*
  17739. * Testing wc_SetKeyUsage()
  17740. */
  17741. static int test_wc_SetKeyUsage(void)
  17742. {
  17743. EXPECT_DECLS;
  17744. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) && !defined(HAVE_FIPS)
  17745. Cert myCert;
  17746. ExpectIntEQ(wc_InitCert(&myCert), 0);
  17747. ExpectIntEQ(wc_SetKeyUsage(&myCert, "keyEncipherment,keyAgreement"), 0);
  17748. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature,nonRepudiation"), 0);
  17749. ExpectIntEQ(wc_SetKeyUsage(&myCert, "contentCommitment,encipherOnly"), 0);
  17750. ExpectIntEQ(wc_SetKeyUsage(&myCert, "decipherOnly"), 0);
  17751. ExpectIntEQ(wc_SetKeyUsage(&myCert, "cRLSign,keyCertSign"), 0);
  17752. /* Test bad args. */
  17753. ExpectIntEQ(wc_SetKeyUsage(NULL, "decipherOnly"), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17754. ExpectIntEQ(wc_SetKeyUsage(&myCert, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17755. ExpectIntEQ(wc_SetKeyUsage(&myCert, ""), WC_NO_ERR_TRACE(KEYUSAGE_E));
  17756. ExpectIntEQ(wc_SetKeyUsage(&myCert, ","), WC_NO_ERR_TRACE(KEYUSAGE_E));
  17757. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature, cRLSign"),
  17758. WC_NO_ERR_TRACE(KEYUSAGE_E));
  17759. #endif
  17760. return EXPECT_RESULT();
  17761. } /* END test_wc_SetKeyUsage */
  17762. /*
  17763. * Testing wc_CheckProbablePrime()
  17764. */
  17765. static int test_wc_CheckProbablePrime(void)
  17766. {
  17767. EXPECT_DECLS;
  17768. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  17769. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING)
  17770. #define CHECK_PROBABLE_PRIME_KEY_BITS 2048
  17771. RsaKey key;
  17772. WC_RNG rng;
  17773. byte e[3];
  17774. word32 eSz = (word32)sizeof(e);
  17775. byte n[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  17776. word32 nSz = (word32)sizeof(n);
  17777. byte d[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  17778. word32 dSz = (word32)sizeof(d);
  17779. byte p[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  17780. word32 pSz = (word32)sizeof(p);
  17781. byte q[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  17782. word32 qSz = (word32)sizeof(q);
  17783. int nlen = CHECK_PROBABLE_PRIME_KEY_BITS;
  17784. int* isPrime;
  17785. int test[5];
  17786. isPrime = test;
  17787. XMEMSET(&key, 0, sizeof(RsaKey));
  17788. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17789. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17790. ExpectIntEQ(wc_InitRng(&rng), 0);
  17791. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  17792. ExpectIntEQ(wc_MakeRsaKey(&key, CHECK_PROBABLE_PRIME_KEY_BITS,
  17793. WC_RSA_EXPONENT, &rng), 0);
  17794. PRIVATE_KEY_UNLOCK();
  17795. ExpectIntEQ(wc_RsaExportKey(&key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q,
  17796. &qSz), 0);
  17797. PRIVATE_KEY_LOCK();
  17798. /* Bad cases */
  17799. ExpectIntEQ(wc_CheckProbablePrime(NULL, pSz, q, qSz, e, eSz, nlen, isPrime),
  17800. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17801. ExpectIntEQ(wc_CheckProbablePrime(p, 0, q, qSz, e, eSz, nlen, isPrime),
  17802. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17803. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, NULL, qSz, e, eSz, nlen, isPrime),
  17804. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17805. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, 0, e, eSz, nlen, isPrime),
  17806. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17807. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, NULL, eSz, nlen, isPrime),
  17808. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17809. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, 0, nlen, isPrime),
  17810. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17811. ExpectIntEQ(wc_CheckProbablePrime(NULL, 0, NULL, 0, NULL, 0, nlen, isPrime),
  17812. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17813. /* Good case */
  17814. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, eSz, nlen, isPrime),
  17815. 0);
  17816. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17817. wc_FreeRng(&rng);
  17818. #undef CHECK_PROBABLE_PRIME_KEY_BITS
  17819. #endif
  17820. return EXPECT_RESULT();
  17821. } /* END test_wc_CheckProbablePrime */
  17822. /*
  17823. * Testing wc_RsaPSS_Verify()
  17824. */
  17825. static int test_wc_RsaPSS_Verify(void)
  17826. {
  17827. EXPECT_DECLS;
  17828. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  17829. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  17830. RsaKey key;
  17831. WC_RNG rng;
  17832. int sz = 256;
  17833. const char* szMessage = "This is the string to be signed";
  17834. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  17835. unsigned char pDecrypted[2048/8];
  17836. byte* pt = pDecrypted;
  17837. word32 outLen = sizeof(pDecrypted);
  17838. XMEMSET(&key, 0, sizeof(RsaKey));
  17839. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17840. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17841. ExpectIntEQ(wc_InitRng(&rng), 0);
  17842. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  17843. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  17844. ExpectIntGT(sz = wc_RsaPSS_Sign((byte*)szMessage,
  17845. (word32)XSTRLEN(szMessage)+1, pSignature, sizeof(pSignature),
  17846. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  17847. /* Bad cases */
  17848. ExpectIntEQ(wc_RsaPSS_Verify(NULL, (word32)sz, pt, outLen,
  17849. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17850. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, 0, pt, outLen,
  17851. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17852. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, (word32)sz, NULL, outLen,
  17853. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17854. ExpectIntEQ(wc_RsaPSS_Verify(NULL, 0, NULL, outLen,
  17855. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17856. /* Good case */
  17857. ExpectIntGT(wc_RsaPSS_Verify(pSignature, (word32)sz, pt, outLen,
  17858. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  17859. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17860. wc_FreeRng(&rng);
  17861. #endif
  17862. return EXPECT_RESULT();
  17863. } /* END test_wc_RsaPSS_Verify */
  17864. /*
  17865. * Testing wc_RsaPSS_VerifyCheck()
  17866. */
  17867. static int test_wc_RsaPSS_VerifyCheck(void)
  17868. {
  17869. EXPECT_DECLS;
  17870. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  17871. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  17872. RsaKey key;
  17873. WC_RNG rng;
  17874. int sz = 256; /* 2048/8 */
  17875. byte digest[32];
  17876. word32 digestSz = sizeof(digest);
  17877. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  17878. word32 pSignatureSz = sizeof(pSignature);
  17879. unsigned char pDecrypted[2048/8];
  17880. byte* pt = pDecrypted;
  17881. word32 outLen = sizeof(pDecrypted);
  17882. XMEMSET(&key, 0, sizeof(RsaKey));
  17883. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17884. XMEMSET(digest, 0, sizeof(digest));
  17885. XMEMSET(pSignature, 0, sizeof(pSignature));
  17886. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17887. ExpectIntEQ(wc_InitRng(&rng), 0);
  17888. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  17889. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  17890. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  17891. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  17892. 0);
  17893. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature, pSignatureSz,
  17894. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  17895. /* Bad cases */
  17896. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, (word32)sz, pt, outLen, digest,
  17897. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17898. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, 0, pt, outLen, digest,
  17899. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17900. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, NULL, outLen, digest,
  17901. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17902. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, 0, NULL, outLen, digest,
  17903. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17904. /* Good case */
  17905. ExpectIntGT(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, pt, outLen, digest,
  17906. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  17907. ExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17908. wc_FreeRng(&rng);
  17909. #endif
  17910. return EXPECT_RESULT();
  17911. } /* END test_wc_RsaPSS_VerifyCheck */
  17912. /*
  17913. * Testing wc_RsaPSS_VerifyCheckInline()
  17914. */
  17915. static int test_wc_RsaPSS_VerifyCheckInline(void)
  17916. {
  17917. EXPECT_DECLS;
  17918. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  17919. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  17920. RsaKey key;
  17921. WC_RNG rng;
  17922. int sz = 256;
  17923. byte digest[32];
  17924. word32 digestSz = sizeof(digest);
  17925. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  17926. unsigned char pDecrypted[2048/8];
  17927. byte* pt = pDecrypted;
  17928. XMEMSET(&key, 0, sizeof(RsaKey));
  17929. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17930. XMEMSET(digest, 0, sizeof(digest));
  17931. XMEMSET(pSignature, 0, sizeof(pSignature));
  17932. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17933. ExpectIntEQ(wc_InitRng(&rng), 0);
  17934. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  17935. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  17936. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  17937. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  17938. 0);
  17939. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature,
  17940. sizeof(pSignature), WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  17941. /* Bad Cases */
  17942. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, (word32)sz, &pt, digest,
  17943. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17944. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, 0, NULL, digest,
  17945. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17946. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, 0, &pt, digest,
  17947. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17948. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  17949. digestSz, WC_HASH_TYPE_SHA, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17950. /* Good case */
  17951. ExpectIntGT(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  17952. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  17953. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17954. wc_FreeRng(&rng);
  17955. #endif
  17956. return EXPECT_RESULT();
  17957. } /* END test_wc_RsaPSS_VerifyCheckInline */
  17958. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  17959. static void sample_mutex_cb (int flag, int type, const char* file, int line)
  17960. {
  17961. (void)flag;
  17962. (void)type;
  17963. (void)file;
  17964. (void)line;
  17965. }
  17966. #endif
  17967. /*
  17968. * Testing wc_LockMutex_ex
  17969. */
  17970. static int test_wc_LockMutex_ex(void)
  17971. {
  17972. EXPECT_DECLS;
  17973. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  17974. int flag = CRYPTO_LOCK;
  17975. int type = 0;
  17976. const char* file = "./test-LockMutex_ex.txt";
  17977. int line = 0;
  17978. /* without SetMutexCb */
  17979. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), WC_NO_ERR_TRACE(BAD_STATE_E));
  17980. /* with SetMutexCb */
  17981. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  17982. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), 0);
  17983. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  17984. #endif
  17985. return EXPECT_RESULT();
  17986. } /* End test_wc_LockMutex_ex*/
  17987. /*
  17988. * Testing wc_SetMutexCb
  17989. */
  17990. static int test_wc_SetMutexCb(void)
  17991. {
  17992. EXPECT_DECLS;
  17993. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  17994. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  17995. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  17996. #endif
  17997. return EXPECT_RESULT();
  17998. } /* End test_wc_SetMutexCb*/
  17999. /*
  18000. * Testing wc_RsaKeyToDer()
  18001. */
  18002. static int test_wc_RsaKeyToDer(void)
  18003. {
  18004. EXPECT_DECLS;
  18005. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18006. RsaKey genKey;
  18007. WC_RNG rng;
  18008. byte* der = NULL;
  18009. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18010. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18011. int bits = 1024;
  18012. word32 derSz = 611;
  18013. /* (2 x 128) + 2 (possible leading 00) + (5 x 64) + 5 (possible leading 00)
  18014. + 3 (e) + 8 (ASN tag) + 10 (ASN length) + 4 seqSz + 3 version */
  18015. #else
  18016. int bits = 2048;
  18017. word32 derSz = 1196;
  18018. /* (2 x 256) + 2 (possible leading 00) + (5 x 128) + 5 (possible leading 00)
  18019. + 3 (e) + 8 (ASN tag) + 17 (ASN length) + 4 seqSz + 3 version */
  18020. #endif
  18021. XMEMSET(&rng, 0, sizeof(rng));
  18022. XMEMSET(&genKey, 0, sizeof(genKey));
  18023. ExpectNotNull(der = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18024. /* Init structures. */
  18025. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18026. ExpectIntEQ(wc_InitRng(&rng), 0);
  18027. /* Make key. */
  18028. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18029. ExpectIntGT(wc_RsaKeyToDer(&genKey, der, derSz), 0);
  18030. /* Pass good/bad args. */
  18031. ExpectIntEQ(wc_RsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18032. /* Get just the output length */
  18033. ExpectIntGT(wc_RsaKeyToDer(&genKey, NULL, 0), 0);
  18034. /* Try Public Key. */
  18035. genKey.type = 0;
  18036. ExpectIntEQ(wc_RsaKeyToDer(&genKey, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18037. #ifdef WOLFSSL_CHECK_MEM_ZERO
  18038. /* Put back to Private Key */
  18039. genKey.type = 1;
  18040. #endif
  18041. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18042. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18043. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18044. #endif
  18045. return EXPECT_RESULT();
  18046. } /* END test_wc_RsaKeyToDer */
  18047. /*
  18048. * Testing wc_RsaKeyToPublicDer()
  18049. */
  18050. static int test_wc_RsaKeyToPublicDer(void)
  18051. {
  18052. EXPECT_DECLS;
  18053. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18054. RsaKey key;
  18055. WC_RNG rng;
  18056. byte* der = NULL;
  18057. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18058. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18059. int bits = 1024;
  18060. word32 derLen = 162;
  18061. #else
  18062. int bits = 2048;
  18063. word32 derLen = 294;
  18064. #endif
  18065. int ret;
  18066. XMEMSET(&rng, 0, sizeof(rng));
  18067. XMEMSET(&key, 0, sizeof(key));
  18068. ExpectNotNull(der = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18069. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18070. ExpectIntEQ(wc_InitRng(&rng), 0);
  18071. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18072. /* test getting size only */
  18073. ExpectIntGT(wc_RsaKeyToPublicDer(&key, NULL, derLen), 0);
  18074. ExpectIntGT(wc_RsaKeyToPublicDer(&key, der, derLen), 0);
  18075. /* test getting size only */
  18076. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, NULL, derLen, 0), 0);
  18077. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, der, derLen, 0), 0);
  18078. /* Pass in bad args. */
  18079. ExpectIntEQ(wc_RsaKeyToPublicDer(NULL, der, derLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18080. ExpectIntLT(ret = wc_RsaKeyToPublicDer(&key, der, -1), 0);
  18081. ExpectTrue((ret == WC_NO_ERR_TRACE(BUFFER_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  18082. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18083. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18084. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18085. #endif
  18086. return EXPECT_RESULT();
  18087. } /* END test_wc_RsaKeyToPublicDer */
  18088. /*
  18089. * Testing wc_RsaPublicEncrypt() and wc_RsaPrivateDecrypt()
  18090. */
  18091. static int test_wc_RsaPublicEncryptDecrypt(void)
  18092. {
  18093. EXPECT_DECLS;
  18094. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18095. RsaKey key;
  18096. WC_RNG rng;
  18097. const char inStr[] = TEST_STRING;
  18098. const word32 plainLen = (word32)TEST_STRING_SZ;
  18099. const word32 inLen = (word32)TEST_STRING_SZ;
  18100. int bits = TEST_RSA_BITS;
  18101. const word32 cipherLen = TEST_RSA_BYTES;
  18102. word32 cipherLenResult = cipherLen;
  18103. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18104. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18105. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18106. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18107. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18108. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18109. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18110. ExpectNotNull(in);
  18111. ExpectNotNull(plain);
  18112. ExpectNotNull(cipher);
  18113. #endif
  18114. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18115. /* Initialize stack structures. */
  18116. XMEMSET(&key, 0, sizeof(RsaKey));
  18117. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18118. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18119. ExpectIntEQ(wc_InitRng(&rng), 0);
  18120. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18121. /* Encrypt. */
  18122. ExpectIntGT(cipherLenResult = (word32)wc_RsaPublicEncrypt(in, inLen, cipher,
  18123. cipherLen, &key, &rng), 0);
  18124. /* Pass bad args - tested in another testing function.*/
  18125. /* Decrypt */
  18126. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18127. /* Bind rng */
  18128. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18129. #endif
  18130. ExpectIntGE(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen,
  18131. &key), 0);
  18132. ExpectIntEQ(XMEMCMP(plain, inStr, plainLen), 0);
  18133. /* Pass bad args - tested in another testing function.*/
  18134. WC_FREE_VAR(in, NULL);
  18135. WC_FREE_VAR(plain, NULL);
  18136. WC_FREE_VAR(cipher, NULL);
  18137. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18138. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18139. #endif
  18140. return EXPECT_RESULT();
  18141. } /* END test_wc_RsaPublicEncryptDecrypt */
  18142. /*
  18143. * Testing wc_RsaPrivateDecrypt_ex() and wc_RsaPrivateDecryptInline_ex()
  18144. */
  18145. static int test_wc_RsaPublicEncryptDecrypt_ex(void)
  18146. {
  18147. EXPECT_DECLS;
  18148. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS)\
  18149. && !defined(WC_NO_RSA_OAEP) && !defined(NO_SHA256)
  18150. RsaKey key;
  18151. WC_RNG rng;
  18152. const char inStr[] = TEST_STRING;
  18153. const word32 inLen = (word32)TEST_STRING_SZ;
  18154. const word32 plainSz = (word32)TEST_STRING_SZ;
  18155. byte* res = NULL;
  18156. int idx = 0;
  18157. int bits = TEST_RSA_BITS;
  18158. const word32 cipherSz = TEST_RSA_BYTES;
  18159. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18160. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18161. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18162. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18163. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18164. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18165. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18166. ExpectNotNull(in);
  18167. ExpectNotNull(plain);
  18168. ExpectNotNull(cipher);
  18169. #endif
  18170. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18171. /* Initialize stack structures. */
  18172. XMEMSET(&key, 0, sizeof(RsaKey));
  18173. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18174. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, INVALID_DEVID), 0);
  18175. ExpectIntEQ(wc_InitRng(&rng), 0);
  18176. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18177. /* Encrypt */
  18178. ExpectIntGE(idx = wc_RsaPublicEncrypt_ex(in, inLen, cipher, cipherSz, &key,
  18179. &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18180. /* Pass bad args - tested in another testing function.*/
  18181. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18182. /* Decrypt */
  18183. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18184. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18185. #endif
  18186. ExpectIntGE(wc_RsaPrivateDecrypt_ex(cipher, (word32)idx, plain, plainSz,
  18187. &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18188. ExpectIntEQ(XMEMCMP(plain, inStr, plainSz), 0);
  18189. /* Pass bad args - tested in another testing function.*/
  18190. ExpectIntGE(wc_RsaPrivateDecryptInline_ex(cipher, (word32)idx, &res, &key,
  18191. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18192. ExpectIntEQ(XMEMCMP(inStr, res, plainSz), 0);
  18193. #endif
  18194. WC_FREE_VAR(in, NULL);
  18195. WC_FREE_VAR(plain, NULL);
  18196. WC_FREE_VAR(cipher, NULL);
  18197. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18198. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18199. #endif
  18200. return EXPECT_RESULT();
  18201. } /* END test_wc_RsaPublicEncryptDecrypt_ex */
  18202. /*
  18203. * Tesing wc_RsaSSL_Sign() and wc_RsaSSL_Verify()
  18204. */
  18205. static int test_wc_RsaSSL_SignVerify(void)
  18206. {
  18207. EXPECT_DECLS;
  18208. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18209. RsaKey key;
  18210. WC_RNG rng;
  18211. const char inStr[] = TEST_STRING;
  18212. const word32 plainSz = (word32)TEST_STRING_SZ;
  18213. const word32 inLen = (word32)TEST_STRING_SZ;
  18214. word32 idx = 0;
  18215. int bits = TEST_RSA_BITS;
  18216. const word32 outSz = TEST_RSA_BYTES;
  18217. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18218. WC_DECLARE_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18219. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18220. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18221. WC_ALLOC_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18222. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18223. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18224. ExpectNotNull(in);
  18225. ExpectNotNull(out);
  18226. ExpectNotNull(plain);
  18227. #endif
  18228. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18229. XMEMSET(&key, 0, sizeof(RsaKey));
  18230. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18231. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18232. ExpectIntEQ(wc_InitRng(&rng), 0);
  18233. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18234. /* Sign. */
  18235. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, &key, &rng), (int)outSz);
  18236. idx = (int)outSz;
  18237. /* Test bad args. */
  18238. ExpectIntEQ(wc_RsaSSL_Sign(NULL, inLen, out, outSz, &key, &rng),
  18239. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18240. ExpectIntEQ(wc_RsaSSL_Sign(in, 0, out, outSz, &key, &rng),
  18241. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18242. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, NULL, outSz, &key, &rng),
  18243. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18244. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, NULL, &rng),
  18245. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18246. /* Verify. */
  18247. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, &key), (int)inLen);
  18248. /* Pass bad args. */
  18249. ExpectIntEQ(wc_RsaSSL_Verify(NULL, idx, plain, plainSz, &key),
  18250. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18251. ExpectIntEQ(wc_RsaSSL_Verify(out, 0, plain, plainSz, &key),
  18252. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18253. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, NULL, plainSz, &key),
  18254. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18255. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, NULL),
  18256. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18257. WC_FREE_VAR(in, NULL);
  18258. WC_FREE_VAR(out, NULL);
  18259. WC_FREE_VAR(plain, NULL);
  18260. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18261. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18262. #endif
  18263. return EXPECT_RESULT();
  18264. } /* END test_wc_RsaSSL_SignVerify */
  18265. /*
  18266. * Testing wc_RsaEncryptSize()
  18267. */
  18268. static int test_wc_RsaEncryptSize(void)
  18269. {
  18270. EXPECT_DECLS;
  18271. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18272. RsaKey key;
  18273. WC_RNG rng;
  18274. XMEMSET(&key, 0, sizeof(RsaKey));
  18275. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18276. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18277. ExpectIntEQ(wc_InitRng(&rng), 0);
  18278. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18279. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18280. ExpectIntEQ(MAKE_RSA_KEY(&key, 1024, WC_RSA_EXPONENT, &rng), 0);
  18281. ExpectIntEQ(wc_RsaEncryptSize(&key), 128);
  18282. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18283. #endif
  18284. ExpectIntEQ(MAKE_RSA_KEY(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18285. ExpectIntEQ(wc_RsaEncryptSize(&key), 256);
  18286. /* Pass in bad arg. */
  18287. ExpectIntEQ(wc_RsaEncryptSize(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18288. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18289. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18290. #endif
  18291. return EXPECT_RESULT();
  18292. } /* END test_wc_RsaEncryptSize*/
  18293. /*
  18294. * Testing wc_RsaFlattenPublicKey()
  18295. */
  18296. static int test_wc_RsaFlattenPublicKey(void)
  18297. {
  18298. EXPECT_DECLS;
  18299. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18300. RsaKey key;
  18301. WC_RNG rng;
  18302. byte e[256];
  18303. byte n[256];
  18304. word32 eSz = sizeof(e);
  18305. word32 nSz = sizeof(n);
  18306. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18307. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18308. int bits = 1024;
  18309. #else
  18310. int bits = 2048;
  18311. #endif
  18312. XMEMSET(&key, 0, sizeof(RsaKey));
  18313. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18314. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18315. ExpectIntEQ(wc_InitRng(&rng), 0);
  18316. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18317. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz), 0);
  18318. /* Pass bad args. */
  18319. ExpectIntEQ(wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz),
  18320. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18321. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, NULL, &eSz, n, &nSz),
  18322. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18323. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, NULL, n, &nSz),
  18324. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18325. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, NULL, &nSz),
  18326. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18327. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, NULL),
  18328. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18329. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18330. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18331. #endif
  18332. return EXPECT_RESULT();
  18333. } /* END test_wc_RsaFlattenPublicKey */
  18334. /*
  18335. * unit test for wc_AesCcmSetKey
  18336. */
  18337. static int test_wc_AesCcmSetKey(void)
  18338. {
  18339. EXPECT_DECLS;
  18340. #ifdef HAVE_AESCCM
  18341. Aes aes;
  18342. const byte key16[] = {
  18343. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18344. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18345. };
  18346. const byte key24[] = {
  18347. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18348. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18349. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  18350. };
  18351. const byte key32[] = {
  18352. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18353. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18354. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18355. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  18356. };
  18357. XMEMSET(&aes, 0, sizeof(Aes));
  18358. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18359. #ifdef WOLFSSL_AES_128
  18360. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18361. #endif
  18362. #ifdef WOLFSSL_AES_192
  18363. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24)), 0);
  18364. #endif
  18365. #ifdef WOLFSSL_AES_256
  18366. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32)), 0);
  18367. #endif
  18368. /* Test bad args. */
  18369. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18370. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18371. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18372. wc_AesFree(&aes);
  18373. #endif
  18374. return EXPECT_RESULT();
  18375. } /* END test_wc_AesCcmSetKey */
  18376. /*
  18377. * Unit test function for wc_AesCcmEncrypt and wc_AesCcmDecrypt
  18378. */
  18379. static int test_wc_AesCcmEncryptDecrypt(void)
  18380. {
  18381. EXPECT_DECLS;
  18382. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  18383. Aes aes;
  18384. const byte key16[] = {
  18385. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18386. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18387. };
  18388. /* plaintext */
  18389. const byte plainT[] = {
  18390. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  18391. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  18392. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  18393. };
  18394. /* nonce */
  18395. const byte iv[] = {
  18396. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  18397. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  18398. };
  18399. const byte c[] = { /* cipher text. */
  18400. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  18401. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  18402. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  18403. };
  18404. const byte t[] = { /* Auth tag */
  18405. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  18406. };
  18407. const byte authIn[] = {
  18408. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  18409. };
  18410. byte cipherOut[sizeof(plainT)];
  18411. byte authTag[sizeof(t)];
  18412. #ifdef HAVE_AES_DECRYPT
  18413. byte plainOut[sizeof(cipherOut)];
  18414. #endif
  18415. XMEMSET(&aes, 0, sizeof(Aes));
  18416. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18417. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18418. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18419. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)), 0);
  18420. ExpectIntEQ(XMEMCMP(cipherOut, c, sizeof(c)), 0);
  18421. ExpectIntEQ(XMEMCMP(t, authTag, sizeof(t)), 0);
  18422. #ifdef HAVE_AES_DECRYPT
  18423. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18424. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)), 0);
  18425. ExpectIntEQ(XMEMCMP(plainOut, plainT, sizeof(plainT)), 0);
  18426. #endif
  18427. /* Pass in bad args. Encrypt*/
  18428. ExpectIntEQ(wc_AesCcmEncrypt(NULL, cipherOut, plainT, sizeof(cipherOut),
  18429. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18430. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18431. ExpectIntEQ(wc_AesCcmEncrypt(&aes, NULL, plainT, sizeof(cipherOut),
  18432. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18433. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18434. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, NULL, sizeof(cipherOut),
  18435. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18436. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18437. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18438. NULL, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18439. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18440. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18441. iv, sizeof(iv), NULL, sizeof(authTag), authIn , sizeof(authIn)),
  18442. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18443. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18444. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18445. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18446. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18447. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18448. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18449. #ifdef HAVE_AES_DECRYPT
  18450. /* Pass in bad args. Decrypt*/
  18451. ExpectIntEQ(wc_AesCcmDecrypt(NULL, plainOut, cipherOut, sizeof(plainOut),
  18452. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18453. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18454. ExpectIntEQ(wc_AesCcmDecrypt(&aes, NULL, cipherOut, sizeof(plainOut),
  18455. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18456. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18457. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, NULL, sizeof(plainOut),
  18458. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18459. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18460. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18461. NULL, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18462. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18463. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18464. iv, sizeof(iv), NULL, sizeof(authTag), authIn, sizeof(authIn)),
  18465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18466. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18467. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18468. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18469. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18470. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18471. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18472. #endif
  18473. wc_AesFree(&aes);
  18474. #endif /* HAVE_AESCCM */
  18475. return EXPECT_RESULT();
  18476. } /* END test_wc_AesCcmEncryptDecrypt */
  18477. #if defined(WOLFSSL_AES_EAX) && \
  18478. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  18479. /*
  18480. * Testing test_wc_AesEaxVectors()
  18481. */
  18482. static int test_wc_AesEaxVectors(void)
  18483. {
  18484. EXPECT_DECLS;
  18485. typedef struct {
  18486. byte key[AES_256_KEY_SIZE];
  18487. int key_length;
  18488. byte iv[AES_BLOCK_SIZE];
  18489. int iv_length;
  18490. byte aad[AES_BLOCK_SIZE * 2];
  18491. int aad_length;
  18492. byte msg[AES_BLOCK_SIZE * 5];
  18493. int msg_length;
  18494. byte ct[AES_BLOCK_SIZE * 5];
  18495. int ct_length;
  18496. byte tag[AES_BLOCK_SIZE];
  18497. int tag_length;
  18498. int valid;
  18499. } AadVector;
  18500. /* Test vectors obtained from Google wycheproof project
  18501. * https://github.com/google/wycheproof
  18502. * from testvectors/aes_eax_test.json
  18503. */
  18504. const AadVector vectors[] = {
  18505. {
  18506. /* key, key length */
  18507. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  18508. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  18509. /* iv, iv length */
  18510. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  18511. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  18512. /* aad, aad length */
  18513. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  18514. /* msg, msg length */
  18515. {0x00}, 0,
  18516. /* ct, ct length */
  18517. {0x00}, 0,
  18518. /* tag, tag length */
  18519. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2, 0x7b,
  18520. 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  18521. /* valid */
  18522. 1,
  18523. },
  18524. {
  18525. /* key, key length */
  18526. {0x91, 0x94, 0x5d, 0x3f, 0x4d, 0xcb, 0xee, 0x0b,
  18527. 0xf4, 0x5e, 0xf5, 0x22, 0x55, 0xf0, 0x95, 0xa4}, 16,
  18528. /* iv, iv length */
  18529. {0xbe, 0xca, 0xf0, 0x43, 0xb0, 0xa2, 0x3d, 0x84,
  18530. 0x31, 0x94, 0xba, 0x97, 0x2c, 0x66, 0xde, 0xbd}, 16,
  18531. /* aad, aad length */
  18532. {0xfa, 0x3b, 0xfd, 0x48, 0x06, 0xeb, 0x53, 0xfa}, 8,
  18533. /* msg, msg length */
  18534. {0xf7, 0xfb}, 2,
  18535. /* ct, ct length */
  18536. {0x19, 0xdd}, 2,
  18537. /* tag, tag length */
  18538. {0x5c, 0x4c, 0x93, 0x31, 0x04, 0x9d, 0x0b, 0xda,
  18539. 0xb0, 0x27, 0x74, 0x08, 0xf6, 0x79, 0x67, 0xe5}, 16,
  18540. /* valid */
  18541. 1,
  18542. },
  18543. {
  18544. /* key, key length */
  18545. {0x01, 0xf7, 0x4a, 0xd6, 0x40, 0x77, 0xf2, 0xe7,
  18546. 0x04, 0xc0, 0xf6, 0x0a, 0xda, 0x3d, 0xd5, 0x23}, 16,
  18547. /* iv, iv length */
  18548. {0x70, 0xc3, 0xdb, 0x4f, 0x0d, 0x26, 0x36, 0x84,
  18549. 0x00, 0xa1, 0x0e, 0xd0, 0x5d, 0x2b, 0xff, 0x5e}, 16,
  18550. /* aad, aad length */
  18551. {0x23, 0x4a, 0x34, 0x63, 0xc1, 0x26, 0x4a, 0xc6}, 8,
  18552. /* msg, msg length */
  18553. {0x1a, 0x47, 0xcb, 0x49, 0x33}, 5,
  18554. /* ct, ct length */
  18555. {0xd8, 0x51, 0xd5, 0xba, 0xe0}, 5,
  18556. /* tag, tag length */
  18557. {0x3a, 0x59, 0xf2, 0x38, 0xa2, 0x3e, 0x39, 0x19,
  18558. 0x9d, 0xc9, 0x26, 0x66, 0x26, 0xc4, 0x0f, 0x80}, 16,
  18559. /* valid */
  18560. 1,
  18561. },
  18562. {
  18563. /* key, key length */
  18564. {0xd0, 0x7c, 0xf6, 0xcb, 0xb7, 0xf3, 0x13, 0xbd,
  18565. 0xde, 0x66, 0xb7, 0x27, 0xaf, 0xd3, 0xc5, 0xe8}, 16,
  18566. /* iv, iv length */
  18567. {0x84, 0x08, 0xdf, 0xff, 0x3c, 0x1a, 0x2b, 0x12,
  18568. 0x92, 0xdc, 0x19, 0x9e, 0x46, 0xb7, 0xd6, 0x17}, 16,
  18569. /* aad, aad length */
  18570. {0x33, 0xcc, 0xe2, 0xea, 0xbf, 0xf5, 0xa7, 0x9d}, 8,
  18571. /* msg, msg length */
  18572. {0x48, 0x1c, 0x9e, 0x39, 0xb1}, 5,
  18573. /* ct, ct length */
  18574. {0x63, 0x2a, 0x9d, 0x13, 0x1a}, 5,
  18575. /* tag, tag length */
  18576. {0xd4, 0xc1, 0x68, 0xa4, 0x22, 0x5d, 0x8e, 0x1f,
  18577. 0xf7, 0x55, 0x93, 0x99, 0x74, 0xa7, 0xbe, 0xde}, 16,
  18578. /* valid */
  18579. 1,
  18580. },
  18581. {
  18582. /* key, key length */
  18583. {0x35, 0xb6, 0xd0, 0x58, 0x00, 0x05, 0xbb, 0xc1,
  18584. 0x2b, 0x05, 0x87, 0x12, 0x45, 0x57, 0xd2, 0xc2}, 16,
  18585. /* iv, iv length */
  18586. {0xfd, 0xb6, 0xb0, 0x66, 0x76, 0xee, 0xdc, 0x5c,
  18587. 0x61, 0xd7, 0x42, 0x76, 0xe1, 0xf8, 0xe8, 0x16}, 16,
  18588. /* aad, aad length */
  18589. {0xae, 0xb9, 0x6e, 0xae, 0xbe, 0x29, 0x70, 0xe9}, 8,
  18590. /* msg, msg length */
  18591. {0x40, 0xd0, 0xc0, 0x7d, 0xa5, 0xe4}, 6,
  18592. /* ct, ct length */
  18593. {0x07, 0x1d, 0xfe, 0x16, 0xc6, 0x75}, 6,
  18594. /* tag, tag length */
  18595. {0xcb, 0x06, 0x77, 0xe5, 0x36, 0xf7, 0x3a, 0xfe,
  18596. 0x6a, 0x14, 0xb7, 0x4e, 0xe4, 0x98, 0x44, 0xdd}, 16,
  18597. /* valid */
  18598. 1,
  18599. },
  18600. {
  18601. /* key, key length */
  18602. {0xbd, 0x8e, 0x6e, 0x11, 0x47, 0x5e, 0x60, 0xb2,
  18603. 0x68, 0x78, 0x4c, 0x38, 0xc6, 0x2f, 0xeb, 0x22}, 16,
  18604. /* iv, iv length */
  18605. {0x6e, 0xac, 0x5c, 0x93, 0x07, 0x2d, 0x8e, 0x85,
  18606. 0x13, 0xf7, 0x50, 0x93, 0x5e, 0x46, 0xda, 0x1b}, 16,
  18607. /* aad, aad length */
  18608. {0xd4, 0x48, 0x2d, 0x1c, 0xa7, 0x8d, 0xce, 0x0f}, 8,
  18609. /* msg, msg length */
  18610. {0x4d, 0xe3, 0xb3, 0x5c, 0x3f, 0xc0, 0x39, 0x24,
  18611. 0x5b, 0xd1, 0xfb, 0x7d}, 12,
  18612. /* ct, ct length */
  18613. {0x83, 0x5b, 0xb4, 0xf1, 0x5d, 0x74, 0x3e, 0x35,
  18614. 0x0e, 0x72, 0x84, 0x14}, 12,
  18615. /* tag, tag length */
  18616. {0xab, 0xb8, 0x64, 0x4f, 0xd6, 0xcc, 0xb8, 0x69,
  18617. 0x47, 0xc5, 0xe1, 0x05, 0x90, 0x21, 0x0a, 0x4f}, 16,
  18618. /* valid */
  18619. 1,
  18620. },
  18621. {
  18622. /* key, key length */
  18623. {0x7c, 0x77, 0xd6, 0xe8, 0x13, 0xbe, 0xd5, 0xac,
  18624. 0x98, 0xba, 0xa4, 0x17, 0x47, 0x7a, 0x2e, 0x7d}, 16,
  18625. /* iv, iv length */
  18626. {0x1a, 0x8c, 0x98, 0xdc, 0xd7, 0x3d, 0x38, 0x39,
  18627. 0x3b, 0x2b, 0xf1, 0x56, 0x9d, 0xee, 0xfc, 0x19}, 16,
  18628. /* aad, aad length */
  18629. {0x65, 0xd2, 0x01, 0x79, 0x90, 0xd6, 0x25, 0x28}, 8,
  18630. /* msg, msg length */
  18631. {0x8b, 0x0a, 0x79, 0x30, 0x6c, 0x9c, 0xe7, 0xed,
  18632. 0x99, 0xda, 0xe4, 0xf8, 0x7f, 0x8d, 0xd6, 0x16,
  18633. 0x36}, 17,
  18634. /* ct, ct length */
  18635. {0x02, 0x08, 0x3e, 0x39, 0x79, 0xda, 0x01, 0x48,
  18636. 0x12, 0xf5, 0x9f, 0x11, 0xd5, 0x26, 0x30, 0xda,
  18637. 0x30}, 17,
  18638. /* tag, tag length */
  18639. {0x13, 0x73, 0x27, 0xd1, 0x06, 0x49, 0xb0, 0xaa,
  18640. 0x6e, 0x1c, 0x18, 0x1d, 0xb6, 0x17, 0xd7, 0xf2}, 16,
  18641. /* valid */
  18642. 1,
  18643. },
  18644. {
  18645. /* key, key length */
  18646. {0x5f, 0xff, 0x20, 0xca, 0xfa, 0xb1, 0x19, 0xca,
  18647. 0x2f, 0xc7, 0x35, 0x49, 0xe2, 0x0f, 0x5b, 0x0d}, 16,
  18648. /* iv, iv length */
  18649. {0xdd, 0xe5, 0x9b, 0x97, 0xd7, 0x22, 0x15, 0x6d,
  18650. 0x4d, 0x9a, 0xff, 0x2b, 0xc7, 0x55, 0x98, 0x26}, 16,
  18651. /* aad, aad length */
  18652. {0x54, 0xb9, 0xf0, 0x4e, 0x6a, 0x09, 0x18, 0x9a}, 8,
  18653. /* msg, msg length */
  18654. {0x1b, 0xda, 0x12, 0x2b, 0xce, 0x8a, 0x8d, 0xba,
  18655. 0xf1, 0x87, 0x7d, 0x96, 0x2b, 0x85, 0x92, 0xdd,
  18656. 0x2d, 0x56}, 18,
  18657. /* ct, ct length */
  18658. {0x2e, 0xc4, 0x7b, 0x2c, 0x49, 0x54, 0xa4, 0x89,
  18659. 0xaf, 0xc7, 0xba, 0x48, 0x97, 0xed, 0xcd, 0xae,
  18660. 0x8c, 0xc3}, 18,
  18661. /* tag, tag length */
  18662. {0x3b, 0x60, 0x45, 0x05, 0x99, 0xbd, 0x02, 0xc9,
  18663. 0x63, 0x82, 0x90, 0x2a, 0xef, 0x7f, 0x83, 0x2a}, 16,
  18664. /* valid */
  18665. 1,
  18666. },
  18667. {
  18668. /* key, key length */
  18669. {0xa4, 0xa4, 0x78, 0x2b, 0xcf, 0xfd, 0x3e, 0xc5,
  18670. 0xe7, 0xef, 0x6d, 0x8c, 0x34, 0xa5, 0x61, 0x23}, 16,
  18671. /* iv, iv length */
  18672. {0xb7, 0x81, 0xfc, 0xf2, 0xf7, 0x5f, 0xa5, 0xa8,
  18673. 0xde, 0x97, 0xa9, 0xca, 0x48, 0xe5, 0x22, 0xec}, 16,
  18674. /* aad, aad length */
  18675. {0x89, 0x9a, 0x17, 0x58, 0x97, 0x56, 0x1d, 0x7e}, 8,
  18676. /* msg, msg length */
  18677. {0x6c, 0xf3, 0x67, 0x20, 0x87, 0x2b, 0x85, 0x13,
  18678. 0xf6, 0xea, 0xb1, 0xa8, 0xa4, 0x44, 0x38, 0xd5,
  18679. 0xef, 0x11}, 18,
  18680. /* ct, ct length */
  18681. {0x0d, 0xe1, 0x8f, 0xd0, 0xfd, 0xd9, 0x1e, 0x7a,
  18682. 0xf1, 0x9f, 0x1d, 0x8e, 0xe8, 0x73, 0x39, 0x38,
  18683. 0xb1, 0xe8}, 18,
  18684. /* tag, tag length */
  18685. {0xe7, 0xf6, 0xd2, 0x23, 0x16, 0x18, 0x10, 0x2f,
  18686. 0xdb, 0x7f, 0xe5, 0x5f, 0xf1, 0x99, 0x17, 0x00}, 16,
  18687. /* valid */
  18688. 1,
  18689. },
  18690. {
  18691. /* key, key length */
  18692. {0x83, 0x95, 0xfc, 0xf1, 0xe9, 0x5b, 0xeb, 0xd6,
  18693. 0x97, 0xbd, 0x01, 0x0b, 0xc7, 0x66, 0xaa, 0xc3}, 16,
  18694. /* iv, iv length */
  18695. {0x22, 0xe7, 0xad, 0xd9, 0x3c, 0xfc, 0x63, 0x93,
  18696. 0xc5, 0x7e, 0xc0, 0xb3, 0xc1, 0x7d, 0x6b, 0x44}, 16,
  18697. /* aad, aad length */
  18698. {0x12, 0x67, 0x35, 0xfc, 0xc3, 0x20, 0xd2, 0x5a}, 8,
  18699. /* msg, msg length */
  18700. {0xca, 0x40, 0xd7, 0x44, 0x6e, 0x54, 0x5f, 0xfa,
  18701. 0xed, 0x3b, 0xd1, 0x2a, 0x74, 0x0a, 0x65, 0x9f,
  18702. 0xfb, 0xbb, 0x3c, 0xea, 0xb7}, 21,
  18703. /* ct, ct length */
  18704. {0xcb, 0x89, 0x20, 0xf8, 0x7a, 0x6c, 0x75, 0xcf,
  18705. 0xf3, 0x96, 0x27, 0xb5, 0x6e, 0x3e, 0xd1, 0x97,
  18706. 0xc5, 0x52, 0xd2, 0x95, 0xa7}, 21,
  18707. /* tag, tag length */
  18708. {0xcf, 0xc4, 0x6a, 0xfc, 0x25, 0x3b, 0x46, 0x52,
  18709. 0xb1, 0xaf, 0x37, 0x95, 0xb1, 0x24, 0xab, 0x6e}, 16,
  18710. /* valid */
  18711. 1,
  18712. },
  18713. {
  18714. /* key, key length */
  18715. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18716. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18717. /* iv, iv length */
  18718. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  18719. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  18720. /* aad, aad length */
  18721. {0x00}, 0,
  18722. /* msg, msg length */
  18723. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18724. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18725. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18726. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18727. /* ct, ct length */
  18728. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  18729. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  18730. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  18731. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  18732. /* tag, tag length */
  18733. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  18734. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  18735. /* valid */
  18736. 1,
  18737. },
  18738. {
  18739. /* key, key length */
  18740. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18741. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18742. /* iv, iv length */
  18743. {0xae, 0xf0, 0x3d, 0x00, 0x59, 0x84, 0x94, 0xe9,
  18744. 0xfb, 0x03, 0xcd, 0x7d, 0x8b, 0x59, 0x08, 0x66}, 16,
  18745. /* aad, aad length */
  18746. {0x00}, 0,
  18747. /* msg, msg length */
  18748. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18749. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18750. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18751. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18752. /* ct, ct length */
  18753. {0xd1, 0x9a, 0xc5, 0x98, 0x49, 0x02, 0x6a, 0x91,
  18754. 0xaa, 0x1b, 0x9a, 0xec, 0x29, 0xb1, 0x1a, 0x20,
  18755. 0x2a, 0x4d, 0x73, 0x9f, 0xd8, 0x6c, 0x28, 0xe3,
  18756. 0xae, 0x3d, 0x58, 0x8e, 0xa2, 0x1d, 0x70, 0xc6}, 32,
  18757. /* tag, tag length */
  18758. {0xc3, 0x0f, 0x6c, 0xd9, 0x20, 0x20, 0x74, 0xed,
  18759. 0x6e, 0x2a, 0x2a, 0x36, 0x0e, 0xac, 0x8c, 0x47}, 16,
  18760. /* valid */
  18761. 1,
  18762. },
  18763. {
  18764. /* key, key length */
  18765. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18766. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18767. /* iv, iv length */
  18768. {0x55, 0xd1, 0x25, 0x11, 0xc6, 0x96, 0xa8, 0x0d,
  18769. 0x05, 0x14, 0xd1, 0xff, 0xba, 0x49, 0xca, 0xda}, 16,
  18770. /* aad, aad length */
  18771. {0x00}, 0,
  18772. /* msg, msg length */
  18773. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18774. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18775. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18776. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18777. /* ct, ct length */
  18778. {0x21, 0x08, 0x55, 0x8a, 0xc4, 0xb2, 0xc2, 0xd5,
  18779. 0xcc, 0x66, 0xce, 0xa5, 0x1d, 0x62, 0x10, 0xe0,
  18780. 0x46, 0x17, 0x7a, 0x67, 0x63, 0x1c, 0xd2, 0xdd,
  18781. 0x8f, 0x09, 0x46, 0x97, 0x33, 0xac, 0xb5, 0x17}, 32,
  18782. /* tag, tag length */
  18783. {0xfc, 0x35, 0x5e, 0x87, 0xa2, 0x67, 0xbe, 0x3a,
  18784. 0xe3, 0xe4, 0x4c, 0x0b, 0xf3, 0xf9, 0x9b, 0x2b}, 16,
  18785. /* valid */
  18786. 1,
  18787. },
  18788. {
  18789. /* key, key length */
  18790. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18791. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18792. /* iv, iv length */
  18793. {0x79, 0x42, 0x2d, 0xdd, 0x91, 0xc4, 0xee, 0xe2,
  18794. 0xde, 0xae, 0xf1, 0xf9, 0x68, 0x30, 0x53, 0x04}, 16,
  18795. /* aad, aad length */
  18796. {0x00}, 0,
  18797. /* msg, msg length */
  18798. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18799. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18800. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18801. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18802. /* ct, ct length */
  18803. {0x4d, 0x2c, 0x15, 0x24, 0xca, 0x4b, 0xaa, 0x4e,
  18804. 0xef, 0xcc, 0xe6, 0xb9, 0x1b, 0x22, 0x7e, 0xe8,
  18805. 0x3a, 0xba, 0xff, 0x81, 0x05, 0xdc, 0xaf, 0xa2,
  18806. 0xab, 0x19, 0x1f, 0x5d, 0xf2, 0x57, 0x50, 0x35}, 32,
  18807. /* tag, tag length */
  18808. {0xe2, 0xc8, 0x65, 0xce, 0x2d, 0x7a, 0xbd, 0xac,
  18809. 0x02, 0x4c, 0x6f, 0x99, 0x1a, 0x84, 0x83, 0x90}, 16,
  18810. /* valid */
  18811. 1,
  18812. },
  18813. {
  18814. /* key, key length */
  18815. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18816. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18817. /* iv, iv length */
  18818. {0x0a, 0xf5, 0xaa, 0x7a, 0x76, 0x76, 0xe2, 0x83,
  18819. 0x06, 0x30, 0x6b, 0xcd, 0x9b, 0xf2, 0x00, 0x3a}, 16,
  18820. /* aad, aad length */
  18821. {0x00}, 0,
  18822. /* msg, msg length */
  18823. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18824. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18825. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18826. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18827. /* ct, ct length */
  18828. {0x8e, 0xb0, 0x1e, 0x62, 0x18, 0x5d, 0x78, 0x2e,
  18829. 0xb9, 0x28, 0x7a, 0x34, 0x1a, 0x68, 0x62, 0xac,
  18830. 0x52, 0x57, 0xd6, 0xf9, 0xad, 0xc9, 0x9e, 0xe0,
  18831. 0xa2, 0x4d, 0x9c, 0x22, 0xb3, 0xe9, 0xb3, 0x8a}, 32,
  18832. /* tag, tag length */
  18833. {0x39, 0xc3, 0x39, 0xbc, 0x8a, 0x74, 0xc7, 0x5e,
  18834. 0x2c, 0x65, 0xc6, 0x11, 0x95, 0x44, 0xd6, 0x1e}, 16,
  18835. /* valid */
  18836. 1,
  18837. },
  18838. {
  18839. /* key, key length */
  18840. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18841. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18842. /* iv, iv length */
  18843. {0xaf, 0x5a, 0x03, 0xae, 0x7e, 0xdd, 0x73, 0x47,
  18844. 0x1b, 0xdc, 0xdf, 0xac, 0x5e, 0x19, 0x4a, 0x60}, 16,
  18845. /* aad, aad length */
  18846. {0x00}, 0,
  18847. /* msg, msg length */
  18848. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18849. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18850. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18851. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18852. /* ct, ct length */
  18853. {0x94, 0xc5, 0xd2, 0xac, 0xa6, 0xdb, 0xbc, 0xe8,
  18854. 0xc2, 0x45, 0x13, 0xa2, 0x5e, 0x09, 0x5c, 0x0e,
  18855. 0x54, 0xa9, 0x42, 0x86, 0x0d, 0x32, 0x7a, 0x22,
  18856. 0x2a, 0x81, 0x5c, 0xc7, 0x13, 0xb1, 0x63, 0xb4}, 32,
  18857. /* tag, tag length */
  18858. {0xf5, 0x0b, 0x30, 0x30, 0x4e, 0x45, 0xc9, 0xd4,
  18859. 0x11, 0xe8, 0xdf, 0x45, 0x08, 0xa9, 0x86, 0x12}, 16,
  18860. /* valid */
  18861. 1,
  18862. },
  18863. {
  18864. /* key, key length */
  18865. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18866. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18867. /* iv, iv length */
  18868. {0xb3, 0x70, 0x87, 0x68, 0x0f, 0x0e, 0xdd, 0x5a,
  18869. 0x52, 0x22, 0x8b, 0x8c, 0x7a, 0xae, 0xa6, 0x64}, 16,
  18870. /* aad, aad length */
  18871. {0x00}, 0,
  18872. /* msg, msg length */
  18873. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18874. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18875. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18876. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18877. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  18878. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  18879. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  18880. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, 64,
  18881. /* ct, ct length */
  18882. {0x3b, 0xb6, 0x17, 0x3e, 0x37, 0x72, 0xd4, 0xb6,
  18883. 0x2e, 0xef, 0x37, 0xf9, 0xef, 0x07, 0x81, 0xf3,
  18884. 0x60, 0xb6, 0xc7, 0x4b, 0xe3, 0xbf, 0x6b, 0x37,
  18885. 0x10, 0x67, 0xbc, 0x1b, 0x09, 0x0d, 0x9d, 0x66,
  18886. 0x22, 0xa1, 0xfb, 0xec, 0x6a, 0xc4, 0x71, 0xb3,
  18887. 0x34, 0x9c, 0xd4, 0x27, 0x7a, 0x10, 0x1d, 0x40,
  18888. 0x89, 0x0f, 0xbf, 0x27, 0xdf, 0xdc, 0xd0, 0xb4,
  18889. 0xe3, 0x78, 0x1f, 0x98, 0x06, 0xda, 0xab, 0xb6}, 64,
  18890. /* tag, tag length */
  18891. {0xa0, 0x49, 0x87, 0x45, 0xe5, 0x99, 0x99, 0xdd,
  18892. 0xc3, 0x2d, 0x5b, 0x14, 0x02, 0x41, 0x12, 0x4e}, 16,
  18893. /* valid */
  18894. 1,
  18895. },
  18896. {
  18897. /* key, key length */
  18898. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18899. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18900. /* iv, iv length */
  18901. {0x4f, 0x80, 0x2d, 0xa6, 0x2a, 0x38, 0x45, 0x55,
  18902. 0xa1, 0x9b, 0xc2, 0xb3, 0x82, 0xeb, 0x25, 0xaf}, 16,
  18903. /* aad, aad length */
  18904. {0x00}, 0,
  18905. /* msg, msg length */
  18906. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18907. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18908. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18909. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18910. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  18911. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  18912. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  18913. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  18914. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
  18915. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, 80,
  18916. /* ct, ct length */
  18917. {0xe9, 0xb0, 0xbb, 0x88, 0x57, 0x81, 0x8c, 0xe3,
  18918. 0x20, 0x1c, 0x36, 0x90, 0xd2, 0x1d, 0xaa, 0x7f,
  18919. 0x26, 0x4f, 0xb8, 0xee, 0x93, 0xcc, 0x7a, 0x46,
  18920. 0x74, 0xea, 0x2f, 0xc3, 0x2b, 0xf1, 0x82, 0xfb,
  18921. 0x2a, 0x7e, 0x8a, 0xd5, 0x15, 0x07, 0xad, 0x4f,
  18922. 0x31, 0xce, 0xfc, 0x23, 0x56, 0xfe, 0x79, 0x36,
  18923. 0xa7, 0xf6, 0xe1, 0x9f, 0x95, 0xe8, 0x8f, 0xdb,
  18924. 0xf1, 0x76, 0x20, 0x91, 0x6d, 0x3a, 0x6f, 0x3d,
  18925. 0x01, 0xfc, 0x17, 0xd3, 0x58, 0x67, 0x2f, 0x77,
  18926. 0x7f, 0xd4, 0x09, 0x92, 0x46, 0xe4, 0x36, 0xe1}, 80,
  18927. /* tag, tag length */
  18928. {0x67, 0x91, 0x0b, 0xe7, 0x44, 0xb8, 0x31, 0x5a,
  18929. 0xe0, 0xeb, 0x61, 0x24, 0x59, 0x0c, 0x5d, 0x8b}, 16,
  18930. /* valid */
  18931. 1,
  18932. },
  18933. {
  18934. /* key, key length */
  18935. {0xb6, 0x7b, 0x1a, 0x6e, 0xfd, 0xd4, 0x0d, 0x37,
  18936. 0x08, 0x0f, 0xbe, 0x8f, 0x80, 0x47, 0xae, 0xb9}, 16,
  18937. /* iv, iv length */
  18938. {0xfa, 0x29, 0x4b, 0x12, 0x99, 0x72, 0xf7, 0xfc,
  18939. 0x5b, 0xbd, 0x5b, 0x96, 0xbb, 0xa8, 0x37, 0xc9}, 16,
  18940. /* aad, aad length */
  18941. {0x00}, 0,
  18942. /* msg, msg length */
  18943. {0x00}, 0,
  18944. /* ct, ct length */
  18945. {0x00}, 0,
  18946. /* tag, tag length */
  18947. {0xb1, 0x4b, 0x64, 0xfb, 0x58, 0x98, 0x99, 0x69,
  18948. 0x95, 0x70, 0xcc, 0x91, 0x60, 0xe3, 0x98, 0x96}, 16,
  18949. /* valid */
  18950. 1,
  18951. },
  18952. {
  18953. /* key, key length */
  18954. {0x20, 0x9e, 0x6d, 0xbf, 0x2a, 0xd2, 0x6a, 0x10,
  18955. 0x54, 0x45, 0xfc, 0x02, 0x07, 0xcd, 0x9e, 0x9a}, 16,
  18956. /* iv, iv length */
  18957. {0x94, 0x77, 0x84, 0x9d, 0x6c, 0xcd, 0xfc, 0xa1,
  18958. 0x12, 0xd9, 0x2e, 0x53, 0xfa, 0xe4, 0xa7, 0xca}, 16,
  18959. /* aad, aad length */
  18960. {0x00}, 0,
  18961. /* msg, msg length */
  18962. {0x01}, 1,
  18963. /* ct, ct length */
  18964. {0x1d}, 1,
  18965. /* tag, tag length */
  18966. {0x52, 0xa5, 0xf6, 0x00, 0xfe, 0x53, 0x38, 0x02,
  18967. 0x6a, 0x7c, 0xb0, 0x9c, 0x11, 0x64, 0x00, 0x82}, 16,
  18968. /* valid */
  18969. 1,
  18970. },
  18971. {
  18972. /* key, key length */
  18973. {0xa5, 0x49, 0x44, 0x2e, 0x35, 0x15, 0x40, 0x32,
  18974. 0xd0, 0x7c, 0x86, 0x66, 0x00, 0x6a, 0xa6, 0xa2}, 16,
  18975. /* iv, iv length */
  18976. {0x51, 0x71, 0x52, 0x45, 0x68, 0xe8, 0x1d, 0x97,
  18977. 0xe8, 0xc4, 0xde, 0x4b, 0xa5, 0x6c, 0x10, 0xa0}, 16,
  18978. /* aad, aad length */
  18979. {0x00}, 0,
  18980. /* msg, msg length */
  18981. {0x11, 0x82, 0xe9, 0x35, 0x96, 0xca, 0xc5, 0x60,
  18982. 0x89, 0x46, 0x40, 0x0b, 0xc7, 0x3f, 0x3a}, 15,
  18983. /* ct, ct length */
  18984. {0xd7, 0xb8, 0xa6, 0xb4, 0x3d, 0x2e, 0x9f, 0x98,
  18985. 0xc2, 0xb4, 0x4c, 0xe5, 0xe3, 0xcf, 0xdb}, 15,
  18986. /* tag, tag length */
  18987. {0x1b, 0xdd, 0x52, 0xfc, 0x98, 0x7d, 0xaf, 0x0e,
  18988. 0xe1, 0x92, 0x34, 0xc9, 0x05, 0xea, 0x64, 0x5f}, 16,
  18989. /* valid */
  18990. 1,
  18991. },
  18992. {
  18993. /* key, key length */
  18994. {0x95, 0x8b, 0xcd, 0xb6, 0x6a, 0x39, 0x52, 0xb5,
  18995. 0x37, 0x01, 0x58, 0x2a, 0x68, 0xa0, 0xe4, 0x74}, 16,
  18996. /* iv, iv length */
  18997. {0x0e, 0x6e, 0xc8, 0x79, 0xb0, 0x2c, 0x6f, 0x51,
  18998. 0x69, 0x76, 0xe3, 0x58, 0x98, 0x42, 0x8d, 0xa7}, 16,
  18999. /* aad, aad length */
  19000. {0x00}, 0,
  19001. /* msg, msg length */
  19002. {0x14, 0x04, 0x15, 0x82, 0x3e, 0xcc, 0x89, 0x32,
  19003. 0xa0, 0x58, 0x38, 0x4b, 0x73, 0x8e, 0xa6, 0xea,
  19004. 0x6d, 0x4d, 0xfe, 0x3b, 0xbe, 0xee}, 22,
  19005. /* ct, ct length */
  19006. {0x73, 0xe5, 0xc6, 0xf0, 0xe7, 0x03, 0xa5, 0x2d,
  19007. 0x02, 0xf7, 0xf7, 0xfa, 0xeb, 0x1b, 0x77, 0xfd,
  19008. 0x4f, 0xd0, 0xcb, 0x42, 0x1e, 0xaf}, 22,
  19009. /* tag, tag length */
  19010. {0x6c, 0x15, 0x4a, 0x85, 0x96, 0x8e, 0xdd, 0x74,
  19011. 0x77, 0x65, 0x75, 0xa4, 0x45, 0x0b, 0xd8, 0x97}, 16,
  19012. /* valid */
  19013. 1,
  19014. },
  19015. {
  19016. /* key, key length */
  19017. {0x96, 0x5b, 0x75, 0x7b, 0xa5, 0x01, 0x8a, 0x8d,
  19018. 0x66, 0xed, 0xc7, 0x8e, 0x0c, 0xee, 0xe8, 0x6b}, 16,
  19019. /* iv, iv length */
  19020. {0x2e, 0x35, 0x90, 0x1a, 0xe7, 0xd4, 0x91, 0xee,
  19021. 0xcc, 0x88, 0x38, 0xfe, 0xdd, 0x63, 0x14, 0x05}, 16,
  19022. /* aad, aad length */
  19023. {0xdf, 0x10, 0xd0, 0xd2, 0x12, 0x24, 0x24, 0x50}, 8,
  19024. /* msg, msg length */
  19025. {0x36, 0xe5, 0x7a, 0x76, 0x39, 0x58, 0xb0, 0x2c,
  19026. 0xea, 0x9d, 0x6a, 0x67, 0x6e, 0xbc, 0xe8, 0x1f}, 16,
  19027. /* ct, ct length */
  19028. {0x93, 0x6b, 0x69, 0xb6, 0xc9, 0x55, 0xad, 0xfd,
  19029. 0x15, 0x53, 0x9b, 0x9b, 0xe4, 0x98, 0x9c, 0xb6}, 16,
  19030. /* tag, tag length */
  19031. {0xee, 0x15, 0xa1, 0x45, 0x4e, 0x88, 0xfa, 0xad,
  19032. 0x8e, 0x48, 0xa8, 0xdf, 0x29, 0x83, 0xb4, 0x25}, 16,
  19033. /* valid */
  19034. 1,
  19035. },
  19036. {
  19037. /* key, key length */
  19038. {0x88, 0xd0, 0x20, 0x33, 0x78, 0x1c, 0x7b, 0x41,
  19039. 0x64, 0x71, 0x1a, 0x05, 0x42, 0x0f, 0x25, 0x6e}, 16,
  19040. /* iv, iv length */
  19041. {0x7f, 0x29, 0x85, 0x29, 0x63, 0x15, 0x50, 0x7a,
  19042. 0xa4, 0xc0, 0xa9, 0x3d, 0x5c, 0x12, 0xbd, 0x77}, 16,
  19043. /* aad, aad length */
  19044. {0x7c, 0x57, 0x1d, 0x2f, 0xbb, 0x5f, 0x62, 0x52,
  19045. 0x3c, 0x0e, 0xb3, 0x38, 0xbe, 0xf9, 0xa9}, 15,
  19046. /* msg, msg length */
  19047. {0xd9, 0x8a, 0xdc, 0x03, 0xd9, 0xd5, 0x82, 0x73,
  19048. 0x2e, 0xb0, 0x7d, 0xf2, 0x3d, 0x7b, 0x9f, 0x74}, 16,
  19049. /* ct, ct length */
  19050. {0x67, 0xca, 0xac, 0x35, 0x44, 0x3a, 0x31, 0x38,
  19051. 0xd2, 0xcb, 0x81, 0x1f, 0x0c, 0xe0, 0x4d, 0xd2}, 16,
  19052. /* tag, tag length */
  19053. {0xb7, 0x96, 0x8e, 0x0b, 0x56, 0x40, 0xe3, 0xb2,
  19054. 0x36, 0x56, 0x96, 0x53, 0x20, 0x8b, 0x9d, 0xeb}, 16,
  19055. /* valid */
  19056. 1,
  19057. },
  19058. {
  19059. /* key, key length */
  19060. {0x51, 0x58, 0x40, 0xcf, 0x67, 0xd2, 0xe4, 0x0e,
  19061. 0xb6, 0x5e, 0x54, 0xa2, 0x4c, 0x72, 0xcb, 0xf2}, 16,
  19062. /* iv, iv length */
  19063. {0xbf, 0x47, 0xaf, 0xdf, 0xd4, 0x92, 0x13, 0x7a,
  19064. 0x24, 0x23, 0x6b, 0xc3, 0x67, 0x97, 0xa8, 0x8e}, 16,
  19065. /* aad, aad length */
  19066. {0x16, 0x84, 0x3c, 0x09, 0x1d, 0x43, 0xb0, 0xa1,
  19067. 0x91, 0xd0, 0xc7, 0x3d, 0x15, 0x60, 0x1b, 0xe9}, 16,
  19068. /* msg, msg length */
  19069. {0xc8, 0x34, 0x58, 0x8c, 0xb6, 0xda, 0xf9, 0xf0,
  19070. 0x6d, 0xd2, 0x35, 0x19, 0xf4, 0xbe, 0x9f, 0x56}, 16,
  19071. /* ct, ct length */
  19072. {0x20, 0x0a, 0xc4, 0x51, 0xfb, 0xeb, 0x0f, 0x61,
  19073. 0x51, 0xd6, 0x15, 0x83, 0xa4, 0x3b, 0x73, 0x43}, 16,
  19074. /* tag, tag length */
  19075. {0x2a, 0xd4, 0x3e, 0x4c, 0xaa, 0x51, 0x98, 0x3a,
  19076. 0x9d, 0x4d, 0x24, 0x48, 0x1b, 0xf4, 0xc8, 0x39}, 16,
  19077. /* valid */
  19078. 1,
  19079. },
  19080. {
  19081. /* key, key length */
  19082. {0x2e, 0x44, 0x92, 0xd4, 0x44, 0xe5, 0xb6, 0xf4,
  19083. 0xce, 0xc8, 0xc2, 0xd3, 0x61, 0x5a, 0xc8, 0x58}, 16,
  19084. /* iv, iv length */
  19085. {0xd0, 0x2b, 0xf0, 0x76, 0x3a, 0x9f, 0xef, 0xbf,
  19086. 0x70, 0xc3, 0x3a, 0xee, 0x1e, 0x9d, 0xa1, 0xd6}, 16,
  19087. /* aad, aad length */
  19088. {0x90, 0x4d, 0x86, 0xf1, 0x33, 0xce, 0xc1, 0x5a,
  19089. 0x0c, 0x3c, 0xaf, 0x14, 0xd7, 0xe0, 0x29, 0xc8,
  19090. 0x2a, 0x07, 0x70, 0x5a, 0x23, 0xf0, 0xd0, 0x80}, 24,
  19091. /* msg, msg length */
  19092. {0x9e, 0x62, 0xd6, 0x51, 0x1b, 0x0b, 0xda, 0x7d,
  19093. 0xd7, 0x74, 0x0b, 0x61, 0x4d, 0x97, 0xba, 0xe0}, 16,
  19094. /* ct, ct length */
  19095. {0x27, 0xc6, 0xe9, 0xa6, 0x53, 0xc5, 0x25, 0x3c,
  19096. 0xa1, 0xc5, 0x67, 0x3f, 0x97, 0xb9, 0xb3, 0x3e}, 16,
  19097. /* tag, tag length */
  19098. {0x2d, 0x58, 0x12, 0x71, 0xe1, 0xfa, 0x9e, 0x36,
  19099. 0x86, 0x13, 0x6c, 0xaa, 0x8f, 0x4d, 0x6c, 0x8e}, 16,
  19100. /* valid */
  19101. 1,
  19102. },
  19103. {
  19104. /* key, key length */
  19105. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19106. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19107. /* iv, iv length */
  19108. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19109. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19110. /* aad, aad length */
  19111. {0x00}, 0,
  19112. /* msg, msg length */
  19113. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19114. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19115. /* ct, ct length */
  19116. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19117. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19118. /* tag, tag length */
  19119. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19120. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19121. /* valid */
  19122. 0,
  19123. },
  19124. {
  19125. /* key, key length */
  19126. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19127. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19128. /* iv, iv length */
  19129. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19130. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19131. /* aad, aad length */
  19132. {0x00}, 0,
  19133. /* msg, msg length */
  19134. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19135. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19136. /* ct, ct length */
  19137. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19138. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19139. /* tag, tag length */
  19140. {0xe4, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19141. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19142. /* valid */
  19143. 0,
  19144. },
  19145. {
  19146. /* key, key length */
  19147. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19148. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19149. /* iv, iv length */
  19150. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19151. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19152. /* aad, aad length */
  19153. {0x00}, 0,
  19154. /* msg, msg length */
  19155. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19156. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19157. /* ct, ct length */
  19158. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19159. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19160. /* tag, tag length */
  19161. {0x66, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19162. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19163. /* valid */
  19164. 0,
  19165. },
  19166. {
  19167. /* key, key length */
  19168. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19169. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19170. /* iv, iv length */
  19171. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19172. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19173. /* aad, aad length */
  19174. {0x00}, 0,
  19175. /* msg, msg length */
  19176. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19177. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19178. /* ct, ct length */
  19179. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19180. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19181. /* tag, tag length */
  19182. {0xe6, 0x0f, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19183. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19184. /* valid */
  19185. 0,
  19186. },
  19187. {
  19188. /* key, key length */
  19189. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19190. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19191. /* iv, iv length */
  19192. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19193. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19194. /* aad, aad length */
  19195. {0x00}, 0,
  19196. /* msg, msg length */
  19197. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19198. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19199. /* ct, ct length */
  19200. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19201. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19202. /* tag, tag length */
  19203. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0xf2,
  19204. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19205. /* valid */
  19206. 0,
  19207. },
  19208. {
  19209. /* key, key length */
  19210. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19211. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19212. /* iv, iv length */
  19213. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19214. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19215. /* aad, aad length */
  19216. {0x00}, 0,
  19217. /* msg, msg length */
  19218. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19219. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19220. /* ct, ct length */
  19221. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19222. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19223. /* tag, tag length */
  19224. {0xe6, 0x0e, 0x7c, 0x50, 0x12, 0xa6, 0xdb, 0xf2,
  19225. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19226. /* valid */
  19227. 0,
  19228. },
  19229. {
  19230. /* key, key length */
  19231. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19232. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19233. /* iv, iv length */
  19234. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19235. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19236. /* aad, aad length */
  19237. {0x00}, 0,
  19238. /* msg, msg length */
  19239. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19240. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19241. /* ct, ct length */
  19242. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19243. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19244. /* tag, tag length */
  19245. {0xe6, 0x0e, 0x7c, 0x50, 0x11, 0xa6, 0xdb, 0xf2,
  19246. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19247. /* valid */
  19248. 0,
  19249. },
  19250. {
  19251. /* key, key length */
  19252. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19253. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19254. /* iv, iv length */
  19255. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19256. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19257. /* aad, aad length */
  19258. {0x00}, 0,
  19259. /* msg, msg length */
  19260. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19261. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19262. /* ct, ct length */
  19263. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19264. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19265. /* tag, tag length */
  19266. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19267. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19268. /* valid */
  19269. 0,
  19270. },
  19271. {
  19272. /* key, key length */
  19273. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19274. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19275. /* iv, iv length */
  19276. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19277. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19278. /* aad, aad length */
  19279. {0x00}, 0,
  19280. /* msg, msg length */
  19281. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19282. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19283. /* ct, ct length */
  19284. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19285. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19286. /* tag, tag length */
  19287. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19288. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19289. /* valid */
  19290. 0,
  19291. },
  19292. {
  19293. /* key, key length */
  19294. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19295. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19296. /* iv, iv length */
  19297. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19298. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19299. /* aad, aad length */
  19300. {0x00}, 0,
  19301. /* msg, msg length */
  19302. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19303. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19304. /* ct, ct length */
  19305. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19306. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19307. /* tag, tag length */
  19308. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19309. 0xd2, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19310. /* valid */
  19311. 0,
  19312. },
  19313. {
  19314. /* key, key length */
  19315. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19316. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19317. /* iv, iv length */
  19318. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19319. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19320. /* aad, aad length */
  19321. {0x00}, 0,
  19322. /* msg, msg length */
  19323. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19324. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19325. /* ct, ct length */
  19326. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19327. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19328. /* tag, tag length */
  19329. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19330. 0x52, 0xb8, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19331. /* valid */
  19332. 0,
  19333. },
  19334. {
  19335. /* key, key length */
  19336. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19337. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19338. /* iv, iv length */
  19339. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19340. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19341. /* aad, aad length */
  19342. {0x00}, 0,
  19343. /* msg, msg length */
  19344. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19345. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19346. /* ct, ct length */
  19347. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19348. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19349. /* tag, tag length */
  19350. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19351. 0x52, 0x98, 0xb0, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19352. /* valid */
  19353. 0,
  19354. },
  19355. {
  19356. /* key, key length */
  19357. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19358. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19359. /* iv, iv length */
  19360. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19361. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19362. /* aad, aad length */
  19363. {0x00}, 0,
  19364. /* msg, msg length */
  19365. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19366. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19367. /* ct, ct length */
  19368. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19369. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19370. /* tag, tag length */
  19371. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19372. 0x52, 0x98, 0xb1, 0x92, 0x9a, 0xc3, 0x56, 0xa7}, 16,
  19373. /* valid */
  19374. 0,
  19375. },
  19376. {
  19377. /* key, key length */
  19378. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19379. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19380. /* iv, iv length */
  19381. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19382. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19383. /* aad, aad length */
  19384. {0x00}, 0,
  19385. /* msg, msg length */
  19386. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19387. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19388. /* ct, ct length */
  19389. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19390. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19391. /* tag, tag length */
  19392. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19393. 0x52, 0x98, 0xb1, 0x92, 0x99, 0xc3, 0x56, 0xa7}, 16,
  19394. /* valid */
  19395. 0,
  19396. },
  19397. {
  19398. /* key, key length */
  19399. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19400. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19401. /* iv, iv length */
  19402. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19403. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19404. /* aad, aad length */
  19405. {0x00}, 0,
  19406. /* msg, msg length */
  19407. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19408. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19409. /* ct, ct length */
  19410. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19411. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19412. /* tag, tag length */
  19413. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19414. 0x52, 0x98, 0xb1, 0x92, 0x1b, 0xc3, 0x56, 0xa7}, 16,
  19415. /* valid */
  19416. 0,
  19417. },
  19418. {
  19419. /* key, key length */
  19420. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19421. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19422. /* iv, iv length */
  19423. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19424. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19425. /* aad, aad length */
  19426. {0x00}, 0,
  19427. /* msg, msg length */
  19428. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19429. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19430. /* ct, ct length */
  19431. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19432. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19433. /* tag, tag length */
  19434. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19435. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa6}, 16,
  19436. /* valid */
  19437. 0,
  19438. },
  19439. {
  19440. /* key, key length */
  19441. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19442. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19443. /* iv, iv length */
  19444. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19445. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19446. /* aad, aad length */
  19447. {0x00}, 0,
  19448. /* msg, msg length */
  19449. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19450. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19451. /* ct, ct length */
  19452. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19453. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19454. /* tag, tag length */
  19455. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19456. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa5}, 16,
  19457. /* valid */
  19458. 0,
  19459. },
  19460. {
  19461. /* key, key length */
  19462. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19463. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19464. /* iv, iv length */
  19465. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19466. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19467. /* aad, aad length */
  19468. {0x00}, 0,
  19469. /* msg, msg length */
  19470. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19471. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19472. /* ct, ct length */
  19473. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19474. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19475. /* tag, tag length */
  19476. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19477. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xe7}, 16,
  19478. /* valid */
  19479. 0,
  19480. },
  19481. {
  19482. /* key, key length */
  19483. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19484. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19485. /* iv, iv length */
  19486. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19487. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19488. /* aad, aad length */
  19489. {0x00}, 0,
  19490. /* msg, msg length */
  19491. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19492. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19493. /* ct, ct length */
  19494. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19495. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19496. /* tag, tag length */
  19497. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19498. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  19499. /* valid */
  19500. 0,
  19501. },
  19502. {
  19503. /* key, key length */
  19504. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19505. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19506. /* iv, iv length */
  19507. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19508. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19509. /* aad, aad length */
  19510. {0x00}, 0,
  19511. /* msg, msg length */
  19512. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19513. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19514. /* ct, ct length */
  19515. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19516. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19517. /* tag, tag length */
  19518. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19519. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19520. /* valid */
  19521. 0,
  19522. },
  19523. {
  19524. /* key, key length */
  19525. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19526. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19527. /* iv, iv length */
  19528. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19529. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19530. /* aad, aad length */
  19531. {0x00}, 0,
  19532. /* msg, msg length */
  19533. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19534. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19535. /* ct, ct length */
  19536. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19537. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19538. /* tag, tag length */
  19539. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0x72,
  19540. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19541. /* valid */
  19542. 0,
  19543. },
  19544. {
  19545. /* key, key length */
  19546. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19547. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19548. /* iv, iv length */
  19549. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19550. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19551. /* aad, aad length */
  19552. {0x00}, 0,
  19553. /* msg, msg length */
  19554. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19555. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19556. /* ct, ct length */
  19557. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19558. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19559. /* tag, tag length */
  19560. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19561. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  19562. /* valid */
  19563. 0,
  19564. },
  19565. {
  19566. /* key, key length */
  19567. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19568. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19569. /* iv, iv length */
  19570. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19571. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19572. /* aad, aad length */
  19573. {0x00}, 0,
  19574. /* msg, msg length */
  19575. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19576. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19577. /* ct, ct length */
  19578. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19579. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19580. /* tag, tag length */
  19581. {0x19, 0xf1, 0x83, 0xaf, 0xec, 0x59, 0x24, 0x0d,
  19582. 0xad, 0x67, 0x4e, 0x6d, 0x64, 0x3c, 0xa9, 0x58}, 16,
  19583. /* valid */
  19584. 0,
  19585. },
  19586. {
  19587. /* key, key length */
  19588. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19589. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19590. /* iv, iv length */
  19591. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19592. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19593. /* aad, aad length */
  19594. {0x00}, 0,
  19595. /* msg, msg length */
  19596. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19597. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19598. /* ct, ct length */
  19599. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19600. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19601. /* tag, tag length */
  19602. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19603. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 16,
  19604. /* valid */
  19605. 0,
  19606. },
  19607. {
  19608. /* key, key length */
  19609. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19610. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19611. /* iv, iv length */
  19612. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19613. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19614. /* aad, aad length */
  19615. {0x00}, 0,
  19616. /* msg, msg length */
  19617. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19618. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19619. /* ct, ct length */
  19620. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19621. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19622. /* tag, tag length */
  19623. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  19624. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 16,
  19625. /* valid */
  19626. 0,
  19627. },
  19628. {
  19629. /* key, key length */
  19630. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19631. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19632. /* iv, iv length */
  19633. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19634. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19635. /* aad, aad length */
  19636. {0x00}, 0,
  19637. /* msg, msg length */
  19638. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19639. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19640. /* ct, ct length */
  19641. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19642. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19643. /* tag, tag length */
  19644. {0x66, 0x8e, 0xfc, 0xd0, 0x93, 0x26, 0x5b, 0x72,
  19645. 0xd2, 0x18, 0x31, 0x12, 0x1b, 0x43, 0xd6, 0x27}, 16,
  19646. /* valid */
  19647. 0,
  19648. },
  19649. {
  19650. /* key, key length */
  19651. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19652. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19653. /* iv, iv length */
  19654. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19655. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19656. /* aad, aad length */
  19657. {0x00}, 0,
  19658. /* msg, msg length */
  19659. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19660. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19661. /* ct, ct length */
  19662. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19663. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19664. /* tag, tag length */
  19665. {0xe7, 0x0f, 0x7d, 0x51, 0x12, 0xa7, 0xda, 0xf3,
  19666. 0x53, 0x99, 0xb0, 0x93, 0x9a, 0xc2, 0x57, 0xa6}, 16,
  19667. /* valid */
  19668. 0,
  19669. },
  19670. };
  19671. byte ciphertext[sizeof(vectors[0].ct)];
  19672. byte authtag[sizeof(vectors[0].tag)];
  19673. int i;
  19674. int len;
  19675. int ret;
  19676. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  19677. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  19678. len = sizeof(authtag);
  19679. ExpectIntEQ(wc_AesEaxEncryptAuth(vectors[i].key, vectors[i].key_length,
  19680. ciphertext,
  19681. vectors[i].msg, vectors[i].msg_length,
  19682. vectors[i].iv, vectors[i].iv_length,
  19683. authtag, len,
  19684. vectors[i].aad, vectors[i].aad_length),
  19685. 0);
  19686. /* check ciphertext matches vector */
  19687. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].ct, vectors[i].ct_length),
  19688. 0);
  19689. /* check that computed tag matches vector only for vectors marked as valid */
  19690. ret = XMEMCMP(authtag, vectors[i].tag, len);
  19691. if (vectors[i].valid) {
  19692. ExpectIntEQ(ret, 0);
  19693. }
  19694. else {
  19695. ExpectIntNE(ret, 0);
  19696. }
  19697. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  19698. /* Decrypt, checking that the computed auth tags match */
  19699. ExpectIntEQ(wc_AesEaxDecryptAuth(vectors[i].key, vectors[i].key_length,
  19700. ciphertext,
  19701. vectors[i].ct, vectors[i].ct_length,
  19702. vectors[i].iv, vectors[i].iv_length,
  19703. authtag, len,
  19704. vectors[i].aad, vectors[i].aad_length),
  19705. 0);
  19706. /* check decrypted ciphertext matches vector plaintext */
  19707. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].msg, vectors[i].msg_length),
  19708. 0);
  19709. }
  19710. return EXPECT_RESULT();
  19711. } /* END test_wc_AesEaxVectors */
  19712. /*
  19713. * Testing test_wc_AesEaxEncryptAuth()
  19714. */
  19715. static int test_wc_AesEaxEncryptAuth(void)
  19716. {
  19717. EXPECT_DECLS;
  19718. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19719. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  19720. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  19721. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  19722. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19723. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  19724. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  19725. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  19726. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  19727. const byte msg[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  19728. byte ciphertext[sizeof(msg)];
  19729. byte authtag[AES_BLOCK_SIZE];
  19730. int i;
  19731. int len;
  19732. len = sizeof(authtag);
  19733. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19734. ciphertext,
  19735. msg, sizeof(msg),
  19736. iv, sizeof(iv),
  19737. authtag, (word32)len,
  19738. aad, sizeof(aad)),
  19739. 0);
  19740. /* Test null checking */
  19741. ExpectIntEQ(wc_AesEaxEncryptAuth(NULL, sizeof(key),
  19742. ciphertext,
  19743. msg, sizeof(msg),
  19744. iv, sizeof(iv),
  19745. authtag, (word32)len,
  19746. aad, sizeof(aad)),
  19747. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19748. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19749. NULL,
  19750. msg, sizeof(msg),
  19751. iv, sizeof(iv),
  19752. authtag, (word32)len,
  19753. aad, sizeof(aad)),
  19754. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19755. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19756. ciphertext,
  19757. NULL, sizeof(msg),
  19758. iv, sizeof(iv),
  19759. authtag, (word32)len,
  19760. aad, sizeof(aad)),
  19761. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19762. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19763. ciphertext,
  19764. msg, sizeof(msg),
  19765. NULL, sizeof(iv),
  19766. authtag, (word32)len,
  19767. aad, sizeof(aad)),
  19768. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19769. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19770. ciphertext,
  19771. msg, sizeof(msg),
  19772. iv, sizeof(iv),
  19773. NULL, (word32)len,
  19774. aad, sizeof(aad)),
  19775. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19776. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19777. ciphertext,
  19778. msg, sizeof(msg),
  19779. iv, sizeof(iv),
  19780. authtag, (word32)len,
  19781. NULL, sizeof(aad)),
  19782. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19783. /* Test bad key lengths */
  19784. for (i = 0; i <= 32; i++) {
  19785. int exp_ret;
  19786. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  19787. || i == AES_256_KEY_SIZE) {
  19788. exp_ret = 0;
  19789. }
  19790. else {
  19791. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  19792. }
  19793. ExpectIntEQ(wc_AesEaxEncryptAuth(key, (word32)i,
  19794. ciphertext,
  19795. msg, sizeof(msg),
  19796. iv, sizeof(iv),
  19797. authtag, (word32)len,
  19798. aad, sizeof(aad)),
  19799. exp_ret);
  19800. }
  19801. /* Test auth tag size out of range */
  19802. len = AES_BLOCK_SIZE + 1;
  19803. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19804. ciphertext,
  19805. msg, sizeof(msg),
  19806. iv, sizeof(iv),
  19807. authtag, (word32)len,
  19808. aad, sizeof(aad)),
  19809. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19810. return EXPECT_RESULT();
  19811. } /* END test_wc_AesEaxEncryptAuth() */
  19812. /*
  19813. * Testing test_wc_AesEaxDecryptAuth()
  19814. */
  19815. static int test_wc_AesEaxDecryptAuth(void)
  19816. {
  19817. EXPECT_DECLS;
  19818. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19819. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  19820. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  19821. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  19822. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19823. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  19824. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  19825. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  19826. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  19827. const byte ct[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  19828. /* Garbage tag that should always fail for above aad */
  19829. const byte tag[] = {0xFE, 0xED, 0xBE, 0xEF, 0xDE, 0xAD, 0xC0, 0xDE,
  19830. 0xCA, 0xFE, 0xBE, 0xEF, 0xDE, 0xAF, 0xBE, 0xEF};
  19831. byte plaintext[sizeof(ct)];
  19832. int i;
  19833. int len;
  19834. len = sizeof(tag);
  19835. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  19836. plaintext,
  19837. ct, sizeof(ct),
  19838. iv, sizeof(iv),
  19839. tag, (word32)len,
  19840. aad, sizeof(aad)),
  19841. WC_NO_ERR_TRACE(AES_EAX_AUTH_E));
  19842. /* Test null checking */
  19843. ExpectIntEQ(wc_AesEaxDecryptAuth(NULL, sizeof(key),
  19844. plaintext,
  19845. ct, sizeof(ct),
  19846. iv, sizeof(iv),
  19847. tag, (word32)len,
  19848. aad, sizeof(aad)),
  19849. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19850. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  19851. NULL,
  19852. ct, sizeof(ct),
  19853. iv, sizeof(iv),
  19854. tag, (word32)len,
  19855. aad, sizeof(aad)),
  19856. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19857. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  19858. plaintext,
  19859. NULL, sizeof(ct),
  19860. iv, sizeof(iv),
  19861. tag, (word32)len,
  19862. aad, sizeof(aad)),
  19863. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19864. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  19865. plaintext,
  19866. ct, sizeof(ct),
  19867. NULL, sizeof(iv),
  19868. tag, (word32)len,
  19869. aad, sizeof(aad)),
  19870. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19871. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  19872. plaintext,
  19873. ct, sizeof(ct),
  19874. iv, sizeof(iv),
  19875. NULL, (word32)len,
  19876. aad, sizeof(aad)),
  19877. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19878. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  19879. plaintext,
  19880. ct, sizeof(ct),
  19881. iv, sizeof(iv),
  19882. tag, (word32)len,
  19883. NULL, sizeof(aad)),
  19884. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19885. /* Test bad key lengths */
  19886. for (i = 0; i <= 32; i++) {
  19887. int exp_ret;
  19888. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  19889. || i == AES_256_KEY_SIZE) {
  19890. exp_ret = WC_NO_ERR_TRACE(AES_EAX_AUTH_E);
  19891. }
  19892. else {
  19893. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  19894. }
  19895. ExpectIntEQ(wc_AesEaxDecryptAuth(key, (word32)i,
  19896. plaintext,
  19897. ct, sizeof(ct),
  19898. iv, sizeof(iv),
  19899. tag, (word32)len,
  19900. aad, sizeof(aad)),
  19901. exp_ret);
  19902. }
  19903. /* Test auth tag size out of range */
  19904. len = AES_BLOCK_SIZE + 1;
  19905. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  19906. plaintext,
  19907. ct, sizeof(ct),
  19908. iv, sizeof(iv),
  19909. tag, (word32)len,
  19910. aad, sizeof(aad)),
  19911. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19912. return EXPECT_RESULT();
  19913. } /* END test_wc_AesEaxDecryptAuth() */
  19914. #endif /* WOLFSSL_AES_EAX &&
  19915. * (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) && !HAVE_SELFTEST
  19916. */
  19917. /*
  19918. * Testing wc_InitDsaKey()
  19919. */
  19920. static int test_wc_InitDsaKey(void)
  19921. {
  19922. EXPECT_DECLS;
  19923. #ifndef NO_DSA
  19924. DsaKey key;
  19925. XMEMSET(&key, 0, sizeof(DsaKey));
  19926. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  19927. /* Pass in bad args. */
  19928. ExpectIntEQ(wc_InitDsaKey(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19929. wc_FreeDsaKey(&key);
  19930. #endif
  19931. return EXPECT_RESULT();
  19932. } /* END test_wc_InitDsaKey */
  19933. /*
  19934. * Testing wc_DsaSign() and wc_DsaVerify()
  19935. */
  19936. static int test_wc_DsaSignVerify(void)
  19937. {
  19938. EXPECT_DECLS;
  19939. #if !defined(NO_DSA)
  19940. DsaKey key;
  19941. WC_RNG rng;
  19942. wc_Sha sha;
  19943. byte signature[DSA_SIG_SIZE];
  19944. byte hash[WC_SHA_DIGEST_SIZE];
  19945. word32 idx = 0;
  19946. word32 bytes;
  19947. int answer;
  19948. #ifdef USE_CERT_BUFFERS_1024
  19949. byte tmp[ONEK_BUF];
  19950. XMEMSET(tmp, 0, sizeof(tmp));
  19951. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  19952. bytes = sizeof_dsa_key_der_1024;
  19953. #elif defined(USE_CERT_BUFFERS_2048)
  19954. byte tmp[TWOK_BUF];
  19955. XMEMSET(tmp, 0, sizeof(tmp));
  19956. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  19957. bytes = sizeof_dsa_key_der_2048;
  19958. #else
  19959. byte tmp[TWOK_BUF];
  19960. XFILE fp = XBADFILE;
  19961. XMEMSET(tmp, 0, sizeof(tmp));
  19962. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  19963. ExpectTrue((bytes = (word32)XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  19964. if (fp != XBADFILE)
  19965. XFCLOSE(fp);
  19966. #endif /* END USE_CERT_BUFFERS_1024 */
  19967. ExpectIntEQ(wc_InitSha(&sha), 0);
  19968. ExpectIntEQ(wc_ShaUpdate(&sha, tmp, bytes), 0);
  19969. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  19970. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  19971. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  19972. ExpectIntEQ(wc_InitRng(&rng), 0);
  19973. /* Sign. */
  19974. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), 0);
  19975. /* Test bad args. */
  19976. ExpectIntEQ(wc_DsaSign(NULL, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19977. ExpectIntEQ(wc_DsaSign(hash, NULL, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19978. ExpectIntEQ(wc_DsaSign(hash, signature, NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19979. ExpectIntEQ(wc_DsaSign(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19980. /* Verify. */
  19981. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), 0);
  19982. ExpectIntEQ(answer, 1);
  19983. /* Pass in bad args. */
  19984. ExpectIntEQ(wc_DsaVerify(NULL, signature, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19985. ExpectIntEQ(wc_DsaVerify(hash, NULL, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19986. ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19987. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19988. #if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
  19989. /* hard set q to 0 and test fail case */
  19990. mp_free(&key.q);
  19991. mp_init(&key.q);
  19992. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19993. mp_set(&key.q, 1);
  19994. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19995. #endif
  19996. DoExpectIntEQ(wc_FreeRng(&rng),0);
  19997. wc_FreeDsaKey(&key);
  19998. wc_ShaFree(&sha);
  19999. #endif
  20000. return EXPECT_RESULT();
  20001. } /* END test_wc_DsaSign */
  20002. /*
  20003. * Testing wc_DsaPrivateKeyDecode() and wc_DsaPublicKeyDecode()
  20004. */
  20005. static int test_wc_DsaPublicPrivateKeyDecode(void)
  20006. {
  20007. EXPECT_DECLS;
  20008. #if !defined(NO_DSA)
  20009. DsaKey key;
  20010. word32 bytes = 0;
  20011. word32 idx = 0;
  20012. int ret = 0;
  20013. #ifdef USE_CERT_BUFFERS_1024
  20014. byte tmp[ONEK_BUF];
  20015. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20016. bytes = sizeof_dsa_key_der_1024;
  20017. #elif defined(USE_CERT_BUFFERS_2048)
  20018. byte tmp[TWOK_BUF];
  20019. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20020. bytes = sizeof_dsa_key_der_2048;
  20021. #else
  20022. byte tmp[TWOK_BUF];
  20023. XFILE fp = XBADFILE;
  20024. XMEMSET(tmp, 0, sizeof(tmp));
  20025. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20026. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20027. if (fp != XBADFILE)
  20028. XFCLOSE(fp);
  20029. #endif /* END USE_CERT_BUFFERS_1024 */
  20030. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20031. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20032. /* Test bad args. */
  20033. ExpectIntEQ(wc_DsaPrivateKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20034. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20035. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20036. ExpectIntLT(ret = wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20037. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20038. wc_FreeDsaKey(&key);
  20039. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20040. idx = 0; /* Reset */
  20041. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20042. /* Test bad args. */
  20043. ExpectIntEQ(wc_DsaPublicKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20044. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20045. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20046. ExpectIntLT(ret = wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20047. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20048. wc_FreeDsaKey(&key);
  20049. #endif /* !NO_DSA */
  20050. return EXPECT_RESULT();
  20051. } /* END test_wc_DsaPublicPrivateKeyDecode */
  20052. /*
  20053. * Testing wc_MakeDsaKey() and wc_MakeDsaParameters()
  20054. */
  20055. static int test_wc_MakeDsaKey(void)
  20056. {
  20057. EXPECT_DECLS;
  20058. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20059. DsaKey genKey;
  20060. WC_RNG rng;
  20061. XMEMSET(&genKey, 0, sizeof(genKey));
  20062. XMEMSET(&rng, 0, sizeof(rng));
  20063. ExpectIntEQ(wc_InitDsaKey(&genKey), 0);
  20064. ExpectIntEQ(wc_InitRng(&rng), 0);
  20065. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &genKey), 0);
  20066. /* Test bad args. */
  20067. ExpectIntEQ(wc_MakeDsaParameters(NULL, ONEK_BUF, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20068. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20069. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF + 1, &genKey),
  20070. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20071. ExpectIntEQ(wc_MakeDsaKey(&rng, &genKey), 0);
  20072. /* Test bad args. */
  20073. ExpectIntEQ(wc_MakeDsaKey(NULL, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20074. ExpectIntEQ(wc_MakeDsaKey(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20075. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20076. wc_FreeDsaKey(&genKey);
  20077. #endif
  20078. return EXPECT_RESULT();
  20079. } /* END test_wc_MakeDsaKey */
  20080. /*
  20081. * Testing wc_DsaKeyToDer()
  20082. */
  20083. static int test_wc_DsaKeyToDer(void)
  20084. {
  20085. EXPECT_DECLS;
  20086. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20087. DsaKey key;
  20088. word32 bytes;
  20089. word32 idx = 0;
  20090. #ifdef USE_CERT_BUFFERS_1024
  20091. byte tmp[ONEK_BUF];
  20092. byte der[ONEK_BUF];
  20093. XMEMSET(tmp, 0, sizeof(tmp));
  20094. XMEMSET(der, 0, sizeof(der));
  20095. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20096. bytes = sizeof_dsa_key_der_1024;
  20097. #elif defined(USE_CERT_BUFFERS_2048)
  20098. byte tmp[TWOK_BUF];
  20099. byte der[TWOK_BUF];
  20100. XMEMSET(tmp, 0, sizeof(tmp));
  20101. XMEMSET(der, 0, sizeof(der));
  20102. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20103. bytes = sizeof_dsa_key_der_2048;
  20104. #else
  20105. byte tmp[TWOK_BUF];
  20106. byte der[TWOK_BUF];
  20107. XFILE fp = XBADFILE;
  20108. XMEMSET(tmp, 0, sizeof(tmp));
  20109. XMEMSET(der, 0, sizeof(der));
  20110. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20111. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20112. if (fp != XBADFILE)
  20113. XFCLOSE(fp);
  20114. #endif /* END USE_CERT_BUFFERS_1024 */
  20115. XMEMSET(&key, 0, sizeof(DsaKey));
  20116. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20117. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20118. ExpectIntGE(wc_DsaKeyToDer(&key, der, bytes), 0);
  20119. ExpectIntEQ(XMEMCMP(der, tmp, bytes), 0);
  20120. /* Test bad args. */
  20121. ExpectIntEQ(wc_DsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20122. ExpectIntEQ(wc_DsaKeyToDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20123. wc_FreeDsaKey(&key);
  20124. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20125. return EXPECT_RESULT();
  20126. } /* END test_wc_DsaKeyToDer */
  20127. /*
  20128. * Testing wc_DsaKeyToPublicDer()
  20129. * (indirectly testing setDsaPublicKey())
  20130. */
  20131. static int test_wc_DsaKeyToPublicDer(void)
  20132. {
  20133. EXPECT_DECLS;
  20134. #ifndef HAVE_SELFTEST
  20135. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20136. DsaKey key;
  20137. WC_RNG rng;
  20138. byte* der = NULL;
  20139. word32 sz = 0;
  20140. word32 idx = 0;
  20141. XMEMSET(&key, 0, sizeof(DsaKey));
  20142. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20143. ExpectNotNull(der = (byte*)XMALLOC(ONEK_BUF, NULL,
  20144. DYNAMIC_TYPE_TMP_BUFFER));
  20145. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20146. ExpectIntEQ(wc_InitRng(&rng), 0);
  20147. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &key), 0);
  20148. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20149. ExpectIntGE(sz = (word32)wc_DsaKeyToPublicDer(&key, der, ONEK_BUF), 0);
  20150. wc_FreeDsaKey(&key);
  20151. idx = 0;
  20152. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20153. /* Test without the SubjectPublicKeyInfo header */
  20154. ExpectIntGE(sz = (word32)wc_SetDsaPublicKey(der, &key, ONEK_BUF, 0), 0);
  20155. wc_FreeDsaKey(&key);
  20156. idx = 0;
  20157. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20158. /* Test bad args. */
  20159. ExpectIntEQ(wc_DsaKeyToPublicDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20160. ExpectIntEQ(wc_DsaKeyToPublicDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20161. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20162. wc_FreeDsaKey(&key);
  20163. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  20164. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20165. #endif /* !HAVE_SELFTEST */
  20166. return EXPECT_RESULT();
  20167. } /* END test_wc_DsaKeyToPublicDer */
  20168. /*
  20169. * Testing wc_DsaImportParamsRaw()
  20170. */
  20171. static int test_wc_DsaImportParamsRaw(void)
  20172. {
  20173. EXPECT_DECLS;
  20174. #if !defined(NO_DSA)
  20175. DsaKey key;
  20176. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20177. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20178. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20179. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20180. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20181. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20182. "80a0093113a8bd73";
  20183. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20184. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20185. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20186. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20187. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20188. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20189. "76341a7e7d9";
  20190. /* invalid p and q parameters */
  20191. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20192. const char* invalidQ = "96c5390a";
  20193. XMEMSET(&key, 0, sizeof(DsaKey));
  20194. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20195. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20196. /* test bad args */
  20197. /* null key struct */
  20198. ExpectIntEQ(wc_DsaImportParamsRaw(NULL, p, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20199. /* null param pointers */
  20200. ExpectIntEQ(wc_DsaImportParamsRaw(&key, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20201. /* illegal p length */
  20202. ExpectIntEQ(wc_DsaImportParamsRaw(&key, invalidP, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20203. /* illegal q length */
  20204. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, invalidQ, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20205. wc_FreeDsaKey(&key);
  20206. #endif
  20207. return EXPECT_RESULT();
  20208. } /* END test_wc_DsaImportParamsRaw */
  20209. /*
  20210. * Testing wc_DsaImportParamsRawCheck()
  20211. */
  20212. static int test_wc_DsaImportParamsRawCheck(void)
  20213. {
  20214. EXPECT_DECLS;
  20215. #if !defined(NO_DSA) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20216. DsaKey key;
  20217. int trusted = 0;
  20218. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20219. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20220. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20221. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20222. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20223. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20224. "80a0093113a8bd73";
  20225. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20226. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20227. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20228. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20229. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20230. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20231. "76341a7e7d9";
  20232. /* invalid p and q parameters */
  20233. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20234. const char* invalidQ = "96c5390a";
  20235. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20236. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, q, g, trusted, NULL), 0);
  20237. /* test bad args */
  20238. /* null key struct */
  20239. ExpectIntEQ(wc_DsaImportParamsRawCheck(NULL, p, q, g, trusted, NULL),
  20240. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20241. /* null param pointers */
  20242. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
  20243. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20244. /* illegal p length */
  20245. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
  20246. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20247. /* illegal q length */
  20248. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
  20249. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20250. wc_FreeDsaKey(&key);
  20251. #endif
  20252. return EXPECT_RESULT();
  20253. } /* END test_wc_DsaImportParamsRawCheck */
  20254. /*
  20255. * Testing wc_DsaExportParamsRaw()
  20256. */
  20257. static int test_wc_DsaExportParamsRaw(void)
  20258. {
  20259. EXPECT_DECLS;
  20260. #if !defined(NO_DSA)
  20261. DsaKey key;
  20262. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20263. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20264. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20265. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20266. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20267. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20268. "80a0093113a8bd73";
  20269. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20270. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20271. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20272. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20273. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20274. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20275. "76341a7e7d9";
  20276. const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
  20277. "\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
  20278. "\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
  20279. "\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
  20280. "\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
  20281. "\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
  20282. "\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
  20283. "\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
  20284. "\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
  20285. "\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
  20286. "\x80\xa0\x09\x31\x13\xa8\xbd\x73";
  20287. const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
  20288. "\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
  20289. const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
  20290. "\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
  20291. "\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
  20292. "\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
  20293. "\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
  20294. "\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
  20295. "\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
  20296. "\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
  20297. "\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
  20298. "\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
  20299. "\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
  20300. byte pOut[MAX_DSA_PARAM_SIZE];
  20301. byte qOut[MAX_DSA_PARAM_SIZE];
  20302. byte gOut[MAX_DSA_PARAM_SIZE];
  20303. word32 pOutSz;
  20304. word32 qOutSz;
  20305. word32 gOutSz;
  20306. XMEMSET(&key, 0, sizeof(DsaKey));
  20307. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20308. /* first test using imported raw parameters, for expected */
  20309. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20310. pOutSz = sizeof(pOut);
  20311. qOutSz = sizeof(qOut);
  20312. gOutSz = sizeof(gOut);
  20313. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20314. &gOutSz), 0);
  20315. /* validate exported parameters are correct */
  20316. ExpectIntEQ(XMEMCMP(pOut, pCompare, pOutSz), 0);
  20317. ExpectIntEQ(XMEMCMP(qOut, qCompare, qOutSz), 0);
  20318. ExpectIntEQ(XMEMCMP(gOut, gCompare, gOutSz), 0);
  20319. /* test bad args */
  20320. /* null key struct */
  20321. ExpectIntEQ(wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20322. &gOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20323. /* null output pointers */
  20324. ExpectIntEQ(wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz, NULL,
  20325. &gOutSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20326. /* null output size pointers */
  20327. ExpectIntEQ( wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL, gOut,
  20328. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20329. /* p output buffer size too small */
  20330. pOutSz = 1;
  20331. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20332. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20333. pOutSz = sizeof(pOut);
  20334. /* q output buffer size too small */
  20335. qOutSz = 1;
  20336. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20337. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20338. qOutSz = sizeof(qOut);
  20339. /* g output buffer size too small */
  20340. gOutSz = 1;
  20341. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20342. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20343. wc_FreeDsaKey(&key);
  20344. #endif
  20345. return EXPECT_RESULT();
  20346. } /* END test_wc_DsaExportParamsRaw */
  20347. /*
  20348. * Testing wc_DsaExportKeyRaw()
  20349. */
  20350. static int test_wc_DsaExportKeyRaw(void)
  20351. {
  20352. EXPECT_DECLS;
  20353. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20354. DsaKey key;
  20355. WC_RNG rng;
  20356. byte xOut[MAX_DSA_PARAM_SIZE];
  20357. byte yOut[MAX_DSA_PARAM_SIZE];
  20358. word32 xOutSz, yOutSz;
  20359. XMEMSET(&key, 0, sizeof(key));
  20360. XMEMSET(&rng, 0, sizeof(rng));
  20361. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20362. ExpectIntEQ(wc_InitRng(&rng), 0);
  20363. ExpectIntEQ(wc_MakeDsaParameters(&rng, 1024, &key), 0);
  20364. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20365. /* try successful export */
  20366. xOutSz = sizeof(xOut);
  20367. yOutSz = sizeof(yOut);
  20368. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz), 0);
  20369. /* test bad args */
  20370. /* null key struct */
  20371. ExpectIntEQ(wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz),
  20372. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20373. /* null output pointers */
  20374. ExpectIntEQ(wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz),
  20375. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20376. /* null output size pointers */
  20377. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL),
  20378. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20379. /* x output buffer size too small */
  20380. xOutSz = 1;
  20381. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20382. WC_NO_ERR_TRACE(BUFFER_E));
  20383. xOutSz = sizeof(xOut);
  20384. /* y output buffer size too small */
  20385. yOutSz = 1;
  20386. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20387. WC_NO_ERR_TRACE(BUFFER_E));
  20388. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20389. wc_FreeDsaKey(&key);
  20390. #endif
  20391. return EXPECT_RESULT();
  20392. } /* END test_wc_DsaExportParamsRaw */
  20393. /*
  20394. * Testing wc_ed25519_make_key().
  20395. */
  20396. static int test_wc_ed25519_make_key(void)
  20397. {
  20398. EXPECT_DECLS;
  20399. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  20400. ed25519_key key;
  20401. WC_RNG rng;
  20402. unsigned char pubkey[ED25519_PUB_KEY_SIZE+1];
  20403. int pubkey_sz = ED25519_PUB_KEY_SIZE;
  20404. XMEMSET(&key, 0, sizeof(ed25519_key));
  20405. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20406. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20407. ExpectIntEQ(wc_InitRng(&rng), 0);
  20408. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey, (word32)pubkey_sz),
  20409. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20410. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey+1, (word32)pubkey_sz),
  20411. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20412. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20413. /* Test bad args. */
  20414. ExpectIntEQ(wc_ed25519_make_key(NULL, ED25519_KEY_SIZE, &key),
  20415. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20416. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, NULL),
  20417. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20418. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE - 1, &key),
  20419. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20420. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE + 1, &key),
  20421. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20422. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20423. wc_ed25519_free(&key);
  20424. #endif
  20425. return EXPECT_RESULT();
  20426. } /* END test_wc_ed25519_make_key */
  20427. /*
  20428. * Testing wc_ed25519_init()
  20429. */
  20430. static int test_wc_ed25519_init(void)
  20431. {
  20432. EXPECT_DECLS;
  20433. #if defined(HAVE_ED25519)
  20434. ed25519_key key;
  20435. XMEMSET(&key, 0, sizeof(ed25519_key));
  20436. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20437. /* Test bad args. */
  20438. ExpectIntEQ(wc_ed25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20439. wc_ed25519_free(&key);
  20440. #endif
  20441. return EXPECT_RESULT();
  20442. } /* END test_wc_ed25519_init */
  20443. /*
  20444. * Test wc_ed25519_sign_msg() and wc_ed25519_verify_msg()
  20445. */
  20446. static int test_wc_ed25519_sign_msg(void)
  20447. {
  20448. EXPECT_DECLS;
  20449. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
  20450. WC_RNG rng;
  20451. ed25519_key key;
  20452. byte msg[] = "Everybody gets Friday off.\n";
  20453. byte sig[ED25519_SIG_SIZE+1];
  20454. word32 msglen = sizeof(msg);
  20455. word32 siglen = ED25519_SIG_SIZE;
  20456. word32 badSigLen = ED25519_SIG_SIZE - 1;
  20457. #ifdef HAVE_ED25519_VERIFY
  20458. int verify_ok = 0; /*1 = Verify success.*/
  20459. #endif
  20460. /* Initialize stack variables. */
  20461. XMEMSET(&key, 0, sizeof(ed25519_key));
  20462. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20463. XMEMSET(sig, 0, sizeof(sig));
  20464. /* Initialize key. */
  20465. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20466. ExpectIntEQ(wc_InitRng(&rng), 0);
  20467. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20468. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, &key), 0);
  20469. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20470. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig+1, &siglen, &key), 0);
  20471. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20472. /* Test bad args. */
  20473. ExpectIntEQ(wc_ed25519_sign_msg(NULL, msglen, sig, &siglen, &key),
  20474. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20475. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, NULL, &siglen, &key),
  20476. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20477. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, NULL, &key),
  20478. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20479. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, NULL),
  20480. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20481. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &badSigLen, &key),
  20482. WC_NO_ERR_TRACE(BUFFER_E));
  20483. ExpectIntEQ(badSigLen, ED25519_SIG_SIZE);
  20484. badSigLen -= 1;
  20485. #ifdef HAVE_ED25519_VERIFY
  20486. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20487. &key), 0);
  20488. ExpectIntEQ(verify_ok, 1);
  20489. /* Test bad args. */
  20490. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen - 1, msg, msglen,
  20491. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20492. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen + 1, msg, msglen,
  20493. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20494. ExpectIntEQ(wc_ed25519_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  20495. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20496. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, NULL, msglen, &verify_ok,
  20497. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20498. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, NULL, &key),
  20499. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20500. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20501. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20502. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, badSigLen, msg, msglen, &verify_ok,
  20503. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20504. #endif /* Verify. */
  20505. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20506. wc_ed25519_free(&key);
  20507. #endif
  20508. return EXPECT_RESULT();
  20509. } /* END test_wc_ed25519_sign_msg */
  20510. /*
  20511. * Testing wc_ed25519_import_public()
  20512. */
  20513. static int test_wc_ed25519_import_public(void)
  20514. {
  20515. EXPECT_DECLS;
  20516. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20517. ed25519_key pubKey;
  20518. WC_RNG rng;
  20519. const byte in[] = "Ed25519PublicKeyUnitTest......\n";
  20520. word32 inlen = sizeof(in);
  20521. XMEMSET(&pubKey, 0, sizeof(ed25519_key));
  20522. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20523. ExpectIntEQ(wc_ed25519_init(&pubKey), 0);
  20524. ExpectIntEQ(wc_InitRng(&rng), 0);
  20525. #ifdef HAVE_ED25519_MAKE_KEY
  20526. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &pubKey), 0);
  20527. #endif
  20528. ExpectIntEQ(wc_ed25519_import_public_ex(in, inlen, &pubKey, 1), 0);
  20529. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  20530. /* Test bad args. */
  20531. ExpectIntEQ(wc_ed25519_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20532. ExpectIntEQ(wc_ed25519_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20533. ExpectIntEQ(wc_ed25519_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20534. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20535. wc_ed25519_free(&pubKey);
  20536. #endif
  20537. return EXPECT_RESULT();
  20538. } /* END wc_ed25519_import_public */
  20539. /*
  20540. * Testing wc_ed25519_import_private_key()
  20541. */
  20542. static int test_wc_ed25519_import_private_key(void)
  20543. {
  20544. EXPECT_DECLS;
  20545. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20546. ed25519_key key;
  20547. WC_RNG rng;
  20548. const byte privKey[] = "Ed25519PrivateKeyUnitTest.....\n";
  20549. const byte pubKey[] = "Ed25519PublicKeyUnitTest......\n";
  20550. word32 privKeySz = sizeof(privKey);
  20551. word32 pubKeySz = sizeof(pubKey);
  20552. #ifdef HAVE_ED25519_KEY_EXPORT
  20553. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  20554. word32 bothKeysSz = sizeof(bothKeys);
  20555. #endif
  20556. XMEMSET(&key, 0, sizeof(ed25519_key));
  20557. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20558. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20559. ExpectIntEQ(wc_InitRng(&rng), 0);
  20560. #ifdef HAVE_ED25519_MAKE_KEY
  20561. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20562. #endif
  20563. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, privKeySz, pubKey,
  20564. pubKeySz, &key, 1), 0);
  20565. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  20566. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  20567. #ifdef HAVE_ED25519_KEY_EXPORT
  20568. PRIVATE_KEY_UNLOCK();
  20569. ExpectIntEQ(wc_ed25519_export_private(&key, bothKeys, &bothKeysSz), 0);
  20570. PRIVATE_KEY_LOCK();
  20571. ExpectIntEQ(wc_ed25519_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  20572. &key, 1), 0);
  20573. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  20574. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  20575. #endif
  20576. /* Test bad args. */
  20577. ExpectIntEQ(wc_ed25519_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  20578. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20579. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL,
  20580. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20581. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  20582. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20583. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz - 1, pubKey,
  20584. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20585. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  20586. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20587. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL, 0,
  20588. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20589. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20590. wc_ed25519_free(&key);
  20591. #endif
  20592. return EXPECT_RESULT();
  20593. } /* END test_wc_ed25519_import_private_key */
  20594. /*
  20595. * Testing wc_ed25519_export_public() and wc_ed25519_export_private_only()
  20596. */
  20597. static int test_wc_ed25519_export(void)
  20598. {
  20599. EXPECT_DECLS;
  20600. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  20601. ed25519_key key;
  20602. WC_RNG rng;
  20603. byte priv[ED25519_PRV_KEY_SIZE];
  20604. byte pub[ED25519_PUB_KEY_SIZE];
  20605. word32 privSz = sizeof(priv);
  20606. word32 pubSz = sizeof(pub);
  20607. #ifndef HAVE_ED25519_MAKE_KEY
  20608. const byte privKey[] = {
  20609. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  20610. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  20611. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  20612. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  20613. };
  20614. const byte pubKey[] = {
  20615. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  20616. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  20617. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  20618. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  20619. };
  20620. #endif
  20621. XMEMSET(&key, 0, sizeof(ed25519_key));
  20622. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20623. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20624. ExpectIntEQ(wc_InitRng(&rng), 0);
  20625. #ifdef HAVE_ED25519_MAKE_KEY
  20626. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20627. #else
  20628. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  20629. pubKey, sizeof(pubKey), &key, 1), 0);
  20630. #endif
  20631. PRIVATE_KEY_UNLOCK();
  20632. ExpectIntEQ(wc_ed25519_export_public(&key, pub, &pubSz), 0);
  20633. ExpectIntEQ(pubSz, ED25519_KEY_SIZE);
  20634. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  20635. /* Test bad args. */
  20636. ExpectIntEQ(wc_ed25519_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20637. ExpectIntEQ(wc_ed25519_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20638. ExpectIntEQ(wc_ed25519_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20639. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, &privSz), 0);
  20640. ExpectIntEQ(privSz, ED25519_KEY_SIZE);
  20641. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  20642. /* Test bad args. */
  20643. ExpectIntEQ(wc_ed25519_export_private_only(NULL, priv, &privSz),
  20644. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20645. ExpectIntEQ(wc_ed25519_export_private_only(&key, NULL, &privSz),
  20646. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20647. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, NULL),
  20648. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20649. PRIVATE_KEY_LOCK();
  20650. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20651. wc_ed25519_free(&key);
  20652. #endif
  20653. return EXPECT_RESULT();
  20654. } /* END test_wc_ed25519_export */
  20655. /*
  20656. * Testing wc_ed25519_size()
  20657. */
  20658. static int test_wc_ed25519_size(void)
  20659. {
  20660. EXPECT_DECLS;
  20661. #if defined(HAVE_ED25519)
  20662. ed25519_key key;
  20663. WC_RNG rng;
  20664. #ifndef HAVE_ED25519_MAKE_KEY
  20665. const byte privKey[] = {
  20666. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  20667. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  20668. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  20669. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  20670. };
  20671. const byte pubKey[] = {
  20672. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  20673. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  20674. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  20675. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  20676. };
  20677. #endif
  20678. XMEMSET(&key, 0, sizeof(ed25519_key));
  20679. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20680. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20681. ExpectIntEQ(wc_InitRng(&rng), 0);
  20682. #ifdef HAVE_ED25519_MAKE_KEY
  20683. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20684. #else
  20685. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  20686. pubKey, sizeof(pubKey), &key, 1), 0);
  20687. #endif
  20688. ExpectIntEQ(wc_ed25519_size(&key), ED25519_KEY_SIZE);
  20689. /* Test bad args. */
  20690. ExpectIntEQ(wc_ed25519_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20691. ExpectIntEQ(wc_ed25519_sig_size(&key), ED25519_SIG_SIZE);
  20692. /* Test bad args. */
  20693. ExpectIntEQ(wc_ed25519_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20694. ExpectIntEQ(wc_ed25519_pub_size(&key), ED25519_PUB_KEY_SIZE);
  20695. /* Test bad args. */
  20696. ExpectIntEQ(wc_ed25519_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20697. ExpectIntEQ(wc_ed25519_priv_size(&key), ED25519_PRV_KEY_SIZE);
  20698. /* Test bad args. */
  20699. ExpectIntEQ(wc_ed25519_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20700. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20701. wc_ed25519_free(&key);
  20702. #endif
  20703. return EXPECT_RESULT();
  20704. } /* END test_wc_ed25519_size */
  20705. /*
  20706. * Testing wc_ed25519_export_private() and wc_ed25519_export_key()
  20707. */
  20708. static int test_wc_ed25519_exportKey(void)
  20709. {
  20710. EXPECT_DECLS;
  20711. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  20712. WC_RNG rng;
  20713. ed25519_key key;
  20714. byte priv[ED25519_PRV_KEY_SIZE];
  20715. byte pub[ED25519_PUB_KEY_SIZE];
  20716. byte privOnly[ED25519_PRV_KEY_SIZE];
  20717. word32 privSz = sizeof(priv);
  20718. word32 pubSz = sizeof(pub);
  20719. word32 privOnlySz = sizeof(privOnly);
  20720. #ifndef HAVE_ED25519_MAKE_KEY
  20721. const byte privKey[] = {
  20722. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  20723. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  20724. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  20725. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  20726. };
  20727. const byte pubKey[] = {
  20728. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  20729. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  20730. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  20731. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  20732. };
  20733. #endif
  20734. XMEMSET(&key, 0, sizeof(ed25519_key));
  20735. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20736. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20737. ExpectIntEQ(wc_InitRng(&rng), 0);
  20738. #ifdef HAVE_ED25519_MAKE_KEY
  20739. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20740. #else
  20741. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  20742. pubKey, sizeof(pubKey), &key, 1), 0);
  20743. #endif
  20744. PRIVATE_KEY_UNLOCK();
  20745. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, &privOnlySz), 0);
  20746. /* Test bad args. */
  20747. ExpectIntEQ(wc_ed25519_export_private(NULL, privOnly, &privOnlySz),
  20748. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20749. ExpectIntEQ(wc_ed25519_export_private(&key, NULL, &privOnlySz),
  20750. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20751. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20752. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  20753. /* Test bad args. */
  20754. ExpectIntEQ(wc_ed25519_export_key(NULL, priv, &privSz, pub, &pubSz),
  20755. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20756. ExpectIntEQ(wc_ed25519_export_key(&key, NULL, &privSz, pub, &pubSz),
  20757. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20758. ExpectIntEQ(wc_ed25519_export_key(&key, priv, NULL, pub, &pubSz),
  20759. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20760. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, NULL, &pubSz),
  20761. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20762. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, NULL),
  20763. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20764. PRIVATE_KEY_LOCK();
  20765. /* Cross check output. */
  20766. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  20767. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20768. wc_ed25519_free(&key);
  20769. #endif
  20770. return EXPECT_RESULT();
  20771. } /* END test_wc_ed25519_exportKey */
  20772. /*
  20773. * Testing wc_Ed25519PublicKeyToDer
  20774. */
  20775. static int test_wc_Ed25519PublicKeyToDer(void)
  20776. {
  20777. EXPECT_DECLS;
  20778. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  20779. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  20780. ed25519_key key;
  20781. byte derBuf[1024];
  20782. XMEMSET(&key, 0, sizeof(ed25519_key));
  20783. /* Test bad args */
  20784. ExpectIntEQ(wc_Ed25519PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20785. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20786. ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  20787. wc_ed25519_free(&key);
  20788. /* Test good args */
  20789. if (EXPECT_SUCCESS()) {
  20790. WC_RNG rng;
  20791. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20792. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20793. ExpectIntEQ(wc_InitRng(&rng), 0);
  20794. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20795. /* length only */
  20796. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 0), 0);
  20797. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 1), 0);
  20798. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, derBuf,
  20799. (word32)sizeof(derBuf), 1), 0);
  20800. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20801. wc_ed25519_free(&key);
  20802. }
  20803. #endif
  20804. return EXPECT_RESULT();
  20805. } /* END testing wc_Ed25519PublicKeyToDer */
  20806. /*
  20807. * Testing wc_curve25519_init and wc_curve25519_free.
  20808. */
  20809. static int test_wc_curve25519_init(void)
  20810. {
  20811. EXPECT_DECLS;
  20812. #if defined(HAVE_CURVE25519)
  20813. curve25519_key key;
  20814. ExpectIntEQ(wc_curve25519_init(&key), 0);
  20815. /* Test bad args for wc_curve25519_init */
  20816. ExpectIntEQ(wc_curve25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20817. /* Test good args for wc_curve_25519_free */
  20818. wc_curve25519_free(&key);
  20819. /* Test bad args for wc_curve25519 free. */
  20820. wc_curve25519_free(NULL);
  20821. #endif
  20822. return EXPECT_RESULT();
  20823. } /* END test_wc_curve25519_init and wc_curve_25519_free*/
  20824. /*
  20825. * Testing test_wc_curve25519_size.
  20826. */
  20827. static int test_wc_curve25519_size(void)
  20828. {
  20829. EXPECT_DECLS;
  20830. #if defined(HAVE_CURVE25519)
  20831. curve25519_key key;
  20832. ExpectIntEQ(wc_curve25519_init(&key), 0);
  20833. /* Test good args for wc_curve25519_size */
  20834. ExpectIntEQ(wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  20835. /* Test bad args for wc_curve25519_size */
  20836. ExpectIntEQ(wc_curve25519_size(NULL), 0);
  20837. wc_curve25519_free(&key);
  20838. #endif
  20839. return EXPECT_RESULT();
  20840. } /* END test_wc_curve25519_size*/
  20841. /*
  20842. * Testing test_wc_curve25519_export_key_raw().
  20843. */
  20844. static int test_wc_curve25519_export_key_raw(void)
  20845. {
  20846. EXPECT_DECLS;
  20847. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  20848. curve25519_key key;
  20849. WC_RNG rng;
  20850. byte privateKey[CURVE25519_KEYSIZE];
  20851. byte publicKey[CURVE25519_KEYSIZE];
  20852. word32 prvkSz;
  20853. word32 pubkSz;
  20854. byte prik[CURVE25519_KEYSIZE];
  20855. byte pubk[CURVE25519_KEYSIZE];
  20856. word32 prksz;
  20857. word32 pbksz;
  20858. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20859. ExpectIntEQ(wc_curve25519_init(&key), 0);
  20860. ExpectIntEQ(wc_InitRng(&rng), 0);
  20861. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  20862. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  20863. prvkSz = CURVE25519_KEYSIZE;
  20864. pubkSz = CURVE25519_KEYSIZE;
  20865. ExpectIntEQ(wc_curve25519_export_key_raw(NULL, privateKey, &prvkSz,
  20866. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20867. prvkSz = CURVE25519_KEYSIZE;
  20868. pubkSz = CURVE25519_KEYSIZE;
  20869. ExpectIntEQ(wc_curve25519_export_key_raw(&key, NULL, &prvkSz, publicKey,
  20870. &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20871. prvkSz = CURVE25519_KEYSIZE;
  20872. pubkSz = CURVE25519_KEYSIZE;
  20873. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, NULL,
  20874. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20875. /* prvkSz = CURVE25519_KEYSIZE; */
  20876. pubkSz = CURVE25519_KEYSIZE;
  20877. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  20878. NULL, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20879. prvkSz = CURVE25519_KEYSIZE;
  20880. pubkSz = CURVE25519_KEYSIZE;
  20881. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  20882. publicKey, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20883. /* cross-testing */
  20884. prksz = CURVE25519_KEYSIZE;
  20885. ExpectIntEQ(wc_curve25519_export_private_raw(&key, prik, &prksz), 0);
  20886. pbksz = CURVE25519_KEYSIZE;
  20887. ExpectIntEQ(wc_curve25519_export_public(&key, pubk, &pbksz), 0);
  20888. prvkSz = CURVE25519_KEYSIZE;
  20889. /* pubkSz = CURVE25519_KEYSIZE; */
  20890. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  20891. publicKey, &pubkSz), 0);
  20892. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  20893. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  20894. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  20895. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  20896. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  20897. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  20898. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20899. wc_curve25519_free(&key);
  20900. #endif
  20901. return EXPECT_RESULT();
  20902. } /* end of test_wc_curve25519_export_key_raw */
  20903. /*
  20904. * Testing test_wc_curve25519_export_key_raw_ex().
  20905. */
  20906. static int test_wc_curve25519_export_key_raw_ex(void)
  20907. {
  20908. EXPECT_DECLS;
  20909. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  20910. curve25519_key key;
  20911. WC_RNG rng;
  20912. byte privateKey[CURVE25519_KEYSIZE];
  20913. byte publicKey[CURVE25519_KEYSIZE];
  20914. word32 prvkSz;
  20915. word32 pubkSz;
  20916. byte prik[CURVE25519_KEYSIZE];
  20917. byte pubk[CURVE25519_KEYSIZE];
  20918. word32 prksz;
  20919. word32 pbksz;
  20920. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20921. ExpectIntEQ(wc_curve25519_init(&key), 0);
  20922. ExpectIntEQ(wc_InitRng(&rng), 0);
  20923. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  20924. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  20925. prvkSz = CURVE25519_KEYSIZE;
  20926. pubkSz = CURVE25519_KEYSIZE;
  20927. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  20928. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20929. prvkSz = CURVE25519_KEYSIZE;
  20930. pubkSz = CURVE25519_KEYSIZE;
  20931. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  20932. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20933. prvkSz = CURVE25519_KEYSIZE;
  20934. pubkSz = CURVE25519_KEYSIZE;
  20935. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  20936. NULL, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20937. /* prvkSz = CURVE25519_KEYSIZE; */
  20938. pubkSz = CURVE25519_KEYSIZE;
  20939. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  20940. &prvkSz, NULL, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20941. prvkSz = CURVE25519_KEYSIZE;
  20942. pubkSz = CURVE25519_KEYSIZE;
  20943. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  20944. &prvkSz, publicKey, NULL, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20945. prvkSz = CURVE25519_KEYSIZE;
  20946. /* pubkSz = CURVE25519_KEYSIZE; */
  20947. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  20948. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20949. prvkSz = CURVE25519_KEYSIZE;
  20950. pubkSz = CURVE25519_KEYSIZE;
  20951. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  20952. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20953. prvkSz = CURVE25519_KEYSIZE;
  20954. pubkSz = CURVE25519_KEYSIZE;
  20955. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  20956. NULL, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20957. /* prvkSz = CURVE25519_KEYSIZE; */
  20958. pubkSz = CURVE25519_KEYSIZE;
  20959. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  20960. &prvkSz, NULL, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20961. prvkSz = CURVE25519_KEYSIZE;
  20962. pubkSz = CURVE25519_KEYSIZE;
  20963. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  20964. &prvkSz, publicKey, NULL, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20965. /* illegal value for endian */
  20966. prvkSz = CURVE25519_KEYSIZE;
  20967. /* pubkSz = CURVE25519_KEYSIZE; */
  20968. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  20969. publicKey, NULL, EC25519_BIG_ENDIAN + 10), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20970. /* cross-testing */
  20971. prksz = CURVE25519_KEYSIZE;
  20972. ExpectIntEQ(wc_curve25519_export_private_raw( &key, prik, &prksz), 0);
  20973. pbksz = CURVE25519_KEYSIZE;
  20974. ExpectIntEQ(wc_curve25519_export_public( &key, pubk, &pbksz), 0);
  20975. prvkSz = CURVE25519_KEYSIZE;
  20976. /* pubkSz = CURVE25519_KEYSIZE; */
  20977. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  20978. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  20979. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  20980. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  20981. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  20982. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  20983. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  20984. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  20985. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  20986. publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), 0);
  20987. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  20988. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  20989. /* try once with another endian */
  20990. prvkSz = CURVE25519_KEYSIZE;
  20991. pubkSz = CURVE25519_KEYSIZE;
  20992. ExpectIntEQ(wc_curve25519_export_key_raw_ex( &key, privateKey, &prvkSz,
  20993. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  20994. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  20995. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  20996. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20997. wc_curve25519_free(&key);
  20998. #endif
  20999. return EXPECT_RESULT();
  21000. } /* end of test_wc_curve25519_export_key_raw_ex */
  21001. /*
  21002. * Testing wc_curve25519_make_key
  21003. */
  21004. static int test_wc_curve25519_make_key(void)
  21005. {
  21006. EXPECT_DECLS;
  21007. #if defined(HAVE_CURVE25519)
  21008. curve25519_key key;
  21009. WC_RNG rng;
  21010. int keysize;
  21011. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21012. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21013. ExpectIntEQ(wc_InitRng(&rng), 0);
  21014. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21015. ExpectIntEQ(keysize = wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21016. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, &key), 0);
  21017. /* test bad cases*/
  21018. ExpectIntEQ(wc_curve25519_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21019. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21020. ExpectIntEQ(wc_curve25519_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21021. ExpectIntEQ(wc_curve25519_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21022. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21023. wc_curve25519_free(&key);
  21024. #endif
  21025. return EXPECT_RESULT();
  21026. } /* END test_wc_curve25519_make_key*/
  21027. /*
  21028. * Testing wc_curve25519_shared_secret_ex
  21029. */
  21030. static int test_wc_curve25519_shared_secret_ex(void)
  21031. {
  21032. EXPECT_DECLS;
  21033. #if defined(HAVE_CURVE25519)
  21034. curve25519_key private_key;
  21035. curve25519_key public_key;
  21036. WC_RNG rng;
  21037. byte out[CURVE25519_KEYSIZE];
  21038. word32 outLen = sizeof(out);
  21039. int endian = EC25519_BIG_ENDIAN;
  21040. ExpectIntEQ(wc_curve25519_init(&private_key), 0);
  21041. ExpectIntEQ(wc_curve25519_init(&public_key), 0);
  21042. ExpectIntEQ(wc_InitRng(&rng), 0);
  21043. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &private_key),
  21044. 0);
  21045. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &public_key),
  21046. 0);
  21047. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21048. &outLen, endian), 0);
  21049. /* test bad cases*/
  21050. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21051. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21052. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, &public_key, out, &outLen,
  21053. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21054. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, NULL, out, &outLen,
  21055. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21056. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, NULL,
  21057. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21058. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21059. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21060. /* curve25519.c is checking for public_key size less than or equal to 0x7f,
  21061. * increasing to 0x8f checks for error being returned*/
  21062. public_key.p.point[CURVE25519_KEYSIZE-1] = 0x8F;
  21063. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21064. &outLen, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21065. outLen = outLen - 2;
  21066. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21067. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21068. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21069. wc_curve25519_free(&private_key);
  21070. wc_curve25519_free(&public_key);
  21071. #endif
  21072. return EXPECT_RESULT();
  21073. } /* END test_wc_curve25519_shared_secret_ex*/
  21074. /*
  21075. * Testing wc_curve25519_make_pub
  21076. */
  21077. static int test_wc_curve25519_make_pub(void)
  21078. {
  21079. EXPECT_DECLS;
  21080. #ifdef HAVE_CURVE25519
  21081. curve25519_key key;
  21082. WC_RNG rng;
  21083. byte out[CURVE25519_KEYSIZE];
  21084. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21085. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21086. ExpectIntEQ(wc_InitRng(&rng), 0);
  21087. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21088. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out,
  21089. (int)sizeof(key.k), key.k), 0);
  21090. /* test bad cases*/
  21091. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k,
  21092. (int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21093. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21094. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21095. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out,
  21096. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21097. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL,
  21098. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21099. /* verify clamping test */
  21100. key.k[0] |= ~248;
  21101. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21102. key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21103. key.k[0] &= 248;
  21104. /* repeat the expected-to-succeed test. */
  21105. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21106. key.k), 0);
  21107. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21108. wc_curve25519_free(&key);
  21109. #endif
  21110. return EXPECT_RESULT();
  21111. } /* END test_wc_curve25519_make_pub */
  21112. /*
  21113. * Testing test_wc_curve25519_export_public_ex
  21114. */
  21115. static int test_wc_curve25519_export_public_ex(void)
  21116. {
  21117. EXPECT_DECLS;
  21118. #if defined(HAVE_CURVE25519)
  21119. curve25519_key key;
  21120. WC_RNG rng;
  21121. byte out[CURVE25519_KEYSIZE];
  21122. word32 outLen = sizeof(out);
  21123. int endian = EC25519_BIG_ENDIAN;
  21124. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21125. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21126. ExpectIntEQ(wc_InitRng(&rng), 0);
  21127. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21128. ExpectIntEQ(wc_curve25519_export_public(&key, out, &outLen), 0);
  21129. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian), 0);
  21130. /* test bad cases*/
  21131. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, NULL, NULL, endian),
  21132. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21133. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, out, &outLen, endian),
  21134. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21135. ExpectIntEQ(wc_curve25519_export_public_ex(&key, NULL, &outLen, endian),
  21136. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21137. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, NULL, endian),
  21138. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21139. outLen = outLen - 2;
  21140. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian),
  21141. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21142. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21143. wc_curve25519_free(&key);
  21144. #endif
  21145. return EXPECT_RESULT();
  21146. } /* END test_wc_curve25519_export_public_ex*/
  21147. /*
  21148. * Testing test_wc_curve25519_import_private_raw_ex
  21149. */
  21150. static int test_wc_curve25519_import_private_raw_ex(void)
  21151. {
  21152. EXPECT_DECLS;
  21153. #if defined(HAVE_CURVE25519)
  21154. curve25519_key key;
  21155. WC_RNG rng;
  21156. byte priv[CURVE25519_KEYSIZE];
  21157. byte pub[CURVE25519_KEYSIZE];
  21158. word32 privSz = sizeof(priv);
  21159. word32 pubSz = sizeof(pub);
  21160. int endian = EC25519_BIG_ENDIAN;
  21161. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21162. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21163. ExpectIntEQ(wc_InitRng(&rng), 0);
  21164. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21165. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
  21166. endian), 0);
  21167. ExpectIntEQ(wc_curve25519_export_public(&key, pub, &pubSz), 0);
  21168. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21169. &key, endian), 0);
  21170. /* test bad cases*/
  21171. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, 0, NULL, 0, NULL,
  21172. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21173. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21174. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21175. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21176. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21177. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21178. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21179. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, 0, pub, pubSz,
  21180. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21181. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, 0,
  21182. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21183. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21184. &key, EC25519_LITTLE_ENDIAN), 0);
  21185. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21186. wc_curve25519_free(&key);
  21187. #endif
  21188. return EXPECT_RESULT();
  21189. } /* END test_wc_curve25519_import_private_raw_ex*/
  21190. /*
  21191. * Testing test_wc_curve25519_import_private
  21192. */
  21193. static int test_wc_curve25519_import_private(void)
  21194. {
  21195. EXPECT_DECLS;
  21196. #if defined(HAVE_CURVE25519)
  21197. curve25519_key key;
  21198. WC_RNG rng;
  21199. byte priv[CURVE25519_KEYSIZE];
  21200. word32 privSz = sizeof(priv);
  21201. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21202. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21203. ExpectIntEQ(wc_InitRng(&rng), 0);
  21204. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21205. ExpectIntEQ(wc_curve25519_export_private_raw(&key, priv, &privSz), 0);
  21206. ExpectIntEQ(wc_curve25519_import_private(priv, privSz, &key), 0);
  21207. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21208. wc_curve25519_free(&key);
  21209. #endif
  21210. return EXPECT_RESULT();
  21211. } /* END test_wc_curve25519_import*/
  21212. /*
  21213. * Testing test_wc_curve25519_export_private_raw_ex
  21214. */
  21215. static int test_wc_curve25519_export_private_raw_ex(void)
  21216. {
  21217. EXPECT_DECLS;
  21218. #if defined(HAVE_CURVE25519)
  21219. curve25519_key key;
  21220. byte out[CURVE25519_KEYSIZE];
  21221. word32 outLen = sizeof(out);
  21222. int endian = EC25519_BIG_ENDIAN;
  21223. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21224. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21225. 0);
  21226. /* test bad cases*/
  21227. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, NULL, NULL, endian),
  21228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21229. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, out, &outLen, endian),
  21230. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21231. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, NULL, &outLen,
  21232. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21233. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, NULL, endian),
  21234. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21235. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen,
  21236. EC25519_LITTLE_ENDIAN), 0);
  21237. outLen = outLen - 2;
  21238. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21239. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21240. wc_curve25519_free(&key);
  21241. #endif
  21242. return EXPECT_RESULT();
  21243. } /* END test_wc_curve25519_export_private_raw_ex*/
  21244. /*
  21245. * Testing wc_ed448_make_key().
  21246. */
  21247. static int test_wc_ed448_make_key(void)
  21248. {
  21249. EXPECT_DECLS;
  21250. #if defined(HAVE_ED448)
  21251. ed448_key key;
  21252. WC_RNG rng;
  21253. unsigned char pubkey[ED448_PUB_KEY_SIZE];
  21254. XMEMSET(&key, 0, sizeof(ed448_key));
  21255. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21256. ExpectIntEQ(wc_ed448_init(&key), 0);
  21257. ExpectIntEQ(wc_InitRng(&rng), 0);
  21258. ExpectIntEQ(wc_ed448_make_public(&key, pubkey, sizeof(pubkey)),
  21259. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  21260. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21261. /* Test bad args. */
  21262. ExpectIntEQ(wc_ed448_make_key(NULL, ED448_KEY_SIZE, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21263. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21264. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE - 1, &key),
  21265. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21266. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE + 1, &key),
  21267. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21268. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21269. wc_ed448_free(&key);
  21270. #endif
  21271. return EXPECT_RESULT();
  21272. } /* END test_wc_ed448_make_key */
  21273. /*
  21274. * Testing wc_ed448_init()
  21275. */
  21276. static int test_wc_ed448_init(void)
  21277. {
  21278. EXPECT_DECLS;
  21279. #if defined(HAVE_ED448)
  21280. ed448_key key;
  21281. XMEMSET(&key, 0, sizeof(ed448_key));
  21282. ExpectIntEQ(wc_ed448_init(&key), 0);
  21283. /* Test bad args. */
  21284. ExpectIntEQ(wc_ed448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21285. wc_ed448_free(&key);
  21286. #endif
  21287. return EXPECT_RESULT();
  21288. } /* END test_wc_ed448_init */
  21289. /*
  21290. * Test wc_ed448_sign_msg() and wc_ed448_verify_msg()
  21291. */
  21292. static int test_wc_ed448_sign_msg(void)
  21293. {
  21294. EXPECT_DECLS;
  21295. #if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
  21296. ed448_key key;
  21297. WC_RNG rng;
  21298. byte msg[] = "Everybody gets Friday off.\n";
  21299. byte sig[ED448_SIG_SIZE];
  21300. word32 msglen = sizeof(msg);
  21301. word32 siglen = sizeof(sig);
  21302. word32 badSigLen = sizeof(sig) - 1;
  21303. #ifdef HAVE_ED448_VERIFY
  21304. int verify_ok = 0; /*1 = Verify success.*/
  21305. #endif
  21306. /* Initialize stack variables. */
  21307. XMEMSET(&key, 0, sizeof(ed448_key));
  21308. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21309. XMEMSET(sig, 0, siglen);
  21310. /* Initialize key. */
  21311. ExpectIntEQ(wc_ed448_init(&key), 0);
  21312. ExpectIntEQ(wc_InitRng(&rng), 0);
  21313. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21314. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, &key, NULL, 0), 0);
  21315. ExpectIntEQ(siglen, ED448_SIG_SIZE);
  21316. /* Test bad args. */
  21317. ExpectIntEQ(wc_ed448_sign_msg(NULL, msglen, sig, &siglen, &key, NULL, 0),
  21318. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21319. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, NULL, &siglen, &key, NULL, 0),
  21320. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21321. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, NULL, &key, NULL, 0),
  21322. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21323. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, NULL, NULL, 0),
  21324. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21325. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &badSigLen, &key, NULL, 0),
  21326. WC_NO_ERR_TRACE(BUFFER_E));
  21327. ExpectIntEQ(badSigLen, ED448_SIG_SIZE);
  21328. badSigLen -= 1;
  21329. #ifdef HAVE_ED448_VERIFY
  21330. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok, &key,
  21331. NULL, 0), 0);
  21332. ExpectIntEQ(verify_ok, 1);
  21333. /* Test bad args. */
  21334. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen - 1, msg, msglen, &verify_ok,
  21335. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21336. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen + 1, msg, msglen, &verify_ok,
  21337. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21338. ExpectIntEQ(wc_ed448_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  21339. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21340. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, NULL, msglen, &verify_ok,
  21341. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21342. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, NULL,
  21343. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21344. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok,
  21345. NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21346. ExpectIntEQ(wc_ed448_verify_msg(sig, badSigLen, msg, msglen, &verify_ok,
  21347. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21348. #endif /* Verify. */
  21349. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21350. wc_ed448_free(&key);
  21351. #endif
  21352. return EXPECT_RESULT();
  21353. } /* END test_wc_ed448_sign_msg */
  21354. /*
  21355. * Testing wc_ed448_import_public()
  21356. */
  21357. static int test_wc_ed448_import_public(void)
  21358. {
  21359. EXPECT_DECLS;
  21360. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21361. ed448_key pubKey;
  21362. WC_RNG rng;
  21363. const byte in[] =
  21364. "Ed448PublicKeyUnitTest.................................\n";
  21365. word32 inlen = sizeof(in);
  21366. XMEMSET(&pubKey, 0, sizeof(ed448_key));
  21367. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21368. ExpectIntEQ(wc_ed448_init(&pubKey), 0);
  21369. ExpectIntEQ(wc_InitRng(&rng), 0);
  21370. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &pubKey), 0);
  21371. ExpectIntEQ(wc_ed448_import_public_ex(in, inlen, &pubKey, 1), 0);
  21372. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  21373. /* Test bad args. */
  21374. ExpectIntEQ(wc_ed448_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21375. ExpectIntEQ(wc_ed448_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21376. ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21377. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21378. wc_ed448_free(&pubKey);
  21379. #endif
  21380. return EXPECT_RESULT();
  21381. } /* END wc_ed448_import_public */
  21382. /*
  21383. * Testing wc_ed448_import_private_key()
  21384. */
  21385. static int test_wc_ed448_import_private_key(void)
  21386. {
  21387. EXPECT_DECLS;
  21388. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21389. ed448_key key;
  21390. WC_RNG rng;
  21391. const byte privKey[] =
  21392. "Ed448PrivateKeyUnitTest................................\n";
  21393. const byte pubKey[] =
  21394. "Ed448PublicKeyUnitTest.................................\n";
  21395. word32 privKeySz = sizeof(privKey);
  21396. word32 pubKeySz = sizeof(pubKey);
  21397. #ifdef HAVE_ED448_KEY_EXPORT
  21398. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21399. word32 bothKeysSz = sizeof(bothKeys);
  21400. #endif
  21401. XMEMSET(&key, 0, sizeof(ed448_key));
  21402. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21403. ExpectIntEQ(wc_ed448_init(&key), 0);
  21404. ExpectIntEQ(wc_InitRng(&rng), 0);
  21405. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21406. ExpectIntEQ(wc_ed448_import_private_key_ex(privKey, privKeySz, pubKey,
  21407. pubKeySz, &key, 1), 0);
  21408. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21409. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21410. #ifdef HAVE_ED448_KEY_EXPORT
  21411. PRIVATE_KEY_UNLOCK();
  21412. ExpectIntEQ(wc_ed448_export_private(&key, bothKeys, &bothKeysSz), 0);
  21413. PRIVATE_KEY_LOCK();
  21414. ExpectIntEQ(wc_ed448_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21415. &key, 1), 0);
  21416. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21417. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21418. #endif
  21419. /* Test bad args. */
  21420. ExpectIntEQ(wc_ed448_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21421. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21422. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, pubKeySz,
  21423. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21424. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21425. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21426. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz - 1, pubKey,
  21427. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21428. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21429. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21430. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, 0, &key),
  21431. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21432. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21433. wc_ed448_free(&key);
  21434. #endif
  21435. return EXPECT_RESULT();
  21436. } /* END test_wc_ed448_import_private_key */
  21437. /*
  21438. * Testing wc_ed448_export_public() and wc_ed448_export_private_only()
  21439. */
  21440. static int test_wc_ed448_export(void)
  21441. {
  21442. EXPECT_DECLS;
  21443. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21444. ed448_key key;
  21445. WC_RNG rng;
  21446. byte priv[ED448_PRV_KEY_SIZE];
  21447. byte pub[ED448_PUB_KEY_SIZE];
  21448. word32 privSz = sizeof(priv);
  21449. word32 pubSz = sizeof(pub);
  21450. XMEMSET(&key, 0, sizeof(ed448_key));
  21451. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21452. ExpectIntEQ(wc_ed448_init(&key), 0);
  21453. ExpectIntEQ(wc_InitRng(&rng), 0);
  21454. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21455. ExpectIntEQ(wc_ed448_export_public(&key, pub, &pubSz), 0);
  21456. ExpectIntEQ(pubSz, ED448_KEY_SIZE);
  21457. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21458. /* Test bad args. */
  21459. ExpectIntEQ(wc_ed448_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21460. ExpectIntEQ(wc_ed448_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21461. ExpectIntEQ(wc_ed448_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21462. PRIVATE_KEY_UNLOCK();
  21463. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, &privSz), 0);
  21464. ExpectIntEQ(privSz, ED448_KEY_SIZE);
  21465. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21466. /* Test bad args. */
  21467. ExpectIntEQ(wc_ed448_export_private_only(NULL, priv, &privSz),
  21468. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21469. ExpectIntEQ(wc_ed448_export_private_only(&key, NULL, &privSz),
  21470. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21471. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21472. PRIVATE_KEY_LOCK();
  21473. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21474. wc_ed448_free(&key);
  21475. #endif
  21476. return EXPECT_RESULT();
  21477. } /* END test_wc_ed448_export */
  21478. /*
  21479. * Testing wc_ed448_size()
  21480. */
  21481. static int test_wc_ed448_size(void)
  21482. {
  21483. EXPECT_DECLS;
  21484. #if defined(HAVE_ED448)
  21485. ed448_key key;
  21486. WC_RNG rng;
  21487. XMEMSET(&key, 0, sizeof(ed448_key));
  21488. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21489. ExpectIntEQ(wc_ed448_init(&key), 0);
  21490. ExpectIntEQ(wc_InitRng(&rng), 0);
  21491. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21492. ExpectIntEQ(wc_ed448_size(&key), ED448_KEY_SIZE);
  21493. /* Test bad args. */
  21494. ExpectIntEQ(wc_ed448_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21495. ExpectIntEQ(wc_ed448_sig_size(&key), ED448_SIG_SIZE);
  21496. /* Test bad args. */
  21497. ExpectIntEQ(wc_ed448_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21498. ExpectIntEQ(wc_ed448_pub_size(&key), ED448_PUB_KEY_SIZE);
  21499. /* Test bad args. */
  21500. ExpectIntEQ(wc_ed448_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21501. ExpectIntEQ(wc_ed448_priv_size(&key), ED448_PRV_KEY_SIZE);
  21502. /* Test bad args. */
  21503. ExpectIntEQ(wc_ed448_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21504. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21505. wc_ed448_free(&key);
  21506. #endif
  21507. return EXPECT_RESULT();
  21508. } /* END test_wc_ed448_size */
  21509. /*
  21510. * Testing wc_ed448_export_private() and wc_ed448_export_key()
  21511. */
  21512. static int test_wc_ed448_exportKey(void)
  21513. {
  21514. EXPECT_DECLS;
  21515. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21516. ed448_key key;
  21517. WC_RNG rng;
  21518. byte priv[ED448_PRV_KEY_SIZE];
  21519. byte pub[ED448_PUB_KEY_SIZE];
  21520. byte privOnly[ED448_PRV_KEY_SIZE];
  21521. word32 privSz = sizeof(priv);
  21522. word32 pubSz = sizeof(pub);
  21523. word32 privOnlySz = sizeof(privOnly);
  21524. XMEMSET(&key, 0, sizeof(ed448_key));
  21525. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21526. ExpectIntEQ(wc_ed448_init(&key), 0);
  21527. ExpectIntEQ(wc_InitRng(&rng), 0);
  21528. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21529. PRIVATE_KEY_UNLOCK();
  21530. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, &privOnlySz), 0);
  21531. /* Test bad args. */
  21532. ExpectIntEQ(wc_ed448_export_private(NULL, privOnly, &privOnlySz),
  21533. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21534. ExpectIntEQ(wc_ed448_export_private(&key, NULL, &privOnlySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21535. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21536. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21537. /* Test bad args. */
  21538. ExpectIntEQ(wc_ed448_export_key(NULL, priv, &privSz, pub, &pubSz),
  21539. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21540. ExpectIntEQ(wc_ed448_export_key(&key, NULL, &privSz, pub, &pubSz),
  21541. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21542. ExpectIntEQ(wc_ed448_export_key(&key, priv, NULL, pub, &pubSz),
  21543. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21544. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, NULL, &pubSz),
  21545. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21546. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, NULL),
  21547. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21548. PRIVATE_KEY_LOCK();
  21549. /* Cross check output. */
  21550. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  21551. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21552. wc_ed448_free(&key);
  21553. #endif
  21554. return EXPECT_RESULT();
  21555. } /* END test_wc_ed448_exportKey */
  21556. /*
  21557. * Testing wc_Ed448PublicKeyToDer
  21558. */
  21559. static int test_wc_Ed448PublicKeyToDer(void)
  21560. {
  21561. EXPECT_DECLS;
  21562. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  21563. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  21564. ed448_key key;
  21565. byte derBuf[1024];
  21566. XMEMSET(&key, 0, sizeof(ed448_key));
  21567. /* Test bad args */
  21568. ExpectIntEQ(wc_Ed448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21569. ExpectIntEQ(wc_ed448_init(&key), 0);
  21570. ExpectIntEQ(wc_Ed448PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  21571. wc_ed448_free(&key);
  21572. /* Test good args */
  21573. if (EXPECT_SUCCESS()) {
  21574. WC_RNG rng;
  21575. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21576. ExpectIntEQ(wc_ed448_init(&key), 0);
  21577. ExpectIntEQ(wc_InitRng(&rng), 0);
  21578. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21579. /* length only */
  21580. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 0), 0);
  21581. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 1), 0);
  21582. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, derBuf,
  21583. (word32)sizeof(derBuf), 1), 0);
  21584. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21585. wc_ed448_free(&key);
  21586. }
  21587. #endif
  21588. return EXPECT_RESULT();
  21589. } /* END testing wc_Ed448PublicKeyToDer */
  21590. /*
  21591. * Testing wc_curve448_init and wc_curve448_free.
  21592. */
  21593. static int test_wc_curve448_init(void)
  21594. {
  21595. EXPECT_DECLS;
  21596. #if defined(HAVE_CURVE448)
  21597. curve448_key key;
  21598. /* Test bad args for wc_curve448_init */
  21599. ExpectIntEQ(wc_curve448_init(&key), 0);
  21600. /* Test bad args for wc_curve448_init */
  21601. ExpectIntEQ(wc_curve448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21602. /* Test good args for wc_curve_448_free */
  21603. wc_curve448_free(&key);
  21604. /* Test bad args for wc_curve448_free */
  21605. wc_curve448_free(NULL);
  21606. #endif
  21607. return EXPECT_RESULT();
  21608. } /* END test_wc_curve448_init and wc_curve_448_free*/
  21609. /*
  21610. * Testing wc_curve448_make_key
  21611. */
  21612. static int test_wc_curve448_make_key(void)
  21613. {
  21614. EXPECT_DECLS;
  21615. #if defined(HAVE_CURVE448)
  21616. curve448_key key;
  21617. WC_RNG rng;
  21618. int keysize;
  21619. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21620. ExpectIntEQ(wc_curve448_init(&key), 0);
  21621. ExpectIntEQ(wc_InitRng(&rng), 0);
  21622. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21623. ExpectIntEQ(keysize = wc_curve448_size(&key), CURVE448_KEY_SIZE);
  21624. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, &key), 0);
  21625. /* test bad cases */
  21626. ExpectIntEQ(wc_curve448_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21627. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21628. ExpectIntEQ(wc_curve448_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21629. ExpectIntEQ(wc_curve448_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21630. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21631. wc_curve448_free(&key);
  21632. #endif
  21633. return EXPECT_RESULT();
  21634. } /* END test_wc_curve448_make_key*/
  21635. /*
  21636. * Testing test_wc_curve448_shared_secret_ex
  21637. */
  21638. static int test_wc_curve448_shared_secret_ex(void)
  21639. {
  21640. EXPECT_DECLS;
  21641. #if defined(HAVE_CURVE448)
  21642. curve448_key private_key;
  21643. curve448_key public_key;
  21644. WC_RNG rng;
  21645. byte out[CURVE448_KEY_SIZE];
  21646. word32 outLen = sizeof(out);
  21647. int endian = EC448_BIG_ENDIAN;
  21648. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21649. ExpectIntEQ(wc_curve448_init(&private_key), 0);
  21650. ExpectIntEQ(wc_InitRng(&rng), 0);
  21651. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key), 0);
  21652. ExpectIntEQ(wc_curve448_init(&public_key), 0);
  21653. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key), 0);
  21654. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  21655. &outLen, endian), 0);
  21656. /* test bad cases */
  21657. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21658. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21659. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, &public_key, out, &outLen,
  21660. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21661. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, NULL, out, &outLen,
  21662. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21663. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
  21664. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21665. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  21666. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21667. outLen = outLen - 2;
  21668. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  21669. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21670. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21671. wc_curve448_free(&private_key);
  21672. wc_curve448_free(&public_key);
  21673. #endif
  21674. return EXPECT_RESULT();
  21675. } /* END test_wc_curve448_shared_secret_ex*/
  21676. /*
  21677. * Testing test_wc_curve448_export_public_ex
  21678. */
  21679. static int test_wc_curve448_export_public_ex(void)
  21680. {
  21681. EXPECT_DECLS;
  21682. #if defined(HAVE_CURVE448)
  21683. WC_RNG rng;
  21684. curve448_key key;
  21685. byte out[CURVE448_KEY_SIZE];
  21686. word32 outLen = sizeof(out);
  21687. int endian = EC448_BIG_ENDIAN;
  21688. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21689. ExpectIntEQ(wc_curve448_init(&key), 0);
  21690. ExpectIntEQ(wc_InitRng(&rng), 0);
  21691. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21692. ExpectIntEQ(wc_curve448_export_public(&key, out, &outLen), 0);
  21693. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian), 0);
  21694. /* test bad cases*/
  21695. ExpectIntEQ(wc_curve448_export_public_ex(NULL, NULL, NULL, endian),
  21696. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21697. ExpectIntEQ(wc_curve448_export_public_ex(NULL, out, &outLen, endian),
  21698. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21699. ExpectIntEQ(wc_curve448_export_public_ex(&key, NULL, &outLen, endian),
  21700. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21701. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, NULL, endian),
  21702. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21703. outLen = outLen - 2;
  21704. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian),
  21705. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21706. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21707. wc_curve448_free(&key);
  21708. #endif
  21709. return EXPECT_RESULT();
  21710. } /* END test_wc_curve448_export_public_ex*/
  21711. /*
  21712. * Testing test_wc_curve448_export_private_raw_ex
  21713. */
  21714. static int test_wc_curve448_export_private_raw_ex(void)
  21715. {
  21716. EXPECT_DECLS;
  21717. #if defined(HAVE_CURVE448)
  21718. curve448_key key;
  21719. byte out[CURVE448_KEY_SIZE];
  21720. word32 outLen = sizeof(out);
  21721. int endian = EC448_BIG_ENDIAN;
  21722. ExpectIntEQ(wc_curve448_init(&key), 0);
  21723. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  21724. 0);
  21725. /* test bad cases*/
  21726. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian),
  21727. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21728. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian),
  21729. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21730. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian),
  21731. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21732. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, NULL, endian),
  21733. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21734. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen,
  21735. EC448_LITTLE_ENDIAN), 0);
  21736. outLen = outLen - 2;
  21737. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  21738. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21739. wc_curve448_free(&key);
  21740. #endif
  21741. return EXPECT_RESULT();
  21742. } /* END test_wc_curve448_export_private_raw_ex*/
  21743. /*
  21744. * Testing test_wc_curve448_import_private_raw_ex
  21745. */
  21746. static int test_wc_curve448_import_private_raw_ex(void)
  21747. {
  21748. EXPECT_DECLS;
  21749. #if defined(HAVE_CURVE448)
  21750. curve448_key key;
  21751. WC_RNG rng;
  21752. byte priv[CURVE448_KEY_SIZE];
  21753. byte pub[CURVE448_KEY_SIZE];
  21754. word32 privSz = sizeof(priv);
  21755. word32 pubSz = sizeof(pub);
  21756. int endian = EC448_BIG_ENDIAN;
  21757. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21758. ExpectIntEQ(wc_curve448_init(&key), 0);
  21759. ExpectIntEQ(wc_InitRng(&rng), 0);
  21760. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21761. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  21762. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  21763. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  21764. &key, endian), 0);
  21765. /* test bad cases */
  21766. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0),
  21767. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21768. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21769. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21770. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21771. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21772. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  21773. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21774. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
  21775. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21776. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
  21777. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21778. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  21779. &key, EC448_LITTLE_ENDIAN), 0);
  21780. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21781. wc_curve448_free(&key);
  21782. #endif
  21783. return EXPECT_RESULT();
  21784. } /* END test_wc_curve448_import_private_raw_ex*/
  21785. /*
  21786. * Testing test_curve448_export_key_raw
  21787. */
  21788. static int test_wc_curve448_export_key_raw(void)
  21789. {
  21790. EXPECT_DECLS;
  21791. #if defined(HAVE_CURVE448)
  21792. curve448_key key;
  21793. WC_RNG rng;
  21794. byte priv[CURVE448_KEY_SIZE];
  21795. byte pub[CURVE448_KEY_SIZE];
  21796. word32 privSz = sizeof(priv);
  21797. word32 pubSz = sizeof(pub);
  21798. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21799. ExpectIntEQ(wc_curve448_init(&key), 0);
  21800. ExpectIntEQ(wc_InitRng(&rng), 0);
  21801. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21802. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  21803. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  21804. ExpectIntEQ(wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz),
  21805. 0);
  21806. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21807. wc_curve448_free(&key);
  21808. #endif
  21809. return EXPECT_RESULT();
  21810. } /* END test_wc_curve448_import_private_raw_ex*/
  21811. /*
  21812. * Testing test_wc_curve448_import_private
  21813. */
  21814. static int test_wc_curve448_import_private(void)
  21815. {
  21816. EXPECT_DECLS;
  21817. #if defined(HAVE_CURVE448)
  21818. curve448_key key;
  21819. WC_RNG rng;
  21820. byte priv[CURVE448_KEY_SIZE];
  21821. word32 privSz = sizeof(priv);
  21822. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21823. ExpectIntEQ(wc_curve448_init(&key), 0);
  21824. ExpectIntEQ(wc_InitRng(&rng), 0);
  21825. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21826. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  21827. ExpectIntEQ(wc_curve448_import_private(priv, privSz, &key), 0);
  21828. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21829. wc_curve448_free(&key);
  21830. #endif
  21831. return EXPECT_RESULT();
  21832. } /* END test_wc_curve448_import*/
  21833. /*
  21834. * Testing test_wc_curve448_size.
  21835. */
  21836. static int test_wc_curve448_size(void)
  21837. {
  21838. EXPECT_DECLS;
  21839. #if defined(HAVE_CURVE448)
  21840. curve448_key key;
  21841. ExpectIntEQ(wc_curve448_init(&key), 0);
  21842. /* Test good args for wc_curve448_size */
  21843. ExpectIntEQ(wc_curve448_size(&key), CURVE448_KEY_SIZE);
  21844. /* Test bad args for wc_curve448_size */
  21845. ExpectIntEQ(wc_curve448_size(NULL), 0);
  21846. wc_curve448_free(&key);
  21847. #endif
  21848. return EXPECT_RESULT();
  21849. } /* END test_wc_curve448_size*/
  21850. /*
  21851. * Testing wc_ecc_make_key.
  21852. */
  21853. static int test_wc_ecc_make_key(void)
  21854. {
  21855. EXPECT_DECLS;
  21856. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  21857. ecc_key key;
  21858. WC_RNG rng;
  21859. int ret;
  21860. XMEMSET(&key, 0, sizeof(ecc_key));
  21861. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21862. ExpectIntEQ(wc_ecc_init(&key), 0);
  21863. ExpectIntEQ(wc_InitRng(&rng), 0);
  21864. ret = wc_ecc_make_key(&rng, KEY14, &key);
  21865. #if defined(WOLFSSL_ASYNC_CRYPT)
  21866. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  21867. #endif
  21868. ExpectIntEQ(ret, 0);
  21869. /* Pass in bad args. */
  21870. ExpectIntEQ(wc_ecc_make_key(NULL, KEY14, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21871. ExpectIntEQ(wc_ecc_make_key(&rng, KEY14, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21872. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21873. wc_ecc_free(&key);
  21874. #ifdef FP_ECC
  21875. wc_ecc_fp_free();
  21876. #endif
  21877. #endif
  21878. return EXPECT_RESULT();
  21879. } /* END test_wc_ecc_make_key */
  21880. /*
  21881. * Testing wc_ecc_init()
  21882. */
  21883. static int test_wc_ecc_init(void)
  21884. {
  21885. EXPECT_DECLS;
  21886. #ifdef HAVE_ECC
  21887. ecc_key key;
  21888. XMEMSET(&key, 0, sizeof(ecc_key));
  21889. ExpectIntEQ(wc_ecc_init(&key), 0);
  21890. /* Pass in bad args. */
  21891. ExpectIntEQ(wc_ecc_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21892. wc_ecc_free(&key);
  21893. #endif
  21894. return EXPECT_RESULT();
  21895. } /* END test_wc_ecc_init */
  21896. /*
  21897. * Testing wc_ecc_check_key()
  21898. */
  21899. static int test_wc_ecc_check_key(void)
  21900. {
  21901. EXPECT_DECLS;
  21902. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  21903. ecc_key key;
  21904. WC_RNG rng;
  21905. int ret;
  21906. XMEMSET(&rng, 0, sizeof(rng));
  21907. XMEMSET(&key, 0, sizeof(key));
  21908. ExpectIntEQ(wc_ecc_init(&key), 0);
  21909. ExpectIntEQ(wc_InitRng(&rng), 0);
  21910. ret = wc_ecc_make_key(&rng, KEY14, &key);
  21911. #if defined(WOLFSSL_ASYNC_CRYPT)
  21912. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  21913. #endif
  21914. ExpectIntEQ(ret, 0);
  21915. ExpectIntEQ(wc_ecc_check_key(&key), 0);
  21916. /* Pass in bad args. */
  21917. ExpectIntEQ(wc_ecc_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21918. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21919. wc_ecc_free(&key);
  21920. #ifdef FP_ECC
  21921. wc_ecc_fp_free();
  21922. #endif
  21923. #endif
  21924. return EXPECT_RESULT();
  21925. } /* END test_wc_ecc_check_key */
  21926. /*
  21927. * Testing wc_ecc_get_generator()
  21928. */
  21929. static int test_wc_ecc_get_generator(void)
  21930. {
  21931. EXPECT_DECLS;
  21932. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  21933. !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  21934. ecc_point* pt = NULL;
  21935. ExpectNotNull(pt = wc_ecc_new_point());
  21936. ExpectIntEQ(wc_ecc_get_generator(pt, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  21937. MP_OKAY);
  21938. /* Test bad args. */
  21939. /* Returns Zero for bad arg. */
  21940. ExpectIntNE(wc_ecc_get_generator(pt, -1), MP_OKAY);
  21941. ExpectIntNE(wc_ecc_get_generator(NULL, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  21942. MP_OKAY);
  21943. /* If we ever get to 1000 curves increase this number */
  21944. ExpectIntNE(wc_ecc_get_generator(pt, 1000), MP_OKAY);
  21945. ExpectIntNE(wc_ecc_get_generator(NULL, -1), MP_OKAY);
  21946. wc_ecc_del_point(pt);
  21947. #endif
  21948. return EXPECT_RESULT();
  21949. } /* END test_wc_ecc_get_generator */
  21950. /*
  21951. * Testing wc_ecc_size()
  21952. */
  21953. static int test_wc_ecc_size(void)
  21954. {
  21955. EXPECT_DECLS;
  21956. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  21957. WC_RNG rng;
  21958. ecc_key key;
  21959. int ret;
  21960. XMEMSET(&key, 0, sizeof(ecc_key));
  21961. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21962. ExpectIntEQ(wc_ecc_init(&key), 0);
  21963. ExpectIntEQ(wc_InitRng(&rng), 0);
  21964. ret = wc_ecc_make_key(&rng, KEY14, &key);
  21965. #if defined(WOLFSSL_ASYNC_CRYPT)
  21966. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  21967. #endif
  21968. ExpectIntEQ(ret, 0);
  21969. ExpectIntEQ(wc_ecc_size(&key), KEY14);
  21970. /* Test bad args. */
  21971. /* Returns Zero for bad arg. */
  21972. ExpectIntEQ(wc_ecc_size(NULL), 0);
  21973. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21974. wc_ecc_free(&key);
  21975. #endif
  21976. return EXPECT_RESULT();
  21977. } /* END test_wc_ecc_size */
  21978. static int test_wc_ecc_params(void)
  21979. {
  21980. EXPECT_DECLS;
  21981. /* FIPS/CAVP self-test modules do not have `wc_ecc_get_curve_params`.
  21982. It was added after certifications */
  21983. #if defined(HAVE_ECC) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  21984. const ecc_set_type* ecc_set;
  21985. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  21986. /* Test for SECP256R1 curve */
  21987. int curve_id = ECC_SECP256R1;
  21988. int curve_idx;
  21989. ExpectIntNE(curve_idx = wc_ecc_get_curve_idx(curve_id), ECC_CURVE_INVALID);
  21990. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(curve_idx));
  21991. ExpectIntEQ(ecc_set->id, curve_id);
  21992. #endif
  21993. /* Test case when SECP256R1 is not enabled */
  21994. /* Test that we get curve params for index 0 */
  21995. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(0));
  21996. #endif /* HAVE_ECC && !HAVE_FIPS && !HAVE_SELFTEST */
  21997. return EXPECT_RESULT();
  21998. }
  21999. /*
  22000. * Testing wc_ecc_sign_hash() and wc_ecc_verify_hash()
  22001. */
  22002. static int test_wc_ecc_signVerify_hash(void)
  22003. {
  22004. EXPECT_DECLS;
  22005. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && !defined(NO_ASN) && !defined(WC_NO_RNG)
  22006. ecc_key key;
  22007. WC_RNG rng;
  22008. int ret;
  22009. #ifdef HAVE_ECC_VERIFY
  22010. int verify = 0;
  22011. #endif
  22012. word32 siglen = ECC_BUFSIZE;
  22013. byte sig[ECC_BUFSIZE];
  22014. byte adjustedSig[ECC_BUFSIZE+1];
  22015. byte digest[] = TEST_STRING;
  22016. word32 digestlen = (word32)TEST_STRING_SZ;
  22017. /* Init stack var */
  22018. XMEMSET(&key, 0, sizeof(ecc_key));
  22019. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22020. XMEMSET(sig, 0, siglen);
  22021. XMEMSET(adjustedSig, 0, ECC_BUFSIZE+1);
  22022. /* Init structs. */
  22023. ExpectIntEQ(wc_ecc_init(&key), 0);
  22024. ExpectIntEQ(wc_InitRng(&rng), 0);
  22025. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22026. #if defined(WOLFSSL_ASYNC_CRYPT)
  22027. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22028. #endif
  22029. ExpectIntEQ(ret, 0);
  22030. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, &key),
  22031. 0);
  22032. /* Check bad args. */
  22033. ExpectIntEQ(wc_ecc_sign_hash(NULL, digestlen, sig, &siglen, &rng, &key),
  22034. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22035. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, NULL, &siglen, &rng, &key),
  22036. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22037. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, NULL, &rng, &key),
  22038. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22039. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, NULL, &key),
  22040. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22041. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, NULL),
  22042. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22043. #ifdef HAVE_ECC_VERIFY
  22044. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22045. &key), 0);
  22046. ExpectIntEQ(verify, 1);
  22047. /* test check on length of signature passed in */
  22048. XMEMCPY(adjustedSig, sig, siglen);
  22049. adjustedSig[1] = adjustedSig[1] + 1; /* add 1 to length for extra byte*/
  22050. #ifndef NO_STRICT_ECDSA_LEN
  22051. ExpectIntNE(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22052. &verify, &key), 0);
  22053. #else
  22054. /* if NO_STRICT_ECDSA_LEN is set then extra bytes after the signature
  22055. * is allowed */
  22056. ExpectIntEQ(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22057. &verify, &key), 0);
  22058. #endif
  22059. /* Test bad args. */
  22060. ExpectIntEQ(wc_ecc_verify_hash(NULL, siglen, digest, digestlen, &verify,
  22061. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22062. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, NULL, digestlen, &verify, &key),
  22063. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22064. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, NULL, &key),
  22065. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22066. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22067. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22068. #endif /* HAVE_ECC_VERIFY */
  22069. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22070. wc_ecc_free(&key);
  22071. #ifdef FP_ECC
  22072. wc_ecc_fp_free();
  22073. #endif
  22074. #endif
  22075. return EXPECT_RESULT();
  22076. } /* END test_wc_ecc_sign_hash */
  22077. /*
  22078. * Testing wc_ecc_shared_secret()
  22079. */
  22080. static int test_wc_ecc_shared_secret(void)
  22081. {
  22082. EXPECT_DECLS;
  22083. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG)
  22084. ecc_key key;
  22085. ecc_key pubKey;
  22086. WC_RNG rng;
  22087. #if defined(NO_ECC256)
  22088. int ret;
  22089. #endif
  22090. byte out[KEY32];
  22091. int keySz = sizeof(out);
  22092. word32 outlen = (word32)sizeof(out);
  22093. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22094. const char* qx =
  22095. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22096. const char* qy =
  22097. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22098. const char* d =
  22099. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22100. const char* curveName = "SECP256R1";
  22101. const byte expected_shared_secret[] =
  22102. {
  22103. 0x65, 0xc0, 0xd4, 0x61, 0x17, 0xe6, 0x09, 0x75,
  22104. 0xf0, 0x12, 0xa0, 0x4d, 0x0b, 0x41, 0x30, 0x7a,
  22105. 0x51, 0xf0, 0xb3, 0xaf, 0x23, 0x8f, 0x0f, 0xdf,
  22106. 0xf1, 0xff, 0x23, 0x64, 0x28, 0xca, 0xf8, 0x06
  22107. };
  22108. #endif
  22109. PRIVATE_KEY_UNLOCK();
  22110. /* Initialize variables. */
  22111. XMEMSET(&key, 0, sizeof(ecc_key));
  22112. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22113. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22114. XMEMSET(out, 0, keySz);
  22115. ExpectIntEQ(wc_ecc_init(&key), 0);
  22116. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22117. ExpectIntEQ(wc_InitRng(&rng), 0);
  22118. #if !defined(NO_ECC256)
  22119. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22120. ExpectIntEQ(wc_ecc_import_raw(&pubKey, qx, qy, NULL, curveName), 0);
  22121. #else
  22122. ret = wc_ecc_make_key(&rng, keySz, &key);
  22123. #if defined(WOLFSSL_ASYNC_CRYPT)
  22124. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22125. #endif
  22126. ExpectIntEQ(ret, 0);
  22127. ret = wc_ecc_make_key(&rng, keySz, &key);
  22128. #if defined(WOLFSSL_ASYNC_CRYPT)
  22129. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22130. #endif
  22131. ExpectIntEQ(ret, 0);
  22132. #endif
  22133. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22134. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22135. !defined(HAVE_SELFTEST)
  22136. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  22137. #endif
  22138. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen), 0);
  22139. #if !defined(NO_ECC256)
  22140. ExpectIntEQ(XMEMCMP(out, expected_shared_secret, outlen), 0);
  22141. #endif
  22142. /* Test bad args. */
  22143. ExpectIntEQ(wc_ecc_shared_secret(NULL, &pubKey, out, &outlen),
  22144. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22145. ExpectIntEQ(wc_ecc_shared_secret(&key, NULL, out, &outlen),
  22146. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22147. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, NULL, &outlen),
  22148. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22149. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, NULL),
  22150. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22151. /* Invalid length */
  22152. outlen = 1;
  22153. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen),
  22154. WC_NO_ERR_TRACE(BUFFER_E));
  22155. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22156. wc_ecc_free(&pubKey);
  22157. wc_ecc_free(&key);
  22158. #ifdef FP_ECC
  22159. wc_ecc_fp_free();
  22160. #endif
  22161. PRIVATE_KEY_LOCK();
  22162. #endif
  22163. return EXPECT_RESULT();
  22164. } /* END tests_wc_ecc_shared_secret */
  22165. /*
  22166. * testint wc_ecc_export_x963()
  22167. */
  22168. static int test_wc_ecc_export_x963(void)
  22169. {
  22170. EXPECT_DECLS;
  22171. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22172. ecc_key key;
  22173. WC_RNG rng;
  22174. byte out[ECC_ASN963_MAX_BUF_SZ];
  22175. word32 outlen = sizeof(out);
  22176. int ret;
  22177. PRIVATE_KEY_UNLOCK();
  22178. /* Initialize variables. */
  22179. XMEMSET(&key, 0, sizeof(ecc_key));
  22180. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22181. XMEMSET(out, 0, outlen);
  22182. ExpectIntEQ(wc_ecc_init(&key), 0);
  22183. ExpectIntEQ(wc_InitRng(&rng), 0);
  22184. ret = wc_ecc_make_key(&rng, KEY20, &key);
  22185. #if defined(WOLFSSL_ASYNC_CRYPT)
  22186. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22187. #endif
  22188. ExpectIntEQ(ret, 0);
  22189. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), 0);
  22190. /* Test bad args. */
  22191. ExpectIntEQ(wc_ecc_export_x963(NULL, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22192. ExpectIntEQ(wc_ecc_export_x963(&key, NULL, &outlen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22193. ExpectIntEQ(wc_ecc_export_x963(&key, out, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22194. key.idx = -4;
  22195. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22196. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22197. wc_ecc_free(&key);
  22198. #ifdef FP_ECC
  22199. wc_ecc_fp_free();
  22200. #endif
  22201. PRIVATE_KEY_LOCK();
  22202. #endif
  22203. return EXPECT_RESULT();
  22204. } /* END test_wc_ecc_export_x963 */
  22205. /*
  22206. * Testing wc_ecc_export_x963_ex()
  22207. * compile with --enable-compkey will use compression.
  22208. */
  22209. static int test_wc_ecc_export_x963_ex(void)
  22210. {
  22211. EXPECT_DECLS;
  22212. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22213. ecc_key key;
  22214. WC_RNG rng;
  22215. int ret;
  22216. byte out[ECC_ASN963_MAX_BUF_SZ];
  22217. word32 outlen = sizeof(out);
  22218. #ifdef HAVE_COMP_KEY
  22219. word32 badOutLen = 5;
  22220. #endif
  22221. /* Init stack variables. */
  22222. XMEMSET(&key, 0, sizeof(ecc_key));
  22223. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22224. XMEMSET(out, 0, outlen);
  22225. PRIVATE_KEY_UNLOCK();
  22226. ExpectIntEQ(wc_ecc_init(&key), 0);
  22227. ExpectIntEQ(wc_InitRng(&rng), 0);
  22228. ret = wc_ecc_make_key(&rng, KEY64, &key);
  22229. #if defined(WOLFSSL_ASYNC_CRYPT)
  22230. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22231. #endif
  22232. ExpectIntEQ(ret, 0);
  22233. #ifdef HAVE_COMP_KEY
  22234. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), 0);
  22235. #else
  22236. ExpectIntEQ(ret = wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP), 0);
  22237. #endif
  22238. /* Test bad args. */
  22239. #ifdef HAVE_COMP_KEY
  22240. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22241. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22242. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22243. #if defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3))
  22244. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP), WC_NO_ERR_TRACE(BUFFER_E));
  22245. #else
  22246. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP),
  22247. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22248. #endif
  22249. key.idx = -4;
  22250. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22251. #else
  22252. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, NOCOMP),
  22253. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22254. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, NOCOMP),
  22255. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22256. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, 1), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  22257. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, NOCOMP),
  22258. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22259. key.idx = -4;
  22260. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP),
  22261. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22262. #endif
  22263. PRIVATE_KEY_LOCK();
  22264. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22265. wc_ecc_free(&key);
  22266. #ifdef FP_ECC
  22267. wc_ecc_fp_free();
  22268. #endif
  22269. #endif
  22270. return EXPECT_RESULT();
  22271. } /* END test_wc_ecc_export_x963_ex */
  22272. /*
  22273. * testing wc_ecc_import_x963()
  22274. */
  22275. static int test_wc_ecc_import_x963(void)
  22276. {
  22277. EXPECT_DECLS;
  22278. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22279. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22280. ecc_key pubKey;
  22281. ecc_key key;
  22282. WC_RNG rng;
  22283. byte x963[ECC_ASN963_MAX_BUF_SZ];
  22284. word32 x963Len = (word32)sizeof(x963);
  22285. int ret;
  22286. /* Init stack variables. */
  22287. XMEMSET(&key, 0, sizeof(ecc_key));
  22288. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22289. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22290. XMEMSET(x963, 0, x963Len);
  22291. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22292. ExpectIntEQ(wc_ecc_init(&key), 0);
  22293. ExpectIntEQ(wc_InitRng(&rng), 0);
  22294. #if FIPS_VERSION3_GE(6,0,0)
  22295. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22296. #else
  22297. ret = wc_ecc_make_key(&rng, KEY24, &key);
  22298. #endif
  22299. #if defined(WOLFSSL_ASYNC_CRYPT)
  22300. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22301. #endif
  22302. ExpectIntEQ(ret, 0);
  22303. PRIVATE_KEY_UNLOCK();
  22304. ExpectIntEQ(wc_ecc_export_x963(&key, x963, &x963Len), 0);
  22305. PRIVATE_KEY_LOCK();
  22306. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, &pubKey), 0);
  22307. /* Test bad args. */
  22308. ExpectIntEQ(wc_ecc_import_x963(NULL, x963Len, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22309. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22310. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len + 1, &pubKey), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22311. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22312. wc_ecc_free(&key);
  22313. wc_ecc_free(&pubKey);
  22314. #ifdef FP_ECC
  22315. wc_ecc_fp_free();
  22316. #endif
  22317. #endif
  22318. return EXPECT_RESULT();
  22319. } /* END wc_ecc_import_x963 */
  22320. /*
  22321. * testing wc_ecc_import_private_key()
  22322. */
  22323. static int test_wc_ecc_import_private_key(void)
  22324. {
  22325. EXPECT_DECLS;
  22326. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22327. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22328. ecc_key key;
  22329. ecc_key keyImp;
  22330. WC_RNG rng;
  22331. byte privKey[ECC_PRIV_KEY_BUF]; /* Raw private key.*/
  22332. byte x963Key[ECC_ASN963_MAX_BUF_SZ];
  22333. word32 privKeySz = (word32)sizeof(privKey);
  22334. word32 x963KeySz = (word32)sizeof(x963Key);
  22335. int ret;
  22336. /* Init stack variables. */
  22337. XMEMSET(&key, 0, sizeof(ecc_key));
  22338. XMEMSET(&keyImp, 0, sizeof(ecc_key));
  22339. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22340. XMEMSET(privKey, 0, privKeySz);
  22341. XMEMSET(x963Key, 0, x963KeySz);
  22342. PRIVATE_KEY_UNLOCK();
  22343. ExpectIntEQ(wc_ecc_init(&key), 0);
  22344. ExpectIntEQ(wc_ecc_init(&keyImp), 0);
  22345. ExpectIntEQ(wc_InitRng(&rng), 0);
  22346. ret = wc_ecc_make_key(&rng, KEY48, &key);
  22347. #if defined(WOLFSSL_ASYNC_CRYPT)
  22348. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22349. #endif
  22350. ExpectIntEQ(ret, 0);
  22351. PRIVATE_KEY_UNLOCK();
  22352. ExpectIntEQ(wc_ecc_export_x963(&key, x963Key, &x963KeySz), 0);
  22353. PRIVATE_KEY_LOCK();
  22354. ExpectIntEQ(wc_ecc_export_private_only(&key, privKey, &privKeySz), 0);
  22355. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22356. x963KeySz, &keyImp), 0);
  22357. /* Pass in bad args. */
  22358. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22359. x963KeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22360. ExpectIntEQ(wc_ecc_import_private_key(NULL, privKeySz, x963Key, x963KeySz,
  22361. &keyImp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22362. PRIVATE_KEY_LOCK();
  22363. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22364. wc_ecc_free(&keyImp);
  22365. wc_ecc_free(&key);
  22366. #ifdef FP_ECC
  22367. wc_ecc_fp_free();
  22368. #endif
  22369. #endif
  22370. return EXPECT_RESULT();
  22371. } /* END test_wc_ecc_import_private_key */
  22372. /*
  22373. * Testing wc_ecc_export_private_only()
  22374. */
  22375. static int test_wc_ecc_export_private_only(void)
  22376. {
  22377. EXPECT_DECLS;
  22378. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22379. ecc_key key;
  22380. WC_RNG rng;
  22381. byte out[ECC_PRIV_KEY_BUF];
  22382. word32 outlen = sizeof(out);
  22383. int ret;
  22384. /* Init stack variables. */
  22385. XMEMSET(&key, 0, sizeof(ecc_key));
  22386. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22387. XMEMSET(out, 0, outlen);
  22388. PRIVATE_KEY_UNLOCK();
  22389. ExpectIntEQ(wc_ecc_init(&key), 0);
  22390. ExpectIntEQ(wc_InitRng(&rng), 0);
  22391. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22392. #if defined(WOLFSSL_ASYNC_CRYPT)
  22393. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22394. #endif
  22395. ExpectIntEQ(ret, 0);
  22396. ExpectIntEQ(wc_ecc_export_private_only(&key, out, &outlen), 0);
  22397. /* Pass in bad args. */
  22398. ExpectIntEQ(wc_ecc_export_private_only(NULL, out, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22399. ExpectIntEQ(wc_ecc_export_private_only(&key, NULL, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22400. ExpectIntEQ(wc_ecc_export_private_only(&key, out, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22401. PRIVATE_KEY_LOCK();
  22402. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22403. wc_ecc_free(&key);
  22404. #ifdef FP_ECC
  22405. wc_ecc_fp_free();
  22406. #endif
  22407. #endif
  22408. return EXPECT_RESULT();
  22409. } /* END test_wc_ecc_export_private_only */
  22410. /*
  22411. * Testing wc_ecc_rs_to_sig()
  22412. */
  22413. static int test_wc_ecc_rs_to_sig(void)
  22414. {
  22415. EXPECT_DECLS;
  22416. #if defined(HAVE_ECC) && !defined(NO_ASN)
  22417. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  22418. const char* R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  22419. const char* S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  22420. const char* zeroStr = "0";
  22421. byte sig[ECC_MAX_SIG_SIZE];
  22422. word32 siglen = (word32)sizeof(sig);
  22423. /* R and S max size is the order of curve. 2^192.*/
  22424. int keySz = KEY24;
  22425. byte r[KEY24];
  22426. byte s[KEY24];
  22427. word32 rlen = (word32)sizeof(r);
  22428. word32 slen = (word32)sizeof(s);
  22429. /* Init stack variables. */
  22430. XMEMSET(sig, 0, ECC_MAX_SIG_SIZE);
  22431. XMEMSET(r, 0, keySz);
  22432. XMEMSET(s, 0, keySz);
  22433. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, &siglen), 0);
  22434. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, &slen), 0);
  22435. /* Test bad args. */
  22436. ExpectIntEQ(wc_ecc_rs_to_sig(NULL, S, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22437. ExpectIntEQ(wc_ecc_rs_to_sig(R, NULL, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22438. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22439. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, NULL, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22440. ExpectIntEQ(wc_ecc_rs_to_sig(R, zeroStr, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22441. ExpectIntEQ(wc_ecc_rs_to_sig(zeroStr, S, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22442. ExpectIntEQ(wc_ecc_sig_to_rs(NULL, siglen, r, &rlen, s, &slen),
  22443. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22444. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, NULL, &rlen, s, &slen),
  22445. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22446. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, NULL, s, &slen),
  22447. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22448. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, NULL, &slen),
  22449. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22450. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, NULL),
  22451. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22452. #endif
  22453. return EXPECT_RESULT();
  22454. } /* END test_wc_ecc_rs_to_sig */
  22455. static int test_wc_ecc_import_raw(void)
  22456. {
  22457. EXPECT_DECLS;
  22458. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22459. ecc_key key;
  22460. const char* qx =
  22461. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22462. const char* qy =
  22463. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22464. const char* d =
  22465. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22466. const char* curveName = "SECP256R1";
  22467. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22468. const char* kNullStr = "";
  22469. int ret;
  22470. #endif
  22471. XMEMSET(&key, 0, sizeof(ecc_key));
  22472. ExpectIntEQ(wc_ecc_init(&key), 0);
  22473. /* Test good import */
  22474. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22475. /* Test bad args. */
  22476. ExpectIntEQ(wc_ecc_import_raw(NULL, qx, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22477. ExpectIntEQ(wc_ecc_import_raw(&key, NULL, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22478. ExpectIntEQ(wc_ecc_import_raw(&key, qx, NULL, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22479. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22480. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22481. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22482. wc_ecc_free(&key);
  22483. #endif
  22484. ExpectIntLT(ret = wc_ecc_import_raw(&key, kNullStr, kNullStr, kNullStr,
  22485. curveName), 0);
  22486. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  22487. #endif
  22488. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  22489. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22490. wc_ecc_free(&key);
  22491. #endif
  22492. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22493. ExpectIntLT(ret = wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22494. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22495. #else
  22496. ExpectIntEQ(wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22497. #endif
  22498. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22499. wc_ecc_free(&key);
  22500. #endif
  22501. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22502. ExpectIntLT(ret = wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22503. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22504. #else
  22505. ExpectIntEQ(wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22506. #endif
  22507. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22508. wc_ecc_free(&key);
  22509. #endif
  22510. ExpectIntEQ(wc_ecc_import_raw(&key, "0", "0", d, curveName), WC_NO_ERR_TRACE(ECC_INF_E));
  22511. #endif
  22512. wc_ecc_free(&key);
  22513. #endif
  22514. return EXPECT_RESULT();
  22515. } /* END test_wc_ecc_import_raw */
  22516. static int test_wc_ecc_import_unsigned(void)
  22517. {
  22518. EXPECT_DECLS;
  22519. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  22520. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  22521. HAVE_FIPS_VERSION >= 2))
  22522. ecc_key key;
  22523. const byte qx[] = {
  22524. 0xbb, 0x33, 0xac, 0x4c, 0x27, 0x50, 0x4a, 0xc6,
  22525. 0x4a, 0xa5, 0x04, 0xc3, 0x3c, 0xde, 0x9f, 0x36,
  22526. 0xdb, 0x72, 0x2d, 0xce, 0x94, 0xea, 0x2b, 0xfa,
  22527. 0xcb, 0x20, 0x09, 0x39, 0x2c, 0x16, 0xe8, 0x61
  22528. };
  22529. const byte qy[] = {
  22530. 0x02, 0xe9, 0xaf, 0x4d, 0xd3, 0x02, 0x93, 0x9a,
  22531. 0x31, 0x5b, 0x97, 0x92, 0x21, 0x7f, 0xf0, 0xcf,
  22532. 0x18, 0xda, 0x91, 0x11, 0x02, 0x34, 0x86, 0xe8,
  22533. 0x20, 0x58, 0x33, 0x0b, 0x80, 0x34, 0x89, 0xd8
  22534. };
  22535. const byte d[] = {
  22536. 0x45, 0xb6, 0x69, 0x02, 0x73, 0x9c, 0x6c, 0x85,
  22537. 0xa1, 0x38, 0x5b, 0x72, 0xe8, 0xe8, 0xc7, 0xac,
  22538. 0xc4, 0x03, 0x8d, 0x53, 0x35, 0x04, 0xfa, 0x6c,
  22539. 0x28, 0xdc, 0x34, 0x8d, 0xe1, 0xa8, 0x09, 0x8c
  22540. };
  22541. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22542. const byte nullBytes[32] = {0};
  22543. int ret;
  22544. #endif
  22545. int curveId = ECC_SECP256R1;
  22546. XMEMSET(&key, 0, sizeof(ecc_key));
  22547. ExpectIntEQ(wc_ecc_init(&key), 0);
  22548. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  22549. curveId), 0);
  22550. /* Test bad args. */
  22551. ExpectIntEQ(wc_ecc_import_unsigned(NULL, (byte*)qx, (byte*)qy, (byte*)d,
  22552. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22553. ExpectIntEQ(wc_ecc_import_unsigned(&key, NULL, (byte*)qy, (byte*)d,
  22554. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22555. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, NULL, (byte*)d,
  22556. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22557. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  22558. ECC_CURVE_INVALID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22559. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22560. ExpectIntLT(ret = wc_ecc_import_unsigned(&key, (byte*)nullBytes,
  22561. (byte*)nullBytes, (byte*)nullBytes, curveId), 0);
  22562. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  22563. #endif
  22564. wc_ecc_free(&key);
  22565. #endif
  22566. return EXPECT_RESULT();
  22567. } /* END test_wc_ecc_import_unsigned */
  22568. /*
  22569. * Testing wc_ecc_sig_size()
  22570. */
  22571. static int test_wc_ecc_sig_size(void)
  22572. {
  22573. EXPECT_DECLS;
  22574. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22575. ecc_key key;
  22576. WC_RNG rng;
  22577. int keySz = KEY16;
  22578. int ret;
  22579. XMEMSET(&rng, 0, sizeof(rng));
  22580. XMEMSET(&key, 0, sizeof(key));
  22581. ExpectIntEQ(wc_ecc_init(&key), 0);
  22582. ExpectIntEQ(wc_InitRng(&rng), 0);
  22583. ret = wc_ecc_make_key(&rng, keySz, &key);
  22584. #if defined(WOLFSSL_ASYNC_CRYPT)
  22585. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22586. #endif
  22587. ExpectIntEQ(ret, 0);
  22588. ExpectIntLE(wc_ecc_sig_size(&key),
  22589. (2 * keySz + SIG_HEADER_SZ + ECC_MAX_PAD_SZ));
  22590. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22591. wc_ecc_free(&key);
  22592. #endif
  22593. return EXPECT_RESULT();
  22594. } /* END test_wc_ecc_sig_size */
  22595. /*
  22596. * Testing wc_ecc_ctx_new()
  22597. */
  22598. static int test_wc_ecc_ctx_new(void)
  22599. {
  22600. EXPECT_DECLS;
  22601. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22602. WC_RNG rng;
  22603. ecEncCtx* cli = NULL;
  22604. ecEncCtx* srv = NULL;
  22605. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22606. ExpectIntEQ(wc_InitRng(&rng), 0);
  22607. ExpectNotNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22608. ExpectNotNull(srv = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  22609. wc_ecc_ctx_free(cli);
  22610. cli = NULL;
  22611. wc_ecc_ctx_free(srv);
  22612. /* Test bad args. */
  22613. /* wc_ecc_ctx_new_ex() will free if returned NULL. */
  22614. ExpectNull(cli = wc_ecc_ctx_new(0, &rng));
  22615. ExpectNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, NULL));
  22616. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22617. wc_ecc_ctx_free(cli);
  22618. #endif
  22619. return EXPECT_RESULT();
  22620. } /* END test_wc_ecc_ctx_new */
  22621. /*
  22622. * Tesing wc_ecc_reset()
  22623. */
  22624. static int test_wc_ecc_ctx_reset(void)
  22625. {
  22626. EXPECT_DECLS;
  22627. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22628. ecEncCtx* ctx = NULL;
  22629. WC_RNG rng;
  22630. XMEMSET(&rng, 0, sizeof(rng));
  22631. ExpectIntEQ(wc_InitRng(&rng), 0);
  22632. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22633. ExpectIntEQ(wc_ecc_ctx_reset(ctx, &rng), 0);
  22634. /* Pass in bad args. */
  22635. ExpectIntEQ(wc_ecc_ctx_reset(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22636. ExpectIntEQ(wc_ecc_ctx_reset(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22637. wc_ecc_ctx_free(ctx);
  22638. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22639. #endif
  22640. return EXPECT_RESULT();
  22641. } /* END test_wc_ecc_ctx_reset */
  22642. /*
  22643. * Testing wc_ecc_ctx_set_peer_salt() and wc_ecc_ctx_get_own_salt()
  22644. */
  22645. static int test_wc_ecc_ctx_set_peer_salt(void)
  22646. {
  22647. EXPECT_DECLS;
  22648. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22649. WC_RNG rng;
  22650. ecEncCtx* cliCtx = NULL;
  22651. ecEncCtx* servCtx = NULL;
  22652. const byte* cliSalt = NULL;
  22653. const byte* servSalt = NULL;
  22654. XMEMSET(&rng, 0, sizeof(rng));
  22655. ExpectIntEQ(wc_InitRng(&rng), 0);
  22656. ExpectNotNull(cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22657. ExpectNotNull(servCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  22658. /* Test bad args. */
  22659. ExpectNull(cliSalt = wc_ecc_ctx_get_own_salt(NULL));
  22660. ExpectNotNull(cliSalt = wc_ecc_ctx_get_own_salt(cliCtx));
  22661. ExpectNotNull(servSalt = wc_ecc_ctx_get_own_salt(servCtx));
  22662. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, servSalt), 0);
  22663. /* Test bad args. */
  22664. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(NULL, servSalt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22665. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22666. wc_ecc_ctx_free(cliCtx);
  22667. wc_ecc_ctx_free(servCtx);
  22668. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22669. #endif
  22670. return EXPECT_RESULT();
  22671. } /* END test_wc_ecc_ctx_set_peer_salt */
  22672. /*
  22673. * Testing wc_ecc_ctx_set_info()
  22674. */
  22675. static int test_wc_ecc_ctx_set_info(void)
  22676. {
  22677. EXPECT_DECLS;
  22678. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22679. ecEncCtx* ctx = NULL;
  22680. WC_RNG rng;
  22681. const char* optInfo = "Optional Test Info.";
  22682. int optInfoSz = (int)XSTRLEN(optInfo);
  22683. const char* badOptInfo = NULL;
  22684. XMEMSET(&rng, 0, sizeof(rng));
  22685. ExpectIntEQ(wc_InitRng(&rng), 0);
  22686. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22687. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, optInfoSz), 0);
  22688. /* Test bad args. */
  22689. ExpectIntEQ(wc_ecc_ctx_set_info(NULL, (byte*)optInfo, optInfoSz),
  22690. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22691. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)badOptInfo, optInfoSz),
  22692. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22693. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22694. wc_ecc_ctx_free(ctx);
  22695. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22696. #endif
  22697. return EXPECT_RESULT();
  22698. } /* END test_wc_ecc_ctx_set_info */
  22699. /*
  22700. * Testing wc_ecc_encrypt() and wc_ecc_decrypt()
  22701. */
  22702. static int test_wc_ecc_encryptDecrypt(void)
  22703. {
  22704. EXPECT_DECLS;
  22705. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG) && \
  22706. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22707. ecc_key srvKey;
  22708. ecc_key cliKey;
  22709. ecc_key tmpKey;
  22710. WC_RNG rng;
  22711. int ret;
  22712. const char* msg = "EccBlock Size 16";
  22713. word32 msgSz = (word32)XSTRLEN("EccBlock Size 16");
  22714. #ifdef WOLFSSL_ECIES_OLD
  22715. byte out[(sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  22716. #elif defined(WOLFSSL_ECIES_GEN_IV)
  22717. byte out[KEY20 * 2 + 1 + AES_BLOCK_SIZE +
  22718. (sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  22719. #else
  22720. byte out[KEY20 * 2 + 1 + (sizeof("EccBlock Size 16") - 1) +
  22721. WC_SHA256_DIGEST_SIZE];
  22722. #endif
  22723. word32 outSz = (word32)sizeof(out);
  22724. byte plain[sizeof("EccBlock Size 16")];
  22725. word32 plainSz = (word32)sizeof(plain);
  22726. int keySz = KEY20;
  22727. /* Init stack variables. */
  22728. XMEMSET(out, 0, outSz);
  22729. XMEMSET(plain, 0, plainSz);
  22730. XMEMSET(&rng, 0, sizeof(rng));
  22731. XMEMSET(&srvKey, 0, sizeof(ecc_key));
  22732. XMEMSET(&cliKey, 0, sizeof(ecc_key));
  22733. XMEMSET(&tmpKey, 0, sizeof(ecc_key));
  22734. ExpectIntEQ(wc_InitRng(&rng), 0);
  22735. ExpectIntEQ(wc_ecc_init(&cliKey), 0);
  22736. ret = wc_ecc_make_key(&rng, keySz, &cliKey);
  22737. #if defined(WOLFSSL_ASYNC_CRYPT)
  22738. ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_NONE);
  22739. #endif
  22740. ExpectIntEQ(ret, 0);
  22741. ExpectIntEQ(wc_ecc_init(&srvKey), 0);
  22742. ret = wc_ecc_make_key(&rng, keySz, &srvKey);
  22743. #if defined(WOLFSSL_ASYNC_CRYPT)
  22744. ret = wc_AsyncWait(ret, &srvKey.asyncDev, WC_ASYNC_FLAG_NONE);
  22745. #endif
  22746. ExpectIntEQ(ret, 0);
  22747. ExpectIntEQ(wc_ecc_init(&tmpKey), 0);
  22748. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22749. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22750. !defined(HAVE_SELFTEST)
  22751. ExpectIntEQ(wc_ecc_set_rng(&srvKey, &rng), 0);
  22752. ExpectIntEQ(wc_ecc_set_rng(&cliKey, &rng), 0);
  22753. #endif
  22754. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out,
  22755. &outSz, NULL), 0);
  22756. /* Test bad args. */
  22757. ExpectIntEQ(wc_ecc_encrypt(NULL, &srvKey, (byte*)msg, msgSz, out, &outSz,
  22758. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22759. ExpectIntEQ(wc_ecc_encrypt(&cliKey, NULL, (byte*)msg, msgSz, out, &outSz,
  22760. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22761. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, NULL, msgSz, out, &outSz,
  22762. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22763. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, NULL,
  22764. &outSz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22765. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out, NULL,
  22766. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22767. #ifdef WOLFSSL_ECIES_OLD
  22768. tmpKey.dp = cliKey.dp;
  22769. ExpectIntEQ(wc_ecc_copy_point(&cliKey.pubkey, &tmpKey.pubkey), 0);
  22770. #endif
  22771. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, &plainSz,
  22772. NULL), 0);
  22773. ExpectIntEQ(wc_ecc_decrypt(NULL, &tmpKey, out, outSz, plain, &plainSz,
  22774. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22775. #ifdef WOLFSSL_ECIES_OLD
  22776. /* NULL parameter allowed in new implementations - public key comes from
  22777. * the message. */
  22778. ExpectIntEQ(wc_ecc_decrypt(&srvKey, NULL, out, outSz, plain, &plainSz,
  22779. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22780. #endif
  22781. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, NULL, outSz, plain, &plainSz,
  22782. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22783. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, NULL, &plainSz,
  22784. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22785. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, NULL, NULL),
  22786. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22787. ExpectIntEQ(XMEMCMP(msg, plain, msgSz), 0);
  22788. wc_ecc_free(&tmpKey);
  22789. wc_ecc_free(&srvKey);
  22790. wc_ecc_free(&cliKey);
  22791. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22792. #endif
  22793. return EXPECT_RESULT();
  22794. } /* END test_wc_ecc_encryptDecrypt */
  22795. /*
  22796. * Testing wc_ecc_del_point() and wc_ecc_new_point()
  22797. */
  22798. static int test_wc_ecc_del_point(void)
  22799. {
  22800. EXPECT_DECLS;
  22801. #if defined(HAVE_ECC)
  22802. ecc_point* pt = NULL;
  22803. ExpectNotNull(pt = wc_ecc_new_point());
  22804. wc_ecc_del_point(pt);
  22805. #endif
  22806. return EXPECT_RESULT();
  22807. } /* END test_wc_ecc_del_point */
  22808. /*
  22809. * Testing wc_ecc_point_is_at_infinity(), wc_ecc_export_point_der(),
  22810. * wc_ecc_import_point_der(), wc_ecc_copy_point(), wc_ecc_point_is_on_curve(),
  22811. * and wc_ecc_cmp_point()
  22812. */
  22813. static int test_wc_ecc_pointFns(void)
  22814. {
  22815. EXPECT_DECLS;
  22816. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
  22817. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  22818. !defined(WOLFSSL_ATECC608A)
  22819. ecc_key key;
  22820. WC_RNG rng;
  22821. int ret;
  22822. ecc_point* point = NULL;
  22823. ecc_point* cpypt = NULL;
  22824. int idx = 0;
  22825. int keySz = KEY32;
  22826. byte der[DER_SZ(KEY32)];
  22827. word32 derlenChk = 0;
  22828. word32 derSz = DER_SZ(KEY32);
  22829. /* Init stack variables. */
  22830. XMEMSET(der, 0, derSz);
  22831. XMEMSET(&key, 0, sizeof(ecc_key));
  22832. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22833. ExpectIntEQ(wc_InitRng(&rng), 0);
  22834. ExpectIntEQ(wc_ecc_init(&key), 0);
  22835. ret = wc_ecc_make_key(&rng, keySz, &key);
  22836. #if defined(WOLFSSL_ASYNC_CRYPT)
  22837. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22838. #endif
  22839. ExpectIntEQ(ret, 0);
  22840. ExpectNotNull(point = wc_ecc_new_point());
  22841. ExpectNotNull(cpypt = wc_ecc_new_point());
  22842. /* Export */
  22843. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, NULL,
  22844. &derlenChk), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22845. /* Check length value. */
  22846. ExpectIntEQ(derSz, derlenChk);
  22847. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  22848. &derSz), 0);
  22849. /* Test bad args. */
  22850. ExpectIntEQ(wc_ecc_export_point_der(-2, &key.pubkey, der, &derSz),
  22851. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22852. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), NULL, der, &derSz),
  22853. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22854. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  22855. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22856. /* Import */
  22857. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, point), 0);
  22858. ExpectIntEQ(wc_ecc_cmp_point(&key.pubkey, point), 0);
  22859. /* Test bad args. */
  22860. ExpectIntEQ( wc_ecc_import_point_der(NULL, derSz, idx, point),
  22861. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22862. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22863. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, -1, point), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22864. ExpectIntEQ(wc_ecc_import_point_der(der, derSz + 1, idx, point),
  22865. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22866. /* Copy */
  22867. ExpectIntEQ(wc_ecc_copy_point(point, cpypt), 0);
  22868. /* Test bad args. */
  22869. ExpectIntEQ(wc_ecc_copy_point(NULL, cpypt), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22870. ExpectIntEQ(wc_ecc_copy_point(point, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22871. /* Compare point */
  22872. ExpectIntEQ(wc_ecc_cmp_point(point, cpypt), 0);
  22873. /* Test bad args. */
  22874. ExpectIntEQ(wc_ecc_cmp_point(NULL, cpypt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22875. ExpectIntEQ(wc_ecc_cmp_point(point, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22876. /* At infinity if return == 1, otherwise return == 0. */
  22877. ExpectIntEQ(wc_ecc_point_is_at_infinity(point), 0);
  22878. /* Test bad args. */
  22879. ExpectIntEQ(wc_ecc_point_is_at_infinity(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22880. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  22881. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  22882. #ifdef USE_ECC_B_PARAM
  22883. /* On curve if ret == 0 */
  22884. ExpectIntEQ(wc_ecc_point_is_on_curve(point, idx), 0);
  22885. /* Test bad args. */
  22886. ExpectIntEQ(wc_ecc_point_is_on_curve(NULL, idx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22887. ExpectIntEQ(wc_ecc_point_is_on_curve(point, 1000), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22888. #endif /* USE_ECC_B_PARAM */
  22889. #endif /* !HAVE_SELFTEST && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  22890. /* Free */
  22891. wc_ecc_del_point(point);
  22892. wc_ecc_del_point(cpypt);
  22893. wc_ecc_free(&key);
  22894. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22895. #endif
  22896. return EXPECT_RESULT();
  22897. } /* END test_wc_ecc_pointFns */
  22898. /*
  22899. * Testing wc_ecc_shared_secret_ssh()
  22900. */
  22901. static int test_wc_ecc_shared_secret_ssh(void)
  22902. {
  22903. EXPECT_DECLS;
  22904. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && \
  22905. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  22906. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  22907. !defined(WOLFSSL_CRYPTOCELL)
  22908. ecc_key key;
  22909. ecc_key key2;
  22910. WC_RNG rng;
  22911. int ret;
  22912. int keySz = KEY32;
  22913. #if FIPS_VERSION3_GE(6,0,0)
  22914. int key2Sz = KEY28;
  22915. #else
  22916. int key2Sz = KEY24;
  22917. #endif
  22918. byte secret[KEY32];
  22919. word32 secretLen = (word32)keySz;
  22920. /* Init stack variables. */
  22921. XMEMSET(&key, 0, sizeof(ecc_key));
  22922. XMEMSET(&key2, 0, sizeof(ecc_key));
  22923. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22924. XMEMSET(secret, 0, secretLen);
  22925. PRIVATE_KEY_UNLOCK();
  22926. /* Make keys */
  22927. ExpectIntEQ(wc_ecc_init(&key), 0);
  22928. ExpectIntEQ(wc_InitRng(&rng), 0);
  22929. ret = wc_ecc_make_key(&rng, keySz, &key);
  22930. #if defined(WOLFSSL_ASYNC_CRYPT)
  22931. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22932. #endif
  22933. ExpectIntEQ(ret, 0);
  22934. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22935. ExpectIntEQ(wc_ecc_init(&key2), 0);
  22936. ExpectIntEQ(wc_InitRng(&rng), 0);
  22937. ret = wc_ecc_make_key(&rng, key2Sz, &key2);
  22938. #if defined(WOLFSSL_ASYNC_CRYPT)
  22939. ret = wc_AsyncWait(ret, &key2.asyncDev, WC_ASYNC_FLAG_NONE);
  22940. #endif
  22941. ExpectIntEQ(ret, 0);
  22942. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22943. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22944. !defined(HAVE_SELFTEST)
  22945. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  22946. #endif
  22947. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  22948. &secretLen), 0);
  22949. /* Pass in bad args. */
  22950. ExpectIntEQ(wc_ecc_shared_secret_ssh(NULL, &key2.pubkey, secret,
  22951. &secretLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22952. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, NULL, secret, &secretLen),
  22953. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22954. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, NULL, &secretLen),
  22955. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22956. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret, NULL),
  22957. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22958. key.type = ECC_PUBLICKEY;
  22959. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  22960. &secretLen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22961. PRIVATE_KEY_LOCK();
  22962. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22963. wc_ecc_free(&key);
  22964. wc_ecc_free(&key2);
  22965. #ifdef FP_ECC
  22966. wc_ecc_fp_free();
  22967. #endif
  22968. #endif
  22969. return EXPECT_RESULT();
  22970. } /* END test_wc_ecc_shared_secret_ssh */
  22971. /*
  22972. * Testing wc_ecc_verify_hash_ex() and wc_ecc_verify_hash_ex()
  22973. */
  22974. static int test_wc_ecc_verify_hash_ex(void)
  22975. {
  22976. EXPECT_DECLS;
  22977. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && defined(WOLFSSL_PUBLIC_MP) \
  22978. && !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  22979. !defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC)
  22980. ecc_key key;
  22981. WC_RNG rng;
  22982. int ret;
  22983. mp_int r;
  22984. mp_int s;
  22985. mp_int z;
  22986. unsigned char hash[] = "Everyone gets Friday off.EccSig";
  22987. unsigned char iHash[] = "Everyone gets Friday off.......";
  22988. unsigned char shortHash[] = TEST_STRING;
  22989. word32 hashlen = sizeof(hash);
  22990. word32 iHashLen = sizeof(iHash);
  22991. word32 shortHashLen = sizeof(shortHash);
  22992. int keySz = KEY32;
  22993. int verify_ok = 0;
  22994. XMEMSET(&key, 0, sizeof(ecc_key));
  22995. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22996. XMEMSET(&r, 0, sizeof(mp_int));
  22997. XMEMSET(&s, 0, sizeof(mp_int));
  22998. XMEMSET(&z, 0, sizeof(mp_int));
  22999. /* Initialize r, s and z. */
  23000. ExpectIntEQ(mp_init_multi(&r, &s, &z, NULL, NULL, NULL), MP_OKAY);
  23001. ExpectIntEQ(wc_ecc_init(&key), 0);
  23002. ExpectIntEQ(wc_InitRng(&rng), 0);
  23003. ret = wc_ecc_make_key(&rng, keySz, &key);
  23004. #if defined(WOLFSSL_ASYNC_CRYPT)
  23005. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23006. #endif
  23007. ExpectIntEQ(ret, 0);
  23008. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, &s), 0);
  23009. /* verify_ok should be 1. */
  23010. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, hash, hashlen, &verify_ok, &key),
  23011. 0);
  23012. ExpectIntEQ(verify_ok, 1);
  23013. /* verify_ok should be 0 */
  23014. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, iHash, iHashLen, &verify_ok,
  23015. &key), 0);
  23016. ExpectIntEQ(verify_ok, 0);
  23017. /* verify_ok should be 0. */
  23018. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23019. &verify_ok, &key), 0);
  23020. ExpectIntEQ(verify_ok, 0);
  23021. /* Test bad args. */
  23022. ExpectIntEQ(wc_ecc_sign_hash_ex(NULL, hashlen, &rng, &key, &r, &s),
  23023. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23024. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, NULL, &key, &r, &s),
  23025. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23026. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, NULL, &r, &s),
  23027. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23028. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, NULL, &s),
  23029. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23030. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, NULL),
  23031. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23032. /* Test bad args. */
  23033. ExpectIntEQ(wc_ecc_verify_hash_ex(NULL, &s, shortHash, shortHashLen,
  23034. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23035. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, NULL, shortHash, shortHashLen,
  23036. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23037. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &s, shortHash, shortHashLen,
  23038. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23039. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &z, shortHash, shortHashLen,
  23040. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23041. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &z, shortHash, shortHashLen,
  23042. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23043. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, NULL, shortHashLen, &verify_ok,
  23044. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23045. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen, NULL,
  23046. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23047. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23048. &verify_ok, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23049. wc_ecc_free(&key);
  23050. mp_free(&r);
  23051. mp_free(&s);
  23052. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23053. #endif
  23054. return EXPECT_RESULT();
  23055. } /* END test_wc_ecc_verify_hash_ex */
  23056. /*
  23057. * Testing wc_ecc_mulmod()
  23058. */
  23059. static int test_wc_ecc_mulmod(void)
  23060. {
  23061. EXPECT_DECLS;
  23062. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  23063. !(defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
  23064. defined(WOLFSSL_VALIDATE_ECC_IMPORT))
  23065. ecc_key key1;
  23066. ecc_key key2;
  23067. ecc_key key3;
  23068. WC_RNG rng;
  23069. int ret;
  23070. XMEMSET(&key1, 0, sizeof(ecc_key));
  23071. XMEMSET(&key2, 0, sizeof(ecc_key));
  23072. XMEMSET(&key3, 0, sizeof(ecc_key));
  23073. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23074. ExpectIntEQ(wc_ecc_init(&key1), 0);
  23075. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23076. ExpectIntEQ(wc_ecc_init(&key3), 0);
  23077. ExpectIntEQ(wc_InitRng(&rng), 0);
  23078. ret = wc_ecc_make_key(&rng, KEY32, &key1);
  23079. #if defined(WOLFSSL_ASYNC_CRYPT)
  23080. ret = wc_AsyncWait(ret, &key1.asyncDev, WC_ASYNC_FLAG_NONE);
  23081. #endif
  23082. ExpectIntEQ(ret, 0);
  23083. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23084. ExpectIntEQ(wc_ecc_import_raw_ex(&key2, key1.dp->Gx, key1.dp->Gy,
  23085. key1.dp->Af, ECC_SECP256R1), 0);
  23086. ExpectIntEQ(wc_ecc_import_raw_ex(&key3, key1.dp->Gx, key1.dp->Gy,
  23087. key1.dp->prime, ECC_SECP256R1), 0);
  23088. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23089. &key3.pubkey, wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3),
  23090. 1), 0);
  23091. /* Test bad args. */
  23092. ExpectIntEQ(ret = wc_ecc_mulmod(NULL, &key2.pubkey, &key3.pubkey,
  23093. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23094. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23095. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), NULL, &key3.pubkey,
  23096. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23097. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23098. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey, NULL,
  23099. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23100. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23101. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23102. &key3.pubkey, wc_ecc_key_get_priv(&key2), NULL, 1), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23103. wc_ecc_free(&key1);
  23104. wc_ecc_free(&key2);
  23105. wc_ecc_free(&key3);
  23106. #ifdef FP_ECC
  23107. wc_ecc_fp_free();
  23108. #endif
  23109. #endif /* HAVE_ECC && !WOLFSSL_ATECC508A */
  23110. return EXPECT_RESULT();
  23111. } /* END test_wc_ecc_mulmod */
  23112. /*
  23113. * Testing wc_ecc_is_valid_idx()
  23114. */
  23115. static int test_wc_ecc_is_valid_idx(void)
  23116. {
  23117. EXPECT_DECLS;
  23118. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23119. ecc_key key;
  23120. WC_RNG rng;
  23121. int ret;
  23122. int iVal = -2;
  23123. int iVal2 = 3000;
  23124. XMEMSET(&key, 0, sizeof(ecc_key));
  23125. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23126. ExpectIntEQ(wc_ecc_init(&key), 0);
  23127. ExpectIntEQ(wc_InitRng(&rng), 0);
  23128. ret = wc_ecc_make_key(&rng, 32, &key);
  23129. #if defined(WOLFSSL_ASYNC_CRYPT)
  23130. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23131. #endif
  23132. ExpectIntEQ(ret, 0);
  23133. ExpectIntEQ(wc_ecc_is_valid_idx(key.idx), 1);
  23134. /* Test bad args. */
  23135. ExpectIntEQ(wc_ecc_is_valid_idx(iVal), 0);
  23136. ExpectIntEQ(wc_ecc_is_valid_idx(iVal2), 0);
  23137. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23138. wc_ecc_free(&key);
  23139. #ifdef FP_ECC
  23140. wc_ecc_fp_free();
  23141. #endif
  23142. #endif
  23143. return EXPECT_RESULT();
  23144. } /* END test_wc_ecc_is_valid_idx */
  23145. /*
  23146. * Testing wc_ecc_get_curve_id_from_oid()
  23147. */
  23148. static int test_wc_ecc_get_curve_id_from_oid(void)
  23149. {
  23150. EXPECT_DECLS;
  23151. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  23152. !defined(HAVE_FIPS)
  23153. const byte oid[] = {0x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07};
  23154. word32 len = sizeof(oid);
  23155. /* Bad Cases */
  23156. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(NULL, len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23157. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, 0), ECC_CURVE_INVALID);
  23158. /* Good Case */
  23159. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, len), ECC_SECP256R1);
  23160. #endif
  23161. return EXPECT_RESULT();
  23162. } /* END test_wc_ecc_get_curve_id_from_oid */
  23163. /*
  23164. * Testing wc_ecc_sig_size_calc()
  23165. */
  23166. static int test_wc_ecc_sig_size_calc(void)
  23167. {
  23168. EXPECT_DECLS;
  23169. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST)
  23170. ecc_key key;
  23171. WC_RNG rng;
  23172. int sz = 0;
  23173. int ret;
  23174. XMEMSET(&key, 0, sizeof(ecc_key));
  23175. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23176. ExpectIntEQ(wc_ecc_init(&key), 0);
  23177. ExpectIntEQ(wc_InitRng(&rng), 0);
  23178. ret = wc_ecc_make_key(&rng, 16, &key);
  23179. #if defined(WOLFSSL_ASYNC_CRYPT)
  23180. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23181. #endif
  23182. #if FIPS_VERSION3_GE(6,0,0)
  23183. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23184. #else
  23185. ExpectIntEQ(ret, 0);
  23186. #endif
  23187. #if FIPS_VERSION3_LT(6,0,0)
  23188. sz = key.dp->size;
  23189. ExpectIntGT(wc_ecc_sig_size_calc(sz), 0);
  23190. #else
  23191. (void) sz;
  23192. #endif
  23193. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23194. wc_ecc_free(&key);
  23195. #endif
  23196. return EXPECT_RESULT();
  23197. } /* END test_wc_ecc_sig_size_calc */
  23198. /*
  23199. * Testing wc_ecc_sm2_make_key()
  23200. */
  23201. static int test_wc_ecc_sm2_make_key(void)
  23202. {
  23203. int res = TEST_SKIPPED;
  23204. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23205. EXPECT_DECLS;
  23206. WC_RNG rng[1];
  23207. ecc_key key[1];
  23208. XMEMSET(rng, 0, sizeof(*rng));
  23209. XMEMSET(key, 0, sizeof(*key));
  23210. ExpectIntEQ(wc_InitRng(rng), 0);
  23211. ExpectIntEQ(wc_ecc_init(key), 0);
  23212. /* Test invalid parameters. */
  23213. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, NULL, WC_ECC_FLAG_NONE),
  23214. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23215. ExpectIntEQ(wc_ecc_sm2_make_key(rng, NULL, WC_ECC_FLAG_NONE),
  23216. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23217. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, key, WC_ECC_FLAG_NONE),
  23218. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23219. /* Test valid parameters. */
  23220. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23221. ExpectIntEQ(key->dp->id, ECC_SM2P256V1);
  23222. wc_ecc_free(key);
  23223. wc_FreeRng(rng);
  23224. #ifdef FP_ECC
  23225. wc_ecc_fp_free();
  23226. #endif
  23227. res = EXPECT_RESULT();
  23228. #endif
  23229. return res;
  23230. }
  23231. /*
  23232. * Testing wc_ecc_sm2_shared_secret()
  23233. */
  23234. static int test_wc_ecc_sm2_shared_secret(void)
  23235. {
  23236. int res = TEST_SKIPPED;
  23237. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23238. EXPECT_DECLS;
  23239. WC_RNG rng[1];
  23240. ecc_key keyA[1];
  23241. ecc_key keyB[1];
  23242. byte outA[32];
  23243. byte outB[32];
  23244. word32 outALen = 32;
  23245. word32 outBLen = 32;
  23246. XMEMSET(rng, 0, sizeof(*rng));
  23247. XMEMSET(keyA, 0, sizeof(*keyA));
  23248. XMEMSET(keyB, 0, sizeof(*keyB));
  23249. ExpectIntEQ(wc_InitRng(rng), 0);
  23250. ExpectIntEQ(wc_ecc_init(keyA), 0);
  23251. ExpectIntEQ(wc_ecc_init(keyB), 0);
  23252. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyA, WC_ECC_FLAG_NONE), 0);
  23253. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyB, WC_ECC_FLAG_NONE), 0);
  23254. #ifdef ECC_TIMING_RESISTANT
  23255. ExpectIntEQ(wc_ecc_set_rng(keyA, rng), 0);
  23256. ExpectIntEQ(wc_ecc_set_rng(keyB, rng), 0);
  23257. #endif
  23258. /* Test invalid parameters. */
  23259. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23260. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23261. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23262. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23263. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, &outALen),
  23264. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23265. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, outA, &outALen),
  23266. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23267. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, outA, &outALen),
  23268. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23269. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, NULL, &outALen),
  23270. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23271. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23272. /* Test valid parameters. */
  23273. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, &outALen), 0);
  23274. ExpectIntLE(outALen, 32);
  23275. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyB, keyA, outB, &outBLen), 0);
  23276. ExpectIntLE(outBLen, 32);
  23277. ExpectIntEQ(outALen, outBLen);
  23278. ExpectBufEQ(outA, outB, outALen);
  23279. wc_ecc_free(keyB);
  23280. wc_ecc_free(keyA);
  23281. wc_FreeRng(rng);
  23282. #ifdef FP_ECC
  23283. wc_ecc_fp_free();
  23284. #endif
  23285. res = EXPECT_RESULT();
  23286. #endif
  23287. return res;
  23288. }
  23289. /*
  23290. * Testing wc_ecc_sm2_create_digest()
  23291. */
  23292. static int test_wc_ecc_sm2_create_digest(void)
  23293. {
  23294. int res = TEST_SKIPPED;
  23295. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && !defined(NO_HASH_WRAPPER) && \
  23296. (defined(WOLFSSL_SM3) || !defined(NO_SHA256))
  23297. EXPECT_DECLS;
  23298. ecc_key key[1];
  23299. enum wc_HashType hashType;
  23300. unsigned char pub[] = {
  23301. 0x04,
  23302. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23303. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23304. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23305. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23306. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23307. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23308. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23309. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23310. };
  23311. unsigned char id[] = {
  23312. 0x01, 0x02, 0x03,
  23313. };
  23314. unsigned char msg[] = {
  23315. 0x01, 0x02, 0x03,
  23316. };
  23317. unsigned char hash[32];
  23318. #ifdef WOLFSSL_SM3
  23319. unsigned char expHash[32] = {
  23320. 0xc1, 0xdd, 0x92, 0xc5, 0x60, 0xd3, 0x94, 0x28,
  23321. 0xeb, 0x0f, 0x57, 0x79, 0x3f, 0xc9, 0x96, 0xc5,
  23322. 0xfa, 0xf5, 0x90, 0xb2, 0x64, 0x2f, 0xaf, 0x9c,
  23323. 0xc8, 0x57, 0x21, 0x6a, 0x52, 0x7e, 0xf1, 0x95
  23324. };
  23325. #else
  23326. unsigned char expHash[32] = {
  23327. 0xea, 0x41, 0x55, 0x21, 0x61, 0x00, 0x5c, 0x9a,
  23328. 0x57, 0x35, 0x6b, 0x49, 0xca, 0x8f, 0x65, 0xc2,
  23329. 0x0e, 0x29, 0x0c, 0xa0, 0x1d, 0xa7, 0xc4, 0xed,
  23330. 0xdd, 0x51, 0x12, 0xf6, 0xe7, 0x55, 0xc5, 0xf4
  23331. };
  23332. #endif
  23333. #ifdef WOLFSSL_SM3
  23334. hashType = WC_HASH_TYPE_SM3;
  23335. #else
  23336. hashType = WC_HASH_TYPE_SHA256;
  23337. #endif
  23338. XMEMSET(key, 0, sizeof(*key));
  23339. ExpectIntEQ(wc_ecc_init(key), 0);
  23340. /* Test with no curve set. */
  23341. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23342. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23343. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23344. /* Test invalid parameters. */
  23345. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23346. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23347. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23348. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23349. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23350. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23351. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23352. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23353. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23354. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23355. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23356. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23357. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23358. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23359. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23360. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23361. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23362. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23363. /* Bad hash type. */
  23364. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23365. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23366. -1, hash, 0, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23367. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23368. /* Bad hash size. */
  23369. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23370. hashType, hash, 0, key), WC_NO_ERR_TRACE(BUFFER_E));
  23371. /* Test valid parameters. */
  23372. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23373. hashType, hash, sizeof(hash), key), 0);
  23374. ExpectBufEQ(hash, expHash, sizeof(expHash));
  23375. wc_ecc_free(key);
  23376. res = EXPECT_RESULT();
  23377. #endif
  23378. return res;
  23379. }
  23380. /*
  23381. * Testing wc_ecc_sm2_verify_hash_ex()
  23382. */
  23383. static int test_wc_ecc_sm2_verify_hash_ex(void)
  23384. {
  23385. int res = TEST_SKIPPED;
  23386. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY) && \
  23387. defined(WOLFSSL_PUBLIC_MP)
  23388. EXPECT_DECLS;
  23389. ecc_key key[1];
  23390. mp_int r[1];
  23391. mp_int s[1];
  23392. int verified;
  23393. unsigned char pub[] = {
  23394. 0x04,
  23395. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23396. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23397. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23398. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23399. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23400. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23401. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23402. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23403. };
  23404. unsigned char hash[] = {
  23405. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23406. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23407. 0x50, 0x69, 0x5B, 0x20
  23408. };
  23409. unsigned char rData[] = {
  23410. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23411. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23412. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23413. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE7,
  23414. };
  23415. unsigned char sData[] = {
  23416. 0x1D,
  23417. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23418. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23419. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23420. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23421. };
  23422. unsigned char rBadData[] = {
  23423. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23424. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23425. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23426. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE8,
  23427. };
  23428. XMEMSET(key, 0, sizeof(*key));
  23429. XMEMSET(r, 0, sizeof(*r));
  23430. XMEMSET(s, 0, sizeof(*s));
  23431. ExpectIntEQ(mp_init(r), 0);
  23432. ExpectIntEQ(mp_init(s), 0);
  23433. ExpectIntEQ(mp_read_unsigned_bin(r, rData, sizeof(rData)), 0);
  23434. ExpectIntEQ(mp_read_unsigned_bin(s, sData, sizeof(sData)), 0);
  23435. ExpectIntEQ(wc_ecc_init(key), 0);
  23436. /* Test with no curve set. */
  23437. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23438. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23439. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23440. /* Test invalid parameters. */
  23441. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23442. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23443. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, NULL, sizeof(hash),
  23444. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23445. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, NULL, sizeof(hash),
  23446. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23447. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, hash, sizeof(hash),
  23448. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23449. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23450. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23451. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23452. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23453. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, hash, sizeof(hash),
  23454. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23455. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, hash, sizeof(hash),
  23456. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23457. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, NULL, sizeof(hash),
  23458. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23459. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23460. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23461. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23462. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23463. /* Make key not on the SM2 curve. */
  23464. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23465. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23466. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23467. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23468. /* Test valid parameters. */
  23469. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23470. &verified, key), 0);
  23471. ExpectIntEQ(verified, 1);
  23472. ExpectIntEQ(mp_read_unsigned_bin(r, rBadData, sizeof(rBadData)), 0);
  23473. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23474. &verified, key), 0);
  23475. ExpectIntEQ(verified, 0);
  23476. mp_free(s);
  23477. mp_free(r);
  23478. wc_ecc_free(key);
  23479. #ifdef FP_ECC
  23480. wc_ecc_fp_free();
  23481. #endif
  23482. res = EXPECT_RESULT();
  23483. #endif
  23484. return res;
  23485. }
  23486. /*
  23487. * Testing wc_ecc_sm2_verify_hash()
  23488. */
  23489. static int test_wc_ecc_sm2_verify_hash(void)
  23490. {
  23491. int res = TEST_SKIPPED;
  23492. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY)
  23493. EXPECT_DECLS;
  23494. ecc_key key[1];
  23495. int verified;
  23496. unsigned char pub[] = {
  23497. 0x04,
  23498. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23499. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23500. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23501. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23502. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23503. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23504. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23505. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23506. };
  23507. unsigned char hash[] = {
  23508. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23509. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23510. 0x50, 0x69, 0x5B, 0x20
  23511. };
  23512. unsigned char sig[] = {
  23513. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23514. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23515. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23516. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23517. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23518. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23519. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23520. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23521. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23522. };
  23523. unsigned char sigBad[] = {
  23524. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23525. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23526. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23527. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23528. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23529. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23530. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23531. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23532. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDD
  23533. };
  23534. XMEMSET(key, 0, sizeof(*key));
  23535. ExpectIntEQ(wc_ecc_init(key), 0);
  23536. /* Test with no curve set. */
  23537. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23538. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23539. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23540. /* Test invalid parameters. */
  23541. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23542. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23543. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  23544. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23545. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23546. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23547. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23548. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23549. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23550. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23551. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23552. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23553. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  23554. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23555. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23556. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23557. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23558. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23559. /* Make key not on the SM2 curve. */
  23560. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23561. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23562. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23563. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23564. /* Test valid parameters. */
  23565. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23566. &verified, key), 0);
  23567. ExpectIntEQ(verified, 1);
  23568. ExpectIntEQ(wc_ecc_sm2_verify_hash(sigBad, sizeof(sigBad), hash,
  23569. sizeof(hash), &verified, key), 0);
  23570. ExpectIntEQ(verified, 0);
  23571. wc_ecc_free(key);
  23572. #ifdef FP_ECC
  23573. wc_ecc_fp_free();
  23574. #endif
  23575. res = EXPECT_RESULT();
  23576. #endif
  23577. return res;
  23578. }
  23579. /*
  23580. * Testing wc_ecc_sm2_verify_hash_ex()
  23581. */
  23582. static int test_wc_ecc_sm2_sign_hash_ex(void)
  23583. {
  23584. int res = TEST_SKIPPED;
  23585. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN) && \
  23586. defined(WOLFSSL_PUBLIC_MP)
  23587. EXPECT_DECLS;
  23588. WC_RNG rng[1];
  23589. ecc_key key[1];
  23590. mp_int r[1];
  23591. mp_int s[1];
  23592. unsigned char hash[32];
  23593. #ifdef HAVE_ECC_VERIFY
  23594. int verified;
  23595. #endif
  23596. XMEMSET(rng, 0, sizeof(*rng));
  23597. XMEMSET(key, 0, sizeof(*key));
  23598. XMEMSET(r, 0, sizeof(*r));
  23599. XMEMSET(s, 0, sizeof(*s));
  23600. ExpectIntEQ(wc_InitRng(rng), 0);
  23601. ExpectIntEQ(mp_init(r), 0);
  23602. ExpectIntEQ(mp_init(s), 0);
  23603. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  23604. ExpectIntEQ(wc_ecc_init(key), 0);
  23605. /* Test with no curve set. */
  23606. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  23607. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23608. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23609. /* Test invalid parameters. */
  23610. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  23611. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23612. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, NULL, NULL,
  23613. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23614. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, NULL, NULL,
  23615. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23616. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, key, NULL,
  23617. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23618. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, r,
  23619. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23620. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  23621. s), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23622. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, key, r, s),
  23623. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23624. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, key, r, s),
  23625. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23626. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, NULL, r, s),
  23627. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23628. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, NULL, s),
  23629. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23630. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, NULL),
  23631. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23632. /* Make key not on the SM2 curve. */
  23633. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23634. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  23635. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23636. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23637. #ifdef WOLFSSL_SP_MATH_ALL
  23638. {
  23639. mp_int smallR[1];
  23640. sp_init_size(smallR, 1);
  23641. /* Force failure in _ecc_sm2_calc_r_s by r being too small. */
  23642. ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
  23643. smallR, s), 0);
  23644. }
  23645. #endif
  23646. /* Test valid parameters. */
  23647. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  23648. 0);
  23649. #ifdef HAVE_ECC_VERIFY
  23650. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash), &verified,
  23651. key), 0);
  23652. ExpectIntEQ(verified, 1);
  23653. #endif
  23654. mp_free(s);
  23655. mp_free(r);
  23656. wc_ecc_free(key);
  23657. wc_FreeRng(rng);
  23658. #ifdef FP_ECC
  23659. wc_ecc_fp_free();
  23660. #endif
  23661. res = EXPECT_RESULT();
  23662. #endif
  23663. return res;
  23664. }
  23665. /*
  23666. * Testing wc_ecc_sm2_verify_hash()
  23667. */
  23668. static int test_wc_ecc_sm2_sign_hash(void)
  23669. {
  23670. int res = TEST_SKIPPED;
  23671. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN)
  23672. EXPECT_DECLS;
  23673. WC_RNG rng[1];
  23674. ecc_key key[1];
  23675. unsigned char hash[32];
  23676. unsigned char sig[72];
  23677. word32 sigSz = sizeof(sig);
  23678. #ifdef HAVE_ECC_VERIFY
  23679. int verified;
  23680. #endif
  23681. XMEMSET(rng, 0, sizeof(*rng));
  23682. XMEMSET(key, 0, sizeof(*key));
  23683. ExpectIntEQ(wc_InitRng(rng), 0);
  23684. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  23685. ExpectIntEQ(wc_ecc_init(key), 0);
  23686. /* Test with no curve set. */
  23687. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  23688. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23689. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23690. /* Test invalid parameters. */
  23691. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  23692. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23693. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, NULL, NULL,
  23694. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23695. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, NULL, NULL,
  23696. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23697. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, &sigSz, NULL,
  23698. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23699. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, rng,
  23700. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23701. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  23702. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23703. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, &sigSz, rng,
  23704. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23705. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, &sigSz, rng,
  23706. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23707. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, NULL, rng,
  23708. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23709. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, NULL,
  23710. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23711. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng,
  23712. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23713. /* Make key not on the SM2 curve. */
  23714. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23715. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  23716. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23717. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23718. /* Test valid parameters. */
  23719. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  23720. 0);
  23721. #ifdef HAVE_ECC_VERIFY
  23722. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sigSz, hash, sizeof(hash),
  23723. &verified, key), 0);
  23724. ExpectIntEQ(verified, 1);
  23725. #endif
  23726. wc_ecc_free(key);
  23727. wc_FreeRng(rng);
  23728. #ifdef FP_ECC
  23729. wc_ecc_fp_free();
  23730. #endif
  23731. res = EXPECT_RESULT();
  23732. #endif
  23733. return res;
  23734. }
  23735. /*
  23736. * Testing ToTraditional
  23737. */
  23738. static int test_ToTraditional(void)
  23739. {
  23740. EXPECT_DECLS;
  23741. #if !defined(NO_ASN) && (defined(HAVE_PKCS8) || defined(HAVE_PKCS12)) && \
  23742. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  23743. defined(OPENSSL_EXTRA_X509_SMALL)) && !defined(NO_FILESYSTEM)
  23744. XFILE f = XBADFILE;
  23745. byte input[TWOK_BUF];
  23746. word32 sz = 0;
  23747. ExpectTrue((f = XFOPEN("./certs/server-keyPkcs8.der", "rb")) != XBADFILE);
  23748. ExpectTrue((sz = (word32)XFREAD(input, 1, sizeof(input), f)) > 0);
  23749. if (f != XBADFILE)
  23750. XFCLOSE(f);
  23751. /* Good case */
  23752. ExpectIntGT(ToTraditional(input, sz), 0);
  23753. /* Bad cases */
  23754. ExpectIntEQ(ToTraditional(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23755. ExpectIntEQ(ToTraditional(NULL, sz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23756. #ifdef WOLFSSL_ASN_TEMPLATE
  23757. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(BUFFER_E));
  23758. #else
  23759. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(ASN_PARSE_E));
  23760. #endif
  23761. #endif
  23762. return EXPECT_RESULT();
  23763. } /* End test_ToTraditional*/
  23764. /*
  23765. * Testing wc_EccPrivateKeyToDer
  23766. */
  23767. static int test_wc_EccPrivateKeyToDer(void)
  23768. {
  23769. EXPECT_DECLS;
  23770. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  23771. byte output[ONEK_BUF];
  23772. ecc_key eccKey;
  23773. WC_RNG rng;
  23774. word32 inLen;
  23775. word32 outLen = 0;
  23776. int ret;
  23777. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  23778. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23779. PRIVATE_KEY_UNLOCK();
  23780. ExpectIntEQ(wc_InitRng(&rng), 0);
  23781. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  23782. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  23783. #if defined(WOLFSSL_ASYNC_CRYPT)
  23784. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23785. #endif
  23786. ExpectIntEQ(ret, 0);
  23787. inLen = (word32)sizeof(output);
  23788. /* Bad Cases */
  23789. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23790. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23791. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, NULL, inLen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  23792. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23793. /* Good Case */
  23794. ExpectIntGT(outLen = (word32)wc_EccPrivateKeyToDer(&eccKey, output, inLen), 0);
  23795. wc_ecc_free(&eccKey);
  23796. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23797. #if defined(OPENSSL_EXTRA) && defined(HAVE_ALL_CURVES)
  23798. {
  23799. /* test importing private only into a PKEY struct */
  23800. EC_KEY* ec = NULL;
  23801. EVP_PKEY* pkey = NULL;
  23802. const unsigned char* der;
  23803. der = output;
  23804. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &der, outLen));
  23805. der = output;
  23806. ExpectNotNull(ec = d2i_ECPrivateKey(NULL, &der, outLen));
  23807. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ec), SSL_SUCCESS);
  23808. if (EXPECT_FAIL()) {
  23809. EC_KEY_free(ec);
  23810. }
  23811. EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */
  23812. }
  23813. #endif
  23814. PRIVATE_KEY_LOCK();
  23815. #endif
  23816. return EXPECT_RESULT();
  23817. } /* End test_wc_EccPrivateKeyToDer*/
  23818. /*
  23819. * Testing wc_DhPublicKeyDecode
  23820. */
  23821. static int test_wc_DhPublicKeyDecode(void)
  23822. {
  23823. EXPECT_DECLS;
  23824. #ifndef NO_DH
  23825. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  23826. DhKey key;
  23827. word32 inOutIdx;
  23828. XMEMSET(&key, 0, sizeof(DhKey));
  23829. ExpectIntEQ(wc_InitDhKey(&key), 0);
  23830. ExpectIntEQ(wc_DhPublicKeyDecode(NULL,NULL,NULL,0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23831. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  23832. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23833. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  23834. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23835. inOutIdx = 0;
  23836. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL, 0),
  23837. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23838. inOutIdx = 0;
  23839. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, 0),
  23840. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23841. inOutIdx = 0;
  23842. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
  23843. sizeof_dh_pub_key_der_2048), 0);
  23844. ExpectIntNE(key.p.used, 0);
  23845. ExpectIntNE(key.g.used, 0);
  23846. ExpectIntEQ(key.q.used, 0);
  23847. ExpectIntNE(key.pub.used, 0);
  23848. ExpectIntEQ(key.priv.used, 0);
  23849. DoExpectIntEQ(wc_FreeDhKey(&key), 0);
  23850. #endif
  23851. #endif /* !NO_DH */
  23852. return EXPECT_RESULT();
  23853. }
  23854. /*
  23855. * Testing wc_Ed25519KeyToDer
  23856. */
  23857. static int test_wc_Ed25519KeyToDer(void)
  23858. {
  23859. EXPECT_DECLS;
  23860. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  23861. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  23862. byte output[ONEK_BUF];
  23863. ed25519_key ed25519Key;
  23864. WC_RNG rng;
  23865. word32 inLen;
  23866. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  23867. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23868. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  23869. ExpectIntEQ(wc_InitRng(&rng), 0);
  23870. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  23871. inLen = (word32)sizeof(output);
  23872. /* Bad Cases */
  23873. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23874. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23875. ExpectIntEQ(wc_Ed25519KeyToDer(&ed25519Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  23876. /* Good Cases */
  23877. /* length only */
  23878. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, 0), 0);
  23879. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, inLen), 0);
  23880. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, output, inLen), 0);
  23881. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23882. wc_ed25519_free(&ed25519Key);
  23883. #endif
  23884. return EXPECT_RESULT();
  23885. } /* End test_wc_Ed25519KeyToDer*/
  23886. /*
  23887. * Testing wc_Ed25519PrivateKeyToDer
  23888. */
  23889. static int test_wc_Ed25519PrivateKeyToDer(void)
  23890. {
  23891. EXPECT_DECLS;
  23892. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  23893. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  23894. byte output[ONEK_BUF];
  23895. ed25519_key ed25519PrivKey;
  23896. WC_RNG rng;
  23897. word32 inLen;
  23898. XMEMSET(&ed25519PrivKey, 0, sizeof(ed25519_key));
  23899. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23900. ExpectIntEQ(wc_ed25519_init(&ed25519PrivKey), 0);
  23901. ExpectIntEQ(wc_InitRng(&rng), 0);
  23902. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519PrivKey),
  23903. 0);
  23904. inLen = (word32)sizeof(output);
  23905. /* Bad Cases */
  23906. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23907. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23908. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, 0),
  23909. WC_NO_ERR_TRACE(BUFFER_E));
  23910. /* Good Cases */
  23911. /* length only */
  23912. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, NULL, 0), 0);
  23913. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, inLen), 0);
  23914. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23915. wc_ed25519_free(&ed25519PrivKey);
  23916. #endif
  23917. return EXPECT_RESULT();
  23918. } /* End test_wc_Ed25519PrivateKeyToDer*/
  23919. /*
  23920. * Testing wc_Ed448KeyToDer
  23921. */
  23922. static int test_wc_Ed448KeyToDer(void)
  23923. {
  23924. EXPECT_DECLS;
  23925. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  23926. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  23927. byte output[ONEK_BUF];
  23928. ed448_key ed448Key;
  23929. WC_RNG rng;
  23930. word32 inLen;
  23931. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  23932. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23933. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  23934. ExpectIntEQ(wc_InitRng(&rng), 0);
  23935. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  23936. inLen = (word32)sizeof(output);
  23937. /* Bad Cases */
  23938. ExpectIntEQ(wc_Ed448KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23939. ExpectIntEQ(wc_Ed448KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23940. ExpectIntEQ(wc_Ed448KeyToDer(&ed448Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  23941. /* Good Cases */
  23942. /* length only */
  23943. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, NULL, 0), 0);
  23944. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, output, inLen), 0);
  23945. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23946. wc_ed448_free(&ed448Key);
  23947. #endif
  23948. return EXPECT_RESULT();
  23949. } /* End test_wc_Ed448KeyToDer*/
  23950. /*
  23951. * Testing wc_Ed448PrivateKeyToDer
  23952. */
  23953. static int test_wc_Ed448PrivateKeyToDer(void)
  23954. {
  23955. EXPECT_DECLS;
  23956. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  23957. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  23958. byte output[ONEK_BUF];
  23959. ed448_key ed448PrivKey;
  23960. WC_RNG rng;
  23961. word32 inLen;
  23962. XMEMSET(&ed448PrivKey, 0, sizeof(ed448_key));
  23963. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23964. ExpectIntEQ(wc_ed448_init(&ed448PrivKey), 0);
  23965. ExpectIntEQ(wc_InitRng(&rng), 0);
  23966. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448PrivKey),
  23967. 0);
  23968. inLen = (word32)sizeof(output);
  23969. /* Bad Cases */
  23970. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23971. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23972. ExpectIntEQ(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, 0),
  23973. WC_NO_ERR_TRACE(BUFFER_E));
  23974. /* Good cases */
  23975. /* length only */
  23976. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, NULL, 0), 0);
  23977. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, inLen), 0);
  23978. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23979. wc_ed448_free(&ed448PrivKey);
  23980. #endif
  23981. return EXPECT_RESULT();
  23982. } /* End test_wc_Ed448PrivateKeyToDer*/
  23983. /*
  23984. * Testing wc_Curve448PrivateKeyToDer
  23985. */
  23986. static int test_wc_Curve448PrivateKeyToDer(void)
  23987. {
  23988. EXPECT_DECLS;
  23989. #if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
  23990. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  23991. byte output[ONEK_BUF];
  23992. curve448_key curve448PrivKey;
  23993. WC_RNG rng;
  23994. word32 inLen;
  23995. XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
  23996. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23997. ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
  23998. ExpectIntEQ(wc_InitRng(&rng), 0);
  23999. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
  24000. 0);
  24001. inLen = (word32)sizeof(output);
  24002. /* Bad Cases */
  24003. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24004. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24005. ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
  24006. WC_NO_ERR_TRACE(BUFFER_E));
  24007. /* Good cases */
  24008. /* length only */
  24009. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, 0), 0);
  24010. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);
  24011. /* Bad Cases */
  24012. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24013. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24014. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
  24015. WC_NO_ERR_TRACE(BUFFER_E));
  24016. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
  24017. WC_NO_ERR_TRACE(BUFFER_E));
  24018. /* Good cases */
  24019. /* length only */
  24020. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 0), 0);
  24021. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 1), 0);
  24022. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0), 0);
  24023. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1), 0);
  24024. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24025. wc_curve448_free(&curve448PrivKey);
  24026. #endif
  24027. return EXPECT_RESULT();
  24028. } /* End wc_Curve448PrivateKeyToDer*/
  24029. static int test_wc_kyber_make_key_kats(void)
  24030. {
  24031. EXPECT_DECLS;
  24032. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  24033. !defined(WOLFSSL_KYBER_ORIGINAL)
  24034. KyberKey* key;
  24035. #ifndef WOLFSSL_NO_KYBER512
  24036. static const byte seed_512[KYBER_MAKEKEY_RAND_SZ] = {
  24037. /* d */
  24038. 0x2C, 0xB8, 0x43, 0xA0, 0x2E, 0xF0, 0x2E, 0xE1,
  24039. 0x09, 0x30, 0x5F, 0x39, 0x11, 0x9F, 0xAB, 0xF4,
  24040. 0x9A, 0xB9, 0x0A, 0x57, 0xFF, 0xEC, 0xB3, 0xA0,
  24041. 0xE7, 0x5E, 0x17, 0x94, 0x50, 0xF5, 0x27, 0x61,
  24042. /* z */
  24043. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24044. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24045. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24046. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24047. };
  24048. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  24049. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24050. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24051. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24052. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24053. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24054. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24055. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24056. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24057. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24058. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24059. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24060. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24061. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24062. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24063. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24064. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24065. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24066. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24067. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24068. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24069. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24070. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24071. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24072. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24073. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24074. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24075. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24076. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24077. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24078. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24079. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24080. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24081. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24082. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24083. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24084. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24085. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24086. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24087. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24088. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24089. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24090. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24091. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24092. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24093. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24094. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24095. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24096. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24097. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24098. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24099. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24100. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24101. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24102. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24103. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24104. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24105. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24106. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24107. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24108. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24109. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24110. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24111. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24112. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24113. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24114. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24115. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24116. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24117. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24118. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24119. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24120. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24121. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24122. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24123. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24124. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24125. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24126. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24127. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24128. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24129. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24130. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24131. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24132. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24133. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24134. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24135. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24136. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24137. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24138. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24139. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24140. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24141. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24142. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24143. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24144. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24145. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24146. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24147. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24148. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B
  24149. };
  24150. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  24151. 0x7F, 0xE4, 0x20, 0x6F, 0x26, 0xBE, 0xDB, 0x64,
  24152. 0xC1, 0xED, 0x00, 0x09, 0x61, 0x52, 0x45, 0xDC,
  24153. 0x98, 0x48, 0x3F, 0x66, 0x3A, 0xCC, 0x61, 0x7E,
  24154. 0x65, 0x89, 0x8D, 0x59, 0x6A, 0x88, 0x36, 0xC4,
  24155. 0x9F, 0xBD, 0x3B, 0x4A, 0x84, 0x97, 0x59, 0xAA,
  24156. 0x15, 0x46, 0xBD, 0xA8, 0x35, 0xCA, 0xF1, 0x75,
  24157. 0x64, 0x2C, 0x28, 0x28, 0x08, 0x92, 0xA7, 0x87,
  24158. 0x8C, 0xC3, 0x18, 0xBC, 0xC7, 0x5B, 0x83, 0x4C,
  24159. 0xB2, 0x9F, 0xDF, 0x53, 0x60, 0xD7, 0xF9, 0x82,
  24160. 0xA5, 0x2C, 0x88, 0xAE, 0x91, 0x4D, 0xBF, 0x02,
  24161. 0xB5, 0x8B, 0xEB, 0x8B, 0xA8, 0x87, 0xAE, 0x8F,
  24162. 0xAB, 0x5E, 0xB7, 0x87, 0x31, 0xC6, 0x75, 0x78,
  24163. 0x05, 0x47, 0x1E, 0xBC, 0xEC, 0x2E, 0x38, 0xDB,
  24164. 0x1F, 0x4B, 0x83, 0x10, 0xD2, 0x88, 0x92, 0x0D,
  24165. 0x8A, 0x49, 0x27, 0x95, 0xA3, 0x90, 0xA7, 0x4B,
  24166. 0xCD, 0x55, 0xCD, 0x85, 0x57, 0xB4, 0xDA, 0xAB,
  24167. 0xA8, 0x2C, 0x28, 0xCB, 0x3F, 0x15, 0x2C, 0x52,
  24168. 0x31, 0x19, 0x61, 0x93, 0xA6, 0x6A, 0x8C, 0xCF,
  24169. 0x34, 0xB8, 0x0E, 0x1F, 0x69, 0x42, 0xC3, 0x2B,
  24170. 0xCF, 0xF9, 0x6A, 0x6E, 0x3C, 0xF3, 0x93, 0x9B,
  24171. 0x7B, 0x94, 0x24, 0x98, 0xCC, 0x5E, 0x4C, 0xB8,
  24172. 0xE8, 0x46, 0x8E, 0x70, 0x27, 0x59, 0x85, 0x2A,
  24173. 0xA2, 0x29, 0xC0, 0x25, 0x7F, 0x02, 0x98, 0x20,
  24174. 0x97, 0x33, 0x86, 0x07, 0xC0, 0xF0, 0xF4, 0x54,
  24175. 0x46, 0xFA, 0xB4, 0x26, 0x79, 0x93, 0xB8, 0xA5,
  24176. 0x90, 0x8C, 0xAB, 0x9C, 0x46, 0x78, 0x01, 0x34,
  24177. 0x80, 0x4A, 0xE1, 0x88, 0x15, 0xB1, 0x02, 0x05,
  24178. 0x27, 0xA2, 0x22, 0xEC, 0x4B, 0x39, 0xA3, 0x19,
  24179. 0x4E, 0x66, 0x17, 0x37, 0x79, 0x17, 0x14, 0x12,
  24180. 0x26, 0x62, 0xD8, 0xB9, 0x76, 0x9F, 0x6C, 0x67,
  24181. 0xDE, 0x62, 0x5C, 0x0D, 0x48, 0x3C, 0x3D, 0x42,
  24182. 0x0F, 0xF1, 0xBB, 0x88, 0x9A, 0x72, 0x7E, 0x75,
  24183. 0x62, 0x81, 0x51, 0x3A, 0x70, 0x04, 0x76, 0x48,
  24184. 0xD2, 0x9C, 0x0C, 0x30, 0xF9, 0xBE, 0x52, 0xEC,
  24185. 0x0D, 0xEB, 0x97, 0x7C, 0xF0, 0xF3, 0x4F, 0xC2,
  24186. 0x07, 0x84, 0x83, 0x45, 0x69, 0x64, 0x74, 0x34,
  24187. 0x10, 0x63, 0x8C, 0x57, 0xB5, 0x53, 0x95, 0x77,
  24188. 0xBF, 0x85, 0x66, 0x90, 0x78, 0xC3, 0x56, 0xB3,
  24189. 0x46, 0x2E, 0x9F, 0xA5, 0x80, 0x7D, 0x49, 0x59,
  24190. 0x1A, 0xFA, 0x41, 0xC1, 0x96, 0x9F, 0x65, 0xE3,
  24191. 0x40, 0x5C, 0xB6, 0x4D, 0xDF, 0x16, 0x3F, 0x26,
  24192. 0x73, 0x4C, 0xE3, 0x48, 0xB9, 0xCF, 0x45, 0x67,
  24193. 0xA3, 0x3A, 0x59, 0x69, 0xEB, 0x32, 0x6C, 0xFB,
  24194. 0x5A, 0xDC, 0x69, 0x5D, 0xCA, 0x0C, 0x8B, 0x2A,
  24195. 0x7B, 0x1F, 0x4F, 0x40, 0x4C, 0xC7, 0xA0, 0x98,
  24196. 0x1E, 0x2C, 0xC2, 0x4C, 0x1C, 0x23, 0xD1, 0x6A,
  24197. 0xA9, 0xB4, 0x39, 0x24, 0x15, 0xE2, 0x6C, 0x22,
  24198. 0xF4, 0xA9, 0x34, 0xD7, 0x94, 0xC1, 0xFB, 0x4E,
  24199. 0x5A, 0x67, 0x05, 0x11, 0x23, 0xCC, 0xD1, 0x53,
  24200. 0x76, 0x4D, 0xEC, 0x99, 0xD5, 0x53, 0x52, 0x90,
  24201. 0x53, 0xC3, 0xDA, 0x55, 0x0B, 0xCE, 0xA3, 0xAC,
  24202. 0x54, 0x13, 0x6A, 0x26, 0xA6, 0x76, 0xD2, 0xBA,
  24203. 0x84, 0x21, 0x06, 0x70, 0x68, 0xC6, 0x38, 0x1C,
  24204. 0x2A, 0x62, 0xA7, 0x27, 0xC9, 0x33, 0x70, 0x2E,
  24205. 0xE5, 0x80, 0x4A, 0x31, 0xCA, 0x86, 0x5A, 0x45,
  24206. 0x58, 0x8F, 0xB7, 0x4D, 0xE7, 0xE2, 0x22, 0x3D,
  24207. 0x88, 0xC0, 0x60, 0x8A, 0x16, 0xBF, 0xEC, 0x4F,
  24208. 0xAD, 0x67, 0x52, 0xDB, 0x56, 0xB4, 0x8B, 0x88,
  24209. 0x72, 0xBF, 0x26, 0xBA, 0x2F, 0xFA, 0x0C, 0xED,
  24210. 0xE5, 0x34, 0x3B, 0xE8, 0x14, 0x36, 0x89, 0x26,
  24211. 0x5E, 0x06, 0x5F, 0x41, 0xA6, 0x92, 0x5B, 0x86,
  24212. 0xC8, 0x92, 0xE6, 0x2E, 0xB0, 0x77, 0x27, 0x34,
  24213. 0xF5, 0xA3, 0x57, 0xC7, 0x5C, 0xA1, 0xAC, 0x6D,
  24214. 0xF7, 0x8A, 0xB1, 0xB8, 0x88, 0x5A, 0xD0, 0x81,
  24215. 0x96, 0x15, 0x37, 0x6D, 0x33, 0xEB, 0xB9, 0x8F,
  24216. 0x87, 0x33, 0xA6, 0x75, 0x58, 0x03, 0xD9, 0x77,
  24217. 0xBF, 0x51, 0xC1, 0x27, 0x40, 0x42, 0x4B, 0x2B,
  24218. 0x49, 0xC2, 0x83, 0x82, 0xA6, 0x91, 0x7C, 0xBF,
  24219. 0xA0, 0x34, 0xC3, 0xF1, 0x26, 0xA3, 0x8C, 0x21,
  24220. 0x6C, 0x03, 0xC3, 0x57, 0x70, 0xAD, 0x48, 0x1B,
  24221. 0x90, 0x84, 0xB5, 0x58, 0x8D, 0xA6, 0x5F, 0xF1,
  24222. 0x18, 0xA7, 0x4F, 0x93, 0x2C, 0x7E, 0x53, 0x7A,
  24223. 0xBE, 0x58, 0x63, 0xFB, 0x29, 0xA1, 0x0C, 0x09,
  24224. 0x70, 0x1B, 0x44, 0x1F, 0x83, 0x99, 0xC1, 0xF8,
  24225. 0xA6, 0x37, 0x82, 0x5A, 0xCE, 0xA3, 0xE9, 0x31,
  24226. 0x80, 0x57, 0x4F, 0xDE, 0xB8, 0x80, 0x76, 0x66,
  24227. 0x1A, 0xB4, 0x69, 0x51, 0x71, 0x6A, 0x50, 0x01,
  24228. 0x84, 0xA0, 0x40, 0x55, 0x72, 0x66, 0x59, 0x8C,
  24229. 0xAF, 0x76, 0x10, 0x5E, 0x1C, 0x18, 0x70, 0xB4,
  24230. 0x39, 0x69, 0xC3, 0xBC, 0xC1, 0xA0, 0x49, 0x27,
  24231. 0x63, 0x80, 0x17, 0x49, 0x8B, 0xB6, 0x2C, 0xAF,
  24232. 0xD3, 0xA6, 0xB0, 0x82, 0xB7, 0xBF, 0x7A, 0x23,
  24233. 0x45, 0x0E, 0x19, 0x17, 0x99, 0x61, 0x9B, 0x92,
  24234. 0x51, 0x12, 0xD0, 0x72, 0x02, 0x5C, 0xA8, 0x88,
  24235. 0x54, 0x8C, 0x79, 0x1A, 0xA4, 0x22, 0x51, 0x50,
  24236. 0x4D, 0x5D, 0x1C, 0x1C, 0xDD, 0xB2, 0x13, 0x30,
  24237. 0x3B, 0x04, 0x9E, 0x73, 0x46, 0xE8, 0xD8, 0x3A,
  24238. 0xD5, 0x87, 0x83, 0x6F, 0x35, 0x28, 0x4E, 0x10,
  24239. 0x97, 0x27, 0xE6, 0x6B, 0xBC, 0xC9, 0x52, 0x1F,
  24240. 0xE0, 0xB1, 0x91, 0x63, 0x00, 0x47, 0xD1, 0x58,
  24241. 0xF7, 0x56, 0x40, 0xFF, 0xEB, 0x54, 0x56, 0x07,
  24242. 0x27, 0x40, 0x02, 0x1A, 0xFD, 0x15, 0xA4, 0x54,
  24243. 0x69, 0xC5, 0x83, 0x82, 0x9D, 0xAA, 0xC8, 0xA7,
  24244. 0xDE, 0xB0, 0x5B, 0x24, 0xF0, 0x56, 0x7E, 0x43,
  24245. 0x17, 0xB3, 0xE3, 0xB3, 0x33, 0x89, 0xB5, 0xC5,
  24246. 0xF8, 0xB0, 0x4B, 0x09, 0x9F, 0xB4, 0xD1, 0x03,
  24247. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24248. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24249. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24250. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24251. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24252. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24253. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24254. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24255. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24256. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24257. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24258. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24259. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24260. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24261. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24262. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24263. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24264. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24265. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24266. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24267. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24268. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24269. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24270. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24271. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24272. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24273. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24274. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24275. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24276. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24277. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24278. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24279. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24280. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24281. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24282. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24283. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24284. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24285. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24286. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24287. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24288. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24289. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24290. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24291. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24292. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24293. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24294. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24295. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24296. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24297. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24298. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24299. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24300. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24301. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24302. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24303. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24304. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24305. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24306. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24307. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24308. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24309. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24310. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24311. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24312. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24313. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24314. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24315. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24316. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24317. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24318. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24319. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24320. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24321. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24322. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24323. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24324. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24325. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24326. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24327. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24328. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24329. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24330. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24331. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24332. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24333. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24334. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24335. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24336. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24337. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24338. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24339. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24340. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24341. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24342. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24343. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24344. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24345. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24346. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B,
  24347. 0x62, 0x01, 0x30, 0xD6, 0xC2, 0xB8, 0xC9, 0x04,
  24348. 0xA3, 0xBB, 0x93, 0x07, 0xBE, 0x51, 0x03, 0xF8,
  24349. 0xD8, 0x14, 0x50, 0x5F, 0xB6, 0xA6, 0x0A, 0xF7,
  24350. 0x93, 0x7E, 0xA6, 0xCA, 0xA1, 0x17, 0x31, 0x5E,
  24351. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24352. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24353. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24354. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24355. };
  24356. #endif
  24357. #ifndef WOLFSSL_NO_KYBER768
  24358. static const byte seed_768[KYBER_MAKEKEY_RAND_SZ] = {
  24359. /* d */
  24360. 0xE3, 0x4A, 0x70, 0x1C, 0x4C, 0x87, 0x58, 0x2F,
  24361. 0x42, 0x26, 0x4E, 0xE4, 0x22, 0xD3, 0xC6, 0x84,
  24362. 0xD9, 0x76, 0x11, 0xF2, 0x52, 0x3E, 0xFE, 0x0C,
  24363. 0x99, 0x8A, 0xF0, 0x50, 0x56, 0xD6, 0x93, 0xDC,
  24364. /* z */
  24365. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  24366. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  24367. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  24368. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  24369. };
  24370. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  24371. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24372. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24373. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24374. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24375. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24376. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24377. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24378. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24379. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24380. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24381. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24382. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24383. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24384. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24385. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24386. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24387. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24388. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24389. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24390. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24391. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24392. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24393. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24394. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24395. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24396. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24397. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24398. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24399. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24400. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24401. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24402. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24403. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24404. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24405. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24406. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24407. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24408. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24409. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24410. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24411. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24412. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24413. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24414. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24415. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24416. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24417. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24418. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24419. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  24420. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  24421. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  24422. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  24423. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  24424. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  24425. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  24426. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  24427. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  24428. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  24429. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  24430. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  24431. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  24432. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  24433. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  24434. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  24435. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  24436. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  24437. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  24438. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  24439. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  24440. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  24441. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  24442. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  24443. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  24444. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  24445. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  24446. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  24447. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  24448. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  24449. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  24450. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  24451. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  24452. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  24453. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  24454. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  24455. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  24456. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  24457. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  24458. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  24459. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  24460. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  24461. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  24462. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  24463. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  24464. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  24465. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  24466. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  24467. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  24468. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  24469. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  24470. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  24471. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  24472. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  24473. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  24474. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  24475. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  24476. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  24477. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  24478. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  24479. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  24480. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  24481. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  24482. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  24483. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  24484. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  24485. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  24486. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  24487. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  24488. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  24489. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  24490. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  24491. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  24492. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  24493. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  24494. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  24495. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  24496. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  24497. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  24498. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  24499. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  24500. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  24501. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  24502. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  24503. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  24504. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  24505. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  24506. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  24507. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  24508. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  24509. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  24510. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  24511. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  24512. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  24513. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  24514. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  24515. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  24516. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  24517. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  24518. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68
  24519. };
  24520. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  24521. 0x98, 0xA1, 0xB2, 0xDA, 0x4A, 0x65, 0xCF, 0xB5,
  24522. 0x84, 0x5E, 0xA7, 0x31, 0x1E, 0x6A, 0x06, 0xDB,
  24523. 0x73, 0x1F, 0x15, 0x90, 0xC4, 0x1E, 0xE7, 0x4B,
  24524. 0xA1, 0x07, 0x82, 0x71, 0x5B, 0x35, 0xA3, 0x10,
  24525. 0x2D, 0xF6, 0x37, 0x87, 0x2B, 0xE6, 0x5B, 0xAB,
  24526. 0x37, 0xA1, 0xDE, 0x25, 0x11, 0xD7, 0x03, 0xC7,
  24527. 0x02, 0x47, 0xB3, 0x5E, 0xF2, 0x74, 0x35, 0x48,
  24528. 0x50, 0x24, 0xD9, 0x3F, 0xD9, 0xE7, 0x7C, 0x43,
  24529. 0x80, 0x4F, 0x37, 0x17, 0x49, 0xBA, 0x00, 0xB2,
  24530. 0x0A, 0x8C, 0x5C, 0x58, 0x8B, 0xC9, 0xAB, 0xE0,
  24531. 0x68, 0xAE, 0xAA, 0xA9, 0x38, 0x51, 0x7E, 0xBF,
  24532. 0xE5, 0x3B, 0x6B, 0x66, 0x32, 0x82, 0x90, 0x3D,
  24533. 0xCD, 0x18, 0x97, 0x36, 0xD7, 0x29, 0x68, 0x16,
  24534. 0xC7, 0x33, 0xA1, 0xC7, 0x7C, 0x63, 0x75, 0xE5,
  24535. 0x39, 0x7C, 0x0F, 0x18, 0x9B, 0xBF, 0xE4, 0x76,
  24536. 0x43, 0xA6, 0x1F, 0x58, 0xF8, 0xA3, 0xC6, 0x91,
  24537. 0x1B, 0xE4, 0x61, 0x1A, 0x8C, 0x7B, 0xC0, 0x50,
  24538. 0x02, 0x11, 0x63, 0xD0, 0xA4, 0x04, 0xDC, 0x14,
  24539. 0x06, 0x57, 0x48, 0xFF, 0x29, 0xBE, 0x60, 0xD2,
  24540. 0xB9, 0xFD, 0xCC, 0x8F, 0xFD, 0x98, 0xC5, 0x87,
  24541. 0xF3, 0x8C, 0x67, 0x11, 0x57, 0x86, 0x46, 0x4B,
  24542. 0xDB, 0x34, 0x2B, 0x17, 0xE8, 0x97, 0xD6, 0x46,
  24543. 0x17, 0xCB, 0xFB, 0x11, 0x79, 0x73, 0xA5, 0x45,
  24544. 0x89, 0x77, 0xA7, 0xD7, 0x61, 0x7A, 0x1B, 0x4D,
  24545. 0x83, 0xBA, 0x03, 0xC6, 0x11, 0x13, 0x8A, 0x46,
  24546. 0x73, 0xB1, 0xEB, 0x34, 0xB0, 0x78, 0x03, 0x3F,
  24547. 0x97, 0xCF, 0xFE, 0x80, 0xC1, 0x46, 0xA2, 0x69,
  24548. 0x43, 0xF8, 0x42, 0xB9, 0x76, 0x32, 0x7B, 0xF1,
  24549. 0xCB, 0xC6, 0x01, 0x19, 0x52, 0x5B, 0xB9, 0xA3,
  24550. 0xC0, 0x34, 0x93, 0x34, 0x90, 0x00, 0xDD, 0x8F,
  24551. 0x51, 0xBA, 0x21, 0xA2, 0xE9, 0x23, 0x61, 0x76,
  24552. 0x23, 0x24, 0x60, 0x0E, 0x0C, 0x13, 0xAA, 0xA6,
  24553. 0xCB, 0x69, 0xBF, 0xB2, 0x42, 0x76, 0x48, 0x3F,
  24554. 0x6B, 0x02, 0x42, 0x12, 0x59, 0xB7, 0x58, 0x52,
  24555. 0x63, 0xC1, 0xA0, 0x28, 0xD6, 0x82, 0xC5, 0x08,
  24556. 0xBB, 0xC2, 0x80, 0x1A, 0x56, 0xE9, 0x8B, 0x8F,
  24557. 0x62, 0x0B, 0x04, 0x83, 0xD7, 0x9B, 0x5A, 0xD8,
  24558. 0x58, 0x5A, 0xC0, 0xA4, 0x75, 0xBA, 0xC7, 0x78,
  24559. 0x65, 0x19, 0x41, 0x96, 0x33, 0x87, 0x91, 0xB7,
  24560. 0x98, 0x5A, 0x05, 0xD1, 0x09, 0x39, 0x5C, 0xCA,
  24561. 0x89, 0x32, 0x72, 0x2A, 0x91, 0x95, 0x0D, 0x37,
  24562. 0xE1, 0x2B, 0x89, 0x14, 0x20, 0xA5, 0x2B, 0x62,
  24563. 0xCB, 0xFA, 0x81, 0x5D, 0xF6, 0x17, 0x4C, 0xE0,
  24564. 0x0E, 0x68, 0xBC, 0xA7, 0x5D, 0x48, 0x38, 0xCA,
  24565. 0x28, 0x0F, 0x71, 0x3C, 0x7E, 0x69, 0x24, 0xAF,
  24566. 0xD9, 0x5B, 0xAA, 0x0D, 0x01, 0xAD, 0xA6, 0x37,
  24567. 0xB1, 0x58, 0x34, 0x70, 0x34, 0xC0, 0xAB, 0x1A,
  24568. 0x71, 0x83, 0x33, 0x1A, 0x82, 0x0A, 0xCB, 0xCB,
  24569. 0x83, 0x19, 0x3A, 0x1A, 0x94, 0xC8, 0xF7, 0xE3,
  24570. 0x84, 0xAE, 0xD0, 0xC3, 0x5E, 0xD3, 0xCB, 0x33,
  24571. 0x97, 0xBB, 0x63, 0x80, 0x86, 0xE7, 0xA3, 0x5A,
  24572. 0x64, 0x08, 0xA3, 0xA4, 0xB9, 0x0C, 0xE9, 0x53,
  24573. 0x70, 0x7C, 0x19, 0xBC, 0x46, 0xC3, 0xB2, 0xDA,
  24574. 0x3B, 0x2E, 0xE3, 0x23, 0x19, 0xC5, 0x6B, 0x92,
  24575. 0x80, 0x32, 0xB5, 0xED, 0x12, 0x56, 0xD0, 0x75,
  24576. 0x3D, 0x34, 0x14, 0x23, 0xE9, 0xDB, 0x13, 0x9D,
  24577. 0xE7, 0x71, 0x4F, 0xF0, 0x75, 0xCA, 0xF5, 0x8F,
  24578. 0xD9, 0xF5, 0x7D, 0x1A, 0x54, 0x01, 0x9B, 0x59,
  24579. 0x26, 0x40, 0x68, 0x30, 0xDA, 0xE2, 0x9A, 0x87,
  24580. 0x53, 0x02, 0xA8, 0x12, 0x56, 0xF4, 0xD6, 0xCF,
  24581. 0x5E, 0x74, 0x03, 0x4E, 0xA6, 0x14, 0xBF, 0x70,
  24582. 0xC2, 0x76, 0x4B, 0x20, 0xC9, 0x58, 0x9C, 0xDB,
  24583. 0x5C, 0x25, 0x76, 0x1A, 0x04, 0xE5, 0x82, 0x92,
  24584. 0x90, 0x7C, 0x57, 0x8A, 0x94, 0xA3, 0x58, 0x36,
  24585. 0xBE, 0xE3, 0x11, 0x2D, 0xC2, 0xC3, 0xAE, 0x21,
  24586. 0x92, 0xC9, 0xDE, 0xAA, 0x30, 0x4B, 0x29, 0xC7,
  24587. 0xFE, 0xA1, 0xBD, 0xF4, 0x7B, 0x3B, 0x6B, 0xCB,
  24588. 0xA2, 0xC0, 0xE5, 0x5C, 0x9C, 0xDB, 0x6D, 0xE7,
  24589. 0x14, 0x9E, 0x9C, 0xB1, 0x79, 0x17, 0x71, 0x8F,
  24590. 0x12, 0xC8, 0x03, 0x2D, 0xE1, 0xAD, 0xE0, 0x64,
  24591. 0x8D, 0x40, 0x55, 0x19, 0xC7, 0x07, 0x19, 0xBE,
  24592. 0xCC, 0x70, 0x18, 0x45, 0xCF, 0x9F, 0x4B, 0x91,
  24593. 0x2F, 0xE7, 0x19, 0x83, 0xCA, 0x34, 0xF9, 0x01,
  24594. 0x8C, 0x7C, 0xA7, 0xBB, 0x2F, 0x6C, 0x5D, 0x7F,
  24595. 0x8C, 0x5B, 0x29, 0x73, 0x59, 0xEC, 0x75, 0x20,
  24596. 0x9C, 0x25, 0x43, 0xFF, 0x11, 0xC4, 0x24, 0x49,
  24597. 0x77, 0xC5, 0x96, 0x95, 0x24, 0xEC, 0x45, 0x4D,
  24598. 0x44, 0xC3, 0x23, 0xFC, 0xCA, 0x94, 0xAC, 0xAC,
  24599. 0x27, 0x3A, 0x0E, 0xC4, 0x9B, 0x4A, 0x8A, 0x58,
  24600. 0x5B, 0xCE, 0x7A, 0x5B, 0x30, 0x5C, 0x04, 0xC3,
  24601. 0x50, 0x64, 0x22, 0x58, 0x03, 0x57, 0x01, 0x6A,
  24602. 0x85, 0x0C, 0x3F, 0x7E, 0xE1, 0x72, 0x05, 0xA7,
  24603. 0x7B, 0x29, 0x1C, 0x77, 0x31, 0xC9, 0x83, 0x6C,
  24604. 0x02, 0xAE, 0xE5, 0x40, 0x6F, 0x63, 0xC6, 0xA0,
  24605. 0x7A, 0x21, 0x43, 0x82, 0xAA, 0x15, 0x33, 0x6C,
  24606. 0x05, 0xD1, 0x04, 0x55, 0x88, 0x10, 0x76, 0x45,
  24607. 0xEA, 0x7D, 0xE6, 0x87, 0x0F, 0xC0, 0xE5, 0x5E,
  24608. 0x15, 0x40, 0x97, 0x43, 0x01, 0xC4, 0x2E, 0xC1,
  24609. 0x41, 0x05, 0x51, 0x86, 0x80, 0xF6, 0x88, 0xAB,
  24610. 0xE4, 0xCE, 0x45, 0x37, 0x38, 0xFE, 0x47, 0x1B,
  24611. 0x87, 0xFC, 0x31, 0xF5, 0xC6, 0x8A, 0x39, 0xE6,
  24612. 0x8A, 0xF5, 0x1B, 0x02, 0x40, 0xB9, 0x0E, 0x03,
  24613. 0x64, 0xB0, 0x4B, 0xAC, 0x43, 0xD6, 0xFB, 0x68,
  24614. 0xAB, 0x65, 0xAE, 0x02, 0x8B, 0x62, 0xBD, 0x68,
  24615. 0x3B, 0x7D, 0x28, 0xAD, 0x38, 0x80, 0x6B, 0xEE,
  24616. 0x72, 0x5B, 0x5B, 0x24, 0x16, 0xA8, 0xD7, 0x9C,
  24617. 0x16, 0xEC, 0x2A, 0x99, 0xEA, 0x4A, 0x8D, 0x92,
  24618. 0xA2, 0xF5, 0x05, 0x2E, 0x67, 0xF9, 0x73, 0x52,
  24619. 0x28, 0x97, 0x61, 0xC5, 0xC3, 0x9F, 0xC5, 0xC7,
  24620. 0x42, 0xE9, 0xC0, 0xA7, 0x40, 0xCA, 0x59, 0xFC,
  24621. 0x01, 0x82, 0xF7, 0x09, 0xD0, 0x1B, 0x51, 0x87,
  24622. 0xF0, 0x00, 0x63, 0xDA, 0xAB, 0x39, 0x75, 0x96,
  24623. 0xEE, 0xA4, 0xA3, 0x1B, 0xDB, 0xCB, 0xD4, 0xC1,
  24624. 0xBB, 0x0C, 0x55, 0xBE, 0x7C, 0x68, 0x50, 0xFD,
  24625. 0xA9, 0x32, 0x6B, 0x35, 0x3E, 0x28, 0x8C, 0x50,
  24626. 0x13, 0x22, 0x6C, 0x3C, 0x39, 0x23, 0xA7, 0x91,
  24627. 0x60, 0x9E, 0x80, 0x02, 0xE7, 0x3A, 0x5F, 0x7B,
  24628. 0x6B, 0xB4, 0xA8, 0x77, 0xB1, 0xFD, 0xF5, 0x3B,
  24629. 0xB2, 0xBA, 0xB3, 0xDD, 0x42, 0x4D, 0x31, 0xBB,
  24630. 0xB4, 0x48, 0xE6, 0x09, 0xA6, 0x6B, 0x0E, 0x34,
  24631. 0x3C, 0x28, 0x6E, 0x87, 0x60, 0x31, 0x2B, 0x6D,
  24632. 0x37, 0xAA, 0x52, 0x01, 0xD2, 0x1F, 0x53, 0x50,
  24633. 0x3D, 0x88, 0x38, 0x9A, 0xDC, 0xA2, 0x1C, 0x70,
  24634. 0xFB, 0x6C, 0x0F, 0xC9, 0xC6, 0x9D, 0x66, 0x16,
  24635. 0xC9, 0xEA, 0x37, 0x80, 0xE3, 0x55, 0x65, 0xC0,
  24636. 0xC9, 0x7C, 0x15, 0x17, 0x9C, 0x95, 0x34, 0x3E,
  24637. 0xCC, 0x5E, 0x1C, 0x2A, 0x24, 0xDE, 0x46, 0x99,
  24638. 0xF6, 0x87, 0x5E, 0xA2, 0xFA, 0x2D, 0xD3, 0xE3,
  24639. 0x57, 0xBC, 0x43, 0x91, 0x47, 0x95, 0x20, 0x7E,
  24640. 0x02, 0x6B, 0x85, 0x0A, 0x22, 0x37, 0x95, 0x0C,
  24641. 0x10, 0x8A, 0x51, 0x2F, 0xC8, 0x8C, 0x22, 0x48,
  24642. 0x81, 0x12, 0x60, 0x70, 0x88, 0x18, 0x5F, 0xB0,
  24643. 0xE0, 0x9C, 0x2C, 0x41, 0x97, 0xA8, 0x36, 0x87,
  24644. 0x26, 0x6B, 0xAB, 0x2E, 0x58, 0x3E, 0x21, 0xC4,
  24645. 0x0F, 0x4C, 0xC0, 0x08, 0xFE, 0x65, 0x28, 0x04,
  24646. 0xD8, 0x22, 0x3F, 0x15, 0x20, 0xA9, 0x0B, 0x0D,
  24647. 0x53, 0x85, 0xC7, 0x55, 0x3C, 0xC7, 0x67, 0xC5,
  24648. 0x8D, 0x12, 0x0C, 0xCD, 0x3E, 0xF5, 0xB5, 0xD1,
  24649. 0xA6, 0xCD, 0x7B, 0xC0, 0x0D, 0xFF, 0x13, 0x21,
  24650. 0xB2, 0xF2, 0xC4, 0x32, 0xB6, 0x4E, 0xFB, 0x8A,
  24651. 0x3F, 0x5D, 0x00, 0x64, 0xB3, 0xF3, 0x42, 0x93,
  24652. 0x02, 0x6C, 0x85, 0x1C, 0x2D, 0xED, 0x68, 0xB9,
  24653. 0xDF, 0xF4, 0xA2, 0x8F, 0x6A, 0x8D, 0x22, 0x55,
  24654. 0x35, 0xE0, 0x47, 0x70, 0x84, 0x43, 0x0C, 0xFF,
  24655. 0xDA, 0x0A, 0xC0, 0x55, 0x2F, 0x9A, 0x21, 0x27,
  24656. 0x85, 0xB7, 0x49, 0x91, 0x3A, 0x06, 0xFA, 0x22,
  24657. 0x74, 0xC0, 0xD1, 0x5B, 0xAD, 0x32, 0x54, 0x58,
  24658. 0xD3, 0x23, 0xEF, 0x6B, 0xAE, 0x13, 0xC0, 0x01,
  24659. 0x0D, 0x52, 0x5C, 0x1D, 0x52, 0x69, 0x97, 0x3A,
  24660. 0xC2, 0x9B, 0xDA, 0x7C, 0x98, 0x37, 0x46, 0x91,
  24661. 0x8B, 0xA0, 0xE0, 0x02, 0x58, 0x8E, 0x30, 0x37,
  24662. 0x5D, 0x78, 0x32, 0x9E, 0x6B, 0x8B, 0xA8, 0xC4,
  24663. 0x46, 0x2A, 0x69, 0x2F, 0xB6, 0x08, 0x38, 0x42,
  24664. 0xB8, 0xC8, 0xC9, 0x2C, 0x60, 0xF2, 0x52, 0x72,
  24665. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24666. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24667. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24668. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24669. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24670. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24671. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24672. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24673. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24674. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24675. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24676. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24677. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24678. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24679. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24680. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24681. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24682. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24683. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24684. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24685. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24686. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24687. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24688. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24689. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24690. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24691. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24692. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24693. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24694. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24695. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24696. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24697. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24698. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24699. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24700. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24701. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24702. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24703. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24704. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24705. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24706. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24707. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24708. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24709. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24710. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24711. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24712. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24713. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  24714. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  24715. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  24716. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  24717. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  24718. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  24719. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  24720. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  24721. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  24722. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  24723. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  24724. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  24725. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  24726. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  24727. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  24728. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  24729. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  24730. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  24731. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  24732. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  24733. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  24734. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  24735. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  24736. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  24737. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  24738. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  24739. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  24740. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  24741. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  24742. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  24743. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  24744. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  24745. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  24746. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  24747. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  24748. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  24749. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  24750. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  24751. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  24752. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  24753. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  24754. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  24755. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  24756. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  24757. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  24758. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  24759. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  24760. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  24761. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  24762. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  24763. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  24764. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  24765. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  24766. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  24767. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  24768. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  24769. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  24770. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  24771. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  24772. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  24773. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  24774. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  24775. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  24776. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  24777. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  24778. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  24779. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  24780. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  24781. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  24782. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  24783. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  24784. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  24785. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  24786. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  24787. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  24788. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  24789. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  24790. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  24791. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  24792. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  24793. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  24794. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  24795. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  24796. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  24797. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  24798. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  24799. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  24800. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  24801. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  24802. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  24803. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  24804. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  24805. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  24806. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  24807. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  24808. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  24809. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  24810. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  24811. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  24812. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68,
  24813. 0xE2, 0x90, 0x20, 0x83, 0x9D, 0x05, 0x2F, 0xA3,
  24814. 0x72, 0x58, 0x56, 0x27, 0xF8, 0xB5, 0x9E, 0xE3,
  24815. 0x12, 0xAE, 0x41, 0x4C, 0x97, 0x9D, 0x82, 0x5F,
  24816. 0x06, 0xA6, 0x92, 0x9A, 0x79, 0x62, 0x57, 0x18,
  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. #endif
  24823. #ifndef WOLFSSL_NO_KYBER1024
  24824. static const byte seed_1024[KYBER_MAKEKEY_RAND_SZ] = {
  24825. /* d */
  24826. 0x49, 0xAC, 0x8B, 0x99, 0xBB, 0x1E, 0x6A, 0x8E,
  24827. 0xA8, 0x18, 0x26, 0x1F, 0x8B, 0xE6, 0x8B, 0xDE,
  24828. 0xAA, 0x52, 0x89, 0x7E, 0x7E, 0xC6, 0xC4, 0x0B,
  24829. 0x53, 0x0B, 0xC7, 0x60, 0xAB, 0x77, 0xDC, 0xE3,
  24830. /* z */
  24831. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  24832. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  24833. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  24834. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  24835. };
  24836. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  24837. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  24838. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  24839. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  24840. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  24841. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  24842. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  24843. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  24844. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  24845. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  24846. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  24847. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  24848. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  24849. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  24850. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  24851. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  24852. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  24853. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  24854. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  24855. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  24856. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  24857. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  24858. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  24859. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  24860. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  24861. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  24862. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  24863. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  24864. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  24865. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  24866. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  24867. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  24868. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  24869. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  24870. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  24871. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  24872. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  24873. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  24874. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  24875. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  24876. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  24877. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  24878. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  24879. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  24880. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  24881. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  24882. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  24883. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  24884. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  24885. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  24886. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  24887. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  24888. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  24889. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  24890. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  24891. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  24892. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  24893. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  24894. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  24895. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  24896. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  24897. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  24898. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  24899. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  24900. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  24901. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  24902. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  24903. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  24904. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  24905. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  24906. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  24907. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  24908. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  24909. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  24910. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  24911. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  24912. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  24913. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  24914. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  24915. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  24916. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  24917. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  24918. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  24919. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  24920. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  24921. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  24922. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  24923. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  24924. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  24925. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  24926. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  24927. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  24928. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  24929. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  24930. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  24931. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  24932. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  24933. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  24934. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  24935. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  24936. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  24937. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  24938. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  24939. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  24940. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  24941. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  24942. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  24943. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  24944. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  24945. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  24946. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  24947. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  24948. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  24949. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  24950. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  24951. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  24952. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  24953. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  24954. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  24955. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  24956. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  24957. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  24958. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  24959. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  24960. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  24961. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  24962. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  24963. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  24964. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  24965. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  24966. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  24967. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  24968. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  24969. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  24970. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  24971. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  24972. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  24973. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  24974. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  24975. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  24976. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  24977. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  24978. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  24979. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  24980. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  24981. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  24982. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  24983. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  24984. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  24985. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  24986. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  24987. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  24988. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  24989. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  24990. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  24991. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  24992. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  24993. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  24994. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  24995. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  24996. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  24997. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  24998. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  24999. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25000. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25001. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25002. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25003. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25004. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25005. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25006. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25007. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25008. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25009. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25010. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25011. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25012. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25013. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25014. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25015. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25016. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25017. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25018. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25019. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25020. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25021. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25022. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25023. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25024. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25025. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25026. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25027. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25028. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25029. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25030. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25031. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25032. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21
  25033. };
  25034. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  25035. 0x8C, 0x8B, 0x37, 0x22, 0xA8, 0x2E, 0x55, 0x05,
  25036. 0x65, 0x52, 0x16, 0x11, 0xEB, 0xBC, 0x63, 0x07,
  25037. 0x99, 0x44, 0xC9, 0xB1, 0xAB, 0xB3, 0xB0, 0x02,
  25038. 0x0F, 0xF1, 0x2F, 0x63, 0x18, 0x91, 0xA9, 0xC4,
  25039. 0x68, 0xD3, 0xA6, 0x7B, 0xF6, 0x27, 0x12, 0x80,
  25040. 0xDA, 0x58, 0xD0, 0x3C, 0xB0, 0x42, 0xB3, 0xA4,
  25041. 0x61, 0x44, 0x16, 0x37, 0xF9, 0x29, 0xC2, 0x73,
  25042. 0x46, 0x9A, 0xD1, 0x53, 0x11, 0xE9, 0x10, 0xDE,
  25043. 0x18, 0xCB, 0x95, 0x37, 0xBA, 0x1B, 0xE4, 0x2E,
  25044. 0x98, 0xBB, 0x59, 0xE4, 0x98, 0xA1, 0x3F, 0xD4,
  25045. 0x40, 0xD0, 0xE6, 0x9E, 0xE8, 0x32, 0xB4, 0x5C,
  25046. 0xD9, 0x5C, 0x38, 0x21, 0x77, 0xD6, 0x70, 0x96,
  25047. 0xA1, 0x8C, 0x07, 0xF1, 0x78, 0x16, 0x63, 0x65,
  25048. 0x1B, 0xDC, 0xAC, 0x90, 0xDE, 0xDA, 0x3D, 0xDD,
  25049. 0x14, 0x34, 0x85, 0x86, 0x41, 0x81, 0xC9, 0x1F,
  25050. 0xA2, 0x08, 0x0F, 0x6D, 0xAB, 0x3F, 0x86, 0x20,
  25051. 0x4C, 0xEB, 0x64, 0xA7, 0xB4, 0x44, 0x68, 0x95,
  25052. 0xC0, 0x39, 0x87, 0xA0, 0x31, 0xCB, 0x4B, 0x6D,
  25053. 0x9E, 0x04, 0x62, 0xFD, 0xA8, 0x29, 0x17, 0x2B,
  25054. 0x6C, 0x01, 0x2C, 0x63, 0x8B, 0x29, 0xB5, 0xCD,
  25055. 0x75, 0xA2, 0xC9, 0x30, 0xA5, 0x59, 0x6A, 0x31,
  25056. 0x81, 0xC3, 0x3A, 0x22, 0xD5, 0x74, 0xD3, 0x02,
  25057. 0x61, 0x19, 0x6B, 0xC3, 0x50, 0x73, 0x8D, 0x4F,
  25058. 0xD9, 0x18, 0x3A, 0x76, 0x33, 0x36, 0x24, 0x3A,
  25059. 0xCE, 0xD9, 0x9B, 0x32, 0x21, 0xC7, 0x1D, 0x88,
  25060. 0x66, 0x89, 0x5C, 0x4E, 0x52, 0xC1, 0x19, 0xBF,
  25061. 0x32, 0x80, 0xDA, 0xF8, 0x0A, 0x95, 0xE1, 0x52,
  25062. 0x09, 0xA7, 0x95, 0xC4, 0x43, 0x5F, 0xBB, 0x35,
  25063. 0x70, 0xFD, 0xB8, 0xAA, 0x9B, 0xF9, 0xAE, 0xFD,
  25064. 0x43, 0xB0, 0x94, 0xB7, 0x81, 0xD5, 0xA8, 0x11,
  25065. 0x36, 0xDA, 0xB8, 0x8B, 0x87, 0x99, 0x69, 0x65,
  25066. 0x56, 0xFE, 0xC6, 0xAE, 0x14, 0xB0, 0xBB, 0x8B,
  25067. 0xE4, 0x69, 0x5E, 0x9A, 0x12, 0x4C, 0x2A, 0xB8,
  25068. 0xFF, 0x4A, 0xB1, 0x22, 0x9B, 0x8A, 0xAA, 0x8C,
  25069. 0x6F, 0x41, 0xA6, 0x0C, 0x34, 0xC7, 0xB5, 0x61,
  25070. 0x82, 0xC5, 0x5C, 0x2C, 0x68, 0x5E, 0x73, 0x7C,
  25071. 0x6C, 0xA0, 0x0A, 0x23, 0xFB, 0x8A, 0x68, 0xC1,
  25072. 0xCD, 0x61, 0xF3, 0x0D, 0x39, 0x93, 0xA1, 0x65,
  25073. 0x3C, 0x16, 0x75, 0xAC, 0x5F, 0x09, 0x01, 0xA7,
  25074. 0x16, 0x0A, 0x73, 0x96, 0x64, 0x08, 0xB8, 0x87,
  25075. 0x6B, 0x71, 0x53, 0x96, 0xCF, 0xA4, 0x90, 0x3F,
  25076. 0xC6, 0x9D, 0x60, 0x49, 0x1F, 0x81, 0x46, 0x80,
  25077. 0x8C, 0x97, 0xCD, 0x5C, 0x53, 0x3E, 0x71, 0x01,
  25078. 0x79, 0x09, 0xE9, 0x7B, 0x83, 0x5B, 0x86, 0xFF,
  25079. 0x84, 0x7B, 0x42, 0xA6, 0x96, 0x37, 0x54, 0x35,
  25080. 0xE0, 0x06, 0x06, 0x1C, 0xF7, 0xA4, 0x79, 0x46,
  25081. 0x32, 0x72, 0x11, 0x4A, 0x89, 0xEB, 0x3E, 0xAF,
  25082. 0x22, 0x46, 0xF0, 0xF8, 0xC1, 0x04, 0xA1, 0x49,
  25083. 0x86, 0x82, 0x8E, 0x0A, 0xD2, 0x04, 0x20, 0xC9,
  25084. 0xB3, 0x7E, 0xA2, 0x3F, 0x5C, 0x51, 0x49, 0x49,
  25085. 0xE7, 0x7A, 0xD9, 0xE9, 0xAD, 0x12, 0x29, 0x0D,
  25086. 0xD1, 0x21, 0x5E, 0x11, 0xDA, 0x27, 0x44, 0x57,
  25087. 0xAC, 0x86, 0xB1, 0xCE, 0x68, 0x64, 0xB1, 0x22,
  25088. 0x67, 0x7F, 0x37, 0x18, 0xAA, 0x31, 0xB0, 0x25,
  25089. 0x80, 0xE6, 0x43, 0x17, 0x17, 0x8D, 0x38, 0xF2,
  25090. 0x5F, 0x60, 0x9B, 0xC6, 0xC5, 0x5B, 0xC3, 0x74,
  25091. 0xA1, 0xBF, 0x78, 0xEA, 0x8E, 0xCC, 0x21, 0x9B,
  25092. 0x30, 0xB7, 0x4C, 0xBB, 0x32, 0x72, 0xA5, 0x99,
  25093. 0x23, 0x8C, 0x93, 0x98, 0x51, 0x70, 0x04, 0x8F,
  25094. 0x17, 0x67, 0x75, 0xFB, 0x19, 0x96, 0x2A, 0xC3,
  25095. 0xB1, 0x35, 0xAA, 0x59, 0xDB, 0x10, 0x4F, 0x71,
  25096. 0x14, 0xDB, 0xC2, 0xC2, 0xD4, 0x29, 0x49, 0xAD,
  25097. 0xEC, 0xA6, 0xA8, 0x5B, 0x32, 0x3E, 0xE2, 0xB2,
  25098. 0xB2, 0x3A, 0x77, 0xD9, 0xDB, 0x23, 0x59, 0x79,
  25099. 0xA8, 0xE2, 0xD6, 0x7C, 0xF7, 0xD2, 0x13, 0x6B,
  25100. 0xBB, 0xA7, 0x1F, 0x26, 0x95, 0x74, 0xB3, 0x88,
  25101. 0x88, 0xE1, 0x54, 0x13, 0x40, 0xC1, 0x92, 0x84,
  25102. 0x07, 0x4F, 0x9B, 0x7C, 0x8C, 0xF3, 0x7E, 0xB0,
  25103. 0x13, 0x84, 0xE6, 0xE3, 0x82, 0x2E, 0xC4, 0x88,
  25104. 0x2D, 0xFB, 0xBE, 0xC4, 0xE6, 0x09, 0x8E, 0xF2,
  25105. 0xB2, 0xFC, 0x17, 0x7A, 0x1F, 0x0B, 0xCB, 0x65,
  25106. 0xA5, 0x7F, 0xDA, 0xA8, 0x93, 0x15, 0x46, 0x1B,
  25107. 0xEB, 0x78, 0x85, 0xFB, 0x68, 0xB3, 0xCD, 0x09,
  25108. 0x6E, 0xDA, 0x59, 0x6A, 0xC0, 0xE6, 0x1D, 0xD7,
  25109. 0xA9, 0xC5, 0x07, 0xBC, 0x63, 0x45, 0xE0, 0x82,
  25110. 0x7D, 0xFC, 0xC8, 0xA3, 0xAC, 0x2D, 0xCE, 0x51,
  25111. 0xAD, 0x73, 0x1A, 0xA0, 0xEB, 0x93, 0x2A, 0x6D,
  25112. 0x09, 0x83, 0x99, 0x23, 0x47, 0xCB, 0xEB, 0x3C,
  25113. 0xD0, 0xD9, 0xC9, 0x71, 0x97, 0x97, 0xCC, 0x21,
  25114. 0xCF, 0x00, 0x62, 0xB0, 0xAD, 0x94, 0xCA, 0xD7,
  25115. 0x34, 0xC6, 0x3E, 0x6B, 0x5D, 0x85, 0x9C, 0xBE,
  25116. 0x19, 0xF0, 0x36, 0x82, 0x45, 0x35, 0x1B, 0xF4,
  25117. 0x64, 0xD7, 0x50, 0x55, 0x69, 0x79, 0x0D, 0x2B,
  25118. 0xB7, 0x24, 0xD8, 0x65, 0x9A, 0x9F, 0xEB, 0x1C,
  25119. 0x7C, 0x47, 0x3D, 0xC4, 0xD0, 0x61, 0xE2, 0x98,
  25120. 0x63, 0xA2, 0x71, 0x4B, 0xAC, 0x42, 0xAD, 0xCD,
  25121. 0x1A, 0x83, 0x72, 0x77, 0x65, 0x56, 0xF7, 0x92,
  25122. 0x8A, 0x7A, 0x44, 0xE9, 0x4B, 0x6A, 0x25, 0x32,
  25123. 0x2D, 0x03, 0xC0, 0xA1, 0x62, 0x2A, 0x7F, 0xD2,
  25124. 0x61, 0x52, 0x2B, 0x73, 0x58, 0xF0, 0x85, 0xBD,
  25125. 0xFB, 0x60, 0x75, 0x87, 0x62, 0xCB, 0x90, 0x10,
  25126. 0x31, 0x90, 0x1B, 0x5E, 0xEC, 0xF4, 0x92, 0x0C,
  25127. 0x81, 0x02, 0x0A, 0x9B, 0x17, 0x81, 0xBC, 0xB9,
  25128. 0xDD, 0x19, 0xA9, 0xDF, 0xB6, 0x64, 0x58, 0xE7,
  25129. 0x75, 0x7C, 0x52, 0xCE, 0xC7, 0x5B, 0x4B, 0xA7,
  25130. 0x40, 0xA2, 0x40, 0x99, 0xCB, 0x56, 0xBB, 0x60,
  25131. 0xA7, 0x6B, 0x69, 0x01, 0xAA, 0x3E, 0x01, 0x69,
  25132. 0xC9, 0xE8, 0x34, 0x96, 0xD7, 0x3C, 0x4C, 0x99,
  25133. 0x43, 0x5A, 0x28, 0xD6, 0x13, 0xE9, 0x7A, 0x11,
  25134. 0x77, 0xF5, 0x8B, 0x6C, 0xC5, 0x95, 0xD3, 0xB2,
  25135. 0x33, 0x1E, 0x9C, 0xA7, 0xB5, 0x7B, 0x74, 0xDC,
  25136. 0x2C, 0x52, 0x77, 0xD2, 0x6F, 0x2F, 0xE1, 0x92,
  25137. 0x40, 0xA5, 0x5C, 0x35, 0xD6, 0xCF, 0xCA, 0x26,
  25138. 0xC7, 0x3E, 0x9A, 0x2D, 0x7C, 0x98, 0x0D, 0x97,
  25139. 0x96, 0x0A, 0xE1, 0xA0, 0x46, 0x98, 0xC1, 0x6B,
  25140. 0x39, 0x8A, 0x5F, 0x20, 0xC3, 0x5A, 0x09, 0x14,
  25141. 0x14, 0x5C, 0xE1, 0x67, 0x4B, 0x71, 0xAB, 0xC6,
  25142. 0x06, 0x6A, 0x90, 0x9A, 0x3E, 0x4B, 0x91, 0x1E,
  25143. 0x69, 0xD5, 0xA8, 0x49, 0x43, 0x03, 0x61, 0xF7,
  25144. 0x31, 0xB0, 0x72, 0x46, 0xA6, 0x32, 0x9B, 0x52,
  25145. 0x36, 0x19, 0x04, 0x22, 0x50, 0x82, 0xD0, 0xAA,
  25146. 0xC5, 0xB2, 0x1D, 0x6B, 0x34, 0x86, 0x24, 0x81,
  25147. 0xA8, 0x90, 0xC3, 0xC3, 0x60, 0x76, 0x6F, 0x04,
  25148. 0x26, 0x36, 0x03, 0xA6, 0xB7, 0x3E, 0x80, 0x2B,
  25149. 0x1F, 0x70, 0xB2, 0xEB, 0x00, 0x04, 0x68, 0x36,
  25150. 0xB8, 0xF4, 0x93, 0xBF, 0x10, 0xB9, 0x0B, 0x87,
  25151. 0x37, 0xC6, 0xC5, 0x48, 0x44, 0x9B, 0x29, 0x4C,
  25152. 0x47, 0x25, 0x3B, 0xE2, 0x6C, 0xA7, 0x23, 0x36,
  25153. 0xA6, 0x32, 0x06, 0x3A, 0xD3, 0xD0, 0xB4, 0x8C,
  25154. 0x8B, 0x0F, 0x4A, 0x34, 0x44, 0x7E, 0xF1, 0x3B,
  25155. 0x76, 0x40, 0x20, 0xDE, 0x73, 0x9E, 0xB7, 0x9A,
  25156. 0xBA, 0x20, 0xE2, 0xBE, 0x19, 0x51, 0x82, 0x5F,
  25157. 0x29, 0x3B, 0xED, 0xD1, 0x08, 0x9F, 0xCB, 0x0A,
  25158. 0x91, 0xF5, 0x60, 0xC8, 0xE1, 0x7C, 0xDF, 0x52,
  25159. 0x54, 0x1D, 0xC2, 0xB8, 0x1F, 0x97, 0x2A, 0x73,
  25160. 0x75, 0xB2, 0x01, 0xF1, 0x0C, 0x08, 0xD9, 0xB5,
  25161. 0xBC, 0x8B, 0x95, 0x10, 0x00, 0x54, 0xA3, 0xD0,
  25162. 0xAA, 0xFF, 0x89, 0xBD, 0x08, 0xD6, 0xA0, 0xE7,
  25163. 0xF2, 0x11, 0x5A, 0x43, 0x52, 0x31, 0x29, 0x04,
  25164. 0x60, 0xC9, 0xAD, 0x43, 0x5A, 0x3B, 0x3C, 0xF3,
  25165. 0x5E, 0x52, 0x09, 0x1E, 0xDD, 0x18, 0x90, 0x04,
  25166. 0x7B, 0xCC, 0x0A, 0xAB, 0xB1, 0xAC, 0xEB, 0xC7,
  25167. 0x5F, 0x4A, 0x32, 0xBC, 0x14, 0x51, 0xAC, 0xC4,
  25168. 0x96, 0x99, 0x40, 0x78, 0x8E, 0x89, 0x41, 0x21,
  25169. 0x88, 0x94, 0x6C, 0x91, 0x43, 0xC5, 0x04, 0x6B,
  25170. 0xD1, 0xB4, 0x58, 0xDF, 0x61, 0x7C, 0x5D, 0xF5,
  25171. 0x33, 0xB0, 0x52, 0xCD, 0x60, 0x38, 0xB7, 0x75,
  25172. 0x40, 0x34, 0xA2, 0x3C, 0x2F, 0x77, 0x20, 0x13,
  25173. 0x4C, 0x7B, 0x4E, 0xAC, 0xE0, 0x1F, 0xAC, 0x0A,
  25174. 0x28, 0x53, 0xA9, 0x28, 0x58, 0x47, 0xAB, 0xBD,
  25175. 0x06, 0xA3, 0x34, 0x3A, 0x77, 0x8A, 0xC6, 0x06,
  25176. 0x2E, 0x45, 0x8B, 0xC5, 0xE6, 0x1E, 0xCE, 0x1C,
  25177. 0x0D, 0xE0, 0x20, 0x6E, 0x6F, 0xE8, 0xA8, 0x40,
  25178. 0x34, 0xA7, 0xC5, 0xF1, 0xB0, 0x05, 0xFB, 0x0A,
  25179. 0x58, 0x40, 0x51, 0xD3, 0x22, 0x9B, 0x86, 0xC9,
  25180. 0x09, 0xAC, 0x56, 0x47, 0xB3, 0xD7, 0x55, 0x69,
  25181. 0xE0, 0x5A, 0x88, 0x27, 0x9D, 0x80, 0xE5, 0xC3,
  25182. 0x0F, 0x57, 0x4D, 0xC3, 0x27, 0x51, 0x2C, 0x6B,
  25183. 0xBE, 0x81, 0x01, 0x23, 0x9E, 0xC6, 0x28, 0x61,
  25184. 0xF4, 0xBE, 0x67, 0xB0, 0x5B, 0x9C, 0xDA, 0x9C,
  25185. 0x54, 0x5C, 0x13, 0xE7, 0xEB, 0x53, 0xCF, 0xF2,
  25186. 0x60, 0xAD, 0x98, 0x70, 0x19, 0x9C, 0x21, 0xF8,
  25187. 0xC6, 0x3D, 0x64, 0xF0, 0x45, 0x8A, 0x71, 0x41,
  25188. 0x28, 0x50, 0x23, 0xFE, 0xB8, 0x29, 0x29, 0x08,
  25189. 0x72, 0x38, 0x96, 0x44, 0xB0, 0xC3, 0xB7, 0x3A,
  25190. 0xC2, 0xC8, 0xE1, 0x21, 0xA2, 0x9B, 0xB1, 0xC4,
  25191. 0x3C, 0x19, 0xA2, 0x33, 0xD5, 0x6B, 0xED, 0x82,
  25192. 0x74, 0x0E, 0xB0, 0x21, 0xC9, 0x7B, 0x8E, 0xBB,
  25193. 0xA4, 0x0F, 0xF3, 0x28, 0xB5, 0x41, 0x76, 0x0F,
  25194. 0xCC, 0x37, 0x2B, 0x52, 0xD3, 0xBC, 0x4F, 0xCB,
  25195. 0xC0, 0x6F, 0x42, 0x4E, 0xAF, 0x25, 0x38, 0x04,
  25196. 0xD4, 0xCB, 0x46, 0xF4, 0x1F, 0xF2, 0x54, 0xC0,
  25197. 0xC5, 0xBA, 0x48, 0x3B, 0x44, 0xA8, 0x7C, 0x21,
  25198. 0x96, 0x54, 0x55, 0x5E, 0xC7, 0xC1, 0x63, 0xC7,
  25199. 0x9B, 0x9C, 0xB7, 0x60, 0xA2, 0xAD, 0x9B, 0xB7,
  25200. 0x22, 0xB9, 0x3E, 0x0C, 0x28, 0xBD, 0x4B, 0x16,
  25201. 0x85, 0x94, 0x9C, 0x49, 0x6E, 0xAB, 0x1A, 0xFF,
  25202. 0x90, 0x91, 0x9E, 0x37, 0x61, 0xB3, 0x46, 0x83,
  25203. 0x8A, 0xBB, 0x2F, 0x01, 0xA9, 0x1E, 0x55, 0x43,
  25204. 0x75, 0xAF, 0xDA, 0xAA, 0xF3, 0x82, 0x6E, 0x6D,
  25205. 0xB7, 0x9F, 0xE7, 0x35, 0x3A, 0x7A, 0x57, 0x8A,
  25206. 0x7C, 0x05, 0x98, 0xCE, 0x28, 0xB6, 0xD9, 0x91,
  25207. 0x52, 0x14, 0x23, 0x6B, 0xBF, 0xFA, 0x6D, 0x45,
  25208. 0xB6, 0x37, 0x6A, 0x07, 0x92, 0x4A, 0x39, 0xA7,
  25209. 0xBE, 0x81, 0x82, 0x86, 0x71, 0x5C, 0x8A, 0x3C,
  25210. 0x11, 0x0C, 0xD7, 0x6C, 0x02, 0xE0, 0x41, 0x7A,
  25211. 0xF1, 0x38, 0xBD, 0xB9, 0x5C, 0x3C, 0xCA, 0x79,
  25212. 0x8A, 0xC8, 0x09, 0xED, 0x69, 0xCF, 0xB6, 0x72,
  25213. 0xB6, 0xFD, 0xDC, 0x24, 0xD8, 0x9C, 0x06, 0xA6,
  25214. 0x55, 0x88, 0x14, 0xAB, 0x0C, 0x21, 0xC6, 0x2B,
  25215. 0x2F, 0x84, 0xC0, 0xE3, 0xE0, 0x80, 0x3D, 0xB3,
  25216. 0x37, 0xA4, 0xE0, 0xC7, 0x12, 0x7A, 0x6B, 0x4C,
  25217. 0x8C, 0x08, 0xB1, 0xD1, 0xA7, 0x6B, 0xF0, 0x7E,
  25218. 0xB6, 0xE5, 0xB5, 0xBB, 0x47, 0xA1, 0x6C, 0x74,
  25219. 0xBC, 0x54, 0x83, 0x75, 0xFB, 0x29, 0xCD, 0x78,
  25220. 0x9A, 0x5C, 0xFF, 0x91, 0xBD, 0xBD, 0x07, 0x18,
  25221. 0x59, 0xF4, 0x84, 0x6E, 0x35, 0x5B, 0xB0, 0xD2,
  25222. 0x94, 0x84, 0xE2, 0x64, 0xDF, 0xF3, 0x6C, 0x91,
  25223. 0x77, 0xA7, 0xAC, 0xA7, 0x89, 0x08, 0x87, 0x96,
  25224. 0x95, 0xCA, 0x87, 0xF2, 0x54, 0x36, 0xBC, 0x12,
  25225. 0x63, 0x07, 0x24, 0xBB, 0x22, 0xF0, 0xCB, 0x64,
  25226. 0x89, 0x7F, 0xE5, 0xC4, 0x11, 0x95, 0x28, 0x0D,
  25227. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25228. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25229. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25230. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25231. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25232. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25233. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25234. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25235. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25236. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25237. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25238. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25239. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25240. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25241. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25242. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25243. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25244. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25245. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25246. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25247. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25248. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25249. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25250. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25251. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25252. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25253. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25254. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25255. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25256. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25257. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25258. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25259. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25260. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25261. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25262. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25263. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25264. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25265. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25266. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25267. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25268. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25269. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25270. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25271. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25272. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25273. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25274. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25275. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25276. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25277. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25278. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25279. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25280. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25281. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25282. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25283. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25284. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25285. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25286. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25287. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25288. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25289. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25290. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25291. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25292. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25293. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25294. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25295. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25296. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25297. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25298. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25299. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25300. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25301. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25302. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25303. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25304. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25305. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25306. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25307. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25308. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25309. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25310. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25311. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25312. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25313. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25314. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25315. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25316. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25317. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25318. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25319. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25320. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25321. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25322. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25323. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25324. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25325. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25326. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25327. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25328. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25329. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25330. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25331. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25332. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25333. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25334. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25335. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25336. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25337. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25338. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25339. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25340. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25341. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25342. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25343. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25344. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25345. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25346. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25347. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25348. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25349. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25350. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25351. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25352. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25353. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25354. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25355. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25356. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25357. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25358. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25359. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25360. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25361. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25362. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25363. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25364. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25365. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25366. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25367. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25368. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25369. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25370. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25371. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25372. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25373. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25374. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25375. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25376. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25377. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25378. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25379. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25380. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25381. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25382. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25383. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25384. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25385. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25386. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25387. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25388. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25389. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25390. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25391. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25392. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25393. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25394. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25395. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25396. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25397. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25398. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25399. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25400. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25401. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25402. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25403. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25404. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25405. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25406. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25407. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25408. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25409. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25410. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25411. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25412. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25413. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25414. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25415. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25416. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25417. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25418. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25419. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25420. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25421. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25422. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21,
  25423. 0xD2, 0xE5, 0x74, 0xDF, 0xD8, 0xCD, 0x0A, 0xE8,
  25424. 0x93, 0xAA, 0x7E, 0x12, 0x5B, 0x44, 0xB9, 0x24,
  25425. 0xF4, 0x52, 0x23, 0xEC, 0x09, 0xF2, 0xAD, 0x11,
  25426. 0x41, 0xEA, 0x93, 0xA6, 0x80, 0x50, 0xDB, 0xF6,
  25427. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25428. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25429. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25430. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25431. };
  25432. #endif
  25433. static byte pubKey[KYBER_MAX_PUBLIC_KEY_SIZE];
  25434. static byte privKey[KYBER_MAX_PRIVATE_KEY_SIZE];
  25435. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25436. ExpectNotNull(key);
  25437. if (key != NULL) {
  25438. XMEMSET(key, 0, sizeof(KyberKey));
  25439. }
  25440. #ifndef WOLFSSL_NO_KYBER512
  25441. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  25442. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
  25443. 0);
  25444. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25445. KYBER512_PUBLIC_KEY_SIZE), 0);
  25446. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25447. KYBER512_PRIVATE_KEY_SIZE), 0);
  25448. ExpectIntEQ(XMEMCMP(pubKey, ek_512, KYBER512_PUBLIC_KEY_SIZE), 0);
  25449. ExpectIntEQ(XMEMCMP(privKey, dk_512, KYBER512_PRIVATE_KEY_SIZE), 0);
  25450. wc_KyberKey_Free(key);
  25451. #endif
  25452. #ifndef WOLFSSL_NO_KYBER768
  25453. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  25454. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
  25455. 0);
  25456. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25457. KYBER768_PUBLIC_KEY_SIZE), 0);
  25458. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25459. KYBER768_PRIVATE_KEY_SIZE), 0);
  25460. ExpectIntEQ(XMEMCMP(pubKey, ek_768, KYBER768_PUBLIC_KEY_SIZE), 0);
  25461. ExpectIntEQ(XMEMCMP(privKey, dk_768, KYBER768_PRIVATE_KEY_SIZE), 0);
  25462. wc_KyberKey_Free(key);
  25463. #endif
  25464. #ifndef WOLFSSL_NO_KYBER1024
  25465. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  25466. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_1024,
  25467. sizeof(seed_1024)), 0);
  25468. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25469. KYBER1024_PUBLIC_KEY_SIZE), 0);
  25470. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25471. KYBER1024_PRIVATE_KEY_SIZE), 0);
  25472. ExpectIntEQ(XMEMCMP(pubKey, ek_1024, KYBER1024_PUBLIC_KEY_SIZE), 0);
  25473. ExpectIntEQ(XMEMCMP(privKey, dk_1024, KYBER1024_PRIVATE_KEY_SIZE), 0);
  25474. wc_KyberKey_Free(key);
  25475. #endif
  25476. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25477. #endif
  25478. return EXPECT_RESULT();
  25479. }
  25480. static int test_wc_kyber_encapsulate_kats(void)
  25481. {
  25482. EXPECT_DECLS;
  25483. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  25484. !defined(WOLFSSL_KYBER_ORIGINAL)
  25485. KyberKey* key;
  25486. #ifndef WOLFSSL_NO_KYBER512
  25487. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  25488. 0xDD, 0x19, 0x24, 0x93, 0x5A, 0xA8, 0xE6, 0x17,
  25489. 0xAF, 0x18, 0xB5, 0xA0, 0x65, 0xAC, 0x45, 0x72,
  25490. 0x77, 0x67, 0xEE, 0x89, 0x7C, 0xF4, 0xF9, 0x44,
  25491. 0x2B, 0x2A, 0xCE, 0x30, 0xC0, 0x23, 0x7B, 0x30,
  25492. 0x7D, 0x3E, 0x76, 0xBF, 0x8E, 0xEB, 0x78, 0xAD,
  25493. 0xDC, 0x4A, 0xAC, 0xD1, 0x64, 0x63, 0xD8, 0x60,
  25494. 0x2F, 0xD5, 0x48, 0x7B, 0x63, 0xC8, 0x8B, 0xB6,
  25495. 0x60, 0x27, 0xF3, 0x7D, 0x0D, 0x61, 0x4D, 0x6F,
  25496. 0x9C, 0x24, 0x60, 0x3C, 0x42, 0x94, 0x76, 0x64,
  25497. 0xAC, 0x43, 0x98, 0xC6, 0xC5, 0x23, 0x83, 0x46,
  25498. 0x9B, 0x4F, 0x97, 0x77, 0xE5, 0xEC, 0x72, 0x06,
  25499. 0x21, 0x0F, 0x3E, 0x5A, 0x79, 0x6B, 0xF4, 0x5C,
  25500. 0x53, 0x26, 0x8E, 0x25, 0xF3, 0x9A, 0xC2, 0x61,
  25501. 0xAF, 0x3B, 0xFA, 0x2E, 0xE7, 0x55, 0xBE, 0xB8,
  25502. 0xB6, 0x7A, 0xB3, 0xAC, 0x8D, 0xF6, 0xC6, 0x29,
  25503. 0xC1, 0x17, 0x6E, 0x9E, 0x3B, 0x96, 0x5E, 0x93,
  25504. 0x69, 0xF9, 0xB3, 0xB9, 0x2A, 0xD7, 0xC2, 0x09,
  25505. 0x55, 0x64, 0x1D, 0x99, 0x52, 0x6F, 0xE7, 0xB9,
  25506. 0xFE, 0x8C, 0x85, 0x08, 0x20, 0x27, 0x5C, 0xD9,
  25507. 0x64, 0x84, 0x92, 0x50, 0x09, 0x07, 0x33, 0xCE,
  25508. 0x12, 0x4E, 0xCF, 0x31, 0x66, 0x24, 0x37, 0x4B,
  25509. 0xD1, 0x8B, 0x7C, 0x35, 0x8C, 0x06, 0xE9, 0xC1,
  25510. 0x36, 0xEE, 0x12, 0x59, 0xA9, 0x24, 0x5A, 0xBC,
  25511. 0x55, 0xB9, 0x64, 0xD6, 0x89, 0xF5, 0xA0, 0x82,
  25512. 0x92, 0xD2, 0x82, 0x65, 0x65, 0x8E, 0xBB, 0x40,
  25513. 0xCB, 0xFE, 0x48, 0x8A, 0x22, 0x28, 0x27, 0x55,
  25514. 0x90, 0xAB, 0x9F, 0x32, 0xA3, 0x41, 0x09, 0x70,
  25515. 0x9C, 0x1C, 0x29, 0x1D, 0x4A, 0x23, 0x33, 0x72,
  25516. 0x74, 0xC7, 0xA5, 0xA5, 0x99, 0x1C, 0x7A, 0x87,
  25517. 0xB8, 0x1C, 0x97, 0x4A, 0xB1, 0x8C, 0xE7, 0x78,
  25518. 0x59, 0xE4, 0x99, 0x5E, 0x7C, 0x14, 0xF0, 0x37,
  25519. 0x17, 0x48, 0xB7, 0x71, 0x2F, 0xB5, 0x2C, 0x59,
  25520. 0x66, 0xCD, 0x63, 0x06, 0x3C, 0x4F, 0x3B, 0x81,
  25521. 0xB4, 0x7C, 0x45, 0xDD, 0xE8, 0x3F, 0xB3, 0xA2,
  25522. 0x72, 0x40, 0x29, 0xB1, 0x0B, 0x32, 0x30, 0x21,
  25523. 0x4C, 0x04, 0xFA, 0x05, 0x77, 0xFC, 0x29, 0xAC,
  25524. 0x90, 0x86, 0xAE, 0x18, 0xC5, 0x3B, 0x3E, 0xD4,
  25525. 0x4E, 0x50, 0x74, 0x12, 0xFC, 0xA0, 0x4B, 0x4F,
  25526. 0x53, 0x8A, 0x51, 0x58, 0x8E, 0xC1, 0xF1, 0x02,
  25527. 0x9D, 0x15, 0x2D, 0x9A, 0xE7, 0x73, 0x5F, 0x76,
  25528. 0xA0, 0x77, 0xAA, 0x94, 0x84, 0x38, 0x0A, 0xED,
  25529. 0x91, 0x89, 0xE5, 0x91, 0x24, 0x87, 0xFC, 0xC5,
  25530. 0xB7, 0xC7, 0x01, 0x2D, 0x92, 0x23, 0xDD, 0x96,
  25531. 0x7E, 0xEC, 0xDA, 0xC3, 0x00, 0x8A, 0x89, 0x31,
  25532. 0xB6, 0x48, 0x24, 0x35, 0x37, 0xF5, 0x48, 0xC1,
  25533. 0x71, 0x69, 0x8C, 0x5B, 0x38, 0x1D, 0x84, 0x6A,
  25534. 0x72, 0xE5, 0xC9, 0x2D, 0x42, 0x26, 0xC5, 0xA8,
  25535. 0x90, 0x98, 0x84, 0xF1, 0xC4, 0xA3, 0x40, 0x4C,
  25536. 0x17, 0x20, 0xA5, 0x27, 0x94, 0x14, 0xD7, 0xF2,
  25537. 0x7B, 0x2B, 0x98, 0x26, 0x52, 0xB6, 0x74, 0x02,
  25538. 0x19, 0xC5, 0x6D, 0x21, 0x77, 0x80, 0xD7, 0xA5,
  25539. 0xE5, 0xBA, 0x59, 0x83, 0x63, 0x49, 0xF7, 0x26,
  25540. 0x88, 0x1D, 0xEA, 0x18, 0xEF, 0x75, 0xC0, 0x77,
  25541. 0x2A, 0x8B, 0x92, 0x27, 0x66, 0x95, 0x37, 0x18,
  25542. 0xCA, 0xCC, 0x14, 0xCC, 0xBA, 0xCB, 0x5F, 0xC4,
  25543. 0x12, 0xA2, 0xD0, 0xBE, 0x52, 0x18, 0x17, 0x64,
  25544. 0x5A, 0xB2, 0xBF, 0x6A, 0x47, 0x85, 0xE9, 0x2B,
  25545. 0xC9, 0x4C, 0xAF, 0x47, 0x7A, 0x96, 0x78, 0x76,
  25546. 0x79, 0x6C, 0x0A, 0x51, 0x90, 0x31, 0x5A, 0xC0,
  25547. 0x88, 0x56, 0x71, 0xA4, 0xC7, 0x49, 0x56, 0x4C,
  25548. 0x3B, 0x2C, 0x7A, 0xED, 0x90, 0x64, 0xEB, 0xA2,
  25549. 0x99, 0xEF, 0x21, 0x4B, 0xA2, 0xF4, 0x04, 0x93,
  25550. 0x66, 0x7C, 0x8B, 0xD0, 0x32, 0xAE, 0xC5, 0x62,
  25551. 0x17, 0x11, 0xB4, 0x1A, 0x38, 0x52, 0xC5, 0xC2,
  25552. 0xBA, 0xB4, 0xA3, 0x49, 0xCE, 0x4B, 0x7F, 0x08,
  25553. 0x5A, 0x81, 0x2B, 0xBB, 0xC8, 0x20, 0xB8, 0x1B,
  25554. 0xEF, 0xE6, 0x3A, 0x05, 0xB8, 0xBC, 0xDF, 0xE9,
  25555. 0xC2, 0xA7, 0x0A, 0x8B, 0x1A, 0xCA, 0x9B, 0xF9,
  25556. 0x81, 0x64, 0x81, 0x90, 0x7F, 0xF4, 0x43, 0x24,
  25557. 0x61, 0x11, 0x12, 0x87, 0x30, 0x3F, 0x0B, 0xD8,
  25558. 0x17, 0xC0, 0x57, 0x26, 0xBF, 0xA1, 0x8A, 0x2E,
  25559. 0x24, 0xC7, 0x72, 0x49, 0x21, 0x02, 0x80, 0x32,
  25560. 0xF6, 0x22, 0xBD, 0x96, 0x0A, 0x31, 0x7D, 0x83,
  25561. 0xB3, 0x56, 0xB5, 0x7F, 0x4A, 0x80, 0x04, 0x49,
  25562. 0x9C, 0xBC, 0x73, 0xC9, 0x7D, 0x1E, 0xB7, 0x74,
  25563. 0x59, 0x72, 0x63, 0x1C, 0x05, 0x61, 0xC1, 0xA3,
  25564. 0xAB, 0x6E, 0xF9, 0x1B, 0xD3, 0x63, 0x28, 0x0A,
  25565. 0x10, 0x54, 0x5D, 0xA6, 0x93, 0xE6, 0xD5, 0x8A,
  25566. 0xED, 0x68, 0x45, 0xE7, 0xCC, 0x5F, 0x0D, 0x08,
  25567. 0xCA, 0x79, 0x05, 0x05, 0x2C, 0x77, 0x36, 0x6D,
  25568. 0x19, 0x72, 0xCC, 0xFC, 0xC1, 0xA2, 0x76, 0x10,
  25569. 0xCB, 0x54, 0x36, 0x65, 0xAA, 0x79, 0x8E, 0x20,
  25570. 0x94, 0x01, 0x28, 0xB9, 0x56, 0x7A, 0x7E, 0xDB,
  25571. 0x7A, 0x90, 0x04, 0x07, 0xC7, 0x0D, 0x35, 0x94,
  25572. 0x38, 0x43, 0x5E, 0x13, 0x96, 0x16, 0x08, 0xD5,
  25573. 0x52, 0xA9, 0x4C, 0x5C, 0xDA, 0x78, 0x59, 0x22,
  25574. 0x05, 0x09, 0xB4, 0x83, 0xC5, 0xC5, 0x2A, 0x21,
  25575. 0x0E, 0x9C, 0x81, 0x2B, 0xC0, 0xC2, 0x32, 0x8C,
  25576. 0xA0, 0x0E, 0x78, 0x9A, 0x56, 0xB2, 0x60, 0x6B,
  25577. 0x90, 0x29, 0x2E, 0x35, 0x43, 0xDA, 0xCA, 0xA2,
  25578. 0x43, 0x18, 0x41, 0xD6, 0x1A, 0x22, 0xCA, 0x90,
  25579. 0xC1, 0xCC, 0xF0, 0xB5, 0xB4, 0xE0, 0xA6, 0xF6,
  25580. 0x40, 0x53, 0x6D, 0x1A, 0x26, 0xAB, 0x5B, 0x8D,
  25581. 0x21, 0x51, 0x32, 0x79, 0x28, 0xCE, 0x02, 0x90,
  25582. 0x4C, 0xF1, 0xD1, 0x5E, 0x32, 0x78, 0x8A, 0x95,
  25583. 0xF6, 0x2D, 0x3C, 0x27, 0x0B, 0x6F, 0xA1, 0x50,
  25584. 0x8F, 0x97, 0xB9, 0x15, 0x5A, 0x27, 0x26, 0xD8,
  25585. 0x0A, 0x1A, 0xFA, 0x3C, 0x53, 0x87, 0xA2, 0x76,
  25586. 0xA4, 0xD0, 0x31, 0xA0, 0x8A, 0xBF, 0x4F, 0x2E,
  25587. 0x74, 0xF1, 0xA0, 0xBB, 0x8A, 0x0F, 0xD3, 0xCB
  25588. };
  25589. static const byte seed_512[KYBER_ENC_RAND_SZ] = {
  25590. 0x6F, 0xF0, 0x2E, 0x1D, 0xC7, 0xFD, 0x91, 0x1B,
  25591. 0xEE, 0xE0, 0xC6, 0x92, 0xC8, 0xBD, 0x10, 0x0C,
  25592. 0x3E, 0x5C, 0x48, 0x96, 0x4D, 0x31, 0xDF, 0x92,
  25593. 0x99, 0x42, 0x18, 0xE8, 0x06, 0x64, 0xA6, 0xCA
  25594. };
  25595. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  25596. 0x19, 0xC5, 0x92, 0x50, 0x59, 0x07, 0xC2, 0x4C,
  25597. 0x5F, 0xA2, 0xEB, 0xFA, 0x93, 0x2D, 0x2C, 0xBB,
  25598. 0x48, 0xF3, 0xE4, 0x34, 0x0A, 0x28, 0xF7, 0xEB,
  25599. 0xA5, 0xD0, 0x68, 0xFC, 0xAC, 0xAB, 0xED, 0xF7,
  25600. 0x77, 0x84, 0xE2, 0xB2, 0x4D, 0x79, 0x61, 0x77,
  25601. 0x5F, 0x0B, 0xF1, 0xA9, 0x97, 0xAE, 0x8B, 0xA9,
  25602. 0xFC, 0x43, 0x11, 0xBE, 0x63, 0x71, 0x67, 0x79,
  25603. 0xC2, 0xB7, 0x88, 0xF8, 0x12, 0xCB, 0xB7, 0x8C,
  25604. 0x74, 0xE7, 0x51, 0x7E, 0x22, 0xE9, 0x10, 0xEF,
  25605. 0xF5, 0xF3, 0x8D, 0x44, 0x46, 0x9C, 0x50, 0xDE,
  25606. 0x16, 0x75, 0xAE, 0x19, 0x8F, 0xD6, 0xA2, 0x89,
  25607. 0xAE, 0x7E, 0x6C, 0x30, 0xA9, 0xD4, 0x35, 0x1B,
  25608. 0x3D, 0x1F, 0x4C, 0x36, 0xEF, 0xF9, 0xC6, 0x8D,
  25609. 0xA9, 0x1C, 0x40, 0xB8, 0x2D, 0xC9, 0xB2, 0x79,
  25610. 0x9A, 0x33, 0xA2, 0x6B, 0x60, 0xA4, 0xE7, 0x0D,
  25611. 0x71, 0x01, 0x86, 0x27, 0x79, 0x46, 0x9F, 0x3A,
  25612. 0x9D, 0xAE, 0xC8, 0xE3, 0xE8, 0xF8, 0xC6, 0xA1,
  25613. 0x6B, 0xF0, 0x92, 0xFB, 0xA5, 0x86, 0x61, 0x86,
  25614. 0xB8, 0xD2, 0x08, 0xFD, 0xEB, 0x27, 0x4A, 0xC1,
  25615. 0xF8, 0x29, 0x65, 0x9D, 0xC2, 0xBE, 0x4A, 0xC4,
  25616. 0xF3, 0x06, 0xCB, 0x55, 0x84, 0xBA, 0xD1, 0x93,
  25617. 0x6A, 0x92, 0xC9, 0xB7, 0x68, 0x19, 0x23, 0x42,
  25618. 0x81, 0xBB, 0x39, 0x58, 0x41, 0xC2, 0x57, 0x56,
  25619. 0x08, 0x6E, 0xA5, 0x64, 0xCA, 0x3E, 0x22, 0x7E,
  25620. 0x3D, 0x9F, 0x10, 0x52, 0xC0, 0x76, 0x6D, 0x2E,
  25621. 0xB7, 0x9A, 0x47, 0xC1, 0x50, 0x72, 0x1E, 0x0D,
  25622. 0xEA, 0x7C, 0x00, 0x69, 0xD5, 0x51, 0xB2, 0x64,
  25623. 0x80, 0x1B, 0x77, 0x27, 0xEC, 0xAF, 0x82, 0xEE,
  25624. 0xCB, 0x99, 0xA8, 0x76, 0xFD, 0xA0, 0x90, 0xBF,
  25625. 0x6C, 0x3F, 0xC6, 0xB1, 0x09, 0xF1, 0x70, 0x14,
  25626. 0x85, 0xF0, 0x3C, 0xE6, 0x62, 0x74, 0xB8, 0x43,
  25627. 0x5B, 0x0A, 0x01, 0x4C, 0xFB, 0x3E, 0x79, 0xCC,
  25628. 0xED, 0x67, 0x05, 0x7B, 0x5A, 0xE2, 0xAD, 0x7F,
  25629. 0x52, 0x79, 0xEB, 0x71, 0x49, 0x42, 0xE4, 0xC1,
  25630. 0xCC, 0xFF, 0x7E, 0x85, 0xC0, 0xDB, 0x43, 0xE5,
  25631. 0xD4, 0x12, 0x89, 0x20, 0x73, 0x63, 0xB4, 0x44,
  25632. 0xBB, 0x51, 0xBB, 0x8A, 0xB0, 0x37, 0x1E, 0x70,
  25633. 0xCB, 0xD5, 0x5F, 0x0F, 0x3D, 0xAD, 0x40, 0x3E,
  25634. 0x10, 0x51, 0x76, 0xE3, 0xE8, 0xA2, 0x25, 0xD8,
  25635. 0x4A, 0xC8, 0xBE, 0xE3, 0x8C, 0x82, 0x1E, 0xE0,
  25636. 0xF5, 0x47, 0x43, 0x11, 0x45, 0xDC, 0xB3, 0x13,
  25637. 0x92, 0x86, 0xAB, 0xB1, 0x17, 0x94, 0xA4, 0x3A,
  25638. 0x3C, 0x1B, 0x52, 0x29, 0xE4, 0xBC, 0xFE, 0x95,
  25639. 0x9C, 0x78, 0xAD, 0xAE, 0xE2, 0xD5, 0xF2, 0x49,
  25640. 0x7B, 0x5D, 0x24, 0xBC, 0x21, 0xFA, 0x03, 0xA9,
  25641. 0xA5, 0x8C, 0x24, 0x55, 0x37, 0x3E, 0xC8, 0x95,
  25642. 0x83, 0xE7, 0xE5, 0x88, 0xD7, 0xFE, 0x67, 0x99,
  25643. 0x1E, 0xE9, 0x37, 0x83, 0xED, 0x4A, 0x6F, 0x9E,
  25644. 0xEA, 0xE0, 0x4E, 0x64, 0xE2, 0xE1, 0xE0, 0xE6,
  25645. 0x99, 0xF6, 0xDC, 0x9C, 0x5D, 0x39, 0xEF, 0x92,
  25646. 0x78, 0xC9, 0x85, 0xE7, 0xFD, 0xF2, 0xA7, 0x64,
  25647. 0xFF, 0xD1, 0xA0, 0xB9, 0x57, 0x92, 0xAD, 0x68,
  25648. 0x1E, 0x93, 0x0D, 0x76, 0xDF, 0x4E, 0xFE, 0x5D,
  25649. 0x65, 0xDB, 0xBD, 0x0F, 0x14, 0x38, 0x48, 0x1E,
  25650. 0xD8, 0x33, 0xAD, 0x49, 0x46, 0xAD, 0x1C, 0x69,
  25651. 0xAD, 0x21, 0xDD, 0x7C, 0x86, 0x18, 0x57, 0x74,
  25652. 0x42, 0x6F, 0x3F, 0xCF, 0x53, 0xB5, 0x2A, 0xD4,
  25653. 0xB4, 0x0D, 0x22, 0x8C, 0xE1, 0x24, 0x07, 0x2F,
  25654. 0x59, 0x2C, 0x7D, 0xAA, 0x05, 0x7F, 0x17, 0xD7,
  25655. 0x90, 0xA5, 0xBD, 0x5B, 0x93, 0x83, 0x4D, 0x58,
  25656. 0xC0, 0x8C, 0x88, 0xDC, 0x8F, 0x0E, 0xF4, 0x88,
  25657. 0x15, 0x64, 0x25, 0xB7, 0x44, 0x65, 0x4E, 0xAC,
  25658. 0xA9, 0xD6, 0x48, 0x58, 0xA4, 0xD6, 0xCE, 0xB4,
  25659. 0x78, 0x79, 0x51, 0x94, 0xBF, 0xAD, 0xB1, 0x8D,
  25660. 0xC0, 0xEA, 0x05, 0x4F, 0x97, 0x71, 0x21, 0x5A,
  25661. 0xD3, 0xCB, 0x1F, 0xD0, 0x31, 0xD7, 0xBE, 0x45,
  25662. 0x98, 0x62, 0x19, 0x26, 0x47, 0x8D, 0x37, 0x5A,
  25663. 0x18, 0x45, 0xAA, 0x91, 0xD7, 0xC7, 0x33, 0xF8,
  25664. 0xF0, 0xE1, 0x88, 0xC8, 0x38, 0x96, 0xED, 0xF8,
  25665. 0x3B, 0x86, 0x46, 0xC9, 0x9E, 0x29, 0xC0, 0xDA,
  25666. 0x22, 0x90, 0xE7, 0x1C, 0x3D, 0x2E, 0x97, 0x07,
  25667. 0x20, 0xC9, 0x7B, 0x5B, 0x7F, 0x95, 0x04, 0x86,
  25668. 0x03, 0x3C, 0x6A, 0x25, 0x71, 0xDD, 0xF2, 0xBC,
  25669. 0xCD, 0xAB, 0xB2, 0xDF, 0xA5, 0xFC, 0xE4, 0xC3,
  25670. 0xA1, 0x88, 0x46, 0x06, 0x04, 0x1D, 0x18, 0x1C,
  25671. 0x72, 0x87, 0x94, 0xAE, 0x0E, 0x80, 0x6E, 0xCB,
  25672. 0x49, 0xAF, 0x16, 0x75, 0x6A, 0x4C, 0xE7, 0x3C,
  25673. 0x87, 0xBD, 0x42, 0x34, 0xE6, 0x0F, 0x05, 0x53,
  25674. 0x5F, 0xA5, 0x92, 0x9F, 0xD5, 0xA3, 0x44, 0x73,
  25675. 0x26, 0x64, 0x01, 0xF6, 0x3B, 0xBD, 0x6B, 0x90,
  25676. 0xE0, 0x03, 0x47, 0x2A, 0xC0, 0xCE, 0x88, 0xF1,
  25677. 0xB6, 0x66, 0x59, 0x72, 0x79, 0xD0, 0x56, 0xA6,
  25678. 0x32, 0xC8, 0xD6, 0xB7, 0x90, 0xFD, 0x41, 0x17,
  25679. 0x67, 0x84, 0x8A, 0x69, 0xE3, 0x7A, 0x8A, 0x83,
  25680. 0x9B, 0xC7, 0x66, 0xA0, 0x2C, 0xA2, 0xF6, 0x95,
  25681. 0xEC, 0x63, 0xF0, 0x56, 0xA4, 0xE2, 0xA1, 0x14,
  25682. 0xCA, 0xCF, 0x9F, 0xD9, 0x0D, 0x73, 0x0C, 0x97,
  25683. 0x0D, 0xB3, 0x87, 0xF6, 0xDE, 0x73, 0x39, 0x5F,
  25684. 0x70, 0x1A, 0x1D, 0x95, 0x3B, 0x2A, 0x89, 0xDD,
  25685. 0x7E, 0xDA, 0xD4, 0x39, 0xFC, 0x20, 0x5A, 0x54,
  25686. 0xA4, 0x81, 0xE8, 0x89, 0xB0, 0x98, 0xD5, 0x25,
  25687. 0x56, 0x70, 0xF0, 0x26, 0xB4, 0xA2, 0xBF, 0x02,
  25688. 0xD2, 0xBD, 0xDE, 0x87, 0xC7, 0x66, 0xB2, 0x5F,
  25689. 0xC5, 0xE0, 0xFD, 0x45, 0x37, 0x57, 0xE7, 0x56,
  25690. 0xD1, 0x8C, 0x8C, 0xD9, 0x12, 0xF9, 0xA7, 0x7F,
  25691. 0x8E, 0x6B, 0xF0, 0x20, 0x53, 0x74, 0xB4, 0x62
  25692. };
  25693. static const byte k_512[KYBER_SS_SZ] = {
  25694. 0x0B, 0xF3, 0x23, 0x33, 0x8D, 0x6F, 0x0A, 0x21,
  25695. 0xD5, 0x51, 0x4B, 0x67, 0x3C, 0xD1, 0x0B, 0x71,
  25696. 0x4C, 0xE6, 0xE3, 0x6F, 0x35, 0xBC, 0xD1, 0xBF,
  25697. 0x54, 0x41, 0x96, 0x36, 0x8E, 0xE5, 0x1A, 0x13
  25698. };
  25699. #endif
  25700. #ifndef WOLFSSL_NO_KYBER768
  25701. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  25702. 0x89, 0xD2, 0xCB, 0x65, 0xF9, 0x4D, 0xCB, 0xFC,
  25703. 0x89, 0x0E, 0xFC, 0x7D, 0x0E, 0x5A, 0x7A, 0x38,
  25704. 0x34, 0x4D, 0x16, 0x41, 0xA3, 0xD0, 0xB0, 0x24,
  25705. 0xD5, 0x07, 0x97, 0xA5, 0xF2, 0x3C, 0x3A, 0x18,
  25706. 0xB3, 0x10, 0x1A, 0x12, 0x69, 0x06, 0x9F, 0x43,
  25707. 0xA8, 0x42, 0xBA, 0xCC, 0x09, 0x8A, 0x88, 0x21,
  25708. 0x27, 0x1C, 0x67, 0x3D, 0xB1, 0xBE, 0xB3, 0x30,
  25709. 0x34, 0xE4, 0xD7, 0x77, 0x4D, 0x16, 0x63, 0x5C,
  25710. 0x7C, 0x2C, 0x3C, 0x27, 0x63, 0x45, 0x35, 0x38,
  25711. 0xBC, 0x16, 0x32, 0xE1, 0x85, 0x15, 0x91, 0xA5,
  25712. 0x16, 0x42, 0x97, 0x4E, 0x59, 0x28, 0xAB, 0xB8,
  25713. 0xE5, 0x5F, 0xE5, 0x56, 0x12, 0xF9, 0xB1, 0x41,
  25714. 0xAF, 0xF0, 0x15, 0x54, 0x53, 0x94, 0xB2, 0x09,
  25715. 0x2E, 0x59, 0x09, 0x70, 0xEC, 0x29, 0xA7, 0xB7,
  25716. 0xE7, 0xAA, 0x1F, 0xB4, 0x49, 0x3B, 0xF7, 0xCB,
  25717. 0x73, 0x19, 0x06, 0xC2, 0xA5, 0xCB, 0x49, 0xE6,
  25718. 0x61, 0x48, 0x59, 0x06, 0x4E, 0x19, 0xB8, 0xFA,
  25719. 0x26, 0xAF, 0x51, 0xC4, 0x4B, 0x5E, 0x75, 0x35,
  25720. 0xBF, 0xDA, 0xC0, 0x72, 0xB6, 0x46, 0xD3, 0xEA,
  25721. 0x49, 0x0D, 0x27, 0x7F, 0x0D, 0x97, 0xCE, 0xD4,
  25722. 0x73, 0x95, 0xFE, 0xD9, 0x1E, 0x8F, 0x2B, 0xCE,
  25723. 0x0E, 0x3C, 0xA1, 0x22, 0xC2, 0x02, 0x5F, 0x74,
  25724. 0x06, 0x7A, 0xB9, 0x28, 0xA8, 0x22, 0xB3, 0x56,
  25725. 0x53, 0xA7, 0x4F, 0x06, 0x75, 0x76, 0x29, 0xAF,
  25726. 0xB1, 0xA1, 0xCA, 0xF2, 0x37, 0x10, 0x0E, 0xA9,
  25727. 0x35, 0xE7, 0x93, 0xC8, 0xF5, 0x8A, 0x71, 0xB3,
  25728. 0xD6, 0xAE, 0x2C, 0x86, 0x58, 0xB1, 0x01, 0x50,
  25729. 0xD4, 0xA3, 0x8F, 0x57, 0x2A, 0x0D, 0x49, 0xD2,
  25730. 0x8A, 0xE8, 0x94, 0x51, 0xD3, 0x38, 0x32, 0x6F,
  25731. 0xDB, 0x3B, 0x43, 0x50, 0x03, 0x6C, 0x10, 0x81,
  25732. 0x11, 0x77, 0x40, 0xED, 0xB8, 0x6B, 0x12, 0x08,
  25733. 0x1C, 0x5C, 0x12, 0x23, 0xDB, 0xB5, 0x66, 0x0D,
  25734. 0x5B, 0x3C, 0xB3, 0x78, 0x7D, 0x48, 0x18, 0x49,
  25735. 0x30, 0x4C, 0x68, 0xBE, 0x87, 0x54, 0x66, 0xF1,
  25736. 0x4E, 0xE5, 0x49, 0x5C, 0x2B, 0xD7, 0x95, 0xAE,
  25737. 0x41, 0x2D, 0x09, 0x00, 0x2D, 0x65, 0xB8, 0x71,
  25738. 0x9B, 0x90, 0xCB, 0xA3, 0x60, 0x3A, 0xC4, 0x95,
  25739. 0x8E, 0xA0, 0x3C, 0xC1, 0x38, 0xC8, 0x6F, 0x78,
  25740. 0x51, 0x59, 0x31, 0x25, 0x33, 0x47, 0x01, 0xB6,
  25741. 0x77, 0xF8, 0x2F, 0x49, 0x52, 0xA4, 0xC9, 0x3B,
  25742. 0x5B, 0x4C, 0x13, 0x4B, 0xB4, 0x2A, 0x85, 0x7F,
  25743. 0xD1, 0x5C, 0x65, 0x08, 0x64, 0xA6, 0xAA, 0x94,
  25744. 0xEB, 0x69, 0x1C, 0x0B, 0x69, 0x1B, 0xE4, 0x68,
  25745. 0x4C, 0x1F, 0x5B, 0x74, 0x90, 0x46, 0x7F, 0xC0,
  25746. 0x1B, 0x1D, 0x1F, 0xDA, 0x4D, 0xDA, 0x35, 0xC4,
  25747. 0xEC, 0xC2, 0x31, 0xBC, 0x73, 0xA6, 0xFE, 0xF4,
  25748. 0x2C, 0x99, 0xD3, 0x4E, 0xB8, 0x2A, 0x4D, 0x01,
  25749. 0x49, 0x87, 0xB3, 0xE3, 0x86, 0x91, 0x0C, 0x62,
  25750. 0x67, 0x9A, 0x11, 0x8F, 0x3C, 0x5B, 0xD9, 0xF4,
  25751. 0x67, 0xE4, 0x16, 0x20, 0x42, 0x42, 0x43, 0x57,
  25752. 0xDB, 0x92, 0xEF, 0x48, 0x4A, 0x4A, 0x17, 0x98,
  25753. 0xC1, 0x25, 0x7E, 0x87, 0x0A, 0x30, 0xCB, 0x20,
  25754. 0xAA, 0xA0, 0x33, 0x5D, 0x83, 0x31, 0x4F, 0xE0,
  25755. 0xAA, 0x7E, 0x63, 0xA8, 0x62, 0x64, 0x80, 0x41,
  25756. 0xA7, 0x2A, 0x63, 0x21, 0x52, 0x32, 0x20, 0xB1,
  25757. 0xAC, 0xE9, 0xBB, 0x70, 0x1B, 0x21, 0xAC, 0x12,
  25758. 0x53, 0xCB, 0x81, 0x2C, 0x15, 0x57, 0x5A, 0x90,
  25759. 0x85, 0xEA, 0xBE, 0xAD, 0xE7, 0x3A, 0x4A, 0xE7,
  25760. 0x6E, 0x6A, 0x7B, 0x15, 0x8A, 0x20, 0x58, 0x6D,
  25761. 0x78, 0xA5, 0xAC, 0x62, 0x0A, 0x5C, 0x9A, 0xBC,
  25762. 0xC9, 0xC0, 0x43, 0x35, 0x0A, 0x73, 0x65, 0x6B,
  25763. 0x0A, 0xBE, 0x82, 0x2D, 0xA5, 0xE0, 0xBA, 0x76,
  25764. 0x04, 0x5F, 0xAD, 0x75, 0x40, 0x1D, 0x7A, 0x3B,
  25765. 0x70, 0x37, 0x91, 0xB7, 0xE9, 0x92, 0x61, 0x71,
  25766. 0x0F, 0x86, 0xB7, 0x24, 0x21, 0xD2, 0x40, 0xA3,
  25767. 0x47, 0x63, 0x83, 0x77, 0x20, 0x5A, 0x15, 0x2C,
  25768. 0x79, 0x41, 0x30, 0xA4, 0xE0, 0x47, 0x74, 0x2B,
  25769. 0x88, 0x83, 0x03, 0xBD, 0xDC, 0x30, 0x91, 0x16,
  25770. 0x76, 0x4D, 0xE7, 0x42, 0x4C, 0xEB, 0xEA, 0x6D,
  25771. 0xB6, 0x53, 0x48, 0xAC, 0x53, 0x7E, 0x01, 0xA9,
  25772. 0xCC, 0x56, 0xEA, 0x66, 0x7D, 0x5A, 0xA8, 0x7A,
  25773. 0xC9, 0xAA, 0xA4, 0x31, 0x7D, 0x26, 0x2C, 0x10,
  25774. 0x14, 0x30, 0x50, 0xB8, 0xD0, 0x7A, 0x72, 0x8C,
  25775. 0xA6, 0x33, 0xC1, 0x3E, 0x46, 0x8A, 0xBC, 0xEA,
  25776. 0xD3, 0x72, 0xC7, 0x7B, 0x8E, 0xCF, 0x3B, 0x98,
  25777. 0x6B, 0x98, 0xC1, 0xE5, 0x58, 0x60, 0xB2, 0xB4,
  25778. 0x21, 0x67, 0x66, 0xAD, 0x87, 0x4C, 0x35, 0xED,
  25779. 0x72, 0x05, 0x06, 0x87, 0x39, 0x23, 0x02, 0x20,
  25780. 0xB5, 0xA2, 0x31, 0x7D, 0x10, 0x2C, 0x59, 0x83,
  25781. 0x56, 0xF1, 0x68, 0xAC, 0xBE, 0x80, 0x60, 0x8D,
  25782. 0xE4, 0xC9, 0xA7, 0x10, 0xB8, 0xDD, 0x07, 0x07,
  25783. 0x8C, 0xD7, 0xC6, 0x71, 0x05, 0x8A, 0xF1, 0xB0,
  25784. 0xB8, 0x30, 0x4A, 0x31, 0x4F, 0x7B, 0x29, 0xBE,
  25785. 0x78, 0xA9, 0x33, 0xC7, 0xB9, 0x29, 0x44, 0x24,
  25786. 0x95, 0x4A, 0x1B, 0xF8, 0xBC, 0x74, 0x5D, 0xE8,
  25787. 0x61, 0x98, 0x65, 0x9E, 0x0E, 0x12, 0x25, 0xA9,
  25788. 0x10, 0x72, 0x60, 0x74, 0x96, 0x9C, 0x39, 0xA9,
  25789. 0x7C, 0x19, 0x24, 0x06, 0x01, 0xA4, 0x6E, 0x01,
  25790. 0x3D, 0xCD, 0xCB, 0x67, 0x7A, 0x8C, 0xBD, 0x2C,
  25791. 0x95, 0xA4, 0x06, 0x29, 0xC2, 0x56, 0xF2, 0x4A,
  25792. 0x32, 0x89, 0x51, 0xDF, 0x57, 0x50, 0x2A, 0xB3,
  25793. 0x07, 0x72, 0xCC, 0x7E, 0x5B, 0x85, 0x00, 0x27,
  25794. 0xC8, 0x55, 0x17, 0x81, 0xCE, 0x49, 0x85, 0xBD,
  25795. 0xAC, 0xF6, 0xB8, 0x65, 0xC1, 0x04, 0xE8, 0xA4,
  25796. 0xBC, 0x65, 0xC4, 0x16, 0x94, 0xD4, 0x56, 0xB7,
  25797. 0x16, 0x9E, 0x45, 0xAB, 0x3D, 0x7A, 0xCA, 0xBE,
  25798. 0xAF, 0xE2, 0x3A, 0xD6, 0xA7, 0xB9, 0x4D, 0x19,
  25799. 0x79, 0xA2, 0xF4, 0xC1, 0xCA, 0xE7, 0xCD, 0x77,
  25800. 0xD6, 0x81, 0xD2, 0x90, 0xB5, 0xD8, 0xE4, 0x51,
  25801. 0xBF, 0xDC, 0xCC, 0xF5, 0x31, 0x0B, 0x9D, 0x12,
  25802. 0xA8, 0x8E, 0xC2, 0x9B, 0x10, 0x25, 0x5D, 0x5E,
  25803. 0x17, 0xA1, 0x92, 0x67, 0x0A, 0xA9, 0x73, 0x1C,
  25804. 0x5C, 0xA6, 0x7E, 0xC7, 0x84, 0xC5, 0x02, 0x78,
  25805. 0x1B, 0xE8, 0x52, 0x7D, 0x6F, 0xC0, 0x03, 0xC6,
  25806. 0x70, 0x1B, 0x36, 0x32, 0x28, 0x4B, 0x40, 0x30,
  25807. 0x7A, 0x52, 0x7C, 0x76, 0x20, 0x37, 0x7F, 0xEB,
  25808. 0x0B, 0x73, 0xF7, 0x22, 0xC9, 0xE3, 0xCD, 0x4D,
  25809. 0xEC, 0x64, 0x87, 0x6B, 0x93, 0xAB, 0x5B, 0x7C,
  25810. 0xFC, 0x4A, 0x65, 0x7F, 0x85, 0x2B, 0x65, 0x92,
  25811. 0x82, 0x86, 0x43, 0x84, 0xF4, 0x42, 0xB2, 0x2E,
  25812. 0x8A, 0x21, 0x10, 0x93, 0x87, 0xB8, 0xB4, 0x75,
  25813. 0x85, 0xFC, 0x68, 0x0D, 0x0B, 0xA4, 0x5C, 0x7A,
  25814. 0x8B, 0x1D, 0x72, 0x74, 0xBD, 0xA5, 0x78, 0x45,
  25815. 0xD1, 0x00, 0xD0, 0xF4, 0x2A, 0x3B, 0x74, 0x62,
  25816. 0x87, 0x73, 0x35, 0x1F, 0xD7, 0xAC, 0x30, 0x5B,
  25817. 0x24, 0x97, 0x63, 0x9B, 0xE9, 0x0B, 0x3F, 0x4F,
  25818. 0x71, 0xA6, 0xAA, 0x35, 0x61, 0xEE, 0xCC, 0x6A,
  25819. 0x69, 0x1B, 0xB5, 0xCB, 0x39, 0x14, 0xD8, 0x63,
  25820. 0x4C, 0xA1, 0xE1, 0xAF, 0x54, 0x3C, 0x04, 0x9A,
  25821. 0x8C, 0x6E, 0x86, 0x8C, 0x51, 0xF0, 0x42, 0x3B,
  25822. 0xD2, 0xD5, 0xAE, 0x09, 0xB7, 0x9E, 0x57, 0xC2,
  25823. 0x7F, 0x3F, 0xE3, 0xAE, 0x2B, 0x26, 0xA4, 0x41,
  25824. 0xBA, 0xBF, 0xC6, 0x71, 0x8C, 0xE8, 0xC0, 0x5B,
  25825. 0x4F, 0xE7, 0x93, 0xB9, 0x10, 0xB8, 0xFB, 0xCB,
  25826. 0xBE, 0x7F, 0x10, 0x13, 0x24, 0x2B, 0x40, 0xE0,
  25827. 0x51, 0x4D, 0x0B, 0xDC, 0x5C, 0x88, 0xBA, 0xC5,
  25828. 0x94, 0xC7, 0x94, 0xCE, 0x51, 0x22, 0xFB, 0xF3,
  25829. 0x48, 0x96, 0x81, 0x91, 0x47, 0xB9, 0x28, 0x38,
  25830. 0x15, 0x87, 0x96, 0x3B, 0x0B, 0x90, 0x03, 0x4A,
  25831. 0xA0, 0x7A, 0x10, 0xBE, 0x17, 0x6E, 0x01, 0xC8,
  25832. 0x0A, 0xD6, 0xA4, 0xB7, 0x1B, 0x10, 0xAF, 0x42,
  25833. 0x41, 0x40, 0x0A, 0x2A, 0x4C, 0xBB, 0xC0, 0x59,
  25834. 0x61, 0xA1, 0x5E, 0xC1, 0x47, 0x4E, 0xD5, 0x1A,
  25835. 0x3C, 0xC6, 0xD3, 0x58, 0x00, 0x67, 0x9A, 0x46,
  25836. 0x28, 0x09, 0xCA, 0xA3, 0xAB, 0x4F, 0x70, 0x94,
  25837. 0xCD, 0x66, 0x10, 0xB4, 0xA7, 0x00, 0xCB, 0xA9,
  25838. 0x39, 0xE7, 0xEA, 0xC9, 0x3E, 0x38, 0xC9, 0x97,
  25839. 0x55, 0x90, 0x87, 0x27, 0x61, 0x9E, 0xD7, 0x6A,
  25840. 0x34, 0xE5, 0x3C, 0x4F, 0xA2, 0x5B, 0xFC, 0x97,
  25841. 0x00, 0x82, 0x06, 0x69, 0x7D, 0xD1, 0x45, 0xE5,
  25842. 0xB9, 0x18, 0x8E, 0x5B, 0x01, 0x4E, 0x94, 0x16,
  25843. 0x81, 0xE1, 0x5F, 0xE3, 0xE1, 0x32, 0xB8, 0xA3,
  25844. 0x90, 0x34, 0x74, 0x14, 0x8B, 0xA2, 0x8B, 0x98,
  25845. 0x71, 0x11, 0xC9, 0xBC, 0xB3, 0x98, 0x9B, 0xBB,
  25846. 0xC6, 0x71, 0xC5, 0x81, 0xB4, 0x4A, 0x49, 0x28,
  25847. 0x45, 0xF2, 0x88, 0xE6, 0x21, 0x96, 0xE4, 0x71,
  25848. 0xFE, 0xD3, 0xC3, 0x9C, 0x1B, 0xBD, 0xDB, 0x08,
  25849. 0x37, 0xD0, 0xD4, 0x70, 0x6B, 0x09, 0x22, 0xC4
  25850. };
  25851. static const byte seed_768[KYBER_ENC_RAND_SZ] = {
  25852. 0x2C, 0xE7, 0x4A, 0xD2, 0x91, 0x13, 0x35, 0x18,
  25853. 0xFE, 0x60, 0xC7, 0xDF, 0x5D, 0x25, 0x1B, 0x9D,
  25854. 0x82, 0xAD, 0xD4, 0x84, 0x62, 0xFF, 0x50, 0x5C,
  25855. 0x6E, 0x54, 0x7E, 0x94, 0x9E, 0x6B, 0x6B, 0xF7
  25856. };
  25857. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  25858. 0x56, 0xB4, 0x2D, 0x59, 0x3A, 0xAB, 0x8E, 0x87,
  25859. 0x73, 0xBD, 0x92, 0xD7, 0x6E, 0xAB, 0xDD, 0xF3,
  25860. 0xB1, 0x54, 0x6F, 0x83, 0x26, 0xF5, 0x7A, 0x7B,
  25861. 0x77, 0x37, 0x64, 0xB6, 0xC0, 0xDD, 0x30, 0x47,
  25862. 0x0F, 0x68, 0xDF, 0xF8, 0x2E, 0x0D, 0xCA, 0x92,
  25863. 0x50, 0x92, 0x74, 0xEC, 0xFE, 0x83, 0xA9, 0x54,
  25864. 0x73, 0x5F, 0xDE, 0x6E, 0x14, 0x67, 0x6D, 0xAA,
  25865. 0xA3, 0x68, 0x0C, 0x30, 0xD5, 0x24, 0xF4, 0xEF,
  25866. 0xA7, 0x9E, 0xD6, 0xA1, 0xF9, 0xED, 0x7E, 0x1C,
  25867. 0x00, 0x56, 0x0E, 0x86, 0x83, 0x53, 0x8C, 0x31,
  25868. 0x05, 0xAB, 0x93, 0x1B, 0xE0, 0xD2, 0xB2, 0x49,
  25869. 0xB3, 0x8C, 0xB9, 0xB1, 0x3A, 0xF5, 0xCE, 0xAF,
  25870. 0x78, 0x87, 0xA5, 0x9D, 0xBA, 0x16, 0x68, 0x8A,
  25871. 0x7F, 0x28, 0xDE, 0x0B, 0x14, 0xD1, 0x9F, 0x39,
  25872. 0x1E, 0xB4, 0x18, 0x32, 0xA5, 0x64, 0x79, 0x41,
  25873. 0x6C, 0xCF, 0x94, 0xE9, 0x97, 0x39, 0x0E, 0xD7,
  25874. 0x87, 0x8E, 0xEA, 0xFF, 0x49, 0x32, 0x8A, 0x70,
  25875. 0xE0, 0xAB, 0x5F, 0xCE, 0x6C, 0x63, 0xC0, 0x9B,
  25876. 0x35, 0xF4, 0xE4, 0x59, 0x94, 0xDE, 0x61, 0x5B,
  25877. 0x88, 0xBB, 0x72, 0x2F, 0x70, 0xE8, 0x7D, 0x2B,
  25878. 0xBD, 0x72, 0xAE, 0x71, 0xE1, 0xEE, 0x90, 0x08,
  25879. 0xE4, 0x59, 0xD8, 0xE7, 0x43, 0x03, 0x9A, 0x8D,
  25880. 0xDE, 0xB8, 0x74, 0xFC, 0xE5, 0x30, 0x1A, 0x2F,
  25881. 0x8C, 0x0E, 0xE8, 0xC2, 0xFE, 0xE7, 0xA4, 0xEE,
  25882. 0x68, 0xB5, 0xED, 0x6A, 0x6D, 0x9A, 0xB7, 0x4F,
  25883. 0x98, 0xBB, 0x3B, 0xA0, 0xFE, 0x89, 0xE8, 0x2B,
  25884. 0xD5, 0xA5, 0x25, 0xC5, 0xE8, 0x79, 0x0F, 0x81,
  25885. 0x8C, 0xCC, 0x60, 0x58, 0x77, 0xD4, 0x6C, 0x8B,
  25886. 0xDB, 0x5C, 0x33, 0x7B, 0x02, 0x5B, 0xB8, 0x40,
  25887. 0xFF, 0x47, 0x18, 0x96, 0xE4, 0x3B, 0xFA, 0x99,
  25888. 0xD7, 0x3D, 0xBE, 0x31, 0x80, 0x5C, 0x27, 0xA4,
  25889. 0x3E, 0x57, 0xF0, 0x61, 0x8B, 0x3A, 0xE5, 0x22,
  25890. 0xA4, 0x64, 0x4E, 0x0D, 0x4E, 0x4C, 0x1C, 0x54,
  25891. 0x84, 0x89, 0x43, 0x1B, 0xE5, 0x58, 0xF3, 0xBF,
  25892. 0xC5, 0x0E, 0x16, 0x61, 0x7E, 0x11, 0x0D, 0xD7,
  25893. 0xAF, 0x9A, 0x6F, 0xD8, 0x3E, 0x3F, 0xBB, 0x68,
  25894. 0xC3, 0x04, 0xD1, 0x5F, 0x6C, 0xB7, 0x00, 0xD6,
  25895. 0x1D, 0x7A, 0xA9, 0x15, 0xA6, 0x75, 0x1E, 0xA3,
  25896. 0xBA, 0x80, 0x22, 0x3E, 0x65, 0x41, 0x32, 0xA2,
  25897. 0x09, 0x99, 0xA4, 0x3B, 0xF4, 0x08, 0x59, 0x27,
  25898. 0x30, 0xB9, 0xA9, 0x49, 0x96, 0x36, 0xC0, 0x9F,
  25899. 0xA7, 0x29, 0xF9, 0xCB, 0x1F, 0x9D, 0x34, 0x42,
  25900. 0xF4, 0x73, 0x57, 0xA2, 0xB9, 0xCF, 0x15, 0xD3,
  25901. 0x10, 0x3B, 0x9B, 0xF3, 0x96, 0xC2, 0x30, 0x88,
  25902. 0xF1, 0x18, 0xED, 0xE3, 0x46, 0xB5, 0xC0, 0x38,
  25903. 0x91, 0xCF, 0xA5, 0xD5, 0x17, 0xCE, 0xF8, 0x47,
  25904. 0x13, 0x22, 0xE7, 0xE3, 0x10, 0x87, 0xC4, 0xB0,
  25905. 0x36, 0xAB, 0xAD, 0x78, 0x4B, 0xFF, 0x72, 0xA9,
  25906. 0xB1, 0x1F, 0xA1, 0x98, 0xFA, 0xCB, 0xCB, 0x91,
  25907. 0xF0, 0x67, 0xFE, 0xAF, 0x76, 0xFC, 0xFE, 0x53,
  25908. 0x27, 0xC1, 0x07, 0x0B, 0x3D, 0xA6, 0x98, 0x84,
  25909. 0x00, 0x75, 0x67, 0x60, 0xD2, 0xD1, 0xF0, 0x60,
  25910. 0x29, 0x8F, 0x16, 0x83, 0xD5, 0x1E, 0x36, 0x16,
  25911. 0xE9, 0x8C, 0x51, 0xC9, 0xC0, 0x3A, 0xA4, 0x2F,
  25912. 0x2E, 0x63, 0x36, 0x51, 0xA4, 0x7A, 0xD3, 0xCC,
  25913. 0x2A, 0xB4, 0xA8, 0x52, 0xAE, 0x0C, 0x4B, 0x04,
  25914. 0xB4, 0xE1, 0xC3, 0xDD, 0x94, 0x44, 0x45, 0xA2,
  25915. 0xB1, 0x2B, 0x4F, 0x42, 0xA6, 0x43, 0x51, 0x05,
  25916. 0xC0, 0x41, 0x22, 0xFC, 0x35, 0x87, 0xAF, 0xE4,
  25917. 0x09, 0xA0, 0x0B, 0x30, 0x8D, 0x63, 0xC5, 0xDD,
  25918. 0x81, 0x63, 0x65, 0x45, 0x04, 0xEE, 0xDB, 0xB7,
  25919. 0xB5, 0x32, 0x95, 0x77, 0xC3, 0x5F, 0xBE, 0xB3,
  25920. 0xF4, 0x63, 0x87, 0x2C, 0xAC, 0x28, 0x14, 0x2B,
  25921. 0x3C, 0x12, 0xA7, 0x40, 0xEC, 0x6E, 0xA7, 0xCE,
  25922. 0x9A, 0xD7, 0x8C, 0x6F, 0xC8, 0xFE, 0x1B, 0x4D,
  25923. 0xF5, 0xFC, 0x55, 0xC1, 0x66, 0x7F, 0x31, 0xF2,
  25924. 0x31, 0x2D, 0xA0, 0x77, 0x99, 0xDC, 0x87, 0x0A,
  25925. 0x47, 0x86, 0x08, 0x54, 0x9F, 0xED, 0xAF, 0xE0,
  25926. 0x21, 0xF1, 0xCF, 0x29, 0x84, 0x18, 0x03, 0x64,
  25927. 0xE9, 0x0A, 0xD9, 0x8D, 0x84, 0x56, 0x52, 0xAA,
  25928. 0x3C, 0xDD, 0x7A, 0x8E, 0xB0, 0x9F, 0x5E, 0x51,
  25929. 0x42, 0x3F, 0xAB, 0x42, 0xA7, 0xB7, 0xBB, 0x4D,
  25930. 0x51, 0x48, 0x64, 0xBE, 0x8D, 0x71, 0x29, 0x7E,
  25931. 0x9C, 0x3B, 0x17, 0xA9, 0x93, 0xF0, 0xAE, 0x62,
  25932. 0xE8, 0xEF, 0x52, 0x63, 0x7B, 0xD1, 0xB8, 0x85,
  25933. 0xBD, 0x9B, 0x6A, 0xB7, 0x27, 0x85, 0x4D, 0x70,
  25934. 0x3D, 0x8D, 0xC4, 0x78, 0xF9, 0x6C, 0xB8, 0x1F,
  25935. 0xCE, 0x4C, 0x60, 0x38, 0x3A, 0xC0, 0x1F, 0xCF,
  25936. 0x0F, 0x97, 0x1D, 0x4C, 0x8F, 0x35, 0x2B, 0x7A,
  25937. 0x82, 0xE2, 0x18, 0x65, 0x2F, 0x2C, 0x10, 0x6C,
  25938. 0xA9, 0x2A, 0xE6, 0x86, 0xBA, 0xCF, 0xCE, 0xF5,
  25939. 0xD3, 0x27, 0x34, 0x7A, 0x97, 0xA9, 0xB3, 0x75,
  25940. 0xD6, 0x73, 0x41, 0x55, 0x2B, 0xC2, 0xC5, 0x38,
  25941. 0x77, 0x8E, 0x0F, 0x98, 0x01, 0x82, 0x3C, 0xCD,
  25942. 0xFC, 0xD1, 0xEA, 0xAD, 0xED, 0x55, 0xB1, 0x8C,
  25943. 0x97, 0x57, 0xE3, 0xF2, 0x12, 0xB2, 0x88, 0x9D,
  25944. 0x38, 0x57, 0xDB, 0x51, 0xF9, 0x81, 0xD1, 0x61,
  25945. 0x85, 0xFD, 0x0F, 0x90, 0x08, 0x53, 0xA7, 0x50,
  25946. 0x05, 0xE3, 0x02, 0x0A, 0x8B, 0x95, 0xB7, 0xD8,
  25947. 0xF2, 0xF2, 0x63, 0x1C, 0x70, 0xD7, 0x8A, 0x95,
  25948. 0x7C, 0x7A, 0x62, 0xE1, 0xB3, 0x71, 0x90, 0x70,
  25949. 0xAC, 0xD1, 0xFD, 0x48, 0x0C, 0x25, 0xB8, 0x38,
  25950. 0x47, 0xDA, 0x02, 0x7B, 0x6E, 0xBB, 0xC2, 0xEE,
  25951. 0xC2, 0xDF, 0x22, 0xC8, 0x7F, 0x9B, 0x46, 0xD5,
  25952. 0xD7, 0xBA, 0xF1, 0x56, 0xB5, 0x3C, 0xEE, 0x92,
  25953. 0x95, 0x72, 0xB9, 0x2C, 0x47, 0x84, 0xC4, 0xE8,
  25954. 0x29, 0xF3, 0x44, 0x6A, 0x1F, 0xFE, 0x47, 0xF9,
  25955. 0x9D, 0xEC, 0xD0, 0x43, 0x60, 0x29, 0xDD, 0xEB,
  25956. 0xD3, 0xED, 0x8E, 0x87, 0xE5, 0xE7, 0x3D, 0x12,
  25957. 0x3D, 0xBE, 0x8A, 0x4D, 0xDA, 0xCF, 0x2A, 0xBD,
  25958. 0xE8, 0x7F, 0x33, 0xAE, 0x2B, 0x62, 0x1C, 0x0E,
  25959. 0xC5, 0xD5, 0xCA, 0xD1, 0x25, 0x9D, 0xEE, 0xC2,
  25960. 0xAE, 0xFF, 0x60, 0x88, 0xF0, 0x4F, 0x27, 0xA2,
  25961. 0x03, 0x38, 0xB5, 0x76, 0x25, 0x43, 0xE5, 0x10,
  25962. 0x08, 0x99, 0xA4, 0xCB, 0xFB, 0x7B, 0x3C, 0xA4,
  25963. 0x56, 0xB3, 0xA1, 0x9B, 0x83, 0xA4, 0xC4, 0x32,
  25964. 0x23, 0x0C, 0x23, 0xE1, 0xC7, 0xF1, 0x07, 0xC4,
  25965. 0xCB, 0x11, 0x21, 0x52, 0xF1, 0xC0, 0xF3, 0x0D,
  25966. 0xA0, 0xBB, 0x33, 0xF4, 0xF1, 0x1F, 0x47, 0xEE,
  25967. 0xA4, 0x38, 0x72, 0xBA, 0xFA, 0x84, 0xAE, 0x22,
  25968. 0x25, 0x6D, 0x70, 0x8E, 0x06, 0x04, 0xDA, 0xDE,
  25969. 0x4B, 0x2A, 0x4D, 0xDE, 0x8C, 0xCC, 0xF1, 0x19,
  25970. 0x30, 0xE1, 0x35, 0x53, 0x93, 0x4A, 0xE3, 0xEC,
  25971. 0xE5, 0x2F, 0x3D, 0x7C, 0xCC, 0x00, 0x28, 0x73,
  25972. 0x77, 0x87, 0x9F, 0xE6, 0xB8, 0xEC, 0xE7, 0xEF,
  25973. 0x79, 0x42, 0x35, 0x07, 0xC9, 0xDA, 0x33, 0x95,
  25974. 0x59, 0xC2, 0x0D, 0xE1, 0xC5, 0x19, 0x55, 0x99,
  25975. 0x9B, 0xAE, 0x47, 0x40, 0x1D, 0xC3, 0xCD, 0xFA,
  25976. 0xA1, 0xB2, 0x56, 0xD0, 0x9C, 0x7D, 0xB9, 0xFC,
  25977. 0x86, 0x98, 0xBF, 0xCE, 0xFA, 0x73, 0x02, 0xD5,
  25978. 0x6F, 0xBC, 0xDE, 0x1F, 0xBA, 0xAA, 0x1C, 0x65,
  25979. 0x34, 0x54, 0xE6, 0xFD, 0x3D, 0x84, 0xE4, 0xF7,
  25980. 0x9A, 0x93, 0x1C, 0x68, 0x1C, 0xBB, 0x6C, 0xB4,
  25981. 0x62, 0xB1, 0x0D, 0xAE, 0x11, 0x2B, 0xDF, 0xB7,
  25982. 0xF6, 0x5C, 0x7F, 0xDF, 0x6E, 0x5F, 0xC5, 0x94,
  25983. 0xEC, 0x3A, 0x47, 0x4A, 0x94, 0xBD, 0x97, 0xE6,
  25984. 0xEC, 0x81, 0xF7, 0x1C, 0x23, 0x0B, 0xF7, 0x0C,
  25985. 0xA0, 0xF1, 0x3C, 0xE3, 0xDF, 0xFB, 0xD9, 0xFF,
  25986. 0x98, 0x04, 0xEF, 0xD8, 0xF3, 0x7A, 0x4D, 0x36,
  25987. 0x29, 0xB4, 0x3A, 0x8F, 0x55, 0x54, 0x4E, 0xBC,
  25988. 0x5A, 0xC0, 0xAB, 0xD9, 0xA3, 0x3D, 0x79, 0x69,
  25989. 0x90, 0x68, 0x34, 0x6A, 0x0F, 0x1A, 0x3A, 0x96,
  25990. 0xE1, 0x15, 0xA5, 0xD8, 0x0B, 0xE1, 0x65, 0xB5,
  25991. 0x62, 0xD0, 0x82, 0x98, 0x4D, 0x5A, 0xAC, 0xC3,
  25992. 0xA2, 0x30, 0x19, 0x81, 0xA6, 0x41, 0x8F, 0x8B,
  25993. 0xA7, 0xD7, 0xB0, 0xD7, 0xCA, 0x58, 0x75, 0xC6
  25994. };
  25995. static const byte k_768[KYBER_SS_SZ] = {
  25996. 0x26, 0x96, 0xD2, 0x8E, 0x9C, 0x61, 0xC2, 0xA0,
  25997. 0x1C, 0xE9, 0xB1, 0x60, 0x8D, 0xCB, 0x9D, 0x29,
  25998. 0x27, 0x85, 0xA0, 0xCD, 0x58, 0xEF, 0xB7, 0xFE,
  25999. 0x13, 0xB1, 0xDE, 0x95, 0xF0, 0xDB, 0x55, 0xB3
  26000. };
  26001. #endif
  26002. #ifndef WOLFSSL_NO_KYBER1024
  26003. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  26004. 0x30, 0x7A, 0x4C, 0xEA, 0x41, 0x48, 0x21, 0x9B,
  26005. 0x95, 0x8E, 0xA0, 0xB7, 0x88, 0x66, 0x59, 0x23,
  26006. 0x5A, 0x4D, 0x19, 0x80, 0xB1, 0x92, 0x61, 0x08,
  26007. 0x47, 0xD8, 0x6E, 0xF3, 0x27, 0x39, 0xF9, 0x4C,
  26008. 0x3B, 0x44, 0x6C, 0x4D, 0x81, 0xD8, 0x9B, 0x8B,
  26009. 0x42, 0x2A, 0x9D, 0x07, 0x9C, 0x88, 0xB1, 0x1A,
  26010. 0xCA, 0xF3, 0x21, 0xB0, 0x14, 0x29, 0x4E, 0x18,
  26011. 0xB2, 0x96, 0xE5, 0x2F, 0x3F, 0x74, 0x4C, 0xF9,
  26012. 0x63, 0x4A, 0x4F, 0xB0, 0x1D, 0xB0, 0xD9, 0x9E,
  26013. 0xF2, 0x0A, 0x63, 0x3A, 0x55, 0x2E, 0x76, 0xA0,
  26014. 0x58, 0x5C, 0x61, 0x09, 0xF0, 0x18, 0x76, 0x8B,
  26015. 0x76, 0x3A, 0xF3, 0x67, 0x8B, 0x47, 0x80, 0x08,
  26016. 0x9C, 0x13, 0x42, 0xB9, 0x69, 0x07, 0xA2, 0x9A,
  26017. 0x1C, 0x11, 0x52, 0x1C, 0x74, 0x4C, 0x27, 0x97,
  26018. 0xD0, 0xBF, 0x2B, 0x9C, 0xCD, 0xCA, 0x61, 0x46,
  26019. 0x72, 0xB4, 0x50, 0x76, 0x77, 0x3F, 0x45, 0x8A,
  26020. 0x31, 0xEF, 0x86, 0x9B, 0xE1, 0xEB, 0x2E, 0xFE,
  26021. 0xB5, 0x0D, 0x0E, 0x37, 0x49, 0x5D, 0xC5, 0xCA,
  26022. 0x55, 0xE0, 0x75, 0x28, 0x93, 0x4F, 0x62, 0x93,
  26023. 0xC4, 0x16, 0x80, 0x27, 0xD0, 0xE5, 0x3D, 0x07,
  26024. 0xFA, 0xCC, 0x66, 0x30, 0xCB, 0x08, 0x19, 0x7E,
  26025. 0x53, 0xFB, 0x19, 0x3A, 0x17, 0x11, 0x35, 0xDC,
  26026. 0x8A, 0xD9, 0x97, 0x94, 0x02, 0xA7, 0x1B, 0x69,
  26027. 0x26, 0xBC, 0xDC, 0xDC, 0x47, 0xB9, 0x34, 0x01,
  26028. 0x91, 0x0A, 0x5F, 0xCC, 0x1A, 0x81, 0x3B, 0x68,
  26029. 0x2B, 0x09, 0xBA, 0x7A, 0x72, 0xD2, 0x48, 0x6D,
  26030. 0x6C, 0x79, 0x95, 0x16, 0x46, 0x5C, 0x14, 0x72,
  26031. 0x9B, 0x26, 0x94, 0x9B, 0x0B, 0x7C, 0xBC, 0x7C,
  26032. 0x64, 0x0F, 0x26, 0x7F, 0xED, 0x80, 0xB1, 0x62,
  26033. 0xC5, 0x1F, 0xD8, 0xE0, 0x92, 0x27, 0xC1, 0x01,
  26034. 0xD5, 0x05, 0xA8, 0xFA, 0xE8, 0xA2, 0xD7, 0x05,
  26035. 0x4E, 0x28, 0xA7, 0x8B, 0xA8, 0x75, 0x0D, 0xEC,
  26036. 0xF9, 0x05, 0x7C, 0x83, 0x97, 0x9F, 0x7A, 0xBB,
  26037. 0x08, 0x49, 0x45, 0x64, 0x80, 0x06, 0xC5, 0xB2,
  26038. 0x88, 0x04, 0xF3, 0x4E, 0x73, 0xB2, 0x38, 0x11,
  26039. 0x1A, 0x65, 0xA1, 0xF5, 0x00, 0xB1, 0xCC, 0x60,
  26040. 0x6A, 0x84, 0x8F, 0x28, 0x59, 0x07, 0x0B, 0xEB,
  26041. 0xA7, 0x57, 0x31, 0x79, 0xF3, 0x61, 0x49, 0xCF,
  26042. 0x58, 0x01, 0xBF, 0x89, 0xA1, 0xC3, 0x8C, 0xC2,
  26043. 0x78, 0x41, 0x55, 0x28, 0xD0, 0x3B, 0xDB, 0x94,
  26044. 0x3F, 0x96, 0x28, 0x0C, 0x8C, 0xC5, 0x20, 0x42,
  26045. 0xD9, 0xB9, 0x1F, 0xAA, 0x9D, 0x6E, 0xA7, 0xBC,
  26046. 0xBB, 0x7A, 0xB1, 0x89, 0x7A, 0x32, 0x66, 0x96,
  26047. 0x6F, 0x78, 0x39, 0x34, 0x26, 0xC7, 0x6D, 0x8A,
  26048. 0x49, 0x57, 0x8B, 0x98, 0xB1, 0x59, 0xEB, 0xB4,
  26049. 0x6E, 0xE0, 0xA8, 0x83, 0xA2, 0x70, 0xD8, 0x05,
  26050. 0x7C, 0xD0, 0x23, 0x1C, 0x86, 0x90, 0x6A, 0x91,
  26051. 0xDB, 0xBA, 0xDE, 0x6B, 0x24, 0x69, 0x58, 0x1E,
  26052. 0x2B, 0xCA, 0x2F, 0xEA, 0x83, 0x89, 0xF7, 0xC7,
  26053. 0x4B, 0xCD, 0x70, 0x96, 0x1E, 0xA5, 0xB9, 0x34,
  26054. 0xFB, 0xCF, 0x9A, 0x65, 0x90, 0xBF, 0x86, 0xB8,
  26055. 0xDB, 0x54, 0x88, 0x54, 0xD9, 0xA3, 0xFB, 0x30,
  26056. 0x11, 0x04, 0x33, 0xBD, 0x7A, 0x1B, 0x65, 0x9C,
  26057. 0xA8, 0x56, 0x80, 0x85, 0x63, 0x92, 0x37, 0xB3,
  26058. 0xBD, 0xC3, 0x7B, 0x7F, 0xA7, 0x16, 0xD4, 0x82,
  26059. 0xA2, 0x5B, 0x54, 0x10, 0x6B, 0x3A, 0x8F, 0x54,
  26060. 0xD3, 0xAA, 0x99, 0xB5, 0x12, 0x3D, 0xA9, 0x60,
  26061. 0x66, 0x90, 0x45, 0x92, 0xF3, 0xA5, 0x4E, 0xE2,
  26062. 0x3A, 0x79, 0x81, 0xAB, 0x60, 0x8A, 0x2F, 0x44,
  26063. 0x13, 0xCC, 0x65, 0x89, 0x46, 0xC6, 0xD7, 0x78,
  26064. 0x0E, 0xA7, 0x65, 0x64, 0x4B, 0x3C, 0xC0, 0x6C,
  26065. 0x70, 0x03, 0x4A, 0xB4, 0xEB, 0x35, 0x19, 0x12,
  26066. 0xE7, 0x71, 0x5B, 0x56, 0x75, 0x5D, 0x09, 0x02,
  26067. 0x15, 0x71, 0xBF, 0x34, 0x0A, 0xB9, 0x25, 0x98,
  26068. 0xA2, 0x4E, 0x81, 0x18, 0x93, 0x19, 0x5B, 0x96,
  26069. 0xA1, 0x62, 0x9F, 0x80, 0x41, 0xF5, 0x86, 0x58,
  26070. 0x43, 0x15, 0x61, 0xFC, 0x0A, 0xB1, 0x52, 0x92,
  26071. 0xB9, 0x13, 0xEC, 0x47, 0x3F, 0x04, 0x47, 0x9B,
  26072. 0xC1, 0x45, 0xCD, 0x4C, 0x56, 0x3A, 0x28, 0x62,
  26073. 0x35, 0x64, 0x6C, 0xD3, 0x05, 0xA9, 0xBE, 0x10,
  26074. 0x14, 0xE2, 0xC7, 0xB1, 0x30, 0xC3, 0x3E, 0xB7,
  26075. 0x7C, 0xC4, 0xA0, 0xD9, 0x78, 0x6B, 0xD6, 0xBC,
  26076. 0x2A, 0x95, 0x4B, 0xF3, 0x00, 0x57, 0x78, 0xF8,
  26077. 0x91, 0x7C, 0xE1, 0x37, 0x89, 0xBB, 0xB9, 0x62,
  26078. 0x80, 0x78, 0x58, 0xB6, 0x77, 0x31, 0x57, 0x2B,
  26079. 0x6D, 0x3C, 0x9B, 0x4B, 0x52, 0x06, 0xFA, 0xC9,
  26080. 0xA7, 0xC8, 0x96, 0x16, 0x98, 0xD8, 0x83, 0x24,
  26081. 0xA9, 0x15, 0x18, 0x68, 0x99, 0xB2, 0x99, 0x23,
  26082. 0xF0, 0x84, 0x42, 0xA3, 0xD3, 0x86, 0xBD, 0x41,
  26083. 0x6B, 0xCC, 0x9A, 0x10, 0x01, 0x64, 0xC9, 0x30,
  26084. 0xEC, 0x35, 0xEA, 0xFB, 0x6A, 0xB3, 0x58, 0x51,
  26085. 0xB6, 0xC8, 0xCE, 0x63, 0x77, 0x36, 0x6A, 0x17,
  26086. 0x5F, 0x3D, 0x75, 0x29, 0x8C, 0x51, 0x8D, 0x44,
  26087. 0x89, 0x89, 0x33, 0xF5, 0x3D, 0xEE, 0x61, 0x71,
  26088. 0x45, 0x09, 0x33, 0x79, 0xC4, 0x65, 0x9F, 0x68,
  26089. 0x58, 0x3B, 0x2B, 0x28, 0x12, 0x26, 0x66, 0xBE,
  26090. 0xC5, 0x78, 0x38, 0x99, 0x1F, 0xF1, 0x6C, 0x36,
  26091. 0x8D, 0xD2, 0x2C, 0x36, 0xE7, 0x80, 0xC9, 0x1A,
  26092. 0x35, 0x82, 0xE2, 0x5E, 0x19, 0x79, 0x4C, 0x6B,
  26093. 0xF2, 0xAB, 0x42, 0x45, 0x8A, 0x8D, 0xD7, 0x70,
  26094. 0x5D, 0xE2, 0xC2, 0xAA, 0x20, 0xC0, 0x54, 0xE8,
  26095. 0x4B, 0x3E, 0xF3, 0x50, 0x32, 0x79, 0x86, 0x26,
  26096. 0xC2, 0x48, 0x26, 0x32, 0x53, 0xA7, 0x1A, 0x11,
  26097. 0x94, 0x35, 0x71, 0x34, 0x0A, 0x97, 0x8C, 0xD0,
  26098. 0xA6, 0x02, 0xE4, 0x7D, 0xEE, 0x54, 0x0A, 0x88,
  26099. 0x14, 0xBA, 0x06, 0xF3, 0x14, 0x14, 0x79, 0x7C,
  26100. 0xDF, 0x60, 0x49, 0x58, 0x23, 0x61, 0xBB, 0xAB,
  26101. 0xA3, 0x87, 0xA8, 0x3D, 0x89, 0x91, 0x3F, 0xE4,
  26102. 0xC0, 0xC1, 0x12, 0xB9, 0x56, 0x21, 0xA4, 0xBD,
  26103. 0xA8, 0x12, 0x3A, 0x14, 0xD1, 0xA8, 0x42, 0xFB,
  26104. 0x57, 0xB8, 0x3A, 0x4F, 0xBA, 0xF3, 0x3A, 0x8E,
  26105. 0x55, 0x22, 0x38, 0xA5, 0x96, 0xAA, 0xE7, 0xA1,
  26106. 0x50, 0xD7, 0x5D, 0xA6, 0x48, 0xBC, 0x44, 0x64,
  26107. 0x49, 0x77, 0xBA, 0x1F, 0x87, 0xA4, 0xC6, 0x8A,
  26108. 0x8C, 0x4B, 0xD2, 0x45, 0xB7, 0xD0, 0x07, 0x21,
  26109. 0xF7, 0xD6, 0x4E, 0x82, 0x2B, 0x08, 0x5B, 0x90,
  26110. 0x13, 0x12, 0xEC, 0x37, 0xA8, 0x16, 0x98, 0x02,
  26111. 0x16, 0x0C, 0xCE, 0x11, 0x60, 0xF0, 0x10, 0xBE,
  26112. 0x8C, 0xBC, 0xAC, 0xE8, 0xE7, 0xB0, 0x05, 0xD7,
  26113. 0x83, 0x92, 0x34, 0xA7, 0x07, 0x86, 0x83, 0x09,
  26114. 0xD0, 0x37, 0x84, 0xB4, 0x27, 0x3B, 0x1C, 0x8A,
  26115. 0x16, 0x01, 0x33, 0xED, 0x29, 0x81, 0x84, 0x70,
  26116. 0x46, 0x25, 0xF2, 0x9C, 0xFA, 0x08, 0x6D, 0x13,
  26117. 0x26, 0x3E, 0xE5, 0x89, 0x91, 0x23, 0xC5, 0x96,
  26118. 0xBA, 0x78, 0x8E, 0x5C, 0x54, 0xA8, 0xE9, 0xBA,
  26119. 0x82, 0x9B, 0x8A, 0x9D, 0x90, 0x4B, 0xC4, 0xBC,
  26120. 0x0B, 0xBE, 0xA7, 0x6B, 0xC5, 0x3F, 0xF8, 0x11,
  26121. 0x21, 0x45, 0x98, 0x47, 0x2C, 0x9C, 0x20, 0x2B,
  26122. 0x73, 0xEF, 0xF0, 0x35, 0xDC, 0x09, 0x70, 0x3A,
  26123. 0xF7, 0xBF, 0x1B, 0xAB, 0xAA, 0xC7, 0x31, 0x93,
  26124. 0xCB, 0x46, 0x11, 0x7A, 0x7C, 0x94, 0x92, 0xA4,
  26125. 0x3F, 0xC9, 0x57, 0x89, 0xA9, 0x24, 0xC5, 0x91,
  26126. 0x27, 0x87, 0xB2, 0xE2, 0x09, 0x0E, 0xBB, 0xCF,
  26127. 0xD3, 0x79, 0x62, 0x21, 0xF0, 0x6D, 0xEB, 0xF9,
  26128. 0xCF, 0x70, 0xE0, 0x56, 0xB8, 0xB9, 0x16, 0x1D,
  26129. 0x63, 0x47, 0xF4, 0x73, 0x35, 0xF3, 0xE1, 0x77,
  26130. 0x6D, 0xA4, 0xBB, 0x87, 0xC1, 0x5C, 0xC8, 0x26,
  26131. 0x14, 0x6F, 0xF0, 0x24, 0x9A, 0x41, 0x3B, 0x45,
  26132. 0xAA, 0x93, 0xA8, 0x05, 0x19, 0x6E, 0xA4, 0x53,
  26133. 0x11, 0x4B, 0x52, 0x4E, 0x31, 0x0A, 0xED, 0xAA,
  26134. 0x46, 0xE3, 0xB9, 0x96, 0x42, 0x36, 0x87, 0x82,
  26135. 0x56, 0x6D, 0x04, 0x9A, 0x72, 0x6D, 0x6C, 0xCA,
  26136. 0x91, 0x09, 0x93, 0xAE, 0xD6, 0x21, 0xD0, 0x14,
  26137. 0x9E, 0xA5, 0x88, 0xA9, 0xAB, 0xD9, 0x09, 0xDB,
  26138. 0xB6, 0x9A, 0xA2, 0x28, 0x29, 0xD9, 0xB8, 0x3A,
  26139. 0xDA, 0x22, 0x09, 0xA6, 0xC2, 0x65, 0x9F, 0x21,
  26140. 0x69, 0xD6, 0x68, 0xB9, 0x31, 0x48, 0x42, 0xC6,
  26141. 0xE2, 0x2A, 0x74, 0x95, 0x8B, 0x4C, 0x25, 0xBB,
  26142. 0xDC, 0xD2, 0x93, 0xD9, 0x9C, 0xB6, 0x09, 0xD8,
  26143. 0x66, 0x74, 0x9A, 0x48, 0x5D, 0xFB, 0x56, 0x02,
  26144. 0x48, 0x83, 0xCF, 0x54, 0x65, 0xDB, 0xA0, 0x36,
  26145. 0x32, 0x06, 0x58, 0x7F, 0x45, 0x59, 0x7F, 0x89,
  26146. 0x00, 0x2F, 0xB8, 0x60, 0x72, 0x32, 0x13, 0x8E,
  26147. 0x03, 0xB2, 0xA8, 0x94, 0x52, 0x5F, 0x26, 0x53,
  26148. 0x70, 0x05, 0x4B, 0x48, 0x86, 0x36, 0x14, 0x47,
  26149. 0x2B, 0x95, 0xD0, 0xA2, 0x30, 0x34, 0x42, 0xE3,
  26150. 0x78, 0xB0, 0xDD, 0x1C, 0x75, 0xAC, 0xBA, 0xB9,
  26151. 0x71, 0xA9, 0xA8, 0xD1, 0x28, 0x1C, 0x79, 0x61,
  26152. 0x3A, 0xCE, 0xC6, 0x93, 0x3C, 0x37, 0x7B, 0x3C,
  26153. 0x57, 0x8C, 0x2A, 0x61, 0xA1, 0xEC, 0x18, 0x1B,
  26154. 0x10, 0x12, 0x97, 0xA3, 0x7C, 0xC5, 0x19, 0x7B,
  26155. 0x29, 0x42, 0xF6, 0xA0, 0xE4, 0x70, 0x4C, 0x0E,
  26156. 0xC6, 0x35, 0x40, 0x48, 0x1B, 0x9F, 0x15, 0x9D,
  26157. 0xC2, 0x55, 0xB5, 0x9B, 0xB5, 0x5D, 0xF4, 0x96,
  26158. 0xAE, 0x54, 0x21, 0x7B, 0x76, 0x89, 0xBD, 0x51,
  26159. 0xDB, 0xA0, 0x38, 0x3A, 0x3D, 0x72, 0xD8, 0x52,
  26160. 0xFF, 0xCA, 0x76, 0xDF, 0x05, 0xB6, 0x6E, 0xEC,
  26161. 0xCB, 0xD4, 0x7B, 0xC5, 0x30, 0x40, 0x81, 0x76,
  26162. 0x28, 0xC7, 0x1E, 0x36, 0x1D, 0x6A, 0xF8, 0x89,
  26163. 0x08, 0x49, 0x16, 0xB4, 0x08, 0xA4, 0x66, 0xC9,
  26164. 0x6E, 0x70, 0x86, 0xC4, 0xA6, 0x0A, 0x10, 0xFC,
  26165. 0xF7, 0x53, 0x7B, 0xB9, 0x4A, 0xFB, 0xCC, 0x7D,
  26166. 0x43, 0x75, 0x90, 0x91, 0x9C, 0x28, 0x65, 0x0C,
  26167. 0x4F, 0x23, 0x68, 0x25, 0x92, 0x26, 0xA9, 0xBF,
  26168. 0xDA, 0x3A, 0x3A, 0x0B, 0xA1, 0xB5, 0x08, 0x7D,
  26169. 0x9D, 0x76, 0x44, 0x2F, 0xD7, 0x86, 0xC6, 0xF8,
  26170. 0x1C, 0x68, 0xC0, 0x36, 0x0D, 0x71, 0x94, 0xD7,
  26171. 0x07, 0x2C, 0x45, 0x33, 0xAE, 0xA8, 0x6C, 0x2D,
  26172. 0x1F, 0x8C, 0x0A, 0x27, 0x69, 0x60, 0x66, 0xF6,
  26173. 0xCF, 0xD1, 0x10, 0x03, 0xF7, 0x97, 0x27, 0x0B,
  26174. 0x32, 0x38, 0x97, 0x13, 0xCF, 0xFA, 0x09, 0x3D,
  26175. 0x99, 0x1B, 0x63, 0x84, 0x4C, 0x38, 0x5E, 0x72,
  26176. 0x27, 0x7F, 0x16, 0x6F, 0x5A, 0x39, 0x34, 0xD6,
  26177. 0xBB, 0x89, 0xA4, 0x78, 0x8D, 0xE2, 0x83, 0x21,
  26178. 0xDE, 0xFC, 0x74, 0x57, 0xAB, 0x48, 0x4B, 0xD3,
  26179. 0x09, 0x86, 0xDC, 0x1D, 0xAB, 0x30, 0x08, 0xCD,
  26180. 0x7B, 0x22, 0xF6, 0x97, 0x02, 0xFA, 0xBB, 0x9A,
  26181. 0x10, 0x45, 0x40, 0x7D, 0xA4, 0x79, 0x1C, 0x35,
  26182. 0x90, 0xFF, 0x59, 0x9D, 0x81, 0xD6, 0x88, 0xCF,
  26183. 0xA7, 0xCC, 0x12, 0xA6, 0x8C, 0x50, 0xF5, 0x1A,
  26184. 0x10, 0x09, 0x41, 0x1B, 0x44, 0x85, 0x0F, 0x90,
  26185. 0x15, 0xDC, 0x84, 0xA9, 0x3B, 0x17, 0xC7, 0xA2,
  26186. 0x07, 0x55, 0x2C, 0x66, 0x1E, 0xA9, 0x83, 0x8E,
  26187. 0x31, 0xB9, 0x5E, 0xAD, 0x54, 0x62, 0x48, 0xE5,
  26188. 0x6B, 0xE7, 0xA5, 0x13, 0x05, 0x05, 0x26, 0x87,
  26189. 0x71, 0x19, 0x98, 0x80, 0xA1, 0x41, 0x77, 0x1A,
  26190. 0x9E, 0x47, 0xAC, 0xFE, 0xD5, 0x90, 0xCB, 0x3A,
  26191. 0xA7, 0xCB, 0x7C, 0x5F, 0x74, 0x91, 0x1D, 0x89,
  26192. 0x12, 0xC2, 0x9D, 0x62, 0x33, 0xF4, 0xD5, 0x3B,
  26193. 0xC6, 0x41, 0x39, 0xE2, 0xF5, 0x5B, 0xE7, 0x55,
  26194. 0x07, 0xDD, 0x77, 0x86, 0x8E, 0x38, 0x4A, 0xEC,
  26195. 0x58, 0x1F, 0x3F, 0x41, 0x1D, 0xB1, 0xA7, 0x42,
  26196. 0x97, 0x2D, 0x3E, 0xBF, 0xD3, 0x31, 0x5C, 0x84,
  26197. 0xA5, 0xAD, 0x63, 0xA0, 0xE7, 0x5C, 0x8B, 0xCA,
  26198. 0x3E, 0x30, 0x41, 0xE0, 0x5D, 0x90, 0x67, 0xAF,
  26199. 0xF3, 0xB1, 0x24, 0x4F, 0x76, 0x3E, 0x79, 0x83
  26200. };
  26201. static const byte seed_1024[KYBER_ENC_RAND_SZ] = {
  26202. 0x59, 0xC5, 0x15, 0x4C, 0x04, 0xAE, 0x43, 0xAA,
  26203. 0xFF, 0x32, 0x70, 0x0F, 0x08, 0x17, 0x00, 0x38,
  26204. 0x9D, 0x54, 0xBE, 0xC4, 0xC3, 0x7C, 0x08, 0x8B,
  26205. 0x1C, 0x53, 0xF6, 0x62, 0x12, 0xB1, 0x2C, 0x72
  26206. };
  26207. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  26208. 0xE2, 0xD5, 0xFD, 0x4C, 0x13, 0xCE, 0xA0, 0xB5,
  26209. 0x2D, 0x87, 0x4F, 0xEA, 0x90, 0x12, 0xF3, 0xA5,
  26210. 0x17, 0x43, 0xA1, 0x09, 0x37, 0x10, 0xBB, 0xF2,
  26211. 0x39, 0x50, 0xF9, 0x14, 0x7A, 0x47, 0x2E, 0xE5,
  26212. 0x53, 0x39, 0x28, 0xA2, 0xF4, 0x6D, 0x59, 0x2F,
  26213. 0x35, 0xDA, 0x8B, 0x4F, 0x75, 0x8C, 0x89, 0x3B,
  26214. 0x0D, 0x7B, 0x98, 0x94, 0x8B, 0xE4, 0x47, 0xB1,
  26215. 0x7C, 0xB2, 0xAE, 0x58, 0xAF, 0x8A, 0x48, 0x9D,
  26216. 0xDD, 0x92, 0x32, 0xB9, 0x9B, 0x1C, 0x0D, 0x2D,
  26217. 0xE7, 0x7C, 0xAA, 0x47, 0x2B, 0xC3, 0xBB, 0xD4,
  26218. 0xA7, 0xC6, 0x0D, 0xBF, 0xDC, 0xA9, 0x2E, 0xBF,
  26219. 0x3A, 0x1C, 0xE1, 0xC2, 0x2D, 0xAD, 0x13, 0xE8,
  26220. 0x87, 0x00, 0x4E, 0x29, 0x24, 0xFD, 0x22, 0x65,
  26221. 0x6F, 0x5E, 0x50, 0x87, 0x91, 0xDE, 0x06, 0xD8,
  26222. 0x5E, 0x1A, 0x14, 0x26, 0x80, 0x8E, 0xD9, 0xA8,
  26223. 0x9F, 0x6E, 0x2F, 0xD3, 0xC2, 0x45, 0xD4, 0x75,
  26224. 0x8B, 0x22, 0xB0, 0x2C, 0xAD, 0xE3, 0x3B, 0x60,
  26225. 0xFC, 0x88, 0x9A, 0x33, 0xFC, 0x44, 0x47, 0xED,
  26226. 0xEB, 0xBF, 0xD4, 0x53, 0x0D, 0xE8, 0x65, 0x96,
  26227. 0xA3, 0x37, 0x89, 0xD5, 0xDB, 0xA6, 0xE6, 0xEC,
  26228. 0x9F, 0x89, 0x87, 0x9A, 0xF4, 0xBE, 0x49, 0x09,
  26229. 0xA6, 0x90, 0x17, 0xC9, 0xBB, 0x7A, 0x5E, 0x31,
  26230. 0x81, 0x5E, 0xA5, 0xF1, 0x32, 0xEE, 0xC4, 0x98,
  26231. 0x4F, 0xAA, 0x7C, 0xCF, 0x59, 0x4D, 0xD0, 0x0D,
  26232. 0x4D, 0x84, 0x87, 0xE4, 0x56, 0x21, 0xAF, 0x8F,
  26233. 0x6E, 0x33, 0x05, 0x51, 0x43, 0x9C, 0x93, 0xEC,
  26234. 0x07, 0x8A, 0x7A, 0x3C, 0xC1, 0x59, 0x4A, 0xF9,
  26235. 0x1F, 0x84, 0x17, 0x37, 0x5F, 0xD6, 0x08, 0x8C,
  26236. 0xEB, 0x5E, 0x85, 0xC6, 0x70, 0x99, 0x09, 0x1B,
  26237. 0xAC, 0x11, 0x49, 0x8A, 0x0D, 0x71, 0x14, 0x55,
  26238. 0xF5, 0xE0, 0xD9, 0x5C, 0xD7, 0xBB, 0xE5, 0xCD,
  26239. 0xD8, 0xFE, 0xCB, 0x31, 0x9E, 0x68, 0x53, 0xC2,
  26240. 0x3C, 0x9B, 0xE2, 0xC7, 0x63, 0xDF, 0x57, 0x86,
  26241. 0x66, 0xC4, 0x0A, 0x40, 0xA8, 0x74, 0x86, 0xE4,
  26242. 0x6B, 0xA8, 0x71, 0x61, 0x46, 0x19, 0x29, 0x04,
  26243. 0x51, 0x0A, 0x6D, 0xC5, 0x9D, 0xA8, 0x02, 0x58,
  26244. 0x25, 0x28, 0x3D, 0x68, 0x4D, 0xB9, 0x14, 0x10,
  26245. 0xB4, 0xF1, 0x2C, 0x6D, 0x8F, 0xBD, 0x0A, 0xDD,
  26246. 0x75, 0xD3, 0x09, 0x89, 0x18, 0xCB, 0x04, 0xAC,
  26247. 0x7B, 0xC4, 0xDB, 0x0D, 0x6B, 0xCD, 0xF1, 0x19,
  26248. 0x4D, 0xD8, 0x62, 0x92, 0xE0, 0x5B, 0x7B, 0x86,
  26249. 0x30, 0x62, 0x5B, 0x58, 0x9C, 0xC5, 0x09, 0xD2,
  26250. 0x15, 0xBB, 0xD0, 0x6A, 0x2E, 0x7C, 0x66, 0xF4,
  26251. 0x24, 0xCD, 0xF8, 0xC4, 0x0A, 0xC6, 0xC1, 0xE5,
  26252. 0xAE, 0x6C, 0x96, 0x4B, 0x7D, 0x9E, 0x92, 0xF9,
  26253. 0x5F, 0xC5, 0xC8, 0x85, 0x22, 0x81, 0x62, 0x8B,
  26254. 0x81, 0xB9, 0xAF, 0xAB, 0xC7, 0xF0, 0x3B, 0xE3,
  26255. 0xF6, 0x2E, 0x80, 0x47, 0xBB, 0x88, 0xD0, 0x1C,
  26256. 0x68, 0x68, 0x7B, 0x8D, 0xD4, 0xFE, 0x63, 0x82,
  26257. 0x00, 0x62, 0xB6, 0x78, 0x8A, 0x53, 0x72, 0x90,
  26258. 0x53, 0x82, 0x6E, 0xD3, 0xB7, 0xC7, 0xEF, 0x82,
  26259. 0x41, 0xE1, 0x9C, 0x85, 0x11, 0x7B, 0x3C, 0x53,
  26260. 0x41, 0x88, 0x1D, 0x4F, 0x29, 0x9E, 0x50, 0x37,
  26261. 0x4C, 0x8E, 0xEF, 0xD5, 0x56, 0x0B, 0xD1, 0x83,
  26262. 0x19, 0xA7, 0x96, 0x3A, 0x3D, 0x02, 0xF0, 0xFB,
  26263. 0xE8, 0x4B, 0xC4, 0x84, 0xB5, 0xA4, 0x01, 0x8B,
  26264. 0x97, 0xD2, 0x74, 0x19, 0x1C, 0x95, 0xF7, 0x02,
  26265. 0xBA, 0xB9, 0xB0, 0xD1, 0x05, 0xFA, 0xF9, 0xFD,
  26266. 0xCF, 0xF9, 0x7E, 0x43, 0x72, 0x36, 0x56, 0x75,
  26267. 0x99, 0xFA, 0xF7, 0x3B, 0x07, 0x5D, 0x40, 0x61,
  26268. 0x04, 0xD4, 0x03, 0xCD, 0xF8, 0x12, 0x24, 0xDA,
  26269. 0x59, 0x0B, 0xEC, 0x28, 0x97, 0xE3, 0x01, 0x09,
  26270. 0xE1, 0xF2, 0xE5, 0xAE, 0x46, 0x10, 0xC8, 0x09,
  26271. 0xA7, 0x3F, 0x63, 0x8C, 0x84, 0x21, 0x0B, 0x34,
  26272. 0x47, 0xA7, 0xC8, 0xB6, 0xDD, 0xDB, 0x5A, 0xE2,
  26273. 0x00, 0xBF, 0x20, 0xE2, 0xFE, 0x4D, 0x4B, 0xA6,
  26274. 0xC6, 0xB1, 0x27, 0x67, 0xFB, 0x87, 0x60, 0xF6,
  26275. 0x6C, 0x51, 0x18, 0xE7, 0xA9, 0x93, 0x5B, 0x41,
  26276. 0xC9, 0xA4, 0x71, 0xA1, 0xD3, 0x23, 0x76, 0x88,
  26277. 0xC1, 0xE6, 0x18, 0xCC, 0x3B, 0xE9, 0x36, 0xAA,
  26278. 0x3F, 0x5E, 0x44, 0xE0, 0x86, 0x82, 0x0B, 0x81,
  26279. 0x0E, 0x06, 0x32, 0x11, 0xFC, 0x21, 0xC4, 0x04,
  26280. 0x4B, 0x3A, 0xC4, 0xD0, 0x0D, 0xF1, 0xBC, 0xC7,
  26281. 0xB2, 0x4D, 0xC0, 0x7B, 0xA4, 0x8B, 0x23, 0xB0,
  26282. 0xFC, 0x12, 0xA3, 0xED, 0x3D, 0x0A, 0x5C, 0xF7,
  26283. 0x67, 0x14, 0x15, 0xAB, 0x9C, 0xF2, 0x12, 0x86,
  26284. 0xFE, 0x63, 0xFB, 0x41, 0x41, 0x85, 0x70, 0x55,
  26285. 0x5D, 0x47, 0x39, 0xB8, 0x81, 0x04, 0xA8, 0x59,
  26286. 0x3F, 0x29, 0x30, 0x25, 0xA4, 0xE3, 0xEE, 0x7C,
  26287. 0x67, 0xE4, 0xB4, 0x8E, 0x40, 0xF6, 0xBA, 0x8C,
  26288. 0x09, 0x86, 0x0C, 0x3F, 0xBB, 0xE5, 0x5D, 0x45,
  26289. 0xB4, 0x5F, 0xC9, 0xAB, 0x62, 0x9B, 0x17, 0xC2,
  26290. 0x76, 0xC9, 0xC9, 0xE2, 0xAF, 0x3A, 0x04, 0x3B,
  26291. 0xEA, 0xFC, 0x18, 0xFD, 0x4F, 0x25, 0xEE, 0x7F,
  26292. 0x83, 0xBD, 0xDC, 0xD2, 0xD9, 0x39, 0x14, 0xB7,
  26293. 0xED, 0x4F, 0x7C, 0x9A, 0xF1, 0x27, 0xF3, 0xF1,
  26294. 0x5C, 0x27, 0x7B, 0xE1, 0x65, 0x51, 0xFE, 0xF3,
  26295. 0xAE, 0x03, 0xD7, 0xB9, 0x14, 0x3F, 0x0C, 0x9C,
  26296. 0x01, 0x9A, 0xB9, 0x7E, 0xEA, 0x07, 0x63, 0x66,
  26297. 0x13, 0x1F, 0x51, 0x83, 0x63, 0x71, 0x1B, 0x34,
  26298. 0xE9, 0x6D, 0x3F, 0x8A, 0x51, 0x3F, 0x3E, 0x20,
  26299. 0xB1, 0xD4, 0x52, 0xC4, 0xB7, 0xAE, 0x3B, 0x97,
  26300. 0x5E, 0xA9, 0x4D, 0x88, 0x0D, 0xAC, 0x66, 0x93,
  26301. 0x39, 0x97, 0x50, 0xD0, 0x22, 0x20, 0x40, 0x3F,
  26302. 0x0D, 0x3E, 0x3F, 0xC1, 0x17, 0x2A, 0x4D, 0xE9,
  26303. 0xDC, 0x28, 0x0E, 0xAF, 0x0F, 0xEE, 0x28, 0x83,
  26304. 0xA6, 0x66, 0x0B, 0xF5, 0xA3, 0xD2, 0x46, 0xFF,
  26305. 0x41, 0xD2, 0x1B, 0x36, 0xEA, 0x52, 0x1C, 0xF7,
  26306. 0xAA, 0x68, 0x9F, 0x80, 0x0D, 0x0F, 0x86, 0xF4,
  26307. 0xFA, 0x10, 0x57, 0xD8, 0xA1, 0x3F, 0x9D, 0xA8,
  26308. 0xFF, 0xFD, 0x0D, 0xC1, 0xFA, 0xD3, 0xC0, 0x4B,
  26309. 0xB1, 0xCC, 0xCB, 0x7C, 0x83, 0x4D, 0xB0, 0x51,
  26310. 0xA7, 0xAC, 0x2E, 0x4C, 0x60, 0x30, 0x19, 0x96,
  26311. 0xC9, 0x30, 0x71, 0xEA, 0x41, 0x6B, 0x42, 0x17,
  26312. 0x59, 0x93, 0x56, 0x59, 0xCF, 0x62, 0xCA, 0x5F,
  26313. 0x13, 0xAE, 0x07, 0xC3, 0xB1, 0x95, 0xC1, 0x48,
  26314. 0x15, 0x9D, 0x8B, 0xEB, 0x03, 0xD4, 0x40, 0xB0,
  26315. 0x0F, 0x53, 0x05, 0x76, 0x5F, 0x20, 0xC0, 0xC4,
  26316. 0x6E, 0xEE, 0x59, 0xC6, 0xD1, 0x62, 0x06, 0x40,
  26317. 0x2D, 0xB1, 0xC7, 0x15, 0xE8, 0x88, 0xBD, 0xE5,
  26318. 0x9C, 0x78, 0x1F, 0x35, 0xA7, 0xCC, 0x7C, 0x1C,
  26319. 0x5E, 0xCB, 0x21, 0x55, 0xAE, 0x3E, 0x95, 0x9C,
  26320. 0x09, 0x64, 0xCC, 0x1E, 0xF8, 0xD7, 0xC6, 0x9D,
  26321. 0x14, 0x58, 0xA9, 0xA4, 0x2F, 0x95, 0xF4, 0xC6,
  26322. 0xB5, 0xB9, 0x96, 0x34, 0x57, 0x12, 0xAA, 0x29,
  26323. 0x0F, 0xBB, 0xF7, 0xDF, 0xD4, 0xA6, 0xE8, 0x64,
  26324. 0x63, 0x02, 0x2A, 0x3F, 0x47, 0x25, 0xF6, 0x51,
  26325. 0x1B, 0xF7, 0xEA, 0x5E, 0x95, 0xC7, 0x07, 0xCD,
  26326. 0x35, 0x73, 0x60, 0x9A, 0xAD, 0xEA, 0xF5, 0x40,
  26327. 0x15, 0x2C, 0x49, 0x5F, 0x37, 0xFE, 0x6E, 0xC8,
  26328. 0xBB, 0x9F, 0xA2, 0xAA, 0x61, 0xD1, 0x57, 0x35,
  26329. 0x93, 0x4F, 0x47, 0x37, 0x92, 0x8F, 0xDE, 0x90,
  26330. 0xBA, 0x99, 0x57, 0x22, 0x46, 0x5D, 0x4A, 0x64,
  26331. 0x50, 0x5A, 0x52, 0x01, 0xF0, 0x7A, 0xA5, 0x8C,
  26332. 0xFD, 0x8A, 0xE2, 0x26, 0xE0, 0x20, 0x70, 0xB2,
  26333. 0xDB, 0xF5, 0x12, 0xB9, 0x75, 0x31, 0x9A, 0x7E,
  26334. 0x87, 0x53, 0xB4, 0xFD, 0xAE, 0x0E, 0xB4, 0x92,
  26335. 0x28, 0x69, 0xCC, 0x8E, 0x25, 0xC4, 0xA5, 0x56,
  26336. 0x0C, 0x2A, 0x06, 0x85, 0xDE, 0x3A, 0xC3, 0x92,
  26337. 0xA8, 0x92, 0x5B, 0xA8, 0x82, 0x00, 0x48, 0x94,
  26338. 0x74, 0x2E, 0x43, 0xCC, 0xFC, 0x27, 0x74, 0x39,
  26339. 0xEC, 0x80, 0x50, 0xA9, 0xAE, 0xB4, 0x29, 0x32,
  26340. 0xE0, 0x1C, 0x84, 0x0D, 0xFC, 0xED, 0xCC, 0x34,
  26341. 0xD3, 0x99, 0x12, 0x89, 0xA6, 0x2C, 0x17, 0xD1,
  26342. 0x28, 0x4C, 0x83, 0x95, 0x14, 0xB9, 0x33, 0x51,
  26343. 0xDB, 0xB2, 0xDD, 0xA8, 0x1F, 0x92, 0x45, 0x65,
  26344. 0xD7, 0x0E, 0x70, 0x79, 0xD5, 0xB8, 0x12, 0x6C,
  26345. 0xAA, 0xB7, 0xA4, 0xA1, 0xC7, 0x31, 0x65, 0x5A,
  26346. 0x53, 0xBC, 0xC0, 0x9F, 0x5D, 0x63, 0xEC, 0x90,
  26347. 0x86, 0xDE, 0xA6, 0x50, 0x05, 0x59, 0x85, 0xED,
  26348. 0xFA, 0x82, 0x97, 0xD9, 0xC9, 0x54, 0x10, 0xC5,
  26349. 0xD1, 0x89, 0x4D, 0x17, 0xD5, 0x93, 0x05, 0x49,
  26350. 0xAD, 0xBC, 0x2B, 0x87, 0x33, 0xC9, 0x9F, 0xE6,
  26351. 0x2E, 0x17, 0xC4, 0xDE, 0x34, 0xA5, 0xD8, 0x9B,
  26352. 0x12, 0xD1, 0x8E, 0x42, 0xA4, 0x22, 0xD2, 0xCE,
  26353. 0x77, 0x9C, 0x2C, 0x28, 0xEB, 0x2D, 0x98, 0x00,
  26354. 0x3D, 0x5C, 0xD3, 0x23, 0xFC, 0xBE, 0xCF, 0x02,
  26355. 0xB5, 0x06, 0x6E, 0x0E, 0x73, 0x48, 0x10, 0xF0,
  26356. 0x9E, 0xD8, 0x90, 0x13, 0xC0, 0x0F, 0x01, 0x1B,
  26357. 0xD2, 0x20, 0xF2, 0xE5, 0xD6, 0xA3, 0x62, 0xDF,
  26358. 0x90, 0x59, 0x91, 0x98, 0xA0, 0x93, 0xB0, 0x3C,
  26359. 0x8D, 0x8E, 0xFB, 0xFE, 0x0B, 0x61, 0x75, 0x92,
  26360. 0xFA, 0xF1, 0xE6, 0x42, 0x20, 0xC4, 0x44, 0x0B,
  26361. 0x53, 0xFF, 0xB4, 0x71, 0x64, 0xF3, 0x69, 0xC9,
  26362. 0x52, 0x90, 0xBA, 0x9F, 0x31, 0x08, 0xD6, 0x86,
  26363. 0xC5, 0x7D, 0xB6, 0x45, 0xC5, 0x3C, 0x01, 0x2E,
  26364. 0x57, 0xAF, 0x25, 0xBD, 0x66, 0x93, 0xE2, 0xCC,
  26365. 0x6B, 0x57, 0x65, 0x1A, 0xF1, 0x59, 0x1F, 0xE5,
  26366. 0xD8, 0x91, 0x66, 0x40, 0xEC, 0x01, 0x7C, 0x25,
  26367. 0x3D, 0xF0, 0x60, 0x6B, 0xB6, 0xB3, 0x03, 0x5F,
  26368. 0xAE, 0x74, 0x8F, 0x3D, 0x40, 0x34, 0x22, 0x3B,
  26369. 0x1B, 0x5E, 0xFB, 0xF5, 0x28, 0x3E, 0x77, 0x8C,
  26370. 0x10, 0x94, 0x29, 0x1C, 0xF7, 0xB1, 0x9B, 0xE0,
  26371. 0xF3, 0x17, 0x35, 0x0E, 0x6F, 0x85, 0x18, 0xFD,
  26372. 0xE0, 0xEF, 0xB1, 0x38, 0x1F, 0xB6, 0xE1, 0x6C,
  26373. 0x24, 0x1F, 0x7F, 0x17, 0xA5, 0x21, 0x06, 0x93,
  26374. 0xA2, 0x74, 0x15, 0x9E, 0x7F, 0xAC, 0x86, 0x8C,
  26375. 0xD0, 0xDC, 0x43, 0x59, 0xC3, 0xD9, 0xEE, 0xFE,
  26376. 0xA0, 0xD9, 0xE3, 0x1E, 0x43, 0xFA, 0x65, 0x13,
  26377. 0x92, 0xC6, 0x5A, 0x54, 0x3A, 0x59, 0xB3, 0xEE,
  26378. 0xE3, 0xA6, 0x39, 0xDC, 0x94, 0x17, 0xD0, 0x56,
  26379. 0xA5, 0xFF, 0x0F, 0x16, 0x0B, 0xEE, 0xE2, 0xEA,
  26380. 0xC2, 0x9A, 0x7D, 0x88, 0xC0, 0x98, 0x2C, 0xF7,
  26381. 0x0B, 0x5A, 0x46, 0x37, 0x9F, 0x21, 0xE5, 0x06,
  26382. 0xAA, 0xC6, 0x1A, 0x9B, 0xB1, 0xB8, 0xC2, 0xB9,
  26383. 0xDA, 0xB0, 0xE4, 0x4A, 0x82, 0x3B, 0x61, 0xD0,
  26384. 0xAA, 0x11, 0xD9, 0x4F, 0x76, 0xA4, 0xA8, 0xE2,
  26385. 0x1F, 0x9D, 0x42, 0x80, 0x68, 0x32, 0x08, 0xF4,
  26386. 0xEA, 0x91, 0x11, 0x16, 0xF6, 0xFD, 0x6A, 0x97,
  26387. 0x42, 0x69, 0x34, 0xEC, 0x34, 0x26, 0xB8, 0xC8,
  26388. 0xF7, 0x03, 0xDA, 0x85, 0xE9, 0xDC, 0xF9, 0x93,
  26389. 0x36, 0x13, 0x60, 0x03, 0x72, 0x8B, 0x8E, 0xCD,
  26390. 0xD0, 0x4A, 0x38, 0x9F, 0x6A, 0x81, 0x7A, 0x78,
  26391. 0xBF, 0xA6, 0x1B, 0xA4, 0x60, 0x20, 0xBF, 0x3C,
  26392. 0x34, 0x82, 0x95, 0x08, 0xF9, 0xD0, 0x6D, 0x15,
  26393. 0x53, 0xCD, 0x98, 0x7A, 0xAC, 0x38, 0x0D, 0x86,
  26394. 0xF1, 0x68, 0x84, 0x3B, 0xA3, 0x90, 0x4D, 0xE5,
  26395. 0xF7, 0x05, 0x8A, 0x41, 0xB4, 0xCD, 0x38, 0x8B,
  26396. 0xC9, 0xCE, 0x3A, 0xBA, 0x7E, 0xE7, 0x13, 0x9B,
  26397. 0x7F, 0xC9, 0xE5, 0xB8, 0xCF, 0xAA, 0xA3, 0x89,
  26398. 0x90, 0xBD, 0x4A, 0x5D, 0xB3, 0x2E, 0x26, 0x13,
  26399. 0xE7, 0xEC, 0x4F, 0x5F, 0x8B, 0x12, 0x92, 0xA3,
  26400. 0x8C, 0x6F, 0x4F, 0xF5, 0xA4, 0x04, 0x90, 0xD7,
  26401. 0x6B, 0x12, 0x66, 0x52, 0xFC, 0xF8, 0x6E, 0x24,
  26402. 0x52, 0x35, 0xD6, 0x36, 0xC6, 0x5C, 0xD1, 0x02,
  26403. 0xB0, 0x1E, 0x22, 0x78, 0x1A, 0x72, 0x91, 0x8C
  26404. };
  26405. static const byte k_1024[KYBER_SS_SZ] = {
  26406. 0x72, 0x64, 0xBD, 0xE5, 0xC6, 0xCE, 0xC1, 0x48,
  26407. 0x49, 0x69, 0x3E, 0x2C, 0x3C, 0x86, 0xE4, 0x8F,
  26408. 0x80, 0x95, 0x8A, 0x4F, 0x61, 0x86, 0xFC, 0x69,
  26409. 0x33, 0x3A, 0x41, 0x48, 0xE6, 0xE4, 0x97, 0xF3
  26410. };
  26411. #endif
  26412. static byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  26413. static byte ss[KYBER_SS_SZ];
  26414. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26415. ExpectNotNull(key);
  26416. if (key != NULL) {
  26417. XMEMSET(key, 0, sizeof(KyberKey));
  26418. }
  26419. #ifndef WOLFSSL_NO_KYBER512
  26420. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  26421. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
  26422. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_512,
  26423. sizeof(seed_512)), 0);
  26424. ExpectIntEQ(XMEMCMP(ct, c_512, KYBER512_CIPHER_TEXT_SIZE), 0);
  26425. ExpectIntEQ(XMEMCMP(ss, k_512, KYBER_SS_SZ), 0);
  26426. wc_KyberKey_Free(key);
  26427. #endif
  26428. #ifndef WOLFSSL_NO_KYBER768
  26429. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  26430. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
  26431. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_768,
  26432. sizeof(seed_768)), 0);
  26433. ExpectIntEQ(XMEMCMP(ct, c_768, KYBER768_CIPHER_TEXT_SIZE), 0);
  26434. ExpectIntEQ(XMEMCMP(ss, k_768, KYBER_SS_SZ), 0);
  26435. wc_KyberKey_Free(key);
  26436. #endif
  26437. #ifndef WOLFSSL_NO_KYBER1024
  26438. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  26439. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
  26440. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
  26441. sizeof(seed_1024)), 0);
  26442. ExpectIntEQ(XMEMCMP(ct, c_1024, KYBER1024_CIPHER_TEXT_SIZE), 0);
  26443. ExpectIntEQ(XMEMCMP(ss, k_1024, KYBER_SS_SZ), 0);
  26444. wc_KyberKey_Free(key);
  26445. #endif
  26446. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26447. #endif
  26448. return EXPECT_RESULT();
  26449. }
  26450. static int test_wc_kyber_decapsulate_kats(void)
  26451. {
  26452. EXPECT_DECLS;
  26453. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  26454. !defined(WOLFSSL_KYBER_ORIGINAL)
  26455. KyberKey* key;
  26456. #ifndef WOLFSSL_NO_KYBER512
  26457. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  26458. 0x69, 0xF9, 0xCB, 0xFD, 0x12, 0x37, 0xBA, 0x16,
  26459. 0x1C, 0xF6, 0xE6, 0xC1, 0x8F, 0x48, 0x8F, 0xC6,
  26460. 0xE3, 0x9A, 0xB4, 0xA5, 0xC9, 0xE6, 0xC2, 0x2E,
  26461. 0xA4, 0xE3, 0xAD, 0x8F, 0x26, 0x7A, 0x9C, 0x44,
  26462. 0x20, 0x10, 0xD3, 0x2E, 0x61, 0xF8, 0x3E, 0x6B,
  26463. 0xFA, 0x5C, 0x58, 0x70, 0x61, 0x45, 0x37, 0x6D,
  26464. 0xBB, 0x84, 0x95, 0x28, 0xF6, 0x80, 0x07, 0xC8,
  26465. 0x22, 0xB3, 0x3A, 0x95, 0xB8, 0x49, 0x04, 0xDC,
  26466. 0xD2, 0x70, 0x8D, 0x03, 0x40, 0xC8, 0xB8, 0x08,
  26467. 0xBC, 0xD3, 0xAA, 0xD0, 0xE4, 0x8B, 0x85, 0x84,
  26468. 0x95, 0x83, 0xA1, 0xB4, 0xE5, 0x94, 0x5D, 0xD9,
  26469. 0x51, 0x4A, 0x7F, 0x64, 0x61, 0xE0, 0x57, 0xB7,
  26470. 0xEC, 0xF6, 0x19, 0x57, 0xE9, 0x7C, 0xF6, 0x28,
  26471. 0x15, 0xF9, 0xC3, 0x22, 0x94, 0xB3, 0x26, 0xE1,
  26472. 0xA1, 0xC4, 0xE3, 0x60, 0xB9, 0x49, 0x8B, 0xA8,
  26473. 0x0F, 0x8C, 0xA9, 0x15, 0x32, 0xB1, 0x71, 0xD0,
  26474. 0xAE, 0xFC, 0x48, 0x49, 0xFA, 0x53, 0xBC, 0x61,
  26475. 0x79, 0x32, 0xE2, 0x08, 0xA6, 0x77, 0xC6, 0x04,
  26476. 0x4A, 0x66, 0x00, 0xB8, 0xD8, 0xB8, 0x3F, 0x26,
  26477. 0xA7, 0x47, 0xB1, 0x8C, 0xFB, 0x78, 0xBE, 0xAF,
  26478. 0xC5, 0x51, 0xAD, 0x52, 0xB7, 0xCA, 0x6C, 0xB8,
  26479. 0x8F, 0x3B, 0x5D, 0x9C, 0xE2, 0xAF, 0x6C, 0x67,
  26480. 0x95, 0x6C, 0x47, 0x8C, 0xEF, 0x49, 0x1F, 0x59,
  26481. 0xE0, 0x19, 0x1B, 0x3B, 0xBE, 0x92, 0x9B, 0x94,
  26482. 0xB6, 0x66, 0xC1, 0x76, 0x13, 0x8B, 0x00, 0xF4,
  26483. 0x97, 0x24, 0x34, 0x1E, 0xE2, 0xE1, 0x64, 0xB9,
  26484. 0x4C, 0x05, 0x3C, 0x18, 0x5A, 0x51, 0xF9, 0x3E,
  26485. 0x00, 0xF3, 0x68, 0x61, 0x61, 0x3A, 0x7F, 0xD7,
  26486. 0x2F, 0xEB, 0xD2, 0x3A, 0x8B, 0x96, 0xA2, 0x60,
  26487. 0x23, 0x42, 0x39, 0xC9, 0x62, 0x8F, 0x99, 0x5D,
  26488. 0xC1, 0x38, 0x07, 0xB4, 0x3A, 0x69, 0x46, 0x81,
  26489. 0x67, 0xCB, 0x1A, 0x8F, 0x9D, 0xD0, 0x7E, 0xE3,
  26490. 0xB3, 0x32, 0x38, 0xF6, 0x30, 0x96, 0xEB, 0xC4,
  26491. 0x9D, 0x50, 0x51, 0xC4, 0xB6, 0x59, 0x63, 0xD7,
  26492. 0x4A, 0x47, 0x66, 0xC2, 0x26, 0xF0, 0xB9, 0x4F,
  26493. 0x18, 0x62, 0xC2, 0x12, 0x4C, 0x8C, 0x74, 0x97,
  26494. 0x48, 0xC0, 0xBC, 0x4D, 0xC1, 0x4C, 0xB3, 0x49,
  26495. 0x06, 0xB8, 0x1C, 0x55, 0x24, 0xFB, 0x81, 0x00,
  26496. 0x79, 0x85, 0x42, 0xDC, 0x6C, 0xC2, 0xAA, 0x0A,
  26497. 0x70, 0x85, 0x75, 0xEA, 0xBC, 0xC1, 0x1F, 0x96,
  26498. 0xA9, 0xE6, 0x1C, 0x01, 0x7A, 0x96, 0xA7, 0xCE,
  26499. 0x93, 0xC4, 0x20, 0x91, 0x73, 0x71, 0x13, 0xAE,
  26500. 0x78, 0x3C, 0x0A, 0xE8, 0x75, 0x5E, 0x59, 0x41,
  26501. 0x11, 0xED, 0xFA, 0xBF, 0xD8, 0x6C, 0x32, 0x12,
  26502. 0xC6, 0x12, 0xA7, 0xB6, 0x2A, 0xFD, 0x3C, 0x7A,
  26503. 0x5C, 0x78, 0xB2, 0xF0, 0x73, 0x44, 0xB7, 0x89,
  26504. 0xC2, 0xB2, 0xDB, 0xB5, 0xF4, 0x44, 0x8B, 0xE9,
  26505. 0x7B, 0xBA, 0x42, 0x33, 0xC0, 0x03, 0x9C, 0x0F,
  26506. 0xE8, 0x43, 0x00, 0xF9, 0xB0, 0x3A, 0xC9, 0x94,
  26507. 0x97, 0xE6, 0xD4, 0x6B, 0x6E, 0x95, 0x30, 0x8F,
  26508. 0xF8, 0x47, 0x90, 0xF6, 0x12, 0xCF, 0x18, 0x6E,
  26509. 0xC1, 0x68, 0x11, 0xE8, 0x0C, 0x17, 0x93, 0x16,
  26510. 0xA6, 0x3B, 0x25, 0x70, 0x3F, 0x60, 0xB8, 0x42,
  26511. 0xB6, 0x19, 0x07, 0xE6, 0x28, 0x94, 0xE7, 0x36,
  26512. 0x64, 0x7B, 0x3C, 0x09, 0xDA, 0x6F, 0xEC, 0x59,
  26513. 0x32, 0x78, 0x2B, 0x36, 0xE0, 0x63, 0x50, 0x85,
  26514. 0xA3, 0x94, 0x9E, 0x69, 0x4D, 0x7E, 0x17, 0xCB,
  26515. 0xA3, 0xD9, 0x06, 0x43, 0x30, 0x43, 0x8C, 0x07,
  26516. 0x1B, 0x58, 0x36, 0xA7, 0x70, 0xC5, 0x5F, 0x62,
  26517. 0x13, 0xCC, 0x14, 0x25, 0x84, 0x5D, 0xE5, 0xA3,
  26518. 0x34, 0xD7, 0x5D, 0x3E, 0x50, 0x58, 0xC7, 0x80,
  26519. 0x9F, 0xDA, 0x4B, 0xCD, 0x78, 0x19, 0x1D, 0xA9,
  26520. 0x79, 0x73, 0x25, 0xE6, 0x23, 0x6C, 0x26, 0x50,
  26521. 0xFC, 0x60, 0x4E, 0xE4, 0x3A, 0x83, 0xCE, 0xB3,
  26522. 0x49, 0x80, 0x08, 0x44, 0x03, 0xA3, 0x32, 0x59,
  26523. 0x85, 0x79, 0x07, 0x79, 0x9A, 0x9D, 0x2A, 0x71,
  26524. 0x3A, 0x63, 0x3B, 0x5C, 0x90, 0x47, 0x27, 0xF6,
  26525. 0x1E, 0x42, 0x52, 0x09, 0x91, 0xD6, 0x55, 0x70,
  26526. 0x5C, 0xB6, 0xBC, 0x1B, 0x74, 0xAF, 0x60, 0x71,
  26527. 0x3E, 0xF8, 0x71, 0x2F, 0x14, 0x08, 0x68, 0x69,
  26528. 0xBE, 0x8E, 0xB2, 0x97, 0xD2, 0x28, 0xB3, 0x25,
  26529. 0xA0, 0x60, 0x9F, 0xD6, 0x15, 0xEA, 0xB7, 0x08,
  26530. 0x15, 0x40, 0xA6, 0x1A, 0x82, 0xAB, 0xF4, 0x3B,
  26531. 0x7D, 0xF9, 0x8A, 0x59, 0x5B, 0xE1, 0x1F, 0x41,
  26532. 0x6B, 0x41, 0xE1, 0xEB, 0x75, 0xBB, 0x57, 0x97,
  26533. 0x7C, 0x25, 0xC6, 0x4E, 0x97, 0x43, 0x7D, 0x88,
  26534. 0xCA, 0x5F, 0xDA, 0x61, 0x59, 0xD6, 0x68, 0xF6,
  26535. 0xBA, 0xB8, 0x15, 0x75, 0x55, 0xB5, 0xD5, 0x4C,
  26536. 0x0F, 0x47, 0xCB, 0xCD, 0x16, 0x84, 0x3B, 0x1A,
  26537. 0x0A, 0x0F, 0x02, 0x10, 0xEE, 0x31, 0x03, 0x13,
  26538. 0x96, 0x7F, 0x3D, 0x51, 0x64, 0x99, 0x01, 0x8F,
  26539. 0xDF, 0x31, 0x14, 0x77, 0x24, 0x70, 0xA1, 0x88,
  26540. 0x9C, 0xC0, 0x6C, 0xB6, 0xB6, 0x69, 0x0A, 0xC3,
  26541. 0x1A, 0xBC, 0xFA, 0xF4, 0xBC, 0x70, 0x76, 0x84,
  26542. 0x54, 0x5B, 0x00, 0x0B, 0x58, 0x0C, 0xCB, 0xFC,
  26543. 0xBC, 0xE9, 0xFA, 0x70, 0xAA, 0xEA, 0x0B, 0xBD,
  26544. 0x91, 0x10, 0x99, 0x2A, 0x7C, 0x6C, 0x06, 0xCB,
  26545. 0x36, 0x85, 0x27, 0xFD, 0x22, 0x90, 0x90, 0x75,
  26546. 0x7E, 0x6F, 0xE7, 0x57, 0x05, 0xFA, 0x59, 0x2A,
  26547. 0x76, 0x08, 0xF0, 0x50, 0xC6, 0xF8, 0x87, 0x03,
  26548. 0xCC, 0x28, 0xCB, 0x00, 0x0C, 0x1D, 0x7E, 0x77,
  26549. 0xB8, 0x97, 0xB7, 0x2C, 0x62, 0xBC, 0xC7, 0xAE,
  26550. 0xA2, 0x1A, 0x57, 0x72, 0x94, 0x83, 0xD2, 0x21,
  26551. 0x18, 0x32, 0xBE, 0xD6, 0x12, 0x43, 0x0C, 0x98,
  26552. 0x31, 0x03, 0xC6, 0x9E, 0x8C, 0x07, 0x2C, 0x0E,
  26553. 0xA7, 0x89, 0x8F, 0x22, 0x83, 0xBE, 0xC4, 0x8C,
  26554. 0x5A, 0xC8, 0x19, 0x84, 0xD4, 0xA5, 0xA8, 0x36,
  26555. 0x19, 0x73, 0x5A, 0x84, 0x2B, 0xD1, 0x72, 0xC0,
  26556. 0xD1, 0xB3, 0x9F, 0x43, 0x58, 0x8A, 0xF1, 0x70,
  26557. 0x45, 0x8B, 0xA9, 0xEE, 0x74, 0x92, 0xEA, 0xAA,
  26558. 0x94, 0xEA, 0x53, 0xA4, 0xD3, 0x84, 0x98, 0xEC,
  26559. 0xBB, 0x98, 0xA5, 0xF4, 0x07, 0xE7, 0xC9, 0x7B,
  26560. 0x4E, 0x16, 0x6E, 0x39, 0x71, 0x92, 0xC2, 0x16,
  26561. 0x03, 0x30, 0x14, 0xB8, 0x78, 0xE9, 0x38, 0x07,
  26562. 0x5C, 0x6C, 0x1F, 0x10, 0xA0, 0x06, 0x5A, 0xBC,
  26563. 0x31, 0x63, 0x72, 0x2F, 0x1A, 0x2E, 0xFF, 0xEC,
  26564. 0x8D, 0x6E, 0x3A, 0x0C, 0x4F, 0x71, 0x74, 0xFC,
  26565. 0x16, 0xB7, 0x9F, 0xB5, 0x18, 0x6A, 0x75, 0x16,
  26566. 0x8F, 0x81, 0xA5, 0x6A, 0xA4, 0x8A, 0x20, 0xA0,
  26567. 0x4B, 0xDD, 0xF1, 0x82, 0xC6, 0xE1, 0x79, 0xC3,
  26568. 0xF6, 0x90, 0x61, 0x55, 0x5E, 0xF7, 0x39, 0x6D,
  26569. 0xD0, 0xB7, 0x49, 0x96, 0x01, 0xA6, 0xEB, 0x3A,
  26570. 0x96, 0xA9, 0xA2, 0x2D, 0x04, 0xF1, 0x16, 0x8D,
  26571. 0xB5, 0x63, 0x55, 0xB0, 0x76, 0x00, 0xA2, 0x03,
  26572. 0x70, 0x63, 0x7B, 0x64, 0x59, 0x76, 0xBB, 0xD9,
  26573. 0x7B, 0x6D, 0x62, 0x88, 0xA0, 0xD3, 0x03, 0x63,
  26574. 0x60, 0x47, 0x2E, 0x3A, 0xC7, 0x1D, 0x56, 0x6D,
  26575. 0xB8, 0xFB, 0xB1, 0xB1, 0xD7, 0x6C, 0xB7, 0x55,
  26576. 0xCD, 0x0D, 0x68, 0xBD, 0xBF, 0xC0, 0x48, 0xEB,
  26577. 0xA2, 0x52, 0x5E, 0xEA, 0x9D, 0xD5, 0xB1, 0x44,
  26578. 0xFB, 0x3B, 0x60, 0xFB, 0xC3, 0x42, 0x39, 0x32,
  26579. 0x0C, 0xBC, 0x06, 0x9B, 0x35, 0xAB, 0x16, 0xB8,
  26580. 0x75, 0x65, 0x36, 0xFB, 0x33, 0xE8, 0xA6, 0xAF,
  26581. 0x1D, 0xD4, 0x2C, 0x79, 0xF4, 0x8A, 0xD1, 0x20,
  26582. 0xAE, 0x4B, 0x15, 0x9D, 0x3D, 0x8C, 0x31, 0x90,
  26583. 0x60, 0xCC, 0xE5, 0x69, 0xC3, 0xF6, 0x03, 0x53,
  26584. 0x65, 0x58, 0x5D, 0x34, 0x41, 0x37, 0x95, 0xA6,
  26585. 0xA1, 0x8E, 0xC5, 0x13, 0x6A, 0xB1, 0x3C, 0x90,
  26586. 0xE3, 0xAF, 0x14, 0xC0, 0xB8, 0xA4, 0x64, 0xC8,
  26587. 0x6B, 0x90, 0x73, 0x22, 0x2B, 0x56, 0xB3, 0xF7,
  26588. 0x32, 0x8A, 0xEA, 0x79, 0x81, 0x55, 0x32, 0x59,
  26589. 0x11, 0x25, 0x0E, 0xF0, 0x16, 0xD7, 0x28, 0x02,
  26590. 0xE3, 0x87, 0x8A, 0xA5, 0x05, 0x40, 0xCC, 0x98,
  26591. 0x39, 0x56, 0x97, 0x1D, 0x6E, 0xFA, 0x35, 0x2C,
  26592. 0x02, 0x55, 0x4D, 0xC7, 0x60, 0xA5, 0xA9, 0x13,
  26593. 0x58, 0xEA, 0x56, 0x37, 0x08, 0x84, 0xFD, 0x5B,
  26594. 0x3F, 0x85, 0xB7, 0x0E, 0x83, 0xE4, 0x69, 0x7D,
  26595. 0xEB, 0x17, 0x05, 0x16, 0x9E, 0x9C, 0x60, 0xA7,
  26596. 0x45, 0x28, 0xCF, 0x15, 0x28, 0x1C, 0xB1, 0xB1,
  26597. 0xC4, 0x57, 0xD4, 0x67, 0xB5, 0xF9, 0x3A, 0x60,
  26598. 0x37, 0x3D, 0x10, 0xE0, 0xCF, 0x6A, 0x83, 0x7A,
  26599. 0xA3, 0xC9, 0x59, 0x6A, 0x72, 0xBE, 0xC2, 0x9B,
  26600. 0x2D, 0x7E, 0x58, 0x65, 0x3D, 0x53, 0x30, 0x61,
  26601. 0xD3, 0x81, 0xD5, 0x17, 0x59, 0x75, 0x22, 0x17,
  26602. 0xEB, 0x46, 0xCA, 0xC7, 0x80, 0x7C, 0x4A, 0xD3,
  26603. 0x8B, 0x61, 0x16, 0x44, 0xAC, 0xF0, 0xA3, 0xF2,
  26604. 0x6B, 0x6B, 0x08, 0x4A, 0xB4, 0x7A, 0x83, 0xBF,
  26605. 0x0D, 0x69, 0x6F, 0x8A, 0x47, 0x68, 0xFC, 0x35,
  26606. 0xBC, 0xA6, 0xBC, 0x79, 0x03, 0xB2, 0xA2, 0x37,
  26607. 0xC2, 0x77, 0x49, 0xF5, 0x51, 0x0C, 0x86, 0x38,
  26608. 0x69, 0xE6, 0xAE, 0x56, 0xBB, 0x2A, 0xFE, 0x47,
  26609. 0x71, 0xC9, 0x22, 0x18, 0x74, 0xF5, 0x0F, 0x5B,
  26610. 0x14, 0xBA, 0xAD, 0x59, 0x93, 0xB4, 0x92, 0x38,
  26611. 0xFD, 0x0A, 0x0C, 0x9F, 0x79, 0xB7, 0xB4, 0x58,
  26612. 0x4E, 0x41, 0x30, 0x1F, 0x7A, 0x88, 0x5C, 0x9F,
  26613. 0x91, 0x81, 0x9B, 0xEA, 0x00, 0xD5, 0x12, 0x58,
  26614. 0x17, 0x30, 0x53, 0x9F, 0xB3, 0x7E, 0x59, 0xE8,
  26615. 0x6A, 0x6D, 0x19, 0xCA, 0x25, 0xF0, 0xA8, 0x11,
  26616. 0xC9, 0xB4, 0x28, 0xBA, 0x86, 0x14, 0xAA, 0x4F,
  26617. 0x94, 0x80, 0x7B, 0xC0, 0x31, 0xCB, 0xCC, 0x18,
  26618. 0x3F, 0x3B, 0xF0, 0x7F, 0xE2, 0xC1, 0xA6, 0xEB,
  26619. 0xA8, 0x0D, 0x5A, 0x70, 0x6E, 0xE0, 0xDA, 0xB2,
  26620. 0x7E, 0x23, 0x14, 0x58, 0x02, 0x5D, 0x84, 0xA7,
  26621. 0xA9, 0xB0, 0x23, 0x05, 0x01, 0x11, 0x6C, 0x29,
  26622. 0x0A, 0x6B, 0xB5, 0x06, 0x26, 0xD9, 0x7B, 0x93,
  26623. 0x98, 0x50, 0x94, 0x28, 0x28, 0x39, 0x0B, 0x0A,
  26624. 0x20, 0x01, 0xB7, 0x85, 0x3A, 0xD1, 0xAE, 0x9B,
  26625. 0x01, 0x1B, 0x2D, 0xB3, 0x6C, 0xAE, 0xEA, 0x73,
  26626. 0xA2, 0x32, 0x8E, 0x3C, 0x56, 0x48, 0x5B, 0x49,
  26627. 0x1C, 0x29, 0x91, 0x15, 0xA0, 0x17, 0xC9, 0x07,
  26628. 0xAB, 0x54, 0x31, 0x72, 0x60, 0xA5, 0x93, 0xA0,
  26629. 0xD7, 0xBA, 0x6D, 0x06, 0x61, 0x5D, 0x6E, 0x2C,
  26630. 0xA8, 0x4B, 0x86, 0x0E, 0xFF, 0x3C, 0xCB, 0x59,
  26631. 0x72, 0x11, 0xBF, 0xE3, 0x6B, 0xDE, 0xF8, 0x06,
  26632. 0x9A, 0xFA, 0x36, 0xC5, 0xA7, 0x33, 0x92, 0x72,
  26633. 0x26, 0x50, 0xE4, 0x95, 0x7D, 0xCA, 0x59, 0x7A,
  26634. 0xCB, 0xA5, 0x60, 0x5B, 0x63, 0xC1, 0x63, 0xCF,
  26635. 0xA9, 0x4B, 0x64, 0xDD, 0xD6, 0x23, 0x01, 0xA4,
  26636. 0x33, 0x20, 0x83, 0x36, 0x19, 0x72, 0x58, 0x9D,
  26637. 0xB0, 0x59, 0x9A, 0x69, 0x4D, 0xD4, 0x54, 0x7A,
  26638. 0x5E, 0xE9, 0x19, 0x65, 0x77, 0xC2, 0x2E, 0xD4,
  26639. 0x27, 0xAC, 0x89, 0xBB, 0x8B, 0xA3, 0x75, 0x3E,
  26640. 0xB7, 0x6C, 0x41, 0xF2, 0xC1, 0x12, 0x9C, 0x8A,
  26641. 0x77, 0xD6, 0x80, 0x5F, 0xA7, 0x19, 0xB1, 0xB6,
  26642. 0xCA, 0x11, 0xB7, 0x40, 0xA7, 0x8A, 0x3D, 0x41,
  26643. 0xB5, 0x33, 0x05, 0x26, 0xAB, 0x87, 0xD5, 0x8D,
  26644. 0x59, 0x25, 0x31, 0x5A, 0x14, 0x85, 0xED, 0xC6,
  26645. 0x47, 0xC1, 0x60, 0x4E, 0xB3, 0x81, 0x38, 0xDE,
  26646. 0x63, 0x7A, 0xD2, 0xC6, 0xCA, 0x5B, 0xE4, 0x4E,
  26647. 0x10, 0x08, 0xB2, 0xC0, 0x86, 0x7B, 0x22, 0x9C,
  26648. 0xCC, 0x36, 0x61, 0x9E, 0x27, 0x58, 0xC4, 0xC2,
  26649. 0x02, 0x9E, 0xAE, 0xB2, 0x6E, 0x7A, 0x80, 0x3F,
  26650. 0xCA, 0x30, 0x5A, 0x59, 0xCD, 0x58, 0x5E, 0x11,
  26651. 0x7D, 0x69, 0x8E, 0xCE, 0x01, 0x1C, 0xC3, 0xFC,
  26652. 0xE5, 0x4D, 0x2E, 0x11, 0x45, 0x45, 0xA2, 0x1A,
  26653. 0xC5, 0xBE, 0x67, 0x71, 0xAB, 0x8F, 0x13, 0x12,
  26654. 0x2F, 0xAD, 0x29, 0x5E, 0x74, 0x5A, 0x50, 0x3B,
  26655. 0x14, 0x2F, 0x91, 0xAE, 0xF7, 0xBD, 0xE9, 0x99,
  26656. 0x98, 0x84, 0x5F, 0xDA, 0x04, 0x35, 0x55, 0xC9,
  26657. 0xC1, 0xEE, 0x53, 0x5B, 0xE1, 0x25, 0xE5, 0xDC,
  26658. 0xE5, 0xD2, 0x66, 0x66, 0x7E, 0x72, 0x3E, 0x67,
  26659. 0xB6, 0xBA, 0x89, 0x1C, 0x16, 0xCB, 0xA1, 0x74,
  26660. 0x09, 0x8A, 0x3F, 0x35, 0x17, 0x78, 0xB0, 0x88,
  26661. 0x8C, 0x95, 0x90, 0xA9, 0x09, 0x0C, 0xD4, 0x04
  26662. };
  26663. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  26664. 0x16, 0x1C, 0xD2, 0x59, 0xFE, 0xAA, 0x7E, 0xC6,
  26665. 0xB2, 0x86, 0x49, 0x8A, 0x9A, 0x6F, 0x69, 0xF8,
  26666. 0xB2, 0x62, 0xA2, 0xE2, 0x09, 0x3D, 0x0F, 0xBD,
  26667. 0x76, 0xD5, 0xDC, 0x1C, 0x9F, 0xDE, 0x0D, 0xED,
  26668. 0xB3, 0x65, 0x81, 0x00, 0x4C, 0xB4, 0x81, 0x12,
  26669. 0xF8, 0x52, 0xE7, 0xF8, 0x7F, 0x64, 0x9E, 0x8A,
  26670. 0x42, 0xCD, 0x9E, 0x03, 0x49, 0xE7, 0xDA, 0xBD,
  26671. 0xF0, 0xA9, 0xAC, 0x1B, 0x52, 0x1C, 0x37, 0xEA,
  26672. 0x52, 0x41, 0x37, 0x0A, 0x8A, 0xB2, 0x91, 0x1C,
  26673. 0xC7, 0x99, 0x02, 0xC9, 0x5D, 0x28, 0x22, 0x4F,
  26674. 0xA8, 0x89, 0x6A, 0xD7, 0x15, 0x20, 0x9E, 0xCD,
  26675. 0xD5, 0xD7, 0x84, 0xE9, 0x1D, 0xD9, 0xD0, 0xBE,
  26676. 0x91, 0x6B, 0x45, 0x65, 0xF4, 0xD5, 0x66, 0x9A,
  26677. 0xEE, 0x0D, 0xEF, 0x93, 0x1E, 0x97, 0x68, 0x29,
  26678. 0x4E, 0xEC, 0x52, 0x58, 0xDE, 0x83, 0x91, 0xEC,
  26679. 0xE2, 0x71, 0xE7, 0xE4, 0xCF, 0xD9, 0xD2, 0x3A,
  26680. 0x79, 0xFA, 0xC3, 0xA8, 0xE0, 0xDB, 0x5D, 0xDD,
  26681. 0x6E, 0x01, 0x07, 0x23, 0x56, 0x88, 0xBB, 0xDF,
  26682. 0x7B, 0xC5, 0xD5, 0x63, 0x2F, 0x20, 0x6C, 0x63,
  26683. 0xA0, 0xC9, 0x56, 0x4F, 0x30, 0x96, 0x5C, 0xA5,
  26684. 0x8C, 0x69, 0xFF, 0x92, 0xD2, 0x5A, 0x4F, 0x93,
  26685. 0xA0, 0x9E, 0xAB, 0x9B, 0x90, 0x85, 0x94, 0x7E,
  26686. 0x07, 0x8A, 0x23, 0xE4, 0xD9, 0xC1, 0x3B, 0x8A,
  26687. 0x56, 0xE7, 0x3E, 0x18, 0xDF, 0x42, 0xD6, 0x94,
  26688. 0x9F, 0xAF, 0x59, 0x21, 0xF2, 0xE3, 0x73, 0xD4,
  26689. 0x50, 0xC8, 0xC0, 0x9D, 0x07, 0xB1, 0x52, 0xA9,
  26690. 0x7C, 0x24, 0x54, 0x47, 0x42, 0x94, 0x81, 0xD4,
  26691. 0x98, 0xBE, 0xB7, 0x25, 0x6B, 0xC4, 0x7F, 0x68,
  26692. 0xF9, 0x92, 0x2B, 0x0B, 0x1C, 0x62, 0xD9, 0xC2,
  26693. 0x3F, 0x9F, 0x73, 0x3D, 0xD7, 0x37, 0x92, 0xCF,
  26694. 0xC7, 0xB4, 0x3C, 0xBC, 0xEA, 0x27, 0x7D, 0x51,
  26695. 0xB2, 0xB8, 0xAD, 0x4A, 0x4F, 0x52, 0x2F, 0x64,
  26696. 0x2C, 0xAD, 0x5C, 0x5D, 0xEB, 0x21, 0xF3, 0x62,
  26697. 0x7F, 0x8A, 0xF4, 0xD3, 0xE5, 0xBC, 0x9E, 0x91,
  26698. 0xD4, 0xCB, 0x2F, 0x12, 0x4B, 0x5B, 0xD7, 0xC2,
  26699. 0xF4, 0xA0, 0x50, 0xCA, 0x75, 0x5B, 0xDB, 0x80,
  26700. 0x56, 0x60, 0x96, 0x63, 0xFB, 0x95, 0x11, 0xC9,
  26701. 0xAD, 0x83, 0xB5, 0x03, 0x90, 0x88, 0xCC, 0x01,
  26702. 0xF0, 0xDD, 0x54, 0x35, 0x3B, 0x0D, 0xD7, 0x43,
  26703. 0x3F, 0x0C, 0x6C, 0xEE, 0x0D, 0x07, 0x59, 0x59,
  26704. 0x81, 0x0D, 0xEC, 0x54, 0x16, 0x52, 0x2B, 0xB1,
  26705. 0xF1, 0xF6, 0x55, 0x47, 0xA0, 0xC2, 0xE9, 0xCC,
  26706. 0x9B, 0xC1, 0x7F, 0x8D, 0x39, 0xD2, 0x93, 0x09,
  26707. 0xEB, 0xE7, 0x9F, 0x21, 0x33, 0x1B, 0x75, 0xE1,
  26708. 0x2A, 0xF2, 0xE9, 0x3F, 0x03, 0xF7, 0x4F, 0x7F,
  26709. 0x87, 0xD3, 0x60, 0xF1, 0xDA, 0xF8, 0x6C, 0xED,
  26710. 0x73, 0x60, 0x92, 0xA2, 0x11, 0xA8, 0x15, 0x88,
  26711. 0x59, 0xC4, 0x2E, 0x22, 0x3C, 0xFE, 0x2E, 0x6E,
  26712. 0x55, 0x34, 0x37, 0xD8, 0x05, 0x76, 0xCF, 0xD1,
  26713. 0x94, 0x4E, 0x97, 0xEE, 0xFF, 0x9B, 0x49, 0xE5,
  26714. 0xEC, 0xCF, 0xC6, 0x78, 0xEE, 0x16, 0x52, 0x68,
  26715. 0xDF, 0xE3, 0xD3, 0x59, 0x6B, 0x4B, 0x86, 0x20,
  26716. 0x4A, 0x81, 0xC6, 0x06, 0x3B, 0x0C, 0xDC, 0xE6,
  26717. 0x19, 0xFD, 0xBB, 0x96, 0xDF, 0x7D, 0xE6, 0xE0,
  26718. 0xBD, 0x52, 0x70, 0xB4, 0xD5, 0x9C, 0x4D, 0xC5,
  26719. 0x08, 0x47, 0x6E, 0x7F, 0x07, 0x08, 0xF9, 0x8C,
  26720. 0x7A, 0x4F, 0x66, 0x45, 0xC4, 0x9D, 0x06, 0x10,
  26721. 0x0C, 0x76, 0x0C, 0x59, 0x95, 0x28, 0xD1, 0xB8,
  26722. 0xBB, 0xFE, 0x62, 0x81, 0x91, 0xCC, 0x08, 0x3C,
  26723. 0x8D, 0x22, 0x5A, 0x09, 0x3F, 0x9F, 0x17, 0xE3,
  26724. 0x55, 0x74, 0x98, 0x6F, 0x86, 0xBA, 0xA4, 0x68,
  26725. 0x98, 0xB5, 0x89, 0xF3, 0xCB, 0x7D, 0xB4, 0x6A,
  26726. 0x45, 0xF3, 0xED, 0xD4, 0xFA, 0xC2, 0x08, 0x08,
  26727. 0xF4, 0xCD, 0x02, 0x49, 0xDA, 0x69, 0x3F, 0x8F,
  26728. 0xAB, 0xFB, 0xD4, 0xE1, 0x0C, 0x02, 0xC6, 0x5B,
  26729. 0xA8, 0xC8, 0x61, 0x0F, 0xA8, 0xC6, 0xDF, 0x3D,
  26730. 0xBA, 0xEB, 0x67, 0x63, 0xDD, 0x48, 0x2A, 0xF4,
  26731. 0x15, 0x58, 0xB1, 0xE1, 0x5C, 0xC9, 0xC7, 0xA7,
  26732. 0x2E, 0x07, 0x16, 0x85, 0xAC, 0x19, 0xA0, 0x51,
  26733. 0xF1, 0x92, 0x45, 0xB9, 0xF7, 0x7C, 0x30, 0x38,
  26734. 0xA5, 0x4E, 0x29, 0x58, 0x62, 0x3E, 0xB8, 0x10,
  26735. 0x59, 0x55, 0x60, 0x9E, 0x27, 0xD6, 0x7C, 0xF7,
  26736. 0x2E, 0xC5, 0xC4, 0xA8, 0xE9, 0xB9, 0xC2, 0x92,
  26737. 0x4A, 0x9E, 0x22, 0x98, 0x50, 0x8B, 0xAB, 0xA1,
  26738. 0x3C, 0xF1, 0x11, 0xFD, 0xFB, 0x06, 0x2C, 0x96,
  26739. 0x07, 0xAC, 0x1A, 0xAA, 0x6C, 0x63, 0x73, 0x10,
  26740. 0xA8, 0x89, 0x4B, 0xF0, 0xB9, 0x6F, 0x0C, 0x19,
  26741. 0x13, 0x61, 0x86, 0xB6, 0x18, 0xDF, 0xFB, 0x27,
  26742. 0x55, 0x28, 0xBE, 0xD1, 0xCC, 0x27, 0x15, 0xDE,
  26743. 0xF4, 0x12, 0xF7, 0x7A, 0x3C, 0xF9, 0x66, 0x45,
  26744. 0x73, 0x3B, 0x04, 0x8A, 0x78, 0x47, 0x43, 0x20,
  26745. 0xD1, 0xA3, 0x80, 0xF5, 0xEE, 0xDB, 0xDA, 0x21,
  26746. 0xFA, 0x01, 0x25, 0xC9, 0x1D, 0x3C, 0x37, 0xC5,
  26747. 0x4B, 0xF3, 0x75, 0x2A, 0x1F, 0x84, 0x71, 0xC8,
  26748. 0x1F, 0xCA, 0xE2, 0xD3, 0xED, 0xA9, 0x66, 0xE1,
  26749. 0x4E, 0x66, 0xF2, 0x23, 0xB0, 0x54, 0xD7, 0x98,
  26750. 0x48, 0xFF, 0x94, 0x11, 0xD6, 0x34, 0x02, 0x4A,
  26751. 0x09, 0x89, 0x70, 0xAD, 0xE6, 0xA8, 0x8B, 0x5F,
  26752. 0x90, 0x69, 0xF7, 0x60, 0x58, 0x4D, 0xC4, 0xCF,
  26753. 0xFF, 0xCE, 0xA8, 0xEC, 0xE1, 0x1B, 0xB5, 0x56,
  26754. 0x6B, 0xD2, 0x36, 0x0A, 0xB7, 0x07, 0xDF, 0x2D,
  26755. 0x21, 0xB6, 0x74, 0x88, 0xD9, 0x31, 0xF0, 0x20,
  26756. 0x06, 0x91, 0x76, 0x42, 0x3E, 0x69, 0x44, 0x49,
  26757. 0x0C, 0xB3, 0x85, 0xE7, 0x0B, 0x35, 0x8A, 0x25,
  26758. 0x34, 0x6B, 0xAF, 0xCD, 0xD0, 0x6D, 0x40, 0x2F,
  26759. 0xF2, 0x4D, 0x6C, 0x1E, 0x5F, 0x61, 0xA8, 0x5D
  26760. };
  26761. static const byte kprime_512[KYBER_SS_SZ] = {
  26762. 0xDF, 0x46, 0x2A, 0xD6, 0x8F, 0x1E, 0xC8, 0x97,
  26763. 0x2E, 0xD9, 0xB0, 0x2D, 0x6D, 0xE0, 0x60, 0x4B,
  26764. 0xDE, 0xC7, 0x57, 0x20, 0xE0, 0x50, 0x49, 0x73,
  26765. 0x51, 0xE6, 0xEC, 0x93, 0x3E, 0x71, 0xF8, 0x82
  26766. };
  26767. #endif
  26768. #ifndef WOLFSSL_NO_KYBER768
  26769. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  26770. 0x1E, 0x4A, 0xC8, 0x7B, 0x1A, 0x69, 0x2A, 0x52,
  26771. 0x9F, 0xDB, 0xBA, 0xB9, 0x33, 0x74, 0xC5, 0x7D,
  26772. 0x11, 0x0B, 0x10, 0xF2, 0xB1, 0xDD, 0xEB, 0xAC,
  26773. 0x0D, 0x19, 0x6B, 0x7B, 0xA6, 0x31, 0xB8, 0xE9,
  26774. 0x29, 0x30, 0x28, 0xA8, 0xF3, 0x79, 0x88, 0x8C,
  26775. 0x42, 0x2D, 0xC8, 0xD3, 0x2B, 0xBF, 0x22, 0x60,
  26776. 0x10, 0xC2, 0xC1, 0xEC, 0x73, 0x18, 0x90, 0x80,
  26777. 0x45, 0x6B, 0x05, 0x64, 0xB2, 0x58, 0xB0, 0xF2,
  26778. 0x31, 0x31, 0xBC, 0x79, 0xC8, 0xE8, 0xC1, 0x1C,
  26779. 0xEF, 0x39, 0x38, 0xB2, 0x43, 0xC5, 0xCE, 0x9C,
  26780. 0x0E, 0xDD, 0x37, 0xC8, 0xF9, 0xD2, 0x98, 0x77,
  26781. 0xDB, 0xBB, 0x61, 0x5B, 0x9B, 0x5A, 0xC3, 0xC9,
  26782. 0x48, 0x48, 0x7E, 0x46, 0x71, 0x96, 0xA9, 0x14,
  26783. 0x3E, 0xFB, 0xC7, 0xCE, 0xDB, 0x64, 0xB4, 0x5D,
  26784. 0x4A, 0xCD, 0xA2, 0x66, 0x6C, 0xBC, 0x28, 0x04,
  26785. 0xF2, 0xC8, 0x66, 0x2E, 0x12, 0x8F, 0x6A, 0x99,
  26786. 0x69, 0xEC, 0x15, 0xBC, 0x0B, 0x93, 0x51, 0xF6,
  26787. 0xF9, 0x63, 0x46, 0xAA, 0x7A, 0xBC, 0x74, 0x3A,
  26788. 0x14, 0xFA, 0x03, 0x0E, 0x37, 0xA2, 0xE7, 0x59,
  26789. 0x7B, 0xDD, 0xFC, 0x5A, 0x22, 0xF9, 0xCE, 0xDA,
  26790. 0xF8, 0x61, 0x48, 0x32, 0x52, 0x72, 0x10, 0xB2,
  26791. 0x6F, 0x02, 0x4C, 0x7F, 0x6C, 0x0D, 0xCF, 0x55,
  26792. 0x1E, 0x97, 0xA4, 0x85, 0x87, 0x64, 0xC3, 0x21,
  26793. 0xD1, 0x83, 0x4A, 0xD5, 0x1D, 0x75, 0xBB, 0x24,
  26794. 0x6D, 0x27, 0x72, 0x37, 0xB7, 0xBD, 0x41, 0xDC,
  26795. 0x43, 0x62, 0xD0, 0x63, 0xF4, 0x29, 0x82, 0x92,
  26796. 0x27, 0x2D, 0x01, 0x01, 0x17, 0x80, 0xB7, 0x98,
  26797. 0x56, 0xB2, 0x96, 0xC4, 0xE9, 0x46, 0x65, 0x8B,
  26798. 0x79, 0x60, 0x31, 0x97, 0xC9, 0xB2, 0xA9, 0x9E,
  26799. 0xC6, 0x6A, 0xCB, 0x06, 0xCE, 0x2F, 0x69, 0xB5,
  26800. 0xA5, 0xA6, 0x1E, 0x9B, 0xD0, 0x6A, 0xD4, 0x43,
  26801. 0xCE, 0xB0, 0xC7, 0x4E, 0xD6, 0x53, 0x45, 0xA9,
  26802. 0x03, 0xB6, 0x14, 0xE8, 0x13, 0x68, 0xAA, 0xC2,
  26803. 0xB3, 0xD2, 0xA7, 0x9C, 0xA8, 0xCC, 0xAA, 0x1C,
  26804. 0x3B, 0x88, 0xFB, 0x82, 0xA3, 0x66, 0x32, 0x86,
  26805. 0x0B, 0x3F, 0x79, 0x50, 0x83, 0x3F, 0xD0, 0x21,
  26806. 0x2E, 0xC9, 0x6E, 0xDE, 0x4A, 0xB6, 0xF5, 0xA0,
  26807. 0xBD, 0xA3, 0xEC, 0x60, 0x60, 0xA6, 0x58, 0xF9,
  26808. 0x45, 0x7F, 0x6C, 0xC8, 0x7C, 0x6B, 0x62, 0x0C,
  26809. 0x1A, 0x14, 0x51, 0x98, 0x74, 0x86, 0xE4, 0x96,
  26810. 0x61, 0x2A, 0x10, 0x1D, 0x0E, 0x9C, 0x20, 0x57,
  26811. 0x7C, 0x57, 0x1E, 0xDB, 0x52, 0x82, 0x60, 0x8B,
  26812. 0xF4, 0xE1, 0xAC, 0x92, 0x6C, 0x0D, 0xB1, 0xC8,
  26813. 0x2A, 0x50, 0x4A, 0x79, 0x9D, 0x89, 0x88, 0x5C,
  26814. 0xA6, 0x25, 0x2B, 0xD5, 0xB1, 0xC1, 0x83, 0xAF,
  26815. 0x70, 0x13, 0x92, 0xA4, 0x07, 0xC0, 0x5B, 0x84,
  26816. 0x8C, 0x2A, 0x30, 0x16, 0xC4, 0x06, 0x13, 0xF0,
  26817. 0x2A, 0x44, 0x9B, 0x3C, 0x79, 0x26, 0xDA, 0x06,
  26818. 0x7A, 0x53, 0x31, 0x16, 0x50, 0x68, 0x40, 0x09,
  26819. 0x75, 0x10, 0x46, 0x0B, 0xBF, 0xD3, 0x60, 0x73,
  26820. 0xDC, 0xB0, 0xBF, 0xA0, 0x09, 0xB3, 0x6A, 0x91,
  26821. 0x23, 0xEA, 0xA6, 0x8F, 0x83, 0x5F, 0x74, 0xA0,
  26822. 0x1B, 0x00, 0xD2, 0x09, 0x78, 0x35, 0x96, 0x4D,
  26823. 0xF5, 0x21, 0xCE, 0x92, 0x10, 0x78, 0x9C, 0x30,
  26824. 0xB7, 0xF0, 0x6E, 0x58, 0x44, 0xB4, 0x44, 0xC5,
  26825. 0x33, 0x22, 0x39, 0x6E, 0x47, 0x99, 0xBA, 0xF6,
  26826. 0xA8, 0x8A, 0xF7, 0x31, 0x58, 0x60, 0xD0, 0x19,
  26827. 0x2D, 0x48, 0xC2, 0xC0, 0xDA, 0x6B, 0x5B, 0xA6,
  26828. 0x43, 0x25, 0x54, 0x3A, 0xCD, 0xF5, 0x90, 0x0E,
  26829. 0x8B, 0xC4, 0x77, 0xAB, 0x05, 0x82, 0x00, 0x72,
  26830. 0xD4, 0x63, 0xAF, 0xFE, 0xD0, 0x97, 0xE0, 0x62,
  26831. 0xBD, 0x78, 0xC9, 0x9D, 0x12, 0xB3, 0x85, 0x13,
  26832. 0x1A, 0x24, 0x1B, 0x70, 0x88, 0x65, 0xB4, 0x19,
  26833. 0x0A, 0xF6, 0x9E, 0xA0, 0xA6, 0x4D, 0xB7, 0x14,
  26834. 0x48, 0xA6, 0x08, 0x29, 0x36, 0x9C, 0x75, 0x55,
  26835. 0x19, 0x8E, 0x43, 0x8C, 0x9A, 0xBC, 0x31, 0x0B,
  26836. 0xC7, 0x01, 0x01, 0x91, 0x3B, 0xB1, 0x2F, 0xAA,
  26837. 0x5B, 0xEE, 0xF9, 0x75, 0x84, 0x16, 0x17, 0xC8,
  26838. 0x47, 0xCD, 0x6B, 0x33, 0x6F, 0x87, 0x79, 0x87,
  26839. 0x75, 0x38, 0x22, 0x02, 0x0B, 0x92, 0xC4, 0xCC,
  26840. 0x97, 0x05, 0x5C, 0x9B, 0x1E, 0x0B, 0x12, 0x8B,
  26841. 0xF1, 0x1F, 0x50, 0x50, 0x05, 0xB6, 0xAB, 0x0E,
  26842. 0x62, 0x77, 0x95, 0xA2, 0x06, 0x09, 0xEF, 0xA9,
  26843. 0x91, 0xE5, 0x98, 0xB8, 0x0F, 0x37, 0xB1, 0xC6,
  26844. 0xA1, 0xC3, 0xA1, 0xE9, 0xAE, 0xE7, 0x02, 0x8F,
  26845. 0x77, 0x57, 0x0A, 0xB2, 0x13, 0x91, 0x28, 0xA0,
  26846. 0x01, 0x08, 0xC5, 0x0E, 0xB3, 0x05, 0xCD, 0xB8,
  26847. 0xF9, 0xA6, 0x03, 0xA6, 0xB0, 0x78, 0x41, 0x3F,
  26848. 0x6F, 0x9B, 0x14, 0xC6, 0xD8, 0x2B, 0x51, 0x99,
  26849. 0xCE, 0x59, 0xD8, 0x87, 0x90, 0x2A, 0x28, 0x1A,
  26850. 0x02, 0x7B, 0x71, 0x74, 0x95, 0xFE, 0x12, 0x67,
  26851. 0x2A, 0x12, 0x7B, 0xBF, 0x9B, 0x25, 0x6C, 0x43,
  26852. 0x72, 0x0D, 0x7C, 0x16, 0x0B, 0x28, 0x1C, 0x12,
  26853. 0x75, 0x7D, 0xA1, 0x35, 0xB1, 0x93, 0x33, 0x52,
  26854. 0xBE, 0x4A, 0xB6, 0x7E, 0x40, 0x24, 0x8A, 0xFC,
  26855. 0x31, 0x8E, 0x23, 0x70, 0xC3, 0xB8, 0x20, 0x8E,
  26856. 0x69, 0x5B, 0xDF, 0x33, 0x74, 0x59, 0xB9, 0xAC,
  26857. 0xBF, 0xE5, 0xB4, 0x87, 0xF7, 0x6E, 0x9B, 0x4B,
  26858. 0x40, 0x01, 0xD6, 0xCF, 0x90, 0xCA, 0x8C, 0x69,
  26859. 0x9A, 0x17, 0x4D, 0x42, 0x97, 0x2D, 0xC7, 0x33,
  26860. 0xF3, 0x33, 0x89, 0xFD, 0xF5, 0x9A, 0x1D, 0xAB,
  26861. 0xA8, 0x1D, 0x83, 0x49, 0x55, 0x02, 0x73, 0x34,
  26862. 0x18, 0x5A, 0xD0, 0x2C, 0x76, 0xCF, 0x29, 0x48,
  26863. 0x46, 0xCA, 0x92, 0x94, 0xBA, 0x0E, 0xD6, 0x67,
  26864. 0x41, 0xDD, 0xEC, 0x79, 0x1C, 0xAB, 0x34, 0x19,
  26865. 0x6A, 0xC5, 0x65, 0x7C, 0x5A, 0x78, 0x32, 0x1B,
  26866. 0x56, 0xC3, 0x33, 0x06, 0xB5, 0x10, 0x23, 0x97,
  26867. 0xA5, 0xC0, 0x9C, 0x35, 0x08, 0xF7, 0x6B, 0x48,
  26868. 0x28, 0x24, 0x59, 0xF8, 0x1D, 0x0C, 0x72, 0xA4,
  26869. 0x3F, 0x73, 0x7B, 0xC2, 0xF1, 0x2F, 0x45, 0x42,
  26870. 0x26, 0x28, 0xB6, 0x7D, 0xB5, 0x1A, 0xC1, 0x42,
  26871. 0x42, 0x76, 0xA6, 0xC0, 0x8C, 0x3F, 0x76, 0x15,
  26872. 0x66, 0x5B, 0xBB, 0x8E, 0x92, 0x81, 0x48, 0xA2,
  26873. 0x70, 0xF9, 0x91, 0xBC, 0xF3, 0x65, 0xA9, 0x0F,
  26874. 0x87, 0xC3, 0x06, 0x87, 0xB6, 0x88, 0x09, 0xC9,
  26875. 0x1F, 0x23, 0x18, 0x13, 0xB8, 0x66, 0xBE, 0xA8,
  26876. 0x2E, 0x30, 0x37, 0x4D, 0x80, 0xAA, 0x0C, 0x02,
  26877. 0x97, 0x34, 0x37, 0x49, 0x8A, 0x53, 0xB1, 0x4B,
  26878. 0xF6, 0xB6, 0xCA, 0x1E, 0xD7, 0x6A, 0xB8, 0xA2,
  26879. 0x0D, 0x54, 0xA0, 0x83, 0xF4, 0xA2, 0x6B, 0x7C,
  26880. 0x03, 0x8D, 0x81, 0x96, 0x76, 0x40, 0xC2, 0x0B,
  26881. 0xF4, 0x43, 0x1E, 0x71, 0xDA, 0xCC, 0xE8, 0x57,
  26882. 0x7B, 0x21, 0x24, 0x0E, 0x49, 0x4C, 0x31, 0xF2,
  26883. 0xD8, 0x77, 0xDA, 0xF4, 0x92, 0x4F, 0xD3, 0x9D,
  26884. 0x82, 0xD6, 0x16, 0x7F, 0xBC, 0xC1, 0xF9, 0xC5,
  26885. 0xA2, 0x59, 0xF8, 0x43, 0xE3, 0x09, 0x87, 0xCC,
  26886. 0xC4, 0xBC, 0xE7, 0x49, 0x3A, 0x24, 0x04, 0xB5,
  26887. 0xE4, 0x43, 0x87, 0xF7, 0x07, 0x42, 0x57, 0x81,
  26888. 0xB7, 0x43, 0xFB, 0x55, 0x56, 0x85, 0x58, 0x4E,
  26889. 0x25, 0x57, 0xCC, 0x03, 0x8B, 0x1A, 0x9B, 0x3F,
  26890. 0x40, 0x43, 0x12, 0x1F, 0x54, 0x72, 0xEB, 0x2B,
  26891. 0x96, 0xE5, 0x94, 0x1F, 0xEC, 0x01, 0x1C, 0xEE,
  26892. 0xA5, 0x07, 0x91, 0x63, 0x6C, 0x6A, 0xBC, 0x26,
  26893. 0xC1, 0x37, 0x7E, 0xE3, 0xB5, 0x14, 0x6F, 0xC7,
  26894. 0xC8, 0x5C, 0xB3, 0x35, 0xB1, 0xE7, 0x95, 0xEE,
  26895. 0xC2, 0x03, 0x3E, 0xE4, 0x4B, 0x9A, 0xA9, 0x06,
  26896. 0x85, 0x24, 0x5E, 0xF7, 0xB4, 0x43, 0x6C, 0x00,
  26897. 0x0E, 0x66, 0xBC, 0x8B, 0xCB, 0xF1, 0xCD, 0xB8,
  26898. 0x03, 0xAC, 0x14, 0x21, 0xB1, 0xFD, 0xB2, 0x66,
  26899. 0xD5, 0x29, 0x1C, 0x83, 0x10, 0x37, 0x3A, 0x8A,
  26900. 0x3C, 0xE9, 0x56, 0x2A, 0xB1, 0x97, 0x95, 0x38,
  26901. 0x71, 0xAB, 0x99, 0xF3, 0x82, 0xCC, 0x5A, 0xA9,
  26902. 0xC0, 0xF2, 0x73, 0xD1, 0xDC, 0xA5, 0x5D, 0x27,
  26903. 0x12, 0x85, 0x38, 0x71, 0xE1, 0xA8, 0x3C, 0xB3,
  26904. 0xB8, 0x54, 0x50, 0xF7, 0x6D, 0x3F, 0x3C, 0x42,
  26905. 0xBA, 0xB5, 0x50, 0x5F, 0x72, 0x12, 0xFD, 0xB6,
  26906. 0xB8, 0xB7, 0xF6, 0x02, 0x99, 0x72, 0xA8, 0xF3,
  26907. 0x75, 0x1E, 0x4C, 0x94, 0xC1, 0x10, 0x8B, 0x02,
  26908. 0xD6, 0xAC, 0x79, 0xF8, 0xD9, 0x38, 0xF0, 0x5A,
  26909. 0x1B, 0x2C, 0x22, 0x9B, 0x14, 0xB4, 0x2B, 0x31,
  26910. 0xB0, 0x1A, 0x36, 0x40, 0x17, 0xE5, 0x95, 0x78,
  26911. 0xC6, 0xB0, 0x33, 0x83, 0x37, 0x74, 0xCB, 0x9B,
  26912. 0x57, 0x0F, 0x90, 0x86, 0xB7, 0x22, 0x90, 0x3B,
  26913. 0x37, 0x54, 0x46, 0xB4, 0x95, 0xD8, 0xA2, 0x9B,
  26914. 0xF8, 0x07, 0x51, 0x87, 0x7A, 0x80, 0xFB, 0x72,
  26915. 0x4A, 0x02, 0x10, 0xC3, 0xE1, 0x69, 0x2F, 0x39,
  26916. 0x7C, 0x2F, 0x1D, 0xDC, 0x2E, 0x6B, 0xA1, 0x7A,
  26917. 0xF8, 0x1B, 0x92, 0xAC, 0xFA, 0xBE, 0xF5, 0xF7,
  26918. 0x57, 0x3C, 0xB4, 0x93, 0xD1, 0x84, 0x02, 0x7B,
  26919. 0x71, 0x82, 0x38, 0xC8, 0x9A, 0x35, 0x49, 0xB8,
  26920. 0x90, 0x5B, 0x28, 0xA8, 0x33, 0x62, 0x86, 0x7C,
  26921. 0x08, 0x2D, 0x30, 0x19, 0xD3, 0xCA, 0x70, 0x70,
  26922. 0x07, 0x31, 0xCE, 0xB7, 0x3E, 0x84, 0x72, 0xC1,
  26923. 0xA3, 0xA0, 0x93, 0x36, 0x1C, 0x5F, 0xEA, 0x6A,
  26924. 0x7D, 0x40, 0x95, 0x5D, 0x07, 0xA4, 0x1B, 0x64,
  26925. 0xE5, 0x00, 0x81, 0xA3, 0x61, 0xB6, 0x04, 0xCC,
  26926. 0x51, 0x84, 0x47, 0xC8, 0xE2, 0x57, 0x65, 0xAB,
  26927. 0x7D, 0x68, 0xB2, 0x43, 0x27, 0x52, 0x07, 0xAF,
  26928. 0x8C, 0xA6, 0x56, 0x4A, 0x4C, 0xB1, 0xE9, 0x41,
  26929. 0x99, 0xDB, 0xA1, 0x87, 0x8C, 0x59, 0xBE, 0xC8,
  26930. 0x09, 0xAB, 0x48, 0xB2, 0xF2, 0x11, 0xBA, 0xDC,
  26931. 0x6A, 0x19, 0x98, 0xD9, 0xC7, 0x22, 0x7C, 0x13,
  26932. 0x03, 0xF4, 0x69, 0xD4, 0x6A, 0x9C, 0x7E, 0x53,
  26933. 0x03, 0xF9, 0x8A, 0xBA, 0x67, 0x56, 0x9A, 0xE8,
  26934. 0x22, 0x7C, 0x16, 0xBA, 0x1F, 0xB3, 0x24, 0x44,
  26935. 0x66, 0xA2, 0x5E, 0x7F, 0x82, 0x36, 0x71, 0x81,
  26936. 0x0C, 0xC2, 0x62, 0x06, 0xFE, 0xB2, 0x9C, 0x7E,
  26937. 0x2A, 0x1A, 0x91, 0x95, 0x9E, 0xEB, 0x03, 0xA9,
  26938. 0x82, 0x52, 0xA4, 0xF7, 0x41, 0x26, 0x74, 0xEB,
  26939. 0x9A, 0x4B, 0x27, 0x7E, 0x1F, 0x25, 0x95, 0xFC,
  26940. 0xA6, 0x40, 0x33, 0xB4, 0x1B, 0x40, 0x33, 0x08,
  26941. 0x12, 0xE9, 0x73, 0x5B, 0x7C, 0x60, 0x75, 0x01,
  26942. 0xCD, 0x81, 0x83, 0xA2, 0x2A, 0xFC, 0x33, 0x92,
  26943. 0x55, 0x37, 0x44, 0xF3, 0x3C, 0x4D, 0x20, 0x25,
  26944. 0x26, 0x94, 0x5C, 0x6D, 0x78, 0xA6, 0x0E, 0x20,
  26945. 0x1A, 0x16, 0x98, 0x7A, 0x6F, 0xA5, 0x9D, 0x94,
  26946. 0x46, 0x4B, 0x56, 0x50, 0x65, 0x56, 0x78, 0x48,
  26947. 0x24, 0xA0, 0x70, 0x58, 0xF5, 0x73, 0x20, 0xE7,
  26948. 0x6C, 0x82, 0x5B, 0x93, 0x47, 0xF2, 0x93, 0x6F,
  26949. 0x4A, 0x0E, 0x5C, 0xDA, 0xA1, 0x8C, 0xF8, 0x83,
  26950. 0x39, 0x45, 0xAE, 0x31, 0x2A, 0x36, 0xB5, 0xF5,
  26951. 0xA3, 0x81, 0x0A, 0xAC, 0x82, 0x38, 0x1F, 0xDA,
  26952. 0xE4, 0xCB, 0x9C, 0x68, 0x31, 0xD8, 0xEB, 0x8A,
  26953. 0xBA, 0xB8, 0x50, 0x41, 0x64, 0x43, 0xD7, 0x39,
  26954. 0x08, 0x6B, 0x1C, 0x32, 0x6F, 0xC2, 0xA3, 0x97,
  26955. 0x57, 0x04, 0xE3, 0x96, 0xA5, 0x96, 0x80, 0xC3,
  26956. 0xB5, 0xF3, 0x60, 0xF5, 0x48, 0x0D, 0x2B, 0x62,
  26957. 0x16, 0x9C, 0xD9, 0x4C, 0xA7, 0x1B, 0x37, 0xBC,
  26958. 0x58, 0x78, 0xBA, 0x29, 0x85, 0xE0, 0x68, 0xBA,
  26959. 0x05, 0x0B, 0x2C, 0xE5, 0x07, 0x26, 0xD4, 0xB4,
  26960. 0x45, 0x1B, 0x77, 0xAA, 0xA8, 0x67, 0x6E, 0xAE,
  26961. 0x09, 0x49, 0x82, 0x21, 0x01, 0x92, 0x19, 0x7B,
  26962. 0x1E, 0x92, 0xA2, 0x7F, 0x59, 0x86, 0x8B, 0x78,
  26963. 0x86, 0x78, 0x87, 0xB9, 0xA7, 0x0C, 0x32, 0xAF,
  26964. 0x84, 0x63, 0x0A, 0xA9, 0x08, 0x81, 0x43, 0x79,
  26965. 0xE6, 0x51, 0x91, 0x50, 0xBA, 0x16, 0x43, 0x9B,
  26966. 0x5E, 0x2B, 0x06, 0x03, 0xD0, 0x6A, 0xA6, 0x67,
  26967. 0x45, 0x57, 0xF5, 0xB0, 0x98, 0x3E, 0x5C, 0xB6,
  26968. 0xA9, 0x75, 0x96, 0x06, 0x9B, 0x01, 0xBB, 0x31,
  26969. 0x28, 0xC4, 0x16, 0x68, 0x06, 0x57, 0x20, 0x4F,
  26970. 0xD0, 0x76, 0x40, 0x39, 0x2E, 0x16, 0xB1, 0x9F,
  26971. 0x33, 0x7A, 0x99, 0xA3, 0x04, 0x84, 0x4E, 0x1A,
  26972. 0xA4, 0x74, 0xE9, 0xC7, 0x99, 0x06, 0x29, 0x71,
  26973. 0xF6, 0x72, 0x26, 0x89, 0x60, 0xF5, 0xA8, 0x2F,
  26974. 0x95, 0x00, 0x70, 0xBB, 0xE9, 0xC2, 0xA7, 0x19,
  26975. 0x50, 0xA3, 0x78, 0x5B, 0xDF, 0x0B, 0x84, 0x40,
  26976. 0x25, 0x5E, 0xD6, 0x39, 0x28, 0xD2, 0x57, 0x84,
  26977. 0x51, 0x68, 0xB1, 0xEC, 0xCC, 0x41, 0x91, 0x32,
  26978. 0x5A, 0xA7, 0x66, 0x45, 0x71, 0x9B, 0x28, 0xEB,
  26979. 0xD8, 0x93, 0x02, 0xDC, 0x67, 0x23, 0xC7, 0x86,
  26980. 0xDF, 0x52, 0x17, 0xB2, 0x43, 0x09, 0x9C, 0xA7,
  26981. 0x82, 0x38, 0xE5, 0x7E, 0x64, 0x69, 0x2F, 0x20,
  26982. 0x6B, 0x17, 0x7A, 0xBC, 0x25, 0x96, 0x60, 0x39,
  26983. 0x5C, 0xD7, 0x86, 0x0F, 0xB3, 0x5A, 0x16, 0xF6,
  26984. 0xB2, 0xFE, 0x65, 0x48, 0xC8, 0x5A, 0xB6, 0x63,
  26985. 0x30, 0xC5, 0x17, 0xFA, 0x74, 0xCD, 0xF3, 0xCB,
  26986. 0x49, 0xD2, 0x6B, 0x11, 0x81, 0x90, 0x1A, 0xF7,
  26987. 0x75, 0xA1, 0xE1, 0x80, 0x81, 0x3B, 0x6A, 0x24,
  26988. 0xC4, 0x56, 0x82, 0x9B, 0x5C, 0x38, 0x10, 0x4E,
  26989. 0xCE, 0x43, 0xC7, 0x6A, 0x43, 0x7A, 0x6A, 0x33,
  26990. 0xB6, 0xFC, 0x6C, 0x5E, 0x65, 0xC8, 0xA8, 0x94,
  26991. 0x66, 0xC1, 0x42, 0x54, 0x85, 0xB2, 0x9B, 0x9E,
  26992. 0x18, 0x54, 0x36, 0x8A, 0xFC, 0xA3, 0x53, 0xE1,
  26993. 0x43, 0xD0, 0xA9, 0x0A, 0x6C, 0x6C, 0x9E, 0x7F,
  26994. 0xDB, 0x62, 0xA6, 0x06, 0x85, 0x6B, 0x56, 0x14,
  26995. 0xF1, 0x2B, 0x64, 0xB7, 0x96, 0x02, 0x0C, 0x35,
  26996. 0x34, 0xC3, 0x60, 0x5C, 0xFD, 0xC7, 0x3B, 0x86,
  26997. 0x71, 0x4F, 0x41, 0x18, 0x50, 0x22, 0x8A, 0x28,
  26998. 0xB8, 0xF4, 0xB4, 0x9E, 0x66, 0x34, 0x16, 0xC8,
  26999. 0x4F, 0x7E, 0x38, 0x1F, 0x6A, 0xF1, 0x07, 0x13,
  27000. 0x43, 0xBF, 0x9D, 0x39, 0xB4, 0x54, 0x39, 0x24,
  27001. 0x0C, 0xC0, 0x38, 0x97, 0x29, 0x5F, 0xEA, 0x08,
  27002. 0x0B, 0x14, 0xBB, 0x2D, 0x81, 0x19, 0xA8, 0x80,
  27003. 0xE1, 0x64, 0x49, 0x5C, 0x61, 0xBE, 0xBC, 0x71,
  27004. 0x39, 0xC1, 0x18, 0x57, 0xC8, 0x5E, 0x17, 0x50,
  27005. 0x33, 0x8D, 0x63, 0x43, 0x91, 0x37, 0x06, 0xA5,
  27006. 0x07, 0xC9, 0x56, 0x64, 0x64, 0xCD, 0x28, 0x37,
  27007. 0xCF, 0x91, 0x4D, 0x1A, 0x3C, 0x35, 0xE8, 0x9B,
  27008. 0x23, 0x5C, 0x6A, 0xB7, 0xED, 0x07, 0x8B, 0xED,
  27009. 0x23, 0x47, 0x57, 0xC0, 0x2E, 0xF6, 0x99, 0x3D,
  27010. 0x4A, 0x27, 0x3C, 0xB8, 0x15, 0x05, 0x28, 0xDA,
  27011. 0x4D, 0x76, 0x70, 0x81, 0x77, 0xE9, 0x42, 0x55,
  27012. 0x46, 0xC8, 0x3E, 0x14, 0x70, 0x39, 0x76, 0x66,
  27013. 0x03, 0xB3, 0x0D, 0xA6, 0x26, 0x8F, 0x45, 0x98,
  27014. 0xA5, 0x31, 0x94, 0x24, 0x0A, 0x28, 0x32, 0xA3,
  27015. 0xD6, 0x75, 0x33, 0xB5, 0x05, 0x6F, 0x9A, 0xAA,
  27016. 0xC6, 0x1B, 0x4B, 0x17, 0xB9, 0xA2, 0x69, 0x3A,
  27017. 0xA0, 0xD5, 0x88, 0x91, 0xE6, 0xCC, 0x56, 0xCD,
  27018. 0xD7, 0x72, 0x41, 0x09, 0x00, 0xC4, 0x05, 0xAF,
  27019. 0x20, 0xB9, 0x03, 0x79, 0x7C, 0x64, 0x87, 0x69,
  27020. 0x15, 0xC3, 0x7B, 0x84, 0x87, 0xA1, 0x44, 0x9C,
  27021. 0xE9, 0x24, 0xCD, 0x34, 0x5C, 0x29, 0xA3, 0x6E,
  27022. 0x08, 0x23, 0x8F, 0x7A, 0x15, 0x7C, 0xC7, 0xE5,
  27023. 0x16, 0xAB, 0x5B, 0xA7, 0x3C, 0x80, 0x63, 0xF7,
  27024. 0x26, 0xBB, 0x5A, 0x0A, 0x03, 0x19, 0xE5, 0x71,
  27025. 0x27, 0x43, 0x8C, 0x7F, 0xC6, 0x01, 0xC9, 0x9C,
  27026. 0xCA, 0xAE, 0x4C, 0x1A, 0x83, 0x72, 0x6F, 0xDC,
  27027. 0xB5, 0x04, 0x5E, 0xD1, 0xA8, 0x2A, 0x98, 0x5E,
  27028. 0xA9, 0x95, 0x39, 0x6D, 0x77, 0x27, 0x2C, 0x66,
  27029. 0xCE, 0x49, 0x32, 0x89, 0xF6, 0x11, 0x09, 0x10,
  27030. 0xF3, 0x7C, 0x27, 0x41, 0xCE, 0x47, 0x02, 0x6A,
  27031. 0x6F, 0x82, 0x61, 0x99, 0x9C, 0x64, 0x82, 0x57,
  27032. 0x2B, 0x16, 0x93, 0x91, 0x2E, 0xF1, 0x2E, 0xEB,
  27033. 0xEA, 0x7A, 0xCF, 0x92, 0x34, 0xFB, 0x40, 0x9F,
  27034. 0x2A, 0x60, 0x90, 0xE6, 0xB0, 0xBF, 0xD8, 0x95,
  27035. 0x46, 0x9D, 0x0B, 0x2A, 0x92, 0x1B, 0xB7, 0x23,
  27036. 0xF8, 0x7A, 0x33, 0xEA, 0x54, 0x65, 0xAB, 0x90,
  27037. 0xF5, 0x14, 0xB6, 0x76, 0x98, 0xC0, 0x76, 0x8B,
  27038. 0x6C, 0xA4, 0x98, 0xB0, 0x22, 0xC5, 0x12, 0xFA,
  27039. 0x08, 0x75, 0xF0, 0x54, 0xAA, 0x22, 0x65, 0x86,
  27040. 0x7E, 0x31, 0xC0, 0xE5, 0x22, 0x65, 0x1E, 0x02,
  27041. 0x4A, 0x07, 0xD6, 0x0D, 0xD9, 0xF6, 0x33, 0x16,
  27042. 0x69, 0x21, 0xF4, 0x12, 0x6B, 0xC2, 0xB6, 0xAA,
  27043. 0x01, 0xCC, 0x15, 0xA0, 0x9B, 0x85, 0xBF, 0xF8,
  27044. 0x21, 0x8C, 0x5A, 0xAE, 0x95, 0xBC, 0x1F, 0xFB,
  27045. 0x26, 0xAE, 0x5A, 0x13, 0x76, 0x70, 0xF0, 0x49,
  27046. 0x10, 0xCA, 0x9D, 0x72, 0x41, 0xB6, 0x66, 0x0C,
  27047. 0x39, 0x4C, 0x54, 0x55, 0x91, 0x77, 0x46, 0xA2,
  27048. 0x66, 0x82, 0xFB, 0x71, 0xA4, 0x32, 0xEA, 0x95,
  27049. 0x30, 0xE8, 0x39, 0xBD, 0xEB, 0x07, 0x43, 0x30,
  27050. 0x04, 0xF4, 0x5A, 0x0D, 0xDA, 0xA0, 0xB2, 0x4E,
  27051. 0x3A, 0x56, 0x6A, 0x54, 0x08, 0x15, 0xF2, 0x81,
  27052. 0xE3, 0xFC, 0x25, 0x9A, 0xC6, 0xCB, 0xC0, 0xAC,
  27053. 0xB8, 0xD6, 0x22, 0x68, 0xB6, 0x03, 0xBC, 0x67,
  27054. 0x6A, 0xB4, 0x15, 0xC4, 0x74, 0xBB, 0x94, 0x87,
  27055. 0x3E, 0x44, 0x87, 0xAE, 0x31, 0xA4, 0xE3, 0x84,
  27056. 0x5C, 0x79, 0x90, 0x15, 0x50, 0x89, 0x0E, 0xE8,
  27057. 0x78, 0x4E, 0xEF, 0x90, 0x4F, 0xEE, 0x62, 0xBA,
  27058. 0x8C, 0x5F, 0x95, 0x2C, 0x68, 0x41, 0x30, 0x52,
  27059. 0xE0, 0xA7, 0xE3, 0x38, 0x8B, 0xB8, 0xFF, 0x0A,
  27060. 0xD6, 0x02, 0xAE, 0x3E, 0xA1, 0x4D, 0x9D, 0xF6,
  27061. 0xDD, 0x5E, 0x4C, 0xC6, 0xA3, 0x81, 0xA4, 0x1D,
  27062. 0xA5, 0xC1, 0x37, 0xEC, 0xC4, 0x9D, 0xF5, 0x87,
  27063. 0xE1, 0x78, 0xEA, 0xF4, 0x77, 0x02, 0xEC, 0x62,
  27064. 0x37, 0x80, 0x69, 0x1A, 0x32, 0x33, 0xF6, 0x9F,
  27065. 0x12, 0xBD, 0x9C, 0x9B, 0x96, 0x37, 0xC5, 0x13,
  27066. 0x78, 0xAD, 0x71, 0xA8, 0x31, 0x05, 0x52, 0x77,
  27067. 0x25, 0x4C, 0xC6, 0x3C, 0x5A, 0xD4, 0xCB, 0x76,
  27068. 0xB4, 0xAB, 0x82, 0xE5, 0xFC, 0xA1, 0x35, 0xE8,
  27069. 0xD2, 0x6A, 0x6B, 0x3A, 0x89, 0xFA, 0x5B, 0x6F
  27070. };
  27071. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  27072. 0xA5, 0xC8, 0x1C, 0x76, 0xC2, 0x43, 0x05, 0xE1,
  27073. 0xCE, 0x5D, 0x81, 0x35, 0xD4, 0x15, 0x23, 0x68,
  27074. 0x2E, 0x9E, 0xE6, 0xD7, 0xB4, 0x0A, 0xD4, 0x1D,
  27075. 0xF1, 0xF3, 0x7C, 0x9B, 0x17, 0xDC, 0xE7, 0x80,
  27076. 0x76, 0x01, 0x9A, 0x6B, 0x0B, 0x7C, 0x95, 0xC9,
  27077. 0xBE, 0x7A, 0xF2, 0x95, 0x07, 0xB2, 0xD5, 0xA6,
  27078. 0x98, 0x7C, 0x8E, 0xE3, 0x25, 0x91, 0x90, 0x85,
  27079. 0x52, 0x43, 0xE6, 0xE5, 0x6F, 0x56, 0x20, 0x60,
  27080. 0x8C, 0x52, 0xD9, 0x6F, 0xAB, 0x10, 0x3A, 0x87,
  27081. 0x00, 0xFB, 0xA1, 0xA8, 0x7D, 0xCA, 0x60, 0x78,
  27082. 0x11, 0x8A, 0x08, 0x71, 0x76, 0x2C, 0x95, 0x34,
  27083. 0xC0, 0xC0, 0xC3, 0x97, 0x8C, 0x91, 0xC3, 0xA0,
  27084. 0x1F, 0x0F, 0x60, 0x8D, 0xCF, 0x75, 0x78, 0x15,
  27085. 0x43, 0x8F, 0xE8, 0x95, 0x7C, 0x8A, 0x85, 0x91,
  27086. 0x83, 0xB1, 0xB6, 0x72, 0x1A, 0x08, 0x65, 0xBE,
  27087. 0xBC, 0x79, 0x9D, 0x4E, 0x5C, 0x0E, 0x7B, 0xD3,
  27088. 0xEA, 0xE4, 0x85, 0x8E, 0x6A, 0xB6, 0xA2, 0xE7,
  27089. 0x65, 0x8E, 0xD8, 0x0D, 0x4E, 0xD1, 0x58, 0xB0,
  27090. 0x36, 0xB9, 0x3F, 0xA0, 0x3A, 0xFA, 0x6A, 0xE3,
  27091. 0x13, 0x6C, 0xF3, 0xD6, 0x93, 0xC9, 0x11, 0xBC,
  27092. 0xC7, 0x59, 0x05, 0xE5, 0xB0, 0xCB, 0x28, 0x65,
  27093. 0xB9, 0xE9, 0x88, 0x45, 0x22, 0xA7, 0x77, 0x77,
  27094. 0x61, 0x3E, 0x53, 0x11, 0x1D, 0x5A, 0x1C, 0x7D,
  27095. 0x3D, 0xAB, 0x73, 0x4C, 0xEB, 0x03, 0x65, 0x7A,
  27096. 0xE0, 0xC8, 0x97, 0x63, 0xE9, 0x94, 0x71, 0x05,
  27097. 0x47, 0x76, 0xBA, 0xE7, 0xD5, 0x1B, 0x0E, 0x73,
  27098. 0xA5, 0xBB, 0x35, 0xAE, 0xC3, 0x0F, 0xF6, 0xBC,
  27099. 0x93, 0x68, 0x49, 0x16, 0xFE, 0xF1, 0x16, 0x25,
  27100. 0x86, 0x45, 0x2F, 0x42, 0x66, 0x53, 0xE2, 0xCA,
  27101. 0x84, 0x4D, 0x57, 0x44, 0x30, 0x7F, 0xF9, 0xAE,
  27102. 0xB2, 0x87, 0xA6, 0x44, 0x77, 0x83, 0xB2, 0x1A,
  27103. 0x0E, 0x93, 0x9C, 0x81, 0x42, 0x1D, 0x63, 0x1F,
  27104. 0x5D, 0xCB, 0x45, 0x2E, 0x51, 0xED, 0x34, 0xE3,
  27105. 0xDA, 0xD1, 0xCF, 0x50, 0x4E, 0x0A, 0x3B, 0x0F,
  27106. 0x47, 0x11, 0xA8, 0xDC, 0x64, 0x99, 0xD1, 0x69,
  27107. 0x1D, 0x10, 0x95, 0x69, 0x33, 0x6C, 0xE1, 0x55,
  27108. 0x8A, 0x4C, 0x0A, 0x46, 0x4E, 0x20, 0x87, 0xEA,
  27109. 0x8F, 0x9E, 0x3B, 0x18, 0xF7, 0x47, 0xEF, 0x61,
  27110. 0xF4, 0x57, 0x6A, 0xEB, 0x42, 0xB1, 0x7C, 0xAD,
  27111. 0xB7, 0xF0, 0xFD, 0x84, 0xDA, 0x8E, 0x3A, 0x6F,
  27112. 0x47, 0x1D, 0x95, 0xED, 0xFA, 0x65, 0xBE, 0x9E,
  27113. 0x6C, 0x9F, 0x6A, 0xE7, 0x56, 0xA2, 0x2A, 0x4F,
  27114. 0x1A, 0x5C, 0x54, 0x3C, 0x26, 0xBA, 0x7B, 0xAD,
  27115. 0x88, 0xE1, 0x6D, 0x5F, 0x5B, 0x7E, 0x12, 0xE2,
  27116. 0xD4, 0xCA, 0x34, 0xB3, 0xA6, 0x4D, 0x17, 0xF8,
  27117. 0x7C, 0xCF, 0xC4, 0xFF, 0x8C, 0x5E, 0x4F, 0x53,
  27118. 0x75, 0x2A, 0x07, 0x7C, 0x68, 0x72, 0x1E, 0x8C,
  27119. 0xC8, 0x17, 0xF9, 0xFF, 0x24, 0x87, 0x61, 0x70,
  27120. 0xFF, 0x2A, 0xF8, 0x9F, 0xA9, 0x58, 0x55, 0xA5,
  27121. 0xB1, 0xDE, 0x34, 0x7C, 0x07, 0xFD, 0xDB, 0xCF,
  27122. 0xE7, 0x26, 0x4A, 0xA5, 0xED, 0x64, 0x01, 0x49,
  27123. 0x15, 0x61, 0xD8, 0x31, 0x53, 0x8F, 0x85, 0x2B,
  27124. 0x0E, 0xD7, 0xB9, 0xE8, 0xEB, 0xAF, 0xFC, 0x06,
  27125. 0x02, 0x84, 0xF2, 0x2D, 0x2B, 0xAE, 0xE5, 0x6F,
  27126. 0xA9, 0xF6, 0xD0, 0x14, 0x32, 0xA1, 0x15, 0xA2,
  27127. 0xD6, 0xA6, 0x4C, 0x38, 0xAE, 0x0A, 0x50, 0xBA,
  27128. 0x36, 0x2F, 0xB5, 0x7B, 0x53, 0xE3, 0xE8, 0x55,
  27129. 0xB8, 0x3C, 0xE8, 0xC4, 0x22, 0x74, 0x04, 0x55,
  27130. 0x99, 0xF6, 0x5F, 0xA6, 0xA8, 0x92, 0x1D, 0x85,
  27131. 0xF9, 0x4E, 0xD2, 0x30, 0xB5, 0x16, 0x71, 0x2D,
  27132. 0xB6, 0xFD, 0x2F, 0xF2, 0x8B, 0x3A, 0x33, 0x71,
  27133. 0xD9, 0xBE, 0x05, 0x8A, 0xE7, 0x5C, 0x2F, 0xA5,
  27134. 0x91, 0xB7, 0xEC, 0x3C, 0x3D, 0xAA, 0x1F, 0x76,
  27135. 0x42, 0xBC, 0x26, 0xC3, 0x24, 0xC0, 0x80, 0x90,
  27136. 0x60, 0x7E, 0x66, 0x62, 0x15, 0x4D, 0xB3, 0x7C,
  27137. 0xF7, 0x47, 0x96, 0x7A, 0x1F, 0x9F, 0xC2, 0x90,
  27138. 0x89, 0xF5, 0x70, 0xEB, 0xE6, 0x0E, 0xEE, 0xF8,
  27139. 0x9F, 0xD2, 0x44, 0x81, 0x02, 0x8C, 0x85, 0xAE,
  27140. 0xF1, 0xDC, 0x3B, 0x09, 0xF2, 0x2C, 0xD3, 0x69,
  27141. 0x1B, 0xBB, 0xB8, 0x21, 0xC7, 0xA8, 0xA0, 0xF3,
  27142. 0x5A, 0xD1, 0x2B, 0xE1, 0xDD, 0x19, 0x9B, 0x97,
  27143. 0x70, 0x48, 0xF3, 0xD4, 0x8C, 0x16, 0xBB, 0x2C,
  27144. 0xA9, 0x4C, 0xEC, 0xB8, 0x92, 0x87, 0x70, 0xD5,
  27145. 0xBB, 0x32, 0x9A, 0x03, 0x27, 0xE0, 0xB2, 0x86,
  27146. 0xFA, 0xA1, 0xC6, 0x52, 0x81, 0x03, 0x1A, 0x31,
  27147. 0xC8, 0x4F, 0x2E, 0xDC, 0x9C, 0x04, 0xD4, 0x75,
  27148. 0xED, 0x4E, 0x12, 0x8E, 0x51, 0xEF, 0xA9, 0x7D,
  27149. 0x01, 0x48, 0xCB, 0xA6, 0xC9, 0x5F, 0x67, 0x4C,
  27150. 0x58, 0x9F, 0x30, 0x1C, 0x26, 0x5B, 0xED, 0x70,
  27151. 0x8E, 0x9A, 0xD8, 0xDA, 0x3C, 0x5C, 0xEC, 0xBD,
  27152. 0xEE, 0xED, 0x35, 0xEF, 0x1E, 0x25, 0x31, 0x32,
  27153. 0xBA, 0x89, 0x92, 0x0D, 0x78, 0x6B, 0x88, 0x23,
  27154. 0x0B, 0x01, 0x3B, 0xCF, 0x2D, 0xC9, 0x2D, 0x6B,
  27155. 0x15, 0x7A, 0xFA, 0x8D, 0xA8, 0x59, 0x2C, 0xD0,
  27156. 0x74, 0x3D, 0x49, 0x82, 0xBE, 0x60, 0xD7, 0xC2,
  27157. 0xD5, 0xC4, 0x72, 0xAB, 0x9F, 0xA7, 0xF4, 0xCC,
  27158. 0x3D, 0x12, 0xB0, 0xEB, 0xAF, 0x0A, 0xBE, 0x55,
  27159. 0x5C, 0x75, 0x80, 0x54, 0x26, 0x84, 0x4D, 0xD9,
  27160. 0x42, 0x86, 0x43, 0xF8, 0x44, 0x06, 0xA1, 0xB8,
  27161. 0xD6, 0xFA, 0xED, 0xFD, 0x8A, 0xE6, 0xE7, 0x3A,
  27162. 0x72, 0x77, 0x2A, 0x21, 0x59, 0xAC, 0xAB, 0xD9,
  27163. 0x72, 0xAE, 0xB6, 0xF7, 0xDE, 0x09, 0x1A, 0xC5,
  27164. 0xFD, 0xD7, 0xF4, 0x9A, 0x3D, 0xC6, 0x64, 0x1C,
  27165. 0xDF, 0x62, 0x44, 0x6B, 0x4B, 0x04, 0xA3, 0x1F,
  27166. 0x73, 0xB8, 0x0A, 0x62, 0xF8, 0x0A, 0x40, 0x4A,
  27167. 0x8C, 0xB1, 0x8C, 0xE3, 0xE6, 0x54, 0x80, 0xEF,
  27168. 0x7B, 0x52, 0xBF, 0x00, 0x91, 0x11, 0x7E, 0x5D,
  27169. 0x08, 0xEA, 0xE1, 0xB0, 0xAA, 0xBB, 0x72, 0xE6,
  27170. 0xDF, 0xFF, 0xF7, 0x6F, 0x6E, 0x44, 0xBB, 0xD7,
  27171. 0xEA, 0x57, 0x0D, 0x66, 0x04, 0xBC, 0x2E, 0x74,
  27172. 0x31, 0x8B, 0xAF, 0xA3, 0x15, 0xA3, 0x88, 0x61,
  27173. 0xAA, 0x1B, 0x21, 0xAF, 0xB2, 0xA5, 0x3F, 0x26,
  27174. 0x14, 0xF1, 0xD6, 0x40, 0x07, 0x59, 0x84, 0xAE,
  27175. 0x62, 0xE2, 0xFC, 0xA1, 0xD1, 0xB4, 0xDB, 0x36,
  27176. 0x9F, 0x15, 0x70, 0x5C, 0xE7, 0xD4, 0xDF, 0x8A,
  27177. 0xE9, 0x82, 0x64, 0x50, 0x10, 0x51, 0xC0, 0xDE,
  27178. 0xF2, 0x1D, 0x64, 0x5D, 0x49, 0x62, 0x5A, 0xF0,
  27179. 0x2C, 0xA4, 0x28, 0xD9, 0xF0, 0xC2, 0xCD, 0x9F,
  27180. 0xBA, 0xEE, 0xAB, 0x97, 0xE8, 0xE9, 0x15, 0x16,
  27181. 0x62, 0xB6, 0x99, 0x2B, 0x4C, 0x99, 0xAB, 0x1B,
  27182. 0x92, 0x5D, 0x08, 0x92, 0x03, 0x63, 0x37, 0x3F,
  27183. 0x76, 0xD3, 0xFD, 0xF0, 0x82, 0x8C, 0xAA, 0x69,
  27184. 0xC8, 0xB1, 0xBD, 0xC6, 0xF5, 0x21, 0xDF, 0x64,
  27185. 0x1C, 0xF1, 0xC8, 0xA4, 0xE7, 0xEF, 0x0C, 0x23,
  27186. 0x28, 0x9A, 0x4E, 0x2C, 0xF1, 0x8A, 0xCE, 0xBB,
  27187. 0xE4, 0xC1, 0xE6, 0x83, 0x69, 0xBD, 0x52, 0x35,
  27188. 0x12, 0x01, 0x42, 0xEC, 0xDD, 0x1A, 0x73, 0x81,
  27189. 0x1E, 0x2E, 0x53, 0x3A, 0x64, 0x7D, 0x7A, 0xEE,
  27190. 0x16, 0xDA, 0xA0, 0x3B, 0x68, 0x36, 0x39, 0xDC,
  27191. 0xF1, 0xE1, 0xF1, 0xE7, 0x1C, 0xFA, 0xED, 0x48,
  27192. 0xF6, 0x9A, 0xEC, 0x3E, 0x83, 0x17, 0x33, 0xDA,
  27193. 0x19, 0xCE, 0xBE, 0xC1, 0xDD, 0xBF, 0x71, 0xCB,
  27194. 0xAE, 0x08, 0x00, 0xF2, 0xF6, 0xD6, 0x4A, 0x09,
  27195. 0x6E, 0xC4, 0x95, 0xD6, 0x2F, 0x43, 0x44, 0xF7,
  27196. 0xAA, 0x56, 0x21, 0xB3, 0x22, 0x35, 0x3A, 0x79,
  27197. 0x5A, 0xA0, 0x99, 0xEA, 0x3A, 0x07, 0x02, 0x72,
  27198. 0xD0, 0x53, 0xD4, 0x65, 0x3A, 0x20, 0xCF, 0x21,
  27199. 0x0E, 0xAA, 0xF1, 0x2C, 0xAE, 0x60, 0x23, 0xD8,
  27200. 0xE5, 0x11, 0x8D, 0xF0, 0x4B, 0x38, 0x4A, 0x44,
  27201. 0xD1, 0xED, 0xB9, 0x1C, 0x44, 0x98, 0x9E, 0xF7,
  27202. 0xEE, 0x57, 0xF2, 0xBF, 0x81, 0xA2, 0x4B, 0xDC,
  27203. 0x76, 0x80, 0x7D, 0xA9, 0x67, 0xEE, 0x65, 0x25,
  27204. 0x41, 0x0C, 0x5C, 0x48, 0x50, 0x67, 0xEF, 0xC3,
  27205. 0xD3, 0x9A, 0x9A, 0xD4, 0x2C, 0xC7, 0x53, 0xBA,
  27206. 0xA5, 0x9A, 0x1F, 0xD2, 0x8A, 0xF3, 0x5C, 0x00,
  27207. 0xD1, 0x8A, 0x40, 0x6A, 0x28, 0xFC, 0x79, 0xBA
  27208. };
  27209. static const byte kprime_768[KYBER_SS_SZ] = {
  27210. 0xDC, 0x5B, 0x88, 0x88, 0xBC, 0x1E, 0xBA, 0x5C,
  27211. 0x19, 0x69, 0xC2, 0x11, 0x64, 0xEA, 0x43, 0xE2,
  27212. 0x2E, 0x7A, 0xC0, 0xCD, 0x01, 0x2A, 0x2F, 0x26,
  27213. 0xCB, 0x8C, 0x48, 0x7E, 0x69, 0xEF, 0x7C, 0xE4
  27214. };
  27215. #endif
  27216. #ifndef WOLFSSL_NO_KYBER1024
  27217. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  27218. 0x84, 0x45, 0xC3, 0x36, 0xF3, 0x51, 0x8B, 0x29,
  27219. 0x81, 0x63, 0xDC, 0xBB, 0x63, 0x57, 0x59, 0x79,
  27220. 0x83, 0xCA, 0x2E, 0x87, 0x3D, 0xCB, 0x49, 0x61,
  27221. 0x0C, 0xF5, 0x2F, 0x14, 0xDB, 0xCB, 0x94, 0x7C,
  27222. 0x1F, 0x3E, 0xE9, 0x26, 0x69, 0x67, 0x27, 0x6B,
  27223. 0x0C, 0x57, 0x6C, 0xF7, 0xC3, 0x0E, 0xE6, 0xB9,
  27224. 0x3D, 0xEA, 0x51, 0x18, 0x67, 0x6C, 0xBE, 0xE1,
  27225. 0xB1, 0xD4, 0x79, 0x42, 0x06, 0xFB, 0x36, 0x9A,
  27226. 0xBA, 0x41, 0x16, 0x7B, 0x43, 0x93, 0x85, 0x5C,
  27227. 0x84, 0xEB, 0xA8, 0xF3, 0x23, 0x73, 0xC0, 0x5B,
  27228. 0xAE, 0x76, 0x31, 0xC8, 0x02, 0x74, 0x4A, 0xAD,
  27229. 0xB6, 0xC2, 0xDE, 0x41, 0x25, 0x0C, 0x49, 0x43,
  27230. 0x15, 0x23, 0x0B, 0x52, 0x82, 0x6C, 0x34, 0x58,
  27231. 0x7C, 0xB2, 0x1B, 0x18, 0x3B, 0x49, 0xB2, 0xA5,
  27232. 0xAC, 0x04, 0x92, 0x1A, 0xC6, 0xBF, 0xAC, 0x1B,
  27233. 0x24, 0xA4, 0xB3, 0x7A, 0x93, 0xA4, 0xB1, 0x68,
  27234. 0xCC, 0xE7, 0x59, 0x1B, 0xE6, 0x11, 0x1F, 0x47,
  27235. 0x62, 0x60, 0xF2, 0x76, 0x29, 0x59, 0xF5, 0xC1,
  27236. 0x64, 0x01, 0x18, 0xC2, 0x42, 0x37, 0x72, 0xE2,
  27237. 0xAD, 0x03, 0xDC, 0x71, 0x68, 0xA3, 0x8C, 0x6D,
  27238. 0xD3, 0x9F, 0x5F, 0x72, 0x54, 0x26, 0x42, 0x80,
  27239. 0xC8, 0xBC, 0x10, 0xB9, 0x14, 0x16, 0x80, 0x70,
  27240. 0x47, 0x2F, 0xA8, 0x80, 0xAC, 0xB8, 0x60, 0x1A,
  27241. 0x8A, 0x08, 0x37, 0xF2, 0x5F, 0xE1, 0x94, 0x68,
  27242. 0x7C, 0xD6, 0x8B, 0x7D, 0xE2, 0x34, 0x0F, 0x03,
  27243. 0x6D, 0xAD, 0x89, 0x1D, 0x38, 0xD1, 0xB0, 0xCE,
  27244. 0x9C, 0x26, 0x33, 0x35, 0x5C, 0xF5, 0x7B, 0x50,
  27245. 0xB8, 0x96, 0x03, 0x6F, 0xCA, 0x26, 0x0D, 0x26,
  27246. 0x69, 0xF8, 0x5B, 0xAC, 0x79, 0x71, 0x4F, 0xDA,
  27247. 0xFB, 0x41, 0xEF, 0x80, 0xB8, 0xC3, 0x02, 0x64,
  27248. 0xC3, 0x13, 0x86, 0xAE, 0x60, 0xB0, 0x5F, 0xAA,
  27249. 0x54, 0x2A, 0x26, 0xB4, 0x1E, 0xB8, 0x5F, 0x67,
  27250. 0x06, 0x8F, 0x08, 0x80, 0x34, 0xFF, 0x67, 0xAA,
  27251. 0x2E, 0x81, 0x5A, 0xAB, 0x8B, 0xCA, 0x6B, 0xF7,
  27252. 0x1F, 0x70, 0xEC, 0xC3, 0xCB, 0xCB, 0xC4, 0x5E,
  27253. 0xF7, 0x01, 0xFC, 0xD5, 0x42, 0xBD, 0x21, 0xC7,
  27254. 0xB0, 0x95, 0x68, 0xF3, 0x69, 0xC6, 0x69, 0xF3,
  27255. 0x96, 0x47, 0x38, 0x44, 0xFB, 0xA1, 0x49, 0x57,
  27256. 0xF5, 0x19, 0x74, 0xD8, 0x52, 0xB9, 0x78, 0x01,
  27257. 0x46, 0x03, 0xA2, 0x10, 0xC0, 0x19, 0x03, 0x62,
  27258. 0x87, 0x00, 0x89, 0x94, 0xF2, 0x12, 0x55, 0xB2,
  27259. 0x50, 0x99, 0xAD, 0x82, 0xAA, 0x13, 0x24, 0x38,
  27260. 0x96, 0x3B, 0x2C, 0x0A, 0x47, 0xCD, 0xF5, 0xF3,
  27261. 0x2B, 0xA4, 0x6B, 0x76, 0xC7, 0xA6, 0x55, 0x9F,
  27262. 0x18, 0xBF, 0xD5, 0x55, 0xB7, 0x62, 0xE4, 0x87,
  27263. 0xB6, 0xAC, 0x99, 0x2F, 0xE2, 0x0E, 0x28, 0x3C,
  27264. 0xA0, 0xB3, 0xF6, 0x16, 0x44, 0x96, 0x95, 0x59,
  27265. 0x95, 0xC3, 0xB2, 0x8A, 0x57, 0xBB, 0xC2, 0x98,
  27266. 0x26, 0xF0, 0x6F, 0xB3, 0x8B, 0x25, 0x34, 0x70,
  27267. 0xAF, 0x63, 0x1B, 0xC4, 0x6C, 0x3A, 0x8F, 0x9C,
  27268. 0xE8, 0x24, 0x32, 0x19, 0x85, 0xDD, 0x01, 0xC0,
  27269. 0x5F, 0x69, 0xB8, 0x24, 0xF9, 0x16, 0x63, 0x3B,
  27270. 0x40, 0x65, 0x4C, 0x75, 0xAA, 0xEB, 0x93, 0x85,
  27271. 0x57, 0x6F, 0xFD, 0xE2, 0x99, 0x0A, 0x6B, 0x0A,
  27272. 0x3B, 0xE8, 0x29, 0xD6, 0xD8, 0x4E, 0x34, 0xF1,
  27273. 0x78, 0x05, 0x89, 0xC7, 0x92, 0x04, 0xC6, 0x3C,
  27274. 0x79, 0x8F, 0x55, 0xD2, 0x31, 0x87, 0xE4, 0x61,
  27275. 0xD4, 0x8C, 0x21, 0xE5, 0xC0, 0x47, 0xE5, 0x35,
  27276. 0xB1, 0x9F, 0x45, 0x8B, 0xBA, 0x13, 0x45, 0xB9,
  27277. 0xE4, 0x1E, 0x0C, 0xB4, 0xA9, 0xC2, 0xD8, 0xC4,
  27278. 0x0B, 0x49, 0x0A, 0x3B, 0xAB, 0xC5, 0x53, 0xB3,
  27279. 0x02, 0x6B, 0x16, 0x72, 0xD2, 0x8C, 0xBC, 0x8B,
  27280. 0x49, 0x8A, 0x3A, 0x99, 0x57, 0x9A, 0x83, 0x2F,
  27281. 0xEA, 0xE7, 0x46, 0x10, 0xF0, 0xB6, 0x25, 0x0C,
  27282. 0xC3, 0x33, 0xE9, 0x49, 0x3E, 0xB1, 0x62, 0x1E,
  27283. 0xD3, 0x4A, 0xA4, 0xAB, 0x17, 0x5F, 0x2C, 0xA2,
  27284. 0x31, 0x15, 0x25, 0x09, 0xAC, 0xB6, 0xAC, 0x86,
  27285. 0xB2, 0x0F, 0x6B, 0x39, 0x10, 0x84, 0x39, 0xE5,
  27286. 0xEC, 0x12, 0xD4, 0x65, 0xA0, 0xFE, 0xF3, 0x50,
  27287. 0x03, 0xE1, 0x42, 0x77, 0xA2, 0x18, 0x12, 0x14,
  27288. 0x6B, 0x25, 0x44, 0x71, 0x6D, 0x6A, 0xB8, 0x2D,
  27289. 0x1B, 0x07, 0x26, 0xC2, 0x7A, 0x98, 0xD5, 0x89,
  27290. 0xEB, 0xDA, 0xCC, 0x4C, 0x54, 0xBA, 0x77, 0xB2,
  27291. 0x49, 0x8F, 0x21, 0x7E, 0x14, 0xE3, 0x4E, 0x66,
  27292. 0x02, 0x5A, 0x2A, 0x14, 0x3A, 0x99, 0x25, 0x20,
  27293. 0xA6, 0x1C, 0x06, 0x72, 0xCC, 0x9C, 0xCE, 0xD7,
  27294. 0xC9, 0x45, 0x0C, 0x68, 0x3E, 0x90, 0xA3, 0xE4,
  27295. 0x65, 0x1D, 0xB6, 0x23, 0xA6, 0xDB, 0x39, 0xAC,
  27296. 0x26, 0x12, 0x5B, 0x7F, 0xC1, 0x98, 0x6D, 0x7B,
  27297. 0x04, 0x93, 0xB8, 0xB7, 0x2D, 0xE7, 0x70, 0x7D,
  27298. 0xC2, 0x0B, 0xBD, 0xD4, 0x37, 0x13, 0x15, 0x6A,
  27299. 0xF7, 0xD9, 0x43, 0x0E, 0xF4, 0x53, 0x99, 0x66,
  27300. 0x3C, 0x22, 0x02, 0x73, 0x91, 0x68, 0x69, 0x2D,
  27301. 0xD6, 0x57, 0x54, 0x5B, 0x05, 0x6D, 0x9C, 0x92,
  27302. 0x38, 0x5A, 0x7F, 0x41, 0x4B, 0x34, 0xB9, 0x0C,
  27303. 0x79, 0x60, 0xD5, 0x7B, 0x35, 0xBA, 0x7D, 0xDE,
  27304. 0x7B, 0x81, 0xFC, 0xA0, 0x11, 0x9D, 0x74, 0x1B,
  27305. 0x12, 0x78, 0x09, 0x26, 0x01, 0x8F, 0xE4, 0xC8,
  27306. 0x03, 0x0B, 0xF0, 0x38, 0xE1, 0x8B, 0x4F, 0xA3,
  27307. 0x37, 0x43, 0xD0, 0xD3, 0xC8, 0x46, 0x41, 0x7E,
  27308. 0x9D, 0x59, 0x15, 0xC2, 0x46, 0x31, 0x59, 0x38,
  27309. 0xB1, 0xE2, 0x33, 0x61, 0x45, 0x01, 0xD0, 0x26,
  27310. 0x95, 0x95, 0x51, 0x25, 0x8B, 0x23, 0x32, 0x30,
  27311. 0xD4, 0x28, 0xB1, 0x81, 0xB1, 0x32, 0xF1, 0xD0,
  27312. 0xB0, 0x26, 0x06, 0x7B, 0xA8, 0x16, 0x99, 0x9B,
  27313. 0xC0, 0xCD, 0x6B, 0x54, 0x7E, 0x54, 0x8B, 0x63,
  27314. 0xC9, 0xEA, 0xA0, 0x91, 0xBA, 0xC4, 0x93, 0xDC,
  27315. 0x59, 0x8D, 0xBC, 0x2B, 0x0E, 0x14, 0x6A, 0x25,
  27316. 0x91, 0xC2, 0xA8, 0xC0, 0x09, 0xDD, 0x51, 0x70,
  27317. 0xAA, 0xE0, 0x27, 0xC5, 0x41, 0xA1, 0xB5, 0xE6,
  27318. 0x6E, 0x45, 0xC6, 0x56, 0x12, 0x98, 0x4C, 0x46,
  27319. 0x77, 0x04, 0x93, 0xEC, 0x89, 0x6E, 0xF2, 0x5A,
  27320. 0xA9, 0x30, 0x5E, 0x9F, 0x06, 0x69, 0x2C, 0xD0,
  27321. 0xB2, 0xF0, 0x69, 0x62, 0xE2, 0x05, 0xBE, 0xBE,
  27322. 0x11, 0x3A, 0x34, 0xEB, 0xB1, 0xA4, 0x83, 0x0A,
  27323. 0x9B, 0x37, 0x49, 0x64, 0x1B, 0xB9, 0x35, 0x00,
  27324. 0x7B, 0x23, 0xB2, 0x4B, 0xFE, 0x57, 0x69, 0x56,
  27325. 0x25, 0x4D, 0x7A, 0x35, 0xAA, 0x49, 0x6A, 0xC4,
  27326. 0x46, 0xC6, 0x7A, 0x7F, 0xEC, 0x85, 0xA6, 0x00,
  27327. 0x57, 0xE8, 0x58, 0x06, 0x17, 0xBC, 0xB3, 0xFA,
  27328. 0xD1, 0x5C, 0x76, 0x44, 0x0F, 0xED, 0x54, 0xCC,
  27329. 0x78, 0x93, 0x94, 0xFE, 0xA2, 0x44, 0x52, 0xCC,
  27330. 0x6B, 0x05, 0x85, 0xB7, 0xEB, 0x0A, 0x88, 0xBB,
  27331. 0xA9, 0x50, 0x0D, 0x98, 0x00, 0xE6, 0x24, 0x1A,
  27332. 0xFE, 0xB5, 0x23, 0xB5, 0x5A, 0x96, 0xA5, 0x35,
  27333. 0x15, 0x1D, 0x10, 0x49, 0x57, 0x32, 0x06, 0xE5,
  27334. 0x9C, 0x7F, 0xEB, 0x07, 0x09, 0x66, 0x82, 0x36,
  27335. 0x34, 0xF7, 0x7D, 0x5F, 0x12, 0x91, 0x75, 0x5A,
  27336. 0x24, 0x31, 0x19, 0x62, 0x1A, 0xF8, 0x08, 0x4A,
  27337. 0xB7, 0xAC, 0x1E, 0x22, 0xA0, 0x56, 0x8C, 0x62,
  27338. 0x01, 0x41, 0x7C, 0xBE, 0x36, 0x55, 0xD8, 0xA0,
  27339. 0x8D, 0xD5, 0xB5, 0x13, 0x88, 0x4C, 0x98, 0xD5,
  27340. 0xA4, 0x93, 0xFD, 0x49, 0x38, 0x2E, 0xA4, 0x18,
  27341. 0x60, 0xF1, 0x33, 0xCC, 0xD6, 0x01, 0xE8, 0x85,
  27342. 0x96, 0x64, 0x26, 0xA2, 0xB1, 0xF2, 0x3D, 0x42,
  27343. 0xD8, 0x2E, 0x24, 0x58, 0x2D, 0x99, 0x72, 0x51,
  27344. 0x92, 0xC2, 0x17, 0x77, 0x46, 0x7B, 0x14, 0x57,
  27345. 0xB1, 0xDD, 0x42, 0x9A, 0x0C, 0x41, 0xA5, 0xC3,
  27346. 0xD7, 0x04, 0xCE, 0xA0, 0x62, 0x78, 0xC5, 0x99,
  27347. 0x41, 0xB4, 0x38, 0xC6, 0x27, 0x27, 0x09, 0x78,
  27348. 0x09, 0xB4, 0x53, 0x0D, 0xBE, 0x83, 0x7E, 0xA3,
  27349. 0x96, 0xB6, 0xD3, 0x10, 0x77, 0xFA, 0xD3, 0x73,
  27350. 0x30, 0x53, 0x98, 0x9A, 0x84, 0x42, 0xAA, 0xC4,
  27351. 0x25, 0x5C, 0xB1, 0x63, 0xB8, 0xCA, 0x2F, 0x27,
  27352. 0x50, 0x1E, 0xA9, 0x67, 0x30, 0x56, 0x95, 0xAB,
  27353. 0xD6, 0x59, 0xAA, 0x02, 0xC8, 0x3E, 0xE6, 0x0B,
  27354. 0xB5, 0x74, 0x20, 0x3E, 0x99, 0x37, 0xAE, 0x1C,
  27355. 0x62, 0x1C, 0x8E, 0xCB, 0x5C, 0xC1, 0xD2, 0x1D,
  27356. 0x55, 0x69, 0x60, 0xB5, 0xB9, 0x16, 0x1E, 0xA9,
  27357. 0x6F, 0xFF, 0xEB, 0xAC, 0x72, 0xE1, 0xB8, 0xA6,
  27358. 0x15, 0x4F, 0xC4, 0xD8, 0x8B, 0x56, 0xC0, 0x47,
  27359. 0x41, 0xF0, 0x90, 0xCB, 0xB1, 0x56, 0xA7, 0x37,
  27360. 0xC9, 0xE6, 0xA2, 0x2B, 0xA8, 0xAC, 0x70, 0x4B,
  27361. 0xC3, 0x04, 0xF8, 0xE1, 0x7E, 0x5E, 0xA8, 0x45,
  27362. 0xFD, 0xE5, 0x9F, 0xBF, 0x78, 0x8C, 0xCE, 0x0B,
  27363. 0x97, 0xC8, 0x76, 0x1F, 0x89, 0xA2, 0x42, 0xF3,
  27364. 0x05, 0x25, 0x83, 0xC6, 0x84, 0x4A, 0x63, 0x20,
  27365. 0x31, 0xC9, 0x64, 0xA6, 0xC4, 0xA8, 0x5A, 0x12,
  27366. 0x8A, 0x28, 0x61, 0x9B, 0xA1, 0xBB, 0x3D, 0x1B,
  27367. 0xEA, 0x4B, 0x49, 0x84, 0x1F, 0xC8, 0x47, 0x61,
  27368. 0x4A, 0x06, 0x68, 0x41, 0xF5, 0x2E, 0xD0, 0xEB,
  27369. 0x8A, 0xE0, 0xB8, 0xB0, 0x96, 0xE9, 0x2B, 0x81,
  27370. 0x95, 0x40, 0x58, 0x15, 0xB2, 0x31, 0x26, 0x6F,
  27371. 0x36, 0xB1, 0x8C, 0x1A, 0x53, 0x33, 0x3D, 0xAB,
  27372. 0x95, 0xD2, 0xA9, 0xA3, 0x74, 0xB5, 0x47, 0x8A,
  27373. 0x4A, 0x41, 0xFB, 0x87, 0x59, 0x95, 0x7C, 0x9A,
  27374. 0xB2, 0x2C, 0xAE, 0x54, 0x5A, 0xB5, 0x44, 0xBA,
  27375. 0x8D, 0xD0, 0x5B, 0x83, 0xF3, 0xA6, 0x13, 0xA2,
  27376. 0x43, 0x7A, 0xDB, 0x07, 0x3A, 0x96, 0x35, 0xCB,
  27377. 0x4B, 0xBC, 0x96, 0x5F, 0xB4, 0x54, 0xCF, 0x27,
  27378. 0xB2, 0x98, 0xA4, 0x0C, 0xD0, 0xDA, 0x3B, 0x8F,
  27379. 0x9C, 0xA9, 0x9D, 0x8C, 0xB4, 0x28, 0x6C, 0x5E,
  27380. 0xB4, 0x76, 0x41, 0x67, 0x96, 0x07, 0x0B, 0xA5,
  27381. 0x35, 0xAA, 0xA5, 0x8C, 0xDB, 0x45, 0x1C, 0xD6,
  27382. 0xDB, 0x5C, 0xBB, 0x0C, 0xA2, 0x0F, 0x0C, 0x71,
  27383. 0xDE, 0x97, 0xC3, 0x0D, 0xA9, 0x7E, 0xC7, 0x90,
  27384. 0x6D, 0x06, 0xB4, 0xB9, 0x39, 0x39, 0x60, 0x28,
  27385. 0xC4, 0x6B, 0xA0, 0xE7, 0xA8, 0x65, 0xBC, 0x83,
  27386. 0x08, 0xA3, 0x81, 0x0F, 0x12, 0x12, 0x00, 0x63,
  27387. 0x39, 0xF7, 0xBC, 0x16, 0x9B, 0x16, 0x66, 0xFD,
  27388. 0xF4, 0x75, 0x91, 0x1B, 0xBC, 0x8A, 0xAA, 0xB4,
  27389. 0x17, 0x55, 0xC9, 0xA8, 0xAA, 0xBF, 0xA2, 0x3C,
  27390. 0x0E, 0x37, 0xF8, 0x4F, 0xE4, 0x69, 0x99, 0xE0,
  27391. 0x30, 0x49, 0x4B, 0x92, 0x98, 0xEF, 0x99, 0x34,
  27392. 0xE8, 0xA6, 0x49, 0xC0, 0xA5, 0xCC, 0xE2, 0xB2,
  27393. 0x2F, 0x31, 0x80, 0x9A, 0xFE, 0xD2, 0x39, 0x55,
  27394. 0xD8, 0x78, 0x81, 0xD9, 0x9F, 0xC1, 0xD3, 0x52,
  27395. 0x89, 0x6C, 0xAC, 0x90, 0x55, 0xBE, 0xA0, 0xD0,
  27396. 0x16, 0xCC, 0xBA, 0x78, 0x05, 0xA3, 0xA5, 0x0E,
  27397. 0x22, 0x16, 0x30, 0x37, 0x9B, 0xD0, 0x11, 0x35,
  27398. 0x22, 0x1C, 0xAD, 0x5D, 0x95, 0x17, 0xC8, 0xCC,
  27399. 0x42, 0x63, 0x7B, 0x9F, 0xC0, 0x71, 0x8E, 0x9A,
  27400. 0x9B, 0xB4, 0x94, 0x5C, 0x72, 0xD8, 0xD1, 0x1D,
  27401. 0x3D, 0x65, 0x9D, 0x83, 0xA3, 0xC4, 0x19, 0x50,
  27402. 0x9A, 0xF5, 0xB4, 0x70, 0xDD, 0x89, 0xB7, 0xF3,
  27403. 0xAC, 0xCF, 0x5F, 0x35, 0xCF, 0xC3, 0x22, 0x11,
  27404. 0x5F, 0xD6, 0x6A, 0x5C, 0xD2, 0x87, 0x56, 0x51,
  27405. 0x32, 0x6F, 0x9B, 0x31, 0x68, 0x91, 0x3B, 0xE5,
  27406. 0xB9, 0xC8, 0x7A, 0xE0, 0xB0, 0x25, 0xEC, 0x7A,
  27407. 0x2F, 0x4A, 0x07, 0x27, 0x50, 0x94, 0x6A, 0xC6,
  27408. 0x11, 0x70, 0xA7, 0x82, 0x6D, 0x97, 0x04, 0xC5,
  27409. 0xA2, 0x3A, 0x1C, 0x0A, 0x23, 0x25, 0x14, 0x6C,
  27410. 0x3B, 0xC1, 0x85, 0x88, 0x26, 0xC6, 0xB3, 0x92,
  27411. 0x79, 0xC2, 0xDA, 0x74, 0x38, 0xA3, 0x70, 0xED,
  27412. 0x8A, 0x0A, 0xA5, 0x16, 0x9E, 0x3B, 0xEC, 0x29,
  27413. 0xED, 0x88, 0x47, 0x87, 0x32, 0x75, 0x8D, 0x45,
  27414. 0x41, 0x43, 0xE2, 0x27, 0xF8, 0x59, 0x58, 0x83,
  27415. 0x29, 0x78, 0x42, 0xE6, 0xAF, 0x13, 0x3B, 0x17,
  27416. 0xE4, 0x81, 0x1B, 0x0F, 0x57, 0x13, 0xAC, 0x73,
  27417. 0xB7, 0xE3, 0x47, 0x42, 0x3E, 0xB9, 0x28, 0x22,
  27418. 0xD2, 0x30, 0x6F, 0xA1, 0x45, 0x00, 0xA7, 0x20,
  27419. 0x7A, 0x06, 0x72, 0x67, 0x20, 0x46, 0x54, 0x4A,
  27420. 0xCC, 0x4E, 0xA9, 0xC1, 0x6E, 0xD7, 0x42, 0x1A,
  27421. 0x06, 0x9E, 0x0D, 0x73, 0x7A, 0x98, 0x62, 0x85,
  27422. 0x19, 0xC6, 0xA2, 0x9A, 0x42, 0x4A, 0x86, 0x8B,
  27423. 0x46, 0xD9, 0xA0, 0xCC, 0x7C, 0x6C, 0x9D, 0xDD,
  27424. 0x8B, 0x8B, 0xCB, 0xF4, 0x22, 0xC8, 0xF4, 0x8A,
  27425. 0x73, 0x14, 0x3D, 0x5A, 0xBB, 0x66, 0xBC, 0x55,
  27426. 0x49, 0x94, 0x18, 0x43, 0x08, 0x02, 0xBA, 0xC5,
  27427. 0x44, 0x46, 0x3C, 0xC7, 0x31, 0x9D, 0x17, 0x99,
  27428. 0x8F, 0x29, 0x41, 0x13, 0x65, 0x76, 0x6D, 0x04,
  27429. 0xC8, 0x47, 0xF3, 0x12, 0x9D, 0x90, 0x77, 0xB7,
  27430. 0xD8, 0x33, 0x9B, 0xFB, 0x96, 0xA6, 0x73, 0x9C,
  27431. 0x3F, 0x6B, 0x74, 0xA8, 0xF0, 0x5F, 0x91, 0x38,
  27432. 0xAB, 0x2F, 0xE3, 0x7A, 0xCB, 0x57, 0x63, 0x4D,
  27433. 0x18, 0x20, 0xB5, 0x01, 0x76, 0xF5, 0xA0, 0xB6,
  27434. 0xBC, 0x29, 0x40, 0xF1, 0xD5, 0x93, 0x8F, 0x19,
  27435. 0x36, 0xB5, 0xF9, 0x58, 0x28, 0xB9, 0x2E, 0xB7,
  27436. 0x29, 0x73, 0xC1, 0x59, 0x0A, 0xEB, 0x7A, 0x55,
  27437. 0x2C, 0xEC, 0xA1, 0x0B, 0x00, 0xC3, 0x03, 0xB7,
  27438. 0xC7, 0x5D, 0x40, 0x20, 0x71, 0xA7, 0x9E, 0x2C,
  27439. 0x81, 0x0A, 0xF7, 0xC7, 0x45, 0xE3, 0x33, 0x67,
  27440. 0x12, 0x49, 0x2A, 0x42, 0x04, 0x3F, 0x29, 0x03,
  27441. 0xA3, 0x7C, 0x64, 0x34, 0xCE, 0xE2, 0x0B, 0x1D,
  27442. 0x15, 0x9B, 0x05, 0x76, 0x99, 0xFF, 0x9C, 0x1D,
  27443. 0x3B, 0xD6, 0x80, 0x29, 0x83, 0x9A, 0x08, 0xF4,
  27444. 0x3E, 0x6C, 0x1C, 0x81, 0x99, 0x13, 0x53, 0x2F,
  27445. 0x91, 0x1D, 0xD3, 0x70, 0xC7, 0x02, 0x14, 0x88,
  27446. 0xE1, 0x1C, 0xB5, 0x04, 0xCB, 0x9C, 0x70, 0x57,
  27447. 0x0F, 0xFF, 0x35, 0xB4, 0xB4, 0x60, 0x11, 0x91,
  27448. 0xDC, 0x1A, 0xD9, 0xE6, 0xAD, 0xC5, 0xFA, 0x96,
  27449. 0x18, 0x79, 0x8D, 0x7C, 0xC8, 0x60, 0xC8, 0x7A,
  27450. 0x93, 0x9E, 0x4C, 0xCF, 0x85, 0x33, 0x63, 0x22,
  27451. 0x68, 0xCF, 0x1A, 0x51, 0xAF, 0xF0, 0xCB, 0x81,
  27452. 0x1C, 0x55, 0x45, 0xCB, 0x16, 0x56, 0xE6, 0x52,
  27453. 0x69, 0x47, 0x74, 0x30, 0x69, 0x9C, 0xCD, 0xEA,
  27454. 0x38, 0x00, 0x63, 0x0B, 0x78, 0xCD, 0x58, 0x10,
  27455. 0x33, 0x4C, 0xCF, 0x02, 0xE0, 0x13, 0xF3, 0xB8,
  27456. 0x02, 0x44, 0xE7, 0x0A, 0xCD, 0xB0, 0x60, 0xBB,
  27457. 0xE7, 0xA5, 0x53, 0xB0, 0x63, 0x45, 0x6B, 0x2E,
  27458. 0xA8, 0x07, 0x47, 0x34, 0x13, 0x16, 0x5C, 0xE5,
  27459. 0x7D, 0xD5, 0x63, 0x47, 0x3C, 0xFB, 0xC9, 0x06,
  27460. 0x18, 0xAD, 0xE1, 0xF0, 0xB8, 0x88, 0xAA, 0x48,
  27461. 0xE7, 0x22, 0xBB, 0x27, 0x51, 0x85, 0x8F, 0xE1,
  27462. 0x96, 0x87, 0x44, 0x2A, 0x48, 0xE7, 0xCA, 0x0D,
  27463. 0x2A, 0x29, 0xCD, 0x51, 0xBF, 0xD8, 0xF7, 0x8C,
  27464. 0x17, 0xB9, 0x66, 0x0B, 0xFB, 0x54, 0xA4, 0x70,
  27465. 0xB2, 0xAE, 0x9A, 0x95, 0x5C, 0x6A, 0xB8, 0xD6,
  27466. 0xE5, 0xCC, 0x92, 0xAC, 0x8E, 0xD3, 0xC1, 0x85,
  27467. 0xDA, 0xA8, 0xBC, 0x29, 0xF0, 0x57, 0x8E, 0xBB,
  27468. 0x81, 0x2B, 0x97, 0xC9, 0xE5, 0xA8, 0x48, 0xA6,
  27469. 0x38, 0x4D, 0xE4, 0xE7, 0x5A, 0x31, 0x47, 0x0B,
  27470. 0x53, 0x06, 0x6A, 0x8D, 0x02, 0x7B, 0xA4, 0x4B,
  27471. 0x21, 0x74, 0x9C, 0x04, 0x92, 0x46, 0x5F, 0x90,
  27472. 0x72, 0xB2, 0x83, 0x76, 0xC4, 0xE2, 0x90, 0xB3,
  27473. 0x0C, 0x18, 0x63, 0xF9, 0xE5, 0xB7, 0x99, 0x96,
  27474. 0x08, 0x34, 0x22, 0xBD, 0x8C, 0x27, 0x2C, 0x10,
  27475. 0xEC, 0xC6, 0xEB, 0x9A, 0x0A, 0x82, 0x25, 0xB3,
  27476. 0x1A, 0xA0, 0xA6, 0x6E, 0x35, 0xB9, 0xC0, 0xB9,
  27477. 0xA7, 0x95, 0x82, 0xBA, 0x20, 0xA3, 0xC0, 0x4C,
  27478. 0xD2, 0x99, 0x14, 0xF0, 0x83, 0xA0, 0x15, 0x82,
  27479. 0x88, 0xBA, 0x4D, 0x6E, 0xB6, 0x2D, 0x87, 0x26,
  27480. 0x4B, 0x91, 0x2B, 0xCA, 0x39, 0x73, 0x2F, 0xBD,
  27481. 0xE5, 0x36, 0xA3, 0x77, 0xAD, 0x02, 0xB8, 0xC8,
  27482. 0x35, 0xD4, 0xA2, 0xF4, 0xE7, 0xB1, 0xCE, 0x11,
  27483. 0x5D, 0x0C, 0x86, 0x0B, 0xEA, 0xA7, 0x95, 0x5A,
  27484. 0x49, 0xAD, 0x68, 0x95, 0x86, 0xA8, 0x9A, 0x2B,
  27485. 0x9F, 0x9B, 0x10, 0xD1, 0x59, 0x5D, 0x2F, 0xC0,
  27486. 0x65, 0xAD, 0x01, 0x8A, 0x7D, 0x56, 0xC6, 0x14,
  27487. 0x47, 0x1F, 0x8E, 0x94, 0x6F, 0xE8, 0xAB, 0x49,
  27488. 0xE8, 0x22, 0x65, 0x91, 0x11, 0x9F, 0xCA, 0xDB,
  27489. 0x4F, 0x9A, 0x86, 0x16, 0x31, 0x37, 0x87, 0x36,
  27490. 0xB6, 0x68, 0x8B, 0x78, 0x2D, 0x58, 0xE9, 0x7E,
  27491. 0x45, 0x72, 0x75, 0x3A, 0x96, 0x64, 0xB6, 0xB8,
  27492. 0x53, 0x68, 0x12, 0xB2, 0x59, 0x11, 0xAA, 0x76,
  27493. 0xA2, 0x42, 0x37, 0x54, 0x33, 0x19, 0x27, 0x38,
  27494. 0xEE, 0xE7, 0x62, 0xF6, 0xB8, 0x43, 0x15, 0xBB,
  27495. 0x34, 0x36, 0x23, 0x1E, 0x0A, 0x9B, 0x27, 0x7E,
  27496. 0xD2, 0x8A, 0xE0, 0x05, 0x07, 0x28, 0x34, 0x64,
  27497. 0x57, 0xE1, 0x34, 0x05, 0x06, 0x2D, 0xB2, 0x80,
  27498. 0x4B, 0x8D, 0xA6, 0x0B, 0xB5, 0xC7, 0x93, 0xD4,
  27499. 0xCC, 0x0E, 0x10, 0x1C, 0xBA, 0x2D, 0x91, 0x82,
  27500. 0xFD, 0x71, 0x24, 0xFF, 0x52, 0xBF, 0x4C, 0xA2,
  27501. 0x82, 0x92, 0xAC, 0x26, 0xD6, 0x78, 0x08, 0x89,
  27502. 0x53, 0x97, 0x1D, 0xBA, 0x0B, 0x6F, 0xEC, 0x2C,
  27503. 0x96, 0x59, 0x35, 0x32, 0x91, 0xC7, 0x0C, 0x5B,
  27504. 0x92, 0x45, 0xA0, 0xCA, 0x25, 0x33, 0x04, 0xAF,
  27505. 0xD3, 0xC9, 0x51, 0x02, 0xBE, 0xA6, 0x68, 0x75,
  27506. 0xC6, 0x20, 0x16, 0x80, 0xB4, 0xBD, 0xA3, 0x86,
  27507. 0x87, 0xB6, 0x48, 0xC2, 0x8E, 0xB3, 0x74, 0x78,
  27508. 0xE3, 0xBC, 0x00, 0xCA, 0x8A, 0x3C, 0xC2, 0x72,
  27509. 0x04, 0x64, 0x2B, 0x42, 0xB6, 0x8F, 0xCB, 0xE7,
  27510. 0xB2, 0x1A, 0x36, 0x6D, 0x06, 0x68, 0xA5, 0x02,
  27511. 0x9A, 0x7D, 0xEE, 0xF9, 0x4C, 0xDD, 0x6A, 0x95,
  27512. 0xD7, 0xEA, 0x89, 0x31, 0x67, 0x3B, 0xF7, 0x11,
  27513. 0x2D, 0x40, 0x42, 0x10, 0x7B, 0x1B, 0x8B, 0x97,
  27514. 0x00, 0xC9, 0x74, 0xF9, 0xC4, 0xE8, 0x3A, 0x8F,
  27515. 0xAC, 0xD8, 0x9B, 0xFE, 0x0C, 0xA3, 0xCC, 0x4C,
  27516. 0x2F, 0xCE, 0x80, 0xA0, 0x3D, 0x35, 0x76, 0xC2,
  27517. 0x22, 0xA7, 0x92, 0xB7, 0x2B, 0x1F, 0x07, 0x0A,
  27518. 0xB7, 0xF6, 0xB6, 0xF2, 0xB5, 0xCA, 0x2A, 0xF5,
  27519. 0x05, 0x4A, 0xFA, 0x70, 0xA8, 0x96, 0x99, 0x01,
  27520. 0x59, 0xB4, 0x5D, 0x10, 0x03, 0xE2, 0xA0, 0x56,
  27521. 0x48, 0x67, 0x5E, 0x59, 0x60, 0x16, 0xF1, 0xB7,
  27522. 0x1D, 0xD0, 0xF7, 0xBD, 0xA7, 0xE2, 0x09, 0x7F,
  27523. 0xC7, 0x3B, 0x3A, 0x14, 0x3D, 0x12, 0xC7, 0x26,
  27524. 0x02, 0x0A, 0xC3, 0x49, 0x58, 0xAD, 0x70, 0x62,
  27525. 0xB9, 0x2B, 0x9A, 0xBF, 0x3C, 0xA6, 0xBE, 0x5A,
  27526. 0xE2, 0x9F, 0x57, 0x13, 0x5E, 0x62, 0x5A, 0x36,
  27527. 0x79, 0x71, 0x83, 0x7E, 0x63, 0x63, 0xD1, 0x53,
  27528. 0x20, 0x94, 0xE0, 0x22, 0xA2, 0x34, 0x67, 0xCF,
  27529. 0x93, 0x2E, 0x1F, 0x89, 0xB5, 0xB0, 0x80, 0x3C,
  27530. 0x1E, 0xC9, 0x9B, 0x58, 0x5A, 0x78, 0xB5, 0x86,
  27531. 0x50, 0x96, 0x74, 0x6F, 0x32, 0x25, 0x82, 0x14,
  27532. 0xEC, 0xB3, 0x80, 0x65, 0xC9, 0x7F, 0x45, 0x5E,
  27533. 0x15, 0x5A, 0xCC, 0x2D, 0xD0, 0x05, 0xA9, 0xC7,
  27534. 0x6B, 0xED, 0x59, 0xCD, 0xA7, 0x38, 0x37, 0xD3,
  27535. 0x03, 0x50, 0x4E, 0x6C, 0x97, 0x6A, 0x60, 0x6A,
  27536. 0x2B, 0xE7, 0xBB, 0xEC, 0x59, 0x48, 0xB9, 0x1A,
  27537. 0x34, 0x9E, 0x89, 0x36, 0x68, 0x8C, 0xC0, 0x27,
  27538. 0x97, 0x54, 0xB7, 0x43, 0xAB, 0xC5, 0x86, 0x66,
  27539. 0xB1, 0x9B, 0x6C, 0x32, 0x60, 0x05, 0x1F, 0x19,
  27540. 0x20, 0x6B, 0xB9, 0x62, 0xBB, 0x66, 0x33, 0xEB,
  27541. 0x00, 0x48, 0xE3, 0x2B, 0xAA, 0xCC, 0x5B, 0x02,
  27542. 0x0D, 0x02, 0xC8, 0x6C, 0xA9, 0x77, 0x0A, 0xD4,
  27543. 0x69, 0xDB, 0x54, 0xA1, 0x06, 0xAC, 0x73, 0xA3,
  27544. 0x5B, 0x80, 0x57, 0x42, 0x2B, 0x3D, 0xB2, 0x02,
  27545. 0xC5, 0xA5, 0xB4, 0xE3, 0xD5, 0x35, 0xF0, 0xFC,
  27546. 0x99, 0x32, 0x6C, 0x4B, 0x8B, 0x7B, 0x16, 0xF1,
  27547. 0xCB, 0x5A, 0xF9, 0x68, 0x03, 0xFA, 0x8C, 0x19,
  27548. 0x5F, 0xC0, 0xBC, 0xED, 0xDA, 0xAF, 0x01, 0x2A,
  27549. 0x51, 0x72, 0x8B, 0x76, 0x48, 0x90, 0x82, 0x37,
  27550. 0x3C, 0x91, 0xE9, 0x2C, 0x87, 0xAC, 0xCA, 0x79,
  27551. 0x51, 0x60, 0x78, 0x2E, 0x3B, 0x0D, 0xD6, 0x43,
  27552. 0x54, 0x4B, 0xB9, 0x6A, 0xBC, 0x27, 0x08, 0xD4,
  27553. 0x9B, 0x75, 0x9C, 0xF0, 0x57, 0xAA, 0x22, 0x3B,
  27554. 0xAF, 0xD9, 0x6A, 0x33, 0x0B, 0xAF, 0x39, 0x81,
  27555. 0x0F, 0xE8, 0x67, 0x1B, 0x43, 0x43, 0xC2, 0x97,
  27556. 0xDA, 0x1E, 0x19, 0x69, 0xC9, 0x96, 0x21, 0x6A,
  27557. 0xB5, 0x10, 0x6D, 0xA6, 0x68, 0x94, 0x1B, 0x16,
  27558. 0x0D, 0x44, 0x77, 0x01, 0x71, 0x36, 0xCB, 0xCA,
  27559. 0x5B, 0x5A, 0x8D, 0x44, 0xC4, 0xA8, 0xB1, 0xCF,
  27560. 0x3E, 0xF7, 0x97, 0x85, 0xE5, 0xAA, 0x25, 0xC3,
  27561. 0xA1, 0xAD, 0x6C, 0x24, 0xFD, 0x14, 0x0F, 0x79,
  27562. 0x20, 0x7D, 0xE5, 0xA4, 0x99, 0xF8, 0xA1, 0x53,
  27563. 0x4F, 0xFA, 0x80, 0x4A, 0xA7, 0xB3, 0x88, 0x9C,
  27564. 0xBE, 0x25, 0xC0, 0x41, 0x47, 0x04, 0xAA, 0x57,
  27565. 0x89, 0x7F, 0x17, 0x86, 0x23, 0x64, 0xEC, 0xA5,
  27566. 0x62, 0x58, 0x00, 0x72, 0x48, 0x81, 0x39, 0x12,
  27567. 0xB8, 0x36, 0x49, 0x7F, 0x03, 0x59, 0xC2, 0xF7,
  27568. 0x23, 0x8A, 0x05, 0xD3, 0x05, 0xA0, 0xEA, 0x15,
  27569. 0x2E, 0x72, 0xB4, 0x44, 0x17, 0xA8, 0x68, 0x13,
  27570. 0x4E, 0x91, 0xB3, 0xCA, 0x79, 0x31, 0x23, 0x2F,
  27571. 0xD4, 0xC2, 0x5F, 0x8C, 0x2A, 0x49, 0x2A, 0x33,
  27572. 0x9C, 0xDC, 0x0A, 0x13, 0x89, 0x67, 0x21, 0x14,
  27573. 0x51, 0xF2, 0x56, 0x26, 0x78, 0xFA, 0x14, 0x08,
  27574. 0x0A, 0x34, 0x43, 0x6C, 0x42, 0xB0, 0x78, 0x65,
  27575. 0xAC, 0x03, 0x6A, 0x81, 0xE9, 0x7A, 0x77, 0x87,
  27576. 0xA9, 0x38, 0x02, 0x5C, 0xAF, 0x81, 0x34, 0x50,
  27577. 0x36, 0x8B, 0xED, 0x0C, 0x94, 0xB1, 0x85, 0x76,
  27578. 0x04, 0x52, 0x64, 0x05, 0xD2, 0x7A, 0x1C, 0x1A,
  27579. 0xBC, 0x81, 0xB5, 0xB6, 0xEC, 0x13, 0xC7, 0x19,
  27580. 0x30, 0xA9, 0x7D, 0x92, 0x32, 0xCF, 0x70, 0x21,
  27581. 0xEF, 0x87, 0xA4, 0xD1, 0x55, 0x32, 0x8E, 0x62,
  27582. 0xB5, 0x83, 0xA8, 0x3B, 0x4A, 0xF2, 0x1F, 0x9F,
  27583. 0x57, 0x50, 0xF8, 0x57, 0x51, 0x50, 0x42, 0x4F,
  27584. 0x63, 0xB8, 0x99, 0xD7, 0x1C, 0xAD, 0x26, 0x7C,
  27585. 0x09, 0xE4, 0x46, 0x71, 0x46, 0xE1, 0x6E, 0x9B,
  27586. 0x6C, 0x65, 0x3F, 0x00, 0x8C, 0x31, 0x13, 0x75,
  27587. 0xE2, 0xE0, 0x06, 0xD4, 0x07, 0x6A, 0x54, 0x6B,
  27588. 0x82, 0xF5, 0x31, 0x42, 0x22, 0xF7, 0xC6, 0x54,
  27589. 0x31, 0x7E, 0x79, 0xEC, 0x60, 0x35, 0xB7, 0x3F,
  27590. 0xAF, 0x49, 0x17, 0x57, 0xE6, 0x1C, 0x82, 0x83,
  27591. 0x26, 0xD5, 0x30, 0x44, 0x54, 0x1C, 0x4D, 0x45,
  27592. 0x37, 0xAB, 0xD3, 0xEA, 0x1E, 0x67, 0x99, 0x8C,
  27593. 0x33, 0x82, 0x97, 0x4C, 0xA7, 0x8A, 0xE1, 0xB1,
  27594. 0x96, 0x0E, 0x4A, 0x92, 0x26, 0xB0, 0x21, 0x9A,
  27595. 0xB0, 0x70, 0xF0, 0xD7, 0xAA, 0x66, 0xD7, 0x6F,
  27596. 0x93, 0x16, 0xAD, 0xB8, 0x0C, 0x54, 0xD6, 0x49,
  27597. 0x97, 0x71, 0xB4, 0x71, 0xE8, 0x16, 0x8D, 0x47,
  27598. 0xBC, 0xAA, 0x08, 0x32, 0x4A, 0xB6, 0xBA, 0x92,
  27599. 0xC3, 0xA7, 0x02, 0x75, 0xF2, 0x4F, 0xA4, 0xDC,
  27600. 0x10, 0xE2, 0x51, 0x63, 0x3F, 0xB9, 0x8D, 0x16,
  27601. 0x2B, 0xB5, 0x53, 0x72, 0x02, 0xC6, 0xA5, 0x53,
  27602. 0xCE, 0x78, 0x41, 0xC4, 0xD4, 0x0B, 0x87, 0x3B,
  27603. 0x85, 0xCA, 0x03, 0xA0, 0xA1, 0xE1, 0xCF, 0xAD,
  27604. 0xE6, 0xBA, 0x51, 0x80, 0xAB, 0x13, 0x23, 0xCC,
  27605. 0xBA, 0x9A, 0x3E, 0x9C, 0x53, 0xD3, 0x75, 0x75,
  27606. 0xAB, 0x1F, 0xD9, 0xE7, 0x31, 0x6C, 0x6F, 0xEE,
  27607. 0xCB, 0x0A, 0x14, 0xDF, 0x6F, 0x2D, 0xA5, 0x6C,
  27608. 0x2F, 0x56, 0xF5, 0x5A, 0x89, 0x63, 0x5C, 0xFC,
  27609. 0xFD, 0xA4, 0x79, 0x27, 0xAF, 0x1F, 0x0A, 0x47,
  27610. 0xB2, 0xD4, 0xE4, 0xE6, 0x16, 0x34, 0xB1, 0xB5,
  27611. 0x1D, 0x37, 0xA3, 0xA3, 0x07, 0xA9, 0x72, 0x42,
  27612. 0x0D, 0xE1, 0xB7, 0xA4, 0x81, 0xB8, 0x3E, 0x58,
  27613. 0x3B, 0x6A, 0xF1, 0x6F, 0x63, 0xCB, 0x00, 0xC6
  27614. };
  27615. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  27616. 0x0C, 0x68, 0x1B, 0x4A, 0xA8, 0x1F, 0x26, 0xAD,
  27617. 0xFB, 0x64, 0x5E, 0xC2, 0x4B, 0x37, 0x52, 0xF6,
  27618. 0xB3, 0x2C, 0x68, 0x64, 0x5A, 0xA5, 0xE7, 0xA9,
  27619. 0x99, 0xB6, 0x20, 0x36, 0xA5, 0x3D, 0xC5, 0xCB,
  27620. 0x06, 0x0A, 0x47, 0x3C, 0x08, 0xE5, 0xDA, 0x5C,
  27621. 0x0F, 0x5A, 0xF0, 0xE5, 0x17, 0x0C, 0x65, 0x97,
  27622. 0xE5, 0x0E, 0xC0, 0x80, 0x60, 0xF9, 0x9B, 0x0C,
  27623. 0x00, 0xEE, 0x9B, 0xDD, 0xAD, 0x7E, 0x7D, 0x25,
  27624. 0xA2, 0x2B, 0x22, 0x6F, 0x90, 0x14, 0x9B, 0x4C,
  27625. 0xE8, 0x87, 0xC7, 0x2F, 0xB6, 0x0A, 0xFF, 0x21,
  27626. 0x44, 0xEA, 0x2A, 0x72, 0x38, 0x3B, 0x31, 0x18,
  27627. 0xF9, 0x22, 0xD0, 0x32, 0xA1, 0x6F, 0x55, 0x42,
  27628. 0x89, 0x90, 0x2A, 0x14, 0xCF, 0x77, 0x55, 0x51,
  27629. 0x2B, 0xB1, 0x18, 0x6B, 0xAF, 0xAF, 0xFE, 0x79,
  27630. 0x4D, 0x2B, 0x6C, 0xDE, 0x90, 0x10, 0x9E, 0x65,
  27631. 0x82, 0xD3, 0x9C, 0xE0, 0xC9, 0x61, 0x97, 0x48,
  27632. 0x4B, 0x3F, 0xA0, 0x7F, 0xC9, 0x1D, 0x39, 0x4F,
  27633. 0xC8, 0xD8, 0x8E, 0x7F, 0xC4, 0xBE, 0x00, 0x2E,
  27634. 0x2D, 0xB5, 0x6F, 0x0C, 0x4D, 0x9D, 0x3F, 0xBD,
  27635. 0xA2, 0x74, 0x53, 0x6A, 0x0B, 0x86, 0xAB, 0xC6,
  27636. 0xE3, 0x9B, 0xDA, 0x52, 0x93, 0x1A, 0xEB, 0xB8,
  27637. 0xF1, 0x08, 0x4C, 0x5C, 0x1F, 0x7C, 0xB3, 0x17,
  27638. 0x77, 0x88, 0xB7, 0xF3, 0x31, 0xB7, 0x07, 0x43,
  27639. 0x61, 0x16, 0x34, 0x91, 0xD4, 0x28, 0xE7, 0x8B,
  27640. 0xCB, 0xB5, 0x7B, 0x63, 0x08, 0x41, 0xAA, 0x98,
  27641. 0x73, 0x33, 0x37, 0x7C, 0xF0, 0x95, 0x69, 0xCF,
  27642. 0xD1, 0x4C, 0xC2, 0xA1, 0x1C, 0x50, 0x1B, 0xDF,
  27643. 0x82, 0xC9, 0x3D, 0xE0, 0x5B, 0xEA, 0x20, 0x06,
  27644. 0x0D, 0xE8, 0x9C, 0x68, 0x6B, 0x82, 0x45, 0x71,
  27645. 0xCE, 0xF9, 0x4A, 0xB3, 0xFD, 0xAF, 0xA8, 0x51,
  27646. 0x26, 0x19, 0x81, 0x36, 0x69, 0xD4, 0xF5, 0x36,
  27647. 0x37, 0xFE, 0xFA, 0x4D, 0x02, 0x8C, 0xB2, 0x33,
  27648. 0xE5, 0x69, 0x30, 0xE2, 0x23, 0x5F, 0x7E, 0x60,
  27649. 0x34, 0xCA, 0x94, 0xB1, 0x43, 0xB7, 0x7A, 0xD4,
  27650. 0xA6, 0x87, 0x56, 0xE8, 0xA9, 0x18, 0x4D, 0xBA,
  27651. 0x61, 0xA8, 0x9F, 0x91, 0xED, 0xFB, 0x51, 0xA3,
  27652. 0x92, 0x11, 0x40, 0x24, 0x73, 0xA5, 0xF8, 0x91,
  27653. 0x45, 0x73, 0x6B, 0x2B, 0xF8, 0x56, 0x9C, 0x70,
  27654. 0x5B, 0x0C, 0xDB, 0x89, 0x80, 0xA4, 0x47, 0xE4,
  27655. 0xE1, 0xEA, 0xAD, 0x3E, 0x7E, 0x05, 0x78, 0xF5,
  27656. 0xF8, 0x6B, 0x8D, 0x03, 0xC9, 0xDA, 0xFE, 0x87,
  27657. 0x5E, 0x33, 0x9B, 0x44, 0x23, 0x84, 0x56, 0x16,
  27658. 0x79, 0x9E, 0xDC, 0xE0, 0x5F, 0x31, 0xB9, 0x26,
  27659. 0x64, 0xC5, 0xA5, 0x92, 0x53, 0xA6, 0x0E, 0x9D,
  27660. 0x89, 0x54, 0x8A, 0x30, 0x0C, 0x1A, 0xDB, 0x6D,
  27661. 0x19, 0x0A, 0x77, 0x5C, 0x5E, 0xE6, 0xE8, 0xA8,
  27662. 0x9B, 0x6E, 0x77, 0x9B, 0x03, 0x4C, 0x34, 0x00,
  27663. 0xA6, 0x25, 0xF4, 0xBB, 0xED, 0xBF, 0x91, 0x9C,
  27664. 0x45, 0xB2, 0xBC, 0xD1, 0x4C, 0x66, 0x92, 0x48,
  27665. 0xFC, 0x43, 0xC3, 0xEF, 0x47, 0xE1, 0x00, 0x75,
  27666. 0x89, 0x42, 0xE7, 0x5E, 0x8E, 0xD6, 0x07, 0x5A,
  27667. 0x96, 0xD7, 0x0D, 0x4E, 0xBD, 0x2B, 0x61, 0x35,
  27668. 0x82, 0x24, 0xDD, 0xA1, 0xEC, 0x4C, 0x19, 0xC2,
  27669. 0xA9, 0x28, 0x98, 0x17, 0x6F, 0xEB, 0x3C, 0x02,
  27670. 0xED, 0xCB, 0x99, 0x08, 0xBA, 0xE4, 0x9B, 0xD9,
  27671. 0x4A, 0xF0, 0x28, 0xED, 0xF8, 0xCF, 0xC2, 0xE5,
  27672. 0xF2, 0xE0, 0xBD, 0x37, 0x50, 0x06, 0x98, 0x6A,
  27673. 0xD4, 0x9E, 0x71, 0x75, 0x48, 0xE7, 0x46, 0xFE,
  27674. 0xF4, 0x9C, 0x86, 0x8B, 0xCE, 0xA2, 0x79, 0x0A,
  27675. 0xA9, 0x7E, 0x04, 0x06, 0x1B, 0x75, 0x60, 0x5C,
  27676. 0xB3, 0x9E, 0xFD, 0x46, 0x3D, 0x7B, 0x3D, 0x68,
  27677. 0xBA, 0x57, 0x44, 0x34, 0xFF, 0x7B, 0xE8, 0xE2,
  27678. 0xB8, 0x4B, 0xFC, 0x47, 0xE6, 0x7E, 0x9C, 0xD1,
  27679. 0x5F, 0x3E, 0xD4, 0x50, 0xC6, 0x1A, 0xFB, 0xA7,
  27680. 0x9A, 0x20, 0xB0, 0xB6, 0xF2, 0x87, 0x77, 0x7C,
  27681. 0x72, 0xF4, 0xAD, 0x24, 0x81, 0x74, 0xF1, 0x95,
  27682. 0x94, 0x77, 0xAA, 0x7A, 0x7C, 0x97, 0xF1, 0x22,
  27683. 0xC5, 0x04, 0x47, 0xC7, 0x48, 0x4F, 0x38, 0x2B,
  27684. 0xC4, 0x7D, 0x81, 0xFC, 0xC9, 0xC7, 0xE8, 0x92,
  27685. 0xC8, 0x83, 0x9D, 0x37, 0xB3, 0x53, 0x94, 0xB5,
  27686. 0x3E, 0x6B, 0x2B, 0x18, 0x95, 0xAB, 0xB0, 0xDE,
  27687. 0x8C, 0x98, 0xF2, 0x63, 0x3D, 0xC4, 0x41, 0x3A,
  27688. 0x8D, 0x57, 0x35, 0xDF, 0xC9, 0xA6, 0x40, 0x26,
  27689. 0xB6, 0xF3, 0x47, 0x79, 0xD6, 0xAC, 0x8A, 0xD9,
  27690. 0x9C, 0xC3, 0x1A, 0xA8, 0x98, 0xC2, 0xE7, 0x05,
  27691. 0x7F, 0x3D, 0xB8, 0xA1, 0xA8, 0xA9, 0x85, 0x27,
  27692. 0xA7, 0x9E, 0x43, 0x55, 0x2F, 0x28, 0xD1, 0x02,
  27693. 0x3E, 0x1F, 0x6A, 0x6B, 0x84, 0x85, 0x5C, 0xF5,
  27694. 0xE6, 0xDF, 0x88, 0x9B, 0xA2, 0x69, 0xF0, 0x48,
  27695. 0x94, 0x6E, 0x84, 0x02, 0x1C, 0x65, 0xC5, 0xA9,
  27696. 0x3B, 0x00, 0x7B, 0x07, 0x74, 0x1C, 0x1E, 0xE1,
  27697. 0x76, 0xC7, 0x39, 0x49, 0x11, 0x0F, 0x54, 0x8E,
  27698. 0xF4, 0x33, 0x2D, 0xCD, 0xD4, 0x91, 0xD2, 0xCE,
  27699. 0xFD, 0x02, 0x48, 0x88, 0x3F, 0x5E, 0x95, 0x25,
  27700. 0xBC, 0x91, 0xF3, 0x0A, 0xF1, 0x7C, 0xF5, 0xA9,
  27701. 0x8D, 0xD4, 0x4E, 0xF9, 0xA7, 0x1F, 0x99, 0xBB,
  27702. 0x73, 0x29, 0x85, 0xBA, 0x10, 0xA7, 0x23, 0xEF,
  27703. 0x47, 0x6F, 0xCF, 0x96, 0x6D, 0xA9, 0x45, 0x6B,
  27704. 0x24, 0x97, 0x8E, 0x33, 0x05, 0x0D, 0x0E, 0xC9,
  27705. 0x0D, 0x3C, 0xE4, 0x63, 0x78, 0x85, 0x1C, 0x9E,
  27706. 0xCF, 0xCF, 0xD3, 0x6C, 0x89, 0x5D, 0x44, 0xE9,
  27707. 0xE5, 0x06, 0x99, 0x30, 0x82, 0x52, 0x3D, 0x26,
  27708. 0x18, 0x57, 0x66, 0xB2, 0x35, 0x68, 0xCB, 0x95,
  27709. 0xE6, 0x41, 0x08, 0xF8, 0x9D, 0x10, 0x14, 0x74,
  27710. 0x7C, 0x67, 0xB6, 0xF3, 0xC8, 0x76, 0x7B, 0xE5,
  27711. 0xFC, 0x34, 0x12, 0x27, 0xDE, 0x94, 0x88, 0x86,
  27712. 0x1C, 0x5F, 0xE8, 0x11, 0x40, 0x9F, 0x80, 0x95,
  27713. 0x7D, 0x07, 0x52, 0x2A, 0x72, 0xCF, 0x6A, 0xB0,
  27714. 0x37, 0x8D, 0x0F, 0x2F, 0x28, 0xAF, 0x54, 0x81,
  27715. 0x85, 0xC3, 0x93, 0x67, 0x77, 0x99, 0x44, 0x66,
  27716. 0xA0, 0x19, 0xD3, 0x3B, 0x18, 0xA5, 0x4F, 0x38,
  27717. 0x0A, 0x33, 0x89, 0x2A, 0xB4, 0xD4, 0xBD, 0x50,
  27718. 0x7B, 0x5A, 0x61, 0xD0, 0xD3, 0x58, 0x34, 0x1A,
  27719. 0xC9, 0x2F, 0x07, 0xB4, 0x3B, 0x8F, 0x6A, 0xFC,
  27720. 0x69, 0x91, 0xBB, 0x6A, 0x1E, 0xAC, 0x23, 0xCA,
  27721. 0x6F, 0x73, 0xE9, 0x1F, 0x24, 0x64, 0xBD, 0x11,
  27722. 0x90, 0x98, 0xD7, 0xE7, 0x68, 0xE7, 0x7E, 0xCE,
  27723. 0x53, 0xFB, 0x89, 0x9B, 0xEB, 0x42, 0x26, 0x5E,
  27724. 0xCF, 0x7B, 0x27, 0x1F, 0x66, 0x54, 0x62, 0x82,
  27725. 0xD4, 0x72, 0xC3, 0x62, 0x39, 0x00, 0x6B, 0xB0,
  27726. 0xAB, 0xAB, 0xCC, 0xA2, 0x45, 0x50, 0xBA, 0xA0,
  27727. 0xA6, 0x01, 0x34, 0x8C, 0x81, 0x0F, 0xF5, 0xF9,
  27728. 0xEE, 0x50, 0x4B, 0xF7, 0x15, 0x5D, 0xEE, 0x41,
  27729. 0x41, 0xA1, 0x16, 0x05, 0xA4, 0xF3, 0x50, 0x9A,
  27730. 0xC9, 0xCA, 0xEF, 0x66, 0x24, 0xD2, 0x1D, 0xE3,
  27731. 0x32, 0xD5, 0xD5, 0x08, 0x28, 0xB5, 0x2E, 0x92,
  27732. 0x88, 0x5D, 0x3B, 0x90, 0x55, 0x3B, 0x14, 0x46,
  27733. 0x3A, 0xFB, 0x1E, 0xDC, 0xCD, 0x3B, 0x56, 0x9B,
  27734. 0x5A, 0x7F, 0x00, 0xBB, 0x66, 0x76, 0x9D, 0xAD,
  27735. 0xAC, 0x23, 0xAD, 0x8B, 0xB5, 0xD7, 0x3A, 0x6F,
  27736. 0x39, 0x0E, 0x6F, 0xC2, 0xF6, 0xF8, 0xEE, 0x3C,
  27737. 0xF4, 0x00, 0x9A, 0x5C, 0x3E, 0x1E, 0xF6, 0x0E,
  27738. 0x8F, 0x04, 0x06, 0x72, 0xD2, 0x62, 0xE6, 0x49,
  27739. 0x03, 0x79, 0xBB, 0xC7, 0x04, 0x95, 0xDF, 0xF2,
  27740. 0x37, 0xBE, 0xCD, 0x99, 0x52, 0xCD, 0x7E, 0xDE,
  27741. 0xB6, 0xD1, 0xDF, 0xC3, 0x60, 0xB3, 0xFC, 0x8B,
  27742. 0x0A, 0xF4, 0x80, 0xFF, 0xE0, 0x24, 0xAE, 0xEF,
  27743. 0xCD, 0x4E, 0x9C, 0xE9, 0x5D, 0x9B, 0x46, 0x9C,
  27744. 0x9A, 0x70, 0xE5, 0x11, 0x0D, 0xA0, 0xBA, 0xC1,
  27745. 0x24, 0xFC, 0x37, 0x41, 0xDC, 0xF4, 0x91, 0x16,
  27746. 0x26, 0x17, 0x96, 0x50, 0x4D, 0x5F, 0x49, 0x0B,
  27747. 0x43, 0x3C, 0x33, 0xC4, 0x0E, 0xDC, 0xE2, 0xB7,
  27748. 0x51, 0x51, 0xDA, 0x25, 0x6A, 0x86, 0x8A, 0x5E,
  27749. 0x35, 0xF8, 0x62, 0x26, 0xB8, 0x15, 0x1C, 0x91,
  27750. 0x93, 0x4C, 0xCC, 0x3D, 0xAC, 0xA3, 0x91, 0xDE,
  27751. 0xCC, 0xA7, 0x45, 0x37, 0x56, 0x60, 0xB6, 0xEC,
  27752. 0x41, 0xAE, 0x5D, 0x81, 0x08, 0x38, 0xCB, 0xEE,
  27753. 0xFF, 0xA1, 0x25, 0x57, 0x88, 0x44, 0x12, 0x35,
  27754. 0x7B, 0x10, 0x08, 0x36, 0x3D, 0x32, 0xB2, 0x37,
  27755. 0xAA, 0x1D, 0xD8, 0xE2, 0xD9, 0xC6, 0x36, 0x7A,
  27756. 0xDA, 0x09, 0xB2, 0xC9, 0x50, 0x60, 0x20, 0x6C,
  27757. 0xEC, 0x3E, 0xED, 0x39, 0x1F, 0xDC, 0x5D, 0xBE,
  27758. 0xF6, 0xF0, 0x8B, 0xDF, 0x04, 0x08, 0xE5, 0x85,
  27759. 0xAE, 0x5E, 0xBC, 0x8E, 0x97, 0x45, 0xD4, 0x4F,
  27760. 0xEC, 0xA9, 0x75, 0xAB, 0xBC, 0x14, 0x0B, 0xB3,
  27761. 0x7B, 0x8A, 0xDD, 0x16, 0xFC, 0xC2, 0x95, 0x69,
  27762. 0x10, 0xDC, 0x72, 0xBB, 0x3F, 0x02, 0xE9, 0xA1,
  27763. 0x30, 0xC9, 0xA8, 0x4F, 0x9C, 0xCB, 0x74, 0xD1,
  27764. 0x34, 0xCD, 0xF4, 0x0A, 0xFC, 0xBA, 0x20, 0x09,
  27765. 0xC8, 0xF0, 0x04, 0x02, 0x39, 0xBC, 0x99, 0x22,
  27766. 0x0E, 0xF6, 0x4C, 0x4D, 0xCC, 0xDE, 0x2E, 0x2E,
  27767. 0x5C, 0x9B, 0x68, 0x60, 0x2F, 0xBE, 0x8E, 0xF4,
  27768. 0xC9, 0x8B, 0x34, 0x68, 0xC7, 0x9D, 0xF4, 0xE0,
  27769. 0x78, 0x51, 0x1B, 0xFB, 0x8A, 0xA3, 0xDA, 0x09,
  27770. 0x59, 0x7A, 0x02, 0x51, 0x1E, 0x7C, 0x21, 0xA7,
  27771. 0xCF, 0x66, 0xA9, 0x38, 0x43, 0xA9, 0x48, 0x68,
  27772. 0xF1, 0x9E, 0x85, 0x52, 0x55, 0x2E, 0x3A, 0xCD,
  27773. 0xF6, 0xCB, 0x81, 0x06, 0x34, 0xDB, 0x97, 0xCB,
  27774. 0xC4, 0xBB, 0x56, 0x97, 0x09, 0xDA, 0xD4, 0x84,
  27775. 0x56, 0x45, 0x44, 0x6F, 0xA8, 0xD2, 0x89, 0xFC,
  27776. 0x59, 0x30, 0x7B, 0x80, 0x1E, 0x60, 0xCE, 0x2A,
  27777. 0x91, 0xE0, 0x6E, 0x9C, 0x22, 0xC1, 0x6E, 0x2E,
  27778. 0x59, 0xBD, 0xE3, 0x8A, 0x41, 0x6B, 0xB1, 0xB4,
  27779. 0xAC, 0x54, 0x57, 0x43, 0x8F, 0xDC, 0x5D, 0x64,
  27780. 0x45, 0x0A, 0x89, 0xEC, 0xB8, 0x32, 0xC1, 0xBB,
  27781. 0x27, 0x9D, 0xBF, 0x59, 0x33, 0x46, 0x81, 0x77,
  27782. 0x6A, 0xC0, 0x04, 0x09, 0x84, 0x6D, 0x09, 0xD6,
  27783. 0xF6, 0x87, 0x77, 0x2E, 0x34, 0x08, 0x50, 0xAB,
  27784. 0x86, 0x73, 0x38, 0x42, 0x15, 0xE1, 0x2C, 0x8D,
  27785. 0x0F, 0x53, 0x1C, 0x45, 0x1E, 0x58, 0x49, 0x3E,
  27786. 0x0E, 0xE4, 0x15, 0xAD, 0x59, 0x4D, 0xF3, 0x8C,
  27787. 0x34, 0x40, 0x8C, 0x7E, 0xD9, 0xF0, 0xC3, 0x92,
  27788. 0xF1, 0x53, 0x46, 0x04, 0xEA, 0xC3, 0xD9, 0xC1,
  27789. 0x54, 0x65, 0xA9, 0xA4, 0x66, 0x32, 0x21, 0x4B,
  27790. 0x53, 0x69, 0x90, 0xD7, 0x80, 0x78, 0xE5, 0xBD,
  27791. 0x7E, 0xAE, 0x20, 0x13, 0xFF, 0xF8, 0xFD, 0xD8,
  27792. 0xB2, 0x75, 0xC8, 0x9D, 0x97, 0xC9, 0x35, 0x3D,
  27793. 0xF3, 0xC4, 0x2A, 0x28, 0xE8, 0x14, 0xD8, 0x46,
  27794. 0x8E, 0x2B, 0x48, 0xDB, 0x09, 0x76, 0xD8, 0x8F,
  27795. 0x5E, 0xEC, 0xEF, 0xEA, 0xFB, 0x8F, 0x7F, 0x4A,
  27796. 0xF2, 0x91, 0xA7, 0x28, 0xF6, 0x24, 0x9E, 0xCF,
  27797. 0x56, 0x22, 0x33, 0x92, 0x69, 0xAA, 0x94, 0x53,
  27798. 0x29, 0xE9, 0x19, 0xF8, 0xB4, 0x41, 0xC8, 0x3D,
  27799. 0x55, 0x07, 0xF3, 0x0D, 0xF0, 0xFD, 0x2B, 0x13,
  27800. 0xFF, 0x80, 0x6F, 0x52, 0x2D, 0xAA, 0x11, 0xAF,
  27801. 0x67, 0x6A, 0x51, 0x3C, 0x14, 0x9C, 0x70, 0xF0,
  27802. 0xD6, 0xE9, 0x9A, 0x88, 0x04, 0x50, 0xA5, 0x4E,
  27803. 0x04, 0x17, 0xFE, 0x3C, 0x1E, 0x51, 0x3E, 0x9D,
  27804. 0x92, 0x0E, 0x30, 0xA8, 0xB4, 0x28, 0x91, 0x26,
  27805. 0x7A, 0x2D, 0xC5, 0x0A, 0xD8, 0x1F, 0x98, 0x04,
  27806. 0x49, 0x20, 0xC0, 0x99, 0xDF, 0x22, 0xC7, 0x39,
  27807. 0x98, 0xA2, 0x5C, 0x58, 0x1A, 0x51, 0x78, 0xC7,
  27808. 0x2B, 0x17, 0xAC, 0x87, 0x5B, 0xC6, 0x85, 0x48,
  27809. 0xA0, 0xFB, 0x0C, 0xBE, 0xE3, 0x8F, 0x05, 0x01,
  27810. 0x7B, 0x12, 0x43, 0x33, 0x43, 0xA6, 0x58, 0xF1,
  27811. 0x98, 0x0C, 0x81, 0x24, 0xEA, 0x6D, 0xD8, 0x1F
  27812. };
  27813. static const byte kprime_1024[KYBER_SS_SZ] = {
  27814. 0x8F, 0x33, 0x6E, 0x9C, 0x28, 0xDF, 0x34, 0x9E,
  27815. 0x03, 0x22, 0x0A, 0xF0, 0x1C, 0x42, 0x83, 0x2F,
  27816. 0xEF, 0xAB, 0x1F, 0x2A, 0x74, 0xC1, 0x6F, 0xAF,
  27817. 0x6F, 0x64, 0xAD, 0x07, 0x1C, 0x1A, 0x33, 0x94
  27818. };
  27819. #endif
  27820. static byte ss[KYBER_SS_SZ];
  27821. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  27822. ExpectNotNull(key);
  27823. if (key != NULL) {
  27824. XMEMSET(key, 0, sizeof(KyberKey));
  27825. }
  27826. #ifndef WOLFSSL_NO_KYBER512
  27827. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  27828. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
  27829. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
  27830. ExpectIntEQ(XMEMCMP(ss, kprime_512, KYBER_SS_SZ), 0);
  27831. wc_KyberKey_Free(key);
  27832. #endif
  27833. #ifndef WOLFSSL_NO_KYBER768
  27834. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  27835. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
  27836. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
  27837. ExpectIntEQ(XMEMCMP(ss, kprime_768, KYBER_SS_SZ), 0);
  27838. wc_KyberKey_Free(key);
  27839. #endif
  27840. #ifndef WOLFSSL_NO_KYBER1024
  27841. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  27842. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
  27843. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
  27844. ExpectIntEQ(XMEMCMP(ss, kprime_1024, KYBER_SS_SZ), 0);
  27845. wc_KyberKey_Free(key);
  27846. #endif
  27847. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  27848. #endif
  27849. return EXPECT_RESULT();
  27850. }
  27851. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  27852. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && !defined(WOLFSSL_NO_ML_DSA_44)
  27853. static const byte ml_dsa_44_pub_key[] = {
  27854. 0x7c, 0x33, 0x31, 0x41, 0x15, 0xa7, 0x2d, 0x6b,
  27855. 0x17, 0x7c, 0x10, 0xab, 0x75, 0xf7, 0x83, 0xb3,
  27856. 0x30, 0x75, 0x6f, 0xa9, 0x42, 0xb0, 0x9b, 0x59,
  27857. 0x59, 0x99, 0x2b, 0x5d, 0x7d, 0x6e, 0xeb, 0xdd,
  27858. 0xd9, 0x99, 0x8f, 0x7b, 0xad, 0xe5, 0x90, 0x0f,
  27859. 0xa4, 0x80, 0xd8, 0xa2, 0x0d, 0x95, 0xea, 0x63,
  27860. 0x2b, 0xcf, 0xb4, 0x5b, 0x3c, 0xd1, 0x5a, 0xc4,
  27861. 0xc4, 0xd1, 0x71, 0x28, 0x4b, 0x0b, 0x28, 0x32,
  27862. 0x73, 0xb5, 0x0d, 0xd6, 0x8f, 0x6b, 0x01, 0x26,
  27863. 0x04, 0x45, 0xa3, 0x80, 0xc0, 0x21, 0x12, 0xee,
  27864. 0x52, 0x0f, 0x35, 0xe4, 0x8e, 0xca, 0xf8, 0x91,
  27865. 0xf4, 0x99, 0x51, 0xe2, 0x80, 0x76, 0xa7, 0x2d,
  27866. 0x09, 0xf5, 0x04, 0xcc, 0xa6, 0x6b, 0x20, 0xc4,
  27867. 0xac, 0xcd, 0x6c, 0x9c, 0x09, 0xe7, 0x51, 0xa2,
  27868. 0x29, 0x60, 0xfd, 0xf2, 0xbd, 0x7e, 0x4c, 0x9d,
  27869. 0xc0, 0xba, 0x62, 0x2f, 0x53, 0xb2, 0x47, 0x03,
  27870. 0xf2, 0x6f, 0x70, 0x51, 0xa8, 0xe1, 0xb7, 0x9f,
  27871. 0x37, 0x15, 0xfa, 0xd1, 0x6c, 0x74, 0x1a, 0x2b,
  27872. 0x4f, 0x39, 0x4f, 0x43, 0x49, 0x71, 0x6a, 0xf8,
  27873. 0x7c, 0x65, 0x1a, 0xdd, 0x1a, 0x25, 0xf8, 0x79,
  27874. 0xfa, 0x8c, 0x02, 0xf2, 0xf7, 0xf7, 0x7b, 0x9f,
  27875. 0xe4, 0xaf, 0x9e, 0x1a, 0x0b, 0x5b, 0x2e, 0x41,
  27876. 0xbb, 0xa9, 0x4f, 0xd0, 0xdb, 0xad, 0xe5, 0x25,
  27877. 0xff, 0x36, 0x3b, 0x9a, 0xc3, 0xdf, 0xb6, 0x27,
  27878. 0xd3, 0xba, 0xb0, 0xd4, 0xb2, 0x07, 0xc3, 0xd8,
  27879. 0xab, 0x10, 0x3d, 0xcd, 0x23, 0x52, 0x46, 0xe6,
  27880. 0x96, 0x57, 0x85, 0xc7, 0x60, 0xe2, 0x8c, 0x46,
  27881. 0x65, 0x7d, 0x76, 0x1c, 0x45, 0x20, 0x5d, 0x51,
  27882. 0xd6, 0x13, 0xde, 0xe5, 0x3d, 0xc2, 0x8c, 0x36,
  27883. 0xdb, 0x7f, 0x83, 0x6f, 0x6a, 0xc2, 0xa3, 0xf2,
  27884. 0xdc, 0x63, 0x69, 0x7f, 0xbd, 0xd0, 0xc1, 0x90,
  27885. 0xfb, 0x62, 0x42, 0xa1, 0xf6, 0xf7, 0xdd, 0xc2,
  27886. 0x4a, 0x38, 0x62, 0x9b, 0xef, 0x67, 0xf9, 0x5c,
  27887. 0xd8, 0xff, 0xf4, 0xf2, 0x67, 0x90, 0x42, 0x85,
  27888. 0xaf, 0xe2, 0x92, 0x6e, 0xc4, 0x9b, 0x63, 0xc3,
  27889. 0x91, 0xa5, 0x11, 0x66, 0x13, 0x83, 0xbc, 0xbb,
  27890. 0xc7, 0x34, 0x3b, 0x30, 0x40, 0x53, 0x91, 0xdf,
  27891. 0x7c, 0x3d, 0x17, 0xdd, 0xa1, 0xa6, 0x80, 0xfd,
  27892. 0x26, 0x9d, 0x60, 0x7b, 0xcd, 0xb4, 0x2b, 0xba,
  27893. 0x61, 0x0f, 0x43, 0x7c, 0x51, 0x3c, 0xb9, 0xfa,
  27894. 0xdb, 0x48, 0x35, 0x9f, 0x0d, 0x0c, 0x04, 0xe8,
  27895. 0xf9, 0x6e, 0x07, 0x65, 0x7d, 0x46, 0x1b, 0xd2,
  27896. 0x51, 0xdb, 0x55, 0x27, 0xd7, 0x3d, 0x1e, 0x36,
  27897. 0x07, 0x59, 0x18, 0xec, 0x04, 0x4b, 0x87, 0xbb,
  27898. 0xfb, 0x27, 0xac, 0xeb, 0x8f, 0x43, 0x46, 0xd0,
  27899. 0x39, 0x00, 0x90, 0x54, 0x70, 0xb1, 0x71, 0xf2,
  27900. 0xe7, 0x3d, 0x02, 0x1a, 0xcf, 0x87, 0x16, 0x67,
  27901. 0xa2, 0x3c, 0x31, 0x48, 0xe8, 0xbd, 0x4f, 0xb3,
  27902. 0xc2, 0xfd, 0x3d, 0xa1, 0x9c, 0x87, 0x54, 0x60,
  27903. 0x30, 0x21, 0x52, 0x57, 0xcd, 0x03, 0x96, 0x9e,
  27904. 0xa7, 0x8d, 0xe5, 0x02, 0x04, 0x78, 0x43, 0x72,
  27905. 0xda, 0xb2, 0x22, 0xf1, 0xee, 0x8f, 0x27, 0x0b,
  27906. 0x8f, 0x7b, 0xf8, 0xbc, 0x16, 0xa1, 0xef, 0x0b,
  27907. 0x35, 0xda, 0xfc, 0x29, 0x1b, 0xf8, 0xa1, 0x35,
  27908. 0x40, 0xe7, 0xed, 0x4c, 0x02, 0x4a, 0x83, 0xb7,
  27909. 0x49, 0x75, 0x34, 0x3f, 0x2b, 0xb3, 0x61, 0xf5,
  27910. 0xa3, 0x9b, 0x23, 0xca, 0xfb, 0x58, 0x16, 0x4f,
  27911. 0x3c, 0x50, 0xbf, 0x81, 0xab, 0x54, 0x50, 0x1a,
  27912. 0x39, 0x57, 0x5f, 0x9a, 0x72, 0x22, 0xba, 0xa4,
  27913. 0xf6, 0xbf, 0xac, 0x31, 0x5c, 0xc5, 0x96, 0xd7,
  27914. 0xa9, 0xe4, 0x3b, 0x0c, 0xd0, 0x7f, 0x79, 0x68,
  27915. 0x4d, 0x41, 0x04, 0x81, 0x73, 0xcf, 0x47, 0x4a,
  27916. 0x7b, 0x37, 0xac, 0x8e, 0x47, 0x0d, 0x72, 0x65,
  27917. 0x0f, 0x9d, 0x44, 0xd7, 0x08, 0x21, 0x5b, 0x3f,
  27918. 0xc8, 0x9d, 0xea, 0xa2, 0x64, 0x7b, 0x0d, 0x98,
  27919. 0xc1, 0x61, 0xcd, 0xa4, 0xf7, 0x8c, 0x4a, 0xa3,
  27920. 0x3b, 0xdd, 0x92, 0xce, 0x61, 0x97, 0x0e, 0x98,
  27921. 0xa4, 0x10, 0xb5, 0x1f, 0xc5, 0xfb, 0xee, 0x49,
  27922. 0x36, 0x8f, 0xe3, 0x2d, 0x46, 0x9c, 0xa9, 0xff,
  27923. 0xdd, 0x1a, 0x48, 0x1b, 0x5a, 0x99, 0x84, 0x0a,
  27924. 0x3d, 0x5c, 0xd7, 0x67, 0x32, 0x88, 0x87, 0x2a,
  27925. 0x34, 0x50, 0x04, 0xad, 0xe6, 0xbb, 0x3c, 0xb5,
  27926. 0xee, 0x80, 0x99, 0x70, 0xaa, 0x9d, 0x5a, 0x63,
  27927. 0xec, 0xd5, 0x9a, 0x6a, 0x3a, 0xe8, 0xaa, 0x3d,
  27928. 0x3f, 0xe8, 0x15, 0x2c, 0x16, 0x3e, 0x86, 0x46,
  27929. 0x21, 0xf2, 0xd2, 0x6e, 0x74, 0x3d, 0x53, 0x94,
  27930. 0x7c, 0x41, 0xec, 0x5b, 0xf5, 0xa4, 0xc8, 0x1f,
  27931. 0x75, 0x22, 0x50, 0x58, 0x31, 0xf5, 0x29, 0x9a,
  27932. 0xc2, 0x2c, 0x67, 0xd9, 0xf6, 0x2e, 0xa1, 0xa9,
  27933. 0x0a, 0x69, 0x90, 0x7a, 0xd8, 0xed, 0x5c, 0x09,
  27934. 0x3d, 0x14, 0xa3, 0x2b, 0xc0, 0x47, 0x88, 0xb7,
  27935. 0xea, 0x14, 0x8a, 0xec, 0xaf, 0x0c, 0xb7, 0xc6,
  27936. 0x7c, 0x32, 0x0f, 0x57, 0xea, 0x9f, 0xd4, 0x99,
  27937. 0x8d, 0xab, 0xd6, 0xc9, 0x31, 0x07, 0x81, 0x37,
  27938. 0x3d, 0xf5, 0x07, 0xb3, 0x93, 0xb7, 0x04, 0x20,
  27939. 0xdf, 0x91, 0xef, 0xfb, 0xa6, 0x7d, 0x4b, 0x5d,
  27940. 0xd4, 0x24, 0xd2, 0x0b, 0xc5, 0x34, 0xf6, 0x7a,
  27941. 0xf9, 0x4a, 0x48, 0xc7, 0xab, 0xaf, 0xa8, 0xd2,
  27942. 0xfc, 0x41, 0xc9, 0x8b, 0xa8, 0xc4, 0x2f, 0x94,
  27943. 0x4e, 0xb0, 0xab, 0xd3, 0xd9, 0x09, 0x4b, 0x1f,
  27944. 0x35, 0xb7, 0xb4, 0x4c, 0x2d, 0x6b, 0xe6, 0xb4,
  27945. 0x2e, 0x8a, 0x09, 0xd3, 0x9d, 0x54, 0x3f, 0x53,
  27946. 0xcc, 0x8e, 0x16, 0x18, 0x4e, 0x9a, 0xe8, 0x52,
  27947. 0x84, 0x3a, 0x3e, 0xdb, 0xab, 0x65, 0xc4, 0xa1,
  27948. 0x3c, 0xd0, 0xf6, 0x57, 0x3c, 0x0e, 0x10, 0xed,
  27949. 0xb2, 0xa9, 0x7d, 0x70, 0x3f, 0x18, 0x1a, 0xba,
  27950. 0x31, 0x33, 0xcb, 0x2a, 0xfd, 0x13, 0xf5, 0x23,
  27951. 0xd7, 0x71, 0xfa, 0xb6, 0xe8, 0xda, 0x63, 0xca,
  27952. 0x55, 0x3c, 0x5b, 0x87, 0x27, 0x96, 0x3d, 0xd0,
  27953. 0x43, 0x9d, 0x76, 0x9f, 0x28, 0x5a, 0xb6, 0xc8,
  27954. 0x81, 0xe4, 0x7c, 0x2a, 0x7a, 0x84, 0x0f, 0x2d,
  27955. 0x1b, 0xd0, 0xe4, 0x0e, 0x1b, 0x47, 0x32, 0xc8,
  27956. 0x02, 0x2d, 0x39, 0x0e, 0x7d, 0xb1, 0x12, 0x56,
  27957. 0x50, 0x00, 0xae, 0xcc, 0x45, 0x0a, 0xd5, 0x30,
  27958. 0x16, 0xe7, 0x3a, 0x53, 0x02, 0xbc, 0xd5, 0xef,
  27959. 0xca, 0x00, 0xea, 0x5f, 0xbe, 0x15, 0x0d, 0x08,
  27960. 0x76, 0xc1, 0x03, 0x93, 0x96, 0x4a, 0x88, 0xda,
  27961. 0x9d, 0x0b, 0x51, 0x39, 0x9a, 0xef, 0xd2, 0xde,
  27962. 0x8a, 0x2c, 0xe6, 0xf3, 0xa5, 0x70, 0x15, 0x3a,
  27963. 0x17, 0x43, 0x31, 0xfc, 0x47, 0x9d, 0xec, 0x3b,
  27964. 0x28, 0x6f, 0xdf, 0x45, 0x6f, 0x9e, 0x10, 0xbb,
  27965. 0x8e, 0x43, 0xc5, 0x59, 0xe5, 0x61, 0x9b, 0xa7,
  27966. 0xa1, 0xb8, 0x7a, 0x1c, 0xd4, 0x25, 0x26, 0xca,
  27967. 0xe9, 0x2b, 0x0b, 0x3d, 0x06, 0xeb, 0x44, 0x44,
  27968. 0xab, 0x4a, 0x5e, 0x68, 0x5c, 0x93, 0xf1, 0x3f,
  27969. 0x39, 0x01, 0xb9, 0xf1, 0x01, 0xb7, 0xb6, 0x14,
  27970. 0x44, 0x1d, 0x6d, 0x6b, 0x03, 0x45, 0x0d, 0xf3,
  27971. 0xbf, 0x71, 0x4e, 0xf3, 0x84, 0x3d, 0xef, 0xea,
  27972. 0x60, 0x2e, 0x2e, 0xf7, 0x33, 0xa6, 0xbe, 0x53,
  27973. 0x49, 0x26, 0xed, 0xb4, 0xbf, 0x7f, 0xb0, 0x1d,
  27974. 0x39, 0xb2, 0xc2, 0x88, 0xc2, 0xa2, 0xd4, 0x7f,
  27975. 0x0e, 0x1c, 0x44, 0xa3, 0x38, 0x76, 0xa7, 0xa6,
  27976. 0x19, 0x7e, 0x4c, 0x84, 0x25, 0x01, 0xb2, 0x78,
  27977. 0xb4, 0x56, 0xc5, 0xc1, 0x50, 0x3f, 0xf2, 0xb6,
  27978. 0x76, 0x09, 0x55, 0x57, 0x1c, 0xd1, 0x55, 0x23,
  27979. 0x16, 0x2a, 0x51, 0x16, 0xaa, 0x13, 0x4f, 0x35,
  27980. 0x69, 0xaf, 0xea, 0x01, 0x5f, 0x22, 0xc9, 0x2e,
  27981. 0xe9, 0x8c, 0x6c, 0xa2, 0x17, 0x92, 0xdc, 0x3d,
  27982. 0xd6, 0xf0, 0xfa, 0x5a, 0x53, 0xe0, 0xcd, 0x55,
  27983. 0xa2, 0x91, 0x62, 0xba, 0xae, 0x67, 0x40, 0x1c,
  27984. 0xda, 0xb4, 0xcc, 0xfc, 0x67, 0x1f, 0x44, 0xa0,
  27985. 0x50, 0xa5, 0xde, 0xc5, 0xde, 0x5e, 0xa0, 0x3b,
  27986. 0x05, 0x84, 0x1c, 0x2a, 0xc4, 0x96, 0x47, 0xd6,
  27987. 0x97, 0x56, 0x40, 0x33, 0x99, 0x7c, 0x8b, 0x56,
  27988. 0xb4, 0xfb, 0xf4, 0x23, 0xcb, 0x48, 0x81, 0x6c,
  27989. 0xa4, 0x53, 0x41, 0x8c, 0x28, 0x61, 0xd7, 0x8c,
  27990. 0xde, 0xde, 0xeb, 0xd4, 0xe7, 0x8a, 0x2a, 0x40,
  27991. 0x83, 0x1c, 0xa4, 0x19, 0x0f, 0x6c, 0x73, 0xa5,
  27992. 0x0e, 0xb6, 0x5c, 0x14, 0x36, 0xff, 0xc9, 0x99,
  27993. 0x56, 0x53, 0x8c, 0x4e, 0x4f, 0x4a, 0x82, 0xc8,
  27994. 0x76, 0x83, 0x81, 0xf1, 0x17, 0x82, 0x98, 0x3e,
  27995. 0x9c, 0x99, 0x3a, 0x7c, 0x08, 0x77, 0x3e, 0xe2,
  27996. 0x10, 0x98, 0xb0, 0xf6, 0x1d, 0xd3, 0x24, 0xe8,
  27997. 0x98, 0xcf, 0xd8, 0x9a, 0xb8, 0xd7, 0xbe, 0x56,
  27998. 0xa2, 0xb6, 0xf8, 0x2e, 0xfe, 0xeb, 0x96, 0xfa,
  27999. 0xd0, 0xba, 0x79, 0x9e, 0xde, 0x72, 0x0d, 0x53,
  28000. 0x5f, 0xdd, 0x0d, 0xb2, 0x0a, 0x8f, 0x14, 0x94,
  28001. 0x87, 0x25, 0x5e, 0xcd, 0xd4, 0x4b, 0xaa, 0xc9,
  28002. 0x7e, 0x41, 0x9f, 0x33, 0x77, 0xbe, 0x6d, 0x57,
  28003. 0x68, 0xef, 0xee, 0x1a, 0xc4, 0x5c, 0x7b, 0xca,
  28004. 0x7e, 0x33, 0x93, 0x3d, 0x88, 0x91, 0xd1, 0x34,
  28005. 0x6a, 0x39, 0x98, 0x92, 0x50, 0x1a, 0x02, 0xcf,
  28006. 0x89, 0x34, 0x33, 0x10, 0x65, 0x23, 0x4d, 0xb7,
  28007. 0x00, 0xcc, 0xc1, 0x60, 0xdd, 0x7d, 0x8e, 0xd1,
  28008. 0x16, 0xa7, 0x71, 0x7b, 0x20, 0xcb, 0xe4, 0xe8,
  28009. 0xcc, 0xfc, 0xb8, 0x5f, 0xe4, 0xe2, 0xd6, 0x8c,
  28010. 0x43, 0x9c, 0x06, 0xf4, 0x8d, 0xbc, 0x56, 0xd0,
  28011. 0x0c, 0xd6, 0x0b, 0x6c, 0x33, 0x0e, 0x08, 0x77,
  28012. 0x66, 0x52, 0x1f, 0x48, 0x0c, 0x50, 0x4a, 0xc2,
  28013. 0x99, 0x0a, 0x15, 0x86, 0xc3, 0x9b, 0x7a, 0x5f,
  28014. 0xfb, 0x58, 0xbd, 0x63, 0x0c, 0xbe, 0x83, 0x40,
  28015. 0x8f, 0xba, 0x39, 0xfb, 0x45, 0xb9, 0xf7, 0x96,
  28016. 0x62, 0xec, 0x7e, 0x77, 0xa4, 0xfb, 0xe1, 0x86,
  28017. 0x5c, 0x0a, 0xae, 0x32, 0xbd, 0x79, 0x76, 0x8b
  28018. };
  28019. static const byte ml_dsa_44_good_sig[] = {
  28020. 0x09, 0xf0, 0xae, 0xbb, 0x25, 0xc7, 0xfc, 0xdd,
  28021. 0x93, 0x25, 0x9c, 0x50, 0xd9, 0x2e, 0x72, 0x5d,
  28022. 0x53, 0xf5, 0x29, 0xd7, 0x4c, 0xc2, 0xd6, 0x81,
  28023. 0x5c, 0xf3, 0x3f, 0x9a, 0x8a, 0xa9, 0x00, 0x21,
  28024. 0x6c, 0xc6, 0xb9, 0x72, 0xb7, 0x0e, 0x00, 0x55,
  28025. 0x9f, 0xd7, 0xae, 0x92, 0xc3, 0xbc, 0x8f, 0x2d,
  28026. 0x4f, 0x54, 0x87, 0x56, 0x52, 0xd3, 0xdd, 0xaf,
  28027. 0xe0, 0xff, 0xda, 0x80, 0x1b, 0xf3, 0x56, 0x90,
  28028. 0xdd, 0x07, 0x86, 0xad, 0xf7, 0xf3, 0x8e, 0xcf,
  28029. 0x3a, 0x57, 0x30, 0x52, 0xaa, 0xd2, 0xb1, 0xf0,
  28030. 0x66, 0xea, 0x67, 0xab, 0x94, 0x1d, 0x96, 0x04,
  28031. 0xaa, 0xcf, 0x0e, 0xb0, 0xbc, 0x7d, 0x8a, 0x4c,
  28032. 0x62, 0x21, 0x82, 0x81, 0x98, 0x63, 0x22, 0x91,
  28033. 0xb9, 0xfe, 0x53, 0x63, 0x8d, 0xdf, 0xe6, 0x19,
  28034. 0xc1, 0x54, 0x3b, 0xf0, 0xf5, 0xe4, 0xc4, 0x36,
  28035. 0x66, 0x2f, 0xcc, 0x4f, 0xed, 0xc6, 0x62, 0x7d,
  28036. 0x8b, 0x7b, 0x89, 0xac, 0x23, 0x0b, 0x40, 0x4e,
  28037. 0x2d, 0xdc, 0xe5, 0xa2, 0xbc, 0x8b, 0xac, 0xe7,
  28038. 0x0b, 0xaa, 0x15, 0xa0, 0x79, 0x4a, 0x97, 0x8a,
  28039. 0xc8, 0xb1, 0x31, 0xea, 0x29, 0x99, 0x14, 0x5d,
  28040. 0x5b, 0x8c, 0xc2, 0xd0, 0xc2, 0x29, 0xd0, 0x85,
  28041. 0xb9, 0x25, 0x16, 0x08, 0xe8, 0x41, 0xa7, 0x77,
  28042. 0x1a, 0xbf, 0x5a, 0x48, 0x5a, 0x7f, 0x97, 0x44,
  28043. 0x62, 0xb4, 0x68, 0x2e, 0x05, 0x48, 0xde, 0x0f,
  28044. 0x69, 0xcc, 0x05, 0x3c, 0xa4, 0x85, 0x20, 0x60,
  28045. 0xfd, 0x45, 0x6a, 0x14, 0xb9, 0x76, 0x8d, 0x48,
  28046. 0xe7, 0x71, 0xd0, 0xd7, 0xbe, 0xe3, 0x36, 0xd6,
  28047. 0x94, 0x5c, 0x22, 0x6e, 0x28, 0xc6, 0x34, 0x93,
  28048. 0xf4, 0x6c, 0xf2, 0x62, 0xbf, 0x8f, 0x6d, 0x07,
  28049. 0xff, 0x38, 0x92, 0x23, 0x19, 0x55, 0xd0, 0x66,
  28050. 0x72, 0x76, 0xc1, 0x43, 0xbc, 0x60, 0x5d, 0xaa,
  28051. 0x61, 0x10, 0xdb, 0x0c, 0x49, 0x7b, 0x99, 0xce,
  28052. 0x14, 0xe3, 0x0b, 0x80, 0xdc, 0x8a, 0x3d, 0xa5,
  28053. 0x3a, 0x0e, 0x29, 0x88, 0x09, 0x1f, 0x9c, 0x03,
  28054. 0x32, 0x13, 0xc2, 0xe1, 0x49, 0x26, 0xc7, 0x11,
  28055. 0xfa, 0x7f, 0x2d, 0x64, 0xfc, 0xf9, 0xaf, 0xd0,
  28056. 0x4d, 0xcf, 0x3a, 0x23, 0x49, 0xde, 0xf2, 0x5d,
  28057. 0xad, 0xf3, 0xde, 0xe0, 0x9a, 0xa2, 0x96, 0x0a,
  28058. 0x9d, 0x97, 0x39, 0x88, 0x60, 0x75, 0xec, 0x29,
  28059. 0x9b, 0x93, 0xfc, 0x80, 0xb3, 0xeb, 0xb0, 0xc6,
  28060. 0xa8, 0xea, 0x75, 0x67, 0xed, 0xbd, 0x42, 0x2a,
  28061. 0xed, 0x22, 0x27, 0xdb, 0x41, 0x3a, 0x94, 0x86,
  28062. 0xd7, 0x4a, 0xf1, 0x8f, 0xa5, 0x47, 0x38, 0xa3,
  28063. 0x3c, 0xe7, 0x17, 0x5d, 0xce, 0xdc, 0x32, 0x7c,
  28064. 0xe4, 0x05, 0x58, 0x98, 0x67, 0xc8, 0xaf, 0x35,
  28065. 0x5d, 0xf9, 0xc0, 0x10, 0x6d, 0x9d, 0xd3, 0x27,
  28066. 0x79, 0x3c, 0x1d, 0xdd, 0xfb, 0x53, 0x3c, 0x03,
  28067. 0x4c, 0xb3, 0x1b, 0x0b, 0x3a, 0x60, 0x80, 0xcd,
  28068. 0x9b, 0x1e, 0x5f, 0x3f, 0x29, 0xfa, 0xb1, 0x09,
  28069. 0x9a, 0x88, 0x58, 0x4a, 0xf5, 0xed, 0xe9, 0x7c,
  28070. 0x9d, 0x70, 0xbe, 0x57, 0xfb, 0x92, 0x12, 0xc9,
  28071. 0x8c, 0x6b, 0x77, 0xe2, 0x44, 0xc6, 0x82, 0x2a,
  28072. 0x29, 0xb3, 0x9c, 0xb0, 0x60, 0xda, 0x3d, 0xcd,
  28073. 0x4e, 0x49, 0x96, 0x8c, 0xd7, 0x2b, 0x29, 0x28,
  28074. 0x7b, 0xec, 0xf1, 0x46, 0x40, 0xf0, 0xe1, 0xd7,
  28075. 0x48, 0x9e, 0xdf, 0xfd, 0xa6, 0xd0, 0xaa, 0x35,
  28076. 0x94, 0x7a, 0x94, 0x57, 0xf3, 0xd4, 0x15, 0x19,
  28077. 0xd3, 0xc5, 0x35, 0x73, 0xc4, 0xf5, 0x86, 0x0d,
  28078. 0x2a, 0x5b, 0x67, 0x0d, 0x8d, 0xaa, 0x18, 0x3e,
  28079. 0xea, 0x9d, 0x80, 0xe7, 0xf8, 0xbb, 0x23, 0xea,
  28080. 0x5d, 0x1c, 0x4d, 0xb2, 0x58, 0x7e, 0xe5, 0xef,
  28081. 0x80, 0xc1, 0x63, 0x44, 0xaf, 0x1d, 0xed, 0xf6,
  28082. 0x92, 0x05, 0x0c, 0xda, 0xcc, 0x58, 0x39, 0x27,
  28083. 0xdd, 0x24, 0xac, 0x63, 0x23, 0x34, 0xaa, 0x2d,
  28084. 0xd0, 0x5b, 0xd7, 0x7f, 0x6d, 0xcb, 0x64, 0xed,
  28085. 0xb3, 0x9b, 0x05, 0x90, 0x79, 0xc2, 0x25, 0x68,
  28086. 0xed, 0xf6, 0xa8, 0x7e, 0x30, 0x4a, 0x46, 0x44,
  28087. 0xad, 0xc8, 0x12, 0x8d, 0x04, 0xc3, 0x11, 0x83,
  28088. 0x7e, 0x77, 0xef, 0x9c, 0xa2, 0xf9, 0x3b, 0x06,
  28089. 0x84, 0x7f, 0x72, 0xd9, 0x2f, 0x22, 0x95, 0xb7,
  28090. 0x7b, 0x4e, 0x35, 0x6a, 0xfa, 0x73, 0x7d, 0x88,
  28091. 0x5b, 0xac, 0x7b, 0xc5, 0x53, 0xc1, 0xfe, 0x6b,
  28092. 0x7c, 0x05, 0xc3, 0xe4, 0xae, 0x48, 0x1a, 0xea,
  28093. 0x6e, 0x51, 0x46, 0x1e, 0x82, 0x80, 0xde, 0x31,
  28094. 0xe1, 0x41, 0x71, 0x88, 0x41, 0xa7, 0xb2, 0xcd,
  28095. 0x3d, 0xf7, 0x5c, 0x4f, 0x4c, 0xfd, 0x3f, 0x6f,
  28096. 0x6c, 0x82, 0xc1, 0xba, 0xe0, 0xf0, 0xb4, 0x8c,
  28097. 0xd5, 0xb5, 0x32, 0xbf, 0x91, 0x49, 0x7e, 0x39,
  28098. 0x5e, 0x0a, 0xdf, 0x4b, 0xd6, 0x07, 0x72, 0xff,
  28099. 0x58, 0x65, 0x1b, 0x1f, 0xc6, 0x56, 0xd2, 0x00,
  28100. 0xec, 0x60, 0xd1, 0x22, 0xc9, 0x1a, 0xa4, 0xcc,
  28101. 0x26, 0xb4, 0xd1, 0x93, 0xbc, 0xfc, 0x52, 0xdf,
  28102. 0xa1, 0x23, 0x37, 0x9b, 0xa2, 0xa8, 0x8f, 0xf3,
  28103. 0x39, 0x03, 0xa5, 0x4c, 0xf0, 0x68, 0xe5, 0x95,
  28104. 0x62, 0xfb, 0xd8, 0x88, 0x39, 0xf6, 0x02, 0x0a,
  28105. 0x4e, 0x7c, 0xf0, 0xbf, 0x71, 0x99, 0x0f, 0x19,
  28106. 0x61, 0xd9, 0x39, 0xe8, 0x3f, 0x59, 0x22, 0x4a,
  28107. 0xaa, 0xdd, 0x03, 0xf8, 0x09, 0xb8, 0xaf, 0xd9,
  28108. 0xb9, 0x9c, 0x3f, 0xf1, 0xfe, 0x49, 0xae, 0x99,
  28109. 0x2f, 0xa2, 0x22, 0x5a, 0x3c, 0xe9, 0xe9, 0xf7,
  28110. 0xba, 0x2d, 0xeb, 0x1f, 0x6c, 0xa7, 0xe1, 0x87,
  28111. 0x2f, 0xa5, 0xff, 0xcf, 0x1c, 0x22, 0x8d, 0xf2,
  28112. 0x5f, 0x63, 0xf5, 0xbb, 0x36, 0x66, 0xcc, 0x62,
  28113. 0x89, 0x8e, 0xf7, 0x78, 0xc5, 0x97, 0x95, 0xde,
  28114. 0xec, 0x43, 0x39, 0x6e, 0x0d, 0xe0, 0x8e, 0xbd,
  28115. 0x2b, 0x3b, 0xe6, 0xff, 0xf5, 0x8f, 0x90, 0xd2,
  28116. 0xd2, 0xce, 0x3b, 0x6f, 0x78, 0xf5, 0xd3, 0x42,
  28117. 0xf3, 0x0f, 0x27, 0x4b, 0x2b, 0xe4, 0xd8, 0x0d,
  28118. 0x31, 0xfa, 0xba, 0xdc, 0x54, 0x21, 0x9a, 0xbf,
  28119. 0x1e, 0x1d, 0x06, 0x8e, 0xd9, 0x58, 0xce, 0x9a,
  28120. 0x71, 0x79, 0x4d, 0xcb, 0xfb, 0x99, 0x4b, 0x66,
  28121. 0xed, 0xef, 0x75, 0x20, 0x4d, 0x47, 0x9b, 0x40,
  28122. 0xd5, 0xcf, 0xd9, 0x00, 0xfe, 0x32, 0x45, 0xae,
  28123. 0x4b, 0x7e, 0x8e, 0x7b, 0xf9, 0xd4, 0xd4, 0x2e,
  28124. 0x1a, 0x2a, 0xac, 0x73, 0xdb, 0x79, 0xb7, 0x02,
  28125. 0x6a, 0x3d, 0xa2, 0xfe, 0x52, 0x27, 0x25, 0x43,
  28126. 0xd1, 0xb5, 0x48, 0x0e, 0xef, 0xf1, 0x0f, 0xe7,
  28127. 0x27, 0xc2, 0x59, 0x4e, 0x47, 0xe2, 0x12, 0xaa,
  28128. 0x1e, 0xae, 0xbc, 0x86, 0x22, 0x70, 0x33, 0xa5,
  28129. 0x50, 0x3f, 0xed, 0x3c, 0x98, 0xbb, 0xd5, 0xb3,
  28130. 0x3e, 0x43, 0x21, 0x8e, 0x3e, 0x8c, 0xcc, 0x0c,
  28131. 0xcf, 0x50, 0xcd, 0xeb, 0x1b, 0x9d, 0x0c, 0xc9,
  28132. 0xe3, 0x2f, 0xbb, 0x4b, 0x43, 0xfc, 0x37, 0x27,
  28133. 0xcb, 0xc9, 0x5a, 0xe9, 0x45, 0x92, 0x9d, 0xe9,
  28134. 0x60, 0x8f, 0x93, 0x1b, 0xd8, 0x6a, 0x68, 0x86,
  28135. 0xc2, 0x1d, 0x49, 0x92, 0x11, 0x29, 0x62, 0x14,
  28136. 0x15, 0x4c, 0xe9, 0x33, 0xe3, 0x70, 0x2d, 0x6b,
  28137. 0x8b, 0xb5, 0x22, 0x44, 0x82, 0xbe, 0x43, 0xe2,
  28138. 0x80, 0xfb, 0xb5, 0xfa, 0x6a, 0x30, 0x04, 0x20,
  28139. 0xb6, 0x58, 0xe1, 0xf4, 0x8c, 0xe6, 0x4c, 0x7c,
  28140. 0x8d, 0x38, 0xf6, 0xdd, 0x59, 0xfc, 0x5a, 0xd7,
  28141. 0x9f, 0x34, 0x92, 0xcc, 0xde, 0x65, 0x89, 0xa7,
  28142. 0xd9, 0x57, 0xf7, 0xf2, 0x71, 0x39, 0xaf, 0xb6,
  28143. 0x88, 0x02, 0x40, 0x24, 0x8b, 0x4f, 0xc5, 0xfc,
  28144. 0xdc, 0x5c, 0xc0, 0x1d, 0xa6, 0x68, 0x87, 0xe0,
  28145. 0x8f, 0xdc, 0xf0, 0xac, 0xd8, 0x5f, 0x1c, 0xb3,
  28146. 0x07, 0xac, 0x58, 0x97, 0x3f, 0x3e, 0x72, 0x19,
  28147. 0x18, 0x64, 0x55, 0x73, 0x11, 0x71, 0xd1, 0xa4,
  28148. 0xa6, 0x57, 0xb0, 0x27, 0xaf, 0xad, 0x8a, 0xf7,
  28149. 0xdf, 0xde, 0x1e, 0xdb, 0x31, 0xc9, 0x32, 0x85,
  28150. 0x90, 0x40, 0x3d, 0xfe, 0x64, 0x5d, 0xe3, 0x94,
  28151. 0x74, 0x98, 0xa7, 0xed, 0x84, 0x44, 0x13, 0x76,
  28152. 0xba, 0xe9, 0x09, 0x9a, 0x17, 0xe0, 0x38, 0x03,
  28153. 0x3b, 0x7a, 0xa7, 0x0e, 0x74, 0xbd, 0x93, 0xb1,
  28154. 0x85, 0x64, 0xc9, 0xc4, 0x22, 0xb9, 0xdf, 0x80,
  28155. 0xac, 0xa1, 0x17, 0xdb, 0x11, 0xdb, 0xfa, 0xeb,
  28156. 0x90, 0x3c, 0x28, 0xfb, 0xa2, 0x36, 0x76, 0x61,
  28157. 0x20, 0x00, 0x88, 0x15, 0xc0, 0x79, 0x9f, 0x7d,
  28158. 0x9f, 0x90, 0xdb, 0x79, 0xbf, 0x1c, 0xdf, 0x86,
  28159. 0xc9, 0x60, 0x8c, 0xea, 0xa6, 0x24, 0x81, 0xd6,
  28160. 0x6d, 0xd8, 0x8d, 0x17, 0x5f, 0x5c, 0x6d, 0x93,
  28161. 0xbc, 0xed, 0xe5, 0x41, 0x05, 0xbe, 0xc6, 0x0f,
  28162. 0x66, 0x50, 0xc3, 0xce, 0x7e, 0x6c, 0x80, 0x88,
  28163. 0xf5, 0x52, 0x61, 0xaf, 0xdb, 0xc0, 0x80, 0xbe,
  28164. 0x78, 0x49, 0x64, 0x39, 0x54, 0x26, 0xeb, 0xab,
  28165. 0x07, 0x4d, 0x38, 0x66, 0x06, 0x98, 0x58, 0xaa,
  28166. 0x40, 0xc4, 0x89, 0xb2, 0x08, 0x85, 0xf3, 0x14,
  28167. 0x58, 0x5d, 0x36, 0xf7, 0xf0, 0x6b, 0x72, 0x79,
  28168. 0x6d, 0xbe, 0x5e, 0x24, 0x68, 0xf1, 0x3c, 0xa2,
  28169. 0x82, 0x22, 0x6e, 0xc4, 0x46, 0x94, 0x8e, 0x00,
  28170. 0xcb, 0xc0, 0x07, 0x69, 0xa5, 0x6d, 0x57, 0x04,
  28171. 0x79, 0xeb, 0x06, 0x7a, 0x42, 0x20, 0x6e, 0xdc,
  28172. 0xb5, 0xa4, 0xdd, 0x74, 0xb3, 0x92, 0x16, 0x71,
  28173. 0x7d, 0x99, 0xfa, 0x26, 0x35, 0x57, 0xe2, 0x83,
  28174. 0xc2, 0xb6, 0xfb, 0x0a, 0xae, 0x22, 0xed, 0xe3,
  28175. 0x98, 0x65, 0x18, 0x32, 0xf8, 0xe5, 0xed, 0xa9,
  28176. 0xf9, 0x7d, 0xb8, 0xea, 0x21, 0x51, 0x6c, 0x70,
  28177. 0x4c, 0xfa, 0xec, 0x6d, 0x4c, 0xf4, 0xcb, 0x1c,
  28178. 0x43, 0xfb, 0xfc, 0xbb, 0xa9, 0xcb, 0xc5, 0x21,
  28179. 0xb3, 0x89, 0xd6, 0x4c, 0xc4, 0x42, 0xd1, 0x55,
  28180. 0x3d, 0x43, 0x74, 0xbf, 0xb7, 0x47, 0xb3, 0x5b,
  28181. 0x14, 0xc3, 0x8f, 0x42, 0x30, 0x57, 0xb0, 0x22,
  28182. 0x56, 0xbe, 0x8d, 0x88, 0x7e, 0x7d, 0x63, 0xc8,
  28183. 0xec, 0x01, 0x41, 0xd5, 0x9d, 0xb6, 0x7a, 0x3b,
  28184. 0xfe, 0x8b, 0x95, 0x94, 0xdb, 0xca, 0xf1, 0xb4,
  28185. 0x56, 0xd7, 0x83, 0xf4, 0x11, 0x05, 0x65, 0xde,
  28186. 0x7a, 0xa3, 0x5a, 0x7a, 0x70, 0xe4, 0xd2, 0xad,
  28187. 0xc0, 0xff, 0x3f, 0x66, 0x2e, 0x1a, 0x65, 0x38,
  28188. 0xda, 0x1f, 0x3f, 0xac, 0x04, 0x2f, 0x0f, 0xde,
  28189. 0x7e, 0x55, 0x05, 0x12, 0xe9, 0xe7, 0x69, 0xf9,
  28190. 0x34, 0x2c, 0x84, 0x97, 0xa8, 0x86, 0x0c, 0x24,
  28191. 0x32, 0x87, 0xfd, 0xbe, 0x67, 0xd1, 0x02, 0x21,
  28192. 0x3b, 0x33, 0xfd, 0x11, 0xb1, 0xca, 0x4f, 0xeb,
  28193. 0x40, 0x38, 0xf6, 0x19, 0x83, 0x9d, 0x73, 0x44,
  28194. 0x37, 0xd6, 0x69, 0x6d, 0x85, 0xda, 0xf7, 0x69,
  28195. 0xfb, 0x88, 0x2b, 0xe7, 0xe7, 0x3c, 0x18, 0xa8,
  28196. 0x13, 0xb7, 0xee, 0x5c, 0x50, 0x5b, 0xa3, 0x09,
  28197. 0x1c, 0xef, 0x8d, 0x37, 0x89, 0x75, 0x0f, 0x8b,
  28198. 0xea, 0x17, 0x02, 0x47, 0x21, 0xcb, 0xa8, 0x73,
  28199. 0x71, 0x23, 0x4c, 0xf7, 0x50, 0xdd, 0x21, 0xe5,
  28200. 0xdb, 0x40, 0x3a, 0x87, 0x40, 0x8d, 0x60, 0x89,
  28201. 0x9e, 0x20, 0x00, 0x58, 0xeb, 0xbb, 0x24, 0x9b,
  28202. 0x0a, 0x17, 0x8f, 0xf6, 0x56, 0x07, 0x11, 0x5b,
  28203. 0xa7, 0xcd, 0x93, 0x0a, 0x31, 0x3d, 0x1f, 0x45,
  28204. 0xa0, 0x08, 0x8f, 0x88, 0x34, 0xa5, 0x01, 0x3b,
  28205. 0xea, 0x07, 0xa3, 0x7b, 0x66, 0x3e, 0x96, 0xe8,
  28206. 0xf7, 0x4d, 0x63, 0x04, 0x55, 0x89, 0xf1, 0x02,
  28207. 0x1e, 0x4a, 0x21, 0xb1, 0x2b, 0x8c, 0x7f, 0x2e,
  28208. 0x0c, 0x64, 0x26, 0x36, 0xd8, 0x63, 0xab, 0xf5,
  28209. 0x22, 0xaf, 0xa9, 0xfa, 0xfa, 0x21, 0x4b, 0x7e,
  28210. 0x6f, 0x8c, 0xce, 0x98, 0xf2, 0x85, 0x3f, 0x2c,
  28211. 0x07, 0x90, 0xc3, 0x2c, 0x06, 0xc5, 0xde, 0xc8,
  28212. 0xc2, 0x7c, 0xd7, 0x9b, 0x64, 0x25, 0x8a, 0x9b,
  28213. 0x77, 0x07, 0xc7, 0x4c, 0xd7, 0x67, 0xff, 0xe6,
  28214. 0xdb, 0x17, 0xf5, 0xc4, 0x2a, 0x14, 0x44, 0x1a,
  28215. 0xff, 0xda, 0xe0, 0xa7, 0x09, 0x1c, 0xe9, 0x03,
  28216. 0xde, 0x4a, 0x59, 0xe4, 0xdf, 0xa3, 0x0d, 0x3a,
  28217. 0x43, 0xdf, 0x80, 0x82, 0x87, 0xfa, 0x75, 0xf5,
  28218. 0xe8, 0xef, 0x6f, 0xd0, 0x89, 0xdd, 0xa1, 0x75,
  28219. 0x17, 0x5b, 0x71, 0x47, 0xe8, 0x8d, 0xae, 0xf6,
  28220. 0x18, 0x7f, 0xb9, 0x24, 0x68, 0x3f, 0x17, 0x6b,
  28221. 0xa8, 0x30, 0x67, 0x7e, 0x02, 0x9b, 0xf6, 0x4d,
  28222. 0x03, 0xa8, 0xfb, 0x33, 0x2f, 0xb4, 0x65, 0x72,
  28223. 0x2a, 0x30, 0xa6, 0x93, 0x94, 0x7a, 0x41, 0x0f,
  28224. 0xd3, 0x67, 0x0b, 0xba, 0xa4, 0x49, 0x7c, 0xcf,
  28225. 0x1f, 0x59, 0x1e, 0x2e, 0x45, 0xd4, 0xa8, 0xb1,
  28226. 0x98, 0x2b, 0xd7, 0x6f, 0x55, 0xb8, 0xf2, 0x65,
  28227. 0x7b, 0x96, 0x18, 0xf7, 0x2e, 0xde, 0x9c, 0x39,
  28228. 0x7a, 0x08, 0x2e, 0xe7, 0x3c, 0x9e, 0x4a, 0xfe,
  28229. 0xba, 0x49, 0xce, 0xba, 0x65, 0x18, 0xae, 0xae,
  28230. 0x9b, 0xd5, 0xf5, 0xeb, 0xd3, 0xdc, 0xd7, 0x2c,
  28231. 0x92, 0x3c, 0xe2, 0x93, 0xb9, 0x69, 0xf2, 0x20,
  28232. 0xea, 0xbd, 0xa9, 0x01, 0x2b, 0x72, 0x7c, 0x93,
  28233. 0x6c, 0x1f, 0x80, 0x3a, 0xd2, 0x2d, 0xf6, 0xc1,
  28234. 0x31, 0x63, 0xd2, 0x2f, 0x6c, 0x1a, 0x54, 0x1f,
  28235. 0x74, 0xe6, 0xa0, 0xac, 0xb1, 0x04, 0x03, 0xb3,
  28236. 0x22, 0x19, 0x48, 0x0a, 0xa7, 0x55, 0x25, 0xc1,
  28237. 0x77, 0x28, 0xb9, 0xbe, 0xef, 0xa8, 0xc6, 0x2b,
  28238. 0xd5, 0x6c, 0x5d, 0x7b, 0x85, 0xcd, 0x10, 0x2d,
  28239. 0x9e, 0xfd, 0xb8, 0xa5, 0x10, 0x65, 0xf7, 0x29,
  28240. 0xa7, 0x41, 0x18, 0xc8, 0xc2, 0x23, 0xe5, 0xcb,
  28241. 0x96, 0x91, 0x8a, 0x7e, 0x45, 0x30, 0x6b, 0x91,
  28242. 0xf1, 0x88, 0xb3, 0x2e, 0x92, 0x96, 0x0a, 0x42,
  28243. 0x4a, 0x16, 0x9d, 0x0c, 0xa8, 0xa7, 0xe5, 0x64,
  28244. 0x38, 0x8a, 0x53, 0x41, 0x28, 0xbf, 0xd7, 0xa4,
  28245. 0x14, 0x05, 0x59, 0x11, 0x2e, 0x0f, 0xc8, 0x5c,
  28246. 0x97, 0x8d, 0xd3, 0x92, 0xbf, 0xb9, 0x05, 0xfa,
  28247. 0xff, 0x38, 0xbf, 0xd6, 0xc5, 0x22, 0xf8, 0xa4,
  28248. 0x75, 0x30, 0x45, 0x93, 0x14, 0xda, 0xc0, 0x7f,
  28249. 0xea, 0x24, 0xe0, 0x33, 0x68, 0xf2, 0x6d, 0xe1,
  28250. 0xb1, 0x0c, 0x7d, 0x40, 0xaa, 0x16, 0x53, 0xa1,
  28251. 0xf6, 0x26, 0xb1, 0x25, 0xe8, 0x83, 0xe9, 0xea,
  28252. 0xea, 0xd2, 0x5a, 0x24, 0xda, 0xe2, 0x6e, 0xd1,
  28253. 0x2a, 0x87, 0x64, 0x48, 0x13, 0x55, 0xb1, 0x2c,
  28254. 0x1a, 0x58, 0x43, 0x5b, 0x63, 0x14, 0x3e, 0x02,
  28255. 0xf0, 0xcf, 0x61, 0x7d, 0x83, 0x81, 0xb9, 0x65,
  28256. 0x4b, 0x72, 0xee, 0xff, 0xfb, 0x6a, 0xbe, 0x71,
  28257. 0x26, 0x56, 0x28, 0x13, 0x9f, 0x31, 0xda, 0x8c,
  28258. 0x2f, 0xdb, 0x21, 0xbe, 0x4b, 0x66, 0xbb, 0xad,
  28259. 0x7a, 0x13, 0x55, 0x92, 0x7c, 0xb5, 0x6e, 0x5f,
  28260. 0x45, 0x1b, 0x64, 0x2d, 0xad, 0x6d, 0x32, 0x07,
  28261. 0xe4, 0x91, 0xdc, 0x0c, 0x1b, 0x5f, 0xcd, 0x86,
  28262. 0xe2, 0x99, 0x2b, 0xb9, 0x7e, 0x60, 0xbd, 0xad,
  28263. 0xa1, 0x5c, 0xab, 0x7f, 0x76, 0xf3, 0x77, 0xba,
  28264. 0x73, 0x7f, 0x6a, 0x88, 0x4e, 0xff, 0x40, 0x72,
  28265. 0x7a, 0x4d, 0x9b, 0x20, 0x2d, 0xc9, 0x2a, 0x30,
  28266. 0x0f, 0x8f, 0x0f, 0xc9, 0x79, 0xc8, 0xc3, 0x8a,
  28267. 0x83, 0x52, 0xff, 0x66, 0x7a, 0x42, 0x04, 0x08,
  28268. 0x6e, 0x5b, 0x13, 0xda, 0xb9, 0xb6, 0x2d, 0x45,
  28269. 0x77, 0x9a, 0xa0, 0x2b, 0xc1, 0x87, 0xc2, 0xa6,
  28270. 0x35, 0x7f, 0x39, 0x34, 0x2e, 0x95, 0x1e, 0x8c,
  28271. 0xbf, 0x89, 0x6d, 0xcf, 0x82, 0xb8, 0x9f, 0x9b,
  28272. 0xd1, 0xbc, 0xa2, 0x55, 0x83, 0xf4, 0xca, 0x21,
  28273. 0x11, 0x8f, 0x28, 0xa9, 0x5e, 0x28, 0x23, 0xb4,
  28274. 0x43, 0x60, 0xb6, 0x11, 0x1a, 0x6f, 0xb4, 0xd1,
  28275. 0x96, 0xc8, 0x79, 0xf2, 0x39, 0x8b, 0x82, 0xae,
  28276. 0xe0, 0xc2, 0xe4, 0xf9, 0xfb, 0xf8, 0x85, 0x64,
  28277. 0x28, 0xad, 0xb5, 0xfd, 0x37, 0xc5, 0x21, 0x38,
  28278. 0x31, 0x94, 0x0d, 0xbe, 0xd8, 0xaf, 0x9b, 0x8a,
  28279. 0x7d, 0xfb, 0x56, 0xd8, 0x23, 0xf7, 0x55, 0x55,
  28280. 0xe7, 0xd9, 0x63, 0x65, 0xfd, 0x64, 0x2e, 0x8a,
  28281. 0x1d, 0x1b, 0xac, 0x4e, 0x2f, 0xef, 0x1b, 0x77,
  28282. 0xca, 0x01, 0xd6, 0xfc, 0xb0, 0x11, 0xda, 0x6b,
  28283. 0xef, 0x9f, 0x76, 0x81, 0x3e, 0x3f, 0x26, 0x4b,
  28284. 0x3b, 0x97, 0xa0, 0x7d, 0xd6, 0xcf, 0x51, 0x0d,
  28285. 0x06, 0xf7, 0xf5, 0x88, 0x64, 0x34, 0x7a, 0xe3,
  28286. 0xb9, 0x16, 0xc3, 0x06, 0x04, 0xf3, 0xe9, 0x55,
  28287. 0xd2, 0xff, 0x49, 0xec, 0x57, 0x84, 0x1f, 0x39,
  28288. 0x28, 0x71, 0x57, 0x87, 0x40, 0xf2, 0x7a, 0x30,
  28289. 0xa0, 0x88, 0xba, 0x6c, 0xb1, 0x09, 0x30, 0x3a,
  28290. 0x11, 0x75, 0xcf, 0xbe, 0x4c, 0xf7, 0xf7, 0xca,
  28291. 0x44, 0x52, 0x91, 0xd0, 0x4c, 0x12, 0x3e, 0x3a,
  28292. 0x4b, 0x31, 0x20, 0xfe, 0x27, 0xd2, 0x08, 0x5b,
  28293. 0x83, 0x7b, 0x82, 0xd3, 0xa3, 0x72, 0xba, 0x2f,
  28294. 0x5f, 0xa3, 0x71, 0xcd, 0x8d, 0x3f, 0x94, 0xce,
  28295. 0x86, 0xa8, 0x6b, 0x43, 0xb7, 0x06, 0x80, 0x70,
  28296. 0x64, 0x06, 0xab, 0x54, 0xce, 0xb5, 0x29, 0xaf,
  28297. 0x73, 0xf7, 0x0f, 0x65, 0x70, 0xa7, 0x84, 0x1a,
  28298. 0x0b, 0xdb, 0x0c, 0xa9, 0x20, 0xea, 0x06, 0x7a,
  28299. 0xba, 0x80, 0xc6, 0xae, 0x3e, 0x0a, 0x7b, 0xd6,
  28300. 0x21, 0x99, 0xe0, 0xae, 0x6e, 0x8f, 0x80, 0xa9,
  28301. 0x97, 0x27, 0x3d, 0x7e, 0xb2, 0xd8, 0x06, 0x10,
  28302. 0x36, 0x07, 0x64, 0x12, 0xd0, 0xc7, 0x91, 0xd2,
  28303. 0x81, 0x74, 0x22, 0x8b, 0x8f, 0xe0, 0x48, 0xc4,
  28304. 0xe1, 0x9b, 0x05, 0xc8, 0xc5, 0xc3, 0x9a, 0x7b,
  28305. 0x9d, 0xee, 0x23, 0xe0, 0x98, 0xc0, 0xd0, 0x05,
  28306. 0x21, 0x89, 0x9a, 0xf4, 0x45, 0xd1, 0x1d, 0x80,
  28307. 0x79, 0xb7, 0xfe, 0x3c, 0xff, 0x84, 0x86, 0xf0,
  28308. 0x2a, 0x69, 0x8b, 0x2d, 0x3b, 0x82, 0xa0, 0xab,
  28309. 0xee, 0xe6, 0xf4, 0x64, 0x84, 0x2b, 0x7a, 0x42,
  28310. 0x12, 0x8d, 0x10, 0xa6, 0xae, 0x10, 0x6d, 0x03,
  28311. 0xb5, 0x72, 0x09, 0xf8, 0x3f, 0xe4, 0x1c, 0x0a,
  28312. 0x08, 0x0d, 0x1a, 0x45, 0x5b, 0x70, 0x7b, 0x95,
  28313. 0xa1, 0xa7, 0xb4, 0xb6, 0xbf, 0xcc, 0xfc, 0x09,
  28314. 0x1a, 0x30, 0x40, 0x44, 0x5e, 0x69, 0x73, 0x7a,
  28315. 0x81, 0xa5, 0xb9, 0xd7, 0xdd, 0xe3, 0xee, 0xfb,
  28316. 0x16, 0x1a, 0x1d, 0x40, 0x41, 0x4e, 0x8d, 0x90,
  28317. 0x92, 0x9d, 0xaf, 0xb0, 0xbb, 0xc2, 0xe0, 0xfc,
  28318. 0x06, 0x0b, 0x20, 0x37, 0x47, 0x50, 0x53, 0x65,
  28319. 0x87, 0x89, 0x99, 0xa4, 0xb7, 0xdb, 0x00, 0x00,
  28320. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28321. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28322. 0x0f, 0x20, 0x30, 0x3e
  28323. };
  28324. #endif
  28325. static int test_wc_dilithium(void)
  28326. {
  28327. EXPECT_DECLS;
  28328. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM)
  28329. dilithium_key* key;
  28330. byte level;
  28331. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28332. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28333. WC_RNG rng;
  28334. #endif
  28335. byte* privKey = NULL;
  28336. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28337. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28338. #endif
  28339. byte* pubKey = NULL;
  28340. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28341. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28342. #endif
  28343. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28344. ExpectNotNull(key);
  28345. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28346. DYNAMIC_TYPE_TMP_BUFFER);
  28347. ExpectNotNull(privKey);
  28348. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28349. DYNAMIC_TYPE_TMP_BUFFER);
  28350. ExpectNotNull(pubKey);
  28351. if (key != NULL) {
  28352. XMEMSET(key, 0, sizeof(*key));
  28353. }
  28354. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28355. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28356. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28357. #endif
  28358. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28359. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28360. ExpectIntEQ(wc_InitRng(&rng), 0);
  28361. #endif
  28362. ExpectIntEQ(wc_dilithium_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28363. ExpectIntEQ(wc_dilithium_init_ex(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28364. wc_dilithium_free(NULL);
  28365. ExpectIntEQ(wc_dilithium_init(key), 0);
  28366. wc_dilithium_free(key);
  28367. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  28368. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28369. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28370. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28371. #endif
  28372. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28373. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28374. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28375. #endif
  28376. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28377. ExpectIntEQ(wc_dilithium_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28378. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28379. ExpectIntEQ(wc_dilithium_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28380. #endif
  28381. #endif
  28382. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28383. ExpectIntEQ(wc_dilithium_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28384. #endif
  28385. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28386. ExpectIntEQ(wc_dilithium_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28387. #endif
  28388. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28389. ExpectIntEQ(wc_dilithium_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28390. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28391. ExpectIntEQ(wc_dilithium_priv_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28392. #endif
  28393. #endif
  28394. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28395. ExpectIntEQ(wc_dilithium_pub_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28396. #endif
  28397. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28398. ExpectIntEQ(wc_dilithium_sig_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28399. #endif
  28400. ExpectIntEQ(wc_dilithium_set_level(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28401. ExpectIntEQ(wc_dilithium_set_level(key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28402. ExpectIntEQ(wc_dilithium_set_level(NULL, WC_ML_DSA_44), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28403. ExpectIntEQ(wc_dilithium_set_level(key, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28404. ExpectIntEQ(wc_dilithium_set_level(key, 4), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28405. ExpectIntEQ(wc_dilithium_get_level(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28406. ExpectIntEQ(wc_dilithium_get_level(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28407. ExpectIntEQ(wc_dilithium_get_level(NULL, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28408. ExpectIntEQ(wc_dilithium_get_level(key, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28409. #ifndef WOLFSSL_NO_ML_DSA_87
  28410. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28411. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28412. ExpectIntEQ(level, WC_ML_DSA_87);
  28413. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28414. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL5_KEY_SIZE);
  28415. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28416. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL5_PRV_KEY_SIZE);
  28417. #endif
  28418. #endif
  28419. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28420. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28421. #endif
  28422. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28423. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL5_SIG_SIZE);
  28424. #endif
  28425. #else
  28426. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28427. #endif
  28428. #ifndef WOLFSSL_NO_ML_DSA_65
  28429. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28430. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28431. ExpectIntEQ(level, WC_ML_DSA_65);
  28432. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28433. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL3_KEY_SIZE);
  28434. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28435. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL3_PRV_KEY_SIZE);
  28436. #endif
  28437. #endif
  28438. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28439. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28440. #endif
  28441. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28442. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL3_SIG_SIZE);
  28443. #endif
  28444. #else
  28445. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28446. #endif
  28447. #ifndef WOLFSSL_NO_ML_DSA_44
  28448. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28449. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28450. ExpectIntEQ(level, WC_ML_DSA_44);
  28451. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28452. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL2_KEY_SIZE);
  28453. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28454. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL2_PRV_KEY_SIZE);
  28455. #endif
  28456. #endif
  28457. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28458. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28459. #endif
  28460. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28461. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL2_SIG_SIZE);
  28462. #endif
  28463. #else
  28464. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28465. #endif
  28466. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28467. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28468. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28469. #endif
  28470. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28471. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28472. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28473. #endif
  28474. wc_dilithium_free(key);
  28475. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28476. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28477. wc_FreeRng(&rng);
  28478. #endif
  28479. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28480. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28481. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28482. #endif
  28483. return EXPECT_RESULT();
  28484. }
  28485. static int test_wc_dilithium_make_key(void)
  28486. {
  28487. EXPECT_DECLS;
  28488. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28489. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  28490. dilithium_key* key;
  28491. WC_RNG rng;
  28492. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28493. ExpectNotNull(key);
  28494. if (key != NULL) {
  28495. XMEMSET(key, 0, sizeof(*key));
  28496. }
  28497. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28498. ExpectIntEQ(wc_InitRng(&rng), 0);
  28499. ExpectIntEQ(wc_dilithium_init(key), 0);
  28500. ExpectIntEQ(wc_dilithium_make_key(key, &rng), WC_NO_ERR_TRACE(BAD_STATE_E));
  28501. #ifndef WOLFSSL_NO_ML_DSA_44
  28502. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28503. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28504. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28505. #else
  28506. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28507. #endif
  28508. ExpectIntEQ(wc_dilithium_make_key(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28509. ExpectIntEQ(wc_dilithium_make_key(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28510. ExpectIntEQ(wc_dilithium_make_key(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28511. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28512. wc_dilithium_free(key);
  28513. wc_FreeRng(&rng);
  28514. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28515. #endif
  28516. return EXPECT_RESULT();
  28517. }
  28518. static int test_wc_dilithium_sign(void)
  28519. {
  28520. EXPECT_DECLS;
  28521. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28522. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28523. dilithium_key* key;
  28524. dilithium_key* importKey = NULL;
  28525. WC_RNG rng;
  28526. byte* privKey = NULL;
  28527. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28528. word32 badKeyLen;
  28529. byte msg[32];
  28530. byte* sig = NULL;
  28531. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  28532. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28533. ExpectNotNull(key);
  28534. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  28535. DYNAMIC_TYPE_TMP_BUFFER);
  28536. ExpectNotNull(importKey);
  28537. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28538. DYNAMIC_TYPE_TMP_BUFFER);
  28539. ExpectNotNull(privKey);
  28540. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL,
  28541. DYNAMIC_TYPE_TMP_BUFFER);
  28542. ExpectNotNull(sig);
  28543. if (key != NULL) {
  28544. XMEMSET(key, 0, sizeof(*key));
  28545. }
  28546. if (importKey != NULL) {
  28547. XMEMSET(importKey, 0, sizeof(*importKey));
  28548. }
  28549. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28550. XMEMSET(msg, 0x55, sizeof(msg));
  28551. ExpectIntEQ(wc_InitRng(&rng), 0);
  28552. ExpectIntEQ(wc_dilithium_init(key), 0);
  28553. #ifndef WOLFSSL_NO_ML_DSA_44
  28554. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28555. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28556. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28557. #else
  28558. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28559. #endif
  28560. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  28561. #ifndef WOLFSSL_NO_ML_DSA_44
  28562. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level2_key,
  28563. sizeof_bench_dilithium_level2_key, key), 0);
  28564. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28565. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level3_key,
  28566. sizeof_bench_dilithium_level3_key, key), 0);
  28567. #else
  28568. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level5_key,
  28569. sizeof_bench_dilithium_level5_key, key), 0);
  28570. #endif
  28571. #else
  28572. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28573. #endif
  28574. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, NULL),
  28575. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28576. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, NULL, NULL, NULL),
  28577. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28578. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, NULL, NULL, NULL),
  28579. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28580. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, &sigLen, NULL, NULL),
  28581. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28582. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, key, NULL),
  28583. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28584. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, &rng),
  28585. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28586. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, &sigLen, key, &rng),
  28587. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28588. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, &sigLen, key, &rng),
  28589. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28590. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, NULL, key, &rng),
  28591. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28592. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, NULL, &rng),
  28593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28594. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, NULL),
  28595. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28596. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  28597. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, NULL),
  28598. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28599. ExpectIntEQ(wc_dilithium_export_private(key, NULL, NULL),
  28600. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28601. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, NULL),
  28602. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28603. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, &privKeyLen),
  28604. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28605. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, &privKeyLen),
  28606. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28607. ExpectIntEQ(wc_dilithium_export_private(key, NULL, &privKeyLen),
  28608. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28609. ExpectIntEQ(wc_dilithium_export_private(key, privKey, NULL),
  28610. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28611. badKeyLen = 0;
  28612. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &badKeyLen),
  28613. WC_NO_ERR_TRACE(BUFFER_E));
  28614. #ifndef WOLFSSL_NO_ML_DSA_44
  28615. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  28616. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28617. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  28618. #else
  28619. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  28620. #endif
  28621. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28622. 0);
  28623. #ifndef WOLFSSL_NO_ML_DSA_44
  28624. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  28625. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28626. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  28627. #else
  28628. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  28629. #endif
  28630. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  28631. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  28632. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28633. #ifndef WOLFSSL_NO_ML_DSA_44
  28634. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  28635. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28636. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  28637. #else
  28638. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  28639. #endif
  28640. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, NULL),
  28641. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28642. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, NULL),
  28643. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28644. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, NULL),
  28645. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28646. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, importKey),
  28647. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28648. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, importKey),
  28649. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28650. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, importKey),
  28651. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28652. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, NULL),
  28653. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28654. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  28655. 0);
  28656. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  28657. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  28658. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  28659. #endif
  28660. wc_dilithium_free(importKey);
  28661. wc_dilithium_free(key);
  28662. wc_FreeRng(&rng);
  28663. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28664. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28665. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28666. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28667. #endif
  28668. return EXPECT_RESULT();
  28669. }
  28670. static int test_wc_dilithium_verify(void)
  28671. {
  28672. EXPECT_DECLS;
  28673. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28674. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  28675. (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_DILITHIUM_NO_SIGN))
  28676. dilithium_key* key;
  28677. dilithium_key* importKey = NULL;
  28678. WC_RNG rng;
  28679. byte* pubKey = NULL;
  28680. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28681. word32 badKeyLen;
  28682. byte msg[32];
  28683. byte* sig = NULL;
  28684. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  28685. int res;
  28686. #ifndef WOLFSSL_NO_ML_DSA_44
  28687. byte b;
  28688. #endif
  28689. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28690. ExpectNotNull(key);
  28691. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  28692. DYNAMIC_TYPE_TMP_BUFFER);
  28693. ExpectNotNull(importKey);
  28694. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28695. DYNAMIC_TYPE_TMP_BUFFER);
  28696. ExpectNotNull(pubKey);
  28697. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28698. ExpectNotNull(sig);
  28699. if (key != NULL) {
  28700. XMEMSET(key, 0, sizeof(*key));
  28701. }
  28702. if (importKey != NULL) {
  28703. XMEMSET(importKey, 0, sizeof(*importKey));
  28704. }
  28705. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28706. XMEMSET(msg, 0x55, sizeof(msg));
  28707. ExpectIntEQ(wc_InitRng(&rng), 0);
  28708. ExpectIntEQ(wc_dilithium_init(key), 0);
  28709. #ifndef WOLFSSL_NO_ML_DSA_44
  28710. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28711. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28712. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28713. #else
  28714. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28715. #endif
  28716. #if !defined(WOLFSSL_NO_ML_DSA_44)
  28717. ExpectIntEQ(wc_dilithium_import_public(ml_dsa_44_pub_key,
  28718. (word32)sizeof(ml_dsa_44_pub_key), key), 0);
  28719. if (sig != NULL) {
  28720. XMEMCPY(sig, ml_dsa_44_good_sig, sizeof(ml_dsa_44_good_sig));
  28721. }
  28722. sigLen = (word32)sizeof(ml_dsa_44_good_sig);
  28723. #else
  28724. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  28725. #ifndef WOLFSSL_NO_ML_DSA_65
  28726. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level3_pub_key,
  28727. sizeof_bench_dilithium_level3_pub_key, key), 0);
  28728. #else
  28729. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level5_pub_key,
  28730. sizeof_bench_dilithium_level5_pub_key, key), 0);
  28731. #endif /* !WOLFSSL_NO_ML_DSA_65 */
  28732. #else
  28733. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28734. #endif /* WOLFSSL_DILITHIUM_NO_MAKE_KEY */
  28735. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  28736. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  28737. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, NULL),
  28738. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28739. ExpectIntEQ(wc_dilithium_export_public(key, NULL, NULL),
  28740. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28741. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, NULL),
  28742. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28743. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, &pubKeyLen),
  28744. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28745. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, &pubKeyLen),
  28746. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28747. ExpectIntEQ(wc_dilithium_export_public(key, NULL, &pubKeyLen),
  28748. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28749. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, NULL),
  28750. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28751. badKeyLen = 0;
  28752. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &badKeyLen),
  28753. WC_NO_ERR_TRACE(BUFFER_E));
  28754. #ifndef WOLFSSL_NO_ML_DSA_44
  28755. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28756. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28757. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28758. #else
  28759. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28760. #endif
  28761. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen), 0);
  28762. #ifndef WOLFSSL_NO_ML_DSA_44
  28763. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28764. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28765. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28766. #else
  28767. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28768. #endif
  28769. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, NULL),
  28770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28771. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, NULL, 32, NULL, NULL),
  28772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28773. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, msg, 32, NULL, NULL),
  28774. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28775. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, &res, NULL),
  28776. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28777. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, key),
  28778. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28779. ExpectIntEQ(wc_dilithium_verify_msg(NULL, sigLen, msg, 32, &res, key),
  28780. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28781. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, msg, 32, &res, key),
  28782. WC_NO_ERR_TRACE(BUFFER_E));
  28783. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, NULL, 32, &res, key),
  28784. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28785. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, NULL, key),
  28786. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28787. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, NULL),
  28788. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28789. res = 0;
  28790. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key), 0);
  28791. ExpectIntEQ(res, 1);
  28792. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  28793. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey),
  28794. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28795. #ifndef WOLFSSL_NO_ML_DSA_44
  28796. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  28797. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28798. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  28799. #else
  28800. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  28801. #endif
  28802. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, NULL),
  28803. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28804. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, NULL),
  28805. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28806. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, NULL),
  28807. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28808. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, importKey),
  28809. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28810. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, importKey),
  28811. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28812. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, importKey),
  28813. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28814. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, NULL),
  28815. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28816. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey), 0);
  28817. res = 0;
  28818. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, importKey),
  28819. 0);
  28820. ExpectIntEQ(res, 1);
  28821. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  28822. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28823. #endif
  28824. wc_dilithium_free(importKey);
  28825. #ifndef WOLFSSL_NO_ML_DSA_44
  28826. if (sig != NULL) {
  28827. if (sig[sigLen - 5] == 0) {
  28828. /* Unused hints meant to be 0. */
  28829. sig[sigLen - 5] = 0xff;
  28830. res = 1;
  28831. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  28832. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  28833. ExpectIntEQ(res, 0);
  28834. sig[sigLen - 5] = 0x00;
  28835. }
  28836. /* Last count of hints must be less than PARAMS_ML_DSA_44_OMEGA == 80 */
  28837. b = sig[sigLen - 1];
  28838. sig[sigLen - 1] = 0xff;
  28839. res = 1;
  28840. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  28841. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  28842. ExpectIntEQ(res, 0);
  28843. sig[sigLen - 1] = b;
  28844. if (sig[sigLen - 4] > 1) {
  28845. /* Index must be less than previous. */
  28846. b = sig[sigLen - 84];
  28847. sig[sigLen - 84] = 0xff;
  28848. res = 1;
  28849. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  28850. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  28851. ExpectIntEQ(res, 0);
  28852. sig[sigLen - 84] = b;
  28853. }
  28854. /* Mess up commit hash. */
  28855. sig[0] ^= 0x80;
  28856. res = 1;
  28857. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  28858. 0);
  28859. ExpectIntEQ(res, 0);
  28860. sig[0] ^= 0x80;
  28861. /* Mess up z. */
  28862. sig[100] ^= 0x80;
  28863. res = 1;
  28864. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  28865. 0);
  28866. ExpectIntEQ(res, 0);
  28867. sig[100] ^= 0x80;
  28868. /* Set all indeces to 0. */
  28869. XMEMSET(sig + sigLen - 4, 0, 4);
  28870. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  28871. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  28872. ExpectIntEQ(res, 0);
  28873. }
  28874. #endif
  28875. wc_dilithium_free(key);
  28876. wc_FreeRng(&rng);
  28877. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28878. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28879. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28880. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28881. #endif
  28882. return EXPECT_RESULT();
  28883. }
  28884. static int test_wc_dilithium_sign_vfy(void)
  28885. {
  28886. EXPECT_DECLS;
  28887. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28888. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT) && \
  28889. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \
  28890. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28891. dilithium_key* key;
  28892. WC_RNG rng;
  28893. byte msg[64];
  28894. byte* sig = NULL;
  28895. word32 sigLen;
  28896. byte ctx[10];
  28897. int res;
  28898. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28899. ExpectNotNull(key);
  28900. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28901. ExpectNotNull(sig);
  28902. if (key != NULL) {
  28903. XMEMSET(key, 0, sizeof(*key));
  28904. }
  28905. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28906. XMEMSET(msg, 0xAA, sizeof(msg));
  28907. XMEMSET(ctx, 0x01, sizeof(ctx));
  28908. ExpectIntEQ(wc_InitRng(&rng), 0);
  28909. #ifndef WOLFSSL_NO_ML_DSA_44
  28910. ExpectIntEQ(wc_dilithium_init(key), 0);
  28911. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28912. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28913. sigLen = DILITHIUM_MAX_SIG_SIZE;
  28914. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  28915. sig, &sigLen, key, &rng), 0);
  28916. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  28917. sizeof(msg), &res, key), 0);
  28918. ExpectIntEQ(res, 1);
  28919. sigLen = DILITHIUM_MAX_SIG_SIZE;
  28920. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  28921. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  28922. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  28923. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  28924. ExpectIntEQ(res, 1);
  28925. wc_dilithium_free(key);
  28926. #endif
  28927. #ifndef WOLFSSL_NO_ML_DSA_65
  28928. ExpectIntEQ(wc_dilithium_init(key), 0);
  28929. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28930. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28931. sigLen = DILITHIUM_MAX_SIG_SIZE;
  28932. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  28933. sig, &sigLen, key, &rng), 0);
  28934. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  28935. sizeof(msg), &res, key), 0);
  28936. ExpectIntEQ(res, 1);
  28937. sigLen = DILITHIUM_MAX_SIG_SIZE;
  28938. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  28939. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  28940. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  28941. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  28942. ExpectIntEQ(res, 1);
  28943. wc_dilithium_free(key);
  28944. #endif
  28945. #ifndef WOLFSSL_NO_ML_DSA_87
  28946. ExpectIntEQ(wc_dilithium_init(key), 0);
  28947. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28948. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28949. sigLen = DILITHIUM_MAX_SIG_SIZE;
  28950. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  28951. sig, &sigLen, key, &rng), 0);
  28952. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  28953. sizeof(msg), &res, key), 0);
  28954. ExpectIntEQ(res, 1);
  28955. sigLen = DILITHIUM_MAX_SIG_SIZE;
  28956. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  28957. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  28958. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  28959. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  28960. ExpectIntEQ(res, 1);
  28961. wc_dilithium_free(key);
  28962. #endif
  28963. wc_FreeRng(&rng);
  28964. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28965. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28966. #endif
  28967. return EXPECT_RESULT();
  28968. }
  28969. static int test_wc_dilithium_check_key(void)
  28970. {
  28971. EXPECT_DECLS;
  28972. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28973. defined(WOLFSSL_DILITHIUM_CHECK_KEY) && \
  28974. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  28975. dilithium_key* checkKey;
  28976. WC_RNG rng;
  28977. byte* privCheckKey = NULL;
  28978. word32 privCheckKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28979. byte* pubCheckKey = NULL;
  28980. word32 pubCheckKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28981. checkKey = (dilithium_key*)XMALLOC(sizeof(*checkKey), NULL,
  28982. DYNAMIC_TYPE_TMP_BUFFER);
  28983. ExpectNotNull(checkKey);
  28984. privCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28985. DYNAMIC_TYPE_TMP_BUFFER);
  28986. ExpectNotNull(privCheckKey);
  28987. pubCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28988. DYNAMIC_TYPE_TMP_BUFFER);
  28989. ExpectNotNull(pubCheckKey);
  28990. if (checkKey != NULL) {
  28991. XMEMSET(checkKey, 0, sizeof(*checkKey));
  28992. }
  28993. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28994. ExpectIntEQ(wc_InitRng(&rng), 0);
  28995. ExpectIntEQ(wc_dilithium_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28996. ExpectIntEQ(wc_dilithium_init(checkKey), 0);
  28997. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey,
  28998. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28999. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29000. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29001. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29002. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29003. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29004. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29005. #ifndef WOLFSSL_NO_ML_DSA_44
  29006. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_44), 0);
  29007. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29008. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_65), 0);
  29009. #else
  29010. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_87), 0);
  29011. #endif
  29012. ExpectIntEQ(wc_dilithium_make_key(checkKey, &rng), 0);
  29013. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL, NULL),
  29014. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29015. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL, NULL, NULL, NULL),
  29016. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29017. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey, NULL, NULL, NULL),
  29018. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29019. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, &privCheckKeyLen, NULL,
  29020. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29021. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, pubCheckKey, NULL),
  29022. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29023. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL,
  29024. &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29025. ExpectIntEQ(wc_dilithium_export_key(NULL , privCheckKey,
  29026. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29027. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL ,
  29028. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29029. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29030. NULL , pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29031. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29032. &privCheckKeyLen, NULL , &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29033. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29034. &privCheckKeyLen, pubCheckKey, NULL ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29035. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29036. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), 0);
  29037. /* Modify hash. */
  29038. if (pubCheckKey != NULL) {
  29039. pubCheckKey[0] ^= 0x80;
  29040. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, NULL),
  29041. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29042. ExpectIntEQ(wc_dilithium_import_key(privCheckKey, 0, NULL, 0, NULL),
  29043. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29044. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, pubCheckKey, 0, NULL),
  29045. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29046. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, checkKey),
  29047. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29048. ExpectIntEQ(wc_dilithium_import_key(NULL ,
  29049. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey),
  29050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29051. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29052. 0 , pubCheckKey, pubCheckKeyLen, checkKey),
  29053. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29054. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29055. privCheckKeyLen, NULL , pubCheckKeyLen, checkKey),
  29056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29057. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29058. privCheckKeyLen, pubCheckKey, 0 , checkKey),
  29059. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29060. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29061. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL ),
  29062. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29063. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29064. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29065. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29066. pubCheckKey[0] ^= 0x80;
  29067. /* Modify encoded t1. */
  29068. pubCheckKey[48] ^= 0x80;
  29069. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29070. privCheckKeyLen,pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29071. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29072. pubCheckKey[48] ^= 0x80;
  29073. }
  29074. wc_dilithium_free(checkKey);
  29075. wc_FreeRng(&rng);
  29076. XFREE(pubCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29077. XFREE(privCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29078. XFREE(checkKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29079. #endif
  29080. return EXPECT_RESULT();
  29081. }
  29082. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29083. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  29084. static const unsigned char dilithium_public_der[] = {
  29085. #ifndef WOLFSSL_NO_ML_DSA_44
  29086. 0x30, 0x82, 0x05, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29087. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29088. 0x0c, 0x04, 0x04, 0x03, 0x82, 0x05, 0x21, 0x00,
  29089. 0x0a, 0xf7, 0xc8, 0xa4, 0x96, 0x01, 0xa7, 0xb2,
  29090. 0x2e, 0x4d, 0xc9, 0xd9, 0x1c, 0xa1, 0x86, 0x09,
  29091. 0xce, 0x14, 0x6f, 0xe8, 0x33, 0x3c, 0x7b, 0xdb,
  29092. 0x19, 0x9c, 0x56, 0x39, 0x6a, 0x6c, 0x5d, 0x1f,
  29093. 0xe4, 0x26, 0xcb, 0x16, 0x91, 0x4d, 0xeb, 0x5a,
  29094. 0x36, 0x22, 0xee, 0xda, 0xdf, 0x46, 0x3e, 0xa1,
  29095. 0x4f, 0x9a, 0x30, 0xb5, 0x3f, 0x60, 0xf7, 0x75,
  29096. 0x47, 0xdc, 0x55, 0xf1, 0xbe, 0xbc, 0x87, 0x6c,
  29097. 0x50, 0x7c, 0x21, 0x55, 0x35, 0xad, 0xa7, 0xf9,
  29098. 0x1c, 0xf8, 0xa1, 0x92, 0x79, 0x10, 0x52, 0x7a,
  29099. 0xc3, 0xba, 0xd3, 0x9d, 0xc6, 0x9b, 0xf4, 0xcb,
  29100. 0x1b, 0xa2, 0xde, 0x83, 0x86, 0xa6, 0x35, 0xea,
  29101. 0xf2, 0x8c, 0xdc, 0xba, 0x3e, 0xef, 0x9c, 0xf5,
  29102. 0x8e, 0xc3, 0xb0, 0xc0, 0x5b, 0xcc, 0x35, 0x6a,
  29103. 0x81, 0xe5, 0x17, 0xb3, 0x9a, 0x57, 0xa6, 0x4a,
  29104. 0x87, 0xb1, 0xa7, 0xf5, 0xa2, 0x96, 0x40, 0x8b,
  29105. 0xc1, 0x62, 0xb2, 0xd9, 0x76, 0xe8, 0x51, 0x33,
  29106. 0x44, 0x3d, 0xeb, 0x14, 0x86, 0x88, 0x2c, 0xc1,
  29107. 0x47, 0xba, 0x2b, 0x85, 0x3b, 0x72, 0xcb, 0x9f,
  29108. 0x40, 0xba, 0x19, 0x58, 0xa4, 0x34, 0x0a, 0xd2,
  29109. 0x8c, 0x97, 0xbd, 0x3d, 0x09, 0xb0, 0x4a, 0xeb,
  29110. 0xaa, 0xee, 0x58, 0x1e, 0xc1, 0x19, 0x26, 0x70,
  29111. 0x15, 0xa5, 0x17, 0x7e, 0xd0, 0xa1, 0x08, 0xf9,
  29112. 0x6d, 0xcf, 0x20, 0x62, 0x95, 0x8e, 0x61, 0xf4,
  29113. 0x29, 0x96, 0x6f, 0x38, 0x1c, 0x67, 0xd5, 0xa6,
  29114. 0x4c, 0xf5, 0x1f, 0xda, 0x12, 0x22, 0x24, 0x6b,
  29115. 0x0d, 0xb7, 0x6a, 0xe5, 0xaf, 0x6c, 0x89, 0x52,
  29116. 0xc2, 0x85, 0x85, 0x5f, 0x16, 0x33, 0x0c, 0xc6,
  29117. 0x7a, 0xe0, 0xa8, 0xed, 0x13, 0x58, 0xf3, 0xa0,
  29118. 0x80, 0x42, 0x3c, 0xe3, 0x57, 0xd1, 0xe2, 0x66,
  29119. 0xc4, 0xe0, 0x3d, 0x49, 0x32, 0x21, 0xd9, 0xa1,
  29120. 0x3c, 0x93, 0x0a, 0xf7, 0x5f, 0x34, 0x65, 0xa4,
  29121. 0x30, 0xf9, 0xe7, 0x8a, 0x96, 0x04, 0xdb, 0xc5,
  29122. 0x16, 0x15, 0x10, 0x74, 0x4f, 0xc9, 0x6b, 0x4b,
  29123. 0x66, 0x29, 0xb0, 0xd1, 0x3b, 0xdd, 0x41, 0x0a,
  29124. 0xfe, 0xdf, 0x5f, 0x72, 0x91, 0xbc, 0x99, 0x2f,
  29125. 0x8d, 0x72, 0x3a, 0x4a, 0xde, 0x11, 0x3a, 0x20,
  29126. 0xb2, 0x56, 0xb5, 0x73, 0x89, 0xb4, 0x63, 0x37,
  29127. 0x86, 0xbd, 0x99, 0x8b, 0x03, 0x56, 0x50, 0x21,
  29128. 0x11, 0x78, 0x8c, 0xd5, 0xc1, 0x92, 0x33, 0x72,
  29129. 0x6e, 0x8d, 0x88, 0x2d, 0x10, 0x8f, 0x31, 0xd3,
  29130. 0x23, 0xe5, 0xaa, 0x1f, 0xe1, 0x37, 0xec, 0x34,
  29131. 0x42, 0x30, 0x75, 0xff, 0xb2, 0x1a, 0x8e, 0x29,
  29132. 0x03, 0x4c, 0xfd, 0xdf, 0x53, 0xf2, 0x0b, 0x2d,
  29133. 0xf9, 0x1c, 0x9e, 0xb6, 0x5a, 0x6c, 0x5e, 0x88,
  29134. 0x48, 0x29, 0x89, 0x42, 0xfc, 0x97, 0xfb, 0x27,
  29135. 0x1c, 0x99, 0x2a, 0xbf, 0x7f, 0x04, 0xb2, 0xcd,
  29136. 0xc9, 0x3a, 0x39, 0xfe, 0x4f, 0x47, 0x92, 0x0b,
  29137. 0x85, 0xfc, 0x92, 0x57, 0xc5, 0x0b, 0x23, 0x1f,
  29138. 0x0b, 0x72, 0xb4, 0xde, 0xfe, 0xbe, 0xb7, 0x39,
  29139. 0xb3, 0xd7, 0x48, 0x03, 0xed, 0x76, 0xac, 0x63,
  29140. 0xf7, 0x2a, 0x58, 0xef, 0xdb, 0x63, 0x5a, 0x56,
  29141. 0x68, 0xcc, 0xb2, 0x8b, 0x22, 0xac, 0xdf, 0xc4,
  29142. 0xad, 0x6f, 0xad, 0x24, 0xfd, 0x30, 0xfb, 0xed,
  29143. 0x6e, 0xde, 0x65, 0x2b, 0xb4, 0x57, 0x35, 0x49,
  29144. 0xc1, 0xc9, 0x82, 0xf4, 0x72, 0x69, 0xef, 0x34,
  29145. 0xc0, 0x37, 0x8b, 0x8b, 0xd3, 0xd3, 0x25, 0xcc,
  29146. 0xe5, 0xf5, 0xf6, 0x9c, 0xa3, 0xe7, 0x88, 0xd7,
  29147. 0x55, 0x73, 0x31, 0x4c, 0xb1, 0x7b, 0x64, 0xb3,
  29148. 0x38, 0xde, 0x47, 0x9a, 0xfc, 0xf1, 0xfa, 0xf8,
  29149. 0x6e, 0xc5, 0x95, 0xb9, 0xaf, 0x6a, 0x7a, 0x94,
  29150. 0x80, 0x0d, 0x29, 0x62, 0x99, 0x0a, 0x34, 0xa2,
  29151. 0x8f, 0xa1, 0x5e, 0x98, 0x7c, 0x4e, 0x18, 0xcd,
  29152. 0x63, 0x68, 0x0e, 0xfa, 0x6f, 0x49, 0x01, 0x02,
  29153. 0xcd, 0xf1, 0xc1, 0x09, 0x57, 0xa3, 0x03, 0xec,
  29154. 0x94, 0x36, 0xab, 0xc6, 0x1c, 0xc0, 0x98, 0x22,
  29155. 0x15, 0x5b, 0x5b, 0x61, 0x3c, 0xc2, 0x5b, 0x6f,
  29156. 0x1c, 0x82, 0x41, 0x39, 0x87, 0xde, 0x92, 0xa9,
  29157. 0xe4, 0x12, 0x74, 0x3b, 0x31, 0x36, 0xac, 0x92,
  29158. 0xb0, 0x23, 0x26, 0xfa, 0xd8, 0xa3, 0xe8, 0x84,
  29159. 0xfc, 0x52, 0xc5, 0x7b, 0xd1, 0x4b, 0xe2, 0x1a,
  29160. 0x33, 0xdd, 0x3c, 0xdf, 0x27, 0x50, 0x6f, 0x12,
  29161. 0xd3, 0x17, 0x66, 0xd7, 0x54, 0x33, 0x30, 0x2b,
  29162. 0xe8, 0xd1, 0x1f, 0x2d, 0xf3, 0x37, 0x81, 0xa0,
  29163. 0x3c, 0x21, 0x8c, 0xea, 0x95, 0xa5, 0x5b, 0x3a,
  29164. 0x24, 0xed, 0xf7, 0x67, 0x7b, 0x72, 0x3a, 0xda,
  29165. 0x31, 0xbd, 0xa7, 0x63, 0xa6, 0x6f, 0xf9, 0xdf,
  29166. 0x06, 0x36, 0xb4, 0xe2, 0x35, 0x4b, 0xa5, 0x8e,
  29167. 0x29, 0x8e, 0x6c, 0x02, 0xc5, 0x06, 0x9b, 0x98,
  29168. 0x6e, 0x5e, 0x00, 0x6a, 0x42, 0x09, 0x4b, 0xc3,
  29169. 0x09, 0x37, 0x67, 0x19, 0x58, 0x6d, 0x40, 0x50,
  29170. 0xb0, 0x62, 0x5b, 0xd6, 0x63, 0x7f, 0xed, 0xb0,
  29171. 0x97, 0x80, 0x9e, 0x91, 0x3f, 0x82, 0xfd, 0x83,
  29172. 0x36, 0xce, 0x06, 0xc4, 0xdc, 0xa4, 0x1e, 0x70,
  29173. 0xd4, 0x94, 0xfc, 0x6e, 0x46, 0xa3, 0xc8, 0xed,
  29174. 0x34, 0x0a, 0xb1, 0x9a, 0x66, 0x5d, 0xc0, 0xce,
  29175. 0x73, 0xd3, 0x65, 0xcb, 0xfb, 0x79, 0xdd, 0xf6,
  29176. 0x19, 0xf6, 0xd8, 0xa9, 0xe6, 0x34, 0x15, 0x86,
  29177. 0x7a, 0x30, 0x79, 0xde, 0x2b, 0x06, 0xa4, 0xc0,
  29178. 0xc8, 0xa2, 0xc1, 0x41, 0xb3, 0x4c, 0xf6, 0xdb,
  29179. 0x16, 0xcd, 0xd2, 0x8b, 0xf1, 0x18, 0x5a, 0xc8,
  29180. 0x3e, 0xd9, 0x54, 0x40, 0xd4, 0xce, 0x88, 0xbb,
  29181. 0x66, 0xf1, 0x74, 0x20, 0xa2, 0x3c, 0x31, 0x09,
  29182. 0xba, 0xac, 0x61, 0x15, 0x9f, 0x73, 0x5f, 0xa7,
  29183. 0xe5, 0x0d, 0xb3, 0xab, 0xa2, 0x72, 0x25, 0xc9,
  29184. 0x87, 0x9b, 0x18, 0xdb, 0xff, 0xfb, 0x39, 0x84,
  29185. 0x8d, 0xf8, 0x97, 0x47, 0xab, 0xc4, 0xfb, 0xc2,
  29186. 0xd8, 0xe8, 0xce, 0x6e, 0x65, 0x76, 0x88, 0x4a,
  29187. 0x22, 0x2f, 0xdd, 0x43, 0xa7, 0xc4, 0x8d, 0x32,
  29188. 0x12, 0x75, 0x0b, 0x72, 0xd6, 0xb7, 0x43, 0x84,
  29189. 0xc8, 0x59, 0xa8, 0xb7, 0x8b, 0x84, 0x33, 0x92,
  29190. 0x8f, 0x94, 0xe8, 0xd0, 0xaf, 0x11, 0x35, 0xde,
  29191. 0xb7, 0x63, 0xb8, 0x91, 0x4c, 0x96, 0x4e, 0x9c,
  29192. 0x62, 0x28, 0xa2, 0xbc, 0x0b, 0x90, 0xae, 0x94,
  29193. 0x90, 0xe9, 0x32, 0xeb, 0xe3, 0x77, 0x60, 0x5f,
  29194. 0x87, 0x48, 0x4b, 0xb0, 0x78, 0x0e, 0xe2, 0x85,
  29195. 0x47, 0x06, 0xa4, 0xc9, 0x26, 0xac, 0x8f, 0xe7,
  29196. 0xc2, 0xc7, 0xce, 0xf5, 0xd1, 0x20, 0xa8, 0x56,
  29197. 0xe1, 0x4f, 0x50, 0x90, 0xb3, 0xc1, 0x03, 0x57,
  29198. 0xd3, 0x62, 0x0e, 0x2a, 0xe8, 0x86, 0xf4, 0x94,
  29199. 0x0e, 0xa5, 0x8b, 0x4e, 0x73, 0xa2, 0x76, 0xac,
  29200. 0x00, 0x29, 0xe5, 0x80, 0x26, 0x02, 0x13, 0xd1,
  29201. 0xb2, 0x68, 0x72, 0x23, 0x38, 0x55, 0xfc, 0x4d,
  29202. 0x05, 0x60, 0x49, 0x7b, 0xfb, 0xaa, 0x17, 0x8f,
  29203. 0x26, 0x0a, 0x08, 0x33, 0x8d, 0x7f, 0x4e, 0xe5,
  29204. 0x6e, 0xf8, 0x84, 0x9b, 0x9f, 0xcb, 0xa2, 0x2b,
  29205. 0xfb, 0xaf, 0xad, 0x21, 0xe2, 0x4f, 0x6f, 0x55,
  29206. 0xc1, 0x78, 0x46, 0xe3, 0xb5, 0x63, 0x06, 0x9b,
  29207. 0x93, 0x7d, 0xac, 0xd4, 0xe0, 0x64, 0x01, 0x8d,
  29208. 0xac, 0x30, 0x8b, 0x8b, 0x55, 0xb7, 0x8a, 0x16,
  29209. 0x3f, 0xc9, 0x82, 0x7f, 0xb5, 0x3b, 0x0d, 0xc0,
  29210. 0x46, 0x89, 0x5c, 0x6c, 0x45, 0x21, 0x78, 0xda,
  29211. 0x84, 0x1f, 0xc8, 0xcf, 0xf1, 0x1e, 0x79, 0x71,
  29212. 0x3b, 0xc8, 0xe2, 0x8b, 0x41, 0xfe, 0xaf, 0x2f,
  29213. 0x3b, 0x23, 0x13, 0xc5, 0x46, 0x87, 0xc6, 0x24,
  29214. 0x37, 0x21, 0x68, 0x8a, 0x3e, 0x45, 0x61, 0xf4,
  29215. 0xad, 0xf5, 0x1c, 0x23, 0x45, 0xa3, 0x42, 0xf2,
  29216. 0xa9, 0xac, 0x94, 0x50, 0xc9, 0x3d, 0x5e, 0x70,
  29217. 0x33, 0x2b, 0x78, 0xd1, 0x5c, 0x13, 0x35, 0xe6,
  29218. 0x13, 0x80, 0x5e, 0x55, 0xa7, 0xcc, 0x67, 0xb0,
  29219. 0x6c, 0xfe, 0xa2, 0x24, 0x02, 0x6d, 0xb3, 0xcb,
  29220. 0x9e, 0x94, 0xb3, 0xc6, 0x01, 0xf3, 0x01, 0x3a,
  29221. 0xe4, 0xa7, 0xa3, 0xdf, 0x56, 0x4c, 0x30, 0xce,
  29222. 0xb1, 0xd5, 0x1b, 0x68, 0x9b, 0x75, 0xae, 0xf4,
  29223. 0xb9, 0x2a, 0xe5, 0x8b, 0x7b, 0xe5, 0x99, 0x46,
  29224. 0x5f, 0x29, 0xf6, 0x82, 0xd0, 0x42, 0xb1, 0x45,
  29225. 0x09, 0x16, 0x5b, 0x32, 0x11, 0xca, 0x48, 0xea,
  29226. 0x51, 0x12, 0x0a, 0x9f, 0x6e, 0x3f, 0x74, 0xe6,
  29227. 0xe0, 0xfe, 0xf8, 0xa5, 0xc0, 0xfd, 0x15, 0x6e,
  29228. 0x2b, 0x4a, 0xd5, 0x76, 0xa8, 0x3d, 0xe3, 0x0d,
  29229. 0xfe, 0x44, 0x11, 0x5e, 0x7a, 0xde, 0x12, 0x29,
  29230. 0x5a, 0x5a, 0x25, 0xc0, 0x8e, 0x98, 0xd1, 0x11,
  29231. 0xc8, 0x00, 0x65, 0xb2, 0xf4, 0xd7, 0x56, 0x32,
  29232. 0x46, 0x2b, 0x4f, 0x7e, 0xc3, 0x4e, 0xf1, 0x17,
  29233. 0xff, 0x03, 0x32, 0xae, 0xe3, 0xbe, 0x0b, 0xab,
  29234. 0xfb, 0x43, 0x0f, 0x6d, 0xa5, 0xc6, 0x44, 0xba,
  29235. 0xc9, 0xe3, 0x3d, 0x40, 0xe7, 0x6c, 0xe8, 0x21,
  29236. 0xb2, 0x46, 0x7b, 0x3b, 0x3d, 0xde, 0x80, 0xc8,
  29237. 0xea, 0xf4, 0x6b, 0xf3, 0x53, 0xca, 0x51, 0x84,
  29238. 0xcf, 0xad, 0x7e, 0xce, 0xce, 0xc2, 0x65, 0xfc,
  29239. 0x03, 0x8c, 0xcb, 0xfa, 0xcb, 0x37, 0x89, 0x82,
  29240. 0x59, 0x5e, 0x36, 0x52, 0xe4, 0xbc, 0x8d, 0x47,
  29241. 0x7c, 0xb8, 0x3f, 0x63, 0x59, 0xdc, 0xd3, 0x74,
  29242. 0x11, 0x33, 0xb4, 0x69, 0x74, 0x40, 0x0d, 0x42,
  29243. 0x63, 0x1d, 0xe6, 0x5c, 0x1b, 0xca, 0x41, 0xff,
  29244. 0x23, 0x4e, 0xe8, 0x3d, 0x14, 0xa8, 0x17, 0x18,
  29245. 0xd0, 0x78, 0x08, 0x87, 0x7d, 0x5e, 0xdc, 0x3a,
  29246. 0x07, 0xba, 0x12, 0x8e, 0x8e, 0x56, 0x0a, 0xcb,
  29247. 0x37, 0xf6, 0x54, 0xeb, 0x55, 0x16, 0x8f, 0x06,
  29248. 0x15, 0x28, 0x6b, 0xfb, 0xed, 0x38, 0x9e, 0x9b,
  29249. 0x98, 0x5b, 0xdc, 0x67, 0x33, 0x0e, 0x02, 0x36,
  29250. 0x1b, 0x7a, 0x9a, 0x43, 0xcd, 0xf2, 0x65, 0xef,
  29251. 0x37, 0x19, 0x24, 0x6f, 0x4b, 0xb9, 0x4d, 0x3e,
  29252. 0x0b, 0x47, 0xd1, 0x67, 0x50, 0x6a, 0x7f, 0x07
  29253. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29254. 0x30, 0x82, 0x07, 0xb4, 0x30, 0x0d, 0x06, 0x0b,
  29255. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29256. 0x0c, 0x06, 0x05, 0x03, 0x82, 0x07, 0xa1, 0x00,
  29257. 0xff, 0x89, 0xee, 0xad, 0x20, 0x8f, 0x61, 0xa4,
  29258. 0x07, 0x1c, 0x54, 0x98, 0x8c, 0xf4, 0x2e, 0xd9,
  29259. 0xe6, 0x0f, 0xcb, 0x0e, 0xab, 0xa1, 0x37, 0x4d,
  29260. 0xc0, 0x48, 0x24, 0x78, 0xd6, 0x2d, 0x9b, 0x6f,
  29261. 0x0f, 0x17, 0x08, 0x71, 0xc3, 0xd1, 0xc8, 0x7a,
  29262. 0xe7, 0x32, 0xcb, 0xcd, 0xd6, 0xb5, 0x90, 0x08,
  29263. 0xe1, 0xda, 0xaa, 0x89, 0x3e, 0x4a, 0x62, 0x98,
  29264. 0x3d, 0xc6, 0x71, 0x30, 0xb4, 0x63, 0xa5, 0x3b,
  29265. 0xb3, 0x69, 0x75, 0x10, 0xaf, 0x5e, 0x72, 0x78,
  29266. 0xa2, 0xef, 0x63, 0x63, 0x21, 0xe7, 0xf4, 0xa7,
  29267. 0x9c, 0x50, 0x74, 0x14, 0x3e, 0xdd, 0x73, 0x9e,
  29268. 0x97, 0x65, 0xdd, 0xdf, 0x3c, 0x40, 0x4d, 0x03,
  29269. 0x49, 0xe4, 0xbf, 0x65, 0xe7, 0x44, 0x8f, 0x59,
  29270. 0x00, 0xe2, 0x98, 0xb5, 0x66, 0xa3, 0x3b, 0x11,
  29271. 0x9f, 0xc7, 0xc2, 0x16, 0x61, 0xf0, 0x1e, 0x89,
  29272. 0xc8, 0x96, 0x8d, 0x18, 0xac, 0x86, 0xa0, 0xe2,
  29273. 0xd9, 0x8c, 0xef, 0x53, 0x6d, 0x4e, 0x74, 0xc9,
  29274. 0x66, 0x28, 0x16, 0xf3, 0x62, 0xc4, 0x6f, 0x2b,
  29275. 0x6e, 0x36, 0x03, 0xad, 0xc5, 0xe4, 0x8f, 0x0b,
  29276. 0x90, 0x8c, 0x8f, 0xff, 0x5d, 0xdf, 0x7a, 0xe6,
  29277. 0xaf, 0x9a, 0x43, 0xbc, 0xd4, 0x73, 0x22, 0xdc,
  29278. 0x5f, 0x08, 0xa1, 0x17, 0x97, 0x89, 0x79, 0xf5,
  29279. 0xdc, 0xed, 0x4f, 0x85, 0x8e, 0x0c, 0x23, 0x35,
  29280. 0x3c, 0x34, 0x19, 0x65, 0xf5, 0xd6, 0xc9, 0x2d,
  29281. 0x7a, 0x2e, 0x67, 0xd5, 0xf1, 0x82, 0x97, 0xaa,
  29282. 0x05, 0x26, 0x84, 0x25, 0x47, 0x58, 0x2c, 0xe6,
  29283. 0x59, 0xc7, 0x98, 0x7a, 0xdb, 0x40, 0x45, 0x1c,
  29284. 0x71, 0x55, 0x2e, 0xea, 0x3f, 0x6e, 0x7c, 0x82,
  29285. 0x52, 0x6a, 0x19, 0x3a, 0xd3, 0xa1, 0x3c, 0xce,
  29286. 0x00, 0x06, 0xec, 0xed, 0x97, 0xce, 0xd8, 0xdf,
  29287. 0xde, 0xa3, 0xed, 0xe7, 0x81, 0x62, 0x02, 0x9c,
  29288. 0x1b, 0x51, 0xa1, 0xf4, 0x9d, 0x1b, 0x28, 0x76,
  29289. 0x93, 0x96, 0x20, 0x55, 0x60, 0x1f, 0xaf, 0x52,
  29290. 0xc3, 0xce, 0xb9, 0x12, 0x66, 0xf5, 0x64, 0x22,
  29291. 0x87, 0x86, 0x29, 0x80, 0x8f, 0x18, 0x33, 0xba,
  29292. 0x48, 0x71, 0x1d, 0x00, 0xfe, 0xa5, 0xfc, 0xc6,
  29293. 0x87, 0xbe, 0x44, 0x3c, 0xc9, 0x49, 0xfb, 0x68,
  29294. 0x3c, 0xdf, 0xca, 0xef, 0xa7, 0xdc, 0x67, 0xb8,
  29295. 0x28, 0xd6, 0xad, 0x18, 0xaf, 0xad, 0x1f, 0x4c,
  29296. 0x85, 0xa3, 0x64, 0xac, 0x3f, 0xa9, 0x39, 0x28,
  29297. 0xef, 0x8a, 0x45, 0x7e, 0xb0, 0xf4, 0x89, 0x72,
  29298. 0xf7, 0xb1, 0xef, 0x9d, 0x1c, 0x3c, 0x93, 0xcb,
  29299. 0xa0, 0xfb, 0x2a, 0x90, 0xe2, 0x1d, 0x49, 0x8e,
  29300. 0x36, 0xb8, 0x07, 0xf4, 0xb3, 0x09, 0xf0, 0x6f,
  29301. 0x3c, 0xd9, 0x37, 0x19, 0x57, 0xd4, 0x1e, 0x2a,
  29302. 0xa2, 0xa7, 0x2e, 0xc1, 0xcd, 0x8d, 0x48, 0x47,
  29303. 0xb5, 0x8a, 0x12, 0x93, 0x34, 0xb8, 0xec, 0x32,
  29304. 0x07, 0x49, 0xb6, 0x8d, 0x73, 0xd4, 0x2c, 0x6a,
  29305. 0xa0, 0x33, 0x29, 0x21, 0x5d, 0x37, 0xa9, 0x39,
  29306. 0x40, 0xbe, 0x71, 0x29, 0xbe, 0xd1, 0x4b, 0xbc,
  29307. 0x9a, 0x17, 0x93, 0x52, 0xb8, 0x81, 0xee, 0xc5,
  29308. 0xff, 0x25, 0x78, 0x2f, 0x52, 0x0a, 0x8f, 0xb2,
  29309. 0xef, 0xf3, 0x1d, 0x68, 0x56, 0x31, 0x29, 0x84,
  29310. 0x55, 0x47, 0x32, 0x34, 0x0f, 0x60, 0x07, 0xd6,
  29311. 0x2b, 0xb9, 0x29, 0xaf, 0x0f, 0xcd, 0x1c, 0xc0,
  29312. 0x77, 0x4c, 0xc6, 0x31, 0xdb, 0xf4, 0x17, 0xbe,
  29313. 0x3d, 0xf8, 0x8c, 0xf1, 0x02, 0x7c, 0x6b, 0xd4,
  29314. 0xaf, 0x03, 0xb2, 0xf4, 0x78, 0x8d, 0xd3, 0x4e,
  29315. 0x5c, 0x04, 0xb9, 0x01, 0xe3, 0x73, 0xb4, 0x67,
  29316. 0xe9, 0xa8, 0x77, 0x6f, 0x87, 0x2b, 0xe2, 0x00,
  29317. 0x98, 0x5f, 0x02, 0x43, 0x85, 0x03, 0x4c, 0x71,
  29318. 0xd2, 0xe7, 0x61, 0x03, 0x22, 0x9e, 0xe5, 0xc2,
  29319. 0xa7, 0x66, 0x42, 0x7c, 0x9f, 0xf4, 0xb8, 0x6b,
  29320. 0x2d, 0xe4, 0xaa, 0x51, 0xda, 0x08, 0x73, 0x75,
  29321. 0x26, 0x45, 0xdc, 0xa6, 0x20, 0xd7, 0xcb, 0x00,
  29322. 0xfc, 0xe4, 0xdb, 0x28, 0x92, 0xf8, 0xb0, 0xc7,
  29323. 0xf0, 0x4b, 0x6d, 0xe8, 0xc1, 0x84, 0x38, 0xed,
  29324. 0x1a, 0xd4, 0x66, 0x69, 0xc4, 0x96, 0x40, 0xc4,
  29325. 0x7d, 0xfa, 0x58, 0x70, 0x7e, 0x70, 0x40, 0xba,
  29326. 0xfc, 0x95, 0xb6, 0x4c, 0x7c, 0x58, 0xbc, 0xb3,
  29327. 0x59, 0x08, 0x14, 0x03, 0x35, 0xf3, 0xf1, 0xaa,
  29328. 0xd5, 0xa2, 0x57, 0x70, 0xb6, 0x20, 0x75, 0x0a,
  29329. 0x58, 0x66, 0x74, 0xf7, 0x1c, 0xfd, 0x99, 0x7c,
  29330. 0x20, 0xda, 0xe7, 0x76, 0xcb, 0xf4, 0xa3, 0x9b,
  29331. 0xbc, 0x8f, 0x74, 0xef, 0xe2, 0x46, 0x5a, 0x72,
  29332. 0x33, 0x06, 0x32, 0x1e, 0xbd, 0x4e, 0x4c, 0xf6,
  29333. 0x16, 0x43, 0xa5, 0xa5, 0xa5, 0x6c, 0x76, 0x33,
  29334. 0x35, 0x63, 0xdc, 0xe4, 0xec, 0x7f, 0x8a, 0xfa,
  29335. 0xc3, 0x53, 0x69, 0x28, 0xf7, 0xd6, 0x97, 0xb9,
  29336. 0x3a, 0xf4, 0x15, 0x90, 0x50, 0xd3, 0xdf, 0xf5,
  29337. 0xd3, 0xcf, 0x15, 0x76, 0xe3, 0x3d, 0x24, 0x14,
  29338. 0xfd, 0xd3, 0x01, 0x25, 0x82, 0xb4, 0xe3, 0xd8,
  29339. 0x68, 0x89, 0x86, 0xa8, 0x26, 0x02, 0x5f, 0xc6,
  29340. 0xf4, 0x99, 0x3b, 0x97, 0xa8, 0x65, 0xed, 0x18,
  29341. 0xbb, 0x3c, 0x43, 0x4a, 0x6e, 0xaa, 0xbc, 0x83,
  29342. 0x85, 0x19, 0x9f, 0x9b, 0xb8, 0xa4, 0xa3, 0xb2,
  29343. 0xb7, 0x56, 0x07, 0x6c, 0xbf, 0x7d, 0xff, 0x5d,
  29344. 0xb5, 0x1e, 0x83, 0xc8, 0x74, 0x70, 0x98, 0x17,
  29345. 0x40, 0xe0, 0x2d, 0xad, 0x31, 0x00, 0x8e, 0x42,
  29346. 0xd5, 0xb2, 0x25, 0xaa, 0x82, 0xaf, 0x33, 0xd8,
  29347. 0x5b, 0xe2, 0x07, 0xed, 0xda, 0x84, 0xe9, 0xa2,
  29348. 0xff, 0xbb, 0xa5, 0x47, 0x95, 0x6e, 0xa1, 0x8d,
  29349. 0x59, 0x52, 0xeb, 0xf3, 0x3c, 0x18, 0x29, 0x92,
  29350. 0x72, 0x27, 0x18, 0xfc, 0x95, 0xb9, 0xde, 0x46,
  29351. 0xda, 0xcc, 0x4c, 0x31, 0x1d, 0x78, 0x86, 0xd2,
  29352. 0x8c, 0x38, 0x9c, 0x32, 0xab, 0xf7, 0xca, 0x73,
  29353. 0x85, 0xa5, 0xf1, 0xe0, 0x25, 0x06, 0xf9, 0x18,
  29354. 0x14, 0xab, 0x3b, 0x73, 0x26, 0xee, 0xa0, 0xfd,
  29355. 0x15, 0xac, 0xd6, 0x4e, 0x6b, 0xdb, 0x01, 0xa1,
  29356. 0xdc, 0xd1, 0x2f, 0xd2, 0xb7, 0x5e, 0x12, 0x4f,
  29357. 0x4b, 0x59, 0xd8, 0x03, 0x12, 0x60, 0xc9, 0x81,
  29358. 0xb7, 0x06, 0x23, 0x09, 0xc4, 0xd9, 0xa8, 0x93,
  29359. 0x6e, 0x96, 0xf4, 0x93, 0x53, 0xf0, 0x3d, 0xde,
  29360. 0x10, 0x88, 0xb1, 0xd0, 0xcc, 0xad, 0x2c, 0xbf,
  29361. 0x88, 0x98, 0x8f, 0x25, 0x76, 0xd7, 0x65, 0x77,
  29362. 0xcc, 0x36, 0x1d, 0x1b, 0x6b, 0x60, 0x58, 0xc4,
  29363. 0xfe, 0xe6, 0xca, 0xa8, 0x29, 0x33, 0x69, 0x36,
  29364. 0xb8, 0x12, 0x95, 0x38, 0xd9, 0xd4, 0x16, 0xe9,
  29365. 0x3e, 0x40, 0x8c, 0xc7, 0xae, 0x04, 0x11, 0xdf,
  29366. 0x51, 0xd3, 0xdd, 0xbf, 0xa9, 0x41, 0x43, 0x4c,
  29367. 0xff, 0x87, 0x2f, 0xea, 0x0f, 0x13, 0x66, 0x2a,
  29368. 0x2b, 0x18, 0xe8, 0xc4, 0xff, 0xa0, 0x1c, 0x78,
  29369. 0x79, 0x21, 0xf8, 0xaa, 0x8a, 0xf8, 0x92, 0xdf,
  29370. 0x7b, 0x5f, 0x6a, 0x71, 0x60, 0x67, 0x5d, 0x94,
  29371. 0xf6, 0xbb, 0x1d, 0x90, 0x7c, 0x51, 0x70, 0x1d,
  29372. 0x87, 0xde, 0xf8, 0x91, 0xcb, 0x42, 0x9f, 0xc7,
  29373. 0x4b, 0xa0, 0x16, 0xee, 0xb4, 0x73, 0xe8, 0xe0,
  29374. 0x0b, 0xa5, 0xd3, 0x26, 0x9e, 0x52, 0xda, 0x4a,
  29375. 0x1f, 0xae, 0x76, 0xbf, 0xbb, 0x4d, 0x74, 0x98,
  29376. 0xa6, 0xae, 0xc0, 0x60, 0x96, 0xc5, 0xad, 0x9b,
  29377. 0x91, 0x31, 0xb9, 0x50, 0x3d, 0x9a, 0x0f, 0xe1,
  29378. 0x93, 0xef, 0x08, 0x72, 0xb2, 0x66, 0xe5, 0x5d,
  29379. 0xe4, 0x15, 0x53, 0x8e, 0xb0, 0xb3, 0xf8, 0x78,
  29380. 0xfc, 0x5d, 0x44, 0xc5, 0xbf, 0xf5, 0x01, 0x54,
  29381. 0xc5, 0x45, 0xa9, 0x30, 0xa4, 0xf1, 0x49, 0x79,
  29382. 0x4e, 0xab, 0xfc, 0xb2, 0x93, 0xe7, 0x3a, 0xe1,
  29383. 0x7f, 0x1f, 0x2f, 0x45, 0x3a, 0x53, 0x2b, 0x68,
  29384. 0xb3, 0xa4, 0xac, 0x23, 0x54, 0xb7, 0x5d, 0x25,
  29385. 0xa3, 0xe3, 0x90, 0x8a, 0xb0, 0x02, 0xfb, 0x7f,
  29386. 0x2d, 0xeb, 0x80, 0xc2, 0x5c, 0x62, 0xe1, 0x36,
  29387. 0x5a, 0x82, 0x8f, 0x4e, 0x74, 0xeb, 0x7d, 0x70,
  29388. 0xaf, 0x23, 0x92, 0x65, 0x3a, 0x11, 0xc0, 0x29,
  29389. 0xdb, 0xf7, 0x9a, 0xdc, 0x81, 0x45, 0x25, 0x0c,
  29390. 0x2e, 0x4f, 0x88, 0x41, 0x34, 0x53, 0xc6, 0x08,
  29391. 0x21, 0x77, 0xc1, 0xbb, 0x61, 0x48, 0x20, 0x69,
  29392. 0x1a, 0xbb, 0x71, 0x1b, 0x56, 0x18, 0x79, 0x75,
  29393. 0x16, 0x9a, 0xb3, 0x79, 0x31, 0x11, 0xa2, 0x89,
  29394. 0x8d, 0xea, 0x10, 0xb0, 0x04, 0x7f, 0xf8, 0x6e,
  29395. 0xdc, 0x08, 0x9b, 0x51, 0xa7, 0x64, 0xbd, 0x8d,
  29396. 0xd4, 0xd0, 0x1e, 0x38, 0x50, 0x1a, 0xa8, 0x7e,
  29397. 0x20, 0xae, 0xee, 0x8c, 0xa7, 0x72, 0x94, 0xc9,
  29398. 0xba, 0xf0, 0x67, 0xbd, 0x25, 0x1a, 0x3a, 0xdf,
  29399. 0x75, 0x39, 0xb7, 0xd3, 0x83, 0x3b, 0x89, 0xdf,
  29400. 0xb5, 0x2d, 0xd3, 0x12, 0x24, 0x21, 0x7c, 0x9e,
  29401. 0x92, 0x1c, 0x19, 0xae, 0x28, 0xcb, 0x2e, 0x2e,
  29402. 0x3c, 0xa9, 0x9b, 0xbd, 0xf9, 0x33, 0x30, 0xb2,
  29403. 0xbd, 0x8b, 0xbf, 0xc1, 0x8b, 0x32, 0xf1, 0x20,
  29404. 0xa1, 0x00, 0xfd, 0x11, 0x7d, 0x9a, 0xa8, 0x14,
  29405. 0x2c, 0xce, 0x16, 0x16, 0x4b, 0xdd, 0x56, 0x91,
  29406. 0x15, 0x36, 0x83, 0xcb, 0x01, 0x58, 0x35, 0xe1,
  29407. 0xdc, 0x22, 0x3d, 0xf8, 0xc2, 0x06, 0x54, 0x68,
  29408. 0x77, 0xd1, 0x47, 0x28, 0xdc, 0x09, 0x2a, 0x86,
  29409. 0x13, 0x80, 0xa6, 0xe9, 0xd0, 0xb4, 0xa3, 0x41,
  29410. 0x47, 0xf4, 0x71, 0x24, 0x10, 0x4c, 0x9f, 0xb7,
  29411. 0x57, 0x34, 0x48, 0x1b, 0xb4, 0xed, 0x0e, 0x89,
  29412. 0x4c, 0xf1, 0x73, 0x44, 0xff, 0x35, 0xb6, 0xe0,
  29413. 0x8f, 0x02, 0xa3, 0xa3, 0x81, 0x55, 0x38, 0xb5,
  29414. 0xc1, 0x99, 0xb3, 0x88, 0x84, 0x0d, 0xd9, 0x73,
  29415. 0x77, 0x65, 0x0b, 0xd7, 0xf8, 0x03, 0x88, 0xcb,
  29416. 0xdf, 0x25, 0xaf, 0xc6, 0xf1, 0xfa, 0x5c, 0x4d,
  29417. 0xfa, 0xc3, 0x7b, 0x8f, 0xb8, 0x38, 0x5d, 0x29,
  29418. 0xbb, 0x3d, 0x3e, 0x62, 0x1c, 0xdd, 0xe6, 0x97,
  29419. 0xe6, 0xe9, 0xbe, 0x6e, 0xd2, 0xb7, 0x7a, 0x9a,
  29420. 0x8e, 0xaf, 0xb3, 0xc8, 0x9e, 0x19, 0xee, 0x3d,
  29421. 0x5b, 0x1f, 0xec, 0x34, 0x3a, 0x1c, 0x27, 0x90,
  29422. 0xbd, 0x1e, 0x49, 0x72, 0x25, 0x2e, 0x38, 0x48,
  29423. 0x7d, 0xe1, 0x85, 0x46, 0xa7, 0x1b, 0x4a, 0xd5,
  29424. 0x23, 0x75, 0x6d, 0x8b, 0xc3, 0xf1, 0x87, 0xec,
  29425. 0x8b, 0x45, 0xf0, 0x9b, 0xb2, 0x14, 0x7a, 0x7c,
  29426. 0x8d, 0x78, 0x9c, 0x82, 0x64, 0x14, 0xfe, 0x01,
  29427. 0xfa, 0x04, 0x33, 0x96, 0xdd, 0x5f, 0x56, 0xbc,
  29428. 0xb2, 0x03, 0xe3, 0x0c, 0xa1, 0x09, 0x66, 0xa0,
  29429. 0x5e, 0x44, 0xde, 0x21, 0xae, 0x7d, 0x7a, 0x0e,
  29430. 0x81, 0x27, 0xd2, 0xfb, 0x85, 0xed, 0x27, 0x27,
  29431. 0xac, 0x11, 0x1c, 0xa1, 0x6d, 0xe9, 0xc1, 0xca,
  29432. 0xf6, 0x40, 0x7c, 0x95, 0x01, 0xb7, 0xa8, 0x29,
  29433. 0x9a, 0xd2, 0xcc, 0x62, 0x70, 0x1c, 0x7d, 0x0e,
  29434. 0xe5, 0x60, 0xcb, 0x79, 0xa3, 0xd7, 0x5d, 0x48,
  29435. 0x4b, 0x3c, 0xf8, 0x12, 0xe8, 0x7a, 0x7e, 0x83,
  29436. 0xab, 0x24, 0x33, 0x0f, 0x7b, 0x0a, 0x38, 0xae,
  29437. 0xb1, 0xfc, 0xc3, 0x50, 0x5c, 0x83, 0x53, 0xfd,
  29438. 0x15, 0xd6, 0x49, 0x54, 0xb6, 0x40, 0xe5, 0xe8,
  29439. 0x55, 0xba, 0x08, 0x2f, 0x21, 0xd7, 0x0e, 0x71,
  29440. 0x8a, 0xb2, 0xe1, 0x6b, 0xc6, 0x7e, 0x0f, 0x1c,
  29441. 0x4d, 0x41, 0x9f, 0x38, 0xc2, 0xce, 0x41, 0x41,
  29442. 0x48, 0xcd, 0xec, 0x16, 0x1d, 0x23, 0x8e, 0x41,
  29443. 0xcd, 0x5e, 0xf9, 0x5f, 0x01, 0x5e, 0x73, 0xa2,
  29444. 0xa1, 0xef, 0xe9, 0x57, 0xe0, 0xba, 0xe6, 0xbb,
  29445. 0x2b, 0xff, 0x3e, 0xb8, 0xad, 0xd5, 0x12, 0xc1,
  29446. 0x54, 0x49, 0xca, 0x93, 0xb0, 0x7d, 0x7b, 0xcf,
  29447. 0xf0, 0xc5, 0x94, 0x43, 0x30, 0x94, 0x11, 0x8d,
  29448. 0x15, 0x79, 0x2e, 0x57, 0xb8, 0x24, 0xcd, 0x2e,
  29449. 0xc2, 0x49, 0x3d, 0x92, 0x44, 0x23, 0x0c, 0x3e,
  29450. 0xa0, 0xf9, 0xa5, 0xad, 0x2a, 0x56, 0xec, 0xf4,
  29451. 0x6d, 0x0f, 0x5b, 0xb5, 0xd4, 0x2a, 0x3f, 0x2b,
  29452. 0x17, 0x9f, 0x5d, 0x33, 0x97, 0x42, 0xd4, 0x1e,
  29453. 0x14, 0x49, 0x01, 0xfb, 0xb6, 0x72, 0xbc, 0x14,
  29454. 0x5b, 0x79, 0xf4, 0x0a, 0xc5, 0x49, 0xe1, 0x76,
  29455. 0x44, 0x78, 0x87, 0xd1, 0x8e, 0x5b, 0xd5, 0x95,
  29456. 0xad, 0x19, 0x7c, 0x0d, 0x39, 0x7f, 0x41, 0x2e,
  29457. 0xd7, 0x9e, 0xbc, 0xfd, 0x2c, 0xde, 0xfa, 0x01,
  29458. 0x7d, 0x2b, 0x04, 0xef, 0x4d, 0xf9, 0xf4, 0x5b,
  29459. 0xed, 0x05, 0x9a, 0x50, 0x35, 0xe7, 0xb0, 0xba,
  29460. 0x24, 0xea, 0x16, 0x51, 0xe1, 0x6f, 0x32, 0x08,
  29461. 0x94, 0xd6, 0x19, 0x9d, 0x0e, 0x4c, 0xc1, 0xbb,
  29462. 0x01, 0x87, 0xa5, 0x90, 0x5f, 0x6f, 0xc4, 0xed,
  29463. 0xa1, 0x4c, 0x06, 0x4d, 0x2c, 0x47, 0x24, 0xda,
  29464. 0xae, 0xd2, 0x41, 0x92, 0x1f, 0x46, 0xce, 0xec,
  29465. 0xb1, 0xcc, 0x80, 0x1e, 0xb2, 0xcb, 0x66, 0x48,
  29466. 0x22, 0xec, 0x0e, 0x47, 0xfc, 0xad, 0x17, 0xfe,
  29467. 0x7b, 0xc5, 0x4d, 0x34, 0x95, 0x40, 0xd0, 0x02,
  29468. 0x7e, 0x90, 0xaa, 0x92, 0xaf, 0x48, 0x64, 0xc5,
  29469. 0xc1, 0x56, 0xd8, 0x9b, 0x6c, 0x5f, 0x2e, 0xfa,
  29470. 0xd7, 0x84, 0xdc, 0x71, 0x65, 0x1b, 0xfb, 0xbc,
  29471. 0x21, 0xc7, 0x57, 0xf4, 0x71, 0x2e, 0x6f, 0x34,
  29472. 0x85, 0x99, 0xa8, 0x5c, 0x6f, 0x34, 0x22, 0x44,
  29473. 0x89, 0x01, 0xf9, 0x48, 0xd2, 0xe2, 0xe4, 0x71,
  29474. 0x9d, 0x48, 0x07, 0x97, 0xd4, 0x66, 0xe4, 0x4d,
  29475. 0x48, 0xa3, 0x08, 0x7f, 0x6e, 0xaa, 0x7b, 0xe9,
  29476. 0x93, 0x81, 0x03, 0x0c, 0xd2, 0x48, 0xcf, 0x3f,
  29477. 0x5f, 0xbe, 0x03, 0xfb, 0x0f, 0xad, 0xc3, 0x81,
  29478. 0xd9, 0xce, 0x88, 0x0b, 0xfa, 0xed, 0x29, 0x7e,
  29479. 0x0b, 0xa1, 0x6f, 0x4c, 0x7d, 0xe4, 0x36, 0xff,
  29480. 0xdf, 0x94, 0x1a, 0x24, 0xb3, 0x7b, 0xca, 0x24,
  29481. 0x7e, 0x3a, 0x19, 0x53, 0x13, 0x4a, 0x17, 0x58,
  29482. 0xe7, 0x16, 0x9b, 0x50, 0xd8, 0xda, 0xcc, 0x6e,
  29483. 0x05, 0x25, 0xfe, 0x16, 0xcb, 0x5b, 0xd5, 0x35,
  29484. 0x76, 0x40, 0x44, 0x96, 0x23, 0x97, 0xe2, 0x4a,
  29485. 0x72, 0x0c, 0x54, 0x43, 0xc0, 0x09, 0x85, 0x8e,
  29486. 0x15, 0x85, 0xaf, 0x3c, 0x5e, 0x5f, 0x3c, 0x2d,
  29487. 0x21, 0x42, 0x75, 0xb7, 0xe4, 0x50, 0xf9, 0x00,
  29488. 0xa3, 0x4f, 0xb1, 0x7c, 0xfe, 0x62, 0xd0, 0xe9,
  29489. 0x6d, 0x51, 0xcc, 0x83, 0xc1, 0xdc, 0x37, 0x10,
  29490. 0x90, 0x0a, 0x15, 0xd8, 0xd5, 0x02, 0xf7, 0x74,
  29491. 0xb8, 0x46, 0x84, 0xc3, 0x61, 0x17, 0x26, 0x0f,
  29492. 0xe4, 0xde, 0x1a, 0xcf, 0x42, 0x53, 0x63, 0x2f,
  29493. 0x8d, 0xf7, 0x06, 0x07, 0xc3, 0x33, 0x39, 0x59,
  29494. 0xe9, 0x17, 0xc8, 0x05, 0xd2, 0xa2, 0xae, 0x53,
  29495. 0x2c, 0x7e, 0xd0, 0x9d, 0x5c, 0xb5, 0x42, 0x9f,
  29496. 0x84, 0xd7, 0xfe, 0x93, 0x74, 0xfb, 0xbb, 0xd2,
  29497. 0x1e, 0x57, 0x4e, 0x7f, 0x79, 0xaf, 0xd2, 0xf9,
  29498. 0x5e, 0x41, 0x9e, 0x63, 0x54, 0x61, 0x47, 0x0c,
  29499. 0x92, 0x4c, 0xc9, 0xfe, 0x4f, 0xcb, 0xe5, 0x8e,
  29500. 0x65, 0xb3, 0x97, 0x1b, 0xd8, 0xd1, 0x62, 0xfd
  29501. #else
  29502. 0x30, 0x82, 0x0a, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29503. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29504. 0x0c, 0x08, 0x07, 0x03, 0x82, 0x0a, 0x21, 0x00,
  29505. 0x7f, 0x5f, 0x63, 0x81, 0x6f, 0x04, 0x4c, 0xec,
  29506. 0xa8, 0xaf, 0x7b, 0x99, 0x41, 0xc6, 0xff, 0xdf,
  29507. 0x77, 0x66, 0x28, 0xc0, 0xe2, 0x58, 0xea, 0x9c,
  29508. 0x60, 0xbb, 0x03, 0x3e, 0xca, 0xa8, 0x38, 0x64,
  29509. 0xfb, 0xf7, 0x1b, 0x3f, 0xec, 0xfd, 0x0f, 0xf1,
  29510. 0x9c, 0xe4, 0xfd, 0xad, 0x83, 0xf7, 0x03, 0x66,
  29511. 0x6e, 0x7f, 0x4d, 0x42, 0xab, 0x6b, 0x73, 0x26,
  29512. 0xde, 0x6f, 0x8c, 0xc4, 0xca, 0x21, 0x66, 0x31,
  29513. 0x79, 0x57, 0x88, 0xcb, 0x1e, 0xab, 0xda, 0x1d,
  29514. 0x56, 0x70, 0xd9, 0x83, 0xa1, 0xb4, 0x83, 0xce,
  29515. 0xcc, 0x0f, 0xeb, 0xd6, 0x63, 0xbd, 0xf6, 0x02,
  29516. 0x5d, 0x5b, 0x0c, 0x17, 0x3c, 0x3e, 0x15, 0x02,
  29517. 0x22, 0xa1, 0x5d, 0xb5, 0xc5, 0x81, 0x28, 0x95,
  29518. 0x0b, 0x34, 0x2b, 0x96, 0x0a, 0xae, 0x6a, 0xa8,
  29519. 0xb5, 0x1d, 0x56, 0xbb, 0x7d, 0x83, 0x9a, 0x15,
  29520. 0xad, 0x63, 0x9e, 0x86, 0x8c, 0x6e, 0x6a, 0xa8,
  29521. 0xde, 0x55, 0xd0, 0xce, 0xc0, 0x2e, 0x05, 0xfe,
  29522. 0x1f, 0x4d, 0xd7, 0x12, 0xa4, 0x5a, 0xe9, 0x04,
  29523. 0x0d, 0x20, 0x84, 0x90, 0xb9, 0xca, 0x64, 0xe4,
  29524. 0xad, 0x2e, 0x74, 0x4b, 0x1d, 0x2f, 0xcc, 0xac,
  29525. 0xd8, 0x1a, 0x5e, 0xb2, 0x78, 0xbe, 0x61, 0xf7,
  29526. 0x36, 0xa3, 0xd1, 0x93, 0x86, 0xb5, 0x15, 0xf1,
  29527. 0x74, 0xf8, 0x9f, 0x6d, 0x6a, 0x8f, 0x6d, 0x86,
  29528. 0x8b, 0x36, 0x61, 0x10, 0xc9, 0x1a, 0x31, 0x39,
  29529. 0x09, 0xe6, 0x15, 0xa0, 0xb1, 0xfa, 0x69, 0xd4,
  29530. 0xc2, 0xb2, 0x56, 0x4c, 0x06, 0x33, 0x13, 0xc4,
  29531. 0x78, 0x53, 0x16, 0xfc, 0x52, 0x99, 0xe6, 0x27,
  29532. 0xc9, 0x3b, 0x24, 0x5c, 0x3e, 0x85, 0x73, 0x76,
  29533. 0x61, 0xa3, 0x61, 0xf0, 0x95, 0xd5, 0xb2, 0xf5,
  29534. 0x21, 0xe7, 0x09, 0xc3, 0x0c, 0x5c, 0xb0, 0x36,
  29535. 0xce, 0x45, 0x68, 0x41, 0x45, 0xcb, 0x1c, 0x36,
  29536. 0x2f, 0x3a, 0x00, 0x07, 0x56, 0xbe, 0x61, 0xd2,
  29537. 0x77, 0x37, 0x63, 0xa4, 0xdb, 0xfa, 0xa9, 0x6b,
  29538. 0x37, 0x90, 0x35, 0xd1, 0x1e, 0x27, 0x5b, 0x3e,
  29539. 0xc0, 0x0a, 0x02, 0x64, 0xe4, 0x58, 0x49, 0xab,
  29540. 0x2d, 0xc1, 0x38, 0x29, 0x3d, 0x44, 0xf9, 0xac,
  29541. 0xb7, 0x65, 0xd1, 0x5f, 0xf8, 0xce, 0x52, 0x76,
  29542. 0x22, 0x15, 0x61, 0x02, 0x1f, 0xa7, 0xcd, 0xff,
  29543. 0xeb, 0xa6, 0x7f, 0x6b, 0xba, 0x75, 0xe3, 0x09,
  29544. 0x01, 0x06, 0x41, 0x20, 0x88, 0x75, 0x64, 0x6b,
  29545. 0x97, 0x38, 0x13, 0xab, 0x4c, 0x0a, 0xd4, 0x7e,
  29546. 0xd2, 0xfa, 0x78, 0xe8, 0x9f, 0x5d, 0xf9, 0x53,
  29547. 0x30, 0x17, 0xf1, 0x10, 0x9e, 0x4a, 0x32, 0x17,
  29548. 0x3a, 0x9b, 0xb9, 0x25, 0x8e, 0xeb, 0xd9, 0x41,
  29549. 0x01, 0xa2, 0xc6, 0x58, 0x4a, 0x9f, 0xc3, 0x73,
  29550. 0xfd, 0xe2, 0xe4, 0x2c, 0x92, 0xb4, 0xa2, 0x3d,
  29551. 0x0f, 0x1f, 0x37, 0x64, 0xf1, 0x17, 0x2a, 0x8c,
  29552. 0xc6, 0xb5, 0xb0, 0x69, 0x7d, 0xfe, 0x08, 0xe0,
  29553. 0x8e, 0xaa, 0xe0, 0x08, 0xd5, 0x28, 0x92, 0x51,
  29554. 0x73, 0x8a, 0x2f, 0x7a, 0x4a, 0xbf, 0x52, 0x8d,
  29555. 0x3e, 0x9b, 0x36, 0x6a, 0xfb, 0x19, 0xf0, 0xea,
  29556. 0xfe, 0x05, 0xbd, 0x2d, 0xa9, 0x58, 0x48, 0x02,
  29557. 0xa8, 0x20, 0x9e, 0xdc, 0x04, 0x57, 0xc2, 0x0c,
  29558. 0xae, 0xc1, 0x03, 0xe7, 0x17, 0x48, 0x80, 0x00,
  29559. 0x8d, 0x1b, 0xd0, 0xc5, 0xdc, 0x2a, 0x02, 0x6e,
  29560. 0x8e, 0x54, 0xf3, 0x79, 0x31, 0x02, 0x93, 0xc5,
  29561. 0xf2, 0x55, 0xea, 0x61, 0xd0, 0xb2, 0x8e, 0xc9,
  29562. 0x74, 0x17, 0x0d, 0x38, 0xf8, 0xab, 0xf4, 0x42,
  29563. 0xd4, 0xc2, 0xdc, 0xf7, 0x1b, 0xdb, 0x65, 0x36,
  29564. 0x9f, 0x56, 0xe2, 0xeb, 0xf7, 0xe5, 0x2d, 0x45,
  29565. 0xae, 0xc0, 0x95, 0xbc, 0xe4, 0x1f, 0x22, 0xdc,
  29566. 0x0f, 0x54, 0xed, 0x14, 0xb8, 0xf1, 0x2f, 0x5d,
  29567. 0xd1, 0x79, 0xa0, 0x81, 0x17, 0x71, 0xa1, 0xd6,
  29568. 0xf0, 0x88, 0x9c, 0x1c, 0xc7, 0x95, 0x07, 0xb0,
  29569. 0xea, 0xf7, 0xd3, 0xa2, 0x55, 0xfe, 0x85, 0x65,
  29570. 0x42, 0x06, 0xec, 0xd2, 0xbe, 0x03, 0x8f, 0x63,
  29571. 0x84, 0x4b, 0xb1, 0x47, 0x48, 0x20, 0x71, 0xd2,
  29572. 0xdf, 0xc9, 0x59, 0xb0, 0x24, 0x8a, 0x6e, 0xf9,
  29573. 0x4a, 0xa1, 0x7b, 0xed, 0x11, 0xb6, 0xf9, 0x9b,
  29574. 0xf7, 0x93, 0x0e, 0xcb, 0x7a, 0x32, 0x22, 0x23,
  29575. 0x4e, 0x86, 0xce, 0xad, 0x9d, 0x1b, 0x84, 0x57,
  29576. 0xaf, 0xa5, 0x04, 0x03, 0x0a, 0xc9, 0x04, 0x97,
  29577. 0xd0, 0xce, 0x8e, 0x2a, 0x9a, 0x00, 0x15, 0xeb,
  29578. 0xac, 0x96, 0x57, 0xde, 0xe6, 0xc1, 0x2d, 0xbd,
  29579. 0xfc, 0xd6, 0x95, 0x0f, 0x5f, 0x19, 0xac, 0xaf,
  29580. 0x6c, 0xd8, 0xa6, 0x1e, 0xd8, 0xdb, 0x14, 0xfd,
  29581. 0xba, 0x0f, 0xd0, 0x3f, 0x61, 0xe3, 0x76, 0xfc,
  29582. 0x47, 0x61, 0x07, 0x24, 0x49, 0x17, 0xca, 0x24,
  29583. 0x31, 0x16, 0x26, 0x4f, 0xdc, 0x2b, 0x39, 0xae,
  29584. 0x5f, 0xfa, 0x4f, 0x82, 0xef, 0xe1, 0x41, 0x8c,
  29585. 0x3e, 0x8e, 0xa7, 0x6c, 0xf2, 0x51, 0xf7, 0x85,
  29586. 0x35, 0x6c, 0xad, 0xea, 0x32, 0x35, 0xf3, 0xc0,
  29587. 0x14, 0x17, 0xe2, 0x98, 0x27, 0x36, 0x7e, 0x60,
  29588. 0x2f, 0x01, 0x60, 0x3e, 0x18, 0xf4, 0x4e, 0xe0,
  29589. 0xf5, 0x14, 0x21, 0x81, 0x05, 0x78, 0x1c, 0x5f,
  29590. 0x4e, 0x89, 0xbb, 0x23, 0x60, 0xb1, 0x8f, 0x07,
  29591. 0x53, 0x16, 0x6e, 0xfb, 0x86, 0x07, 0x90, 0xff,
  29592. 0xa6, 0x27, 0x60, 0xe6, 0x3e, 0x92, 0x2a, 0x3c,
  29593. 0xa3, 0x57, 0xec, 0x97, 0x23, 0xaf, 0xd2, 0x44,
  29594. 0xac, 0x09, 0x87, 0xb0, 0x54, 0xe9, 0x5b, 0x50,
  29595. 0x37, 0xfa, 0x12, 0xa4, 0xcb, 0x6f, 0xed, 0x9f,
  29596. 0x29, 0x73, 0xa7, 0x09, 0x29, 0x91, 0x93, 0x5c,
  29597. 0x54, 0xf4, 0x44, 0xc2, 0x04, 0x64, 0xfc, 0xd2,
  29598. 0xf2, 0x0a, 0x0b, 0x45, 0x1f, 0xc5, 0x18, 0xf0,
  29599. 0xff, 0x10, 0x1f, 0x3a, 0x97, 0xf8, 0xb1, 0x83,
  29600. 0x0e, 0x08, 0xe2, 0x55, 0x75, 0x6a, 0x45, 0x96,
  29601. 0xf8, 0x1b, 0xdc, 0xb6, 0x57, 0x83, 0x8c, 0x28,
  29602. 0xc0, 0x4a, 0x57, 0xc6, 0xfb, 0x27, 0x3d, 0xfa,
  29603. 0x5a, 0x0d, 0x69, 0x56, 0x23, 0x66, 0x02, 0x78,
  29604. 0xca, 0xf1, 0xfa, 0xcb, 0xc1, 0xf6, 0x92, 0x1c,
  29605. 0xa0, 0xe3, 0x09, 0x7d, 0x48, 0x5e, 0x86, 0xa0,
  29606. 0x82, 0xa8, 0xf1, 0x1e, 0xe1, 0xfe, 0xc6, 0x9d,
  29607. 0x4f, 0x2e, 0xf4, 0xfc, 0xc6, 0x48, 0x1d, 0xc1,
  29608. 0x2a, 0x6a, 0xb7, 0xea, 0x46, 0x89, 0x04, 0xe9,
  29609. 0xbd, 0xf1, 0xed, 0x16, 0x76, 0xd8, 0x4b, 0x42,
  29610. 0xd5, 0x43, 0xa4, 0xfb, 0x02, 0x01, 0x54, 0x00,
  29611. 0xaf, 0x55, 0x52, 0x27, 0xff, 0x00, 0xe2, 0xbb,
  29612. 0x4a, 0xf2, 0x69, 0xb4, 0x4e, 0x6c, 0x6b, 0xa3,
  29613. 0x96, 0x4f, 0xf4, 0x65, 0x90, 0x2d, 0xc8, 0x57,
  29614. 0x1f, 0xb2, 0xf0, 0x86, 0x7b, 0x93, 0x09, 0x49,
  29615. 0x31, 0xc4, 0xf4, 0x8f, 0xc8, 0x2d, 0xac, 0x1d,
  29616. 0xfc, 0xba, 0xa4, 0xa5, 0x41, 0x90, 0x76, 0x7d,
  29617. 0x9e, 0x47, 0xdc, 0x10, 0xe6, 0x0c, 0xf7, 0x0f,
  29618. 0xa4, 0xba, 0x4f, 0xe2, 0x46, 0x38, 0x4c, 0x28,
  29619. 0xa0, 0x57, 0xb5, 0x3c, 0xb3, 0x4b, 0x8f, 0x03,
  29620. 0x04, 0xff, 0xf6, 0xec, 0x60, 0x90, 0x62, 0xfe,
  29621. 0x74, 0x76, 0x48, 0xb3, 0xf4, 0x0a, 0x6a, 0x5a,
  29622. 0x5b, 0xad, 0xc8, 0x54, 0x62, 0x11, 0x52, 0xd9,
  29623. 0x84, 0x1a, 0x09, 0x4b, 0xca, 0x66, 0xaa, 0x3c,
  29624. 0x36, 0x08, 0x9d, 0x58, 0xd0, 0x4a, 0x3a, 0x8b,
  29625. 0x24, 0xe0, 0x80, 0x9f, 0xe3, 0x76, 0xb6, 0x07,
  29626. 0xb1, 0xbc, 0x00, 0x98, 0xb0, 0xc1, 0xe0, 0xf6,
  29627. 0x1f, 0x4d, 0xa8, 0xd1, 0x69, 0x44, 0x9c, 0x33,
  29628. 0xb0, 0x0f, 0x9c, 0xc9, 0x0c, 0x8c, 0xbc, 0x03,
  29629. 0x58, 0x81, 0x76, 0xab, 0x0d, 0xef, 0x25, 0x5a,
  29630. 0xf6, 0xab, 0x3b, 0xf1, 0x1f, 0x97, 0x12, 0x8e,
  29631. 0x7f, 0x28, 0x77, 0x26, 0x18, 0xc4, 0xc4, 0xda,
  29632. 0x2c, 0x43, 0x57, 0xd2, 0x1f, 0x67, 0x95, 0x40,
  29633. 0x2c, 0x94, 0x41, 0x69, 0x22, 0x8a, 0x24, 0xd9,
  29634. 0xc7, 0xfc, 0xea, 0x49, 0x83, 0x8f, 0x5d, 0x2e,
  29635. 0x9d, 0xac, 0x17, 0xb6, 0xe0, 0xc4, 0xe7, 0xe6,
  29636. 0xd5, 0xc2, 0x73, 0xa1, 0x8f, 0x33, 0x14, 0x02,
  29637. 0xae, 0x01, 0x9f, 0x6f, 0x40, 0x92, 0x4e, 0x03,
  29638. 0xc2, 0xa9, 0xf1, 0x36, 0x78, 0xe4, 0xde, 0x39,
  29639. 0x4d, 0x29, 0x2e, 0xc2, 0x00, 0x93, 0x79, 0xe4,
  29640. 0xb2, 0x29, 0x4b, 0x81, 0x5c, 0x06, 0x06, 0xbc,
  29641. 0xc1, 0x01, 0x1c, 0xa7, 0x08, 0xf7, 0x47, 0x1f,
  29642. 0x52, 0x4f, 0xdf, 0x94, 0x1e, 0xe6, 0x89, 0xe6,
  29643. 0x26, 0x71, 0x2e, 0xa2, 0xd2, 0xfe, 0x04, 0xf2,
  29644. 0x12, 0x4c, 0x06, 0x78, 0x34, 0xc0, 0xb9, 0x76,
  29645. 0x62, 0x3b, 0x72, 0x25, 0x8c, 0x0d, 0x73, 0x24,
  29646. 0xcf, 0x4b, 0x4c, 0x47, 0x20, 0x9d, 0x04, 0x7f,
  29647. 0x86, 0x2c, 0x45, 0xb8, 0xfe, 0xb2, 0xaa, 0x36,
  29648. 0xf8, 0xe0, 0x24, 0x25, 0x05, 0x23, 0x12, 0x16,
  29649. 0xbf, 0x64, 0x10, 0xdd, 0xe4, 0xc0, 0xb0, 0x85,
  29650. 0xa7, 0xd3, 0xd1, 0x18, 0x1b, 0x81, 0x6b, 0x94,
  29651. 0xfd, 0x07, 0x43, 0xdd, 0x12, 0x37, 0x78, 0x69,
  29652. 0xec, 0x8c, 0xd0, 0x41, 0x2c, 0x42, 0x94, 0x3e,
  29653. 0x9f, 0xe3, 0x49, 0xb3, 0xb8, 0x45, 0x0b, 0x1d,
  29654. 0xc1, 0x9b, 0x4d, 0x21, 0x85, 0x62, 0xea, 0xd1,
  29655. 0xc9, 0x12, 0x30, 0x8c, 0x4b, 0x63, 0xeb, 0x7d,
  29656. 0x02, 0x52, 0x15, 0xa1, 0x95, 0x48, 0x9f, 0xc2,
  29657. 0xce, 0xf3, 0x4b, 0xff, 0x5a, 0xb6, 0x8f, 0xce,
  29658. 0xcd, 0x42, 0x21, 0x40, 0x82, 0xad, 0x08, 0x99,
  29659. 0x4d, 0x24, 0x58, 0x25, 0xf3, 0x7e, 0x42, 0x86,
  29660. 0x06, 0x33, 0x1f, 0x53, 0xbb, 0x07, 0x33, 0xca,
  29661. 0xc0, 0x02, 0x18, 0x30, 0x3c, 0xc5, 0x67, 0x1c,
  29662. 0x32, 0x3f, 0x2d, 0x58, 0x4c, 0x24, 0x6e, 0x60,
  29663. 0x96, 0x1a, 0xf4, 0xd0, 0x55, 0xb8, 0x84, 0xf0,
  29664. 0xb9, 0x83, 0xbf, 0x3d, 0x37, 0xe4, 0xa6, 0x06,
  29665. 0x1c, 0xd1, 0xd7, 0x91, 0x24, 0xdc, 0x3f, 0xcc,
  29666. 0x71, 0xf3, 0x0c, 0x90, 0x2c, 0x1d, 0x2f, 0x90,
  29667. 0xc8, 0x3c, 0x6f, 0x2c, 0x5d, 0xad, 0x8c, 0xdf,
  29668. 0xbb, 0x0d, 0x2a, 0x7f, 0x4a, 0x34, 0x5a, 0xd9,
  29669. 0x83, 0xfd, 0x61, 0x36, 0xe0, 0x0a, 0xb3, 0xf6,
  29670. 0x69, 0xb1, 0xaf, 0x81, 0x22, 0xd6, 0x9e, 0x9a,
  29671. 0xf8, 0xa6, 0x24, 0x8e, 0x0c, 0xcb, 0x25, 0xc2,
  29672. 0xfc, 0xc5, 0x94, 0xbd, 0x23, 0x9c, 0xa9, 0xbd,
  29673. 0x76, 0x28, 0xa4, 0x55, 0x92, 0x7c, 0xe6, 0x76,
  29674. 0xf7, 0x30, 0xf8, 0x7d, 0xdc, 0x0a, 0x93, 0x9e,
  29675. 0x7c, 0x39, 0x0a, 0x70, 0xa0, 0xb2, 0x77, 0xe0,
  29676. 0x7a, 0x89, 0x50, 0xce, 0x75, 0xca, 0x2f, 0xa4,
  29677. 0x12, 0x0e, 0xcb, 0x75, 0x1f, 0x0a, 0x83, 0xe8,
  29678. 0x14, 0x80, 0xa7, 0xb0, 0xe8, 0x11, 0xca, 0x12,
  29679. 0x5e, 0xf7, 0x31, 0x65, 0xbd, 0x20, 0x3d, 0x8c,
  29680. 0xa6, 0x89, 0x83, 0x68, 0x66, 0x03, 0x28, 0x49,
  29681. 0x17, 0xc4, 0x3f, 0x43, 0x02, 0x9b, 0xf8, 0xed,
  29682. 0xae, 0x8e, 0x68, 0xbc, 0x8e, 0x39, 0xe7, 0x15,
  29683. 0x32, 0x45, 0x66, 0x2c, 0x1f, 0xce, 0x56, 0xc7,
  29684. 0xc0, 0x15, 0x52, 0x19, 0x40, 0xcf, 0x87, 0x20,
  29685. 0xcd, 0x3d, 0xec, 0x90, 0x8d, 0x04, 0x01, 0x31,
  29686. 0x0b, 0x74, 0x80, 0x6e, 0x61, 0xa7, 0xf3, 0x4c,
  29687. 0xb2, 0x16, 0x00, 0xd5, 0xdb, 0xcc, 0xbb, 0x2c,
  29688. 0x9f, 0xb6, 0x02, 0x4a, 0xcf, 0x71, 0x06, 0xfd,
  29689. 0x60, 0xe0, 0x00, 0xbe, 0x22, 0xba, 0x39, 0x36,
  29690. 0xa8, 0x7e, 0xe5, 0xcb, 0xea, 0x87, 0xb1, 0xee,
  29691. 0xa2, 0x6c, 0x85, 0x94, 0x18, 0x6c, 0xab, 0x9a,
  29692. 0x93, 0xa7, 0xab, 0x4e, 0x3b, 0x85, 0xf3, 0xef,
  29693. 0x8f, 0x15, 0x74, 0x21, 0x9f, 0x5d, 0x9c, 0x22,
  29694. 0x32, 0x71, 0xb5, 0x4d, 0x7f, 0xaa, 0x85, 0xe0,
  29695. 0x05, 0x2a, 0x53, 0xbb, 0x3c, 0xab, 0xc3, 0xd2,
  29696. 0x73, 0x6e, 0x97, 0xa3, 0xfd, 0x05, 0x58, 0xaa,
  29697. 0x49, 0xc8, 0x69, 0xa9, 0x0b, 0x73, 0xd4, 0xe9,
  29698. 0x1d, 0x84, 0x60, 0x34, 0x2a, 0x09, 0xb3, 0x0f,
  29699. 0x08, 0x13, 0x67, 0x77, 0xb3, 0x24, 0xdf, 0xad,
  29700. 0xbf, 0x51, 0x71, 0x2b, 0xbe, 0x4f, 0x5d, 0xf4,
  29701. 0xe7, 0x25, 0x4c, 0x24, 0xa2, 0x4a, 0x22, 0xec,
  29702. 0xcc, 0x7c, 0x6c, 0x62, 0xee, 0x47, 0x12, 0x43,
  29703. 0x88, 0xe4, 0x71, 0xaa, 0x63, 0xaa, 0x2b, 0xed,
  29704. 0x70, 0xbf, 0x26, 0x37, 0xcc, 0xa4, 0xff, 0xe9,
  29705. 0xb6, 0x65, 0x31, 0x4d, 0x0d, 0x32, 0xd6, 0x84,
  29706. 0xb8, 0xab, 0x98, 0xa7, 0x10, 0x44, 0x77, 0xc7,
  29707. 0x2a, 0x60, 0xf0, 0xf5, 0xd5, 0xd4, 0x3a, 0x73,
  29708. 0x11, 0xa5, 0x1b, 0x18, 0x3c, 0x13, 0xfb, 0xda,
  29709. 0x76, 0x9d, 0xeb, 0x3e, 0xb9, 0x7a, 0xce, 0x02,
  29710. 0xa7, 0x5e, 0x25, 0x96, 0xd2, 0xbc, 0x85, 0x1a,
  29711. 0xd1, 0xa4, 0xe2, 0x02, 0x15, 0x08, 0x49, 0x16,
  29712. 0x7c, 0xaf, 0xc6, 0x38, 0x7b, 0x95, 0xf9, 0x37,
  29713. 0xc0, 0x87, 0x73, 0x6f, 0x01, 0xcd, 0x2b, 0xf1,
  29714. 0xe7, 0x6e, 0x47, 0x18, 0x30, 0xb8, 0x16, 0x87,
  29715. 0x1d, 0x23, 0x62, 0x22, 0x85, 0x92, 0x69, 0x46,
  29716. 0x9c, 0x65, 0xd8, 0xf1, 0x27, 0x32, 0xe4, 0x16,
  29717. 0x7f, 0x9a, 0xba, 0x46, 0x61, 0x60, 0x34, 0xe5,
  29718. 0xc0, 0x14, 0xb5, 0xde, 0x4d, 0xd1, 0x71, 0x39,
  29719. 0x26, 0xdc, 0x0c, 0x0a, 0x53, 0x9e, 0x31, 0x10,
  29720. 0x45, 0x7a, 0xf9, 0xc8, 0xfa, 0x1d, 0x69, 0x5e,
  29721. 0x25, 0xc1, 0xe2, 0x00, 0xbf, 0x94, 0xa3, 0xa2,
  29722. 0x97, 0xca, 0xb4, 0x6a, 0x89, 0x68, 0xdd, 0xed,
  29723. 0x6b, 0x99, 0x5a, 0x87, 0x9e, 0xe9, 0x68, 0xe4,
  29724. 0xf2, 0xc2, 0x7e, 0x37, 0x02, 0xdf, 0x96, 0x1a,
  29725. 0x5b, 0xed, 0xa1, 0xe8, 0xdf, 0x3c, 0xf7, 0xd2,
  29726. 0x25, 0xac, 0xf7, 0x4a, 0x7f, 0x10, 0x27, 0x2b,
  29727. 0x02, 0xc7, 0x95, 0x10, 0x5a, 0xb5, 0xb0, 0xcd,
  29728. 0xa9, 0xe1, 0x36, 0xe2, 0x1c, 0x87, 0x99, 0x0e,
  29729. 0x0a, 0x44, 0xec, 0x97, 0x75, 0xa7, 0x03, 0x27,
  29730. 0x38, 0x3b, 0x16, 0x30, 0x00, 0x98, 0xbe, 0x77,
  29731. 0xfe, 0x3a, 0xac, 0x6f, 0x8f, 0x4d, 0xe1, 0xa9,
  29732. 0x9c, 0xba, 0x39, 0x52, 0xe8, 0xf7, 0xe4, 0xe6,
  29733. 0xf9, 0xe9, 0xb3, 0x57, 0x82, 0xb2, 0x23, 0xd6,
  29734. 0xa5, 0x14, 0xc0, 0x78, 0xb4, 0xa0, 0xf9, 0x96,
  29735. 0xe4, 0x03, 0xe8, 0x6c, 0x27, 0xd8, 0x37, 0x7c,
  29736. 0x8f, 0xf4, 0x80, 0x09, 0x09, 0xc9, 0x32, 0x15,
  29737. 0xe0, 0x3f, 0x37, 0xa7, 0x1a, 0x5f, 0x8c, 0xfb,
  29738. 0xdd, 0xfe, 0x6b, 0x34, 0x28, 0x53, 0x03, 0x4b,
  29739. 0x39, 0x91, 0xf2, 0x48, 0x4c, 0x2a, 0x45, 0xfe,
  29740. 0x66, 0xf7, 0x23, 0x74, 0xb8, 0x30, 0x70, 0xb4,
  29741. 0x0c, 0x2c, 0x65, 0xb1, 0x4e, 0x32, 0x0f, 0x50,
  29742. 0xbb, 0x46, 0x9b, 0x03, 0x34, 0x38, 0xfb, 0xe4,
  29743. 0x25, 0x37, 0x8d, 0x0f, 0xa1, 0x41, 0x50, 0x85,
  29744. 0x92, 0x07, 0x71, 0xff, 0x3c, 0xe6, 0xd9, 0x1d,
  29745. 0x55, 0xb7, 0x10, 0x9c, 0xea, 0x70, 0x5f, 0xa3,
  29746. 0xba, 0x84, 0x99, 0x91, 0x30, 0x3d, 0x4c, 0x98,
  29747. 0x0b, 0x1f, 0x1f, 0xcc, 0x17, 0x94, 0xdd, 0x78,
  29748. 0x7d, 0x50, 0xe5, 0xf5, 0x21, 0x88, 0x5a, 0x52,
  29749. 0x76, 0x5a, 0x97, 0xbe, 0xba, 0xa9, 0xfe, 0x82,
  29750. 0x8a, 0xb5, 0x46, 0xcf, 0x9c, 0xbe, 0xe8, 0x2f,
  29751. 0x01, 0x2f, 0x6a, 0x03, 0x8a, 0xfa, 0x4b, 0x0b,
  29752. 0xdc, 0x78, 0x79, 0x9c, 0x49, 0xc4, 0x01, 0x26,
  29753. 0x16, 0x58, 0xc6, 0xb8, 0xee, 0x6c, 0xc9, 0xa9,
  29754. 0x38, 0x7c, 0xcf, 0xf3, 0xf8, 0xd0, 0x6b, 0x99,
  29755. 0x43, 0x13, 0xe0, 0x43, 0x8e, 0xfb, 0xb2, 0xdb,
  29756. 0x61, 0x67, 0xf4, 0xfc, 0x01, 0x21, 0xd9, 0xb1,
  29757. 0x1e, 0x6c, 0x6f, 0x2a, 0x9a, 0x4b, 0x86, 0x3c,
  29758. 0x62, 0x03, 0x53, 0x83, 0x11, 0x18, 0x1a, 0x59,
  29759. 0x9e, 0x25, 0xfe, 0xdb, 0x85, 0xd0, 0xee, 0x7c,
  29760. 0x97, 0x72, 0xca, 0xf3, 0x0d, 0xd4, 0x19, 0x66,
  29761. 0x14, 0xaf, 0x46, 0x68, 0x75, 0xdb, 0x8f, 0x5f,
  29762. 0x77, 0x7f, 0xfe, 0xa9, 0xe6, 0xa1, 0x9e, 0x46,
  29763. 0x5e, 0x92, 0xda, 0xea, 0xdd, 0x89, 0x01, 0xd9,
  29764. 0xab, 0x25, 0x7d, 0xb4, 0x64, 0x50, 0x8f, 0xa3,
  29765. 0xbe, 0xe2, 0x03, 0xd5, 0xc6, 0x9c, 0xc2, 0xf8,
  29766. 0xac, 0xa4, 0x36, 0xa9, 0x37, 0x10, 0x59, 0x00,
  29767. 0x45, 0xbb, 0x55, 0x33, 0xb9, 0x6f, 0xbc, 0xa2,
  29768. 0x02, 0x9e, 0xa3, 0x1d, 0xf4, 0x17, 0x78, 0x9b,
  29769. 0xbc, 0x42, 0x4e, 0x21, 0xc3, 0xde, 0xb5, 0x70,
  29770. 0x4a, 0x23, 0x1e, 0xd4, 0x36, 0x5d, 0x7a, 0x08,
  29771. 0x37, 0x55, 0x98, 0x07, 0xa0, 0x16, 0xa3, 0x4e,
  29772. 0xa1, 0x2b, 0x96, 0x8b, 0x51, 0x63, 0x48, 0xab,
  29773. 0xc9, 0x19, 0x6f, 0x5f, 0x25, 0x9d, 0xe7, 0x25,
  29774. 0x63, 0xf0, 0x8e, 0xdb, 0x06, 0x2d, 0x42, 0x31,
  29775. 0xfd, 0x14, 0x2b, 0x7a, 0x31, 0x43, 0x04, 0xd5,
  29776. 0xe2, 0x89, 0x2e, 0xa8, 0xe4, 0x6e, 0xd5, 0xa5,
  29777. 0x21, 0x67, 0x9b, 0x92, 0x61, 0x79, 0xdd, 0xe5,
  29778. 0x44, 0x43, 0x45, 0x57, 0x13, 0xec, 0x04, 0xc1,
  29779. 0x41, 0xa3, 0x14, 0x70, 0x86, 0xda, 0x76, 0x5d,
  29780. 0xe8, 0x61, 0xd2, 0xfb, 0x7b, 0xe4, 0x71, 0x46,
  29781. 0xa3, 0x52, 0xbf, 0xf2, 0xa0, 0x3c, 0xc1, 0x90,
  29782. 0x0c, 0x2e, 0xeb, 0xb3, 0x38, 0xae, 0x13, 0x27,
  29783. 0x84, 0xe9, 0x7a, 0xd6, 0x02, 0x40, 0x84, 0xff,
  29784. 0x87, 0x1f, 0x37, 0x44, 0xd8, 0x2e, 0x93, 0xf7,
  29785. 0x0a, 0xff, 0x5b, 0x4d, 0x07, 0x82, 0xfd, 0x6e,
  29786. 0x44, 0xcc, 0x19, 0xc3, 0x7d, 0x7c, 0x31, 0xf9,
  29787. 0x0e, 0xa8, 0x1c, 0x0d, 0xcb, 0x8e, 0xe8, 0x33,
  29788. 0xb2, 0xff, 0x9e, 0x1d, 0x99, 0x7c, 0x46, 0x5b,
  29789. 0xc7, 0x28, 0xec, 0x01, 0x62, 0x82, 0xfe, 0x2a,
  29790. 0x22, 0xa3, 0x86, 0x4e, 0x47, 0xe2, 0x57, 0xf1,
  29791. 0xb4, 0x58, 0x94, 0x89, 0xe5, 0xf1, 0xcd, 0x4d,
  29792. 0x90, 0xd1, 0xa4, 0x4c, 0x34, 0x5d, 0xde, 0xdc,
  29793. 0x39, 0x63, 0x8b, 0x85, 0xfd, 0x02, 0x21, 0xf1,
  29794. 0x12, 0xa3, 0x6d, 0x65, 0x0f, 0x8d, 0xe5, 0xcd,
  29795. 0x70, 0xd5, 0x1d, 0xf8, 0x65, 0x99, 0xfb, 0xe8,
  29796. 0xb5, 0x5a, 0x09, 0x39, 0x9e, 0x09, 0x45, 0x62,
  29797. 0x22, 0x1d, 0xa2, 0x46, 0xbf, 0x75, 0x20, 0xd1,
  29798. 0xe7, 0xb0, 0x06, 0x68, 0xc3, 0x50, 0x48, 0xfc,
  29799. 0xf8, 0x5c, 0x67, 0x69, 0x68, 0x66, 0xb6, 0x81,
  29800. 0x95, 0x91, 0x81, 0x3d, 0xf6, 0x34, 0xd9, 0x4b,
  29801. 0x06, 0x35, 0x17, 0x59, 0x89, 0x18, 0x74, 0x32,
  29802. 0x50, 0xcf, 0x81, 0x16, 0x8e, 0x53, 0x9d, 0x1c,
  29803. 0xad, 0x2d, 0x8e, 0x16, 0x41, 0xda, 0xca, 0xab,
  29804. 0x78, 0x0d, 0xc9, 0x49, 0x61, 0xaa, 0x18, 0xf4,
  29805. 0x56, 0x48, 0x29, 0x8c, 0xe3, 0x9a, 0x7d, 0x58,
  29806. 0xf8, 0x99, 0x72, 0xf1, 0x78, 0xa8, 0x5a, 0x97,
  29807. 0xe3, 0x2a, 0xc6, 0xa9, 0x59, 0xde, 0xcc, 0x62,
  29808. 0xfb, 0xab, 0xc5, 0x9a, 0x0b, 0xc7, 0x16, 0x8f,
  29809. 0x18, 0x20, 0x6e, 0x01, 0x7e, 0x04, 0xef, 0x72,
  29810. 0x83, 0x61, 0xb8, 0x1a, 0x77, 0x0f, 0xd1, 0xa9,
  29811. 0x75, 0xe0, 0x4a, 0x11, 0x69, 0x9d, 0xb6, 0xc9,
  29812. 0x2e, 0xd3, 0xbf, 0xe2, 0x5b, 0x24, 0x77, 0x30,
  29813. 0x85, 0x91, 0xef, 0xa8, 0x93, 0x4e, 0xad, 0x99,
  29814. 0xad, 0xcb, 0x6d, 0x9d, 0x8f, 0xd8, 0x0f, 0xe5,
  29815. 0x41, 0xd9, 0x9e, 0x0b, 0xce, 0x33, 0xd9, 0xbb,
  29816. 0x87, 0x66, 0x2c, 0xa3, 0x0b, 0x68, 0x1b, 0xb0,
  29817. 0x71, 0x30, 0xfa, 0x15, 0x2e, 0xe8, 0xc1, 0x99,
  29818. 0x71, 0x01, 0xcc, 0xdb, 0x6f, 0x9f, 0x8a, 0xfd,
  29819. 0xb4, 0x0f, 0x35, 0xa1, 0x36, 0xf4, 0x3a, 0xc4,
  29820. 0x17, 0x77, 0x43, 0x60, 0x10, 0x18, 0xb4, 0xc2,
  29821. 0xe5, 0xc0, 0x64, 0xd8, 0x38, 0x7c, 0x05, 0x9a,
  29822. 0xfb, 0x2b, 0xb3, 0x9b, 0x9e, 0x34, 0x6b, 0x4b,
  29823. 0xc8, 0x3b, 0x77, 0xe0, 0x6f, 0x08, 0xa1, 0x7b,
  29824. 0x66, 0x69, 0x2f, 0xdb, 0x34, 0x9e, 0x98, 0x90,
  29825. 0x5b, 0x4d, 0x7b, 0xa2, 0x32, 0x8e, 0x64, 0xe6,
  29826. 0x0d, 0x75, 0xc9, 0x96, 0xe3, 0x57, 0xba, 0xad,
  29827. 0x3e, 0x3b, 0x23, 0xfb, 0x9e, 0x7f, 0xc0, 0x3c,
  29828. 0xd5, 0x41, 0x9c, 0xfb, 0xbc, 0xb3, 0x52, 0x49
  29829. #endif
  29830. };
  29831. #endif
  29832. static int test_wc_dilithium_public_der_decode(void)
  29833. {
  29834. EXPECT_DECLS;
  29835. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29836. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  29837. dilithium_key* key;
  29838. word32 idx = 0;
  29839. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29840. ExpectNotNull(key);
  29841. if (key != NULL) {
  29842. XMEMSET(key, 0, sizeof(*key));
  29843. }
  29844. ExpectIntEQ(wc_dilithium_init(key), 0);
  29845. #ifndef WOLFSSL_NO_ML_DSA_44
  29846. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29847. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29848. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29849. #else
  29850. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29851. #endif
  29852. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(dilithium_public_der, &idx, key,
  29853. (word32)sizeof(dilithium_public_der)), 0);
  29854. wc_dilithium_free(key);
  29855. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29856. #endif
  29857. return EXPECT_RESULT();
  29858. }
  29859. static int test_wc_dilithium_der(void)
  29860. {
  29861. EXPECT_DECLS;
  29862. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29863. !defined(WOLFSSL_DILITHIUM_NO_ASN1) && \
  29864. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  29865. #define DILITHIUM_MAX_DER_SIZE 8192
  29866. dilithium_key* key;
  29867. WC_RNG rng;
  29868. byte* der = NULL;
  29869. int len;
  29870. int pubLen;
  29871. int pubDerLen;
  29872. int privDerLen;
  29873. int keyDerLen;
  29874. word32 idx;
  29875. #ifndef WOLFSSL_NO_ML_DSA_44
  29876. pubLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE;
  29877. pubDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + 24;
  29878. privDerLen = DILITHIUM_LEVEL2_KEY_SIZE + 30;
  29879. keyDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + DILITHIUM_LEVEL2_KEY_SIZE + 34;
  29880. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29881. pubLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE;
  29882. pubDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + 24;
  29883. privDerLen = DILITHIUM_LEVEL3_KEY_SIZE + 30;
  29884. keyDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + DILITHIUM_LEVEL3_KEY_SIZE + 34;
  29885. #else
  29886. pubLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE;
  29887. pubDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + 24;
  29888. privDerLen = DILITHIUM_LEVEL5_KEY_SIZE + 30;
  29889. keyDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + DILITHIUM_LEVEL5_KEY_SIZE + 34;
  29890. #endif
  29891. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29892. ExpectNotNull(key);
  29893. der = (byte*)XMALLOC(DILITHIUM_MAX_DER_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29894. ExpectNotNull(der);
  29895. if (key != NULL) {
  29896. XMEMSET(key, 0, sizeof(*key));
  29897. }
  29898. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29899. ExpectIntEQ(wc_InitRng(&rng), 0);
  29900. ExpectIntEQ(wc_dilithium_init(key), 0);
  29901. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  29902. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29903. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  29904. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29905. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  29906. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29907. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, pubDerLen),
  29908. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29909. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, privDerLen),
  29910. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29911. #ifndef WOLFSSL_NO_ML_DSA_44
  29912. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29913. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29914. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29915. #else
  29916. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29917. #endif
  29918. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  29919. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29920. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  29921. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29922. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  29923. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29924. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29925. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, 0 ,
  29926. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29927. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , 0 ,
  29928. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29929. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE,
  29930. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29931. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE,
  29932. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29933. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , der , 0 ,
  29934. 0), WC_NO_ERR_TRACE(BUFFER_E));
  29935. /* Get length only. */
  29936. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  29937. 0), pubLen);
  29938. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  29939. 0), pubLen);
  29940. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  29941. 1), pubDerLen);
  29942. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  29943. 1), pubDerLen);
  29944. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  29945. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29946. ExpectIntGT(wc_Dilithium_PrivateKeyToDer(key , NULL,
  29947. 0 ), 0);
  29948. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  29949. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29950. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  29951. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29952. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  29953. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29954. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , der ,
  29955. 0 ), WC_NO_ERR_TRACE(BUFFER_E));
  29956. /* Get length only. */
  29957. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , NULL,
  29958. DILITHIUM_MAX_DER_SIZE), privDerLen);
  29959. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, 0 ),
  29960. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29961. ExpectIntGT(wc_Dilithium_KeyToDer(key , NULL, 0 ),
  29962. 0 );
  29963. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , 0 ),
  29964. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29965. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE),
  29966. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29967. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE),
  29968. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29969. ExpectIntEQ(wc_Dilithium_KeyToDer(key , der , 0 ),
  29970. WC_NO_ERR_TRACE(BUFFER_E));
  29971. /* Get length only. */
  29972. ExpectIntEQ(wc_Dilithium_KeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE),
  29973. keyDerLen);
  29974. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, 0 ),
  29975. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29976. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, NULL, 0 ),
  29977. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29978. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, NULL, 0 ),
  29979. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29980. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, key , 0 ),
  29981. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29982. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, pubDerLen),
  29983. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29984. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, key , pubDerLen),
  29985. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29986. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, key , pubDerLen),
  29987. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29988. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, NULL, pubDerLen),
  29989. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29990. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, key , 0 ),
  29991. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29992. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, 0 ),
  29993. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29994. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, NULL, 0 ),
  29995. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29996. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, NULL, 0 ),
  29997. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29998. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, key , 0 ),
  29999. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30000. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, privDerLen),
  30001. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30002. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, key , privDerLen),
  30003. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30004. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, key , privDerLen),
  30005. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30006. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, NULL, privDerLen),
  30007. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30008. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, key , 0 ),
  30009. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30010. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30011. DILITHIUM_MAX_DER_SIZE, 0), pubLen);
  30012. ExpectIntEQ(wc_dilithium_import_public(der, len, key), 0);
  30013. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30014. DILITHIUM_MAX_DER_SIZE, 1), pubDerLen);
  30015. idx = 0;
  30016. {
  30017. fprintf(stderr, "\n");
  30018. for (int ii = 0; ii < pubDerLen; ii++) {
  30019. if ((ii % 8) == 0) fprintf(stderr, " ");
  30020. fprintf(stderr, "0x%02x,", der[ii]);
  30021. if ((ii % 8) == 7) fprintf(stderr, "\n");
  30022. else fprintf(stderr, " ");
  30023. }
  30024. }
  30025. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, len), 0);
  30026. ExpectIntEQ(len = wc_Dilithium_PrivateKeyToDer(key, der,
  30027. DILITHIUM_MAX_DER_SIZE), privDerLen);
  30028. idx = 0;
  30029. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30030. ExpectIntEQ(len = wc_Dilithium_KeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30031. keyDerLen);
  30032. idx = 0;
  30033. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30034. wc_dilithium_free(key);
  30035. wc_FreeRng(&rng);
  30036. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30037. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30038. #endif
  30039. return EXPECT_RESULT();
  30040. }
  30041. static int test_wc_dilithium_make_key_from_seed(void)
  30042. {
  30043. EXPECT_DECLS;
  30044. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30045. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  30046. dilithium_key* key;
  30047. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  30048. #ifndef WOLFSSL_NO_ML_DSA_44
  30049. static const byte seed_44[] = {
  30050. 0x93, 0xEF, 0x2E, 0x6E, 0xF1, 0xFB, 0x08, 0x99,
  30051. 0x9D, 0x14, 0x2A, 0xBE, 0x02, 0x95, 0x48, 0x23,
  30052. 0x70, 0xD3, 0xF4, 0x3B, 0xDB, 0x25, 0x4A, 0x78,
  30053. 0xE2, 0xB0, 0xD5, 0x16, 0x8E, 0xCA, 0x06, 0x5F
  30054. };
  30055. static const byte pk_44[] = {
  30056. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30057. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30058. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30059. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30060. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  30061. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  30062. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  30063. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  30064. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  30065. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  30066. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  30067. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  30068. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  30069. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  30070. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  30071. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  30072. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  30073. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  30074. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  30075. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  30076. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  30077. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  30078. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  30079. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  30080. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  30081. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  30082. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  30083. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  30084. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  30085. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  30086. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  30087. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  30088. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  30089. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  30090. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  30091. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  30092. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  30093. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  30094. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  30095. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  30096. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  30097. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  30098. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  30099. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  30100. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  30101. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  30102. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  30103. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  30104. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  30105. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  30106. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  30107. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  30108. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  30109. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  30110. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  30111. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  30112. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  30113. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  30114. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  30115. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  30116. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  30117. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  30118. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  30119. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  30120. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  30121. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  30122. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  30123. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  30124. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  30125. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  30126. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  30127. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  30128. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  30129. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  30130. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  30131. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  30132. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  30133. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  30134. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  30135. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  30136. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  30137. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  30138. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  30139. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  30140. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  30141. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  30142. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  30143. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  30144. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  30145. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  30146. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  30147. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  30148. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  30149. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  30150. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  30151. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  30152. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  30153. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  30154. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  30155. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  30156. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  30157. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  30158. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  30159. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  30160. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  30161. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  30162. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  30163. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  30164. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  30165. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  30166. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  30167. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  30168. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  30169. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  30170. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  30171. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  30172. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  30173. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  30174. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  30175. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  30176. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  30177. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  30178. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  30179. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  30180. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  30181. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  30182. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  30183. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  30184. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  30185. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  30186. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  30187. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  30188. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  30189. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  30190. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  30191. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  30192. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  30193. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  30194. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  30195. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  30196. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  30197. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  30198. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  30199. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  30200. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  30201. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  30202. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  30203. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  30204. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  30205. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  30206. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  30207. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  30208. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  30209. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  30210. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  30211. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  30212. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  30213. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  30214. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  30215. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  30216. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  30217. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  30218. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  30219. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  30220. };
  30221. static const byte sk_44[] = {
  30222. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30223. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30224. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30225. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30226. 0xBA, 0x2B, 0x57, 0xC4, 0x46, 0x55, 0x6E, 0xE2,
  30227. 0xB7, 0x2C, 0x78, 0xB9, 0x6B, 0xB7, 0xA8, 0x50,
  30228. 0x3D, 0xE4, 0x0A, 0xFB, 0x54, 0x18, 0x4E, 0x3B,
  30229. 0x54, 0x63, 0xC2, 0x1A, 0xF7, 0x48, 0x53, 0x23,
  30230. 0xDF, 0x98, 0xF0, 0x16, 0x0A, 0xE5, 0xD1, 0x37,
  30231. 0x51, 0x27, 0x25, 0xF8, 0x9D, 0x56, 0x3B, 0xC9,
  30232. 0xA1, 0x89, 0xD3, 0x1D, 0x20, 0xB3, 0xB3, 0xC8,
  30233. 0xFF, 0xAA, 0xF5, 0xE4, 0x86, 0xE7, 0x90, 0x51,
  30234. 0xF6, 0xF3, 0x60, 0x5C, 0xCA, 0x25, 0x69, 0xFD,
  30235. 0xB4, 0x6B, 0x33, 0x18, 0xD2, 0x38, 0x42, 0xCE,
  30236. 0x40, 0xD6, 0x43, 0x86, 0x13, 0xF6, 0x8B, 0x45,
  30237. 0x5B, 0x0D, 0x3B, 0xCA, 0x0E, 0x05, 0x0D, 0x4D,
  30238. 0x11, 0x99, 0x88, 0xA2, 0xC4, 0x80, 0x1B, 0x90,
  30239. 0x84, 0xE0, 0xB0, 0x48, 0xC9, 0x28, 0x09, 0x22,
  30240. 0x30, 0x90, 0x24, 0x06, 0x49, 0x98, 0x40, 0x65,
  30241. 0x5A, 0x26, 0x8A, 0xDA, 0x32, 0x90, 0xDA, 0x48,
  30242. 0x08, 0x22, 0x81, 0x90, 0xC8, 0x14, 0x61, 0xDC,
  30243. 0x16, 0x6A, 0x21, 0x47, 0x8E, 0x08, 0xB2, 0x21,
  30244. 0xE3, 0x08, 0x68, 0x1A, 0x02, 0x44, 0x14, 0xC6,
  30245. 0x65, 0xE1, 0x98, 0x71, 0x90, 0xC6, 0x69, 0x0C,
  30246. 0x15, 0x44, 0xC9, 0xA0, 0x11, 0xCC, 0x34, 0x71,
  30247. 0x83, 0x40, 0x45, 0x00, 0x12, 0x4D, 0x91, 0x08,
  30248. 0x00, 0x83, 0x36, 0x84, 0x12, 0x85, 0x4C, 0xCC,
  30249. 0x00, 0x41, 0x09, 0x90, 0x70, 0x18, 0x95, 0x00,
  30250. 0xA2, 0xB2, 0x85, 0x94, 0x26, 0x41, 0x0B, 0x00,
  30251. 0x41, 0x0A, 0xB9, 0x80, 0xC0, 0xC6, 0x10, 0x0C,
  30252. 0x33, 0x29, 0xA3, 0xA6, 0x28, 0x1C, 0x26, 0x10,
  30253. 0x1A, 0x37, 0x49, 0x13, 0x35, 0x8A, 0x0B, 0x29,
  30254. 0x2E, 0x82, 0xA2, 0x70, 0x8B, 0x38, 0x49, 0x94,
  30255. 0x04, 0x80, 0x9B, 0x26, 0x10, 0xA4, 0x80, 0x30,
  30256. 0x04, 0x37, 0x0C, 0x48, 0xB2, 0x60, 0x04, 0x17,
  30257. 0x2E, 0x19, 0x49, 0x64, 0xC8, 0xC4, 0x64, 0x1A,
  30258. 0x96, 0x60, 0x10, 0x83, 0x6D, 0x20, 0x38, 0x22,
  30259. 0x49, 0x06, 0x08, 0x1B, 0xB7, 0x20, 0x01, 0x48,
  30260. 0x4D, 0xE1, 0x10, 0x49, 0x08, 0x38, 0x44, 0x4C,
  30261. 0x16, 0x8E, 0x04, 0xB2, 0x2C, 0x09, 0x91, 0x50,
  30262. 0x83, 0x36, 0x06, 0x5C, 0x02, 0x8C, 0x8A, 0x38,
  30263. 0x05, 0x1A, 0xB5, 0x81, 0x82, 0xC0, 0x09, 0x51,
  30264. 0x12, 0x72, 0x22, 0x10, 0x0D, 0x04, 0x08, 0x2A,
  30265. 0xA4, 0x84, 0x10, 0x58, 0x08, 0x52, 0x08, 0x26,
  30266. 0x0A, 0x02, 0xB6, 0x2D, 0x8A, 0x12, 0x0E, 0x14,
  30267. 0x22, 0x10, 0x48, 0x44, 0x0A, 0x14, 0x23, 0x91,
  30268. 0x50, 0x40, 0x90, 0x0A, 0x27, 0x92, 0xA4, 0xB0,
  30269. 0x60, 0x08, 0x84, 0x11, 0xC4, 0x40, 0x22, 0x63,
  30270. 0x46, 0x2A, 0xDA, 0xA6, 0x90, 0xC1, 0xB2, 0x30,
  30271. 0x50, 0x10, 0x00, 0xA0, 0xB4, 0x6C, 0x53, 0xB4,
  30272. 0x50, 0x13, 0x05, 0x8D, 0x02, 0x31, 0x0E, 0x08,
  30273. 0x20, 0x10, 0x91, 0xC8, 0x4C, 0x22, 0xA7, 0x50,
  30274. 0xC2, 0xA6, 0x70, 0x92, 0x46, 0x41, 0x63, 0x16,
  30275. 0x8C, 0x84, 0x00, 0x11, 0x0B, 0x81, 0x90, 0x13,
  30276. 0x83, 0x71, 0x21, 0x85, 0x30, 0x1B, 0x18, 0x46,
  30277. 0xA3, 0x10, 0x84, 0x14, 0x43, 0x40, 0x80, 0x98,
  30278. 0x25, 0x0C, 0x27, 0x2C, 0x94, 0x42, 0x41, 0xA2,
  30279. 0x88, 0x45, 0x02, 0x13, 0x05, 0x44, 0xB6, 0x44,
  30280. 0x52, 0x22, 0x92, 0xD0, 0x80, 0x50, 0x4B, 0xA6,
  30281. 0x04, 0x84, 0x36, 0x70, 0x09, 0xB2, 0x4D, 0x19,
  30282. 0xA8, 0x84, 0x24, 0x93, 0x49, 0x94, 0xA2, 0x80,
  30283. 0x49, 0xB4, 0x48, 0x91, 0x28, 0x64, 0xA1, 0xC8,
  30284. 0x65, 0x4B, 0x82, 0x85, 0x93, 0x30, 0x06, 0x63,
  30285. 0x12, 0x66, 0x10, 0x37, 0x01, 0x4A, 0x40, 0x80,
  30286. 0x18, 0x18, 0x90, 0x44, 0xC4, 0x0D, 0x4B, 0x28,
  30287. 0x81, 0xA2, 0x06, 0x40, 0xD4, 0x30, 0x2C, 0x1B,
  30288. 0x96, 0x4C, 0xE1, 0xB2, 0x60, 0x44, 0x28, 0x41,
  30289. 0xD8, 0x30, 0x65, 0x24, 0x09, 0x04, 0x64, 0x00,
  30290. 0x89, 0x63, 0xC2, 0x24, 0xC0, 0x00, 0x49, 0x92,
  30291. 0x16, 0x52, 0x23, 0xC1, 0x29, 0x42, 0x26, 0x91,
  30292. 0xD0, 0x38, 0x31, 0x83, 0x28, 0x28, 0x4C, 0x28,
  30293. 0x61, 0x1A, 0xB2, 0x88, 0x80, 0x26, 0x2D, 0x0C,
  30294. 0x19, 0x52, 0x5B, 0x22, 0x60, 0x8A, 0x92, 0x28,
  30295. 0xA2, 0x18, 0x90, 0xD9, 0x42, 0x52, 0xCB, 0x40,
  30296. 0x8E, 0x9B, 0x16, 0x06, 0x4B, 0xC8, 0x05, 0xE0,
  30297. 0x06, 0x6C, 0x49, 0xC2, 0x25, 0xD4, 0x22, 0x69,
  30298. 0x14, 0x11, 0x69, 0x1C, 0x34, 0x90, 0x0C, 0x85,
  30299. 0x8D, 0x1C, 0x84, 0x49, 0x63, 0x10, 0x85, 0x08,
  30300. 0x34, 0x89, 0x58, 0x16, 0x66, 0xA0, 0x38, 0x68,
  30301. 0x0B, 0xA2, 0x50, 0xE0, 0x84, 0x61, 0xC1, 0x26,
  30302. 0x6E, 0xC9, 0x14, 0x6A, 0xC0, 0xC0, 0x31, 0x84,
  30303. 0x18, 0x2E, 0xDC, 0x16, 0x52, 0x14, 0x18, 0x91,
  30304. 0x0A, 0x39, 0x2C, 0x83, 0xA6, 0x8D, 0x12, 0x29,
  30305. 0x62, 0x92, 0xA6, 0x60, 0x08, 0xA5, 0x10, 0xD9,
  30306. 0xC8, 0x4D, 0x24, 0x48, 0x24, 0x83, 0x98, 0x24,
  30307. 0x1A, 0x44, 0x42, 0x08, 0x08, 0x48, 0xC8, 0x96,
  30308. 0x2D, 0xA1, 0x10, 0x20, 0x60, 0x24, 0x51, 0x9C,
  30309. 0x30, 0x11, 0xDB, 0xC8, 0x04, 0x11, 0x22, 0x51,
  30310. 0x18, 0x04, 0x68, 0xE2, 0x24, 0x4E, 0x10, 0xC4,
  30311. 0x0D, 0x18, 0x37, 0x29, 0x11, 0xB7, 0x84, 0x43,
  30312. 0x84, 0x8D, 0x54, 0x40, 0x70, 0x64, 0x80, 0x70,
  30313. 0x21, 0xB0, 0x4D, 0x00, 0x26, 0x62, 0x00, 0x45,
  30314. 0x25, 0x1B, 0x83, 0x84, 0x84, 0x80, 0x70, 0x19,
  30315. 0xB0, 0x04, 0x0A, 0xC9, 0x28, 0xCA, 0x80, 0x05,
  30316. 0x1B, 0x21, 0x4E, 0xD4, 0xB0, 0x49, 0x8C, 0x96,
  30317. 0x6C, 0xD0, 0x96, 0x25, 0x48, 0x32, 0x72, 0x54,
  30318. 0x12, 0x05, 0x09, 0x98, 0x8C, 0x8A, 0x32, 0x6D,
  30319. 0xC0, 0x04, 0x31, 0x63, 0xC8, 0x61, 0xC8, 0xC2,
  30320. 0x68, 0x9B, 0xB4, 0x8C, 0x5B, 0xC0, 0x2D, 0xC3,
  30321. 0xA8, 0x8D, 0x1B, 0x16, 0x6C, 0xD8, 0x96, 0x41,
  30322. 0x98, 0x34, 0x02, 0x44, 0x14, 0x2C, 0xD3, 0x86,
  30323. 0x44, 0x0A, 0x18, 0x8A, 0x1A, 0x46, 0x92, 0x1A,
  30324. 0xB7, 0x08, 0x4C, 0x34, 0x24, 0x21, 0x91, 0x0D,
  30325. 0x9A, 0x96, 0x2D, 0xCB, 0x24, 0x22, 0x92, 0x86,
  30326. 0x08, 0x98, 0xA0, 0x50, 0xDA, 0x44, 0x6A, 0x19,
  30327. 0xB1, 0x05, 0x8B, 0x20, 0x6E, 0x24, 0xC4, 0x81,
  30328. 0xC9, 0x98, 0x40, 0x22, 0x19, 0x32, 0x11, 0x05,
  30329. 0x69, 0xD3, 0x94, 0x91, 0x08, 0xA7, 0x71, 0xDB,
  30330. 0xC0, 0x70, 0x02, 0xB8, 0x28, 0x83, 0xB4, 0x49,
  30331. 0xA0, 0x44, 0x8A, 0x0B, 0xB4, 0x10, 0x61, 0x02,
  30332. 0x48, 0x1C, 0xA6, 0x11, 0xE3, 0x20, 0x66, 0x40,
  30333. 0xB4, 0x70, 0x03, 0xB6, 0x04, 0x60, 0x48, 0x21,
  30334. 0x5B, 0x21, 0x83, 0x39, 0x88, 0xDB, 0x67, 0x4A,
  30335. 0x61, 0xE7, 0xC2, 0x08, 0xDE, 0xBE, 0x8D, 0xAE,
  30336. 0x41, 0x19, 0xAF, 0xB0, 0x26, 0x61, 0xA6, 0x9A,
  30337. 0xBC, 0x8B, 0xDD, 0x24, 0x5B, 0x5D, 0x0F, 0xB1,
  30338. 0xA2, 0x67, 0x01, 0xC9, 0xB9, 0xC9, 0xA8, 0xF7,
  30339. 0xD9, 0xFC, 0xD4, 0xC2, 0x87, 0xFF, 0x3D, 0x60,
  30340. 0x8C, 0xF2, 0x58, 0x28, 0x2A, 0x1E, 0xB2, 0x9F,
  30341. 0x93, 0x04, 0xE8, 0x9C, 0x14, 0xF3, 0xE1, 0xCE,
  30342. 0x56, 0x12, 0x89, 0x1C, 0x60, 0x29, 0x34, 0x52,
  30343. 0x60, 0x06, 0xC9, 0x9B, 0x4A, 0xA2, 0x39, 0x9B,
  30344. 0xF4, 0x94, 0xBC, 0xF8, 0xDF, 0x61, 0xD6, 0xDF,
  30345. 0x4C, 0x69, 0xBC, 0x93, 0xE0, 0x2D, 0x49, 0x95,
  30346. 0xE2, 0xF7, 0x6E, 0x9F, 0xDA, 0x4E, 0xF6, 0x7E,
  30347. 0xB7, 0x25, 0x6C, 0xA8, 0x9A, 0x3F, 0x38, 0xFE,
  30348. 0xB2, 0xE9, 0xDF, 0x6A, 0x01, 0x0D, 0xC1, 0xC1,
  30349. 0x50, 0x02, 0xFB, 0xD4, 0x56, 0xFA, 0xE8, 0x84,
  30350. 0x82, 0x1A, 0x34, 0x16, 0x6B, 0x06, 0x58, 0xA2,
  30351. 0x41, 0x25, 0x95, 0x71, 0x8E, 0x14, 0x9B, 0xBC,
  30352. 0x6E, 0x22, 0x0A, 0xEE, 0x26, 0x8D, 0x4D, 0x82,
  30353. 0x18, 0xC2, 0x5F, 0x6A, 0x95, 0x7D, 0xE5, 0xB2,
  30354. 0x6C, 0xEA, 0x7B, 0x14, 0xCB, 0x32, 0x0D, 0x89,
  30355. 0xE1, 0x69, 0x9A, 0xD9, 0xF2, 0xB3, 0x89, 0xC6,
  30356. 0x7E, 0xF9, 0x33, 0x86, 0xA2, 0xC6, 0x5F, 0x2C,
  30357. 0x32, 0x23, 0x33, 0x67, 0xD7, 0x6A, 0xE4, 0xAB,
  30358. 0x2A, 0xBB, 0xD4, 0x22, 0xE9, 0x8E, 0x49, 0x3D,
  30359. 0xCC, 0x3C, 0xC5, 0xDA, 0xF6, 0x89, 0xB6, 0x5C,
  30360. 0xC4, 0xBC, 0x3F, 0xA5, 0x1C, 0x9C, 0x59, 0xEE,
  30361. 0xAF, 0x07, 0x55, 0x17, 0x0C, 0x24, 0x95, 0x80,
  30362. 0x4D, 0x02, 0xA6, 0x07, 0xC5, 0xBF, 0x88, 0x7C,
  30363. 0xD8, 0x6A, 0x03, 0x89, 0xF2, 0x8F, 0xC9, 0x72,
  30364. 0x5E, 0xF4, 0x60, 0x03, 0xF1, 0x3B, 0x01, 0x87,
  30365. 0x68, 0x4B, 0xEA, 0xB1, 0xF2, 0x4A, 0x29, 0xF5,
  30366. 0x31, 0x96, 0x01, 0xF3, 0x09, 0xC9, 0x1D, 0x2A,
  30367. 0x33, 0x3D, 0x1B, 0x88, 0xDF, 0x20, 0x5A, 0x51,
  30368. 0x20, 0xC4, 0xCF, 0xDC, 0x22, 0x38, 0x12, 0x4E,
  30369. 0x4E, 0x2B, 0x47, 0xD0, 0xB5, 0xE6, 0x6A, 0x65,
  30370. 0x4F, 0xE4, 0xCC, 0xCB, 0x07, 0x8F, 0x07, 0xCB,
  30371. 0xD4, 0x55, 0xD1, 0x5D, 0x3E, 0xEC, 0x7D, 0xA2,
  30372. 0x74, 0xD2, 0x4A, 0x2E, 0x57, 0x18, 0x84, 0xDE,
  30373. 0x41, 0xC3, 0xA9, 0xA4, 0xFD, 0xB3, 0xF6, 0x09,
  30374. 0x8A, 0x17, 0x2C, 0x30, 0x96, 0x80, 0x39, 0xBD,
  30375. 0x0E, 0x4E, 0xB3, 0xE2, 0xFB, 0x6D, 0x6E, 0xEE,
  30376. 0xD3, 0x9E, 0x0B, 0x63, 0x62, 0xD5, 0x4E, 0x7B,
  30377. 0x88, 0x95, 0x98, 0x69, 0xDD, 0xD5, 0xD8, 0x73,
  30378. 0xD9, 0x65, 0x24, 0x01, 0xA2, 0x9F, 0x27, 0xA2,
  30379. 0x8E, 0xA6, 0x6D, 0x32, 0xCC, 0xB0, 0xEF, 0x3B,
  30380. 0xF4, 0x60, 0x0F, 0x75, 0x57, 0xEE, 0x8D, 0x54,
  30381. 0xBF, 0x1D, 0xAD, 0x18, 0xF4, 0x5D, 0xDC, 0xD4,
  30382. 0xC9, 0xED, 0x57, 0xB1, 0x3E, 0x44, 0x5B, 0xF1,
  30383. 0x22, 0xA4, 0x3F, 0x53, 0x94, 0x03, 0x89, 0xBF,
  30384. 0x87, 0x14, 0xFF, 0xAC, 0x72, 0x1E, 0x59, 0x31,
  30385. 0x7E, 0x4B, 0x70, 0x50, 0x0A, 0xD0, 0xD1, 0xB9,
  30386. 0xA6, 0x27, 0x05, 0x4D, 0x31, 0x93, 0x20, 0x8C,
  30387. 0x77, 0x4E, 0x0B, 0x20, 0xED, 0x04, 0x1A, 0x8C,
  30388. 0x05, 0x5E, 0x75, 0xEE, 0xCD, 0x37, 0x38, 0xF0,
  30389. 0x07, 0x15, 0x8F, 0xAD, 0xDF, 0xCA, 0x5F, 0x43,
  30390. 0x56, 0x2D, 0x63, 0x6A, 0x5A, 0xCF, 0x3A, 0x39,
  30391. 0x83, 0xD3, 0xCF, 0xEB, 0xCA, 0x10, 0xB8, 0x13,
  30392. 0xF9, 0xF6, 0x52, 0x65, 0x19, 0x19, 0x9A, 0x03,
  30393. 0x13, 0xCD, 0x1D, 0xE1, 0x3F, 0x06, 0xAD, 0x53,
  30394. 0x86, 0xE1, 0xE1, 0x20, 0x79, 0x5F, 0xD2, 0x67,
  30395. 0xB7, 0xF4, 0x20, 0x19, 0xD8, 0x4D, 0xF6, 0xCD,
  30396. 0x1B, 0xF9, 0x19, 0x30, 0xFC, 0xA7, 0xAF, 0xD5,
  30397. 0x2E, 0x80, 0x70, 0x0F, 0x4C, 0xF5, 0xCD, 0xC3,
  30398. 0x8A, 0x5F, 0x7A, 0x57, 0x49, 0x79, 0x1C, 0x2F,
  30399. 0xDF, 0xFC, 0x4A, 0x10, 0x75, 0x3C, 0x24, 0xDB,
  30400. 0x19, 0xE8, 0xEB, 0x65, 0x1C, 0x5B, 0x36, 0x32,
  30401. 0x00, 0xF0, 0xB5, 0xD1, 0x69, 0x94, 0x70, 0x26,
  30402. 0xE9, 0xF7, 0x4F, 0x01, 0x2D, 0xC7, 0xC5, 0xB3,
  30403. 0x39, 0xDD, 0x49, 0xD2, 0x61, 0xCA, 0x1D, 0x37,
  30404. 0xF8, 0xF2, 0x83, 0x46, 0xE6, 0x19, 0x78, 0x05,
  30405. 0x4F, 0x45, 0xAE, 0xE4, 0x36, 0xDC, 0xCB, 0xE7,
  30406. 0xBF, 0xAF, 0xE0, 0x7C, 0xE9, 0xA8, 0xB8, 0x3C,
  30407. 0x90, 0xA2, 0x68, 0x6F, 0xA9, 0x54, 0x02, 0x85,
  30408. 0x09, 0x25, 0xC8, 0x58, 0x2B, 0xC9, 0xB7, 0x34,
  30409. 0xE4, 0xEC, 0xA1, 0xF7, 0xB2, 0x0B, 0x08, 0x6F,
  30410. 0x12, 0x9F, 0x27, 0x7A, 0x5C, 0xBD, 0xAA, 0x96,
  30411. 0x3C, 0x92, 0x71, 0x7E, 0xF7, 0x0E, 0xC1, 0x9B,
  30412. 0xF3, 0xDB, 0xC6, 0xDA, 0x20, 0x3A, 0xD9, 0x0F,
  30413. 0x3B, 0x13, 0xBB, 0xC2, 0x2F, 0xBD, 0x98, 0x0B,
  30414. 0xB1, 0xB9, 0xD3, 0xA3, 0x44, 0x52, 0xB3, 0x35,
  30415. 0x70, 0x21, 0xCE, 0x36, 0x13, 0x58, 0x4E, 0x09,
  30416. 0x36, 0xBF, 0x1D, 0x09, 0x42, 0x09, 0x37, 0x81,
  30417. 0x5E, 0x11, 0xCC, 0x5D, 0x5D, 0xDB, 0x4B, 0xF1,
  30418. 0xD8, 0x30, 0xC4, 0xF8, 0x3F, 0x30, 0xE5, 0x15,
  30419. 0x92, 0x1C, 0x78, 0x4D, 0x87, 0xBB, 0x20, 0xC0,
  30420. 0x9E, 0x3C, 0x64, 0xBD, 0xCE, 0x9A, 0xB1, 0xC6,
  30421. 0x9F, 0xD3, 0x07, 0xEF, 0xE3, 0x59, 0xC7, 0xF9,
  30422. 0x38, 0x56, 0x6C, 0x9F, 0x25, 0x17, 0xB0, 0x63,
  30423. 0x38, 0x51, 0x67, 0xE2, 0x47, 0xF3, 0x10, 0x81,
  30424. 0x11, 0x9B, 0xAC, 0x6B, 0x55, 0xA0, 0xBD, 0xD7,
  30425. 0x14, 0x25, 0x51, 0x0F, 0xFA, 0x2A, 0xBD, 0xFA,
  30426. 0x88, 0x83, 0x76, 0xA3, 0x7F, 0x20, 0xC2, 0x48,
  30427. 0x01, 0x52, 0xBB, 0x36, 0x16, 0x34, 0x52, 0x00,
  30428. 0x07, 0xC5, 0xB3, 0x4B, 0xF2, 0x28, 0x17, 0xCB,
  30429. 0x2E, 0x67, 0xAC, 0x1A, 0x82, 0x67, 0x0B, 0x71,
  30430. 0xF1, 0x96, 0xC8, 0x9F, 0x23, 0xBA, 0x31, 0x4B,
  30431. 0x16, 0xA9, 0x48, 0x49, 0x93, 0x04, 0xEF, 0x5C,
  30432. 0x03, 0xDC, 0xF5, 0x8E, 0x52, 0xBE, 0x31, 0x48,
  30433. 0x63, 0xE7, 0x23, 0xC5, 0x6D, 0x3A, 0xEB, 0x34,
  30434. 0x0B, 0xFF, 0x18, 0xAB, 0xFA, 0x20, 0xDC, 0x03,
  30435. 0x44, 0x20, 0x30, 0x23, 0x05, 0x33, 0xD9, 0x12,
  30436. 0x9B, 0x83, 0xED, 0x22, 0xC3, 0x51, 0xF2, 0x32,
  30437. 0x81, 0x72, 0xE3, 0x63, 0x44, 0x74, 0x44, 0xAE,
  30438. 0x5C, 0x69, 0x02, 0xB7, 0x92, 0x79, 0x9F, 0x54,
  30439. 0x44, 0x50, 0x78, 0x71, 0x19, 0x61, 0x2E, 0x9B,
  30440. 0xB4, 0x13, 0x0A, 0x33, 0xA2, 0xA5, 0x96, 0x2A,
  30441. 0xC0, 0x9D, 0x57, 0x7D, 0x6D, 0xDC, 0x88, 0x1F,
  30442. 0xE6, 0x61, 0x61, 0x26, 0xD8, 0xA0, 0xA7, 0xDF,
  30443. 0x2B, 0x22, 0x53, 0xBC, 0x8E, 0xC4, 0xE3, 0x53,
  30444. 0x86, 0xEA, 0x55, 0x11, 0xF0, 0xF1, 0x58, 0x87,
  30445. 0x14, 0x5B, 0x6C, 0x23, 0xAB, 0x3D, 0x40, 0x33,
  30446. 0x39, 0xE4, 0x04, 0x07, 0x3E, 0xD9, 0xC6, 0xA8,
  30447. 0x96, 0xA2, 0xF9, 0xEC, 0x70, 0xC4, 0x4B, 0xD2,
  30448. 0xAE, 0xC1, 0x0F, 0xC4, 0x36, 0x0E, 0x87, 0x63,
  30449. 0x6B, 0xE1, 0x55, 0xB6, 0xA6, 0x7B, 0x7E, 0xDF,
  30450. 0x38, 0xCF, 0x73, 0x00, 0x48, 0x13, 0xC9, 0xE7,
  30451. 0xD2, 0xC6, 0x54, 0xC2, 0x53, 0x0A, 0x71, 0xE5,
  30452. 0xF8, 0xC1, 0x09, 0x42, 0xFB, 0x6D, 0x88, 0x41,
  30453. 0x53, 0x5A, 0xB1, 0xDA, 0x43, 0xE8, 0xCB, 0x0B,
  30454. 0xB8, 0x9E, 0x78, 0xEC, 0x91, 0xF8, 0xDE, 0x15,
  30455. 0x31, 0xA0, 0x36, 0x65, 0xCC, 0xD5, 0xA7, 0x5B,
  30456. 0xDA, 0x0E, 0xD0, 0xE5, 0x98, 0x64, 0xEE, 0xEF,
  30457. 0x51, 0xA8, 0x3F, 0xA5, 0x53, 0xAF, 0x66, 0x2A,
  30458. 0xEE, 0x00, 0xD1, 0xF8, 0x36, 0x7B, 0x4D, 0x5D,
  30459. 0xDD, 0xC3, 0x45, 0x54, 0x4C, 0x6B, 0xD5, 0x14,
  30460. 0xF8, 0x88, 0xE6, 0x03, 0x3C, 0x25, 0x5D, 0xB6,
  30461. 0x50, 0xDA, 0x73, 0x4A, 0xD3, 0x3A, 0x3C, 0xF8,
  30462. 0x4B, 0xD3, 0xF0, 0x6F, 0xA1, 0xA7, 0xCA, 0x02,
  30463. 0xE4, 0xB8, 0xE9, 0x93, 0xAE, 0x7A, 0xE6, 0x34,
  30464. 0x20, 0xA4, 0x6B, 0xA8, 0xA3, 0x81, 0x3D, 0x1E,
  30465. 0x9D, 0x29, 0x66, 0xBB, 0x85, 0x60, 0xD7, 0x1C,
  30466. 0x62, 0xA0, 0x44, 0xEA, 0x94, 0x17, 0x9F, 0x4E,
  30467. 0xB1, 0xB6, 0xED, 0x60, 0x71, 0x9D, 0x51, 0xE0,
  30468. 0xEE, 0xF6, 0xCD, 0x07, 0x91, 0x52, 0xF6, 0xBE,
  30469. 0x48, 0x8E, 0xC9, 0x19, 0x11, 0xC6, 0xD3, 0xF1,
  30470. 0xD1, 0x17, 0x3C, 0x54, 0x1F, 0x9D, 0x25, 0xBF,
  30471. 0x34, 0x2F, 0xCA, 0xA3, 0xFF, 0x46, 0xC1, 0x8F,
  30472. 0x2A, 0x04, 0x41, 0xD8, 0x3B, 0xDE, 0x35, 0x46,
  30473. 0xA9, 0x82, 0x6C, 0x34, 0x96, 0xE0, 0x6F, 0x2F,
  30474. 0x2B, 0x0E, 0xEB, 0x9D, 0x5B, 0xE8, 0x73, 0x9F,
  30475. 0x83, 0xA4, 0x2D, 0x3B, 0x30, 0x0E, 0x70, 0xEE,
  30476. 0x84, 0xDF, 0xFF, 0xB2, 0x07, 0x64, 0xA0, 0x60,
  30477. 0x21, 0x2F, 0x05, 0x8C, 0x8A, 0x5F, 0xFA, 0x9A,
  30478. 0x34, 0xE9, 0x28, 0xD6, 0xA7, 0xE0, 0x77, 0x08,
  30479. 0xFE, 0x53, 0x93, 0xE3, 0x01, 0x7C, 0xE4, 0x70,
  30480. 0xEB, 0x96, 0x58, 0xA7, 0x4E, 0x49, 0x51, 0xE6,
  30481. 0xFA, 0x48, 0x54, 0xC9, 0xE9, 0xC2, 0x89, 0x88,
  30482. 0x81, 0x2E, 0x44, 0x18, 0xA2, 0xE8, 0x32, 0x58,
  30483. 0x0B, 0x4A, 0x27, 0x03, 0x72, 0xBC, 0x69, 0x67,
  30484. 0x68, 0x89, 0xD0, 0xCC, 0x43, 0x24, 0x0E, 0xDA,
  30485. 0xBC, 0x1D, 0x31, 0x14, 0xD8, 0xF3, 0x5A, 0xB2,
  30486. 0xE9, 0xEA, 0x95, 0x30, 0x82, 0xE9, 0x53, 0x62,
  30487. 0x79, 0xAC, 0xB3, 0xBE, 0x16, 0xD3, 0xA2, 0x05,
  30488. 0xF4, 0x6C, 0xB6, 0x7B, 0x22, 0x14, 0x96, 0x93,
  30489. 0x5A, 0xC0, 0x42, 0x92, 0xBB, 0xFB, 0x9A, 0x61,
  30490. 0xC0, 0xA0, 0x3E, 0xF4, 0xC9, 0xB6, 0x82, 0x04,
  30491. 0x95, 0xF3, 0xD8, 0x0E, 0x4A, 0x6F, 0xB7, 0xE1,
  30492. 0xC6, 0x99, 0x03, 0xFA, 0x22, 0x6E, 0x02, 0x3E,
  30493. 0x95, 0xBA, 0x41, 0x6D, 0xF2, 0xE5, 0xE4, 0x54,
  30494. 0x1E, 0x15, 0xDC, 0xC0, 0x00, 0xB5, 0xE6, 0x5C,
  30495. 0x97, 0x20, 0xDA, 0xF6, 0x96, 0x01, 0x2F, 0xA2,
  30496. 0xA6, 0xCF, 0x75, 0x8E, 0xD6, 0xD2, 0x25, 0xA3,
  30497. 0xE4, 0xFE, 0xE4, 0x5A, 0xC5, 0xFB, 0x48, 0x70,
  30498. 0x7F, 0xAE, 0x13, 0x3D, 0x59, 0x2C, 0xFD, 0x2E,
  30499. 0x8C, 0x43, 0xC2, 0x12, 0x6F, 0x65, 0x2B, 0xEE,
  30500. 0x9B, 0xAB, 0x43, 0xA1, 0xA1, 0x0B, 0xE2, 0x41,
  30501. 0x1A, 0x67, 0x94, 0xB2, 0x6C, 0xB5, 0x5C, 0xC2,
  30502. 0x17, 0xEB, 0x7B, 0x0B, 0x14, 0x6D, 0x23, 0xF7,
  30503. 0x92, 0x2D, 0x32, 0x22, 0xAE, 0x5E, 0xE8, 0xC6,
  30504. 0xD3, 0x8E, 0x83, 0x99, 0xBA, 0x51, 0xC6, 0x81,
  30505. 0xB8, 0x38, 0x16, 0xFC, 0xF7, 0x44, 0x38, 0x82,
  30506. 0x59, 0x20, 0xF9, 0xCE, 0x8A, 0x20, 0x2A, 0x8F,
  30507. 0x6D, 0x94, 0x2D, 0xA8, 0x62, 0x38, 0xFB, 0x4C,
  30508. 0x9F, 0x21, 0x98, 0xEA, 0x8D, 0xFF, 0x81, 0xC1,
  30509. 0x72, 0x86, 0xE0, 0x18, 0xDF, 0x4B, 0x7F, 0xE3,
  30510. 0x88, 0x4D, 0x17, 0x59, 0xE4, 0xC5, 0x9B, 0xB5,
  30511. 0x26, 0x17, 0xAE, 0xD4, 0xE7, 0x8E, 0x4E, 0x7C,
  30512. 0x4E, 0x9A, 0x36, 0xE4, 0xE9, 0x96, 0xD3, 0x23,
  30513. 0x91, 0xA3, 0x4A, 0x0D, 0xAA, 0xAB, 0x6B, 0x54,
  30514. 0x08, 0x15, 0xA3, 0x4D, 0x20, 0x40, 0x7A, 0xEF,
  30515. 0x81, 0x94, 0x9B, 0xE6, 0x7B, 0x90, 0x69, 0x50,
  30516. 0xD8, 0x9B, 0xE9, 0xF0, 0x85, 0xE9, 0x9E, 0xB5,
  30517. 0x87, 0x26, 0x95, 0x17, 0x3B, 0x3E, 0xFA, 0xCA,
  30518. 0xE9, 0x45, 0x5D, 0x2B, 0x2C, 0xD4, 0xF7, 0x10,
  30519. 0xB8, 0x72, 0xCF, 0x66, 0x2B, 0x73, 0x62, 0x16,
  30520. 0xB1, 0xBB, 0xFB, 0x1F, 0x5F, 0x3D, 0x48, 0x6C,
  30521. 0x7B, 0x4B, 0x87, 0x56, 0x12, 0x33, 0x3F, 0x8E,
  30522. 0x4B, 0xA9, 0x33, 0xDC, 0x79, 0xF0, 0xED, 0xFD,
  30523. 0x7B, 0xAA, 0xDE, 0x2C, 0x16, 0xF2, 0x14, 0x6A,
  30524. 0x49, 0x6F, 0x79, 0xC4, 0x2A, 0x4D, 0x6B, 0x52,
  30525. 0x39, 0xA3, 0x0D, 0xD3, 0xC4, 0x8B, 0xEB, 0x09,
  30526. 0x2C, 0xA0, 0x75, 0x00, 0x10, 0xF6, 0x9E, 0xD4,
  30527. 0xB9, 0x23, 0x20, 0x14, 0x7D, 0xBB, 0xE2, 0x08,
  30528. 0xF6, 0xE8, 0xEB, 0x1C, 0xF2, 0x47, 0xD2, 0x1A,
  30529. 0x3A, 0x3B, 0x01, 0xDF, 0x58, 0xC0, 0xAA, 0x62,
  30530. 0x94, 0x4D, 0xA0, 0xEF, 0x04, 0x50, 0xE8, 0xCE,
  30531. 0x48, 0xAA, 0x13, 0x7E, 0x7E, 0x15, 0x16, 0xC1,
  30532. 0xD5, 0xC8, 0x6E, 0xEA, 0x17, 0xFD, 0xFA, 0xC1,
  30533. 0x69, 0x07, 0x46, 0xE7, 0x26, 0x70, 0x45, 0xA3,
  30534. 0xE9, 0x05, 0x96, 0xBD, 0xB7, 0x5D, 0x50, 0xB6,
  30535. 0xDD, 0x5C, 0x34, 0xE5, 0xC8, 0xD8, 0x9D, 0xC6,
  30536. 0xF2, 0xF1, 0xD2, 0x44, 0x40, 0xE5, 0x7B, 0x47,
  30537. 0x59, 0xB8, 0x62, 0x5F, 0x72, 0xBC, 0x4A, 0x7B,
  30538. 0x10, 0xD5, 0x19, 0xD3, 0x31, 0xF9, 0xC4, 0x00,
  30539. 0xAA, 0xE1, 0xE5, 0x0D, 0x48, 0x0C, 0xAA, 0xE5,
  30540. 0xA1, 0xC0, 0xFA, 0x99, 0xD7, 0x79, 0x24, 0xCF,
  30541. 0x8D, 0xFE, 0x56, 0xCD, 0x70, 0x92, 0xE7, 0xB9
  30542. };
  30543. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  30544. #ifndef WOLFSSL_NO_ML_DSA_65
  30545. static const byte seed_65[] = {
  30546. 0x70, 0xCE, 0xFB, 0x9A, 0xED, 0x5B, 0x68, 0xE0,
  30547. 0x18, 0xB0, 0x79, 0xDA, 0x82, 0x84, 0xB9, 0xD5,
  30548. 0xCA, 0xD5, 0x49, 0x9E, 0xD9, 0xC2, 0x65, 0xFF,
  30549. 0x73, 0x58, 0x80, 0x05, 0xD8, 0x5C, 0x22, 0x5C
  30550. };
  30551. static const byte pk_65[] = {
  30552. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  30553. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  30554. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  30555. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  30556. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  30557. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  30558. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  30559. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  30560. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  30561. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  30562. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  30563. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  30564. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  30565. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  30566. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  30567. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  30568. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  30569. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  30570. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  30571. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  30572. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  30573. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  30574. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  30575. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  30576. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  30577. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  30578. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  30579. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  30580. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  30581. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  30582. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  30583. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  30584. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  30585. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  30586. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  30587. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  30588. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  30589. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  30590. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  30591. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  30592. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  30593. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  30594. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  30595. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  30596. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  30597. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  30598. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  30599. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  30600. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  30601. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  30602. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  30603. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  30604. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  30605. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  30606. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  30607. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  30608. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  30609. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  30610. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  30611. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  30612. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  30613. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  30614. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  30615. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  30616. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  30617. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  30618. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  30619. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  30620. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  30621. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  30622. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  30623. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  30624. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  30625. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  30626. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  30627. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  30628. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  30629. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  30630. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  30631. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  30632. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  30633. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  30634. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  30635. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  30636. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  30637. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  30638. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  30639. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  30640. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  30641. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  30642. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  30643. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  30644. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  30645. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  30646. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  30647. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  30648. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  30649. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  30650. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  30651. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  30652. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  30653. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  30654. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  30655. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  30656. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  30657. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  30658. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  30659. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  30660. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  30661. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  30662. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  30663. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  30664. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  30665. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  30666. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  30667. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  30668. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  30669. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  30670. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  30671. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  30672. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  30673. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  30674. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  30675. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  30676. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  30677. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  30678. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  30679. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  30680. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  30681. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  30682. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  30683. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  30684. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  30685. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  30686. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  30687. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  30688. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  30689. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  30690. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  30691. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  30692. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  30693. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  30694. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  30695. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  30696. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  30697. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  30698. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  30699. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  30700. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  30701. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  30702. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  30703. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  30704. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  30705. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  30706. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  30707. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  30708. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  30709. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  30710. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  30711. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  30712. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  30713. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  30714. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  30715. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  30716. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  30717. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  30718. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  30719. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  30720. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  30721. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  30722. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  30723. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  30724. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  30725. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  30726. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  30727. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  30728. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  30729. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  30730. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  30731. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  30732. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  30733. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  30734. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  30735. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  30736. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  30737. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  30738. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  30739. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  30740. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  30741. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  30742. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  30743. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  30744. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  30745. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  30746. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  30747. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  30748. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  30749. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  30750. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  30751. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  30752. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  30753. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  30754. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  30755. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  30756. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  30757. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  30758. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  30759. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  30760. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  30761. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  30762. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  30763. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  30764. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  30765. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  30766. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  30767. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  30768. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  30769. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  30770. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  30771. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  30772. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  30773. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  30774. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  30775. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  30776. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  30777. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  30778. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  30779. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  30780. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  30781. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  30782. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  30783. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  30784. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  30785. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  30786. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  30787. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  30788. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  30789. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  30790. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  30791. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  30792. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  30793. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  30794. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  30795. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  30796. };
  30797. static const byte sk_65[] = {
  30798. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  30799. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  30800. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  30801. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  30802. 0xE3, 0x8D, 0x1C, 0x14, 0xF6, 0x46, 0x7C, 0x35,
  30803. 0xA9, 0xF3, 0x80, 0xD2, 0x7D, 0xE6, 0x1F, 0x7C,
  30804. 0x75, 0x03, 0x15, 0x69, 0xEA, 0x2E, 0xC8, 0x26,
  30805. 0x0E, 0xEE, 0x91, 0x05, 0x26, 0x1B, 0x7F, 0xE1,
  30806. 0x60, 0xC9, 0x13, 0x44, 0xB0, 0xC6, 0x76, 0x4C,
  30807. 0x20, 0x4E, 0x5B, 0x8D, 0x42, 0x46, 0x50, 0xBE,
  30808. 0xC0, 0x6B, 0x9E, 0x2E, 0x62, 0x5A, 0xF0, 0x7E,
  30809. 0x23, 0xF4, 0x95, 0x0C, 0xA2, 0x4F, 0xB4, 0xD6,
  30810. 0xEC, 0x2C, 0x8B, 0x3A, 0x71, 0x7C, 0x93, 0x11,
  30811. 0xEB, 0x87, 0x27, 0x9F, 0xE2, 0x5E, 0x31, 0x1F,
  30812. 0x48, 0xB8, 0x25, 0x65, 0x01, 0xF6, 0x46, 0x34,
  30813. 0x12, 0xB5, 0x0D, 0xBC, 0x89, 0xA8, 0x69, 0xBA,
  30814. 0x22, 0x41, 0x11, 0x26, 0x48, 0x40, 0x07, 0x38,
  30815. 0x73, 0x02, 0x12, 0x44, 0x25, 0x44, 0x57, 0x54,
  30816. 0x83, 0x72, 0x50, 0x33, 0x35, 0x62, 0x58, 0x42,
  30817. 0x32, 0x01, 0x62, 0x11, 0x83, 0x61, 0x02, 0x45,
  30818. 0x66, 0x56, 0x48, 0x35, 0x61, 0x20, 0x84, 0x52,
  30819. 0x60, 0x68, 0x50, 0x45, 0x65, 0x55, 0x12, 0x72,
  30820. 0x47, 0x47, 0x21, 0x21, 0x25, 0x40, 0x22, 0x21,
  30821. 0x42, 0x81, 0x17, 0x65, 0x03, 0x06, 0x42, 0x61,
  30822. 0x52, 0x13, 0x43, 0x25, 0x24, 0x33, 0x82, 0x12,
  30823. 0x11, 0x35, 0x62, 0x33, 0x32, 0x07, 0x47, 0x86,
  30824. 0x22, 0x31, 0x50, 0x83, 0x70, 0x84, 0x26, 0x43,
  30825. 0x45, 0x64, 0x51, 0x48, 0x31, 0x14, 0x86, 0x24,
  30826. 0x66, 0x86, 0x74, 0x33, 0x71, 0x36, 0x67, 0x26,
  30827. 0x01, 0x47, 0x07, 0x72, 0x11, 0x61, 0x58, 0x85,
  30828. 0x58, 0x38, 0x71, 0x83, 0x80, 0x67, 0x01, 0x65,
  30829. 0x78, 0x70, 0x64, 0x77, 0x85, 0x60, 0x02, 0x88,
  30830. 0x53, 0x48, 0x46, 0x62, 0x25, 0x83, 0x54, 0x88,
  30831. 0x04, 0x74, 0x40, 0x12, 0x57, 0x43, 0x71, 0x07,
  30832. 0x75, 0x44, 0x38, 0x71, 0x21, 0x14, 0x22, 0x08,
  30833. 0x88, 0x72, 0x23, 0x58, 0x87, 0x46, 0x14, 0x85,
  30834. 0x53, 0x71, 0x67, 0x73, 0x82, 0x28, 0x22, 0x74,
  30835. 0x14, 0x03, 0x57, 0x73, 0x28, 0x71, 0x83, 0x80,
  30836. 0x78, 0x14, 0x34, 0x87, 0x52, 0x07, 0x64, 0x74,
  30837. 0x01, 0x60, 0x75, 0x61, 0x06, 0x08, 0x61, 0x32,
  30838. 0x21, 0x46, 0x15, 0x65, 0x42, 0x67, 0x08, 0x20,
  30839. 0x84, 0x10, 0x73, 0x13, 0x03, 0x61, 0x02, 0x86,
  30840. 0x50, 0x45, 0x26, 0x12, 0x16, 0x68, 0x33, 0x55,
  30841. 0x25, 0x84, 0x73, 0x53, 0x54, 0x52, 0x65, 0x17,
  30842. 0x10, 0x60, 0x00, 0x38, 0x57, 0x77, 0x81, 0x24,
  30843. 0x26, 0x80, 0x41, 0x46, 0x43, 0x26, 0x67, 0x41,
  30844. 0x06, 0x03, 0x55, 0x41, 0x28, 0x33, 0x37, 0x25,
  30845. 0x23, 0x06, 0x77, 0x82, 0x15, 0x16, 0x31, 0x73,
  30846. 0x00, 0x08, 0x75, 0x26, 0x58, 0x46, 0x34, 0x63,
  30847. 0x88, 0x08, 0x84, 0x64, 0x51, 0x11, 0x24, 0x05,
  30848. 0x32, 0x10, 0x11, 0x18, 0x18, 0x64, 0x78, 0x22,
  30849. 0x41, 0x00, 0x38, 0x55, 0x75, 0x42, 0x10, 0x46,
  30850. 0x83, 0x43, 0x73, 0x38, 0x80, 0x07, 0x83, 0x43,
  30851. 0x78, 0x74, 0x13, 0x57, 0x62, 0x32, 0x68, 0x80,
  30852. 0x65, 0x86, 0x48, 0x53, 0x48, 0x35, 0x51, 0x58,
  30853. 0x50, 0x74, 0x46, 0x05, 0x88, 0x70, 0x07, 0x72,
  30854. 0x01, 0x31, 0x00, 0x87, 0x54, 0x88, 0x14, 0x20,
  30855. 0x84, 0x16, 0x61, 0x15, 0x60, 0x56, 0x85, 0x11,
  30856. 0x58, 0x08, 0x05, 0x88, 0x63, 0x01, 0x82, 0x86,
  30857. 0x13, 0x14, 0x17, 0x22, 0x01, 0x68, 0x17, 0x17,
  30858. 0x86, 0x58, 0x53, 0x10, 0x62, 0x28, 0x52, 0x82,
  30859. 0x26, 0x15, 0x04, 0x31, 0x42, 0x88, 0x54, 0x31,
  30860. 0x78, 0x05, 0x80, 0x11, 0x50, 0x45, 0x68, 0x82,
  30861. 0x33, 0x66, 0x36, 0x36, 0x40, 0x65, 0x15, 0x24,
  30862. 0x47, 0x67, 0x06, 0x45, 0x36, 0x42, 0x26, 0x86,
  30863. 0x75, 0x06, 0x35, 0x41, 0x33, 0x47, 0x85, 0x12,
  30864. 0x17, 0x80, 0x83, 0x87, 0x65, 0x51, 0x42, 0x31,
  30865. 0x38, 0x87, 0x56, 0x62, 0x05, 0x17, 0x40, 0x85,
  30866. 0x28, 0x14, 0x17, 0x21, 0x38, 0x12, 0x60, 0x81,
  30867. 0x24, 0x41, 0x45, 0x75, 0x01, 0x82, 0x87, 0x10,
  30868. 0x10, 0x02, 0x13, 0x25, 0x57, 0x04, 0x21, 0x72,
  30869. 0x42, 0x78, 0x61, 0x11, 0x70, 0x05, 0x30, 0x47,
  30870. 0x72, 0x13, 0x20, 0x30, 0x21, 0x67, 0x44, 0x31,
  30871. 0x57, 0x71, 0x45, 0x57, 0x10, 0x54, 0x16, 0x65,
  30872. 0x74, 0x15, 0x24, 0x02, 0x43, 0x71, 0x51, 0x20,
  30873. 0x55, 0x11, 0x67, 0x83, 0x67, 0x82, 0x52, 0x53,
  30874. 0x35, 0x66, 0x42, 0x46, 0x13, 0x70, 0x22, 0x32,
  30875. 0x74, 0x00, 0x07, 0x06, 0x81, 0x87, 0x17, 0x57,
  30876. 0x80, 0x28, 0x68, 0x01, 0x72, 0x10, 0x04, 0x27,
  30877. 0x55, 0x22, 0x86, 0x42, 0x53, 0x15, 0x81, 0x76,
  30878. 0x30, 0x86, 0x40, 0x83, 0x11, 0x43, 0x30, 0x53,
  30879. 0x82, 0x73, 0x53, 0x03, 0x72, 0x35, 0x68, 0x70,
  30880. 0x45, 0x41, 0x15, 0x73, 0x14, 0x12, 0x31, 0x64,
  30881. 0x32, 0x66, 0x63, 0x56, 0x21, 0x51, 0x50, 0x82,
  30882. 0x10, 0x30, 0x23, 0x38, 0x17, 0x21, 0x27, 0x10,
  30883. 0x23, 0x14, 0x22, 0x75, 0x77, 0x28, 0x37, 0x71,
  30884. 0x62, 0x75, 0x06, 0x88, 0x72, 0x14, 0x18, 0x73,
  30885. 0x13, 0x03, 0x01, 0x50, 0x71, 0x58, 0x62, 0x86,
  30886. 0x62, 0x88, 0x86, 0x86, 0x03, 0x27, 0x01, 0x46,
  30887. 0x17, 0x22, 0x71, 0x38, 0x53, 0x81, 0x70, 0x33,
  30888. 0x88, 0x68, 0x13, 0x78, 0x81, 0x04, 0x86, 0x57,
  30889. 0x30, 0x16, 0x52, 0x31, 0x40, 0x83, 0x07, 0x56,
  30890. 0x82, 0x10, 0x32, 0x31, 0x28, 0x50, 0x06, 0x50,
  30891. 0x81, 0x63, 0x06, 0x75, 0x76, 0x65, 0x11, 0x60,
  30892. 0x14, 0x17, 0x12, 0x12, 0x55, 0x56, 0x48, 0x11,
  30893. 0x41, 0x13, 0x28, 0x82, 0x62, 0x07, 0x47, 0x64,
  30894. 0x24, 0x48, 0x23, 0x24, 0x77, 0x53, 0x26, 0x08,
  30895. 0x17, 0x58, 0x11, 0x56, 0x37, 0x48, 0x35, 0x51,
  30896. 0x47, 0x86, 0x85, 0x66, 0x66, 0x81, 0x73, 0x20,
  30897. 0x21, 0x36, 0x75, 0x22, 0x74, 0x66, 0x83, 0x44,
  30898. 0x57, 0x00, 0x66, 0x64, 0x77, 0x20, 0x47, 0x22,
  30899. 0x28, 0x56, 0x87, 0x12, 0x47, 0x02, 0x48, 0x07,
  30900. 0x02, 0x54, 0x23, 0x01, 0x25, 0x71, 0x37, 0x36,
  30901. 0x75, 0x36, 0x00, 0x52, 0x68, 0x15, 0x33, 0x35,
  30902. 0x82, 0x06, 0x13, 0x73, 0x24, 0x08, 0x71, 0x76,
  30903. 0x15, 0x22, 0x42, 0x60, 0x18, 0x53, 0x43, 0x11,
  30904. 0x64, 0x57, 0x76, 0x17, 0x61, 0x56, 0x68, 0x76,
  30905. 0x60, 0x65, 0x54, 0x78, 0x10, 0x33, 0x63, 0x14,
  30906. 0x21, 0x83, 0x21, 0x60, 0x15, 0x55, 0x80, 0x42,
  30907. 0x38, 0x42, 0x03, 0x13, 0x12, 0x34, 0x36, 0x25,
  30908. 0x27, 0x30, 0x82, 0x81, 0x25, 0x47, 0x51, 0x35,
  30909. 0x44, 0x12, 0x67, 0x35, 0x00, 0x10, 0x01, 0x83,
  30910. 0x85, 0x74, 0x42, 0x40, 0x13, 0x03, 0x61, 0x27,
  30911. 0x81, 0x26, 0x26, 0x81, 0x18, 0x87, 0x43, 0x51,
  30912. 0x20, 0x62, 0x71, 0x27, 0x51, 0x56, 0x10, 0x22,
  30913. 0x22, 0x81, 0x11, 0x81, 0x41, 0x66, 0x66, 0x38,
  30914. 0x20, 0x86, 0x75, 0x56, 0x12, 0x40, 0x06, 0x54,
  30915. 0x61, 0x12, 0x74, 0x40, 0x34, 0x58, 0x58, 0x78,
  30916. 0x10, 0x07, 0x85, 0x25, 0x72, 0x88, 0x57, 0x22,
  30917. 0x22, 0x25, 0x50, 0x84, 0x00, 0x41, 0x26, 0x08,
  30918. 0x36, 0x46, 0x28, 0x78, 0x46, 0x78, 0x05, 0x02,
  30919. 0x28, 0x20, 0x77, 0x13, 0x60, 0x75, 0x14, 0x43,
  30920. 0x68, 0x78, 0x64, 0x31, 0x38, 0x77, 0x73, 0x73,
  30921. 0x55, 0x41, 0x27, 0x00, 0x54, 0x07, 0x08, 0x28,
  30922. 0x68, 0x80, 0x04, 0x53, 0x83, 0x43, 0x22, 0x81,
  30923. 0x00, 0x64, 0x35, 0x48, 0x67, 0x66, 0x50, 0x17,
  30924. 0x75, 0x76, 0x12, 0x75, 0x43, 0x81, 0x62, 0x40,
  30925. 0x33, 0x43, 0x45, 0x38, 0x87, 0x21, 0x66, 0x14,
  30926. 0x70, 0x48, 0x41, 0x43, 0x14, 0x66, 0x58, 0x78,
  30927. 0x45, 0x82, 0x02, 0x25, 0x45, 0x73, 0x15, 0x21,
  30928. 0x32, 0x03, 0x02, 0x48, 0x80, 0x80, 0x13, 0x71,
  30929. 0x25, 0x54, 0x32, 0x72, 0x05, 0x68, 0x65, 0x24,
  30930. 0x68, 0x04, 0x06, 0x16, 0x83, 0x50, 0x54, 0x53,
  30931. 0x37, 0x37, 0x27, 0x22, 0x20, 0x68, 0x08, 0x25,
  30932. 0x50, 0x84, 0x72, 0x86, 0x74, 0x22, 0x36, 0x16,
  30933. 0x80, 0x07, 0x55, 0x18, 0x12, 0x17, 0x84, 0x44,
  30934. 0x81, 0x15, 0x64, 0x50, 0x71, 0x10, 0x58, 0x15,
  30935. 0x51, 0x10, 0x10, 0x47, 0x16, 0x21, 0x07, 0x58,
  30936. 0x61, 0x18, 0x78, 0x00, 0x52, 0x72, 0x64, 0x52,
  30937. 0x17, 0x43, 0x23, 0x40, 0x76, 0x48, 0x67, 0x30,
  30938. 0x77, 0x63, 0x64, 0x87, 0x51, 0x31, 0x63, 0x84,
  30939. 0x68, 0x74, 0x53, 0x63, 0x84, 0x23, 0x54, 0x66,
  30940. 0x10, 0x48, 0x36, 0x33, 0x85, 0x21, 0x48, 0x42,
  30941. 0x03, 0x82, 0x51, 0x10, 0x33, 0x57, 0x46, 0x80,
  30942. 0x16, 0x43, 0x34, 0x02, 0x07, 0x03, 0x53, 0x22,
  30943. 0x12, 0x75, 0x73, 0x34, 0x65, 0x83, 0x33, 0x87,
  30944. 0x43, 0x85, 0x17, 0x50, 0x36, 0x60, 0x88, 0x02,
  30945. 0x58, 0x75, 0x80, 0x88, 0x31, 0x63, 0x60, 0x18,
  30946. 0x21, 0x32, 0x26, 0x15, 0x68, 0x74, 0x11, 0x10,
  30947. 0x33, 0x14, 0x13, 0x05, 0x34, 0x16, 0x72, 0x65,
  30948. 0x35, 0x50, 0x13, 0x34, 0x80, 0x87, 0x10, 0x26,
  30949. 0x48, 0x68, 0x84, 0x52, 0x71, 0x44, 0x23, 0x58,
  30950. 0x80, 0x35, 0x57, 0x70, 0x54, 0x84, 0x28, 0x70,
  30951. 0x55, 0x88, 0x86, 0x83, 0x86, 0x25, 0x21, 0x82,
  30952. 0x72, 0x61, 0x17, 0x78, 0x85, 0x17, 0x67, 0x73,
  30953. 0x00, 0x57, 0x71, 0x11, 0x78, 0x51, 0x10, 0x65,
  30954. 0x63, 0x57, 0x02, 0x87, 0x40, 0x13, 0x40, 0x01,
  30955. 0x26, 0x53, 0x45, 0x12, 0x05, 0x46, 0x75, 0x18,
  30956. 0x80, 0x70, 0x33, 0x35, 0x66, 0x22, 0x62, 0x00,
  30957. 0x70, 0x23, 0x26, 0x87, 0x72, 0x63, 0x11, 0x13,
  30958. 0x33, 0x33, 0x81, 0x41, 0x70, 0x62, 0x28, 0x61,
  30959. 0x51, 0x47, 0x31, 0x30, 0x25, 0x46, 0x51, 0x17,
  30960. 0x61, 0x58, 0x07, 0x41, 0x61, 0x37, 0x37, 0x06,
  30961. 0x14, 0x00, 0x54, 0x88, 0x77, 0x75, 0x67, 0x77,
  30962. 0x66, 0x53, 0x16, 0x72, 0x66, 0x66, 0x88, 0x76,
  30963. 0x43, 0x58, 0x31, 0x04, 0x87, 0x57, 0x06, 0x76,
  30964. 0x47, 0x00, 0x43, 0x63, 0x58, 0x60, 0x52, 0x03,
  30965. 0x44, 0x27, 0x36, 0x48, 0x61, 0x23, 0x72, 0x16,
  30966. 0x10, 0x62, 0x42, 0x08, 0x60, 0x83, 0x23, 0x54,
  30967. 0x03, 0x55, 0x55, 0x73, 0x00, 0x61, 0x03, 0x65,
  30968. 0x34, 0x27, 0x14, 0x15, 0x86, 0x62, 0x55, 0x80,
  30969. 0x16, 0x53, 0x10, 0x18, 0x26, 0x11, 0x35, 0x46,
  30970. 0x82, 0x46, 0x13, 0x25, 0x83, 0x47, 0x70, 0x50,
  30971. 0x06, 0x01, 0x56, 0x02, 0x11, 0x68, 0x54, 0x53,
  30972. 0x03, 0x68, 0x73, 0x36, 0x41, 0x88, 0x86, 0x33,
  30973. 0x42, 0x52, 0x01, 0x58, 0x33, 0x42, 0x32, 0x88,
  30974. 0x56, 0x81, 0x77, 0x55, 0x51, 0x48, 0x48, 0x12,
  30975. 0x01, 0x58, 0x13, 0x85, 0x04, 0x14, 0x71, 0x83,
  30976. 0x57, 0x07, 0x54, 0x55, 0x54, 0x55, 0x28, 0x27,
  30977. 0x31, 0x36, 0x02, 0x12, 0x32, 0x68, 0x32, 0x13,
  30978. 0x82, 0x58, 0x70, 0x28, 0x58, 0x53, 0x44, 0x86,
  30979. 0x72, 0x73, 0x42, 0x84, 0x18, 0x22, 0x08, 0x83,
  30980. 0x61, 0x02, 0x14, 0x16, 0x17, 0x12, 0x41, 0x57,
  30981. 0x48, 0x85, 0x25, 0x10, 0x26, 0x07, 0x36, 0x76,
  30982. 0x12, 0x66, 0x17, 0x21, 0x32, 0x36, 0x03, 0x25,
  30983. 0x41, 0x10, 0x11, 0x22, 0x66, 0x60, 0x16, 0x16,
  30984. 0x32, 0x64, 0x26, 0x05, 0x18, 0x63, 0x51, 0x58,
  30985. 0x51, 0x31, 0x42, 0x53, 0x84, 0x56, 0x66, 0x27,
  30986. 0x83, 0x33, 0x54, 0x50, 0x76, 0x46, 0x50, 0x80,
  30987. 0x25, 0x43, 0x41, 0x57, 0x35, 0x78, 0x25, 0x43,
  30988. 0x02, 0x82, 0x38, 0x47, 0x45, 0x70, 0x15, 0x67,
  30989. 0x51, 0x77, 0x47, 0x80, 0x31, 0x52, 0x75, 0x00,
  30990. 0x00, 0x94, 0x7B, 0xCA, 0x93, 0xC2, 0x7D, 0x58,
  30991. 0x4E, 0x2C, 0x66, 0xEA, 0xC9, 0xC7, 0x64, 0x0C,
  30992. 0x1C, 0xA2, 0x17, 0xEE, 0xF6, 0x6D, 0xAB, 0xBC,
  30993. 0xB2, 0x60, 0xB4, 0xC3, 0x43, 0x00, 0xFA, 0x05,
  30994. 0x13, 0x57, 0x82, 0x0F, 0x57, 0x39, 0x25, 0x44,
  30995. 0x98, 0x2F, 0xD1, 0x10, 0x57, 0xDE, 0x23, 0x3E,
  30996. 0x6D, 0x2D, 0xD8, 0x49, 0x72, 0xA7, 0xE4, 0x7D,
  30997. 0x4D, 0xBA, 0x99, 0xBC, 0x30, 0xCF, 0x8F, 0x2A,
  30998. 0xD5, 0xA2, 0xC0, 0x24, 0x31, 0x95, 0xED, 0x27,
  30999. 0x30, 0xFF, 0xA9, 0x2D, 0x22, 0x7D, 0x15, 0x30,
  31000. 0x95, 0x97, 0x2D, 0x4B, 0x34, 0x47, 0xFF, 0xAC,
  31001. 0x45, 0xA2, 0x3E, 0xB4, 0x1C, 0xBC, 0x87, 0xCD,
  31002. 0xD1, 0x25, 0x0A, 0x8A, 0x47, 0x8B, 0x0F, 0x7A,
  31003. 0x1D, 0x5B, 0x39, 0xAA, 0x22, 0x06, 0xE4, 0x86,
  31004. 0x45, 0x58, 0x4F, 0xE7, 0xBF, 0x7A, 0x13, 0x16,
  31005. 0x8F, 0x48, 0x27, 0x65, 0xE5, 0x7B, 0xB9, 0x24,
  31006. 0xAC, 0x6D, 0x9A, 0x11, 0x36, 0x9F, 0x4A, 0x6A,
  31007. 0xFF, 0xCD, 0x16, 0x9B, 0x7D, 0x75, 0x12, 0x9B,
  31008. 0x35, 0xD5, 0x13, 0x4A, 0x31, 0x76, 0x1B, 0xB8,
  31009. 0x35, 0x5A, 0xEE, 0xED, 0x27, 0xE2, 0x01, 0xA0,
  31010. 0x63, 0x13, 0x01, 0x3E, 0x30, 0x7A, 0x01, 0xA7,
  31011. 0x3A, 0xEA, 0x79, 0x55, 0xC0, 0x57, 0x8C, 0x8C,
  31012. 0x5E, 0x5A, 0x1A, 0x2D, 0x2F, 0xA4, 0x59, 0x3F,
  31013. 0xAC, 0xD9, 0x04, 0xC6, 0x20, 0x40, 0xBD, 0xB9,
  31014. 0xF3, 0x29, 0x93, 0x35, 0x36, 0xBF, 0x8D, 0x81,
  31015. 0xC4, 0x25, 0x6B, 0xAA, 0xE8, 0x72, 0x3F, 0xD4,
  31016. 0xDC, 0x66, 0xBB, 0x5E, 0x7F, 0x9C, 0xA4, 0x90,
  31017. 0x31, 0xA1, 0x93, 0xEC, 0xEC, 0xBB, 0x5D, 0xC3,
  31018. 0x90, 0xEC, 0x6D, 0x55, 0x13, 0xC7, 0x9A, 0x05,
  31019. 0x2B, 0x3F, 0xD4, 0x36, 0x12, 0xFB, 0x73, 0x75,
  31020. 0x31, 0x5D, 0x80, 0x91, 0xF7, 0x9B, 0xAB, 0x13,
  31021. 0x18, 0xF1, 0x78, 0x54, 0x56, 0x1B, 0xC9, 0x3A,
  31022. 0xE0, 0xE5, 0xCD, 0x6D, 0x13, 0x1E, 0x56, 0x2C,
  31023. 0x81, 0x14, 0x81, 0x0C, 0x93, 0x9A, 0xE5, 0x63,
  31024. 0xAA, 0x10, 0xB4, 0x7C, 0xE4, 0x48, 0x43, 0x17,
  31025. 0xF3, 0x4A, 0xBD, 0x02, 0xD0, 0xCC, 0xAD, 0x58,
  31026. 0xDD, 0x29, 0xBC, 0xF6, 0x57, 0xBB, 0xD9, 0x25,
  31027. 0x4B, 0x01, 0xCA, 0x97, 0x26, 0x09, 0x19, 0x38,
  31028. 0xED, 0x32, 0x05, 0x4B, 0x37, 0xDD, 0x61, 0x72,
  31029. 0x40, 0xF4, 0x43, 0x4C, 0x1A, 0x4A, 0x87, 0x11,
  31030. 0xAA, 0x3A, 0x39, 0x9A, 0x8A, 0x53, 0x88, 0x33,
  31031. 0x0B, 0x70, 0x59, 0xEC, 0xCB, 0xB6, 0xB1, 0xB9,
  31032. 0xCF, 0x71, 0x87, 0xAD, 0xF1, 0x0B, 0x0C, 0x91,
  31033. 0x71, 0xD3, 0xC0, 0xF6, 0xE2, 0xD4, 0x60, 0xA4,
  31034. 0x19, 0x24, 0x76, 0x72, 0xE3, 0xB9, 0xFE, 0xA2,
  31035. 0xC9, 0x59, 0x10, 0xBF, 0x2F, 0xB6, 0xA5, 0xD6,
  31036. 0x1F, 0x25, 0x74, 0x53, 0xB0, 0x7A, 0xFB, 0x64,
  31037. 0xB0, 0xBA, 0x27, 0x58, 0xBC, 0xD7, 0x35, 0x75,
  31038. 0x1F, 0x2D, 0x53, 0x51, 0x5E, 0x23, 0x6F, 0xE8,
  31039. 0xA5, 0xB4, 0x39, 0x3B, 0x80, 0xBF, 0x06, 0xDF,
  31040. 0x97, 0xBD, 0xC6, 0x38, 0x00, 0x87, 0xE6, 0xAA,
  31041. 0x8D, 0xDE, 0x6E, 0x09, 0x81, 0x11, 0xA7, 0x34,
  31042. 0x3F, 0xCD, 0xD1, 0xE9, 0x03, 0x70, 0x8E, 0x63,
  31043. 0x7E, 0xBF, 0x28, 0x32, 0x3C, 0xDA, 0x6B, 0x94,
  31044. 0x05, 0x81, 0x0E, 0xDC, 0xFB, 0x36, 0x91, 0x14,
  31045. 0x9E, 0xCF, 0x22, 0x4C, 0x50, 0xF8, 0xDF, 0x92,
  31046. 0xA9, 0x4A, 0xA4, 0x77, 0x0A, 0x0E, 0x91, 0x46,
  31047. 0x61, 0x94, 0xBB, 0x0E, 0x27, 0xBF, 0x1C, 0xAB,
  31048. 0xF1, 0x6A, 0xDF, 0xD3, 0x51, 0x22, 0x00, 0x33,
  31049. 0xF7, 0x6F, 0x59, 0x25, 0x55, 0x7B, 0xCF, 0x96,
  31050. 0x34, 0xE9, 0x46, 0x13, 0x59, 0x62, 0x1D, 0x80,
  31051. 0xB4, 0xBB, 0xAD, 0x7E, 0x2A, 0x6E, 0x43, 0x2D,
  31052. 0xC4, 0x3B, 0x12, 0x6C, 0xA4, 0x2A, 0xB8, 0x8A,
  31053. 0xA8, 0x8F, 0x0A, 0x84, 0xAF, 0x58, 0x02, 0x9C,
  31054. 0x99, 0xA0, 0x24, 0x8F, 0x0C, 0x45, 0x40, 0x71,
  31055. 0xF3, 0x5B, 0x83, 0x1F, 0xED, 0x12, 0x54, 0xD6,
  31056. 0xF4, 0xE2, 0x72, 0x04, 0x85, 0x78, 0x62, 0x15,
  31057. 0xF7, 0xC7, 0xF0, 0xC4, 0xED, 0x15, 0xFA, 0x85,
  31058. 0x3C, 0xD3, 0xAA, 0x07, 0x25, 0x9B, 0x39, 0x24,
  31059. 0x0A, 0x82, 0x13, 0x5C, 0x29, 0x23, 0xA7, 0x2B,
  31060. 0x87, 0x6F, 0xAB, 0xB3, 0xF0, 0xF2, 0xC0, 0x96,
  31061. 0x13, 0xDE, 0x39, 0xD4, 0x59, 0xA0, 0x7C, 0x14,
  31062. 0xE7, 0xBA, 0x43, 0x7D, 0x80, 0x41, 0x49, 0x1F,
  31063. 0xCE, 0xC1, 0x43, 0x34, 0x04, 0xBA, 0xD1, 0xDA,
  31064. 0x9E, 0xE9, 0x47, 0x1E, 0x17, 0xCB, 0x69, 0x1B,
  31065. 0x2A, 0x35, 0x37, 0x10, 0xC9, 0xFF, 0xA4, 0xE5,
  31066. 0x17, 0x81, 0x12, 0x02, 0x77, 0x64, 0xEB, 0x7D,
  31067. 0xE8, 0x09, 0xC3, 0xE1, 0xF1, 0xFA, 0x41, 0x78,
  31068. 0xA5, 0xD4, 0xDC, 0x9E, 0xE2, 0x78, 0x57, 0xEF,
  31069. 0xF2, 0x6B, 0x91, 0x71, 0x1F, 0xC1, 0x44, 0xD5,
  31070. 0xA7, 0x75, 0xB8, 0xB5, 0x0D, 0x5D, 0xB9, 0x39,
  31071. 0xBA, 0x32, 0x07, 0x68, 0x0C, 0x24, 0x2F, 0xC8,
  31072. 0x21, 0x94, 0x7F, 0x93, 0x4C, 0x8D, 0xAE, 0xE2,
  31073. 0x03, 0x56, 0x3D, 0x28, 0x60, 0x6B, 0xE6, 0x24,
  31074. 0xA3, 0x29, 0x01, 0x93, 0x2D, 0xAE, 0x85, 0x71,
  31075. 0x2A, 0xF6, 0xC8, 0x01, 0x60, 0x26, 0x92, 0x7E,
  31076. 0x9B, 0x81, 0x29, 0x57, 0x4B, 0xE3, 0xCB, 0x1E,
  31077. 0x95, 0x33, 0x2B, 0x05, 0x27, 0x07, 0xAC, 0x8A,
  31078. 0xA8, 0xF4, 0x35, 0xE8, 0x8B, 0x7E, 0x56, 0x8D,
  31079. 0x49, 0x87, 0xC6, 0xAC, 0x0E, 0x90, 0x2B, 0x06,
  31080. 0x09, 0xA0, 0x2D, 0x91, 0xB3, 0xF5, 0xFD, 0x3F,
  31081. 0xD9, 0x01, 0xDD, 0xD0, 0xDB, 0x98, 0x73, 0xBD,
  31082. 0x7C, 0x71, 0xED, 0x92, 0x1D, 0x45, 0x77, 0xA7,
  31083. 0x8C, 0x4F, 0xCC, 0x9B, 0xF0, 0x75, 0x20, 0x3D,
  31084. 0x38, 0xF5, 0xE7, 0x6E, 0x74, 0xF2, 0x77, 0x48,
  31085. 0x4E, 0x05, 0x7B, 0x61, 0x89, 0x00, 0x41, 0x31,
  31086. 0xB0, 0xC9, 0xB1, 0xA1, 0x55, 0x29, 0x4D, 0x1C,
  31087. 0xD3, 0xD5, 0x20, 0x8E, 0x26, 0x69, 0x01, 0xD7,
  31088. 0xD3, 0x14, 0xFA, 0xCC, 0xE7, 0xE2, 0xAA, 0x58,
  31089. 0x45, 0x83, 0xA1, 0x1E, 0x4D, 0x7C, 0x21, 0xB9,
  31090. 0x4A, 0x32, 0xE5, 0x08, 0xED, 0xDB, 0xBD, 0x7A,
  31091. 0x65, 0xAA, 0x86, 0xB4, 0xFD, 0xFA, 0x6B, 0xC2,
  31092. 0x85, 0xD4, 0xCF, 0xF5, 0x39, 0x26, 0xC7, 0x17,
  31093. 0x3F, 0xBE, 0x1F, 0x89, 0xCC, 0x30, 0x32, 0x34,
  31094. 0xB8, 0x78, 0xC6, 0xB8, 0x10, 0x1F, 0x58, 0xAC,
  31095. 0x8D, 0x3E, 0x5E, 0x1B, 0xF5, 0xAB, 0x6B, 0x26,
  31096. 0x29, 0x7C, 0xC9, 0x7B, 0x95, 0x95, 0x4A, 0xAB,
  31097. 0xDB, 0x25, 0xBE, 0x00, 0x8A, 0x3F, 0x47, 0xE5,
  31098. 0x64, 0x87, 0xB0, 0x0D, 0x3D, 0xED, 0xA8, 0x90,
  31099. 0xD9, 0x2C, 0x83, 0x95, 0x7F, 0xEA, 0xC6, 0xB8,
  31100. 0x29, 0x1A, 0xF6, 0x59, 0x59, 0xE1, 0xD1, 0xFC,
  31101. 0xA3, 0xBD, 0x19, 0x6E, 0x9F, 0xC9, 0xE6, 0x7E,
  31102. 0x06, 0x07, 0x09, 0x48, 0x22, 0xE5, 0xB4, 0x19,
  31103. 0x1D, 0xB9, 0x68, 0x24, 0xB9, 0xF0, 0x3F, 0x2E,
  31104. 0xF5, 0x7F, 0x52, 0x38, 0xBA, 0x7E, 0x1E, 0x84,
  31105. 0xED, 0x55, 0xB7, 0xDF, 0xF3, 0xD6, 0xC2, 0xC1,
  31106. 0x27, 0x36, 0x92, 0xA9, 0xA1, 0x92, 0x72, 0x16,
  31107. 0x61, 0x30, 0xDB, 0x89, 0xFC, 0x67, 0xDC, 0x94,
  31108. 0xDB, 0x61, 0x4E, 0x3E, 0x82, 0xBA, 0x3A, 0x35,
  31109. 0x12, 0xB0, 0x12, 0xD5, 0x1F, 0xB4, 0x86, 0xB5,
  31110. 0xA3, 0x15, 0x0B, 0x78, 0xE7, 0x24, 0xE2, 0xA1,
  31111. 0x2D, 0xE0, 0x7D, 0x86, 0x71, 0xFB, 0xA2, 0xDA,
  31112. 0x7F, 0xD5, 0xD1, 0x47, 0x20, 0x8F, 0xC3, 0xAF,
  31113. 0x65, 0x3E, 0x65, 0x20, 0xFC, 0x40, 0x87, 0x1A,
  31114. 0xF2, 0x17, 0x7E, 0x65, 0xCB, 0xD0, 0xEA, 0xF3,
  31115. 0x04, 0x21, 0x7B, 0x36, 0x7A, 0x66, 0x5F, 0x22,
  31116. 0x4C, 0xAE, 0xDF, 0xE9, 0x30, 0x06, 0xAC, 0x1E,
  31117. 0x14, 0xBC, 0xD6, 0x7A, 0x88, 0xD1, 0x71, 0xF3,
  31118. 0xD8, 0xF3, 0xE3, 0x58, 0xA7, 0x19, 0x26, 0xBA,
  31119. 0x3E, 0x5C, 0x23, 0x9A, 0x53, 0x12, 0x63, 0xEC,
  31120. 0x94, 0x37, 0xBF, 0x2A, 0x03, 0x3B, 0x8B, 0x55,
  31121. 0xB2, 0xC0, 0xCB, 0x6E, 0x7E, 0x97, 0x31, 0x6E,
  31122. 0x22, 0xDF, 0x77, 0xCA, 0xD9, 0x10, 0xD2, 0x0E,
  31123. 0xEC, 0xE1, 0xC5, 0x09, 0x10, 0xA5, 0xCC, 0x32,
  31124. 0xAD, 0xAB, 0x09, 0x37, 0x75, 0x50, 0xF9, 0x2D,
  31125. 0x5B, 0xB1, 0xF4, 0xC0, 0x7F, 0x4A, 0x28, 0x22,
  31126. 0x33, 0x8E, 0x2C, 0xFF, 0x53, 0x48, 0xDF, 0x77,
  31127. 0xCF, 0x8E, 0xF8, 0xE6, 0x65, 0x7D, 0xED, 0x1E,
  31128. 0x0C, 0xE0, 0x58, 0xE3, 0xCC, 0xFB, 0xF3, 0x9B,
  31129. 0x3F, 0x16, 0x6E, 0x30, 0x3D, 0x33, 0xC3, 0x55,
  31130. 0x6C, 0x9A, 0xC8, 0xEC, 0xB3, 0xDF, 0x7C, 0x74,
  31131. 0xAB, 0x36, 0xD0, 0xF2, 0x79, 0x44, 0x41, 0xBA,
  31132. 0x98, 0x08, 0x82, 0x7B, 0x57, 0x8F, 0xB5, 0xC2,
  31133. 0x9E, 0x49, 0x4E, 0x21, 0x53, 0x9A, 0xD3, 0xAB,
  31134. 0x2B, 0x41, 0xBF, 0x16, 0x1D, 0x7F, 0x69, 0x58,
  31135. 0x9D, 0x45, 0x24, 0xC5, 0x4C, 0x89, 0xB4, 0x86,
  31136. 0xF7, 0x5D, 0x25, 0x2F, 0x54, 0x1C, 0xC6, 0x3B,
  31137. 0x9E, 0x70, 0x6D, 0x64, 0xA1, 0x28, 0x9A, 0x23,
  31138. 0x06, 0xC5, 0x95, 0x36, 0x3C, 0xB6, 0xFB, 0xEF,
  31139. 0x0A, 0x1B, 0x5B, 0x17, 0xAB, 0x5B, 0x17, 0x94,
  31140. 0xBF, 0x27, 0x03, 0x6F, 0x64, 0xEA, 0xF0, 0xBD,
  31141. 0x43, 0x0D, 0xD5, 0x8D, 0x80, 0x01, 0x0C, 0xCD,
  31142. 0xAD, 0xA4, 0xA5, 0xA3, 0xA1, 0xE4, 0x1A, 0x6F,
  31143. 0xBF, 0x12, 0x9D, 0x73, 0x77, 0x9A, 0x37, 0xAE,
  31144. 0x5C, 0x8D, 0x68, 0x41, 0xA9, 0x99, 0x3C, 0x51,
  31145. 0xE3, 0x64, 0xE0, 0x4F, 0xAC, 0x8E, 0x25, 0xA4,
  31146. 0xE6, 0x87, 0x2F, 0x6C, 0x86, 0x0F, 0xA2, 0x65,
  31147. 0xC1, 0xC4, 0x42, 0x6A, 0xD9, 0xC2, 0x1D, 0x26,
  31148. 0xDA, 0x8C, 0x27, 0x85, 0x46, 0xAD, 0xCD, 0x83,
  31149. 0x1F, 0x2B, 0x8B, 0x26, 0xD4, 0xE1, 0xF6, 0x70,
  31150. 0x62, 0x3D, 0x95, 0xC8, 0x36, 0x2D, 0xA6, 0x62,
  31151. 0xD1, 0xFF, 0x0A, 0xB6, 0x87, 0x50, 0x3F, 0x32,
  31152. 0x8D, 0xE0, 0x95, 0x81, 0x0E, 0xDE, 0x12, 0xB4,
  31153. 0x9E, 0xAD, 0x15, 0x33, 0x51, 0x95, 0x58, 0xC1,
  31154. 0xE9, 0x40, 0xB4, 0x6E, 0x4E, 0xDB, 0x02, 0x7B,
  31155. 0xE9, 0xDA, 0x20, 0x39, 0xB2, 0x5D, 0xCF, 0x73,
  31156. 0x57, 0xE1, 0x9E, 0x54, 0x16, 0xAE, 0x26, 0x8C,
  31157. 0x14, 0xFB, 0x3A, 0x8B, 0xAB, 0xCB, 0x3D, 0x23,
  31158. 0xF7, 0x0C, 0xC9, 0xD5, 0x96, 0x81, 0xC5, 0xD8,
  31159. 0x33, 0xAC, 0x22, 0xE6, 0x53, 0xD8, 0x6E, 0x22,
  31160. 0xCE, 0x82, 0x25, 0x40, 0x75, 0x5D, 0x8D, 0x24,
  31161. 0x3C, 0x15, 0x21, 0x3D, 0x07, 0x6C, 0x6B, 0x26,
  31162. 0x43, 0x6D, 0xDC, 0x07, 0xC7, 0xE0, 0x01, 0x34,
  31163. 0x7B, 0x0C, 0xB8, 0x78, 0x3D, 0xFE, 0xFE, 0xDF,
  31164. 0x27, 0x5F, 0xEC, 0x47, 0x92, 0x68, 0x67, 0x34,
  31165. 0x00, 0x7F, 0x0F, 0xF8, 0x54, 0x08, 0x11, 0xC2,
  31166. 0xAF, 0xE6, 0xCA, 0x15, 0x14, 0x20, 0x53, 0x2F,
  31167. 0xA5, 0x52, 0x6A, 0x10, 0x74, 0xC3, 0xD7, 0x89,
  31168. 0xF2, 0x93, 0x2D, 0xE4, 0x2E, 0x3A, 0xCF, 0xBF,
  31169. 0x94, 0x76, 0x0F, 0x42, 0x6D, 0x96, 0xCF, 0x03,
  31170. 0x3F, 0xA4, 0x9E, 0x2F, 0x45, 0x8F, 0x9A, 0x9C,
  31171. 0x2E, 0x71, 0xDA, 0xCF, 0xE0, 0x09, 0xDD, 0x9C,
  31172. 0x3F, 0x3C, 0x8A, 0xB3, 0x28, 0x2D, 0x6F, 0x38,
  31173. 0x3B, 0x98, 0x1C, 0x82, 0xD6, 0x36, 0x4F, 0x0E,
  31174. 0x4B, 0xDB, 0x2A, 0xF6, 0xA9, 0x5B, 0xA6, 0x1F,
  31175. 0x47, 0x41, 0x50, 0xCA, 0xD7, 0x23, 0x3F, 0x89,
  31176. 0x03, 0xDF, 0x97, 0x2D, 0xBB, 0x03, 0x28, 0xC0,
  31177. 0xCB, 0x9D, 0x0C, 0xCB, 0xEF, 0x88, 0x3D, 0x2E,
  31178. 0x6A, 0xDD, 0x18, 0x0E, 0xCA, 0x1B, 0x66, 0x2F,
  31179. 0xC1, 0xD2, 0xDB, 0xBD, 0xDB, 0x36, 0x34, 0x21,
  31180. 0x9E, 0x1E, 0xFF, 0x38, 0xB1, 0xE5, 0x28, 0x75,
  31181. 0x35, 0x6C, 0x03, 0xEA, 0xDE, 0x94, 0x20, 0x55,
  31182. 0xF4, 0x83, 0x50, 0x4B, 0xBB, 0xCB, 0x43, 0x02,
  31183. 0xA4, 0x17, 0xCF, 0x6D, 0x32, 0x8E, 0xD7, 0x93,
  31184. 0xB1, 0xA3, 0xC0, 0x96, 0x9B, 0x7B, 0x34, 0x18,
  31185. 0xF5, 0x0A, 0xB3, 0x9F, 0x83, 0xC5, 0x66, 0x6C,
  31186. 0x90, 0xE3, 0x83, 0x56, 0xF7, 0xF9, 0xD4, 0x94,
  31187. 0xA6, 0xDC, 0xB6, 0x3D, 0x67, 0xC3, 0x4E, 0x3D,
  31188. 0x14, 0xA4, 0xE1, 0x55, 0x96, 0x49, 0x79, 0x26,
  31189. 0xC8, 0x56, 0x8D, 0x8E, 0xC3, 0xDB, 0xD9, 0xC2,
  31190. 0xE8, 0x2C, 0x38, 0x5B, 0xCF, 0xB8, 0xD9, 0x67,
  31191. 0x48, 0x63, 0xBD, 0x4F, 0xBF, 0x17, 0x57, 0xDB,
  31192. 0x44, 0x7B, 0xF8, 0x04, 0xAE, 0x95, 0x01, 0x47,
  31193. 0xC9, 0x1F, 0xBF, 0x9A, 0xA1, 0x78, 0x91, 0x04,
  31194. 0x4C, 0xCA, 0xA7, 0x3B, 0x45, 0x52, 0x85, 0x97,
  31195. 0x46, 0x2C, 0xED, 0x75, 0x1D, 0x01, 0x5E, 0xBB,
  31196. 0xA9, 0xE2, 0xB7, 0xCD, 0xCB, 0xE6, 0xDC, 0x05,
  31197. 0xAA, 0x9E, 0xAE, 0x0C, 0x86, 0x84, 0x8A, 0x34,
  31198. 0x75, 0xBB, 0x1C, 0x57, 0x44, 0xF5, 0x90, 0x3E,
  31199. 0xE4, 0xA8, 0x42, 0xA4, 0x69, 0xCC, 0x18, 0x12,
  31200. 0x71, 0xF2, 0x45, 0xAD, 0x70, 0xD0, 0x2A, 0x48,
  31201. 0x37, 0x86, 0x3B, 0x29, 0x6B, 0x4A, 0xDB, 0x4E,
  31202. 0x8D, 0x03, 0xD8, 0x2B, 0x64, 0xAA, 0x11, 0xDD,
  31203. 0x31, 0xCD, 0xF2, 0x1E, 0xDF, 0x1D, 0xFE, 0x32,
  31204. 0x76, 0xC4, 0xDB, 0xC8, 0x77, 0xE3, 0x5B, 0x15,
  31205. 0xFB, 0x28, 0x35, 0xEC, 0x3A, 0x1C, 0x45, 0x31,
  31206. 0x68, 0xA3, 0x8C, 0xA8, 0xE5, 0x63, 0xCF, 0x3E,
  31207. 0x9A, 0x00, 0x73, 0x6C, 0xD5, 0xCF, 0xBD, 0x28,
  31208. 0x41, 0xD1, 0x0F, 0x94, 0xAD, 0x55, 0x79, 0x9C,
  31209. 0x29, 0x27, 0xE5, 0x46, 0x1B, 0x28, 0xBA, 0xC5,
  31210. 0x17, 0x4D, 0x0C, 0xE3, 0xF8, 0xF7, 0xCD, 0x76,
  31211. 0x09, 0xFB, 0xC8, 0xDA, 0x0C, 0x38, 0xCC, 0x21,
  31212. 0x69, 0x5C, 0xED, 0xAD, 0x12, 0xF8, 0xD2, 0xE6,
  31213. 0x49, 0x51, 0xA8, 0x99, 0x6E, 0x51, 0x0D, 0x6D,
  31214. 0x52, 0x79, 0x7C, 0x5B, 0xA0, 0xEB, 0x4A, 0xFA,
  31215. 0x6B, 0xF2, 0xCC, 0x43, 0xDA, 0x09, 0xDE, 0x31,
  31216. 0x79, 0xE8, 0x99, 0xBD, 0x71, 0x88, 0xB3, 0x2A,
  31217. 0x98, 0xA4, 0x99, 0xD3, 0x72, 0xF3, 0x70, 0x7C,
  31218. 0xED, 0x47, 0x9B, 0x09, 0x81, 0xCB, 0x50, 0xC0,
  31219. 0xC0, 0x53, 0x9C, 0xF7, 0xE3, 0x10, 0x0B, 0x72,
  31220. 0x0E, 0x46, 0x66, 0x52, 0xA4, 0xF4, 0x99, 0xC2,
  31221. 0xBA, 0x3A, 0x17, 0xF5, 0x23, 0x22, 0x68, 0x73,
  31222. 0x0B, 0x96, 0x2B, 0xC5, 0x72, 0xC0, 0xDE, 0x96,
  31223. 0xE8, 0xC9, 0xE2, 0x8F, 0x7E, 0x35, 0x32, 0xC2,
  31224. 0x22, 0x41, 0x96, 0xAA, 0x9E, 0x27, 0x68, 0x8D,
  31225. 0xD0, 0x50, 0xD7, 0xCB, 0x78, 0x54, 0xFB, 0x3C,
  31226. 0x35, 0xF9, 0xC6, 0x2E, 0xFB, 0x10, 0xDA, 0x84,
  31227. 0x83, 0x3F, 0x29, 0xBB, 0x1B, 0xE5, 0xEF, 0x3B,
  31228. 0x53, 0x36, 0x38, 0xEE, 0xF7, 0x43, 0xD8, 0x11,
  31229. 0x9D, 0xDC, 0x29, 0x0B, 0xDF, 0x08, 0xB6, 0xF0,
  31230. 0xF9, 0xE4, 0xE1, 0xE1, 0x34, 0x46, 0xC5, 0x3E,
  31231. 0xD6, 0x98, 0x05, 0xDA, 0x26, 0x90, 0x8A, 0x15,
  31232. 0xDF, 0x1C, 0x48, 0xE0, 0x09, 0xEC, 0x12, 0x53,
  31233. 0xBD, 0x5A, 0x58, 0x98, 0xEB, 0xB5, 0x12, 0x1C,
  31234. 0xC2, 0x49, 0x04, 0xC8, 0xB1, 0x0E, 0x24, 0xE6,
  31235. 0x80, 0xE5, 0x65, 0x98, 0x50, 0x76, 0xFD, 0xA1,
  31236. 0x1D, 0x13, 0xFF, 0xDF, 0xA4, 0xDB, 0x28, 0xAC,
  31237. 0x9F, 0x0A, 0xEA, 0x2F, 0x81, 0xFD, 0x7E, 0xD4,
  31238. 0xDC, 0xA8, 0xD3, 0xB2, 0xE3, 0x84, 0x8B, 0x4D,
  31239. 0x60, 0x46, 0xF6, 0xE0, 0xDE, 0x3A, 0x4F, 0x68,
  31240. 0x3F, 0x25, 0xE0, 0x60, 0x5E, 0x84, 0xB3, 0x6F,
  31241. 0x48, 0x3C, 0x40, 0x4E, 0xF8, 0x99, 0xCB, 0x3F,
  31242. 0xCC, 0xBE, 0x8C, 0xB2, 0xA6, 0xF0, 0xA7, 0xE1,
  31243. 0x0B, 0x19, 0x48, 0xCD, 0x4F, 0x93, 0xF1, 0x81,
  31244. 0x55, 0x5F, 0x66, 0x1D, 0x31, 0xD4, 0x26, 0x80,
  31245. 0x8B, 0xBF, 0x9F, 0x66, 0xFD, 0x60, 0xD6, 0x49,
  31246. 0x26, 0x9C, 0xA3, 0xFE, 0x99, 0x1B, 0x22, 0x42,
  31247. 0x8C, 0x37, 0xAD, 0x2A, 0x08, 0x68, 0x0F, 0x74,
  31248. 0x7C, 0xC0, 0x36, 0x0C, 0xCD, 0x37, 0x3D, 0xC6,
  31249. 0xA9, 0xF4, 0x3A, 0x66, 0x47, 0x0E, 0x01, 0x4E,
  31250. 0x72, 0xB3, 0xD8, 0xC3, 0x8E, 0x02, 0x04, 0x42,
  31251. 0xD8, 0xAA, 0xB9, 0x74, 0xE6, 0x04, 0x93, 0x74,
  31252. 0x14, 0x5B, 0x04, 0xCB, 0x7F, 0x30, 0x44, 0xAA,
  31253. 0xC1, 0xEF, 0xDA, 0xB2, 0xA1, 0x8B, 0xB4, 0x64,
  31254. 0xD4, 0xF2, 0xF2, 0xD8, 0x14, 0x39, 0x74, 0xC9,
  31255. 0x5E, 0xEE, 0x85, 0x6D, 0x59, 0xEC, 0x00, 0x28,
  31256. 0x8E, 0xD4, 0x3F, 0xF5, 0xCC, 0x88, 0x03, 0x00,
  31257. 0x6C, 0x99, 0x55, 0x14, 0xA2, 0xCC, 0x9C, 0xA6,
  31258. 0x22, 0xB6, 0x1B, 0xCD, 0x75, 0xEC, 0x51, 0xC2,
  31259. 0x02, 0xA9, 0x17, 0x10, 0x5B, 0x4A, 0x4B, 0xED,
  31260. 0x1B, 0x80, 0x14, 0x68, 0x31, 0xDC, 0xED, 0x07,
  31261. 0xEF, 0xD2, 0xED, 0x25, 0x73, 0x9F, 0x54, 0x09,
  31262. 0x69, 0x11, 0xB1, 0x50, 0xD3, 0x07, 0x7C, 0xCD,
  31263. 0x73, 0x1A, 0x03, 0x61, 0x68, 0x27, 0x25, 0xD5,
  31264. 0x38, 0x03, 0xF8, 0xFC, 0xEA, 0xA8, 0x39, 0x19,
  31265. 0x29, 0x1E, 0xDB, 0x44, 0x93, 0xEC, 0x84, 0xCC,
  31266. 0xE1, 0xD0, 0xF8, 0x2A, 0x67, 0x92, 0x36, 0xEA,
  31267. 0xD1, 0x00, 0x2A, 0xE8, 0x01, 0x8C, 0xAC, 0x9F,
  31268. 0xDB, 0xD2, 0x46, 0xFF, 0x09, 0x3D, 0x80, 0x3C,
  31269. 0x0D, 0xE3, 0x32, 0x6A, 0x57, 0x90, 0x7B, 0x0D,
  31270. 0xD6, 0xB0, 0x1D, 0x08, 0x14, 0x58, 0xC7, 0x57,
  31271. 0x28, 0xC6, 0x00, 0x82, 0x99, 0x28, 0x89, 0x0A,
  31272. 0x56, 0xAA, 0xAF, 0xEF, 0xCF, 0x74, 0x23, 0xB7,
  31273. 0x0A, 0x6D, 0x86, 0xB4, 0x15, 0xB8, 0x35, 0x8D,
  31274. 0xD0, 0x44, 0xAB, 0xEE, 0x00, 0xB9, 0xC9, 0x79,
  31275. 0x5F, 0xC8, 0xF6, 0x1A, 0x64, 0x68, 0x6D, 0xF5,
  31276. 0xF8, 0x76, 0xA8, 0xF3, 0x30, 0x61, 0x59, 0x9A,
  31277. 0xE8, 0x30, 0xF7, 0xEB, 0x4C, 0x4B, 0xFF, 0x87,
  31278. 0x5F, 0x4A, 0x93, 0x6C, 0x40, 0x3C, 0x5D, 0x16,
  31279. 0x0D, 0xE5, 0xD3, 0x3C, 0xAE, 0xE4, 0x0F, 0xB7,
  31280. 0x18, 0xDD, 0xA4, 0x47, 0x8A, 0xC6, 0xF5, 0x1C,
  31281. 0x59, 0xC2, 0x15, 0x52, 0x54, 0xBD, 0x77, 0x67,
  31282. 0x11, 0x18, 0x41, 0x1E, 0x26, 0x09, 0xD0, 0x00,
  31283. 0x30, 0x6F, 0xC9, 0x50, 0x70, 0x04, 0xA3, 0x1E,
  31284. 0x89, 0x57, 0xEA, 0x40, 0xC2, 0x56, 0x4B, 0x83,
  31285. 0xC3, 0xAB, 0xB7, 0x1A, 0x87, 0xC1, 0x1B, 0xD1,
  31286. 0x8D, 0x78, 0x91, 0xC4, 0x49, 0xDB, 0xBE, 0x79,
  31287. 0xB4, 0xA4, 0xFB, 0x04, 0x83, 0x07, 0xCE, 0x0E,
  31288. 0x81, 0x2B, 0x2C, 0x68, 0xEC, 0xAB, 0x77, 0xFD,
  31289. 0x11, 0x11, 0x52, 0x6A, 0xB0, 0x81, 0x73, 0x06,
  31290. 0xCE, 0xBC, 0xB0, 0x49, 0x7C, 0x55, 0x24, 0x31,
  31291. 0xCE, 0x15, 0xE4, 0xAB, 0x52, 0x28, 0x3F, 0x67,
  31292. 0x94, 0x80, 0xD6, 0x9D, 0xDD, 0xE1, 0xF2, 0x57,
  31293. 0x9C, 0xFD, 0xBE, 0x0B, 0xCA, 0x95, 0xFC, 0x5B,
  31294. 0x2D, 0xB0, 0xC5, 0xCC, 0x76, 0xA3, 0x19, 0x50,
  31295. 0xF5, 0x11, 0x6A, 0xAE, 0x5F, 0x02, 0xD4, 0x67,
  31296. 0x10, 0xE4, 0x25, 0x7A, 0x75, 0xFD, 0xED, 0xF2,
  31297. 0xF4, 0x7C, 0xE3, 0x7C, 0x20, 0x3E, 0x7F, 0x24,
  31298. 0xD3, 0xC9, 0x17, 0x97, 0x13, 0xC5, 0xD8, 0x07,
  31299. 0xC2, 0x96, 0x14, 0x9A, 0x75, 0xCC, 0xB4, 0x44,
  31300. 0xF0, 0xC6, 0xF6, 0xAB, 0xDD, 0x2D, 0xBB, 0x29,
  31301. 0x85, 0xFE, 0x26, 0x74, 0x82, 0x85, 0x8A, 0x1E
  31302. };
  31303. #endif /* WOLFSSL_NO_ML_DSA_65 */
  31304. #ifndef WOLFSSL_NO_ML_DSA_87
  31305. static const byte seed_87[] = {
  31306. 0x38, 0x35, 0x9F, 0xBC, 0xD7, 0x95, 0x82, 0xCF,
  31307. 0xFE, 0x60, 0x9E, 0x13, 0x7E, 0xE2, 0xEF, 0xE8,
  31308. 0xA8, 0xDB, 0xCB, 0xAD, 0x18, 0xBA, 0x92, 0xBB,
  31309. 0x43, 0x3A, 0xB4, 0xF0, 0x9B, 0x49, 0x29, 0x9D
  31310. };
  31311. static const byte pk_87[] = {
  31312. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  31313. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  31314. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  31315. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  31316. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  31317. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  31318. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  31319. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  31320. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  31321. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  31322. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  31323. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  31324. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  31325. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  31326. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  31327. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  31328. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  31329. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  31330. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  31331. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  31332. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  31333. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  31334. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  31335. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  31336. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  31337. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  31338. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  31339. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  31340. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  31341. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  31342. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  31343. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  31344. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  31345. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  31346. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  31347. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  31348. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  31349. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  31350. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  31351. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  31352. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  31353. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  31354. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  31355. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  31356. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  31357. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  31358. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  31359. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  31360. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  31361. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  31362. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  31363. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  31364. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  31365. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  31366. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  31367. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  31368. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  31369. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  31370. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  31371. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  31372. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  31373. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  31374. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  31375. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  31376. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  31377. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  31378. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  31379. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  31380. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  31381. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  31382. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  31383. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  31384. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  31385. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  31386. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  31387. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  31388. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  31389. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  31390. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  31391. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  31392. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  31393. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  31394. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  31395. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  31396. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  31397. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  31398. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  31399. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  31400. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  31401. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  31402. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  31403. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  31404. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  31405. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  31406. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  31407. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  31408. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  31409. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  31410. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  31411. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  31412. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  31413. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  31414. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  31415. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  31416. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  31417. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  31418. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  31419. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  31420. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  31421. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  31422. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  31423. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  31424. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  31425. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  31426. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  31427. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  31428. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  31429. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  31430. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  31431. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  31432. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  31433. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  31434. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  31435. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  31436. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  31437. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  31438. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  31439. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  31440. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  31441. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  31442. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  31443. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  31444. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  31445. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  31446. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  31447. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  31448. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  31449. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  31450. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  31451. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  31452. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  31453. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  31454. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  31455. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  31456. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  31457. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  31458. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  31459. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  31460. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  31461. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  31462. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  31463. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  31464. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  31465. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  31466. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  31467. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  31468. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  31469. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  31470. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  31471. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  31472. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  31473. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  31474. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  31475. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  31476. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  31477. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  31478. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  31479. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  31480. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  31481. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  31482. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  31483. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  31484. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  31485. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  31486. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  31487. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  31488. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  31489. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  31490. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  31491. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  31492. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  31493. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  31494. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  31495. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  31496. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  31497. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  31498. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  31499. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  31500. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  31501. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  31502. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  31503. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  31504. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  31505. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  31506. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  31507. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  31508. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  31509. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  31510. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  31511. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  31512. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  31513. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  31514. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  31515. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  31516. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  31517. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  31518. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  31519. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  31520. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  31521. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  31522. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  31523. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  31524. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  31525. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  31526. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  31527. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  31528. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  31529. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  31530. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  31531. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  31532. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  31533. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  31534. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  31535. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  31536. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  31537. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  31538. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  31539. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  31540. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  31541. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  31542. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  31543. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  31544. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  31545. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  31546. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  31547. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  31548. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  31549. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  31550. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  31551. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  31552. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  31553. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  31554. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  31555. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  31556. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  31557. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  31558. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  31559. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  31560. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  31561. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  31562. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  31563. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  31564. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  31565. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  31566. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  31567. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  31568. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  31569. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  31570. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  31571. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  31572. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  31573. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  31574. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  31575. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  31576. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  31577. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  31578. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  31579. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  31580. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  31581. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  31582. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  31583. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  31584. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  31585. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  31586. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  31587. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  31588. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  31589. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  31590. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  31591. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  31592. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  31593. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  31594. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  31595. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  31596. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  31597. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  31598. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  31599. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  31600. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  31601. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  31602. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  31603. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  31604. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  31605. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  31606. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  31607. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  31608. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  31609. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  31610. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  31611. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  31612. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  31613. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  31614. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  31615. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  31616. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  31617. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  31618. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  31619. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  31620. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  31621. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  31622. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  31623. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  31624. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  31625. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  31626. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  31627. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  31628. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  31629. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  31630. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  31631. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  31632. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  31633. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  31634. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  31635. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  31636. };
  31637. static const byte sk_87[] = {
  31638. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  31639. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  31640. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  31641. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  31642. 0x3B, 0x9A, 0xC2, 0xC1, 0x42, 0x2A, 0x1A, 0xE8,
  31643. 0x02, 0xDD, 0xD7, 0x46, 0x4D, 0x3F, 0x32, 0x72,
  31644. 0x9A, 0x3C, 0x7D, 0xE8, 0x94, 0xD5, 0x06, 0xAC,
  31645. 0xAD, 0x25, 0xCE, 0xB3, 0x72, 0xEA, 0x31, 0x49,
  31646. 0xC9, 0x87, 0x80, 0xDC, 0xD1, 0x31, 0x4B, 0xAA,
  31647. 0x29, 0xB9, 0xB8, 0x07, 0x75, 0x4C, 0x47, 0xDE,
  31648. 0x5D, 0xCA, 0x95, 0x40, 0x64, 0xF2, 0x85, 0x28,
  31649. 0xB8, 0x15, 0xFE, 0x27, 0xB7, 0x9A, 0xC5, 0x06,
  31650. 0xB3, 0xAD, 0x76, 0x29, 0xD2, 0xC9, 0x71, 0xAB,
  31651. 0x8F, 0x28, 0x2E, 0x0C, 0x6E, 0x7E, 0x55, 0x48,
  31652. 0xEE, 0x0E, 0x11, 0x32, 0x42, 0xB7, 0xA0, 0xE0,
  31653. 0x64, 0xA6, 0xDB, 0xCE, 0x30, 0xC5, 0x61, 0x9B,
  31654. 0x19, 0x80, 0x08, 0x89, 0xA0, 0x44, 0x04, 0xB5,
  31655. 0x00, 0x13, 0xC0, 0x88, 0xC1, 0x30, 0x29, 0x62,
  31656. 0x12, 0x4C, 0xD3, 0xB4, 0x91, 0x0A, 0x35, 0x2C,
  31657. 0x43, 0x12, 0x31, 0x19, 0x99, 0x65, 0x22, 0x18,
  31658. 0x52, 0x02, 0xC3, 0x85, 0x23, 0x44, 0x0D, 0x90,
  31659. 0x24, 0x4A, 0x1A, 0x30, 0x22, 0x44, 0x28, 0x61,
  31660. 0x81, 0x06, 0x29, 0x18, 0x97, 0x68, 0x0A, 0x20,
  31661. 0x09, 0x08, 0x32, 0x6A, 0x44, 0xA4, 0x4C, 0x44,
  31662. 0x90, 0x21, 0x8A, 0x16, 0x68, 0x9A, 0xA8, 0x51,
  31663. 0x1A, 0xA5, 0x2C, 0x62, 0x46, 0x8D, 0x04, 0xC3,
  31664. 0x40, 0xD3, 0x86, 0x28, 0x60, 0xA4, 0x60, 0x13,
  31665. 0x18, 0x70, 0x84, 0x94, 0x8C, 0x63, 0xC0, 0x44,
  31666. 0x04, 0xA9, 0x28, 0x20, 0x08, 0x20, 0x43, 0x16,
  31667. 0x2A, 0x23, 0x29, 0x2D, 0x1A, 0xB1, 0x29, 0x48,
  31668. 0xB6, 0x09, 0x21, 0x88, 0x31, 0x00, 0xC5, 0x30,
  31669. 0x00, 0xC4, 0x8C, 0xD9, 0x82, 0x68, 0xE1, 0x30,
  31670. 0x4C, 0x63, 0x32, 0x45, 0x0C, 0x32, 0x86, 0x18,
  31671. 0x08, 0x31, 0x91, 0x98, 0x0D, 0x10, 0xB8, 0x70,
  31672. 0x9B, 0x30, 0x22, 0x64, 0x04, 0x08, 0x93, 0xA4,
  31673. 0x8C, 0x21, 0xC9, 0x70, 0x0C, 0x35, 0x71, 0x5B,
  31674. 0x00, 0x0D, 0x14, 0x31, 0x22, 0xCC, 0x98, 0x10,
  31675. 0x21, 0x04, 0x80, 0x9B, 0x28, 0x64, 0x1C, 0x30,
  31676. 0x80, 0x21, 0x30, 0x71, 0x18, 0x33, 0x50, 0x24,
  31677. 0x25, 0x44, 0x08, 0x17, 0x8C, 0xC0, 0x08, 0x48,
  31678. 0x84, 0x44, 0x90, 0x48, 0x98, 0x30, 0xCA, 0x44,
  31679. 0x00, 0x09, 0x19, 0x51, 0x19, 0x23, 0x0C, 0x52,
  31680. 0x20, 0x0E, 0x49, 0x06, 0x32, 0x1C, 0x15, 0x4E,
  31681. 0x19, 0x48, 0x85, 0x13, 0x25, 0x49, 0xA3, 0x00,
  31682. 0x04, 0x08, 0x15, 0x6D, 0x20, 0x41, 0x0C, 0xDA,
  31683. 0x42, 0x52, 0xC1, 0x34, 0x8C, 0x00, 0x31, 0x69,
  31684. 0x43, 0x82, 0x24, 0x64, 0x94, 0x6D, 0x1C, 0x81,
  31685. 0x11, 0x01, 0x96, 0x21, 0x4B, 0x02, 0x00, 0xCA,
  31686. 0x28, 0x84, 0xCC, 0x46, 0x64, 0x51, 0x18, 0x6A,
  31687. 0x18, 0x10, 0x00, 0xA4, 0x98, 0x21, 0x60, 0xB0,
  31688. 0x68, 0x03, 0x94, 0x6C, 0x94, 0x48, 0x51, 0x80,
  31689. 0x40, 0x46, 0x92, 0x22, 0x2C, 0x23, 0x44, 0x69,
  31690. 0x98, 0x26, 0x4D, 0x1C, 0x01, 0x08, 0x52, 0x02,
  31691. 0x20, 0x8A, 0xA6, 0x08, 0x0A, 0x31, 0x61, 0x93,
  31692. 0x40, 0x0E, 0x9C, 0xC8, 0x11, 0x81, 0x32, 0x2E,
  31693. 0x21, 0x15, 0x84, 0x84, 0xC2, 0x41, 0x00, 0x22,
  31694. 0x72, 0x54, 0x22, 0x62, 0x58, 0x06, 0x92, 0x48,
  31695. 0x48, 0x44, 0x11, 0x27, 0x04, 0x04, 0xC0, 0x11,
  31696. 0x92, 0x82, 0x45, 0xA1, 0xC6, 0x8C, 0xE3, 0x32,
  31697. 0x66, 0xC1, 0x38, 0x72, 0x5A, 0x86, 0x01, 0x0C,
  31698. 0xC9, 0x90, 0x84, 0x34, 0x08, 0x58, 0xA8, 0x60,
  31699. 0x80, 0xC0, 0x70, 0xD0, 0x26, 0x62, 0x9B, 0x30,
  31700. 0x2A, 0x04, 0x29, 0x69, 0x04, 0x10, 0x8D, 0x0B,
  31701. 0xB9, 0x04, 0x50, 0x46, 0x28, 0x50, 0x48, 0x24,
  31702. 0xD0, 0x48, 0x05, 0xA2, 0x48, 0x02, 0xC3, 0x20,
  31703. 0x8C, 0xA0, 0x14, 0x00, 0x41, 0x38, 0x21, 0x4B,
  31704. 0x24, 0x01, 0x04, 0xB5, 0x49, 0x42, 0x00, 0x00,
  31705. 0x0C, 0x24, 0x28, 0x12, 0x40, 0x84, 0xA2, 0x20,
  31706. 0x44, 0x9B, 0x06, 0x90, 0x63, 0xC0, 0x88, 0x8C,
  31707. 0x14, 0x21, 0x49, 0x12, 0x10, 0x54, 0x16, 0x24,
  31708. 0x20, 0x87, 0x44, 0x50, 0x10, 0x85, 0x0C, 0xB5,
  31709. 0x64, 0xDB, 0x24, 0x41, 0xD0, 0x42, 0x29, 0x9A,
  31710. 0x16, 0x8A, 0x21, 0xB4, 0x4C, 0x13, 0xB7, 0x70,
  31711. 0x10, 0xC0, 0x85, 0x19, 0x02, 0x69, 0xCC, 0x40,
  31712. 0x61, 0x1C, 0x48, 0x46, 0x98, 0x06, 0x25, 0x60,
  31713. 0x14, 0x46, 0xE4, 0x22, 0x62, 0x24, 0x27, 0x22,
  31714. 0x62, 0x24, 0x29, 0x44, 0xC6, 0x2D, 0x08, 0x31,
  31715. 0x84, 0x20, 0x32, 0x21, 0x04, 0xB4, 0x61, 0x0A,
  31716. 0x38, 0x12, 0xD9, 0x28, 0x44, 0xA4, 0x08, 0x20,
  31717. 0xCC, 0xA8, 0x29, 0x0B, 0x21, 0x31, 0x0A, 0x34,
  31718. 0x29, 0x03, 0x21, 0x40, 0xC1, 0xA2, 0x6C, 0x8A,
  31719. 0x16, 0x12, 0x52, 0xA6, 0x64, 0xA3, 0xB2, 0x51,
  31720. 0x04, 0x29, 0x51, 0xC4, 0x04, 0x91, 0x63, 0xB0,
  31721. 0x2D, 0x14, 0x44, 0x30, 0x8C, 0x40, 0x66, 0x0C,
  31722. 0x40, 0x0C, 0x01, 0xA5, 0x2C, 0x09, 0x94, 0x2D,
  31723. 0x62, 0xC6, 0x11, 0x03, 0x98, 0x50, 0x19, 0x10,
  31724. 0x4D, 0x19, 0xA8, 0x28, 0xD3, 0x86, 0x40, 0xC0,
  31725. 0x30, 0x65, 0x54, 0xA6, 0x71, 0xE0, 0xB4, 0x85,
  31726. 0x9B, 0x86, 0x10, 0x04, 0x36, 0x69, 0xD0, 0x46,
  31727. 0x29, 0x18, 0xA3, 0x71, 0x40, 0x22, 0x49, 0x00,
  31728. 0x43, 0x85, 0xCB, 0x40, 0x28, 0x89, 0x36, 0x66,
  31729. 0x41, 0x22, 0x69, 0xA4, 0x28, 0x51, 0xD9, 0x80,
  31730. 0x29, 0x14, 0x07, 0x21, 0xDA, 0x80, 0x91, 0x1B,
  31731. 0x26, 0x50, 0x5B, 0xA0, 0x60, 0x99, 0x42, 0x71,
  31732. 0x50, 0x88, 0x49, 0x10, 0x23, 0x09, 0x5A, 0x90,
  31733. 0x21, 0x22, 0x27, 0x8E, 0x43, 0xB2, 0x70, 0x0C,
  31734. 0xC9, 0x4C, 0xA4, 0x02, 0x70, 0x92, 0x40, 0x10,
  31735. 0x0A, 0x39, 0x70, 0x02, 0x36, 0x0E, 0x11, 0x30,
  31736. 0x41, 0xD8, 0x40, 0x2D, 0x1B, 0x24, 0x6D, 0xC3,
  31737. 0x92, 0x61, 0x4C, 0x86, 0x8D, 0x21, 0xB8, 0x00,
  31738. 0xD3, 0x24, 0x22, 0x12, 0xC8, 0x21, 0x12, 0x99,
  31739. 0x85, 0x09, 0x16, 0x0C, 0x5A, 0xA2, 0x24, 0x09,
  31740. 0x34, 0x42, 0x10, 0xA2, 0x24, 0x03, 0x42, 0x8C,
  31741. 0xC0, 0xB2, 0x8D, 0x12, 0xB6, 0x69, 0x63, 0x34,
  31742. 0x0D, 0xCC, 0xB0, 0x65, 0xA1, 0x12, 0x11, 0x4A,
  31743. 0x38, 0x69, 0xCC, 0x14, 0x81, 0x58, 0x44, 0x09,
  31744. 0x54, 0xA6, 0x80, 0x0C, 0xA8, 0x05, 0xC4, 0x38,
  31745. 0x8A, 0x84, 0x06, 0x01, 0x9B, 0x32, 0x2D, 0x83,
  31746. 0x12, 0x90, 0x09, 0x02, 0x60, 0xA1, 0x28, 0x88,
  31747. 0x58, 0x10, 0x41, 0x24, 0x40, 0x02, 0x19, 0x34,
  31748. 0x48, 0x18, 0xA0, 0x4D, 0x00, 0x10, 0x62, 0x13,
  31749. 0x22, 0x50, 0xE3, 0x38, 0x21, 0x9A, 0x96, 0x21,
  31750. 0x53, 0x08, 0x80, 0x51, 0x26, 0x01, 0x99, 0xC4,
  31751. 0x28, 0x1B, 0xB9, 0x71, 0x04, 0x97, 0x84, 0x04,
  31752. 0x05, 0x2C, 0xA0, 0xC2, 0x10, 0xD3, 0x42, 0x81,
  31753. 0x81, 0x42, 0x4D, 0x61, 0x84, 0x6C, 0x5A, 0x30,
  31754. 0x49, 0x1B, 0xC2, 0x24, 0xC0, 0x20, 0x28, 0xCA,
  31755. 0x92, 0x2D, 0x4A, 0x90, 0x10, 0x04, 0x27, 0x86,
  31756. 0x4C, 0x96, 0x21, 0x09, 0x19, 0x45, 0x14, 0x82,
  31757. 0x2C, 0x11, 0xA6, 0x91, 0x13, 0xB8, 0x04, 0x03,
  31758. 0x18, 0x70, 0x01, 0xA2, 0x51, 0x52, 0x14, 0x49,
  31759. 0x5A, 0x02, 0x30, 0xCB, 0x30, 0x2C, 0x94, 0x10,
  31760. 0x2C, 0x00, 0x49, 0x86, 0x09, 0xA0, 0x25, 0xC2,
  31761. 0x12, 0x4C, 0x1B, 0x02, 0x69, 0x40, 0xA4, 0x44,
  31762. 0x41, 0x16, 0x62, 0x02, 0x25, 0x28, 0xDC, 0xA2,
  31763. 0x2D, 0x00, 0x16, 0x42, 0x58, 0x30, 0x66, 0x5B,
  31764. 0x86, 0x24, 0xD4, 0x24, 0x48, 0xDB, 0x26, 0x0C,
  31765. 0x4C, 0x08, 0x85, 0x01, 0x90, 0x49, 0x21, 0x24,
  31766. 0x41, 0x54, 0x06, 0x84, 0x02, 0x43, 0x4A, 0x24,
  31767. 0x42, 0x05, 0x40, 0x14, 0x48, 0xCA, 0x44, 0x84,
  31768. 0xC0, 0x42, 0x0C, 0x98, 0x26, 0x04, 0x9C, 0xA2,
  31769. 0x05, 0xD1, 0xC2, 0x51, 0x13, 0x01, 0x86, 0x1C,
  31770. 0xA1, 0x50, 0xD9, 0x02, 0x50, 0x0C, 0x39, 0x86,
  31771. 0x8C, 0x00, 0x31, 0x22, 0x05, 0x48, 0xD3, 0x10,
  31772. 0x81, 0x12, 0x48, 0x05, 0xD1, 0x08, 0x69, 0x62,
  31773. 0x38, 0x2C, 0x0A, 0x23, 0x70, 0x9B, 0x44, 0x72,
  31774. 0xE3, 0x48, 0x6E, 0x22, 0x96, 0x70, 0x14, 0x33,
  31775. 0x6C, 0xD8, 0x90, 0x29, 0x03, 0x00, 0x49, 0x63,
  31776. 0x20, 0x8A, 0x03, 0x91, 0x25, 0x08, 0x89, 0x21,
  31777. 0xC0, 0x82, 0x0C, 0x99, 0x40, 0x32, 0xC2, 0x34,
  31778. 0x4E, 0x4B, 0x98, 0x69, 0x09, 0x80, 0x44, 0xE4,
  31779. 0x04, 0x69, 0x94, 0x20, 0x09, 0x99, 0x24, 0x6D,
  31780. 0x09, 0xA9, 0x60, 0x01, 0x29, 0x2D, 0xC8, 0x42,
  31781. 0x28, 0x8A, 0x34, 0x02, 0xE4, 0x08, 0x70, 0x0C,
  31782. 0x23, 0x6E, 0x0A, 0x05, 0x49, 0x64, 0x44, 0x2A,
  31783. 0x82, 0xC8, 0x00, 0x02, 0x48, 0x31, 0xCB, 0x90,
  31784. 0x50, 0x1C, 0x05, 0x68, 0x12, 0x12, 0x2C, 0xD0,
  31785. 0x80, 0x0C, 0x59, 0x48, 0x61, 0xCB, 0xA6, 0x09,
  31786. 0x9C, 0xC0, 0x81, 0x42, 0xB8, 0x00, 0x24, 0x41,
  31787. 0x8A, 0x94, 0x20, 0x40, 0x42, 0x14, 0x4D, 0x19,
  31788. 0x46, 0x62, 0x18, 0x05, 0x09, 0x24, 0x33, 0x6A,
  31789. 0xD4, 0x00, 0x61, 0x12, 0x48, 0x32, 0x8A, 0x04,
  31790. 0x72, 0x93, 0xB4, 0x69, 0x62, 0xC2, 0x71, 0x41,
  31791. 0xA6, 0x89, 0x44, 0x96, 0x31, 0x62, 0x30, 0x46,
  31792. 0x83, 0x42, 0x6C, 0x00, 0x19, 0x22, 0x09, 0x46,
  31793. 0x4D, 0x8B, 0x06, 0x49, 0xE1, 0xB0, 0x70, 0x42,
  31794. 0x44, 0x31, 0xC1, 0x80, 0x65, 0x9C, 0x00, 0x24,
  31795. 0x11, 0xA8, 0x31, 0x13, 0x21, 0x2C, 0x4B, 0x46,
  31796. 0x28, 0x1B, 0x18, 0x0D, 0x88, 0x42, 0x70, 0xD1,
  31797. 0xB0, 0x0D, 0x90, 0xC8, 0x45, 0xDA, 0xC2, 0x48,
  31798. 0x59, 0x14, 0x26, 0x22, 0x44, 0x00, 0xC2, 0x94,
  31799. 0x41, 0x50, 0xC8, 0x04, 0x18, 0x00, 0x00, 0xCB,
  31800. 0xA6, 0x24, 0x19, 0x02, 0x10, 0x10, 0x89, 0x0C,
  31801. 0x18, 0x22, 0x21, 0x62, 0xA8, 0x81, 0xC8, 0x92,
  31802. 0x48, 0xD3, 0x94, 0x20, 0x82, 0x06, 0x72, 0x09,
  31803. 0xA8, 0x90, 0x0C, 0x49, 0x8A, 0x41, 0x86, 0x28,
  31804. 0x19, 0xC5, 0x80, 0x9A, 0x18, 0x4D, 0x14, 0x10,
  31805. 0x2E, 0x22, 0x12, 0x52, 0x00, 0x08, 0x12, 0x0C,
  31806. 0x33, 0x45, 0x63, 0xC6, 0x30, 0x10, 0x93, 0x4C,
  31807. 0x60, 0xC6, 0x31, 0xDC, 0x40, 0x0E, 0x98, 0x82,
  31808. 0x50, 0x60, 0x02, 0x2A, 0xD2, 0x22, 0x40, 0xE4,
  31809. 0x06, 0x2D, 0xDB, 0x32, 0x0E, 0xCA, 0x32, 0x4E,
  31810. 0xD4, 0x18, 0x24, 0x08, 0xC3, 0x28, 0x4A, 0xC2,
  31811. 0x68, 0xE2, 0x80, 0x40, 0xA1, 0xC8, 0x64, 0x51,
  31812. 0xC2, 0x65, 0xCB, 0x16, 0x60, 0x23, 0x09, 0x4C,
  31813. 0x82, 0x04, 0x68, 0xD9, 0x22, 0x2E, 0x1C, 0x49,
  31814. 0x92, 0x42, 0x24, 0x21, 0x00, 0x37, 0x0E, 0xC8,
  31815. 0x12, 0x72, 0x64, 0x08, 0x25, 0x0A, 0x20, 0x2A,
  31816. 0x58, 0x24, 0x04, 0x59, 0x16, 0x4C, 0x08, 0x17,
  31817. 0x30, 0x00, 0x46, 0x05, 0x12, 0x90, 0x40, 0x03,
  31818. 0x07, 0x21, 0x52, 0xC0, 0x64, 0x1C, 0x83, 0x6D,
  31819. 0x9C, 0x32, 0x2E, 0x11, 0x15, 0x8A, 0x10, 0x35,
  31820. 0x88, 0x5A, 0xA0, 0x8D, 0xD9, 0x80, 0x48, 0x03,
  31821. 0xB6, 0x4C, 0x01, 0x10, 0x65, 0x10, 0x86, 0x40,
  31822. 0x11, 0x01, 0x42, 0x0A, 0xC1, 0x64, 0xDB, 0x22,
  31823. 0x4D, 0x64, 0xB2, 0x51, 0x02, 0x36, 0x0D, 0x93,
  31824. 0x46, 0x31, 0x14, 0xB6, 0x68, 0x63, 0x84, 0x29,
  31825. 0xC8, 0x10, 0x24, 0x94, 0x30, 0x08, 0x19, 0x37,
  31826. 0x02, 0x14, 0x82, 0x45, 0x88, 0x28, 0x40, 0x54,
  31827. 0xA8, 0x29, 0x90, 0x14, 0x12, 0x61, 0x36, 0x12,
  31828. 0x0B, 0x09, 0x8C, 0xA4, 0x98, 0x28, 0xC2, 0x92,
  31829. 0x45, 0x4C, 0x00, 0x60, 0x63, 0xC4, 0x81, 0xC0,
  31830. 0x36, 0x25, 0xCA, 0x88, 0x2D, 0x24, 0x40, 0x30,
  31831. 0xD3, 0xA8, 0x2D, 0xC9, 0xC8, 0x25, 0xD2, 0x84,
  31832. 0x48, 0x00, 0x32, 0x92, 0x50, 0xA2, 0x71, 0xD3,
  31833. 0x44, 0x0D, 0x22, 0x34, 0x60, 0x12, 0x13, 0x12,
  31834. 0x86, 0x8C, 0x5F, 0x86, 0x20, 0x79, 0x4A, 0x05,
  31835. 0x0E, 0x20, 0xD0, 0xE1, 0x01, 0x17, 0x86, 0x24,
  31836. 0x0E, 0xA6, 0x64, 0xF2, 0xF6, 0x9B, 0xB1, 0xB7,
  31837. 0xE3, 0x0E, 0xC6, 0x6B, 0x1A, 0x4A, 0x0B, 0xE5,
  31838. 0x9B, 0x79, 0xF2, 0x19, 0x8A, 0xD9, 0x80, 0x44,
  31839. 0x83, 0xE4, 0x75, 0xE5, 0x3B, 0x3C, 0x49, 0xCB,
  31840. 0x0C, 0xE5, 0xEF, 0x92, 0x91, 0x2A, 0xF4, 0x40,
  31841. 0xF2, 0x3B, 0x99, 0x58, 0x13, 0xD1, 0x1B, 0x59,
  31842. 0xF7, 0x98, 0xE9, 0x3C, 0x9D, 0x13, 0x53, 0x98,
  31843. 0x17, 0xC7, 0xAC, 0x68, 0xCA, 0xD1, 0xAA, 0x1A,
  31844. 0xC2, 0x76, 0x56, 0xBD, 0x0C, 0x47, 0x97, 0xE9,
  31845. 0xC8, 0xEC, 0x17, 0x78, 0x4C, 0x1A, 0x32, 0x7A,
  31846. 0x9D, 0xFE, 0xAF, 0x4D, 0x61, 0x91, 0xEE, 0xCD,
  31847. 0xAF, 0xE0, 0x49, 0xB7, 0x33, 0xFE, 0x39, 0xD5,
  31848. 0xEB, 0x40, 0x00, 0x93, 0x6F, 0xEE, 0xFC, 0xF8,
  31849. 0x29, 0x28, 0xE9, 0xF9, 0x4C, 0xFD, 0x5C, 0xF4,
  31850. 0xC1, 0xE3, 0xDE, 0xB1, 0x43, 0x3A, 0x47, 0xF6,
  31851. 0xD3, 0x28, 0xB5, 0xE8, 0x3D, 0xD1, 0x56, 0xD0,
  31852. 0x18, 0x2D, 0xC6, 0x92, 0x34, 0x75, 0x91, 0xAA,
  31853. 0x6F, 0x73, 0x2C, 0xFB, 0xE9, 0x82, 0x93, 0x5F,
  31854. 0xD1, 0x84, 0x6C, 0xAC, 0xF4, 0xCB, 0x85, 0x15,
  31855. 0xC5, 0x5A, 0xB8, 0x5E, 0xE5, 0xAD, 0x44, 0xCB,
  31856. 0x09, 0xD3, 0x26, 0x9E, 0x2E, 0x6D, 0x11, 0x78,
  31857. 0x09, 0x61, 0xFD, 0x13, 0x1D, 0x5E, 0x6F, 0xBF,
  31858. 0x89, 0x84, 0x9F, 0x47, 0xF2, 0xB7, 0x1D, 0x82,
  31859. 0x83, 0xFF, 0x25, 0x38, 0x5E, 0x52, 0xB0, 0x7D,
  31860. 0xBB, 0x26, 0x6C, 0x67, 0x4C, 0xEE, 0x3D, 0x0B,
  31861. 0x5D, 0xF5, 0xA5, 0x6D, 0x8B, 0xDC, 0xDC, 0xFA,
  31862. 0xAE, 0xE6, 0xA2, 0x48, 0xE7, 0x1D, 0xB1, 0x34,
  31863. 0x5A, 0xFC, 0x59, 0x7C, 0xA8, 0x30, 0xA1, 0xA3,
  31864. 0x5B, 0x43, 0x96, 0xEF, 0x4C, 0x1A, 0xDF, 0x9E,
  31865. 0xD0, 0x1B, 0xCE, 0x9B, 0x6E, 0xB6, 0x37, 0xFA,
  31866. 0x24, 0xAA, 0x16, 0x0B, 0x90, 0x76, 0xBA, 0xE3,
  31867. 0x05, 0x59, 0xF8, 0xB2, 0x9D, 0xED, 0xB3, 0xD2,
  31868. 0x5B, 0x79, 0x06, 0x4A, 0xB0, 0xCF, 0x8B, 0x8D,
  31869. 0x70, 0xAD, 0xDD, 0xEB, 0x8B, 0x17, 0x42, 0x48,
  31870. 0xD5, 0xAE, 0xA4, 0xD1, 0x8D, 0xE4, 0x3B, 0x89,
  31871. 0x38, 0xCD, 0xD2, 0xAC, 0xBA, 0x54, 0x77, 0xBD,
  31872. 0x4A, 0xAC, 0xC3, 0xCE, 0x59, 0x5E, 0x5D, 0x26,
  31873. 0x9F, 0xE6, 0x75, 0x21, 0x0D, 0x23, 0x15, 0x2B,
  31874. 0x04, 0x71, 0x0F, 0x36, 0x84, 0x28, 0x79, 0x4A,
  31875. 0x75, 0xF4, 0x9B, 0x68, 0x3E, 0xD2, 0x0D, 0xD6,
  31876. 0x47, 0x51, 0x57, 0x77, 0x95, 0x5A, 0x8C, 0xB3,
  31877. 0x8A, 0x36, 0xAF, 0xCD, 0x2C, 0xE0, 0xAC, 0xEC,
  31878. 0x4F, 0x0D, 0xFE, 0x80, 0x77, 0x02, 0xD1, 0xEB,
  31879. 0x3B, 0xDE, 0x72, 0xE9, 0xE0, 0x85, 0xAA, 0x4E,
  31880. 0x09, 0xEB, 0x1B, 0x09, 0x47, 0x41, 0x38, 0x52,
  31881. 0xEC, 0x3C, 0x0A, 0xC5, 0x2F, 0x06, 0xCB, 0x95,
  31882. 0x9C, 0x85, 0x39, 0x4E, 0xB3, 0x74, 0x81, 0x19,
  31883. 0xED, 0xBE, 0x6C, 0x80, 0xD2, 0xD8, 0xF7, 0x92,
  31884. 0xCE, 0x0D, 0x91, 0x5E, 0x4F, 0x4B, 0x15, 0x1E,
  31885. 0xFB, 0x13, 0x5E, 0x7F, 0x4D, 0xC9, 0x7D, 0x85,
  31886. 0x81, 0x41, 0xC5, 0x7F, 0x70, 0x41, 0x7B, 0x43,
  31887. 0xA6, 0xA1, 0x26, 0x95, 0x69, 0x78, 0xD7, 0x8E,
  31888. 0xFB, 0x9F, 0x03, 0x72, 0x43, 0xB4, 0xCB, 0x41,
  31889. 0xDF, 0x96, 0x8B, 0x7E, 0xE5, 0xB5, 0x20, 0x87,
  31890. 0xF0, 0x5A, 0xA9, 0xFE, 0x48, 0x7B, 0xD1, 0x6C,
  31891. 0x03, 0x47, 0xCF, 0x13, 0x35, 0x76, 0x0B, 0xD2,
  31892. 0x39, 0x8A, 0xD5, 0x4D, 0xDA, 0x00, 0xA5, 0xAA,
  31893. 0xC4, 0x46, 0xD8, 0x0B, 0x1C, 0x79, 0x98, 0xC6,
  31894. 0x02, 0x19, 0x2A, 0xDA, 0xFC, 0xB8, 0x09, 0xD1,
  31895. 0x4E, 0xE3, 0x28, 0x64, 0x1B, 0xA3, 0xAA, 0x00,
  31896. 0xF8, 0xD2, 0x9C, 0x3A, 0x84, 0x8A, 0xCB, 0xDC,
  31897. 0x19, 0x46, 0xBC, 0x0D, 0x35, 0xE0, 0xBE, 0x0F,
  31898. 0x8F, 0x7E, 0x3D, 0xA3, 0xF6, 0x8D, 0x9F, 0xA9,
  31899. 0x76, 0x8F, 0x5C, 0xF2, 0x75, 0x53, 0x4A, 0x0E,
  31900. 0xCA, 0x9E, 0x60, 0xFC, 0xEA, 0x38, 0xF1, 0xE0,
  31901. 0x42, 0xC3, 0x16, 0x14, 0x3A, 0x76, 0x7B, 0x33,
  31902. 0xAC, 0xCA, 0xD8, 0xC8, 0xD6, 0x6C, 0x70, 0xC7,
  31903. 0x5F, 0xD1, 0xF0, 0xB2, 0x58, 0x6B, 0x65, 0x3A,
  31904. 0xD4, 0xAF, 0x54, 0xE5, 0x6E, 0xF0, 0x69, 0x33,
  31905. 0xEA, 0xD3, 0x1D, 0xE3, 0x65, 0xD1, 0x10, 0xB9,
  31906. 0xC4, 0xA2, 0xA9, 0x8B, 0xCB, 0xA1, 0x65, 0xCA,
  31907. 0xFE, 0x38, 0x6F, 0x88, 0x7C, 0x72, 0x15, 0x6E,
  31908. 0xB1, 0x4F, 0xF0, 0xDA, 0xD6, 0x65, 0x61, 0x6C,
  31909. 0xE3, 0xCE, 0x65, 0xC1, 0x90, 0x4F, 0x2C, 0x17,
  31910. 0x47, 0xB2, 0xEC, 0x2B, 0x5C, 0x9D, 0x67, 0x76,
  31911. 0xBC, 0xD7, 0x9E, 0x5A, 0xC6, 0x4B, 0x79, 0x33,
  31912. 0xBD, 0xDE, 0xDE, 0xDD, 0xBB, 0xC7, 0x25, 0xBF,
  31913. 0xDB, 0xCC, 0xDE, 0x2F, 0xB3, 0x75, 0xAE, 0x2B,
  31914. 0xE3, 0x53, 0x7B, 0xDF, 0x89, 0xBF, 0x4C, 0x25,
  31915. 0xF8, 0x3A, 0x49, 0xD6, 0xA6, 0xA8, 0xD0, 0x76,
  31916. 0x1C, 0xF3, 0x9D, 0x62, 0x0C, 0x53, 0xED, 0x83,
  31917. 0x7D, 0x19, 0x82, 0x55, 0xCF, 0x5B, 0x91, 0x0A,
  31918. 0x6D, 0xB5, 0x78, 0x77, 0xDF, 0x92, 0xD8, 0xBB,
  31919. 0x6E, 0x9C, 0x52, 0x6B, 0x8C, 0x4E, 0xC9, 0x31,
  31920. 0x00, 0xDE, 0xE0, 0x50, 0x0A, 0x21, 0x0C, 0x98,
  31921. 0x45, 0x83, 0xE1, 0x53, 0x81, 0x60, 0xED, 0xAC,
  31922. 0x2C, 0x6F, 0x86, 0x6E, 0x7F, 0x5D, 0x99, 0xD7,
  31923. 0xB1, 0xB8, 0x15, 0x82, 0xF5, 0xD0, 0xEB, 0xBF,
  31924. 0x27, 0x86, 0xE3, 0xF5, 0x56, 0x01, 0x3B, 0xA9,
  31925. 0xB6, 0xF6, 0x56, 0xEB, 0x79, 0x88, 0x38, 0xEA,
  31926. 0x05, 0x79, 0x20, 0x1A, 0x95, 0xD5, 0x6B, 0xBC,
  31927. 0x3B, 0xCD, 0xB9, 0x51, 0x1A, 0xFB, 0xD4, 0xD8,
  31928. 0x12, 0x88, 0x89, 0x6F, 0x87, 0x10, 0x8C, 0x07,
  31929. 0x7F, 0x1A, 0x81, 0xA3, 0xBD, 0x29, 0x7B, 0xB1,
  31930. 0x24, 0xA8, 0x00, 0x86, 0x89, 0x02, 0x42, 0x99,
  31931. 0x5E, 0x03, 0xCF, 0x42, 0xA0, 0xC2, 0x1E, 0x27,
  31932. 0x2A, 0x9A, 0xFA, 0x1D, 0xC1, 0x03, 0x46, 0x3D,
  31933. 0x2A, 0xB4, 0x94, 0xF7, 0xD0, 0x17, 0x68, 0x6D,
  31934. 0x31, 0x89, 0x4D, 0xD2, 0xF6, 0xEB, 0xB0, 0xC3,
  31935. 0xCB, 0x62, 0x23, 0xEC, 0x79, 0xC6, 0x5D, 0x45,
  31936. 0xC1, 0xB0, 0xD4, 0xEF, 0x19, 0x61, 0xF1, 0x6D,
  31937. 0x65, 0x3F, 0xCF, 0x25, 0x97, 0x7B, 0x65, 0x1E,
  31938. 0xC5, 0x1A, 0x13, 0xAE, 0x8D, 0x4A, 0x34, 0x72,
  31939. 0xEE, 0x71, 0x96, 0x9A, 0x7A, 0x93, 0x6F, 0x5D,
  31940. 0xBB, 0xB9, 0x39, 0x6A, 0x46, 0xD9, 0x76, 0x42,
  31941. 0x35, 0x8C, 0xAF, 0x48, 0x94, 0xC9, 0xA6, 0xDF,
  31942. 0x84, 0xA5, 0x9C, 0x59, 0x62, 0xA6, 0x99, 0x0A,
  31943. 0x76, 0xF0, 0x61, 0x48, 0x90, 0x16, 0x9F, 0x00,
  31944. 0x18, 0x70, 0xD4, 0x9C, 0xF2, 0xE7, 0x50, 0x08,
  31945. 0xCC, 0x4A, 0x5D, 0x85, 0xE7, 0x2D, 0xE2, 0xD6,
  31946. 0xCF, 0x3F, 0xA7, 0x18, 0x52, 0x25, 0x35, 0x22,
  31947. 0xFE, 0x8B, 0x0E, 0x42, 0x3C, 0xB4, 0x17, 0xA3,
  31948. 0x8E, 0xB7, 0x8C, 0x87, 0x63, 0xC3, 0x72, 0x0C,
  31949. 0x04, 0xE6, 0x7F, 0xF8, 0x89, 0x79, 0xEB, 0xA0,
  31950. 0x9E, 0x34, 0x53, 0x8B, 0xB5, 0x23, 0xB9, 0x9B,
  31951. 0x8E, 0x34, 0x16, 0x74, 0x12, 0xF7, 0x7A, 0xEA,
  31952. 0x89, 0x4D, 0x83, 0xAC, 0xF9, 0x46, 0xFC, 0x05,
  31953. 0x4D, 0x0A, 0xF4, 0x72, 0x95, 0xE5, 0x1E, 0xD8,
  31954. 0x3F, 0x74, 0x86, 0x94, 0x0A, 0x4D, 0x41, 0xC0,
  31955. 0x4A, 0xD7, 0xEB, 0xEE, 0x61, 0x0B, 0xF1, 0xD0,
  31956. 0x3F, 0xA5, 0x40, 0x71, 0xD5, 0x1A, 0x15, 0x09,
  31957. 0xE4, 0xF4, 0x91, 0x63, 0xA2, 0x50, 0x81, 0xBE,
  31958. 0x87, 0x90, 0xD0, 0x87, 0xF5, 0xF4, 0xF0, 0x5C,
  31959. 0x88, 0x55, 0x0F, 0xCA, 0x9B, 0xF9, 0x9C, 0x9B,
  31960. 0xE5, 0x95, 0x3D, 0x51, 0xDD, 0x08, 0x45, 0xC9,
  31961. 0x3E, 0x41, 0xEE, 0xEF, 0x62, 0xE0, 0x79, 0x4B,
  31962. 0x29, 0x27, 0xC4, 0xF5, 0xED, 0x9B, 0xD3, 0xE3,
  31963. 0x4E, 0xA9, 0x20, 0x0A, 0x79, 0xDD, 0xEB, 0x4B,
  31964. 0x2D, 0x8F, 0x30, 0x5F, 0xE0, 0x5F, 0x82, 0x7C,
  31965. 0x7E, 0x2E, 0xD1, 0x86, 0x34, 0x1C, 0xB5, 0xD1,
  31966. 0x15, 0x2F, 0xC8, 0x01, 0x04, 0xE0, 0xE1, 0x36,
  31967. 0x83, 0xD9, 0x41, 0x29, 0x4C, 0x77, 0x84, 0x17,
  31968. 0x16, 0x4B, 0x68, 0x4A, 0x97, 0x6E, 0x56, 0xE7,
  31969. 0x8D, 0xA4, 0xD1, 0x7C, 0x3C, 0x73, 0x22, 0x93,
  31970. 0x14, 0x87, 0x0B, 0x85, 0xC4, 0x55, 0xC2, 0x3B,
  31971. 0x83, 0x0B, 0x9A, 0x28, 0xA3, 0xD8, 0xC0, 0xB5,
  31972. 0x66, 0x42, 0x6D, 0xC1, 0x69, 0xF3, 0x26, 0xAB,
  31973. 0xCE, 0x2E, 0xFF, 0xF3, 0x9E, 0x9B, 0x19, 0x9A,
  31974. 0xE5, 0xC1, 0x29, 0x2B, 0x6F, 0x2E, 0xF3, 0x7A,
  31975. 0xF1, 0xDE, 0xA9, 0x27, 0x2C, 0x8D, 0x54, 0x23,
  31976. 0xDF, 0x8A, 0x56, 0x32, 0xF9, 0x91, 0xE1, 0x4D,
  31977. 0xCA, 0x25, 0x14, 0x78, 0x8B, 0x62, 0xBE, 0x16,
  31978. 0x48, 0x28, 0xE9, 0xAC, 0xB8, 0x93, 0xDD, 0xA6,
  31979. 0x02, 0xA5, 0xE2, 0xFB, 0x9E, 0xFC, 0xBE, 0xFD,
  31980. 0x95, 0xAB, 0xFB, 0x82, 0xD2, 0xB0, 0x2D, 0x49,
  31981. 0xCC, 0x53, 0x08, 0x4A, 0x49, 0xAB, 0x1B, 0xEC,
  31982. 0x23, 0xE5, 0xB4, 0xC8, 0xE7, 0x14, 0xCB, 0x03,
  31983. 0x40, 0x5F, 0x1B, 0xCF, 0x7E, 0x11, 0xBB, 0x59,
  31984. 0x72, 0x9D, 0xDC, 0x0B, 0x7B, 0xEF, 0xB2, 0x91,
  31985. 0x27, 0x6D, 0xCE, 0xDA, 0xCA, 0xAD, 0x39, 0xA2,
  31986. 0xF0, 0x1C, 0x7D, 0xC9, 0x8B, 0x9E, 0x06, 0x5E,
  31987. 0xAF, 0xED, 0x1C, 0xC8, 0xCE, 0x3E, 0x84, 0x80,
  31988. 0x80, 0xA2, 0xFC, 0x5B, 0x98, 0xC9, 0xF6, 0xBF,
  31989. 0x50, 0x40, 0x27, 0x33, 0x42, 0xF0, 0x31, 0x2F,
  31990. 0x8B, 0x98, 0x44, 0x59, 0x4A, 0x50, 0x3D, 0xD3,
  31991. 0xE6, 0xAF, 0x1C, 0x9E, 0x35, 0xC1, 0x03, 0x2A,
  31992. 0x4A, 0x8A, 0x5E, 0x7B, 0xF3, 0x3A, 0x82, 0xF3,
  31993. 0x5E, 0x16, 0xED, 0xF8, 0xC6, 0x0C, 0x90, 0x02,
  31994. 0x1D, 0x8C, 0x0B, 0xA4, 0xC3, 0x86, 0x24, 0x5D,
  31995. 0xFE, 0xF0, 0x94, 0x48, 0x43, 0x1D, 0x8C, 0x00,
  31996. 0xD1, 0xE2, 0x6E, 0xE4, 0xD8, 0xC7, 0x7D, 0xAA,
  31997. 0x1A, 0x70, 0x5E, 0xD4, 0x79, 0x2A, 0xCB, 0x4E,
  31998. 0xA2, 0x7C, 0x15, 0x66, 0xFB, 0x56, 0x68, 0x3C,
  31999. 0x43, 0xBF, 0x67, 0x84, 0x2E, 0x67, 0x53, 0x4C,
  32000. 0xB3, 0xF9, 0x67, 0x7C, 0x8A, 0xB9, 0xD0, 0xEE,
  32001. 0xE7, 0x82, 0x7C, 0xDE, 0xFC, 0x22, 0x3A, 0xC9,
  32002. 0x48, 0xB8, 0x80, 0xB5, 0xF1, 0xCE, 0x95, 0x37,
  32003. 0x27, 0x29, 0x32, 0x00, 0x2C, 0x1A, 0x4D, 0xD2,
  32004. 0x18, 0xF5, 0x27, 0x16, 0x6E, 0xBF, 0xB2, 0xB2,
  32005. 0xFA, 0x2B, 0xF3, 0x72, 0x46, 0xEC, 0xDF, 0xDF,
  32006. 0xA7, 0x2B, 0x6D, 0xA1, 0x1C, 0x30, 0xD1, 0xC7,
  32007. 0xD2, 0x48, 0xAD, 0x64, 0x81, 0x8F, 0x69, 0x1D,
  32008. 0x59, 0xB7, 0x55, 0xDA, 0xF7, 0x1B, 0xED, 0x9A,
  32009. 0xB5, 0xFB, 0x52, 0xE0, 0x36, 0x22, 0xA9, 0x00,
  32010. 0xD6, 0x6B, 0x4C, 0x63, 0x84, 0x16, 0x9B, 0xDF,
  32011. 0x9E, 0xB6, 0x1C, 0x02, 0xDF, 0x45, 0xFB, 0x76,
  32012. 0xB1, 0xA2, 0x6F, 0x34, 0xE9, 0x38, 0xB1, 0x90,
  32013. 0x86, 0x17, 0x45, 0xC0, 0x21, 0xFA, 0x87, 0x62,
  32014. 0x00, 0xC7, 0xFC, 0x8E, 0x22, 0x2D, 0xDB, 0xFA,
  32015. 0xD8, 0xBE, 0x78, 0x1B, 0x18, 0x54, 0x24, 0xAA,
  32016. 0xAF, 0xC6, 0x58, 0x62, 0xDB, 0x13, 0x2B, 0xEC,
  32017. 0x6D, 0x18, 0x83, 0x7A, 0x1F, 0x58, 0xA8, 0x76,
  32018. 0xC9, 0x9E, 0x63, 0xF5, 0x14, 0x20, 0xB8, 0x3F,
  32019. 0x45, 0x96, 0x75, 0x61, 0x2F, 0x7A, 0xCF, 0x80,
  32020. 0xB4, 0xEB, 0x1D, 0xD0, 0x72, 0x1C, 0xAA, 0x1B,
  32021. 0x49, 0x70, 0xDA, 0x60, 0x86, 0x79, 0xC6, 0x38,
  32022. 0x3E, 0x81, 0x7F, 0xE1, 0x6B, 0x66, 0xB1, 0x91,
  32023. 0x81, 0xED, 0xFC, 0x39, 0x27, 0x0C, 0x7E, 0x91,
  32024. 0x7B, 0x1F, 0x10, 0xEB, 0x7A, 0x01, 0x19, 0x97,
  32025. 0xE9, 0x67, 0x85, 0x3B, 0x78, 0xE0, 0x0C, 0xFD,
  32026. 0x58, 0xD2, 0x24, 0xD9, 0x33, 0xCC, 0x5A, 0x99,
  32027. 0x55, 0x32, 0xDC, 0xD4, 0xE5, 0x32, 0xE4, 0x03,
  32028. 0x05, 0x15, 0xF4, 0xA0, 0x5B, 0x33, 0x1D, 0x57,
  32029. 0x5D, 0xDA, 0xC2, 0x9B, 0xAB, 0x06, 0x9F, 0x09,
  32030. 0xAF, 0x0D, 0x17, 0x33, 0x73, 0xDB, 0x1E, 0xC2,
  32031. 0xB6, 0x36, 0x6B, 0xB3, 0x71, 0x00, 0x8A, 0x23,
  32032. 0x86, 0xFD, 0x88, 0xBE, 0x77, 0xF5, 0xED, 0x5E,
  32033. 0x19, 0x8C, 0xBE, 0x88, 0xDF, 0x24, 0xBC, 0x6E,
  32034. 0x39, 0x3F, 0xEB, 0xC1, 0x0C, 0x47, 0x0A, 0x72,
  32035. 0xD4, 0x7C, 0x0F, 0x83, 0x46, 0x53, 0xC9, 0xAE,
  32036. 0x80, 0x0E, 0x89, 0x3C, 0x6B, 0xA6, 0x8E, 0xA2,
  32037. 0x8A, 0x83, 0x8F, 0xCB, 0xB6, 0x9C, 0x3E, 0x96,
  32038. 0x4A, 0x5F, 0xAF, 0xC2, 0x06, 0x7D, 0xD4, 0x06,
  32039. 0xB2, 0x57, 0xC9, 0x8D, 0xD3, 0x97, 0x9E, 0xC7,
  32040. 0xC7, 0xEC, 0xBE, 0x96, 0xA3, 0x3D, 0x85, 0x51,
  32041. 0x5D, 0xA2, 0xCB, 0x6A, 0xA5, 0xE1, 0xFF, 0xF2,
  32042. 0x04, 0xAF, 0x62, 0xDD, 0x41, 0x19, 0xA0, 0xE4,
  32043. 0x8C, 0x04, 0xA3, 0xF2, 0xB3, 0x86, 0x60, 0xF5,
  32044. 0x29, 0x64, 0xD8, 0xD4, 0xAE, 0xE1, 0x46, 0xA9,
  32045. 0xC5, 0x3C, 0x31, 0x90, 0x6D, 0xAD, 0x0F, 0xD9,
  32046. 0x0B, 0x5D, 0x83, 0xB3, 0xE3, 0x1B, 0x69, 0x0A,
  32047. 0x4C, 0x49, 0x35, 0x24, 0x99, 0x81, 0xBE, 0x1F,
  32048. 0x1A, 0x85, 0xEC, 0x6E, 0x0F, 0xEE, 0x4C, 0x88,
  32049. 0xF2, 0xD8, 0x9E, 0x29, 0x69, 0xAB, 0x8C, 0xBB,
  32050. 0xEB, 0x50, 0x19, 0x16, 0x55, 0x8D, 0x29, 0xEA,
  32051. 0x7C, 0x3E, 0xCF, 0x1C, 0x9E, 0xF1, 0xA0, 0x43,
  32052. 0x50, 0x63, 0x3B, 0x4C, 0xDA, 0x73, 0x7D, 0xFB,
  32053. 0x15, 0x1C, 0xB5, 0xE7, 0x36, 0x11, 0x73, 0xF3,
  32054. 0xAE, 0xDD, 0xDF, 0x52, 0x7D, 0x73, 0xF2, 0xF9,
  32055. 0xD5, 0xB6, 0x21, 0x3A, 0xA6, 0x8F, 0x88, 0x3E,
  32056. 0x9A, 0x26, 0x33, 0x78, 0x5E, 0xC6, 0xBE, 0x64,
  32057. 0x2A, 0x9F, 0xD0, 0xF2, 0x1A, 0x42, 0xF6, 0xB9,
  32058. 0xDA, 0xAB, 0xDC, 0xD1, 0xE6, 0xAD, 0xBE, 0xF6,
  32059. 0x48, 0x41, 0xB5, 0x96, 0x86, 0xEA, 0xE3, 0xEC,
  32060. 0x88, 0xEE, 0xF0, 0xA9, 0xCB, 0xC1, 0x2B, 0xC0,
  32061. 0x12, 0x62, 0x2D, 0xF2, 0xDD, 0x93, 0xA8, 0x62,
  32062. 0x29, 0x04, 0x4A, 0xF2, 0xF2, 0x60, 0xD2, 0x18,
  32063. 0x3F, 0x51, 0xE8, 0x33, 0xEE, 0x92, 0xD9, 0x8F,
  32064. 0x02, 0x51, 0xE3, 0xF8, 0x5F, 0xAB, 0x74, 0xCE,
  32065. 0x36, 0x7B, 0x8B, 0x7A, 0xA6, 0x3D, 0x3C, 0xF8,
  32066. 0xC8, 0xBF, 0x4D, 0x78, 0x35, 0x8B, 0xAE, 0x0A,
  32067. 0x02, 0x41, 0xE2, 0x10, 0xAC, 0x69, 0x35, 0x30,
  32068. 0x87, 0xCC, 0x73, 0x31, 0x35, 0x7E, 0xB4, 0x45,
  32069. 0x0F, 0x95, 0x09, 0xCF, 0xE5, 0x95, 0xF5, 0x40,
  32070. 0x32, 0xEE, 0x05, 0x77, 0x54, 0xA8, 0xED, 0xD7,
  32071. 0x46, 0xCB, 0x92, 0x82, 0xE7, 0x68, 0xDC, 0x6B,
  32072. 0x83, 0x0C, 0x5B, 0x4A, 0x21, 0x93, 0x43, 0xAD,
  32073. 0x12, 0x4E, 0xDB, 0x3B, 0xBC, 0x42, 0x50, 0x55,
  32074. 0x66, 0xA7, 0x03, 0x8C, 0x95, 0x9B, 0xC3, 0x55,
  32075. 0x85, 0xB6, 0x05, 0x5F, 0x19, 0x68, 0xDA, 0x24,
  32076. 0x3F, 0x77, 0x8F, 0x4E, 0x46, 0xDB, 0x46, 0x2A,
  32077. 0xBE, 0xB9, 0x3B, 0x81, 0x24, 0x3C, 0x31, 0xEB,
  32078. 0x59, 0x62, 0x2E, 0xDF, 0x81, 0xF0, 0x6C, 0xCC,
  32079. 0x61, 0xD2, 0xA6, 0xEA, 0x73, 0xE1, 0x09, 0xC3,
  32080. 0x87, 0x91, 0x5F, 0x27, 0x7B, 0xCF, 0x1F, 0xC1,
  32081. 0x11, 0x05, 0xBB, 0xA7, 0x02, 0x93, 0xC0, 0xFA,
  32082. 0xB5, 0xC0, 0x65, 0xF2, 0x3B, 0xAA, 0x19, 0x29,
  32083. 0x0A, 0x30, 0x2F, 0x08, 0x09, 0x11, 0x07, 0xA4,
  32084. 0xB1, 0xD5, 0x68, 0x85, 0x26, 0x22, 0x09, 0x83,
  32085. 0x83, 0x42, 0x77, 0x60, 0xEF, 0x8F, 0x29, 0x28,
  32086. 0x62, 0x5B, 0xDD, 0xA5, 0xF5, 0x14, 0xC5, 0xAD,
  32087. 0xE9, 0x59, 0x89, 0x1E, 0xF2, 0x95, 0x9F, 0x24,
  32088. 0x8A, 0x35, 0x32, 0xBF, 0x9D, 0x30, 0xE7, 0x14,
  32089. 0x05, 0x9E, 0xBD, 0xEC, 0x95, 0x87, 0x08, 0xF8,
  32090. 0xA8, 0x3C, 0x26, 0x8B, 0xEF, 0x26, 0x82, 0xD6,
  32091. 0x03, 0xCA, 0x88, 0x63, 0x47, 0xE1, 0x98, 0xFD,
  32092. 0x68, 0x23, 0x39, 0x99, 0xC7, 0x7D, 0x30, 0xD7,
  32093. 0x45, 0x5D, 0xE6, 0xBC, 0xFD, 0x01, 0x44, 0x27,
  32094. 0x70, 0x62, 0xB3, 0x04, 0xBE, 0xF0, 0xE3, 0x4C,
  32095. 0x5A, 0x9D, 0x8D, 0x78, 0x0D, 0x29, 0xEC, 0x23,
  32096. 0x21, 0xE0, 0x73, 0x40, 0x77, 0x1C, 0x46, 0x36,
  32097. 0x04, 0x83, 0xAD, 0xCA, 0xF1, 0x2D, 0x5B, 0x79,
  32098. 0xFD, 0xBF, 0xE2, 0x85, 0x6A, 0xCE, 0x88, 0x59,
  32099. 0xF6, 0xB1, 0x24, 0x14, 0xB3, 0xF7, 0xE8, 0xBB,
  32100. 0x58, 0x13, 0x49, 0x89, 0x60, 0xF3, 0x4F, 0xDC,
  32101. 0x64, 0xFC, 0x84, 0x85, 0x79, 0xCA, 0xF9, 0xDC,
  32102. 0xCF, 0x19, 0xB4, 0xFB, 0x82, 0x5E, 0xD5, 0x71,
  32103. 0x6D, 0xCC, 0xCD, 0x68, 0x72, 0xCB, 0xDE, 0x38,
  32104. 0x31, 0xD6, 0x73, 0x84, 0x94, 0x2C, 0xD8, 0xA9,
  32105. 0xEC, 0x4B, 0xBF, 0xEF, 0x57, 0x06, 0xB8, 0xF9,
  32106. 0xF0, 0x5F, 0xE1, 0xE8, 0xFE, 0x69, 0xD3, 0xEA,
  32107. 0x6A, 0x86, 0x21, 0xC2, 0x21, 0x44, 0x17, 0x7B,
  32108. 0x1C, 0x12, 0x59, 0xE1, 0xA7, 0x9D, 0xFD, 0xF8,
  32109. 0x97, 0x28, 0x88, 0x7B, 0xEF, 0x1A, 0x70, 0x48,
  32110. 0x25, 0x56, 0x83, 0x1B, 0x67, 0x24, 0x40, 0xE1,
  32111. 0x3F, 0xE3, 0xE3, 0xFC, 0x82, 0x04, 0xA0, 0x2E,
  32112. 0xA1, 0xEF, 0xF1, 0x9D, 0x95, 0x25, 0x38, 0x87,
  32113. 0x28, 0x5B, 0xFB, 0xEA, 0x16, 0xA0, 0xF2, 0x19,
  32114. 0xEF, 0xBC, 0xEC, 0x30, 0xA8, 0xAE, 0x86, 0x58,
  32115. 0x9A, 0x57, 0x03, 0x10, 0x3A, 0x8A, 0x39, 0x3F,
  32116. 0xA6, 0xF6, 0xB6, 0x57, 0x70, 0x4A, 0xC6, 0x77,
  32117. 0xC1, 0x4C, 0xD1, 0x0D, 0x3D, 0x62, 0xD1, 0x3F,
  32118. 0xBD, 0x37, 0x8C, 0x2D, 0xDA, 0x32, 0x5B, 0x61,
  32119. 0xB8, 0x59, 0x52, 0xD5, 0x12, 0x93, 0x87, 0x1E,
  32120. 0x1F, 0xCD, 0xC9, 0x48, 0xC7, 0x7B, 0xEA, 0xE9,
  32121. 0xA6, 0xF0, 0xE8, 0x7C, 0xE1, 0xA8, 0x05, 0x1C,
  32122. 0x8F, 0x80, 0x87, 0x68, 0x5C, 0x12, 0x62, 0x4B,
  32123. 0xDF, 0x58, 0x38, 0x0E, 0xD6, 0x6F, 0x55, 0xB4,
  32124. 0x3D, 0xDD, 0x6D, 0x36, 0x21, 0x73, 0xA5, 0xBD,
  32125. 0x38, 0x98, 0x59, 0xC1, 0x7D, 0x95, 0xEC, 0xE3,
  32126. 0xAB, 0x73, 0x26, 0x39, 0xFF, 0xE4, 0x51, 0xCD,
  32127. 0x10, 0x3E, 0xE4, 0x85, 0x4D, 0xB2, 0xF3, 0x96,
  32128. 0x14, 0xF6, 0x58, 0xBA, 0xA3, 0x84, 0xBC, 0x99,
  32129. 0x48, 0xD0, 0x71, 0x4E, 0xB4, 0x8A, 0x88, 0x71,
  32130. 0x43, 0xE7, 0xA1, 0xFA, 0x4B, 0x69, 0x0C, 0x22,
  32131. 0xB4, 0x92, 0xA7, 0x0C, 0x61, 0x2B, 0x59, 0xFF,
  32132. 0xD2, 0xD6, 0xB3, 0xB5, 0xE9, 0x9C, 0x20, 0x03,
  32133. 0xE2, 0xC3, 0x59, 0xB1, 0xE6, 0x2D, 0xCB, 0x62,
  32134. 0x0C, 0x7A, 0x24, 0x6A, 0x7B, 0x9B, 0x32, 0x46,
  32135. 0x13, 0x15, 0x56, 0xF2, 0xF3, 0xD5, 0x13, 0xA2,
  32136. 0x3C, 0x6A, 0x9F, 0xD2, 0x28, 0x0E, 0xD6, 0x86,
  32137. 0xD7, 0x67, 0xCC, 0xD0, 0x17, 0x54, 0xEB, 0x4C,
  32138. 0x99, 0x69, 0x2F, 0x2B, 0x38, 0x0C, 0x36, 0x08,
  32139. 0x13, 0x44, 0xC1, 0xD3, 0x5E, 0xE1, 0x94, 0x97,
  32140. 0x36, 0xB6, 0x97, 0x6F, 0x48, 0x52, 0xCF, 0xBE,
  32141. 0x64, 0xFA, 0xBC, 0xF1, 0x1B, 0x9A, 0xFB, 0x82,
  32142. 0x85, 0x76, 0xB4, 0xF9, 0x78, 0x7A, 0xA7, 0xD0,
  32143. 0x3E, 0x84, 0x59, 0x8A, 0x71, 0x43, 0xEF, 0x73,
  32144. 0x11, 0xFA, 0xF2, 0x97, 0x0E, 0x23, 0xED, 0x4C,
  32145. 0x17, 0x3F, 0x98, 0x5D, 0x64, 0x50, 0x16, 0x5A,
  32146. 0xE3, 0xE2, 0x41, 0xA1, 0x82, 0x34, 0xE7, 0x4F,
  32147. 0xF3, 0xDD, 0xB9, 0x21, 0xA5, 0x30, 0x0B, 0x1C,
  32148. 0x4F, 0xB6, 0xE4, 0x32, 0xE6, 0x98, 0xF5, 0x3F,
  32149. 0x66, 0xE3, 0x8C, 0x07, 0xBC, 0xD6, 0xE7, 0x76,
  32150. 0x05, 0xDF, 0x46, 0x24, 0xD5, 0x79, 0x07, 0x62,
  32151. 0x92, 0xDE, 0x1C, 0xE6, 0xFC, 0x6F, 0x00, 0x81,
  32152. 0xA3, 0x8B, 0xD9, 0x2D, 0x39, 0xB2, 0x4B, 0x73,
  32153. 0xBA, 0xC1, 0xC5, 0x2B, 0xD6, 0x8E, 0x91, 0x81,
  32154. 0xD3, 0xDC, 0xD0, 0xAC, 0x75, 0x34, 0xDB, 0x48,
  32155. 0x90, 0x1E, 0x59, 0x84, 0xF9, 0x90, 0x25, 0x57,
  32156. 0xBF, 0xA2, 0x31, 0xB2, 0xEA, 0x28, 0xC3, 0x18,
  32157. 0x32, 0x62, 0xA1, 0xB2, 0x22, 0x1F, 0x74, 0x26,
  32158. 0xEA, 0x88, 0xA5, 0x81, 0x60, 0x93, 0xA5, 0xCA,
  32159. 0xE2, 0xCD, 0x5D, 0x59, 0xA9, 0x39, 0x0F, 0xC9,
  32160. 0x3A, 0x29, 0x56, 0x94, 0x4B, 0x06, 0x4C, 0xF0,
  32161. 0x13, 0xBC, 0xDB, 0x67, 0xFB, 0x42, 0x3D, 0x13,
  32162. 0x28, 0xD2, 0xC6, 0xD7, 0xBA, 0x32, 0x90, 0x13,
  32163. 0xFA, 0x2D, 0x30, 0xEF, 0xD6, 0x9F, 0xDC, 0xA1,
  32164. 0xA9, 0x5E, 0xA6, 0xD0, 0x6C, 0x73, 0x63, 0x53,
  32165. 0x4B, 0x2F, 0x3F, 0x7D, 0xAA, 0xFA, 0x29, 0x6E,
  32166. 0xAA, 0x09, 0xB3, 0x66, 0x8E, 0x9C, 0xF8, 0x2D,
  32167. 0x9B, 0xA9, 0x59, 0xB3, 0x2F, 0x3C, 0xAD, 0x3C,
  32168. 0x10, 0xC6, 0xEA, 0x48, 0x61, 0x15, 0x54, 0x53,
  32169. 0x9C, 0x37, 0xDF, 0x6B, 0xCA, 0x33, 0x85, 0xEA,
  32170. 0xD3, 0xFC, 0xFF, 0x96, 0xD3, 0x72, 0xB4, 0x23,
  32171. 0x93, 0xB7, 0x3C, 0x8D, 0xAA, 0xAA, 0x31, 0x50,
  32172. 0x6E, 0xE0, 0x52, 0x7B, 0x7F, 0xB3, 0xE5, 0x93,
  32173. 0xDC, 0xCC, 0xA5, 0x7C, 0x8F, 0xBB, 0xD4, 0xA3,
  32174. 0xC7, 0xF8, 0xA5, 0x38, 0x99, 0x86, 0x91, 0x32,
  32175. 0xFB, 0xC3, 0xE4, 0x05, 0x06, 0x07, 0xBB, 0xFE,
  32176. 0x29, 0xC6, 0x75, 0xE3, 0x94, 0x5E, 0x74, 0xA3,
  32177. 0x1C, 0xD5, 0x31, 0xBA, 0x7A, 0xEB, 0x2E, 0x2F,
  32178. 0x0C, 0xD9, 0x90, 0xB8, 0xF9, 0x83, 0xA9, 0x0D,
  32179. 0xFE, 0xA0, 0x56, 0x8F, 0x06, 0x77, 0xEA, 0x95,
  32180. 0x63, 0xF7, 0xC4, 0x79, 0xDE, 0x96, 0x89, 0x40,
  32181. 0xCF, 0x24, 0x29, 0x92, 0x69, 0x28, 0x65, 0xCF,
  32182. 0xDA, 0x89, 0xFA, 0x07, 0x8B, 0xBE, 0xF4, 0x9C,
  32183. 0xE4, 0x57, 0x5B, 0xDF, 0xB3, 0x80, 0x36, 0x60,
  32184. 0x11, 0xC8, 0x43, 0x5F, 0x12, 0xB4, 0x2D, 0x9A,
  32185. 0xB9, 0x9A, 0xB6, 0xA3, 0x19, 0x12, 0xC4, 0x35,
  32186. 0x41, 0x49, 0xD7, 0x23, 0x10, 0x1D, 0x13, 0x65,
  32187. 0xA6, 0x5E, 0x7C, 0xC6, 0x8D, 0x82, 0xE3, 0x05,
  32188. 0x17, 0x77, 0x39, 0x02, 0xFB, 0x38, 0xDD, 0xA2,
  32189. 0xB3, 0x24, 0xE7, 0x20, 0x8E, 0x98, 0x7E, 0xD2,
  32190. 0x87, 0xD0, 0x92, 0xE7, 0x66, 0x2A, 0x43, 0x02,
  32191. 0x41, 0xBF, 0xCA, 0x55, 0x2D, 0x31, 0x41, 0x27,
  32192. 0xE3, 0x8C, 0x85, 0x97, 0xA8, 0x95, 0x19, 0xD4,
  32193. 0xF1, 0xE6, 0x2A, 0x79, 0x46, 0x5A, 0xD5, 0xF4,
  32194. 0xEA, 0xA3, 0xFA, 0x77, 0xCD, 0x98, 0x32, 0x6D,
  32195. 0x2F, 0x92, 0xCE, 0x98, 0x52, 0x05, 0x5C, 0xEC,
  32196. 0xCF, 0x62, 0xD6, 0x3C, 0xB9, 0xD7, 0xF1, 0x98,
  32197. 0xAE, 0x08, 0x5E, 0x4D, 0x45, 0xC8, 0xE4, 0x8F,
  32198. 0xCF, 0xFE, 0x59, 0x3A, 0xD6, 0x52, 0xD9, 0x15,
  32199. 0x41, 0x67, 0xBF, 0x3E, 0x61, 0x95, 0x81, 0x0A,
  32200. 0x44, 0x5A, 0xE1, 0x58, 0xF1, 0xF9, 0xA6, 0x79,
  32201. 0x33, 0x63, 0xAF, 0xC1, 0xF2, 0x2C, 0xA8, 0x82,
  32202. 0xFE, 0xED, 0x3A, 0x5F, 0x57, 0x27, 0xCA, 0x76,
  32203. 0x47, 0x7C, 0x5F, 0x23, 0xF0, 0xFC, 0x87, 0x00,
  32204. 0xCD, 0xC6, 0xA5, 0xBC, 0xB2, 0xB2, 0x0B, 0x4F,
  32205. 0x92, 0x66, 0x35, 0x1D, 0x30, 0x4A, 0x96, 0xA8,
  32206. 0x2B, 0xF5, 0xF3, 0x14, 0xAF, 0x68, 0x5C, 0x1C,
  32207. 0x70, 0x7C, 0x92, 0xE3, 0xE8, 0x47, 0xB7, 0x04,
  32208. 0x7D, 0x68, 0x9C, 0x70, 0xB2, 0x5E, 0x55, 0x01,
  32209. 0xCA, 0xEC, 0x99, 0x19, 0x62, 0x6F, 0x4A, 0x0F,
  32210. 0xC8, 0x15, 0x86, 0xAF, 0x1E, 0xC8, 0x88, 0x89,
  32211. 0xB4, 0x23, 0x38, 0x7D, 0x5D, 0x95, 0x48, 0x26,
  32212. 0x18, 0xA6, 0x50, 0xE8, 0x0B, 0x53, 0xB0, 0x7C,
  32213. 0xAC, 0xE3, 0x22, 0x89, 0x40, 0x60, 0x2E, 0x3D,
  32214. 0xB4, 0x74, 0x66, 0xCE, 0x9B, 0xCC, 0xB6, 0xE4,
  32215. 0xD8, 0xAA, 0x61, 0xC8, 0x91, 0x25, 0x83, 0xE8,
  32216. 0x10, 0xB3, 0xB2, 0xE7, 0xE9, 0xCB, 0x48, 0xBD,
  32217. 0x40, 0x3E, 0xCF, 0x08, 0xD2, 0x8C, 0x70, 0xAE,
  32218. 0x0B, 0x62, 0x08, 0x59, 0xC1, 0xF0, 0x9B, 0x61,
  32219. 0x13, 0x14, 0x04, 0xC3, 0xD5, 0xBF, 0xFC, 0xD8,
  32220. 0x60, 0xE0, 0xF4, 0x2A, 0xB2, 0x99, 0x00, 0x62,
  32221. 0x30, 0xB2, 0x87, 0x6D, 0x77, 0xDD, 0xA9, 0x1C,
  32222. 0x8C, 0x62, 0xBD, 0x93, 0xA8, 0x44, 0xE4, 0xB3,
  32223. 0x44, 0xE3, 0x25, 0x5E, 0xEA, 0x53, 0x1C, 0x6C,
  32224. 0x45, 0x8D, 0x04, 0xAB, 0xDB, 0x0F, 0xAE, 0xF2,
  32225. 0xD1, 0xC0, 0xB4, 0xC5, 0x5F, 0x57, 0x0A, 0x5A,
  32226. 0x51, 0x02, 0x3F, 0x4D, 0x4E, 0xFF, 0xF5, 0x9F,
  32227. 0x9A, 0xBE, 0x17, 0x92, 0x2F, 0xE7, 0x32, 0xCA,
  32228. 0x71, 0xBC, 0xD4, 0x34, 0xAD, 0x77, 0x10, 0xB8,
  32229. 0x4C, 0xD4, 0xAC, 0x9F, 0x25, 0x07, 0xA0, 0x68,
  32230. 0x26, 0x56, 0x2A, 0xD7, 0xF6, 0x47, 0x82, 0x6F,
  32231. 0x9D, 0xBB, 0xE4, 0xED, 0xD2, 0x3F, 0x12, 0x43,
  32232. 0x69, 0xDB, 0x85, 0x26, 0xFC, 0x2B, 0x4D, 0x52,
  32233. 0xF0, 0x74, 0x14, 0x15, 0xF9, 0x72, 0xBE, 0xF6,
  32234. 0xA9, 0x35, 0xBD, 0x81, 0x2A, 0x56, 0xC8, 0x22,
  32235. 0x1B, 0x7D, 0xEF, 0x0F, 0x51, 0x06, 0xBC, 0x01,
  32236. 0xE9, 0x13, 0xE3, 0xD4, 0x3D, 0xB8, 0x6C, 0x2B,
  32237. 0xB4, 0xC7, 0xE0, 0x76, 0x26, 0x63, 0xC6, 0xDE,
  32238. 0x78, 0x87, 0x21, 0xC2, 0xAA, 0x07, 0xF8, 0x95,
  32239. 0x48, 0x87, 0xE2, 0x14, 0x2F, 0x2E, 0x91, 0x4A,
  32240. 0x09, 0x9E, 0xFC, 0x0A, 0xEE, 0x13, 0x39, 0x21,
  32241. 0x0D, 0x3E, 0x53, 0xDA, 0x3E, 0xCF, 0x88, 0x62,
  32242. 0x4B, 0x11, 0x19, 0xBE, 0x34, 0x01, 0x0B, 0x88,
  32243. 0x6C, 0x80, 0xF5, 0x1D, 0x18, 0x50, 0x83, 0x8F,
  32244. 0x21, 0x50, 0xE7, 0x2B, 0x04, 0x2A, 0xF3, 0x28,
  32245. 0x99, 0xC0, 0xD3, 0xD7, 0xB0, 0x2A, 0x57, 0xF8,
  32246. 0xCF, 0x26, 0x3A, 0x36, 0x95, 0x62, 0xE4, 0xE9,
  32247. 0x45, 0xA3, 0x12, 0x82, 0xA5, 0x02, 0xA9, 0x5E,
  32248. 0xE9, 0xBB, 0x03, 0x16, 0xC6, 0x86, 0x10, 0x06,
  32249. 0xDA, 0xC1, 0x7F, 0x93, 0x6F, 0x54, 0xC4, 0xC7
  32250. };
  32251. #endif /* WOLFSSL_NO_ML_DSA_87 */
  32252. #else
  32253. #ifndef WOLFSSL_NO_ML_DSA_44
  32254. static const byte seed_44[] = {
  32255. 0xBA, 0xC0, 0x59, 0x52, 0x75, 0x5B, 0x26, 0x47,
  32256. 0x01, 0xCA, 0x7D, 0x80, 0x6D, 0xFA, 0x08, 0x35,
  32257. 0x10, 0x28, 0xF6, 0x7B, 0x0E, 0x83, 0xC4, 0x24,
  32258. 0x01, 0x6F, 0x66, 0xCC, 0x83, 0x87, 0xD4, 0x69
  32259. };
  32260. static const byte pk_44[] = {
  32261. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32262. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32263. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32264. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32265. 0xED, 0x7E, 0xA9, 0xED, 0x2D, 0xED, 0x5A, 0x71,
  32266. 0xDD, 0xAE, 0x4A, 0x06, 0xE0, 0x2A, 0x5A, 0xAF,
  32267. 0x99, 0x69, 0x89, 0xC6, 0xAF, 0xE3, 0x2A, 0xFE,
  32268. 0x3D, 0x6E, 0x0A, 0x46, 0x71, 0x48, 0xD7, 0x17,
  32269. 0x99, 0x20, 0x01, 0x78, 0xD5, 0x8B, 0x40, 0xCB,
  32270. 0x81, 0xA0, 0x33, 0x38, 0xAE, 0x2B, 0x83, 0x4A,
  32271. 0xFD, 0x5F, 0xE0, 0xB7, 0xEE, 0xA0, 0xC4, 0x3D,
  32272. 0xB6, 0xA4, 0xD5, 0x59, 0x4B, 0xDD, 0x87, 0x1A,
  32273. 0xFC, 0x03, 0x30, 0xA0, 0xB3, 0xAD, 0x75, 0x3C,
  32274. 0xD4, 0x47, 0x72, 0x59, 0xCE, 0xB7, 0x80, 0xFD,
  32275. 0x34, 0x35, 0x5E, 0x96, 0xC8, 0x42, 0xD9, 0xDD,
  32276. 0x6C, 0xF1, 0xAB, 0xEF, 0x48, 0xD1, 0xA8, 0x02,
  32277. 0x02, 0x0F, 0x5B, 0x71, 0x4D, 0x36, 0x1E, 0x0D,
  32278. 0xC2, 0x09, 0x46, 0x7B, 0xF9, 0xEA, 0x24, 0x8F,
  32279. 0x7C, 0xCF, 0xB8, 0x9C, 0xF7, 0x49, 0x15, 0x8E,
  32280. 0x16, 0x49, 0x7E, 0xC5, 0x54, 0xF5, 0x03, 0x1D,
  32281. 0x16, 0x12, 0x02, 0x72, 0x1B, 0x38, 0x2D, 0x58,
  32282. 0x53, 0x15, 0x5E, 0xB6, 0x72, 0xCC, 0xA1, 0x09,
  32283. 0xB0, 0x2F, 0x10, 0xFA, 0x21, 0x45, 0x46, 0x37,
  32284. 0xD4, 0xFA, 0x7F, 0xFB, 0xB0, 0xD9, 0x20, 0xE2,
  32285. 0xCB, 0x56, 0xB3, 0x1E, 0xDF, 0x82, 0x67, 0x25,
  32286. 0x09, 0xD1, 0x8F, 0xFF, 0xE0, 0x43, 0xBD, 0x37,
  32287. 0x2B, 0x73, 0x0E, 0x13, 0x08, 0xC9, 0x49, 0x88,
  32288. 0x69, 0x69, 0xD9, 0x8C, 0x86, 0xE4, 0x7E, 0x63,
  32289. 0x35, 0xC5, 0xE1, 0xD0, 0x14, 0x9A, 0x89, 0x27,
  32290. 0x28, 0x17, 0xB0, 0x5B, 0x7A, 0x8F, 0xDD, 0x72,
  32291. 0x8B, 0x0A, 0x0D, 0x49, 0x58, 0x59, 0x2F, 0x0D,
  32292. 0x8F, 0x3D, 0x16, 0xCE, 0x7B, 0x11, 0xC7, 0x06,
  32293. 0x5D, 0xD5, 0x6D, 0x7B, 0x96, 0xED, 0x1E, 0x1A,
  32294. 0xF4, 0x10, 0x85, 0xDA, 0xDE, 0x84, 0x2F, 0x2B,
  32295. 0xBA, 0xFB, 0xA2, 0x5F, 0x33, 0x7D, 0x7C, 0x18,
  32296. 0x6B, 0xDF, 0x43, 0x3C, 0xE9, 0xEB, 0xB4, 0xC5,
  32297. 0x8E, 0x52, 0xF5, 0x7E, 0x4C, 0x3E, 0x6A, 0x33,
  32298. 0x41, 0x4C, 0x14, 0x05, 0x8E, 0x2C, 0x19, 0x0E,
  32299. 0x86, 0x91, 0x66, 0xDE, 0xF6, 0x4B, 0x35, 0xC2,
  32300. 0xDF, 0x3D, 0x4C, 0x7B, 0xC5, 0x58, 0x5E, 0x86,
  32301. 0x89, 0x6A, 0xFC, 0x86, 0x48, 0x75, 0xD1, 0x18,
  32302. 0xD1, 0xCB, 0x41, 0xC0, 0xF6, 0xD8, 0x87, 0x79,
  32303. 0xD9, 0xA2, 0x56, 0x2E, 0x83, 0x26, 0x11, 0xC1,
  32304. 0x4B, 0x53, 0x37, 0x85, 0x62, 0xFF, 0x6A, 0x67,
  32305. 0xFD, 0x18, 0x79, 0xD7, 0x55, 0x9B, 0xF7, 0x64,
  32306. 0xA9, 0x21, 0xB6, 0x1B, 0xF6, 0x11, 0x85, 0xF8,
  32307. 0xC0, 0x68, 0xDE, 0x61, 0x0C, 0x61, 0x7E, 0x8E,
  32308. 0xED, 0x9E, 0x58, 0x84, 0x16, 0x1A, 0x28, 0xC5,
  32309. 0x41, 0x63, 0xB3, 0xF0, 0x82, 0xAA, 0xE8, 0x36,
  32310. 0x81, 0x5C, 0xD3, 0xB7, 0xFB, 0x92, 0xF4, 0x7A,
  32311. 0x1E, 0x85, 0xA2, 0xB7, 0x21, 0xD5, 0xFA, 0xC8,
  32312. 0xE8, 0x02, 0x43, 0x5B, 0x56, 0x42, 0x03, 0x17,
  32313. 0x67, 0xEE, 0x3E, 0x31, 0x23, 0x63, 0xC7, 0x33,
  32314. 0x95, 0xDE, 0x07, 0xF6, 0x11, 0x3A, 0x2C, 0x3F,
  32315. 0x7B, 0xBB, 0x2D, 0x5C, 0x23, 0xF9, 0x2F, 0x9C,
  32316. 0x51, 0x19, 0x9F, 0x35, 0xC3, 0x18, 0x9F, 0x83,
  32317. 0x6E, 0xA8, 0x03, 0xF1, 0x79, 0x1F, 0xB0, 0xC8,
  32318. 0x2F, 0xF4, 0x2E, 0x9A, 0x26, 0xF3, 0x44, 0x02,
  32319. 0x8F, 0x45, 0x8B, 0xB0, 0x25, 0x1D, 0xF2, 0xD4,
  32320. 0x55, 0xB7, 0x65, 0xEF, 0xDB, 0x3D, 0x8E, 0x92,
  32321. 0xC8, 0xA0, 0x63, 0x4C, 0x38, 0xA3, 0x54, 0xD3,
  32322. 0xC2, 0x5A, 0x2A, 0x6A, 0x15, 0x27, 0x2A, 0xE2,
  32323. 0xFC, 0x25, 0xB6, 0xC8, 0x68, 0xEB, 0xED, 0x2D,
  32324. 0x23, 0xE8, 0x6D, 0x5C, 0xDD, 0x3F, 0x18, 0xB4,
  32325. 0x6E, 0x79, 0x36, 0xC9, 0x1C, 0xB4, 0x92, 0x41,
  32326. 0xAD, 0x35, 0xD4, 0x15, 0xE4, 0x64, 0x1C, 0x51,
  32327. 0xCB, 0x0C, 0x41, 0xB7, 0xFD, 0xC1, 0x09, 0x3E,
  32328. 0xD2, 0x4D, 0x38, 0x88, 0x77, 0x1C, 0x71, 0x91,
  32329. 0x74, 0xD3, 0x28, 0xE0, 0xCE, 0x9A, 0x11, 0x8D,
  32330. 0xBF, 0x4D, 0x8D, 0xF0, 0x44, 0xF6, 0x79, 0xFC,
  32331. 0x4C, 0xAD, 0x17, 0x88, 0xC0, 0x8C, 0x0B, 0x7A,
  32332. 0x90, 0x01, 0x53, 0x6C, 0x6B, 0x44, 0xF6, 0xE5,
  32333. 0x2E, 0xEC, 0x44, 0x4F, 0xB8, 0x9B, 0x10, 0xBE,
  32334. 0xCF, 0x55, 0x55, 0x29, 0x83, 0xB8, 0xD0, 0x25,
  32335. 0x5B, 0xCE, 0x8F, 0xA5, 0xB7, 0x6C, 0xA7, 0x47,
  32336. 0x65, 0xA9, 0xE9, 0x9B, 0xA5, 0xBC, 0x28, 0x1D,
  32337. 0x9F, 0x1F, 0x5E, 0x97, 0x42, 0x10, 0x84, 0x92,
  32338. 0xFB, 0x38, 0x0B, 0x2E, 0xAC, 0x79, 0x0A, 0x7D,
  32339. 0x00, 0x2C, 0x35, 0xD0, 0x54, 0x0D, 0x28, 0xE7,
  32340. 0xAB, 0x06, 0x02, 0xDA, 0x89, 0xA3, 0x06, 0x8E,
  32341. 0x13, 0x9A, 0xA7, 0xCA, 0x48, 0x09, 0xB0, 0x48,
  32342. 0x37, 0x08, 0xA7, 0x7D, 0xDA, 0xEB, 0x58, 0x64,
  32343. 0x39, 0xB3, 0xF3, 0xB2, 0x4C, 0x00, 0x4B, 0xCB,
  32344. 0x94, 0x36, 0xD4, 0x7C, 0x73, 0x45, 0xC8, 0x93,
  32345. 0xE5, 0x2A, 0x11, 0xF0, 0xEF, 0x0C, 0xED, 0x5F,
  32346. 0x8B, 0x0C, 0x86, 0xAD, 0x3A, 0x01, 0x07, 0x1A,
  32347. 0xC0, 0x34, 0xE8, 0x74, 0x21, 0x27, 0x73, 0x56,
  32348. 0x93, 0x76, 0x5D, 0x80, 0x59, 0xB4, 0xA4, 0xDC,
  32349. 0x80, 0xE7, 0xCE, 0x70, 0x0E, 0x0F, 0xEC, 0x56,
  32350. 0x42, 0x6E, 0x9C, 0x76, 0x3D, 0xF6, 0xB4, 0x41,
  32351. 0xE2, 0x3E, 0xAC, 0x25, 0xE7, 0x86, 0xA7, 0xA7,
  32352. 0x0A, 0x0D, 0x5D, 0x04, 0x1F, 0x45, 0xD4, 0x5B,
  32353. 0x42, 0x38, 0x4C, 0x60, 0xE7, 0xB7, 0x0D, 0xC7,
  32354. 0x28, 0x4F, 0xA5, 0x4E, 0x0C, 0x1B, 0xC4, 0xDA,
  32355. 0x50, 0x1A, 0xA0, 0x93, 0xAE, 0x10, 0x9A, 0x1A,
  32356. 0xC8, 0xC6, 0x56, 0xFC, 0x0A, 0xEA, 0x89, 0x3A,
  32357. 0x28, 0x21, 0xE9, 0x52, 0x9D, 0xEB, 0x07, 0x68,
  32358. 0xC1, 0x57, 0x32, 0x25, 0x1F, 0x93, 0x5D, 0x35,
  32359. 0xB2, 0x4B, 0x58, 0x30, 0xAF, 0x51, 0xC6, 0x7D,
  32360. 0x47, 0xD1, 0xA2, 0xAD, 0xDE, 0x75, 0x48, 0x84,
  32361. 0x74, 0x19, 0x74, 0x18, 0xA0, 0x2C, 0xD8, 0xB2,
  32362. 0xFE, 0x44, 0x78, 0x95, 0x6A, 0xBF, 0x56, 0x4D,
  32363. 0x20, 0x79, 0xE7, 0xE2, 0xE3, 0x56, 0x69, 0xB3,
  32364. 0xFA, 0xE1, 0xEB, 0xE6, 0x11, 0xAC, 0x18, 0xB3,
  32365. 0x98, 0xC1, 0x04, 0x20, 0x96, 0x4B, 0xAD, 0xDE,
  32366. 0x5B, 0x18, 0xEB, 0x7B, 0xBC, 0x15, 0x11, 0x57,
  32367. 0x29, 0x10, 0xE5, 0x80, 0x78, 0x4A, 0xF0, 0x87,
  32368. 0xF6, 0xD1, 0x3C, 0x23, 0xC5, 0xF4, 0x2D, 0xD7,
  32369. 0xAB, 0xA4, 0xD7, 0xB8, 0x45, 0x8E, 0x04, 0x1B,
  32370. 0x78, 0x59, 0x9F, 0x81, 0xE6, 0x04, 0xDF, 0x70,
  32371. 0x2B, 0x14, 0x74, 0x16, 0x49, 0xDA, 0xF0, 0xE1,
  32372. 0xC8, 0x29, 0xCC, 0x87, 0x8C, 0x2F, 0xFB, 0x18,
  32373. 0x3B, 0x47, 0xFC, 0x79, 0x04, 0x84, 0xCB, 0x0A,
  32374. 0xD2, 0x64, 0xBF, 0x86, 0xEA, 0x01, 0xAC, 0xE0,
  32375. 0xBD, 0xEC, 0x3B, 0xE1, 0xA7, 0x6C, 0xDE, 0x1D,
  32376. 0x58, 0x76, 0xCC, 0x53, 0x9E, 0xF6, 0xC6, 0xD4,
  32377. 0x2C, 0x87, 0x92, 0xA2, 0x89, 0x27, 0x31, 0x33,
  32378. 0x01, 0xA5, 0xA2, 0xE8, 0x8F, 0x13, 0x19, 0x0F,
  32379. 0xFD, 0x73, 0xB9, 0x91, 0xBD, 0xB8, 0x80, 0x9A,
  32380. 0xA3, 0xB1, 0x21, 0x6C, 0x91, 0x13, 0x8A, 0xAE,
  32381. 0xC7, 0xCB, 0x67, 0x14, 0xD1, 0xC0, 0x28, 0x89,
  32382. 0x04, 0x8C, 0x9F, 0xDE, 0xA0, 0x9A, 0x99, 0xA8,
  32383. 0x61, 0xE6, 0x8F, 0x8E, 0x39, 0xEF, 0x6B, 0x5E,
  32384. 0x84, 0x5F, 0x5D, 0x24, 0x37, 0x73, 0x9D, 0x75,
  32385. 0xC4, 0xEF, 0xE2, 0xA1, 0xF2, 0xBC, 0x0D, 0xE1,
  32386. 0x0D, 0xEC, 0xFA, 0xEE, 0xC1, 0x63, 0xC8, 0x2E,
  32387. 0x7D, 0x85, 0x65, 0xC3, 0xF2, 0x0D, 0x8B, 0x73,
  32388. 0xF9, 0x3B, 0x0B, 0x3D, 0x49, 0x8B, 0xFB, 0x16,
  32389. 0x5B, 0x75, 0x48, 0x9B, 0x56, 0x0A, 0x83, 0x4C,
  32390. 0x0D, 0x13, 0xB2, 0xB4, 0x25, 0xC7, 0x2C, 0xCB,
  32391. 0xA7, 0x9E, 0xCA, 0x41, 0x44, 0x14, 0x9A, 0x03,
  32392. 0xD3, 0x01, 0x8C, 0xB0, 0xD5, 0xA9, 0x36, 0xA4,
  32393. 0x16, 0x21, 0x49, 0x0A, 0x99, 0xA1, 0x89, 0xA5,
  32394. 0x91, 0x10, 0xA2, 0x1B, 0x3F, 0x98, 0x1E, 0x1C,
  32395. 0x43, 0xAA, 0x9C, 0x16, 0x5A, 0xF0, 0x18, 0x64,
  32396. 0x0F, 0x6A, 0xE3, 0x97, 0x83, 0x31, 0x4E, 0x84,
  32397. 0xC9, 0xEA, 0xD8, 0x9F, 0xEA, 0x9E, 0xD6, 0xF2,
  32398. 0x0E, 0x15, 0xA5, 0x48, 0x15, 0x8B, 0x10, 0x1D,
  32399. 0x77, 0x78, 0x1B, 0x54, 0x03, 0xC1, 0x2C, 0xB1,
  32400. 0xC8, 0x22, 0x11, 0x9D, 0xB8, 0x82, 0x94, 0x26,
  32401. 0xA0, 0xED, 0x6C, 0xAD, 0xA8, 0x03, 0xC2, 0xED,
  32402. 0x02, 0x74, 0x3E, 0x54, 0xBD, 0x77, 0xA6, 0x0B,
  32403. 0x37, 0xFE, 0x04, 0xCD, 0x25, 0x10, 0x2D, 0x52,
  32404. 0xC2, 0xD4, 0x5B, 0x9B, 0xAE, 0xFE, 0x35, 0x73,
  32405. 0x16, 0x61, 0x84, 0x25, 0x1D, 0xBE, 0x95, 0x34,
  32406. 0xA4, 0xF6, 0xB9, 0xA4, 0xF9, 0xAA, 0x5D, 0x1E,
  32407. 0x49, 0xBB, 0x19, 0xD9, 0x64, 0xD7, 0x48, 0x1A,
  32408. 0x0A, 0x93, 0xC3, 0x69, 0x13, 0x12, 0x68, 0xBB,
  32409. 0x97, 0x97, 0xBD, 0x99, 0x69, 0xCE, 0xE6, 0xF5,
  32410. 0x84, 0x7B, 0xCC, 0xE4, 0x7D, 0xD3, 0xCD, 0x8A,
  32411. 0x7A, 0x4B, 0x98, 0xF4, 0x09, 0x9D, 0xEA, 0x5D,
  32412. 0x4E, 0x1F, 0xE1, 0x1E, 0x6C, 0x48, 0xD3, 0x5E,
  32413. 0x67, 0xD9, 0xFF, 0x64, 0x4D, 0xA7, 0x64, 0x7A,
  32414. 0x01, 0xB2, 0xE9, 0x63, 0x14, 0x10, 0xB7, 0x08,
  32415. 0x0C, 0xF9, 0x4D, 0x66, 0x48, 0x46, 0xE3, 0xC2,
  32416. 0x48, 0x6B, 0x47, 0xCE, 0x00, 0x98, 0x92, 0x83,
  32417. 0xF7, 0xE0, 0x1F, 0x96, 0xFA, 0x53, 0xD5, 0x49,
  32418. 0x1C, 0xC7, 0x89, 0xB4, 0xA5, 0x4B, 0x63, 0xBF,
  32419. 0xD2, 0x00, 0x79, 0xDD, 0xC1, 0x60, 0xAA, 0xF2,
  32420. 0x0F, 0x47, 0xB9, 0x4F, 0x8A, 0x66, 0x05, 0x3D,
  32421. 0x96, 0x36, 0x64, 0x48, 0x5F, 0x7E, 0x56, 0x2B,
  32422. 0xB3, 0x47, 0xE2, 0x76, 0x64, 0x21, 0x65, 0x34,
  32423. 0xFC, 0xDD, 0x2D, 0x4C, 0xE2, 0x99, 0x33, 0x04,
  32424. 0xE4, 0x26, 0x15, 0x37, 0x6C, 0x32, 0xB9, 0x17
  32425. };
  32426. static const byte sk_44[] = {
  32427. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32428. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32429. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32430. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32431. 0x73, 0x61, 0x49, 0x01, 0x0F, 0x94, 0x08, 0x30,
  32432. 0x26, 0x02, 0x12, 0x63, 0x64, 0x15, 0x7A, 0x4D,
  32433. 0xBA, 0xF5, 0x25, 0xA7, 0xAA, 0x0B, 0x7C, 0x3D,
  32434. 0xCE, 0x05, 0x91, 0x95, 0xEF, 0x17, 0x2F, 0xE2,
  32435. 0x5A, 0x03, 0x5E, 0x2E, 0x4D, 0xFA, 0xE7, 0x5F,
  32436. 0xCD, 0x61, 0x34, 0xFB, 0x3D, 0x3C, 0x5C, 0x60,
  32437. 0x1A, 0x6F, 0x09, 0xB5, 0x9D, 0xDD, 0x90, 0x53,
  32438. 0xF6, 0x89, 0x50, 0xC2, 0xE1, 0xED, 0x0A, 0x61,
  32439. 0x8F, 0xFA, 0xDC, 0x2D, 0xB2, 0x8B, 0xA1, 0x56,
  32440. 0xAC, 0x5E, 0x0E, 0xF1, 0x3B, 0x1E, 0x22, 0x9F,
  32441. 0xAA, 0x05, 0x96, 0xA3, 0x5E, 0x44, 0x86, 0xA8,
  32442. 0xBA, 0x15, 0xD1, 0x11, 0x7D, 0xAA, 0xD0, 0xAA,
  32443. 0x01, 0x27, 0x25, 0x04, 0x82, 0x89, 0xA4, 0x22,
  32444. 0x2E, 0xDB, 0x80, 0x45, 0xD2, 0x30, 0x45, 0x59,
  32445. 0x16, 0x64, 0xE2, 0x08, 0x86, 0x50, 0x00, 0x8E,
  32446. 0xCA, 0x08, 0x51, 0x5A, 0x06, 0x01, 0x54, 0x82,
  32447. 0x20, 0xC4, 0x92, 0x30, 0x02, 0x21, 0x4E, 0x0A,
  32448. 0x93, 0x89, 0x84, 0xB8, 0x70, 0x24, 0x40, 0x51,
  32449. 0x24, 0xB3, 0x44, 0xDB, 0x08, 0x40, 0x1B, 0x37,
  32450. 0x44, 0x21, 0x22, 0x8E, 0x8C, 0x16, 0x42, 0x10,
  32451. 0x22, 0x0E, 0xA1, 0xB2, 0x8D, 0x18, 0x49, 0x30,
  32452. 0xC1, 0x32, 0x69, 0x21, 0x03, 0x8E, 0x49, 0x44,
  32453. 0x08, 0xD3, 0x16, 0x89, 0x10, 0xA4, 0x25, 0x5C,
  32454. 0x22, 0x8A, 0xC0, 0xC8, 0x08, 0xC1, 0x04, 0x6A,
  32455. 0xD2, 0xA0, 0x50, 0x8A, 0x02, 0x52, 0x92, 0x16,
  32456. 0x44, 0x54, 0x30, 0x4A, 0x92, 0x32, 0x0C, 0x4C,
  32457. 0x44, 0x2D, 0x04, 0x15, 0x2A, 0x99, 0x24, 0x42,
  32458. 0x52, 0xA8, 0x30, 0x53, 0x24, 0x85, 0x9A, 0xB8,
  32459. 0x01, 0xE2, 0x08, 0x09, 0x23, 0x28, 0x08, 0xC4,
  32460. 0x98, 0x85, 0x0B, 0xB9, 0x40, 0x60, 0x26, 0x28,
  32461. 0x0A, 0x45, 0x12, 0x0C, 0x43, 0x84, 0x82, 0x16,
  32462. 0x89, 0xC4, 0x48, 0x28, 0x58, 0x18, 0x2A, 0x20,
  32463. 0x07, 0x02, 0xD3, 0x82, 0x45, 0x50, 0xB0, 0x50,
  32464. 0x64, 0x36, 0x91, 0x52, 0x02, 0x45, 0x5A, 0x42,
  32465. 0x26, 0x01, 0x28, 0x71, 0xD4, 0x86, 0x10, 0x19,
  32466. 0xC4, 0x68, 0xC4, 0x30, 0x66, 0xE0, 0x02, 0x49,
  32467. 0x18, 0x34, 0x05, 0x04, 0x02, 0x04, 0x90, 0x94,
  32468. 0x4C, 0x01, 0xA7, 0x80, 0x12, 0x97, 0x08, 0x19,
  32469. 0xC5, 0x41, 0x24, 0xC1, 0x61, 0x08, 0xB0, 0x0C,
  32470. 0x21, 0xC1, 0x49, 0x9B, 0x42, 0x51, 0x62, 0x18,
  32471. 0x22, 0x54, 0x06, 0x06, 0x93, 0x26, 0x70, 0x49,
  32472. 0x86, 0x91, 0x00, 0x28, 0x6C, 0x02, 0xC9, 0x60,
  32473. 0x13, 0xC3, 0x09, 0xCB, 0x14, 0x66, 0x09, 0x17,
  32474. 0x25, 0x1C, 0x16, 0x89, 0x01, 0xB6, 0x01, 0x60,
  32475. 0x86, 0x71, 0x58, 0x96, 0x04, 0x82, 0x38, 0x61,
  32476. 0x43, 0x40, 0x72, 0xCC, 0x46, 0x71, 0x81, 0x20,
  32477. 0x2C, 0x18, 0x20, 0x6E, 0x03, 0x91, 0x11, 0x9A,
  32478. 0x08, 0x89, 0x43, 0x06, 0x48, 0x64, 0x02, 0x6C,
  32479. 0x21, 0x33, 0x8D, 0x48, 0x16, 0x66, 0x9B, 0xA4,
  32480. 0x2D, 0x01, 0x10, 0x66, 0xDC, 0xB0, 0x25, 0x40,
  32481. 0xA0, 0x24, 0xA2, 0xB4, 0x44, 0xC8, 0x26, 0x61,
  32482. 0x0A, 0x10, 0x4E, 0xD0, 0x04, 0x11, 0x4A, 0x82,
  32483. 0x51, 0x03, 0x04, 0x6C, 0x18, 0x88, 0x6C, 0xE0,
  32484. 0x98, 0x41, 0x11, 0x29, 0x06, 0x62, 0x12, 0x8E,
  32485. 0xDA, 0x42, 0x91, 0x09, 0x48, 0x60, 0xD1, 0xB4,
  32486. 0x80, 0x10, 0x30, 0x30, 0x80, 0x38, 0x82, 0xD0,
  32487. 0x84, 0x0D, 0x08, 0x14, 0x92, 0x24, 0x41, 0x40,
  32488. 0x0C, 0x10, 0x89, 0xCC, 0x38, 0x8A, 0x13, 0xB6,
  32489. 0x89, 0x1A, 0xA7, 0x24, 0x5C, 0x10, 0x12, 0x1B,
  32490. 0x21, 0x50, 0x91, 0xB4, 0x29, 0x99, 0xB6, 0x51,
  32491. 0x04, 0xB1, 0x91, 0x59, 0xA6, 0x05, 0x19, 0x08,
  32492. 0x4A, 0x4A, 0x84, 0x6C, 0x1C, 0x49, 0x02, 0x44,
  32493. 0x20, 0x85, 0x14, 0xB1, 0x89, 0x09, 0x44, 0x2C,
  32494. 0x10, 0x02, 0x22, 0xE1, 0xB4, 0x25, 0x01, 0x21,
  32495. 0x71, 0x53, 0xC2, 0x85, 0x82, 0x88, 0x28, 0xC0,
  32496. 0x02, 0x52, 0x19, 0xC5, 0x51, 0x19, 0xA5, 0x09,
  32497. 0xC0, 0x82, 0x91, 0x21, 0x47, 0x0D, 0x1C, 0x30,
  32498. 0x69, 0xDC, 0xB8, 0x6C, 0x04, 0x41, 0x6A, 0x91,
  32499. 0x16, 0x40, 0xA0, 0xC8, 0x24, 0x1A, 0x10, 0x01,
  32500. 0x04, 0x39, 0x25, 0x80, 0x16, 0x02, 0x63, 0x36,
  32501. 0x71, 0x90, 0xB0, 0x8D, 0x44, 0x16, 0x8E, 0xDA,
  32502. 0x16, 0x2E, 0xCB, 0x44, 0x20, 0x54, 0x38, 0x06,
  32503. 0x54, 0xC4, 0x01, 0x51, 0x40, 0x86, 0x52, 0x44,
  32504. 0x0E, 0x82, 0x02, 0x32, 0x21, 0x38, 0x89, 0x19,
  32505. 0x04, 0x40, 0xD8, 0x12, 0x68, 0x21, 0x98, 0x11,
  32506. 0x03, 0x33, 0x8A, 0x18, 0x00, 0x45, 0xCB, 0x22,
  32507. 0x32, 0xC3, 0x04, 0x46, 0x09, 0x18, 0x51, 0x22,
  32508. 0x44, 0x89, 0x13, 0x16, 0x6E, 0xDA, 0x46, 0x45,
  32509. 0x09, 0x19, 0x41, 0x81, 0x10, 0x01, 0xDC, 0x18,
  32510. 0x8E, 0xC8, 0x44, 0x4C, 0x00, 0x17, 0x82, 0x9C,
  32511. 0xA6, 0x4D, 0xC8, 0x08, 0x10, 0x24, 0x42, 0x6D,
  32512. 0x91, 0x38, 0x89, 0x8C, 0x40, 0x6E, 0x00, 0x35,
  32513. 0x11, 0xD3, 0x24, 0x09, 0x1A, 0x01, 0x65, 0x88,
  32514. 0x48, 0x45, 0x09, 0x01, 0x71, 0x43, 0xB8, 0x80,
  32515. 0x11, 0x82, 0x2C, 0x84, 0xB8, 0x49, 0x58, 0x14,
  32516. 0x28, 0x92, 0x20, 0x32, 0x09, 0x12, 0x05, 0x20,
  32517. 0x81, 0x2D, 0x5B, 0x86, 0x11, 0x04, 0x90, 0x45,
  32518. 0x49, 0x80, 0x40, 0xD1, 0xC8, 0x24, 0x98, 0xC2,
  32519. 0x2C, 0x99, 0xA2, 0x30, 0x04, 0x98, 0x8C, 0x53,
  32520. 0x24, 0x02, 0x8A, 0x04, 0x01, 0x4C, 0x28, 0x71,
  32521. 0xC3, 0x86, 0x6C, 0x24, 0x49, 0x81, 0x04, 0x02,
  32522. 0x28, 0x62, 0x44, 0x32, 0x61, 0x20, 0x28, 0x01,
  32523. 0x04, 0x11, 0x0C, 0x09, 0x08, 0x90, 0x98, 0x84,
  32524. 0x63, 0xB2, 0x45, 0x63, 0x38, 0x2E, 0x04, 0xA4,
  32525. 0x0C, 0x18, 0x05, 0x4E, 0xCC, 0x86, 0x90, 0x43,
  32526. 0x40, 0x91, 0x54, 0x02, 0x21, 0x43, 0x28, 0x42,
  32527. 0x23, 0x94, 0x29, 0xC8, 0xA6, 0x91, 0x02, 0x09,
  32528. 0x80, 0xE3, 0x82, 0x00, 0xC1, 0x34, 0x08, 0xD1,
  32529. 0x34, 0x84, 0x12, 0x45, 0x8C, 0x02, 0xC6, 0x81,
  32530. 0x41, 0xC6, 0x6C, 0x1B, 0x12, 0x24, 0x04, 0x08,
  32531. 0x0D, 0x02, 0x00, 0x0C, 0x9C, 0xA2, 0x05, 0x49,
  32532. 0x34, 0x65, 0x00, 0x06, 0x89, 0x88, 0x34, 0x00,
  32533. 0xD8, 0x82, 0x29, 0x92, 0x12, 0x91, 0xE3, 0x36,
  32534. 0x86, 0xD1, 0x80, 0x71, 0x98, 0xB0, 0x50, 0x48,
  32535. 0xC6, 0x11, 0x14, 0x80, 0x0D, 0xA0, 0x12, 0x4D,
  32536. 0x9B, 0xB2, 0x40, 0x21, 0x41, 0x50, 0x4B, 0x36,
  32537. 0x05, 0x52, 0x10, 0x26, 0x19, 0xB2, 0x60, 0x92,
  32538. 0xA2, 0x24, 0xCB, 0x08, 0x00, 0x14, 0x22, 0x49,
  32539. 0x5A, 0xD0, 0x55, 0xBD, 0x2B, 0x45, 0xE4, 0x31,
  32540. 0x41, 0xA8, 0xC3, 0xA3, 0xAD, 0xBD, 0xB6, 0x37,
  32541. 0x92, 0x06, 0x95, 0x6B, 0x3D, 0xD8, 0xE5, 0x33,
  32542. 0x71, 0xB6, 0x62, 0xB7, 0x67, 0x6C, 0x77, 0x84,
  32543. 0x63, 0x2F, 0x41, 0x1D, 0xBA, 0x51, 0x27, 0xE1,
  32544. 0x24, 0x5D, 0xC2, 0x38, 0x71, 0x65, 0x9E, 0x8E,
  32545. 0xE4, 0xEB, 0xBB, 0x1D, 0x89, 0xEB, 0x18, 0xCA,
  32546. 0x0C, 0xA6, 0x86, 0xA3, 0x4D, 0x7C, 0x7A, 0x02,
  32547. 0xAC, 0xDD, 0x34, 0xCE, 0x05, 0x3B, 0x1B, 0x49,
  32548. 0xF4, 0x6D, 0x12, 0x33, 0xBC, 0x52, 0x70, 0x59,
  32549. 0xDF, 0xBC, 0x5D, 0x49, 0x42, 0x6A, 0xED, 0xC7,
  32550. 0xF1, 0x8C, 0xF5, 0x6D, 0x1F, 0xBC, 0xE4, 0xBD,
  32551. 0x45, 0x5D, 0x59, 0xF8, 0xCE, 0x9A, 0x39, 0xB5,
  32552. 0x96, 0x32, 0xFD, 0x93, 0x65, 0x8E, 0x92, 0xF1,
  32553. 0x8F, 0xB0, 0x99, 0xF3, 0x80, 0x0F, 0x66, 0x14,
  32554. 0xFE, 0xEB, 0x23, 0x17, 0x2D, 0x4C, 0x8F, 0x41,
  32555. 0x9A, 0x9B, 0xD1, 0x5B, 0x5B, 0xC0, 0x3D, 0xA6,
  32556. 0x0E, 0xF3, 0xE0, 0xA1, 0x04, 0xDC, 0x24, 0x18,
  32557. 0x9D, 0x90, 0xC6, 0x89, 0x5A, 0x7F, 0x10, 0x1E,
  32558. 0x4B, 0x21, 0xEC, 0x91, 0xD8, 0x5D, 0x65, 0xDB,
  32559. 0xCF, 0x90, 0x62, 0x85, 0xE9, 0x58, 0xA3, 0x47,
  32560. 0x92, 0x1C, 0xD0, 0x0C, 0xA3, 0xF3, 0x3E, 0x36,
  32561. 0xDB, 0x24, 0xA6, 0x98, 0xAB, 0xA7, 0x89, 0x2B,
  32562. 0x71, 0x6C, 0x4D, 0x00, 0xB0, 0xD5, 0xA0, 0xCA,
  32563. 0x1A, 0x76, 0x8E, 0x80, 0xB7, 0xAE, 0x83, 0x89,
  32564. 0x50, 0xF8, 0xA7, 0x52, 0x8B, 0x94, 0xD2, 0x2B,
  32565. 0x9F, 0x49, 0x92, 0x3D, 0x54, 0x0D, 0xB8, 0xD1,
  32566. 0x19, 0x49, 0xAC, 0x91, 0xAF, 0xDB, 0xE9, 0x24,
  32567. 0x4D, 0xD8, 0xE1, 0xD5, 0x16, 0x0E, 0xB1, 0x39,
  32568. 0x40, 0x7D, 0x5F, 0xF5, 0x92, 0xB4, 0xAF, 0xC3,
  32569. 0x76, 0x2B, 0xDB, 0x7D, 0x52, 0x97, 0x62, 0x9F,
  32570. 0xCF, 0x32, 0x19, 0x5F, 0xE6, 0x32, 0xFB, 0x8E,
  32571. 0x39, 0x24, 0xB4, 0xEB, 0xE9, 0x17, 0x9E, 0x47,
  32572. 0x69, 0x4D, 0x92, 0x82, 0x96, 0x88, 0x38, 0x11,
  32573. 0xCE, 0xD6, 0xBF, 0x18, 0xE3, 0x51, 0x40, 0x81,
  32574. 0x11, 0xA0, 0x74, 0xDA, 0x0D, 0x5E, 0xEC, 0xD8,
  32575. 0x5D, 0x33, 0x22, 0x1E, 0xB9, 0x5D, 0xBF, 0x79,
  32576. 0xB0, 0xA1, 0xEF, 0xD1, 0x2D, 0xA0, 0x5F, 0xA1,
  32577. 0xC7, 0x6E, 0xD5, 0x08, 0xB8, 0xD0, 0xC1, 0x95,
  32578. 0x51, 0x9B, 0x07, 0xC3, 0x4A, 0x0A, 0xB5, 0xA1,
  32579. 0x28, 0xFE, 0x95, 0x95, 0x0A, 0xCF, 0x83, 0xA8,
  32580. 0xEB, 0x8F, 0xFB, 0x18, 0xD5, 0xBD, 0x69, 0x50,
  32581. 0xF1, 0xDF, 0x06, 0xFA, 0x9A, 0x65, 0x47, 0xBB,
  32582. 0x56, 0xE9, 0xCB, 0x8F, 0x69, 0x5F, 0xE0, 0xAD,
  32583. 0x19, 0x3A, 0x70, 0xE5, 0x66, 0x42, 0xD7, 0x1C,
  32584. 0x0C, 0xB4, 0x03, 0x89, 0x7D, 0x47, 0x4D, 0x29,
  32585. 0x67, 0x8C, 0x41, 0x73, 0xAB, 0x7D, 0xFD, 0x69,
  32586. 0x15, 0xAD, 0xE3, 0xB7, 0xF8, 0x98, 0x3B, 0xCA,
  32587. 0x8F, 0x27, 0x37, 0x7B, 0x72, 0x2C, 0x5F, 0x23,
  32588. 0x73, 0x15, 0xE2, 0xB6, 0xBD, 0xDE, 0x84, 0xF8,
  32589. 0x7E, 0x22, 0xB9, 0xFD, 0xD3, 0x4D, 0x62, 0x80,
  32590. 0xBA, 0xC5, 0x57, 0x29, 0x30, 0x1B, 0x06, 0x4D,
  32591. 0x20, 0xB1, 0x53, 0x86, 0xCB, 0x6A, 0x4A, 0xE3,
  32592. 0xC1, 0xA9, 0x88, 0xCF, 0xEB, 0x15, 0x2F, 0xA8,
  32593. 0xA8, 0x6F, 0xFC, 0x2A, 0xA8, 0x0E, 0xD9, 0xFA,
  32594. 0xEA, 0xD7, 0x3B, 0xCE, 0xF8, 0x5B, 0xD8, 0x92,
  32595. 0x22, 0x6A, 0x1A, 0x8E, 0x5E, 0x91, 0x37, 0x2C,
  32596. 0x21, 0x05, 0xC4, 0xAC, 0xF7, 0x62, 0x83, 0xBA,
  32597. 0x55, 0xD5, 0x2C, 0xCE, 0xA1, 0x19, 0x93, 0x0E,
  32598. 0xDE, 0xB6, 0xB8, 0x78, 0x0F, 0xBF, 0x4C, 0xA4,
  32599. 0x66, 0xAD, 0x97, 0x2F, 0xEE, 0x34, 0xE9, 0xA2,
  32600. 0xB6, 0x1D, 0x3C, 0x60, 0xFB, 0xB8, 0x7F, 0xF8,
  32601. 0xFD, 0x34, 0x8C, 0xC5, 0xC7, 0x38, 0x72, 0x74,
  32602. 0x19, 0xA9, 0xCF, 0x54, 0x49, 0x5B, 0xBA, 0x70,
  32603. 0x12, 0xC1, 0x61, 0xDC, 0x32, 0x61, 0x49, 0x66,
  32604. 0xF3, 0x57, 0xAA, 0x0F, 0xE6, 0x44, 0x9E, 0x8A,
  32605. 0x19, 0x9C, 0x6B, 0x63, 0x2C, 0x14, 0x1E, 0xDD,
  32606. 0x00, 0x27, 0xE3, 0x95, 0xE3, 0xE7, 0xD9, 0xFF,
  32607. 0x30, 0x2D, 0x14, 0x19, 0x4F, 0x49, 0x20, 0x0B,
  32608. 0x58, 0x2A, 0x23, 0x1C, 0xE2, 0xAD, 0x6B, 0x9C,
  32609. 0x7B, 0xB6, 0x20, 0x63, 0x08, 0x24, 0x55, 0x04,
  32610. 0x58, 0x1F, 0x0E, 0xBE, 0x2A, 0x6F, 0x79, 0x90,
  32611. 0x9E, 0x15, 0x8F, 0x4B, 0xDB, 0xE2, 0xBE, 0xBC,
  32612. 0x28, 0xB1, 0xC8, 0xFE, 0x00, 0x6D, 0x71, 0xCC,
  32613. 0x91, 0x6A, 0xCC, 0xF8, 0x12, 0x8B, 0xEC, 0xF3,
  32614. 0x46, 0x53, 0xB1, 0x7F, 0xB3, 0x79, 0xF0, 0xC7,
  32615. 0xD7, 0xA5, 0xCF, 0x2C, 0xC3, 0x09, 0x66, 0x82,
  32616. 0x53, 0x43, 0xFD, 0xAC, 0xDE, 0xD5, 0x85, 0xB3,
  32617. 0x79, 0x74, 0x55, 0xE8, 0xF6, 0xE5, 0xFB, 0xF0,
  32618. 0x63, 0x0C, 0x36, 0x63, 0x65, 0x10, 0x43, 0xC9,
  32619. 0x60, 0x99, 0xD6, 0x0C, 0xB9, 0x66, 0x1C, 0xA9,
  32620. 0x97, 0x4D, 0xDB, 0xA8, 0x13, 0x9E, 0xAE, 0xCA,
  32621. 0x7A, 0x5F, 0xE3, 0x24, 0xA0, 0xEE, 0x8A, 0x9D,
  32622. 0x7F, 0x03, 0x53, 0x21, 0x6B, 0xAF, 0x3D, 0xF9,
  32623. 0x38, 0xF3, 0x7A, 0x1D, 0xDA, 0xE2, 0xEF, 0xBA,
  32624. 0x86, 0x21, 0x85, 0x1F, 0x36, 0x08, 0x0B, 0xDA,
  32625. 0x37, 0x5A, 0x0A, 0xD7, 0x55, 0x41, 0xD5, 0x84,
  32626. 0x1B, 0x36, 0xA2, 0x50, 0x65, 0xD7, 0xF3, 0xA3,
  32627. 0xEB, 0xE1, 0xDE, 0x0F, 0x85, 0xAA, 0xF6, 0x2F,
  32628. 0xAB, 0xBB, 0xC8, 0xF1, 0x2A, 0xD1, 0x0A, 0x9B,
  32629. 0xE4, 0x7B, 0xBC, 0x4D, 0x42, 0xD8, 0xA3, 0x4C,
  32630. 0x07, 0x6A, 0x60, 0x3E, 0xE2, 0xDA, 0xE7, 0x00,
  32631. 0xDF, 0x27, 0x94, 0xEF, 0x90, 0x99, 0x88, 0x2C,
  32632. 0xCF, 0xAA, 0xE1, 0x71, 0x2D, 0xFD, 0x00, 0x9C,
  32633. 0x55, 0xBF, 0xC4, 0x7A, 0x55, 0xE9, 0xE0, 0xB4,
  32634. 0x7F, 0x3D, 0xE9, 0xB0, 0x01, 0xA7, 0x27, 0x23,
  32635. 0x27, 0x58, 0x31, 0x0E, 0x8E, 0x80, 0xD8, 0xEB,
  32636. 0x64, 0xA0, 0xC3, 0xC9, 0xEA, 0x69, 0x9C, 0x74,
  32637. 0x5E, 0xAF, 0xD5, 0xEF, 0x5C, 0x4E, 0x40, 0x71,
  32638. 0xD6, 0x57, 0x77, 0xE2, 0xAF, 0x0E, 0x1D, 0xB8,
  32639. 0x5A, 0x91, 0x20, 0x4C, 0x33, 0x4D, 0xD8, 0x4F,
  32640. 0x98, 0xE0, 0x86, 0x1D, 0x02, 0xA0, 0xDA, 0x06,
  32641. 0x17, 0xC4, 0x5D, 0x2E, 0x49, 0x31, 0xE6, 0xE4,
  32642. 0xDC, 0x18, 0x23, 0x26, 0xF3, 0x61, 0xF5, 0x8D,
  32643. 0x26, 0x2C, 0x18, 0x4C, 0xDF, 0x71, 0x90, 0x24,
  32644. 0x96, 0xD3, 0xD4, 0x1A, 0x6F, 0x08, 0xAB, 0x29,
  32645. 0x7D, 0xFF, 0x4E, 0x27, 0x6D, 0x39, 0x83, 0x17,
  32646. 0x90, 0xA4, 0x07, 0x8A, 0xDE, 0x79, 0x53, 0xF6,
  32647. 0x99, 0x2E, 0xA6, 0x39, 0x47, 0xC3, 0xBE, 0x12,
  32648. 0xC7, 0xA5, 0x7E, 0xA2, 0x19, 0x57, 0x04, 0x45,
  32649. 0xBE, 0x44, 0x62, 0x92, 0xCA, 0x56, 0xE1, 0xF0,
  32650. 0x45, 0x3B, 0xA4, 0xF8, 0xF5, 0xCD, 0xC7, 0xD2,
  32651. 0xB2, 0x46, 0x57, 0x51, 0x0B, 0x06, 0xDA, 0x54,
  32652. 0x03, 0x9E, 0x52, 0xA2, 0x78, 0x69, 0x25, 0x2E,
  32653. 0x75, 0x83, 0x25, 0x3F, 0xA3, 0x62, 0x27, 0xB9,
  32654. 0xA6, 0x59, 0x7A, 0xB1, 0xB6, 0xE9, 0xC1, 0xDD,
  32655. 0x2F, 0x22, 0x2D, 0x3B, 0xA3, 0x22, 0xD6, 0x11,
  32656. 0x7B, 0x08, 0x27, 0x92, 0x83, 0x7A, 0x5D, 0x0D,
  32657. 0x6B, 0x9D, 0x5B, 0xEB, 0xE9, 0xC0, 0x88, 0xDE,
  32658. 0x44, 0x55, 0xBA, 0x69, 0xC1, 0x7A, 0x4D, 0xE6,
  32659. 0x35, 0x67, 0x6F, 0x99, 0x9B, 0x07, 0xD8, 0x04,
  32660. 0xAA, 0xEA, 0x7D, 0xFF, 0x8E, 0xB8, 0xAA, 0x4C,
  32661. 0x79, 0xE2, 0x88, 0xA8, 0x1D, 0xE8, 0xA6, 0x77,
  32662. 0xCA, 0x06, 0xC0, 0xDF, 0x0E, 0x2B, 0xCB, 0xFF,
  32663. 0x9F, 0x64, 0x67, 0x11, 0xF1, 0xB9, 0x38, 0x83,
  32664. 0x19, 0x05, 0x30, 0x9B, 0x01, 0x11, 0x55, 0x03,
  32665. 0xAD, 0x44, 0x7D, 0x3C, 0x07, 0xEF, 0x88, 0x19,
  32666. 0x92, 0xC0, 0xFE, 0xE1, 0xAB, 0xDB, 0x24, 0x18,
  32667. 0x17, 0xD0, 0x03, 0x5C, 0x91, 0xD4, 0xA6, 0x2A,
  32668. 0xF1, 0xE9, 0x72, 0x62, 0x58, 0x22, 0x7D, 0x55,
  32669. 0x15, 0xE2, 0xA1, 0x70, 0x14, 0x5E, 0x34, 0xB9,
  32670. 0x5A, 0xB7, 0x5D, 0x3F, 0xB8, 0xB5, 0x45, 0x44,
  32671. 0xD2, 0x50, 0xD1, 0xC6, 0x7E, 0xE7, 0x3D, 0xF4,
  32672. 0xD3, 0xEC, 0xFB, 0x97, 0x32, 0x11, 0x72, 0x51,
  32673. 0xB7, 0x4A, 0xC8, 0x38, 0x96, 0xFC, 0x6F, 0x69,
  32674. 0xC2, 0xD5, 0xD3, 0x28, 0xE9, 0x63, 0x14, 0x14,
  32675. 0xFE, 0xB1, 0xA4, 0x02, 0x80, 0x65, 0x73, 0xD3,
  32676. 0x57, 0x07, 0x95, 0x21, 0x40, 0x00, 0x77, 0xA7,
  32677. 0x6D, 0x44, 0x2B, 0x0D, 0x77, 0x07, 0x92, 0x64,
  32678. 0xD4, 0x3A, 0xE2, 0x7F, 0xF2, 0x1C, 0x14, 0x08,
  32679. 0x60, 0x74, 0x8F, 0xFC, 0x0B, 0xE8, 0xEC, 0xA9,
  32680. 0xB7, 0x97, 0xA7, 0x85, 0x8A, 0xEF, 0xD7, 0x7E,
  32681. 0xD5, 0x15, 0xF7, 0x45, 0x8D, 0x9C, 0xBF, 0x23,
  32682. 0xEB, 0x8C, 0x4D, 0xD2, 0x28, 0x7E, 0x0A, 0x61,
  32683. 0x2E, 0xBA, 0xBE, 0x89, 0x1D, 0x64, 0x45, 0x22,
  32684. 0x70, 0x9D, 0x48, 0xEB, 0x2F, 0x96, 0xF1, 0xA7,
  32685. 0xDE, 0xD3, 0x28, 0x4C, 0xC9, 0xFB, 0xF2, 0x9C,
  32686. 0x5B, 0xFC, 0xBE, 0xBE, 0xF4, 0x38, 0xC9, 0x43,
  32687. 0xC3, 0x66, 0x53, 0xA9, 0x06, 0xE5, 0x71, 0x16,
  32688. 0xA4, 0xBB, 0x3B, 0x50, 0x53, 0xCF, 0xF4, 0x1F,
  32689. 0xD6, 0x00, 0x07, 0x46, 0xFB, 0x97, 0x0B, 0xF9,
  32690. 0x3D, 0xF4, 0xC6, 0x60, 0xD0, 0x37, 0x70, 0xC0,
  32691. 0x2D, 0xD1, 0x9F, 0xA5, 0x78, 0xF3, 0x1F, 0x03,
  32692. 0x81, 0xB1, 0x93, 0xBA, 0xE5, 0x82, 0xE6, 0xD1,
  32693. 0x66, 0x93, 0x83, 0x5B, 0xB9, 0xAD, 0xD9, 0x01,
  32694. 0xA5, 0xB6, 0x5C, 0x69, 0x82, 0xD7, 0x2F, 0x35,
  32695. 0x35, 0x98, 0xEE, 0xE9, 0xA0, 0x74, 0xC1, 0x91,
  32696. 0x44, 0x0A, 0x04, 0xCD, 0x97, 0xBE, 0x6B, 0x60,
  32697. 0x90, 0x9A, 0x48, 0x7B, 0x83, 0xA2, 0x28, 0x97,
  32698. 0xB5, 0xBA, 0xB1, 0x4D, 0x35, 0x8B, 0x34, 0x0A,
  32699. 0xA1, 0xCB, 0xA5, 0xC2, 0xA4, 0x6A, 0x36, 0xB3,
  32700. 0x12, 0x46, 0x59, 0xDB, 0x63, 0xE5, 0xF9, 0xF1,
  32701. 0x7F, 0xAD, 0x42, 0xF4, 0x24, 0xF0, 0x02, 0x3D,
  32702. 0x1E, 0x6C, 0xD5, 0xB3, 0x06, 0x8F, 0x1F, 0x59,
  32703. 0x79, 0xCC, 0xF9, 0x5B, 0x4F, 0x8B, 0xD6, 0x03,
  32704. 0xC7, 0x53, 0xE6, 0xCE, 0xBB, 0xD8, 0x52, 0x89,
  32705. 0x70, 0x5D, 0x98, 0x86, 0xA5, 0x9E, 0x44, 0xA9,
  32706. 0xC8, 0x17, 0xA2, 0x6F, 0x43, 0x2D, 0x8D, 0xA7,
  32707. 0xDE, 0x3E, 0xFA, 0xE7, 0x98, 0x7B, 0xB5, 0xBE,
  32708. 0x7B, 0x10, 0xB8, 0xB8, 0xA5, 0x3D, 0x3E, 0xCD,
  32709. 0x94, 0x19, 0x5E, 0x06, 0x51, 0xB8, 0x58, 0x1E,
  32710. 0x0E, 0xCF, 0xFE, 0xE5, 0xED, 0x84, 0xB5, 0xF5,
  32711. 0x0F, 0x34, 0x32, 0xAC, 0x0A, 0x7F, 0x03, 0xF0,
  32712. 0xF8, 0xFC, 0x69, 0xA0, 0x26, 0x0D, 0x2E, 0xFA,
  32713. 0x62, 0x49, 0x5C, 0xC4, 0xE5, 0xF6, 0x8B, 0xC5,
  32714. 0x26, 0x21, 0x23, 0x3B, 0xBD, 0x9A, 0x23, 0x95,
  32715. 0x69, 0xA7, 0x48, 0x94, 0x30, 0x1E, 0xC3, 0x82,
  32716. 0xB6, 0x75, 0x30, 0xA6, 0xF3, 0x1E, 0xBB, 0xBC,
  32717. 0xF7, 0x21, 0x27, 0x12, 0x2C, 0x51, 0x50, 0x55,
  32718. 0x87, 0x0D, 0xF1, 0xCC, 0x6C, 0xFF, 0xEA, 0x7E,
  32719. 0x2C, 0xDA, 0x8B, 0x9B, 0x20, 0xF4, 0x75, 0xFB,
  32720. 0xC2, 0x3F, 0xBE, 0x09, 0xA6, 0xC9, 0x26, 0xE7,
  32721. 0xB5, 0xC7, 0xE6, 0xB9, 0x35, 0x8C, 0xAF, 0xFA,
  32722. 0xC0, 0x8D, 0x43, 0x33, 0x25, 0xBA, 0xAA, 0xDC,
  32723. 0xCF, 0xBC, 0xE4, 0xC4, 0xC6, 0x26, 0x4A, 0x0D,
  32724. 0x9D, 0xCC, 0x2A, 0xE0, 0x5B, 0x1E, 0xC9, 0x78,
  32725. 0xF8, 0xA2, 0xB5, 0x46, 0xE5, 0x49, 0xB8, 0x4C,
  32726. 0xC2, 0x22, 0x40, 0xCE, 0x97, 0x9A, 0x95, 0x40,
  32727. 0xF7, 0xD6, 0x52, 0x54, 0x3B, 0xBB, 0x42, 0xC5,
  32728. 0x6F, 0x00, 0x7F, 0x83, 0xDD, 0x88, 0x71, 0xF7,
  32729. 0xD4, 0x1B, 0x3D, 0x81, 0xC4, 0xB1, 0x49, 0x9B,
  32730. 0xF3, 0x68, 0x15, 0xC5, 0x15, 0x97, 0x0F, 0xC5,
  32731. 0x43, 0xDD, 0x07, 0xBE, 0x98, 0x43, 0x2C, 0xB3,
  32732. 0xEF, 0x08, 0xCA, 0xDC, 0x9C, 0x27, 0x58, 0xFE,
  32733. 0x49, 0xE9, 0x77, 0xD9, 0x1C, 0x62, 0xA4, 0xA2,
  32734. 0xF9, 0x78, 0xCC, 0xB3, 0x21, 0x06, 0x10, 0xDE,
  32735. 0x5A, 0x52, 0xA3, 0x67, 0xBD, 0x5E, 0xBC, 0x9B,
  32736. 0x4E, 0x40, 0x87, 0x93, 0xCF, 0x0E, 0x27, 0x0E,
  32737. 0xE3, 0x11, 0x4B, 0xB3, 0xE0, 0xCE, 0x24, 0xB6,
  32738. 0x0A, 0x53, 0x03, 0xF8, 0x01, 0x6A, 0x7E, 0xFE,
  32739. 0xC8, 0x66, 0x9F, 0x29, 0xF3, 0x45, 0x94, 0xD6,
  32740. 0x0E, 0x30, 0xB5, 0x61, 0xA9, 0xEC, 0x8F, 0x71,
  32741. 0xF7, 0x36, 0xD6, 0x43, 0x4B, 0x0C, 0xCD, 0x45,
  32742. 0xBB, 0xA4, 0xBD, 0xE9, 0xA9, 0xC3, 0xC1, 0x95,
  32743. 0x1E, 0xF9, 0x42, 0x07, 0x18, 0xEA, 0xF5, 0x0B,
  32744. 0x27, 0xB6, 0xDE, 0xEF, 0x67, 0x33, 0x83, 0x0D,
  32745. 0xD9, 0x5E, 0x3A, 0x93, 0xD2, 0xD0, 0xDB, 0xB9,
  32746. 0x98, 0xF0, 0x25, 0x21, 0xF3, 0xDF, 0x0B, 0x1E
  32747. };
  32748. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  32749. #ifndef WOLFSSL_NO_ML_DSA_65
  32750. static const byte seed_65[] = {
  32751. 0x41, 0xAF, 0x98, 0x7B, 0x02, 0x6E, 0x47, 0x5F,
  32752. 0x37, 0x91, 0x7F, 0x2A, 0x6A, 0x9A, 0x87, 0xE7,
  32753. 0x51, 0xAD, 0xF9, 0x5B, 0x92, 0x7F, 0x2D, 0xCE,
  32754. 0xF0, 0xD4, 0xF3, 0xDA, 0x8F, 0x8C, 0x86, 0x6B
  32755. };
  32756. static const byte pk_65[] = {
  32757. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  32758. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  32759. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  32760. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  32761. 0x39, 0x5D, 0xF9, 0x20, 0x6C, 0x36, 0x0D, 0x4F,
  32762. 0x83, 0x43, 0xBE, 0x86, 0xEF, 0x6C, 0x43, 0xD0,
  32763. 0x3E, 0xD0, 0x63, 0x0A, 0x5B, 0x92, 0x8D, 0x31,
  32764. 0x19, 0x1D, 0xA9, 0x51, 0x61, 0x48, 0xE6, 0x26,
  32765. 0x50, 0x07, 0x54, 0x9B, 0xB0, 0xB7, 0x62, 0x54,
  32766. 0xDB, 0x80, 0x4E, 0x48, 0x7F, 0x48, 0xC5, 0x11,
  32767. 0x91, 0xFC, 0xA9, 0x26, 0x25, 0x08, 0xA5, 0x99,
  32768. 0xA0, 0x3C, 0xB9, 0x0C, 0xCF, 0x6C, 0xCD, 0x83,
  32769. 0x9A, 0x38, 0x6D, 0x22, 0xDE, 0x0A, 0xC3, 0x8F,
  32770. 0xF7, 0xD0, 0x57, 0x40, 0x53, 0xE9, 0xE9, 0x4E,
  32771. 0x73, 0xFA, 0x58, 0x40, 0x9F, 0x6D, 0x8A, 0xD3,
  32772. 0x6F, 0x86, 0x84, 0x4D, 0x18, 0xD7, 0x4C, 0x76,
  32773. 0x39, 0x57, 0x9E, 0xC0, 0xC7, 0xE4, 0xEE, 0x54,
  32774. 0xF4, 0xAD, 0x10, 0xC5, 0x69, 0x59, 0xE0, 0xBC,
  32775. 0x9B, 0xF4, 0x20, 0x8F, 0xBA, 0x0A, 0x94, 0x10,
  32776. 0x55, 0x07, 0x7E, 0xD1, 0xF9, 0x20, 0xCC, 0x2F,
  32777. 0xA9, 0xAE, 0x9D, 0xF5, 0xE4, 0x29, 0x40, 0x7E,
  32778. 0x44, 0xA4, 0xDF, 0xB2, 0xE9, 0x25, 0xE0, 0xBA,
  32779. 0x8D, 0x6C, 0x33, 0x88, 0x9C, 0xEE, 0x27, 0xDB,
  32780. 0xC7, 0x0A, 0x6E, 0x5A, 0x08, 0x92, 0x9B, 0x53,
  32781. 0xF8, 0xFD, 0xF9, 0x5B, 0xEB, 0x03, 0x8E, 0x45,
  32782. 0xCB, 0x91, 0x19, 0x4E, 0x6B, 0x1E, 0xA0, 0xA4,
  32783. 0xF0, 0x43, 0xC9, 0x8F, 0xDF, 0x93, 0x5E, 0x86,
  32784. 0xB0, 0x09, 0xD3, 0x47, 0x38, 0x7C, 0x8E, 0x78,
  32785. 0x85, 0x71, 0x3D, 0x07, 0x2E, 0x2E, 0x12, 0x6F,
  32786. 0x06, 0x97, 0x0E, 0x54, 0xAD, 0x71, 0x09, 0xEF,
  32787. 0xA5, 0x55, 0x0A, 0x39, 0x86, 0xE6, 0x17, 0x17,
  32788. 0x70, 0x9A, 0xA7, 0xA7, 0x1B, 0xCE, 0x78, 0x06,
  32789. 0x2C, 0x61, 0x1A, 0xB9, 0x48, 0x22, 0x41, 0x45,
  32790. 0x15, 0xEB, 0x10, 0x3C, 0x6E, 0x24, 0x37, 0xA4,
  32791. 0xB5, 0xE8, 0x82, 0x4D, 0x6D, 0xCC, 0x44, 0xC6,
  32792. 0xB0, 0x5D, 0xBE, 0x46, 0xDA, 0x5F, 0x00, 0x36,
  32793. 0x5B, 0xBD, 0x87, 0x65, 0x3A, 0x96, 0x21, 0x58,
  32794. 0x45, 0x65, 0xDB, 0xD8, 0x77, 0x76, 0x7B, 0x25,
  32795. 0xC3, 0x78, 0x6E, 0xD9, 0x14, 0xA7, 0x19, 0x69,
  32796. 0x4F, 0xBB, 0x1B, 0xDB, 0x37, 0xCE, 0xAF, 0x8C,
  32797. 0x88, 0x2E, 0x9E, 0x30, 0xF6, 0xAE, 0x43, 0xCC,
  32798. 0x59, 0x0F, 0x67, 0x8A, 0xCB, 0x4F, 0x08, 0x20,
  32799. 0x6D, 0x99, 0xD7, 0xA9, 0xDE, 0xE5, 0xE5, 0xB3,
  32800. 0xFF, 0xAA, 0x45, 0x3C, 0xF1, 0xE3, 0x02, 0x7D,
  32801. 0x2F, 0xEE, 0x69, 0x04, 0x81, 0x73, 0x01, 0x37,
  32802. 0x51, 0x68, 0xC8, 0x0B, 0x51, 0xFD, 0x05, 0xB4,
  32803. 0x05, 0xBB, 0xA1, 0xDB, 0x1D, 0xF6, 0x5F, 0x70,
  32804. 0xD3, 0x0A, 0x37, 0x4B, 0x9C, 0xC4, 0x45, 0x30,
  32805. 0x11, 0x36, 0xE2, 0x48, 0x9F, 0xC4, 0x2E, 0x4E,
  32806. 0x0C, 0x0C, 0xA1, 0x04, 0x41, 0x75, 0x95, 0xAA,
  32807. 0xED, 0xAC, 0xD4, 0xB2, 0xE7, 0x85, 0x7E, 0xE1,
  32808. 0xA6, 0xFE, 0x2A, 0x09, 0x19, 0x09, 0x3D, 0x7C,
  32809. 0x20, 0x1E, 0x98, 0x3D, 0x6E, 0x02, 0xC1, 0xCA,
  32810. 0xBB, 0x24, 0x82, 0x9F, 0x45, 0x1D, 0x26, 0x99,
  32811. 0xAE, 0x02, 0x82, 0xF9, 0x86, 0x3B, 0x67, 0x8C,
  32812. 0xBD, 0xFE, 0xF1, 0xD0, 0xB6, 0xB8, 0xAB, 0x00,
  32813. 0x0F, 0xEC, 0x30, 0xDC, 0x27, 0x58, 0xE2, 0x29,
  32814. 0x18, 0x05, 0x5A, 0x66, 0xA5, 0x88, 0x39, 0x8E,
  32815. 0x49, 0x5B, 0xB9, 0x52, 0x43, 0x84, 0xDC, 0xA9,
  32816. 0x50, 0x2B, 0x83, 0x3C, 0x84, 0x81, 0x37, 0x52,
  32817. 0x30, 0x79, 0xBD, 0x04, 0xB8, 0xDD, 0x47, 0xC1,
  32818. 0x02, 0x2E, 0xEC, 0x24, 0xD0, 0x56, 0x23, 0xE1,
  32819. 0x92, 0xD0, 0x65, 0x7F, 0xC7, 0xC2, 0xF7, 0x60,
  32820. 0x73, 0xB8, 0xAF, 0x0A, 0xF4, 0xEF, 0xFC, 0x1B,
  32821. 0xC2, 0xB9, 0x76, 0x87, 0x8A, 0xA6, 0xC2, 0x3F,
  32822. 0xD3, 0x9F, 0x1F, 0x2D, 0x94, 0xBC, 0x89, 0x4E,
  32823. 0x31, 0x8D, 0x28, 0xD0, 0x90, 0xB5, 0x5B, 0x60,
  32824. 0x30, 0xC6, 0x0B, 0x37, 0x63, 0x5D, 0xDC, 0xC6,
  32825. 0xE0, 0x1A, 0xBA, 0x6B, 0x23, 0xCD, 0x2E, 0x09,
  32826. 0x2D, 0x6A, 0x7E, 0x0C, 0xD9, 0x4F, 0xB1, 0xE2,
  32827. 0x89, 0x67, 0xE7, 0xB1, 0x54, 0x08, 0xB2, 0xFA,
  32828. 0x83, 0x43, 0x7C, 0x77, 0x06, 0xED, 0xE2, 0x29,
  32829. 0x53, 0xB7, 0x09, 0xC4, 0x1B, 0x81, 0x55, 0x12,
  32830. 0x41, 0x8E, 0x8B, 0x03, 0x36, 0xEE, 0x45, 0x70,
  32831. 0x57, 0xA8, 0x73, 0xEF, 0x70, 0x7B, 0x1F, 0x63,
  32832. 0xB0, 0xE8, 0x00, 0xBD, 0x1E, 0xE6, 0xA9, 0x93,
  32833. 0x9D, 0x03, 0x19, 0x22, 0xDF, 0xE1, 0x01, 0xF2,
  32834. 0xA9, 0x6B, 0x90, 0x5C, 0xD2, 0xC1, 0xAC, 0x9F,
  32835. 0xB2, 0x21, 0x1C, 0x2D, 0xC6, 0x80, 0x9A, 0xB5,
  32836. 0x1E, 0x46, 0x95, 0x6C, 0xCE, 0x47, 0x3E, 0x67,
  32837. 0xCD, 0xD6, 0xC9, 0xB9, 0x81, 0x74, 0x7F, 0x17,
  32838. 0xA3, 0xF7, 0x48, 0x99, 0xF3, 0x36, 0x84, 0xF3,
  32839. 0x16, 0x41, 0x55, 0x5F, 0xA7, 0xBF, 0x4B, 0x69,
  32840. 0x8D, 0xA3, 0x3D, 0x1E, 0xEA, 0xF5, 0x1E, 0xC6,
  32841. 0xB8, 0x1C, 0xD6, 0x89, 0x45, 0x68, 0xFA, 0xE7,
  32842. 0xCA, 0x86, 0xE4, 0xB1, 0xC9, 0x9C, 0xB2, 0xAB,
  32843. 0x89, 0x03, 0xE7, 0x19, 0x7B, 0xA9, 0xF2, 0x6B,
  32844. 0x4A, 0x43, 0x1D, 0x90, 0xAF, 0xA4, 0xE3, 0xBC,
  32845. 0xEF, 0xD4, 0x37, 0xC5, 0x55, 0x5C, 0x9E, 0x14,
  32846. 0xC6, 0x18, 0xDD, 0x45, 0x3F, 0x80, 0x49, 0x1C,
  32847. 0x93, 0xFF, 0xBD, 0xDD, 0x75, 0x54, 0x0B, 0xD1,
  32848. 0xA9, 0xF6, 0xBC, 0x89, 0x98, 0x7D, 0x6F, 0x03,
  32849. 0x7B, 0x06, 0xD5, 0x40, 0x7D, 0x85, 0x48, 0x2E,
  32850. 0x11, 0x3E, 0xF0, 0x47, 0x77, 0xD0, 0xBA, 0x03,
  32851. 0x33, 0x58, 0xC4, 0x8F, 0x76, 0xF8, 0x72, 0x47,
  32852. 0x04, 0x21, 0x5E, 0x85, 0x5A, 0x0F, 0x35, 0x77,
  32853. 0xFB, 0x96, 0x29, 0x81, 0x2D, 0x55, 0x6E, 0x53,
  32854. 0xC6, 0x13, 0x1E, 0xFA, 0x4D, 0xCE, 0xA9, 0x36,
  32855. 0x1D, 0x8F, 0xAB, 0xAC, 0x13, 0x19, 0x94, 0xFC,
  32856. 0x4B, 0xCD, 0x36, 0x4C, 0x6E, 0x21, 0xAE, 0xF1,
  32857. 0x13, 0xA4, 0xF7, 0x64, 0x8E, 0xE1, 0xAF, 0x50,
  32858. 0x6A, 0x63, 0x0E, 0xCA, 0x2F, 0xE9, 0x0C, 0x8A,
  32859. 0xE7, 0xF2, 0xE3, 0x68, 0x03, 0xE0, 0x40, 0x1C,
  32860. 0x64, 0xAB, 0xC3, 0xEC, 0xC0, 0x92, 0xE9, 0x57,
  32861. 0x3E, 0x66, 0x72, 0x36, 0x39, 0x22, 0x4E, 0xCD,
  32862. 0x13, 0x08, 0xBA, 0xF8, 0x2B, 0xA1, 0xF2, 0x69,
  32863. 0x44, 0x7E, 0x90, 0x5C, 0xC8, 0xEC, 0xB6, 0xBE,
  32864. 0x8C, 0x30, 0xE0, 0x69, 0xB7, 0x97, 0xA1, 0x1C,
  32865. 0x18, 0xE5, 0x54, 0x62, 0xC3, 0x29, 0x99, 0x21,
  32866. 0x16, 0xD9, 0x78, 0x1C, 0x4C, 0x9C, 0x88, 0x4C,
  32867. 0xA5, 0xE1, 0x11, 0x66, 0x5B, 0x6E, 0x71, 0xE7,
  32868. 0xE2, 0xE7, 0xE4, 0x02, 0xDD, 0x1A, 0x8D, 0x0C,
  32869. 0xF5, 0x32, 0xFD, 0x41, 0x28, 0x35, 0x75, 0xD0,
  32870. 0x0C, 0x5F, 0x06, 0x6A, 0x5A, 0x61, 0x49, 0x59,
  32871. 0xC1, 0x0C, 0xD4, 0x9E, 0xD6, 0x29, 0xE2, 0x37,
  32872. 0xDF, 0x2B, 0x3D, 0xE8, 0x98, 0xB9, 0xDF, 0x8E,
  32873. 0xA0, 0xC4, 0xE2, 0xFC, 0x45, 0x70, 0xE8, 0x1B,
  32874. 0xF4, 0xFA, 0xC5, 0xE6, 0xA7, 0xCF, 0x4F, 0xA2,
  32875. 0xDA, 0x3D, 0x90, 0x49, 0x24, 0x8F, 0x61, 0x54,
  32876. 0xD5, 0x50, 0x8E, 0xE8, 0x0C, 0x14, 0xAD, 0x6F,
  32877. 0x65, 0x88, 0x3A, 0xF6, 0x92, 0xDB, 0x35, 0x5D,
  32878. 0xFF, 0x21, 0x20, 0xAC, 0x01, 0x16, 0x0B, 0xEC,
  32879. 0x84, 0x15, 0x3B, 0xA9, 0x93, 0x92, 0x75, 0xB3,
  32880. 0x73, 0xF1, 0x23, 0x69, 0x94, 0x10, 0xF5, 0xFE,
  32881. 0x20, 0xA8, 0xAF, 0x05, 0x87, 0x49, 0x4E, 0x9C,
  32882. 0xEB, 0x21, 0x0A, 0xCF, 0x0B, 0xA1, 0x65, 0x38,
  32883. 0xA6, 0x18, 0x4D, 0xF7, 0xD8, 0xC1, 0x2C, 0x14,
  32884. 0x4C, 0xD9, 0x40, 0xC2, 0xF7, 0xBF, 0xE3, 0x07,
  32885. 0x79, 0x55, 0xAE, 0xB9, 0xB6, 0x50, 0x06, 0x92,
  32886. 0x94, 0x8C, 0x6A, 0x0E, 0x22, 0x14, 0xE2, 0xCC,
  32887. 0x65, 0xBA, 0x0C, 0x4D, 0xB6, 0x5C, 0x4A, 0xE9,
  32888. 0x0A, 0x08, 0x0C, 0xF9, 0x26, 0xA2, 0x51, 0x85,
  32889. 0x36, 0xE2, 0xC1, 0xF1, 0x0A, 0x66, 0x51, 0x66,
  32890. 0x7A, 0x98, 0x9B, 0x2C, 0x30, 0x1A, 0x0D, 0x49,
  32891. 0x3C, 0x1E, 0xEC, 0x63, 0x53, 0x5E, 0xD9, 0xDD,
  32892. 0x84, 0x69, 0xCD, 0x7E, 0x79, 0x58, 0x3D, 0x6E,
  32893. 0xD9, 0x98, 0x58, 0xD8, 0x0A, 0x48, 0xB5, 0x13,
  32894. 0x3F, 0x72, 0x4C, 0x11, 0x90, 0x15, 0x12, 0x74,
  32895. 0xFF, 0x5C, 0x0D, 0xC6, 0x20, 0x8C, 0xC1, 0x99,
  32896. 0xCA, 0x8E, 0xFC, 0xA2, 0xE8, 0xB8, 0xEE, 0xAA,
  32897. 0x27, 0xC2, 0x97, 0x8D, 0xFA, 0xBE, 0xE0, 0x43,
  32898. 0x99, 0xB6, 0x90, 0x60, 0x00, 0x7C, 0x33, 0xD4,
  32899. 0x87, 0x71, 0x7B, 0x56, 0x6C, 0xAA, 0xE0, 0xAC,
  32900. 0x9D, 0x7E, 0x7E, 0xA3, 0xCF, 0xBB, 0xB3, 0xA0,
  32901. 0x5F, 0xD4, 0xC4, 0x3A, 0xA7, 0xB9, 0x0C, 0xCE,
  32902. 0xF3, 0x05, 0x09, 0x91, 0xA7, 0xE9, 0x11, 0x55,
  32903. 0x32, 0x45, 0xA6, 0x08, 0x0E, 0x10, 0x37, 0x91,
  32904. 0xF3, 0xBF, 0xED, 0x64, 0x26, 0xEB, 0x39, 0xC2,
  32905. 0x57, 0xAE, 0x64, 0x79, 0x33, 0x7C, 0x51, 0xB2,
  32906. 0xC8, 0x85, 0xE0, 0xF9, 0x6D, 0x10, 0x52, 0x9F,
  32907. 0x72, 0xF4, 0xD1, 0x5B, 0x54, 0x5B, 0x93, 0x28,
  32908. 0x36, 0xA8, 0xCD, 0xB3, 0x30, 0x5B, 0x7A, 0xB0,
  32909. 0xB6, 0xF0, 0xD8, 0xA0, 0xBA, 0x24, 0x59, 0x5F,
  32910. 0x43, 0x02, 0x01, 0x57, 0x91, 0x7B, 0x94, 0x07,
  32911. 0x63, 0x23, 0x12, 0x94, 0xFB, 0x9F, 0xF2, 0xC1,
  32912. 0xD6, 0x80, 0x8F, 0x4E, 0xA7, 0x9E, 0x11, 0xD8,
  32913. 0xB3, 0x08, 0xB6, 0x3B, 0x3B, 0xF2, 0xEE, 0x14,
  32914. 0xA5, 0xDB, 0xB0, 0xBB, 0x17, 0xA5, 0x96, 0x3C,
  32915. 0x2F, 0xB9, 0xE7, 0x4A, 0xD7, 0x52, 0x34, 0x98,
  32916. 0xCB, 0x0C, 0xEB, 0x42, 0x5B, 0x2D, 0x2D, 0x2B,
  32917. 0x0D, 0x94, 0x66, 0xD3, 0xAD, 0x08, 0x0A, 0x28,
  32918. 0xF6, 0x0E, 0xDA, 0xD4, 0x54, 0xFD, 0xC6, 0x48,
  32919. 0x08, 0xA1, 0x8D, 0xB0, 0x30, 0xFD, 0x18, 0xB1,
  32920. 0x50, 0xB1, 0xFD, 0xE0, 0x6E, 0x33, 0x25, 0x0D,
  32921. 0x90, 0xB1, 0xC1, 0xE7, 0x88, 0x74, 0x87, 0x05,
  32922. 0xE7, 0xBE, 0xBD, 0xAA, 0x8C, 0x6D, 0xC2, 0x3D,
  32923. 0x6F, 0x95, 0x84, 0xFA, 0x03, 0x74, 0x85, 0xE1,
  32924. 0xED, 0xE5, 0xF4, 0xE8, 0x26, 0x4A, 0x0B, 0x20,
  32925. 0x87, 0xB6, 0xE1, 0x10, 0x75, 0x6D, 0x9F, 0x95,
  32926. 0x39, 0x4C, 0x0F, 0x50, 0x1B, 0xA8, 0x69, 0x82,
  32927. 0xBB, 0xE2, 0xD6, 0x11, 0xD7, 0xBE, 0xFB, 0x4F,
  32928. 0x60, 0xD3, 0x16, 0xC6, 0x04, 0x3A, 0x5A, 0xF5,
  32929. 0x78, 0x9B, 0x0B, 0x21, 0xA1, 0x00, 0x96, 0xCD,
  32930. 0x63, 0x78, 0x1D, 0x2D, 0x4F, 0x6E, 0x50, 0xEE,
  32931. 0x62, 0x2D, 0x88, 0x62, 0x01, 0xF6, 0xB4, 0x17,
  32932. 0x4F, 0x8C, 0xAD, 0xCB, 0x4B, 0xF9, 0xF6, 0x9D,
  32933. 0xC7, 0xD8, 0xCC, 0xBF, 0x96, 0x1B, 0x1B, 0x79,
  32934. 0xF3, 0x25, 0x85, 0x23, 0x10, 0x63, 0x30, 0x8D,
  32935. 0xA8, 0x3A, 0x4B, 0x92, 0x1B, 0x88, 0x53, 0x24,
  32936. 0x2D, 0x29, 0xA5, 0x2E, 0x7A, 0xD5, 0x58, 0xEB,
  32937. 0x1B, 0x1C, 0xE6, 0xB8, 0x94, 0x0C, 0x58, 0x96,
  32938. 0x5B, 0xA0, 0x2C, 0xBF, 0xE2, 0x99, 0xA0, 0x1F,
  32939. 0x0C, 0xCC, 0xBD, 0x83, 0x72, 0x56, 0xBB, 0x13,
  32940. 0x61, 0x5A, 0xC2, 0x04, 0x27, 0x29, 0x1F, 0xD4,
  32941. 0xE4, 0x3D, 0x8A, 0x87, 0xE3, 0x81, 0x91, 0x07,
  32942. 0xD3, 0x9B, 0xBC, 0xA9, 0xB3, 0xBA, 0xF5, 0x8B,
  32943. 0x6A, 0xAD, 0xDE, 0xB0, 0x54, 0x3E, 0xFE, 0xCC,
  32944. 0xD3, 0xCB, 0x2C, 0x69, 0xF0, 0x58, 0xD7, 0xEF,
  32945. 0xA9, 0xC0, 0x15, 0x9B, 0x5A, 0xDF, 0x71, 0x25,
  32946. 0x38, 0x44, 0xEC, 0xA9, 0x18, 0x47, 0x41, 0xCE,
  32947. 0x3D, 0x53, 0x10, 0x12, 0xC3, 0x1B, 0x59, 0x9A,
  32948. 0x93, 0xA1, 0xEA, 0xBE, 0x3E, 0xBA, 0x74, 0xF6,
  32949. 0x2D, 0x40, 0x9D, 0xCB, 0x9E, 0xA1, 0xA5, 0x85,
  32950. 0xFF, 0xDC, 0xC5, 0x60, 0x6F, 0x61, 0xE8, 0x17,
  32951. 0x6C, 0x36, 0x9F, 0x7A, 0x48, 0x47, 0xDD, 0xF1,
  32952. 0xF4, 0x43, 0x21, 0xCB, 0xB3, 0x55, 0x86, 0xD0,
  32953. 0xE9, 0x46, 0x7D, 0xB5, 0x3D, 0x90, 0x34, 0x1E,
  32954. 0xBB, 0x40, 0xD3, 0x2A, 0xEB, 0xE6, 0x4C, 0x46,
  32955. 0x42, 0xA2, 0x8A, 0xBF, 0x90, 0xE7, 0x4B, 0x6D,
  32956. 0x5C, 0x94, 0x97, 0xD2, 0xF0, 0x97, 0x74, 0x4C,
  32957. 0x76, 0x03, 0xAC, 0x3D, 0xDE, 0x15, 0x96, 0x0C,
  32958. 0xEF, 0x18, 0x9D, 0xBD, 0x1A, 0x20, 0x35, 0x7E,
  32959. 0x2A, 0x70, 0x9D, 0xEA, 0x2E, 0x11, 0xDF, 0xF3,
  32960. 0x2F, 0xFE, 0x23, 0xA9, 0xB6, 0xCF, 0xB7, 0xB9,
  32961. 0x3F, 0x4F, 0x30, 0x6B, 0x3B, 0x0D, 0x3B, 0xED,
  32962. 0xCD, 0x77, 0xD4, 0xBF, 0xEE, 0xDD, 0xB6, 0x56,
  32963. 0x24, 0xD4, 0x29, 0x83, 0xDE, 0xDB, 0xC1, 0xFB,
  32964. 0x6A, 0xCE, 0x7F, 0x47, 0xD2, 0xC5, 0xF1, 0x78,
  32965. 0x5C, 0x2C, 0x5A, 0x28, 0x3E, 0x05, 0x50, 0x2E,
  32966. 0xD9, 0xAE, 0x9B, 0x95, 0x64, 0xC7, 0xD2, 0x7B,
  32967. 0xCB, 0xC5, 0x91, 0x80, 0xEB, 0x79, 0xC7, 0xCC,
  32968. 0xA8, 0x06, 0xC8, 0xF9, 0xDF, 0x2A, 0x49, 0x4A,
  32969. 0xF8, 0xFE, 0xBA, 0xA5, 0x85, 0x67, 0x1B, 0xDA,
  32970. 0x51, 0x3B, 0xC2, 0x04, 0xA6, 0xA3, 0xFF, 0x99,
  32971. 0x21, 0xE8, 0x17, 0x91, 0x33, 0x9B, 0x83, 0x75,
  32972. 0x20, 0x5E, 0x95, 0xBE, 0x49, 0xDF, 0x53, 0xFC,
  32973. 0x05, 0xA2, 0x3C, 0xAA, 0x5A, 0x22, 0x15, 0xA5,
  32974. 0x56, 0xE0, 0x51, 0x30, 0x4E, 0x32, 0x14, 0xF2,
  32975. 0x9F, 0x03, 0x51, 0x8E, 0xDD, 0x8B, 0x39, 0x19,
  32976. 0x1E, 0x39, 0xC5, 0xA7, 0x1C, 0xC6, 0xA4, 0xE1,
  32977. 0x77, 0xCA, 0x8C, 0x9D, 0x27, 0xBC, 0xCC, 0x16,
  32978. 0xD6, 0xFC, 0x59, 0x10, 0x23, 0xFF, 0x64, 0x90,
  32979. 0x9C, 0x23, 0x5A, 0xFF, 0x7E, 0x27, 0x1B, 0xC7,
  32980. 0x7F, 0x21, 0x3B, 0x41, 0xDB, 0xBC, 0x96, 0x60,
  32981. 0x0B, 0x35, 0xA1, 0xF3, 0xF8, 0x51, 0x0A, 0x65,
  32982. 0xCF, 0xDF, 0x7A, 0xB8, 0x04, 0x56, 0x49, 0xD7,
  32983. 0xD3, 0xC5, 0x0B, 0x4A, 0x1F, 0x60, 0xE1, 0x86,
  32984. 0x36, 0x53, 0x8E, 0x6C, 0x3E, 0xAF, 0x5B, 0xC1,
  32985. 0xCA, 0xCB, 0x22, 0x1A, 0x07, 0xDA, 0x54, 0xEC,
  32986. 0xAA, 0x06, 0x72, 0x17, 0xCF, 0x80, 0xC4, 0x89,
  32987. 0x56, 0x24, 0x1B, 0xD4, 0xFF, 0x50, 0x6B, 0x51,
  32988. 0x55, 0x4D, 0x6E, 0x79, 0x7E, 0xEC, 0x61, 0xC6,
  32989. 0xE4, 0x21, 0xC8, 0x0E, 0x10, 0x3F, 0x8C, 0x85,
  32990. 0x3A, 0x27, 0xEA, 0x91, 0x07, 0xCB, 0x37, 0x18,
  32991. 0x14, 0xB5, 0x63, 0x6E, 0x00, 0xBC, 0x0F, 0x36,
  32992. 0xF9, 0x54, 0x75, 0xE7, 0x0B, 0xDC, 0xE7, 0xA0,
  32993. 0x59, 0xF0, 0x64, 0xFB, 0x73, 0x07, 0x0E, 0xFE,
  32994. 0x57, 0x7F, 0x0D, 0x12, 0xBC, 0xB0, 0xBF, 0xA2,
  32995. 0x3A, 0x18, 0x08, 0x7E, 0xD5, 0x6C, 0xF0, 0x6F,
  32996. 0xF8, 0x98, 0xFB, 0xA5, 0x10, 0x7B, 0x10, 0x5F,
  32997. 0x6B, 0xC8, 0x6D, 0xDE, 0x2F, 0x1F, 0xE0, 0xC8,
  32998. 0x19, 0xEE, 0xC2, 0x03, 0x39, 0x49, 0x70, 0x3E,
  32999. 0x36, 0xE3, 0x3C, 0x70, 0xE3, 0xEA, 0xAC, 0x34,
  33000. 0x32, 0xB7, 0x0D, 0xBA, 0x7C, 0xAB, 0xE6, 0x18
  33001. };
  33002. static const byte sk_65[] = {
  33003. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  33004. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  33005. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  33006. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  33007. 0x52, 0x8D, 0xA0, 0xC7, 0xD2, 0x80, 0xDD, 0x49,
  33008. 0x0D, 0x5E, 0xB7, 0x65, 0xDB, 0x32, 0x33, 0x15,
  33009. 0x0F, 0x9E, 0xC8, 0xEB, 0xC9, 0x6E, 0xE8, 0xE8,
  33010. 0x5C, 0xBD, 0x18, 0x4F, 0xDC, 0xF8, 0xA8, 0xD9,
  33011. 0xC5, 0x33, 0x84, 0x79, 0x5A, 0x5E, 0xB7, 0x3C,
  33012. 0x6D, 0x82, 0xCA, 0xB9, 0xBA, 0x94, 0xB6, 0x46,
  33013. 0xAE, 0x3A, 0xD9, 0x19, 0x6C, 0xB4, 0xDA, 0xE2,
  33014. 0xF1, 0x4B, 0xB6, 0x43, 0xF0, 0x24, 0x08, 0xE5,
  33015. 0xF7, 0x9A, 0x41, 0xF1, 0x15, 0x9C, 0xA8, 0x08,
  33016. 0x79, 0x9F, 0xB8, 0x26, 0xD4, 0x08, 0x32, 0x47,
  33017. 0xC8, 0xF0, 0xD5, 0x31, 0xA1, 0xC1, 0x19, 0x04,
  33018. 0x02, 0x06, 0x2B, 0x4D, 0x46, 0xAE, 0x43, 0x6A,
  33019. 0x25, 0x82, 0x75, 0x41, 0x70, 0x36, 0x42, 0x48,
  33020. 0x78, 0x06, 0x36, 0x50, 0x23, 0x84, 0x68, 0x10,
  33021. 0x87, 0x08, 0x62, 0x00, 0x08, 0x34, 0x20, 0x73,
  33022. 0x32, 0x13, 0x36, 0x61, 0x87, 0x61, 0x43, 0x50,
  33023. 0x30, 0x02, 0x26, 0x07, 0x65, 0x45, 0x32, 0x00,
  33024. 0x25, 0x75, 0x01, 0x04, 0x88, 0x81, 0x58, 0x64,
  33025. 0x52, 0x40, 0x84, 0x22, 0x88, 0x42, 0x82, 0x56,
  33026. 0x47, 0x50, 0x05, 0x21, 0x88, 0x25, 0x32, 0x25,
  33027. 0x12, 0x85, 0x14, 0x52, 0x87, 0x77, 0x67, 0x18,
  33028. 0x46, 0x54, 0x63, 0x07, 0x88, 0x67, 0x37, 0x26,
  33029. 0x72, 0x62, 0x41, 0x02, 0x00, 0x01, 0x17, 0x84,
  33030. 0x33, 0x64, 0x32, 0x57, 0x06, 0x20, 0x05, 0x44,
  33031. 0x88, 0x57, 0x33, 0x45, 0x70, 0x55, 0x14, 0x43,
  33032. 0x12, 0x54, 0x04, 0x38, 0x37, 0x08, 0x42, 0x57,
  33033. 0x36, 0x05, 0x30, 0x03, 0x86, 0x53, 0x02, 0x53,
  33034. 0x75, 0x22, 0x62, 0x13, 0x38, 0x82, 0x48, 0x30,
  33035. 0x83, 0x83, 0x64, 0x83, 0x13, 0x74, 0x57, 0x32,
  33036. 0x46, 0x70, 0x06, 0x05, 0x82, 0x52, 0x73, 0x55,
  33037. 0x25, 0x77, 0x21, 0x78, 0x57, 0x83, 0x66, 0x20,
  33038. 0x38, 0x53, 0x21, 0x41, 0x77, 0x56, 0x77, 0x46,
  33039. 0x34, 0x42, 0x58, 0x31, 0x08, 0x06, 0x03, 0x62,
  33040. 0x20, 0x35, 0x11, 0x42, 0x35, 0x38, 0x63, 0x86,
  33041. 0x64, 0x13, 0x13, 0x75, 0x40, 0x01, 0x53, 0x74,
  33042. 0x41, 0x31, 0x56, 0x64, 0x38, 0x17, 0x14, 0x16,
  33043. 0x62, 0x33, 0x22, 0x12, 0x64, 0x40, 0x67, 0x11,
  33044. 0x62, 0x42, 0x25, 0x60, 0x38, 0x05, 0x83, 0x13,
  33045. 0x51, 0x00, 0x28, 0x36, 0x62, 0x56, 0x41, 0x43,
  33046. 0x58, 0x37, 0x51, 0x22, 0x70, 0x25, 0x82, 0x82,
  33047. 0x35, 0x24, 0x06, 0x83, 0x48, 0x58, 0x81, 0x78,
  33048. 0x07, 0x86, 0x23, 0x15, 0x75, 0x32, 0x46, 0x75,
  33049. 0x35, 0x40, 0x08, 0x43, 0x10, 0x66, 0x74, 0x05,
  33050. 0x13, 0x72, 0x74, 0x08, 0x83, 0x41, 0x81, 0x08,
  33051. 0x75, 0x87, 0x83, 0x28, 0x56, 0x66, 0x20, 0x01,
  33052. 0x18, 0x83, 0x57, 0x22, 0x14, 0x64, 0x18, 0x05,
  33053. 0x27, 0x75, 0x22, 0x84, 0x12, 0x38, 0x87, 0x52,
  33054. 0x32, 0x25, 0x28, 0x08, 0x14, 0x41, 0x81, 0x14,
  33055. 0x03, 0x24, 0x54, 0x23, 0x04, 0x81, 0x40, 0x36,
  33056. 0x38, 0x38, 0x64, 0x42, 0x46, 0x36, 0x68, 0x11,
  33057. 0x55, 0x00, 0x11, 0x25, 0x76, 0x16, 0x43, 0x07,
  33058. 0x23, 0x03, 0x34, 0x10, 0x46, 0x41, 0x14, 0x02,
  33059. 0x26, 0x10, 0x74, 0x38, 0x38, 0x72, 0x07, 0x87,
  33060. 0x54, 0x11, 0x12, 0x83, 0x75, 0x05, 0x82, 0x17,
  33061. 0x45, 0x20, 0x38, 0x41, 0x37, 0x20, 0x00, 0x08,
  33062. 0x32, 0x18, 0x16, 0x25, 0x58, 0x85, 0x16, 0x88,
  33063. 0x71, 0x82, 0x45, 0x60, 0x33, 0x11, 0x13, 0x42,
  33064. 0x43, 0x37, 0x68, 0x11, 0x16, 0x54, 0x04, 0x08,
  33065. 0x52, 0x78, 0x13, 0x56, 0x83, 0x52, 0x15, 0x24,
  33066. 0x03, 0x61, 0x78, 0x44, 0x13, 0x70, 0x67, 0x36,
  33067. 0x74, 0x86, 0x52, 0x50, 0x15, 0x41, 0x88, 0x74,
  33068. 0x53, 0x00, 0x05, 0x18, 0x65, 0x62, 0x14, 0x84,
  33069. 0x12, 0x32, 0x01, 0x88, 0x40, 0x42, 0x34, 0x05,
  33070. 0x32, 0x80, 0x72, 0x55, 0x20, 0x68, 0x16, 0x43,
  33071. 0x14, 0x15, 0x15, 0x38, 0x43, 0x85, 0x27, 0x60,
  33072. 0x70, 0x18, 0x27, 0x35, 0x53, 0x01, 0x28, 0x73,
  33073. 0x27, 0x84, 0x10, 0x53, 0x67, 0x10, 0x45, 0x40,
  33074. 0x81, 0x52, 0x86, 0x06, 0x11, 0x18, 0x04, 0x31,
  33075. 0x57, 0x25, 0x22, 0x44, 0x47, 0x81, 0x45, 0x44,
  33076. 0x55, 0x04, 0x72, 0x57, 0x06, 0x46, 0x76, 0x23,
  33077. 0x38, 0x85, 0x65, 0x30, 0x08, 0x48, 0x20, 0x13,
  33078. 0x22, 0x77, 0x44, 0x60, 0x43, 0x14, 0x15, 0x27,
  33079. 0x86, 0x22, 0x37, 0x37, 0x27, 0x04, 0x27, 0x50,
  33080. 0x74, 0x31, 0x10, 0x82, 0x00, 0x75, 0x80, 0x44,
  33081. 0x38, 0x10, 0x58, 0x40, 0x86, 0x60, 0x63, 0x13,
  33082. 0x65, 0x18, 0x33, 0x70, 0x57, 0x68, 0x05, 0x10,
  33083. 0x81, 0x03, 0x42, 0x05, 0x25, 0x65, 0x33, 0x57,
  33084. 0x38, 0x05, 0x65, 0x34, 0x46, 0x53, 0x68, 0x11,
  33085. 0x75, 0x10, 0x04, 0x54, 0x18, 0x47, 0x52, 0x24,
  33086. 0x63, 0x23, 0x74, 0x45, 0x11, 0x34, 0x68, 0x32,
  33087. 0x35, 0x38, 0x52, 0x85, 0x28, 0x08, 0x71, 0x78,
  33088. 0x37, 0x38, 0x27, 0x10, 0x80, 0x54, 0x26, 0x33,
  33089. 0x31, 0x82, 0x44, 0x88, 0x33, 0x24, 0x62, 0x86,
  33090. 0x32, 0x82, 0x73, 0x31, 0x28, 0x14, 0x73, 0x87,
  33091. 0x06, 0x35, 0x80, 0x36, 0x67, 0x02, 0x33, 0x75,
  33092. 0x27, 0x36, 0x38, 0x16, 0x35, 0x70, 0x52, 0x16,
  33093. 0x87, 0x58, 0x85, 0x17, 0x22, 0x13, 0x54, 0x85,
  33094. 0x07, 0x53, 0x31, 0x26, 0x78, 0x01, 0x85, 0x18,
  33095. 0x08, 0x68, 0x38, 0x52, 0x11, 0x73, 0x32, 0x25,
  33096. 0x58, 0x82, 0x70, 0x70, 0x36, 0x30, 0x50, 0x38,
  33097. 0x65, 0x12, 0x78, 0x31, 0x77, 0x72, 0x18, 0x41,
  33098. 0x05, 0x42, 0x32, 0x26, 0x26, 0x50, 0x52, 0x86,
  33099. 0x15, 0x76, 0x28, 0x66, 0x88, 0x03, 0x78, 0x28,
  33100. 0x70, 0x33, 0x36, 0x27, 0x16, 0x61, 0x43, 0x56,
  33101. 0x62, 0x81, 0x85, 0x75, 0x47, 0x60, 0x63, 0x38,
  33102. 0x66, 0x81, 0x51, 0x78, 0x03, 0x42, 0x60, 0x38,
  33103. 0x01, 0x24, 0x73, 0x63, 0x81, 0x12, 0x01, 0x27,
  33104. 0x63, 0x13, 0x11, 0x78, 0x36, 0x37, 0x15, 0x03,
  33105. 0x84, 0x58, 0x17, 0x25, 0x67, 0x87, 0x57, 0x83,
  33106. 0x71, 0x85, 0x37, 0x53, 0x86, 0x22, 0x33, 0x28,
  33107. 0x77, 0x30, 0x18, 0x15, 0x01, 0x37, 0x85, 0x40,
  33108. 0x15, 0x38, 0x51, 0x33, 0x17, 0x42, 0x64, 0x04,
  33109. 0x56, 0x27, 0x50, 0x45, 0x11, 0x27, 0x20, 0x17,
  33110. 0x76, 0x55, 0x33, 0x37, 0x58, 0x88, 0x88, 0x45,
  33111. 0x16, 0x55, 0x08, 0x53, 0x52, 0x48, 0x72, 0x85,
  33112. 0x30, 0x15, 0x23, 0x44, 0x22, 0x02, 0x43, 0x45,
  33113. 0x41, 0x10, 0x00, 0x52, 0x32, 0x73, 0x05, 0x75,
  33114. 0x72, 0x16, 0x08, 0x11, 0x51, 0x36, 0x20, 0x04,
  33115. 0x76, 0x48, 0x78, 0x56, 0x60, 0x88, 0x07, 0x47,
  33116. 0x70, 0x20, 0x46, 0x40, 0x43, 0x26, 0x04, 0x37,
  33117. 0x17, 0x51, 0x58, 0x46, 0x72, 0x44, 0x50, 0x23,
  33118. 0x67, 0x63, 0x60, 0x84, 0x30, 0x51, 0x52, 0x53,
  33119. 0x21, 0x74, 0x85, 0x45, 0x74, 0x43, 0x11, 0x72,
  33120. 0x52, 0x65, 0x76, 0x08, 0x78, 0x63, 0x14, 0x27,
  33121. 0x41, 0x34, 0x67, 0x07, 0x45, 0x15, 0x10, 0x83,
  33122. 0x24, 0x02, 0x80, 0x53, 0x07, 0x21, 0x58, 0x10,
  33123. 0x34, 0x20, 0x54, 0x12, 0x58, 0x44, 0x25, 0x53,
  33124. 0x33, 0x46, 0x02, 0x38, 0x60, 0x17, 0x70, 0x64,
  33125. 0x18, 0x52, 0x62, 0x26, 0x65, 0x61, 0x42, 0x31,
  33126. 0x22, 0x57, 0x34, 0x57, 0x02, 0x34, 0x62, 0x76,
  33127. 0x74, 0x38, 0x73, 0x21, 0x68, 0x71, 0x07, 0x21,
  33128. 0x61, 0x05, 0x20, 0x20, 0x86, 0x83, 0x30, 0x25,
  33129. 0x50, 0x50, 0x83, 0x30, 0x31, 0x56, 0x30, 0x31,
  33130. 0x76, 0x04, 0x54, 0x80, 0x75, 0x18, 0x82, 0x23,
  33131. 0x61, 0x87, 0x58, 0x25, 0x13, 0x63, 0x21, 0x51,
  33132. 0x48, 0x02, 0x67, 0x37, 0x12, 0x88, 0x70, 0x60,
  33133. 0x07, 0x36, 0x18, 0x15, 0x87, 0x74, 0x55, 0x60,
  33134. 0x00, 0x54, 0x37, 0x11, 0x01, 0x37, 0x14, 0x17,
  33135. 0x11, 0x72, 0x14, 0x55, 0x31, 0x75, 0x77, 0x48,
  33136. 0x10, 0x23, 0x83, 0x20, 0x00, 0x04, 0x32, 0x64,
  33137. 0x66, 0x61, 0x71, 0x31, 0x03, 0x15, 0x44, 0x32,
  33138. 0x57, 0x25, 0x64, 0x31, 0x28, 0x15, 0x33, 0x67,
  33139. 0x86, 0x87, 0x37, 0x03, 0x12, 0x78, 0x86, 0x13,
  33140. 0x47, 0x80, 0x61, 0x42, 0x50, 0x40, 0x23, 0x37,
  33141. 0x01, 0x01, 0x66, 0x24, 0x06, 0x57, 0x82, 0x02,
  33142. 0x22, 0x42, 0x41, 0x02, 0x26, 0x06, 0x41, 0x35,
  33143. 0x64, 0x16, 0x44, 0x42, 0x38, 0x30, 0x86, 0x88,
  33144. 0x47, 0x71, 0x62, 0x33, 0x24, 0x02, 0x12, 0x37,
  33145. 0x42, 0x33, 0x20, 0x81, 0x80, 0x53, 0x07, 0x65,
  33146. 0x71, 0x27, 0x13, 0x53, 0x15, 0x43, 0x76, 0x38,
  33147. 0x71, 0x30, 0x07, 0x87, 0x25, 0x63, 0x03, 0x33,
  33148. 0x70, 0x56, 0x18, 0x13, 0x83, 0x51, 0x44, 0x40,
  33149. 0x04, 0x80, 0x62, 0x24, 0x20, 0x64, 0x54, 0x40,
  33150. 0x20, 0x73, 0x61, 0x45, 0x01, 0x24, 0x47, 0x78,
  33151. 0x23, 0x34, 0x56, 0x10, 0x25, 0x32, 0x02, 0x70,
  33152. 0x08, 0x02, 0x23, 0x24, 0x80, 0x43, 0x04, 0x02,
  33153. 0x81, 0x11, 0x23, 0x82, 0x03, 0x61, 0x30, 0x33,
  33154. 0x15, 0x36, 0x25, 0x32, 0x14, 0x73, 0x22, 0x46,
  33155. 0x81, 0x25, 0x16, 0x13, 0x52, 0x58, 0x71, 0x61,
  33156. 0x67, 0x08, 0x38, 0x76, 0x71, 0x15, 0x88, 0x47,
  33157. 0x31, 0x25, 0x27, 0x18, 0x31, 0x50, 0x40, 0x71,
  33158. 0x06, 0x87, 0x37, 0x30, 0x85, 0x64, 0x62, 0x78,
  33159. 0x32, 0x74, 0x18, 0x83, 0x67, 0x40, 0x37, 0x44,
  33160. 0x56, 0x02, 0x72, 0x61, 0x27, 0x28, 0x38, 0x38,
  33161. 0x67, 0x17, 0x58, 0x04, 0x61, 0x28, 0x67, 0x37,
  33162. 0x46, 0x50, 0x38, 0x15, 0x45, 0x12, 0x71, 0x44,
  33163. 0x22, 0x02, 0x34, 0x83, 0x40, 0x70, 0x55, 0x75,
  33164. 0x54, 0x26, 0x88, 0x07, 0x25, 0x58, 0x73, 0x60,
  33165. 0x58, 0x61, 0x45, 0x63, 0x35, 0x05, 0x48, 0x63,
  33166. 0x48, 0x57, 0x03, 0x31, 0x28, 0x14, 0x05, 0x01,
  33167. 0x57, 0x34, 0x64, 0x50, 0x23, 0x86, 0x75, 0x85,
  33168. 0x18, 0x75, 0x56, 0x88, 0x08, 0x26, 0x01, 0x34,
  33169. 0x01, 0x57, 0x05, 0x28, 0x35, 0x48, 0x17, 0x57,
  33170. 0x71, 0x81, 0x41, 0x33, 0x77, 0x86, 0x07, 0x77,
  33171. 0x02, 0x25, 0x71, 0x74, 0x37, 0x31, 0x20, 0x14,
  33172. 0x32, 0x54, 0x20, 0x35, 0x54, 0x76, 0x83, 0x15,
  33173. 0x80, 0x73, 0x27, 0x23, 0x00, 0x58, 0x22, 0x84,
  33174. 0x64, 0x56, 0x14, 0x84, 0x38, 0x34, 0x16, 0x21,
  33175. 0x77, 0x07, 0x34, 0x81, 0x66, 0x87, 0x40, 0x11,
  33176. 0x62, 0x46, 0x45, 0x01, 0x20, 0x53, 0x21, 0x73,
  33177. 0x07, 0x76, 0x44, 0x15, 0x61, 0x50, 0x83, 0x48,
  33178. 0x58, 0x58, 0x45, 0x33, 0x25, 0x36, 0x07, 0x42,
  33179. 0x70, 0x24, 0x07, 0x41, 0x08, 0x35, 0x00, 0x78,
  33180. 0x41, 0x47, 0x02, 0x56, 0x07, 0x14, 0x68, 0x33,
  33181. 0x55, 0x77, 0x32, 0x40, 0x55, 0x24, 0x50, 0x26,
  33182. 0x47, 0x12, 0x65, 0x58, 0x43, 0x05, 0x52, 0x55,
  33183. 0x75, 0x50, 0x18, 0x46, 0x65, 0x48, 0x03, 0x32,
  33184. 0x85, 0x31, 0x16, 0x52, 0x71, 0x57, 0x87, 0x46,
  33185. 0x76, 0x14, 0x42, 0x81, 0x28, 0x74, 0x60, 0x34,
  33186. 0x35, 0x55, 0x52, 0x16, 0x58, 0x48, 0x61, 0x75,
  33187. 0x80, 0x88, 0x15, 0x32, 0x72, 0x26, 0x31, 0x03,
  33188. 0x05, 0x03, 0x16, 0x04, 0x07, 0x37, 0x37, 0x73,
  33189. 0x43, 0x81, 0x57, 0x31, 0x88, 0x04, 0x72, 0x76,
  33190. 0x01, 0x61, 0x81, 0x17, 0x37, 0x65, 0x44, 0x38,
  33191. 0x61, 0x23, 0x16, 0x26, 0x52, 0x45, 0x00, 0x73,
  33192. 0x83, 0x63, 0x64, 0x62, 0x26, 0x74, 0x60, 0x11,
  33193. 0x81, 0x08, 0x06, 0x30, 0x36, 0x05, 0x10, 0x48,
  33194. 0x47, 0x35, 0x10, 0x85, 0x30, 0x86, 0x71, 0x38,
  33195. 0x16, 0x37, 0x6F, 0x3B, 0x1C, 0x18, 0xB1, 0xE3,
  33196. 0xE8, 0xEE, 0x83, 0x3E, 0x8D, 0x38, 0x43, 0x9E,
  33197. 0x78, 0x1C, 0xA3, 0xB8, 0x94, 0x06, 0x54, 0xEF,
  33198. 0x44, 0x6C, 0x9A, 0xAC, 0xC3, 0xF1, 0xD3, 0x0E,
  33199. 0xE0, 0x10, 0x5B, 0x8F, 0x63, 0xEB, 0x89, 0x74,
  33200. 0x6E, 0xF4, 0xBE, 0xB5, 0x4C, 0xFC, 0xE8, 0x81,
  33201. 0x2C, 0xF9, 0x47, 0xCF, 0x54, 0x54, 0xFB, 0x1C,
  33202. 0xA5, 0x5F, 0x25, 0xA0, 0xFE, 0x57, 0xF5, 0xFC,
  33203. 0xFD, 0x73, 0xB0, 0xDA, 0x04, 0xB0, 0xBF, 0x28,
  33204. 0x92, 0x92, 0xAF, 0x39, 0x74, 0x72, 0x56, 0x69,
  33205. 0xC3, 0x00, 0x03, 0xE0, 0x50, 0x9F, 0xED, 0xC8,
  33206. 0x0F, 0x6C, 0x89, 0x4B, 0xB0, 0x47, 0xC2, 0xE2,
  33207. 0xAF, 0x48, 0x5C, 0xAD, 0x68, 0xC2, 0x1D, 0x80,
  33208. 0xEF, 0x33, 0xB0, 0xC4, 0xFD, 0xA6, 0x7B, 0x85,
  33209. 0x31, 0xA1, 0x58, 0x87, 0x67, 0x54, 0x71, 0x3F,
  33210. 0xF8, 0xA8, 0xA6, 0x8D, 0x9A, 0xBD, 0xC4, 0x81,
  33211. 0x6B, 0x24, 0xB4, 0xA3, 0x6A, 0x8A, 0x2B, 0xB1,
  33212. 0xFD, 0x1C, 0x2C, 0x25, 0xC3, 0x72, 0xC4, 0xB7,
  33213. 0x75, 0xF8, 0xCC, 0x17, 0x39, 0xCF, 0x2C, 0xE9,
  33214. 0xA4, 0x54, 0x58, 0xE4, 0x1A, 0xAE, 0xC6, 0x4A,
  33215. 0xEE, 0xDE, 0x75, 0x7C, 0xE7, 0x38, 0xBC, 0xDF,
  33216. 0x4D, 0xA0, 0xEE, 0x2B, 0xDD, 0x5F, 0x80, 0x5C,
  33217. 0xCF, 0xF7, 0x2A, 0x5F, 0x73, 0x8B, 0xAC, 0x12,
  33218. 0x34, 0x2E, 0xE3, 0xF1, 0x4C, 0xB7, 0x22, 0x68,
  33219. 0xC2, 0xD6, 0x36, 0x7D, 0xF1, 0x7F, 0x20, 0x46,
  33220. 0xA2, 0x4B, 0x47, 0x4B, 0x32, 0x58, 0xF7, 0xB0,
  33221. 0x88, 0x54, 0x6C, 0x99, 0x3B, 0x0D, 0xA1, 0xE2,
  33222. 0x92, 0x92, 0xEB, 0x72, 0x1E, 0xE7, 0xE5, 0xA1,
  33223. 0xF8, 0x6E, 0x14, 0xA5, 0x39, 0xB0, 0x63, 0x6F,
  33224. 0x78, 0x82, 0xA1, 0x9C, 0x8D, 0x79, 0x02, 0x85,
  33225. 0xA6, 0xDF, 0x7D, 0xEE, 0xCE, 0x17, 0x4D, 0x63,
  33226. 0xCF, 0xF3, 0xB2, 0xFF, 0x85, 0x68, 0x81, 0xCB,
  33227. 0x38, 0x6B, 0x1B, 0x38, 0xA2, 0xE0, 0xF2, 0x4C,
  33228. 0x31, 0xE0, 0x91, 0x93, 0xDD, 0xF3, 0x71, 0x47,
  33229. 0xF2, 0x69, 0xD9, 0x4C, 0xDE, 0xF9, 0x90, 0x61,
  33230. 0x34, 0x62, 0x07, 0x71, 0x79, 0xD0, 0xDD, 0x09,
  33231. 0x32, 0x64, 0x39, 0x49, 0x93, 0x1A, 0x02, 0xBA,
  33232. 0xFA, 0x80, 0x17, 0x6E, 0xDF, 0x97, 0xB6, 0xA2,
  33233. 0x31, 0x34, 0x71, 0xF0, 0xB1, 0x9B, 0x3B, 0x59,
  33234. 0xF4, 0x3B, 0xD2, 0x2A, 0x05, 0x49, 0x3E, 0xFB,
  33235. 0x0C, 0xF8, 0xB5, 0xD7, 0xB6, 0x25, 0x2B, 0x09,
  33236. 0x8B, 0x4B, 0xFA, 0x39, 0x5B, 0xF9, 0xA2, 0x09,
  33237. 0xE9, 0xBB, 0x46, 0x01, 0x30, 0x00, 0x90, 0x32,
  33238. 0x58, 0xA6, 0x9B, 0x67, 0xF5, 0x94, 0x11, 0xC8,
  33239. 0x35, 0x95, 0xFA, 0x6E, 0x67, 0x42, 0x8D, 0x96,
  33240. 0x6D, 0x20, 0xFC, 0xD3, 0x09, 0x61, 0x11, 0x86,
  33241. 0x77, 0xC0, 0x86, 0xA3, 0x54, 0xAE, 0x6D, 0x41,
  33242. 0xEE, 0x17, 0xDC, 0xA1, 0xB0, 0xB7, 0x50, 0x43,
  33243. 0xD6, 0xCE, 0x23, 0xBD, 0xB0, 0x1E, 0x02, 0xE5,
  33244. 0x9E, 0xCF, 0xC6, 0x2E, 0x8C, 0x39, 0x71, 0xB1,
  33245. 0x45, 0x02, 0x75, 0xBA, 0x7F, 0x60, 0xB0, 0x8B,
  33246. 0x1C, 0x33, 0xBA, 0x0C, 0xFF, 0x54, 0x63, 0xE3,
  33247. 0x47, 0x5B, 0x07, 0x77, 0x77, 0xC5, 0x72, 0x24,
  33248. 0x60, 0xFA, 0xDB, 0x0B, 0xF6, 0x41, 0x82, 0x69,
  33249. 0x3C, 0x68, 0x37, 0xF5, 0xFD, 0x45, 0x4A, 0x66,
  33250. 0x6C, 0xD7, 0x01, 0x10, 0x78, 0x4A, 0xED, 0x09,
  33251. 0xAE, 0x49, 0x0A, 0x60, 0xC7, 0x78, 0x56, 0x51,
  33252. 0x15, 0xE3, 0x4A, 0xB5, 0xAE, 0xAD, 0x09, 0xD1,
  33253. 0x71, 0xA8, 0xCA, 0x3C, 0x8A, 0xE6, 0xCA, 0x39,
  33254. 0x43, 0x60, 0x56, 0x83, 0x3C, 0x58, 0x04, 0xD4,
  33255. 0xB4, 0x62, 0xDD, 0x53, 0x05, 0xC8, 0x51, 0xAF,
  33256. 0x59, 0xF6, 0x4F, 0x04, 0xC3, 0x1E, 0x69, 0xFF,
  33257. 0x82, 0xBF, 0xD7, 0x89, 0xD2, 0x30, 0x9F, 0xF2,
  33258. 0xE6, 0x38, 0x05, 0x9C, 0xD5, 0x08, 0xB8, 0x25,
  33259. 0xF3, 0x3B, 0x99, 0x85, 0x4E, 0x40, 0xF8, 0x40,
  33260. 0xF2, 0x4B, 0x5C, 0x3A, 0xA8, 0x64, 0x41, 0x92,
  33261. 0xEA, 0xCA, 0x9A, 0x7B, 0xCF, 0xBA, 0x1F, 0xDE,
  33262. 0xE0, 0x9D, 0xCA, 0xAD, 0xB4, 0x0C, 0x90, 0xFF,
  33263. 0xE1, 0x6C, 0xEC, 0xDD, 0x32, 0x38, 0x2A, 0xF7,
  33264. 0x19, 0x20, 0x39, 0xCB, 0x29, 0x67, 0x2F, 0x70,
  33265. 0x71, 0x12, 0x10, 0xB6, 0xB8, 0x3E, 0x8D, 0xFD,
  33266. 0xB5, 0xFB, 0xBD, 0xBF, 0xA8, 0xCA, 0x19, 0xC4,
  33267. 0xC6, 0xAC, 0x37, 0x31, 0xFC, 0x33, 0xC2, 0x7F,
  33268. 0xA2, 0xA2, 0x6D, 0xEB, 0x15, 0x2E, 0xA1, 0x90,
  33269. 0xF8, 0x29, 0xC6, 0x34, 0xD1, 0x39, 0x30, 0x24,
  33270. 0x1C, 0xB9, 0x26, 0xAC, 0xDD, 0xE5, 0x24, 0x9C,
  33271. 0xDD, 0x35, 0x60, 0x7E, 0x38, 0x0C, 0xC1, 0x2A,
  33272. 0x7D, 0x1E, 0xA9, 0xBA, 0xA5, 0x58, 0x4C, 0xDD,
  33273. 0x26, 0x86, 0x09, 0xDC, 0xC3, 0xB0, 0x1F, 0xCD,
  33274. 0xC9, 0xAD, 0xCB, 0x4A, 0x7E, 0x51, 0x67, 0xE5,
  33275. 0xED, 0x5A, 0xD2, 0x21, 0xDB, 0x2E, 0xAB, 0xD9,
  33276. 0x0A, 0xEC, 0xAE, 0x71, 0xFA, 0x23, 0x7A, 0xEF,
  33277. 0x98, 0xDF, 0x53, 0x89, 0x93, 0xE8, 0x71, 0xD7,
  33278. 0x35, 0xDA, 0x6B, 0x88, 0x31, 0xAF, 0x67, 0xF2,
  33279. 0x97, 0x29, 0x1C, 0x39, 0x67, 0xEB, 0xAF, 0x60,
  33280. 0xD9, 0x53, 0xC4, 0x0F, 0x7A, 0x46, 0x4E, 0xF3,
  33281. 0x2F, 0x8E, 0xAE, 0xFA, 0x64, 0x2E, 0x37, 0xDE,
  33282. 0xA9, 0x74, 0x73, 0x5D, 0xDD, 0xBB, 0x83, 0x54,
  33283. 0x27, 0xB9, 0x7A, 0x63, 0x2B, 0x19, 0x8B, 0x26,
  33284. 0x22, 0x28, 0x84, 0xA0, 0x58, 0x00, 0x2D, 0x55,
  33285. 0xEA, 0x2A, 0x80, 0x0D, 0x6C, 0x97, 0x0E, 0x8B,
  33286. 0xF7, 0x67, 0xB2, 0x8B, 0x2D, 0xDE, 0x8F, 0x58,
  33287. 0xFE, 0x97, 0x81, 0xE7, 0xE2, 0x58, 0x8D, 0x7E,
  33288. 0x1B, 0xAB, 0xE5, 0x15, 0x9D, 0x54, 0xF4, 0x00,
  33289. 0x34, 0x1D, 0x12, 0x1B, 0x03, 0x23, 0x2B, 0x06,
  33290. 0x2E, 0x8C, 0xD0, 0x0A, 0xDC, 0x19, 0xA1, 0x69,
  33291. 0x1D, 0x72, 0x91, 0xB4, 0xED, 0x0E, 0x81, 0xF7,
  33292. 0x05, 0x99, 0x84, 0xFC, 0x74, 0x0F, 0x7D, 0xF8,
  33293. 0x9B, 0x3E, 0x7F, 0x63, 0x7C, 0x73, 0xEB, 0xF5,
  33294. 0x36, 0xB3, 0x24, 0x22, 0xAA, 0x33, 0x0C, 0x30,
  33295. 0x42, 0xC3, 0xE2, 0x04, 0x6B, 0x3F, 0x2A, 0x0D,
  33296. 0xAB, 0xE8, 0x5A, 0x9A, 0x09, 0xD7, 0xB6, 0xAA,
  33297. 0x9C, 0x3E, 0xD0, 0x9E, 0xB5, 0x9B, 0x52, 0x7B,
  33298. 0xAF, 0x2D, 0x6B, 0xE0, 0x40, 0x12, 0x34, 0xBE,
  33299. 0x49, 0xAB, 0xD2, 0xC8, 0xB5, 0x89, 0x1B, 0x79,
  33300. 0xEC, 0xAE, 0x88, 0x89, 0x3C, 0x05, 0xC7, 0x75,
  33301. 0xC5, 0x84, 0xF7, 0x10, 0x49, 0x48, 0x92, 0x69,
  33302. 0x9E, 0xD5, 0x56, 0xB2, 0x1E, 0x81, 0x18, 0x78,
  33303. 0xCB, 0x93, 0x5D, 0x70, 0x3A, 0xB2, 0x67, 0xD1,
  33304. 0xCC, 0x8F, 0x83, 0x03, 0xB9, 0x64, 0x46, 0x22,
  33305. 0x78, 0x0D, 0x55, 0x67, 0x22, 0x58, 0x0E, 0x22,
  33306. 0x6B, 0xBA, 0x01, 0xD4, 0x77, 0x05, 0xA7, 0xAC,
  33307. 0xB7, 0xE5, 0xFC, 0xE6, 0x11, 0xCC, 0x92, 0x5A,
  33308. 0x8C, 0xC0, 0x08, 0x24, 0xAF, 0xCC, 0x4D, 0xBD,
  33309. 0x79, 0xD3, 0x5C, 0x52, 0x2C, 0xFF, 0x1A, 0x48,
  33310. 0xBB, 0x91, 0x59, 0x6A, 0x80, 0x32, 0x8C, 0x75,
  33311. 0x7C, 0xD2, 0xC1, 0x94, 0x94, 0xA8, 0x55, 0x4B,
  33312. 0xF2, 0x96, 0xF7, 0x86, 0xF7, 0x53, 0x4F, 0x54,
  33313. 0x74, 0x05, 0x5C, 0xEF, 0x02, 0xA0, 0x8A, 0xD1,
  33314. 0x88, 0x72, 0xEB, 0x1B, 0x82, 0xF9, 0xFB, 0xDA,
  33315. 0xBC, 0xB9, 0x90, 0x98, 0xF2, 0x4B, 0x9A, 0xA6,
  33316. 0x89, 0xD5, 0xB3, 0xD8, 0x7B, 0x94, 0xE3, 0x1F,
  33317. 0x17, 0x4F, 0xEB, 0x24, 0x06, 0x2B, 0xAB, 0x5F,
  33318. 0x27, 0x9B, 0xCD, 0xCE, 0x50, 0x06, 0x40, 0xDD,
  33319. 0x7A, 0x8C, 0x67, 0xF0, 0x8E, 0x07, 0xB4, 0x1C,
  33320. 0x3C, 0x13, 0xB2, 0x07, 0x6A, 0x38, 0x59, 0x94,
  33321. 0x2C, 0xB1, 0x72, 0xA8, 0x77, 0x5B, 0x15, 0x8F,
  33322. 0x88, 0xC4, 0x5C, 0xDC, 0x92, 0xCA, 0xC0, 0xED,
  33323. 0x02, 0xFF, 0x1D, 0x57, 0x25, 0xBE, 0x67, 0x3E,
  33324. 0x4C, 0xE8, 0x95, 0x2A, 0x80, 0xB2, 0x5D, 0xBC,
  33325. 0xFA, 0x17, 0xA9, 0x35, 0x0A, 0x6B, 0x07, 0xC8,
  33326. 0x8F, 0x88, 0x8D, 0xBC, 0x97, 0x84, 0xE2, 0x07,
  33327. 0x57, 0x92, 0x99, 0x4B, 0xE8, 0xDD, 0xD7, 0xA4,
  33328. 0x58, 0xCB, 0x61, 0xCE, 0x16, 0xFC, 0x22, 0xCD,
  33329. 0x4B, 0x1A, 0x08, 0xC9, 0xAD, 0x3D, 0xB1, 0xF2,
  33330. 0xA9, 0x1B, 0x8E, 0xD0, 0xC7, 0xBC, 0xCE, 0xF9,
  33331. 0x0A, 0x7A, 0x4D, 0xBE, 0x82, 0x0A, 0xBD, 0x6C,
  33332. 0x42, 0x99, 0xBF, 0x86, 0x65, 0x53, 0xAA, 0x04,
  33333. 0x79, 0xD6, 0x6D, 0x7E, 0x0F, 0x40, 0xFA, 0xEE,
  33334. 0xCE, 0x38, 0x3B, 0x1C, 0x2F, 0xA4, 0x45, 0xA3,
  33335. 0x78, 0x2B, 0xA0, 0x29, 0xC5, 0xAA, 0xA9, 0x09,
  33336. 0x29, 0x51, 0xDC, 0x5B, 0xB5, 0x95, 0xE4, 0xCE,
  33337. 0xC8, 0x50, 0x71, 0x2D, 0xE9, 0x32, 0x12, 0xA0,
  33338. 0x7C, 0x88, 0x6B, 0xED, 0xE4, 0x38, 0xB7, 0x92,
  33339. 0xCA, 0xE4, 0xDC, 0xD4, 0x05, 0x3B, 0x2B, 0x84,
  33340. 0x95, 0x07, 0xFF, 0xF4, 0x79, 0xFF, 0x1E, 0x73,
  33341. 0x1B, 0x8E, 0xDF, 0xA3, 0x15, 0xBD, 0x56, 0xAC,
  33342. 0xDA, 0xAD, 0x73, 0x95, 0xC2, 0xD3, 0x72, 0xA8,
  33343. 0xF0, 0x8E, 0x6C, 0xE3, 0x7D, 0xBE, 0x4C, 0x87,
  33344. 0xFC, 0x0F, 0xA6, 0x3B, 0xED, 0xA4, 0x0F, 0x4F,
  33345. 0xF1, 0x5D, 0xF2, 0x56, 0x54, 0xD1, 0xCE, 0x6C,
  33346. 0xCA, 0x1C, 0xCB, 0xC2, 0x45, 0x7F, 0x90, 0x61,
  33347. 0x0E, 0x3D, 0xCE, 0xBB, 0x5E, 0x41, 0x38, 0x2B,
  33348. 0xD4, 0x41, 0x7C, 0x67, 0x7C, 0x71, 0x95, 0x34,
  33349. 0xD7, 0xED, 0x4D, 0xAC, 0x6E, 0xF1, 0x46, 0xEA,
  33350. 0x7D, 0xA4, 0x4C, 0x69, 0x0B, 0x9C, 0x2F, 0xAA,
  33351. 0xF1, 0x17, 0x90, 0x1B, 0xF4, 0x4C, 0x03, 0xBE,
  33352. 0x9D, 0x56, 0xCE, 0x0C, 0xCF, 0xE0, 0x87, 0x44,
  33353. 0xBE, 0x2C, 0x52, 0xD3, 0xBC, 0xAE, 0x02, 0x30,
  33354. 0xC7, 0x26, 0x06, 0x88, 0xA6, 0xAA, 0x9D, 0x50,
  33355. 0xF1, 0x94, 0x58, 0xC7, 0x60, 0xF3, 0xA0, 0x6F,
  33356. 0x53, 0x66, 0x53, 0xCD, 0x1D, 0xBE, 0xD1, 0xF2,
  33357. 0x39, 0xBA, 0x1F, 0xE8, 0x40, 0x84, 0xCD, 0x1C,
  33358. 0x8F, 0x3D, 0xB7, 0xD1, 0x51, 0x00, 0xDE, 0xB8,
  33359. 0x11, 0xD9, 0x66, 0xAD, 0xD5, 0xE9, 0x33, 0x09,
  33360. 0xE1, 0xA8, 0x00, 0x58, 0x65, 0xF1, 0xC1, 0x67,
  33361. 0xB4, 0x3A, 0xA7, 0x98, 0x90, 0x6A, 0xDB, 0x91,
  33362. 0xDB, 0x4A, 0x16, 0x35, 0xDC, 0x3D, 0x69, 0xEB,
  33363. 0x7B, 0xDE, 0xCC, 0x91, 0x1B, 0x8D, 0xE6, 0x46,
  33364. 0x61, 0x8E, 0x3F, 0x4C, 0x88, 0x81, 0x85, 0x4A,
  33365. 0x73, 0x08, 0x56, 0x52, 0xAE, 0xE6, 0x4A, 0x60,
  33366. 0x4A, 0x2E, 0x0C, 0x9A, 0x93, 0x76, 0x35, 0xC9,
  33367. 0x36, 0x28, 0x0C, 0x72, 0x19, 0xAD, 0x33, 0xCF,
  33368. 0x2B, 0xFB, 0xCE, 0x1A, 0x7D, 0xAC, 0xAA, 0x75,
  33369. 0x15, 0x76, 0x81, 0x52, 0x55, 0xCC, 0xB9, 0x39,
  33370. 0x07, 0xA3, 0x39, 0x12, 0x8D, 0x6F, 0x53, 0xAF,
  33371. 0xC7, 0x14, 0x7F, 0xC7, 0x96, 0x5A, 0x49, 0x3C,
  33372. 0x5C, 0xB0, 0x26, 0x47, 0xF4, 0x9D, 0xCA, 0x23,
  33373. 0xA6, 0x7D, 0xA6, 0x61, 0xC4, 0xA3, 0x26, 0x40,
  33374. 0x0F, 0xA7, 0x27, 0x09, 0xBC, 0x39, 0xFD, 0xA7,
  33375. 0x75, 0x38, 0x74, 0xD0, 0x9D, 0x29, 0x15, 0x97,
  33376. 0xDE, 0x25, 0x60, 0x4D, 0x19, 0x36, 0x04, 0xFB,
  33377. 0xA5, 0x2C, 0xB0, 0xC8, 0xB5, 0xFE, 0xE5, 0x94,
  33378. 0x7C, 0xE2, 0x1F, 0x84, 0xBB, 0xFB, 0x78, 0x9E,
  33379. 0xA5, 0x7C, 0x5D, 0x4A, 0xB2, 0x48, 0x6F, 0x6E,
  33380. 0x67, 0x95, 0x16, 0x5F, 0x01, 0x2A, 0xF8, 0x70,
  33381. 0x95, 0xCB, 0x06, 0x93, 0x26, 0x6E, 0x7A, 0x75,
  33382. 0xB5, 0xE5, 0x4E, 0x27, 0x1D, 0x8B, 0x30, 0xA6,
  33383. 0x67, 0x67, 0xD6, 0xE2, 0xD6, 0xD1, 0x99, 0xA4,
  33384. 0x55, 0x73, 0x19, 0x32, 0xF6, 0x0B, 0x6B, 0x4A,
  33385. 0xEE, 0x23, 0x33, 0x38, 0x30, 0x68, 0x6F, 0x8E,
  33386. 0x60, 0xA9, 0x60, 0x97, 0x3E, 0xEA, 0x5D, 0xE1,
  33387. 0x40, 0x6F, 0x0C, 0x76, 0x84, 0xCF, 0xAF, 0x86,
  33388. 0x8D, 0x36, 0xE5, 0x7D, 0xAE, 0x9A, 0x13, 0x70,
  33389. 0x22, 0x2A, 0x31, 0xFE, 0xC2, 0xFB, 0xE1, 0x58,
  33390. 0xA5, 0x4E, 0xEF, 0x10, 0x5B, 0x5E, 0xD4, 0x39,
  33391. 0xFC, 0xF9, 0x15, 0x64, 0x78, 0x43, 0x7D, 0x03,
  33392. 0x9F, 0x5B, 0xCB, 0x86, 0xD2, 0xEF, 0x28, 0xBD,
  33393. 0x14, 0xCB, 0x8A, 0x04, 0x1D, 0x59, 0x23, 0x53,
  33394. 0x4D, 0x13, 0xF9, 0x93, 0xFE, 0x19, 0x9C, 0xC3,
  33395. 0x3F, 0xD9, 0xC1, 0x12, 0x94, 0x84, 0x13, 0x95,
  33396. 0x8F, 0xD9, 0x10, 0xAB, 0x37, 0x69, 0x08, 0x04,
  33397. 0x4A, 0x97, 0x82, 0x28, 0x75, 0xBB, 0xC9, 0xF4,
  33398. 0x3F, 0x19, 0x6B, 0x00, 0x4C, 0x56, 0x16, 0x1F,
  33399. 0x50, 0x82, 0xD1, 0x45, 0xFF, 0x0C, 0x37, 0x28,
  33400. 0x04, 0xBB, 0x6C, 0x00, 0x97, 0x3A, 0x79, 0x2D,
  33401. 0x9A, 0xB9, 0xA5, 0x16, 0x52, 0x02, 0xA3, 0x86,
  33402. 0x81, 0xAA, 0x3A, 0x31, 0xE5, 0xB5, 0x44, 0x2D,
  33403. 0x34, 0xE2, 0x7A, 0xD8, 0xFE, 0xA1, 0x36, 0xC0,
  33404. 0x36, 0x65, 0x73, 0x12, 0x9F, 0x61, 0x3F, 0x59,
  33405. 0xC9, 0x68, 0xB6, 0x34, 0x41, 0x40, 0x25, 0xD6,
  33406. 0xE7, 0xAD, 0x25, 0x7D, 0xCB, 0xF1, 0x2A, 0xD8,
  33407. 0x53, 0x48, 0x9D, 0xBF, 0xB5, 0xD5, 0x61, 0x18,
  33408. 0x0E, 0x2A, 0x21, 0x3E, 0x61, 0x18, 0x07, 0x8E,
  33409. 0x6F, 0x9A, 0x96, 0xA8, 0x61, 0xFE, 0x8D, 0x66,
  33410. 0x1A, 0x21, 0x99, 0xD9, 0x60, 0x8B, 0xAC, 0x85,
  33411. 0x84, 0x3D, 0x41, 0xF9, 0x93, 0x35, 0x24, 0x32,
  33412. 0xFF, 0xC0, 0x8A, 0xFA, 0xBC, 0xA7, 0x85, 0x57,
  33413. 0x3C, 0x16, 0x83, 0xAE, 0x90, 0xDE, 0x40, 0x12,
  33414. 0xE4, 0x2B, 0xA2, 0x47, 0xA4, 0x92, 0x73, 0x54,
  33415. 0x6C, 0xA5, 0xB7, 0xEE, 0x62, 0xEA, 0x62, 0x37,
  33416. 0xD9, 0xD7, 0x73, 0x58, 0x43, 0xDB, 0x20, 0x60,
  33417. 0x8C, 0x4F, 0x87, 0x58, 0xB2, 0x2B, 0xC3, 0x40,
  33418. 0xB0, 0xC1, 0xB6, 0xB6, 0xA9, 0xCD, 0xCC, 0x05,
  33419. 0x4F, 0x38, 0x5F, 0x08, 0xB3, 0x3B, 0x08, 0x4D,
  33420. 0x78, 0x6B, 0x0D, 0x40, 0x46, 0xB9, 0x20, 0xDE,
  33421. 0x29, 0x6F, 0x23, 0x96, 0xDA, 0x02, 0xF5, 0x1C,
  33422. 0x1A, 0x1A, 0x36, 0xA3, 0x3A, 0xFA, 0x1D, 0x80,
  33423. 0x36, 0x3C, 0xF6, 0xB4, 0xDC, 0x2C, 0x88, 0x54,
  33424. 0xF7, 0x86, 0xC6, 0xF2, 0x15, 0xF8, 0x85, 0x33,
  33425. 0xFB, 0x21, 0x20, 0x59, 0xCE, 0x60, 0x4B, 0xE8,
  33426. 0xF1, 0xB7, 0x54, 0x17, 0x1E, 0x83, 0xCD, 0x82,
  33427. 0x39, 0x40, 0x14, 0x31, 0xEC, 0x89, 0xC8, 0xE2,
  33428. 0x6A, 0xAE, 0x3F, 0x49, 0x5B, 0x38, 0xE7, 0xCD,
  33429. 0xE2, 0xF6, 0xEF, 0x90, 0x51, 0x10, 0x83, 0x79,
  33430. 0x27, 0x80, 0x2F, 0x45, 0x78, 0x67, 0xAF, 0xF4,
  33431. 0x65, 0x95, 0x2D, 0xFE, 0x00, 0xF3, 0x2A, 0x60,
  33432. 0x00, 0xF7, 0x26, 0xFA, 0x3C, 0xAD, 0xA9, 0xAF,
  33433. 0xCA, 0xF6, 0x69, 0x48, 0x03, 0xBE, 0x18, 0x73,
  33434. 0x54, 0x06, 0x06, 0x3E, 0x4E, 0xAD, 0xFC, 0x8B,
  33435. 0xC3, 0x43, 0x24, 0x5D, 0xE9, 0xDE, 0x78, 0xDC,
  33436. 0xD0, 0xA7, 0x04, 0x77, 0xF0, 0x0D, 0xA3, 0x37,
  33437. 0x8C, 0x5F, 0x8B, 0xDF, 0xBE, 0x90, 0x1F, 0xA6,
  33438. 0xB3, 0x17, 0x9D, 0x68, 0x36, 0x45, 0x11, 0x60,
  33439. 0xFF, 0xF9, 0xBA, 0xDA, 0x80, 0xAA, 0x37, 0x57,
  33440. 0xDD, 0x34, 0x30, 0x42, 0x7A, 0x9C, 0x86, 0xB4,
  33441. 0x91, 0x30, 0xB8, 0xC0, 0xC4, 0x29, 0x15, 0x31,
  33442. 0xF3, 0x9A, 0xB0, 0xCD, 0xAC, 0x8C, 0x7C, 0x8C,
  33443. 0x4A, 0xDC, 0x76, 0xB6, 0x31, 0x30, 0xDE, 0x2D,
  33444. 0x81, 0x04, 0xC7, 0x48, 0x73, 0x69, 0x02, 0x40,
  33445. 0x30, 0x19, 0x66, 0x94, 0x21, 0x65, 0x13, 0x18,
  33446. 0xC2, 0x09, 0x14, 0x5F, 0xC4, 0x2F, 0xC4, 0xD6,
  33447. 0xA6, 0x05, 0x37, 0xAF, 0x72, 0x0C, 0x47, 0x02,
  33448. 0x29, 0x95, 0x08, 0x9D, 0xC9, 0x07, 0x31, 0x38,
  33449. 0xA9, 0xB5, 0xDA, 0x21, 0x76, 0x1D, 0x84, 0xD0,
  33450. 0x15, 0xAF, 0x2A, 0xA3, 0x69, 0x0A, 0xE9, 0x4F,
  33451. 0x75, 0x8A, 0x50, 0xA5, 0x11, 0xD4, 0x5F, 0xAF,
  33452. 0x70, 0x43, 0xCB, 0xD7, 0x03, 0x9E, 0xB0, 0xBD,
  33453. 0x19, 0x47, 0x94, 0x58, 0x22, 0x86, 0xC6, 0xE3,
  33454. 0x62, 0xD8, 0x63, 0x05, 0xD9, 0xE2, 0xE5, 0x4A,
  33455. 0x04, 0x54, 0x5A, 0x55, 0x25, 0xAD, 0x15, 0x5C,
  33456. 0x4B, 0x71, 0x25, 0xE1, 0x50, 0xE3, 0x62, 0x1B,
  33457. 0xD2, 0x43, 0x28, 0xD2, 0x84, 0xE4, 0xE2, 0x05,
  33458. 0xE3, 0x01, 0x4C, 0x8F, 0x38, 0x17, 0x49, 0xFD,
  33459. 0x3B, 0x52, 0x1A, 0x55, 0xB3, 0x1D, 0x69, 0x83,
  33460. 0xAB, 0x9E, 0xC4, 0x73, 0xEE, 0x64, 0x7A, 0x73,
  33461. 0x19, 0xEF, 0xCD, 0x7D, 0xB7, 0xF4, 0x2E, 0xCB,
  33462. 0x55, 0x2A, 0x8A, 0xCC, 0x8F, 0xF8, 0x4E, 0xFB,
  33463. 0xD2, 0x63, 0x8F, 0xF1, 0x10, 0x89, 0x02, 0x93,
  33464. 0x3E, 0xAC, 0xA4, 0xB4, 0x89, 0xC7, 0xF7, 0x8B,
  33465. 0x3E, 0xE1, 0xE8, 0x93, 0xB9, 0x8E, 0x36, 0x25,
  33466. 0xC1, 0xC0, 0xD9, 0x44, 0x81, 0xC0, 0x99, 0x3C,
  33467. 0x2B, 0x89, 0xF7, 0xDF, 0xDB, 0xD8, 0xCC, 0x84,
  33468. 0xE6, 0xFF, 0xFE, 0xAC, 0x21, 0x16, 0xF1, 0xE2,
  33469. 0xEF, 0x0A, 0x32, 0xA7, 0xDE, 0x87, 0x51, 0xEC,
  33470. 0xB1, 0x0C, 0x0B, 0xC7, 0x07, 0xD9, 0x9A, 0xF8,
  33471. 0xE8, 0xB0, 0xFE, 0xA5, 0x67, 0xAF, 0x53, 0x9F,
  33472. 0xEF, 0x23, 0xEF, 0x7D, 0xFF, 0xA8, 0x8E, 0xDE,
  33473. 0x97, 0x93, 0x32, 0xA6, 0x7C, 0xCF, 0x49, 0xBC,
  33474. 0x36, 0x0D, 0x88, 0x90, 0x89, 0x39, 0x76, 0xA8,
  33475. 0x82, 0x19, 0x02, 0xB6, 0x02, 0x82, 0xFE, 0xED,
  33476. 0x9C, 0x28, 0x8D, 0xB0, 0x1E, 0x2B, 0x2A, 0xCF,
  33477. 0xF3, 0x94, 0xFF, 0x66, 0x33, 0x93, 0x31, 0xD6,
  33478. 0xFC, 0xAF, 0xE7, 0xC5, 0x98, 0x01, 0x46, 0xCD,
  33479. 0xCB, 0xC4, 0x41, 0x13, 0x6D, 0x42, 0xF5, 0x13,
  33480. 0xDF, 0xF9, 0x97, 0x65, 0xD4, 0x7B, 0x6E, 0x10,
  33481. 0x79, 0x5D, 0x5A, 0x82, 0xA2, 0x49, 0x53, 0xA7,
  33482. 0x6D, 0x9C, 0xDD, 0x0A, 0x80, 0x98, 0x58, 0x07,
  33483. 0x30, 0xBF, 0x0B, 0x30, 0xAC, 0x24, 0x9E, 0xA0,
  33484. 0xE8, 0xE4, 0x7A, 0x0D, 0xD0, 0x50, 0x82, 0xAE,
  33485. 0xBB, 0xEC, 0x15, 0x30, 0x2A, 0xF2, 0xA7, 0xA6,
  33486. 0x6A, 0xC8, 0xAE, 0x1E, 0x14, 0x80, 0x7C, 0x18,
  33487. 0xE7, 0x2B, 0x88, 0x65, 0xB7, 0x93, 0x12, 0xB3,
  33488. 0xC1, 0x2A, 0x20, 0xAD, 0x3B, 0x2E, 0x84, 0xC4,
  33489. 0x0D, 0xA7, 0x62, 0x5C, 0x79, 0x52, 0x5D, 0x59,
  33490. 0xA4, 0x69, 0x5C, 0x26, 0xFD, 0x4F, 0x80, 0xCC,
  33491. 0xFE, 0x8E, 0x70, 0x72, 0xB1, 0x41, 0xE1, 0x75,
  33492. 0x53, 0x51, 0xCF, 0x4C, 0x0B, 0x57, 0xF2, 0xB8,
  33493. 0x59, 0x76, 0xE6, 0xEF, 0x6D, 0x74, 0xA6, 0x73,
  33494. 0x69, 0x7F, 0x7C, 0xB2, 0x35, 0xFE, 0x8A, 0x02,
  33495. 0x2F, 0xBE, 0x7C, 0x4D, 0x02, 0xBE, 0x8F, 0xFB,
  33496. 0x7A, 0x58, 0x45, 0xEC, 0xBA, 0x1B, 0xC6, 0xB9,
  33497. 0x8D, 0xF5, 0xB0, 0x82, 0xD1, 0xB4, 0x97, 0x86,
  33498. 0x9B, 0x33, 0x54, 0x49, 0x5B, 0x88, 0xD9, 0xB5,
  33499. 0xD0, 0x93, 0x8A, 0x00, 0x5D, 0x0F, 0x37, 0x88,
  33500. 0x57, 0xE3, 0xFA, 0x7E, 0x7B, 0xFA, 0x43, 0x74,
  33501. 0x8D, 0x64, 0x07, 0xD7, 0x07, 0x85, 0x4D, 0x49,
  33502. 0xBC, 0x83, 0xF5, 0xD4, 0x95, 0x3E, 0x3E, 0x09,
  33503. 0x65, 0xF3, 0xFC, 0x88, 0xA7, 0xF0, 0x46, 0x61,
  33504. 0x44, 0x7D, 0x76, 0xED, 0xC9, 0x8D, 0x0F, 0x8D,
  33505. 0xDA, 0x0D, 0x01, 0xC8, 0xB1, 0xA8, 0x9B, 0x4A,
  33506. 0xF0, 0xA3, 0x88, 0x54, 0xC1, 0xD6, 0x52, 0x97
  33507. };
  33508. #endif /* WOLFSSL_NO_ML_DSA_65 */
  33509. #ifndef WOLFSSL_NO_ML_DSA_87
  33510. static const byte seed_87[] = {
  33511. 0x22, 0x5F, 0x77, 0x07, 0x5E, 0x66, 0xCE, 0x1C,
  33512. 0x99, 0xBA, 0x95, 0xB4, 0xFC, 0xDF, 0x25, 0x8B,
  33513. 0xBB, 0x6F, 0xA5, 0xFE, 0x9C, 0x34, 0x9F, 0x0F,
  33514. 0xDE, 0x3F, 0x71, 0xD5, 0x33, 0x9F, 0x6F, 0xD8
  33515. };
  33516. static const byte pk_87[] = {
  33517. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  33518. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  33519. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  33520. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  33521. 0x24, 0xBF, 0x9E, 0x97, 0x9C, 0xD2, 0x3E, 0xDA,
  33522. 0x8A, 0x1B, 0xB6, 0x76, 0xDA, 0x7D, 0x7F, 0x44,
  33523. 0xAD, 0x6B, 0xB9, 0xB0, 0x70, 0xD3, 0xD6, 0x44,
  33524. 0x7F, 0xBE, 0x6C, 0x0C, 0x71, 0x37, 0xC6, 0xFB,
  33525. 0x7B, 0x39, 0x83, 0x63, 0x9C, 0x41, 0x5C, 0xF2,
  33526. 0xC9, 0x15, 0xFF, 0xD4, 0x18, 0xEA, 0xA1, 0x4D,
  33527. 0xA9, 0xD1, 0xAD, 0x3C, 0x09, 0x8E, 0xA9, 0x05,
  33528. 0x34, 0x6C, 0xAA, 0x75, 0x78, 0xF8, 0x6B, 0x6E,
  33529. 0x52, 0xE6, 0x57, 0x55, 0x16, 0xF4, 0x92, 0x3E,
  33530. 0x74, 0x3F, 0x96, 0xA3, 0x2A, 0xD0, 0x0E, 0xEE,
  33531. 0xA1, 0xCE, 0x8A, 0x33, 0xF4, 0x87, 0xB9, 0xF3,
  33532. 0x22, 0x5D, 0x2D, 0x84, 0xCD, 0x27, 0x57, 0xCC,
  33533. 0xCF, 0xE6, 0xA3, 0x66, 0x24, 0x53, 0x0E, 0x52,
  33534. 0x8A, 0x2F, 0x64, 0xFC, 0xE7, 0x04, 0xE7, 0xA7,
  33535. 0x6C, 0x2E, 0x6A, 0xDC, 0x00, 0xEF, 0x9B, 0xEC,
  33536. 0x91, 0x07, 0xB9, 0x69, 0x8F, 0x11, 0x59, 0xFC,
  33537. 0x52, 0xEF, 0x4C, 0x36, 0x5A, 0xFD, 0xB1, 0x50,
  33538. 0xED, 0xC3, 0x43, 0x5E, 0x03, 0xBB, 0x70, 0x26,
  33539. 0x00, 0x6E, 0x5A, 0x55, 0x13, 0x51, 0xA4, 0xB1,
  33540. 0x5F, 0xB8, 0x9F, 0xD2, 0xE9, 0x98, 0x38, 0xE8,
  33541. 0xCF, 0x41, 0x73, 0xFD, 0x0D, 0xF1, 0xF6, 0x80,
  33542. 0x89, 0xE1, 0x51, 0x8D, 0xD4, 0xB5, 0x79, 0x27,
  33543. 0x76, 0xBD, 0xD9, 0x2F, 0xC7, 0xC7, 0x9B, 0xC7,
  33544. 0x99, 0x7F, 0x78, 0x84, 0xD2, 0xB8, 0x80, 0xC5,
  33545. 0xD2, 0xB7, 0xEE, 0xC8, 0x0A, 0xFE, 0x35, 0x59,
  33546. 0x84, 0x5D, 0x39, 0x08, 0x39, 0xBE, 0x5E, 0xBF,
  33547. 0x95, 0x93, 0xA7, 0x3E, 0xD0, 0x1E, 0xF6, 0x7D,
  33548. 0x50, 0x3F, 0xFB, 0x74, 0x47, 0x04, 0xA2, 0xDC,
  33549. 0x49, 0x48, 0x76, 0x2B, 0xC8, 0x43, 0x45, 0x75,
  33550. 0x72, 0x84, 0x4D, 0x15, 0x74, 0xE3, 0xEB, 0x37,
  33551. 0x83, 0x0A, 0x3B, 0x7C, 0xD4, 0x02, 0xC7, 0x6E,
  33552. 0xD5, 0xB4, 0xFC, 0x15, 0xF0, 0x5E, 0x76, 0x03,
  33553. 0x4C, 0xBB, 0x6A, 0x29, 0xDE, 0xBC, 0x7E, 0x2B,
  33554. 0x34, 0xB2, 0x14, 0x2A, 0x57, 0xCF, 0x1B, 0x39,
  33555. 0x73, 0xE5, 0x8B, 0xFF, 0x47, 0x50, 0x42, 0xDC,
  33556. 0x22, 0x6C, 0x7E, 0x13, 0x71, 0xF3, 0x37, 0x51,
  33557. 0x40, 0xF2, 0x90, 0x57, 0xAC, 0xB4, 0x64, 0x7C,
  33558. 0x5F, 0x92, 0x6D, 0x3F, 0xDC, 0xCC, 0xC8, 0xD2,
  33559. 0xE1, 0x6B, 0x81, 0xA9, 0xED, 0xCD, 0x0C, 0x8B,
  33560. 0x5B, 0x2E, 0x11, 0x89, 0x87, 0x42, 0x4B, 0xEC,
  33561. 0xAD, 0x40, 0xA5, 0xE5, 0xB4, 0x6D, 0x1C, 0xB4,
  33562. 0x01, 0x0A, 0x8E, 0x9F, 0x6F, 0x25, 0x92, 0x5D,
  33563. 0xFE, 0x6B, 0x6F, 0x24, 0x64, 0x5F, 0x9C, 0x88,
  33564. 0x86, 0x96, 0xE8, 0x79, 0x64, 0x5B, 0x6A, 0x3A,
  33565. 0x76, 0x21, 0x90, 0xCC, 0xB7, 0xD6, 0x26, 0x9D,
  33566. 0x35, 0x54, 0x79, 0xDF, 0x71, 0x90, 0x55, 0x2A,
  33567. 0x38, 0x52, 0xD1, 0xE9, 0x56, 0x73, 0xE7, 0x19,
  33568. 0x44, 0x6A, 0xD3, 0x10, 0x24, 0xB9, 0x4B, 0xF8,
  33569. 0xBB, 0xC9, 0x7B, 0x04, 0x66, 0x39, 0xCE, 0x12,
  33570. 0x3F, 0xDE, 0xC3, 0x75, 0xAF, 0x9F, 0x8D, 0x4C,
  33571. 0xF7, 0x16, 0x9B, 0xEB, 0x5F, 0xE5, 0x1B, 0xBF,
  33572. 0x82, 0x2C, 0x53, 0xBA, 0x2D, 0x98, 0xA4, 0xA0,
  33573. 0x14, 0xA2, 0xDE, 0x69, 0x7F, 0x03, 0x3C, 0x9E,
  33574. 0x4A, 0x57, 0xC6, 0xED, 0xF6, 0x10, 0x6A, 0x76,
  33575. 0x2A, 0x81, 0x92, 0x9F, 0x3E, 0xF0, 0xFD, 0xE9,
  33576. 0xB7, 0xB3, 0x8A, 0xF6, 0x1A, 0x19, 0x9A, 0x16,
  33577. 0x0F, 0x09, 0x45, 0xBD, 0xBB, 0x96, 0x7C, 0x72,
  33578. 0x40, 0xFE, 0x94, 0xBD, 0xE1, 0x60, 0x50, 0x53,
  33579. 0x13, 0xC9, 0x2B, 0xFA, 0x52, 0x40, 0xA2, 0xA7,
  33580. 0xF0, 0x8C, 0x85, 0x78, 0xDB, 0xD6, 0x7F, 0x21,
  33581. 0x39, 0xB5, 0x06, 0x72, 0xEE, 0x99, 0xA1, 0xBD,
  33582. 0x78, 0x1F, 0xA4, 0xE9, 0x54, 0xF4, 0xFA, 0xDF,
  33583. 0xA7, 0x9E, 0xDD, 0x8E, 0xB1, 0xCF, 0xA8, 0x48,
  33584. 0x84, 0x5D, 0x70, 0xCB, 0x2D, 0xA9, 0x66, 0x09,
  33585. 0x0B, 0x75, 0x75, 0xA2, 0x32, 0xFE, 0xDF, 0x96,
  33586. 0x33, 0x84, 0xA7, 0x84, 0x48, 0x1A, 0xFA, 0x82,
  33587. 0x79, 0x0A, 0x87, 0xE1, 0x1F, 0x11, 0x74, 0xD4,
  33588. 0x3C, 0xC0, 0x8D, 0x4F, 0xD2, 0x5D, 0xBB, 0x40,
  33589. 0x10, 0xB2, 0x6F, 0x23, 0xD2, 0xD6, 0xF4, 0xA5,
  33590. 0x87, 0xEF, 0x7D, 0xE8, 0xC6, 0xF7, 0xC6, 0x0F,
  33591. 0xF9, 0x6F, 0xF8, 0x4C, 0x39, 0xE4, 0x82, 0x1E,
  33592. 0x1E, 0x6A, 0x80, 0x2F, 0xEC, 0x22, 0xD6, 0xA0,
  33593. 0xAA, 0xB6, 0x2C, 0xCB, 0x16, 0x43, 0x68, 0xC2,
  33594. 0x27, 0xF6, 0xA2, 0x31, 0x62, 0x66, 0xEC, 0x2F,
  33595. 0xFF, 0x8D, 0xB4, 0x19, 0x51, 0x19, 0xA0, 0x8C,
  33596. 0x67, 0xE2, 0x04, 0x04, 0xB9, 0x1F, 0x08, 0x70,
  33597. 0x9E, 0xAA, 0xC2, 0xDE, 0xCB, 0x96, 0x19, 0x8F,
  33598. 0x02, 0x74, 0x10, 0xCC, 0x1B, 0x82, 0x5D, 0x9C,
  33599. 0x07, 0x00, 0xE5, 0xD7, 0x04, 0x51, 0xBA, 0x7F,
  33600. 0x67, 0xF9, 0x64, 0x0C, 0xA3, 0x6B, 0xF3, 0x12,
  33601. 0x21, 0x80, 0x68, 0xD6, 0xA2, 0xCA, 0xFF, 0x59,
  33602. 0x33, 0x43, 0x7D, 0x67, 0xBF, 0xD4, 0x88, 0x4A,
  33603. 0x6E, 0x92, 0xBA, 0x41, 0xE1, 0x28, 0xDA, 0xEB,
  33604. 0xE1, 0xEA, 0x25, 0x60, 0xE1, 0x2F, 0xED, 0x2C,
  33605. 0xD4, 0x4B, 0xC9, 0x4E, 0x9E, 0x9D, 0xFA, 0xBB,
  33606. 0xF9, 0x61, 0x41, 0x4C, 0x24, 0x24, 0xFC, 0x9B,
  33607. 0x62, 0xFE, 0x73, 0x74, 0xF6, 0xB8, 0x9B, 0xA9,
  33608. 0x02, 0x96, 0xF4, 0x90, 0x18, 0xA7, 0xF5, 0x49,
  33609. 0xC1, 0xA3, 0x94, 0xB8, 0xED, 0xBD, 0x0B, 0xF3,
  33610. 0xDB, 0xF3, 0xBC, 0x10, 0x6A, 0x6B, 0x3F, 0x79,
  33611. 0x07, 0xF2, 0x11, 0x09, 0xD5, 0x42, 0x8F, 0xA9,
  33612. 0x09, 0x94, 0xBE, 0xF2, 0x0D, 0x3A, 0x91, 0x33,
  33613. 0x01, 0x31, 0x34, 0xBF, 0x0A, 0xCA, 0xF1, 0x3E,
  33614. 0x66, 0x18, 0xA6, 0x69, 0xEC, 0xEA, 0xC5, 0xE9,
  33615. 0x8B, 0x80, 0xFE, 0x4D, 0x93, 0x7B, 0xD4, 0xE5,
  33616. 0x74, 0x90, 0xFA, 0xFD, 0xCE, 0x45, 0xE8, 0xD7,
  33617. 0xD8, 0x8F, 0x08, 0x8B, 0x3A, 0xA8, 0x01, 0xA2,
  33618. 0xB4, 0xE5, 0xF2, 0x29, 0x41, 0x02, 0xBD, 0xCB,
  33619. 0xF9, 0x4A, 0x62, 0x54, 0x99, 0x94, 0x61, 0xB7,
  33620. 0x8F, 0xA5, 0x8A, 0x7F, 0xDC, 0xAD, 0xD2, 0xF2,
  33621. 0x28, 0x1E, 0xF3, 0x18, 0xAE, 0x21, 0x81, 0xF7,
  33622. 0xE9, 0xE5, 0xBF, 0x2B, 0xC2, 0x98, 0x24, 0xB1,
  33623. 0x45, 0x56, 0x57, 0x31, 0xA1, 0x48, 0xAB, 0x39,
  33624. 0xC2, 0x04, 0x29, 0x1B, 0x5B, 0xD3, 0x23, 0x35,
  33625. 0xCC, 0x5A, 0x58, 0x10, 0x11, 0x5B, 0xD5, 0x88,
  33626. 0xC2, 0x60, 0x37, 0x3D, 0x1C, 0x1C, 0x7B, 0x09,
  33627. 0x95, 0xB5, 0x05, 0x12, 0xD8, 0x52, 0x8D, 0xF5,
  33628. 0xBD, 0x4A, 0xA5, 0x45, 0x6F, 0x3D, 0x55, 0x9D,
  33629. 0x90, 0xAD, 0xD7, 0xA9, 0xD0, 0x25, 0x0B, 0xD7,
  33630. 0x55, 0x11, 0x5C, 0x60, 0xBF, 0xBD, 0xFB, 0x9D,
  33631. 0x2A, 0xCE, 0x4F, 0xE6, 0xB8, 0x36, 0x3A, 0x4D,
  33632. 0xE7, 0xB6, 0xFF, 0x6B, 0xD8, 0xBA, 0xD4, 0xEE,
  33633. 0x95, 0x9A, 0x0A, 0x47, 0xD4, 0x76, 0xE0, 0xF7,
  33634. 0xAC, 0x02, 0xB6, 0xA8, 0x10, 0x1E, 0xA5, 0x98,
  33635. 0xC0, 0xF4, 0x68, 0x5E, 0x55, 0xC1, 0x67, 0xCD,
  33636. 0x16, 0x31, 0xBD, 0xA2, 0x86, 0xF3, 0xF8, 0xC0,
  33637. 0xED, 0x4A, 0xFF, 0xE8, 0xF5, 0x2C, 0xFA, 0xD2,
  33638. 0x06, 0x78, 0x6D, 0x34, 0xBE, 0xF9, 0x15, 0x84,
  33639. 0x6D, 0xE5, 0x5F, 0xA4, 0xAC, 0x84, 0x3B, 0x3A,
  33640. 0xA6, 0x2D, 0xC2, 0x01, 0xE0, 0x63, 0x92, 0xC7,
  33641. 0x77, 0xB5, 0x4E, 0x2C, 0x40, 0x90, 0x48, 0xAF,
  33642. 0x8B, 0xE9, 0x6C, 0x1E, 0xEE, 0x16, 0x8F, 0x4E,
  33643. 0x4F, 0xFF, 0x35, 0x15, 0xE5, 0x51, 0xF4, 0xB2,
  33644. 0x23, 0x1C, 0x6A, 0xCE, 0x05, 0xDC, 0xDC, 0xAD,
  33645. 0x7F, 0x9D, 0xDA, 0xB3, 0x0C, 0xAD, 0x9C, 0x62,
  33646. 0x68, 0xD6, 0x84, 0x00, 0x76, 0xFF, 0xD3, 0x01,
  33647. 0x18, 0xB0, 0xC4, 0xE5, 0xE5, 0x0D, 0x87, 0x8E,
  33648. 0xAF, 0x77, 0xEE, 0xCB, 0x56, 0x88, 0x7F, 0xED,
  33649. 0xC5, 0x7C, 0x54, 0xD6, 0x28, 0x46, 0xE0, 0x8C,
  33650. 0xE6, 0x87, 0xF2, 0x4D, 0x0D, 0x2F, 0x12, 0x62,
  33651. 0x06, 0xDF, 0xB2, 0x4E, 0x03, 0x04, 0x78, 0x0B,
  33652. 0x03, 0x4C, 0xCE, 0x86, 0xD1, 0xCD, 0x53, 0x00,
  33653. 0xED, 0xC6, 0xF8, 0x9A, 0xCB, 0x59, 0x14, 0xA6,
  33654. 0x0C, 0x87, 0x35, 0x92, 0x66, 0x0D, 0x02, 0xA9,
  33655. 0xEF, 0x0D, 0x7D, 0xC6, 0x45, 0xF3, 0x11, 0xEF,
  33656. 0x1F, 0x55, 0x72, 0x1F, 0x1B, 0x45, 0xD2, 0xE4,
  33657. 0x8F, 0x3F, 0x9F, 0xEB, 0x27, 0x02, 0xD8, 0x2C,
  33658. 0xEF, 0xAD, 0x7E, 0x7E, 0x10, 0xDD, 0x91, 0x5E,
  33659. 0x39, 0x06, 0x7C, 0x39, 0xEA, 0x61, 0xB9, 0xCC,
  33660. 0xF1, 0x45, 0x56, 0x81, 0x53, 0x55, 0x42, 0xD4,
  33661. 0x37, 0x0F, 0x53, 0xF0, 0x7F, 0xA0, 0xC6, 0x50,
  33662. 0x9B, 0x1D, 0xC6, 0x7E, 0x9F, 0x1D, 0x89, 0x3B,
  33663. 0xEB, 0x85, 0x59, 0x6D, 0x9C, 0x12, 0xEE, 0xAC,
  33664. 0xFC, 0xAE, 0xC0, 0xAE, 0x5F, 0xD4, 0x9C, 0x62,
  33665. 0xE7, 0x09, 0x8C, 0xFA, 0x80, 0x1A, 0x19, 0x09,
  33666. 0x0F, 0x8D, 0x68, 0x9E, 0x45, 0x33, 0xE2, 0x58,
  33667. 0x7B, 0xEF, 0xC7, 0x6A, 0xDC, 0x38, 0x33, 0x3E,
  33668. 0x5C, 0x53, 0xB5, 0x99, 0xDB, 0x04, 0xA7, 0xEA,
  33669. 0xFB, 0x07, 0x9B, 0x25, 0x47, 0xED, 0xAC, 0x5A,
  33670. 0xAA, 0x1E, 0xE5, 0x23, 0xDE, 0x64, 0xE5, 0x87,
  33671. 0x46, 0x8C, 0x41, 0x52, 0xC9, 0x4F, 0x90, 0x48,
  33672. 0x1C, 0xAA, 0xA6, 0xB0, 0x3A, 0x1E, 0xC9, 0x08,
  33673. 0xF7, 0x82, 0x71, 0x13, 0x76, 0x6B, 0x9E, 0x52,
  33674. 0x22, 0x32, 0xE0, 0xC6, 0xF7, 0xD7, 0x4C, 0xBD,
  33675. 0xC3, 0x1C, 0x18, 0xAF, 0xA0, 0x12, 0xD3, 0x22,
  33676. 0x6A, 0xFC, 0x71, 0x8A, 0x64, 0x24, 0xAC, 0x19,
  33677. 0x4E, 0x85, 0x3C, 0x51, 0xE6, 0xA3, 0xAD, 0xA9,
  33678. 0x59, 0x94, 0xD2, 0x7F, 0xC4, 0x9D, 0x93, 0x5B,
  33679. 0x51, 0xD7, 0xF3, 0x03, 0xE7, 0x7D, 0x5B, 0x13,
  33680. 0x0E, 0xCD, 0x7D, 0x0F, 0x77, 0x3E, 0x84, 0xD7,
  33681. 0x4E, 0x69, 0x57, 0x1B, 0x73, 0x99, 0xC9, 0x4D,
  33682. 0xC0, 0x19, 0x6B, 0x9D, 0x5F, 0xBA, 0x69, 0xEE,
  33683. 0x11, 0xBD, 0x7C, 0x45, 0xD9, 0xA9, 0x65, 0x88,
  33684. 0xA7, 0x0E, 0x16, 0xBF, 0xB3, 0x82, 0x5E, 0x5E,
  33685. 0x56, 0x13, 0x02, 0x7D, 0xB1, 0xDC, 0xF5, 0x4A,
  33686. 0x82, 0x73, 0x72, 0x35, 0x9B, 0x91, 0xAC, 0x04,
  33687. 0x69, 0xE9, 0xEA, 0x19, 0xC9, 0xD8, 0x59, 0xEB,
  33688. 0x8F, 0x22, 0x5F, 0x43, 0x11, 0x0C, 0xCF, 0xB4,
  33689. 0x16, 0x6C, 0x7D, 0x60, 0xCE, 0x14, 0x24, 0xAD,
  33690. 0xD7, 0x07, 0xC2, 0x4E, 0x98, 0xA0, 0xDE, 0x9E,
  33691. 0xE6, 0x31, 0xED, 0xF8, 0x5B, 0x9C, 0xAF, 0xF7,
  33692. 0x57, 0x59, 0x10, 0xA9, 0x92, 0xDC, 0x4F, 0x0C,
  33693. 0x2B, 0x88, 0x75, 0x19, 0x1D, 0xB3, 0xBF, 0x70,
  33694. 0x23, 0x17, 0xD5, 0x1A, 0x50, 0x30, 0x18, 0x14,
  33695. 0x1A, 0x14, 0xE6, 0x1D, 0x4F, 0x8A, 0x96, 0x3E,
  33696. 0xD8, 0x6E, 0xD9, 0xBF, 0x94, 0x4E, 0xDE, 0xB8,
  33697. 0xFF, 0xE1, 0x6F, 0xFD, 0x31, 0xE8, 0xFE, 0x43,
  33698. 0xC2, 0x40, 0x82, 0x45, 0x50, 0xFE, 0x1B, 0xBC,
  33699. 0x77, 0x4B, 0xB4, 0x30, 0xA7, 0xD4, 0x46, 0x32,
  33700. 0x6A, 0xF7, 0xC5, 0x92, 0xDA, 0x70, 0xB1, 0xB7,
  33701. 0xA1, 0x5A, 0x5D, 0x17, 0x3B, 0xDB, 0x2F, 0x28,
  33702. 0x8A, 0x6E, 0xEC, 0xDA, 0xC4, 0xF7, 0x2E, 0xCB,
  33703. 0xEB, 0x96, 0x60, 0x92, 0x1B, 0xDD, 0xD6, 0x13,
  33704. 0x7C, 0x85, 0x9F, 0x8A, 0x9A, 0xE9, 0x5F, 0xC4,
  33705. 0x24, 0xFD, 0x33, 0xDF, 0xB3, 0x98, 0x66, 0xF7,
  33706. 0xA1, 0x5A, 0xDC, 0x01, 0xC9, 0xFA, 0x37, 0xF1,
  33707. 0x7B, 0xD0, 0xF6, 0x66, 0x8A, 0x26, 0x7C, 0xC2,
  33708. 0x1B, 0xFF, 0x62, 0xBC, 0xFD, 0xCD, 0x47, 0xDA,
  33709. 0xEE, 0x75, 0xF2, 0xAC, 0x60, 0x69, 0x87, 0x26,
  33710. 0xCC, 0x92, 0x10, 0x1C, 0x92, 0xC1, 0x43, 0x09,
  33711. 0xE9, 0xCE, 0x7D, 0x05, 0x5C, 0x64, 0x55, 0xCB,
  33712. 0xBB, 0x7A, 0xAE, 0x05, 0xDB, 0x38, 0xD3, 0xD5,
  33713. 0xBB, 0xD9, 0x9F, 0xCB, 0xCF, 0xB7, 0x9C, 0xEF,
  33714. 0x7E, 0x7B, 0x2A, 0x6F, 0x84, 0x4E, 0x6A, 0x7F,
  33715. 0xD3, 0x5F, 0xF3, 0xB3, 0xC1, 0xF0, 0x02, 0x9C,
  33716. 0xA2, 0x4C, 0x86, 0x0E, 0x6B, 0xE2, 0x2B, 0x1D,
  33717. 0x1D, 0xB4, 0x55, 0x7F, 0x85, 0x54, 0x2D, 0x85,
  33718. 0x64, 0x89, 0x92, 0x19, 0x65, 0x44, 0xD7, 0x95,
  33719. 0x48, 0x2C, 0x46, 0x8D, 0x0E, 0xBA, 0xFB, 0x13,
  33720. 0x63, 0x52, 0x2E, 0x22, 0x19, 0x3F, 0x7F, 0xFB,
  33721. 0x54, 0x4D, 0x73, 0xA1, 0x3C, 0x22, 0xD6, 0x5D,
  33722. 0x2B, 0x4A, 0xBD, 0xD7, 0xBB, 0x72, 0x55, 0x80,
  33723. 0xD4, 0x57, 0x4E, 0xDC, 0xF2, 0x8B, 0xB3, 0x09,
  33724. 0x6A, 0xF9, 0x1A, 0xD3, 0x41, 0x0E, 0x72, 0x95,
  33725. 0x49, 0xE7, 0xD1, 0xDC, 0x05, 0x22, 0xC3, 0x3E,
  33726. 0x26, 0x95, 0x00, 0x01, 0x8C, 0xE1, 0x54, 0x47,
  33727. 0x84, 0x10, 0xA7, 0x67, 0x45, 0xBB, 0xB9, 0x7B,
  33728. 0x0B, 0xB4, 0x74, 0x82, 0xED, 0x6C, 0x26, 0x6E,
  33729. 0xF2, 0x56, 0xCA, 0x1A, 0xD1, 0x10, 0x68, 0x40,
  33730. 0x28, 0x23, 0xD5, 0x98, 0xB3, 0x6B, 0x75, 0x16,
  33731. 0x13, 0x87, 0xE1, 0xF2, 0x3F, 0xAB, 0xC0, 0x2A,
  33732. 0xF0, 0x16, 0x59, 0x85, 0x1A, 0x5B, 0x41, 0xB7,
  33733. 0x52, 0xB1, 0x79, 0x46, 0x20, 0xDF, 0x59, 0xFB,
  33734. 0x33, 0xB3, 0x05, 0xF1, 0x12, 0x8B, 0xDB, 0x7C,
  33735. 0x51, 0x90, 0xC9, 0x8A, 0xC9, 0x48, 0x10, 0x54,
  33736. 0xF4, 0x0F, 0x88, 0x1D, 0xDB, 0x40, 0x1B, 0x3A,
  33737. 0xD7, 0x62, 0xD1, 0x75, 0x73, 0xD6, 0xCA, 0x23,
  33738. 0x26, 0xB2, 0xBF, 0x4C, 0xCA, 0x22, 0xDD, 0xF6,
  33739. 0xAF, 0x22, 0xB8, 0x4F, 0xC2, 0xC3, 0xB3, 0xD3,
  33740. 0xED, 0xFA, 0xBA, 0x2E, 0x38, 0x28, 0x6A, 0xAE,
  33741. 0x60, 0xE9, 0x2D, 0x11, 0x33, 0xED, 0x7E, 0xE9,
  33742. 0x29, 0x8E, 0x01, 0xB0, 0x0F, 0x13, 0x83, 0x44,
  33743. 0x17, 0xFA, 0xB6, 0x54, 0x7C, 0xAC, 0x1F, 0xED,
  33744. 0xC9, 0x22, 0xF2, 0x4F, 0x69, 0x24, 0x04, 0xFE,
  33745. 0xC2, 0x6A, 0xEB, 0xB0, 0xE4, 0xF5, 0x03, 0xCB,
  33746. 0xB3, 0x99, 0x50, 0x66, 0x1F, 0x6B, 0xF3, 0xFE,
  33747. 0xB7, 0xBF, 0x8D, 0xBA, 0x59, 0x75, 0x75, 0x51,
  33748. 0xB0, 0xA5, 0xB9, 0x66, 0xC8, 0xDD, 0x35, 0xAE,
  33749. 0x20, 0x66, 0x21, 0x9B, 0x04, 0x3F, 0xC6, 0x90,
  33750. 0x6F, 0x2B, 0x5C, 0x78, 0x49, 0x3C, 0x40, 0xE6,
  33751. 0xF9, 0x6B, 0x1A, 0xEF, 0xCE, 0x5A, 0xC1, 0x68,
  33752. 0xD3, 0x34, 0x05, 0xD0, 0x21, 0x6C, 0xF8, 0xA8,
  33753. 0x55, 0xE4, 0x6E, 0x80, 0x9B, 0xAD, 0xA5, 0xC3,
  33754. 0x55, 0x0B, 0x28, 0xBB, 0x54, 0x02, 0xD4, 0xF6,
  33755. 0x82, 0x73, 0xAB, 0x56, 0x0B, 0xB1, 0x5F, 0x94,
  33756. 0xC3, 0xDA, 0x24, 0x1E, 0x7F, 0x62, 0x6B, 0x98,
  33757. 0x6B, 0x2A, 0xF3, 0x92, 0x37, 0x3A, 0xB9, 0xE6,
  33758. 0x27, 0xC4, 0xBB, 0xAB, 0xE4, 0x9A, 0x60, 0xD2,
  33759. 0xAE, 0xCE, 0xFD, 0x44, 0xEB, 0x1C, 0xCF, 0x74,
  33760. 0x54, 0xFC, 0xEC, 0x4F, 0xC2, 0xBA, 0xF4, 0x3B,
  33761. 0xAC, 0x03, 0xC7, 0x2E, 0xE6, 0x62, 0x44, 0x61,
  33762. 0x42, 0xC8, 0xAE, 0xF1, 0xB2, 0xA9, 0xAC, 0xE0,
  33763. 0xCE, 0x23, 0xAF, 0xCC, 0x86, 0x61, 0xFE, 0xC5,
  33764. 0xCB, 0xAC, 0x4A, 0x1B, 0x5C, 0xC7, 0x2B, 0xFF,
  33765. 0x8A, 0x20, 0x62, 0x0E, 0xB9, 0x1D, 0xDD, 0x93,
  33766. 0x19, 0x29, 0xE4, 0xD9, 0x13, 0x1D, 0x28, 0x32,
  33767. 0x03, 0x5A, 0xA6, 0x8E, 0x20, 0xC7, 0xD6, 0xC6,
  33768. 0x4D, 0x19, 0x17, 0xCC, 0x65, 0xB8, 0x84, 0x0C,
  33769. 0x38, 0xB4, 0xA9, 0x45, 0x2B, 0x91, 0x61, 0x79,
  33770. 0x87, 0x08, 0xA6, 0xBD, 0x28, 0x9A, 0x58, 0x48,
  33771. 0xD5, 0x58, 0xC6, 0xCE, 0xC2, 0xC5, 0x72, 0x16,
  33772. 0xD9, 0xF4, 0xED, 0x66, 0xAC, 0xFA, 0x93, 0xE8,
  33773. 0x26, 0x10, 0x3B, 0x3D, 0x8F, 0xEA, 0x51, 0xCC,
  33774. 0x82, 0xC0, 0xDB, 0xDF, 0xA7, 0x13, 0xFB, 0x1B,
  33775. 0x77, 0x7E, 0x6F, 0x9E, 0x3C, 0xC5, 0x86, 0x35,
  33776. 0x92, 0x5B, 0x6F, 0x76, 0xA1, 0x71, 0x0D, 0x8C,
  33777. 0xDC, 0x95, 0x9F, 0xAC, 0x2C, 0x8E, 0x21, 0x01,
  33778. 0x37, 0x06, 0x28, 0x64, 0x4C, 0x23, 0xE2, 0x75,
  33779. 0x0B, 0xA7, 0xA4, 0xF5, 0x90, 0x87, 0xD2, 0x43,
  33780. 0x71, 0x59, 0x7C, 0x8C, 0xCA, 0x77, 0x3B, 0xC5,
  33781. 0x36, 0x46, 0xF7, 0x2F, 0xD3, 0x47, 0x18, 0xD7,
  33782. 0xC9, 0x4E, 0x56, 0x2D, 0x49, 0x82, 0xAC, 0x7D,
  33783. 0xD7, 0x3D, 0xF1, 0xDD, 0x73, 0x8B, 0xE4, 0xA1,
  33784. 0x10, 0x85, 0xB6, 0x94, 0xBE, 0x6A, 0x5E, 0xEE,
  33785. 0xBD, 0x60, 0xEB, 0x95, 0x76, 0xA8, 0x52, 0xE1,
  33786. 0x47, 0x57, 0xA1, 0x9C, 0xEC, 0x44, 0xE5, 0x6F,
  33787. 0x68, 0x34, 0x7E, 0x19, 0xBE, 0xCE, 0x56, 0xC9,
  33788. 0xBE, 0xCE, 0xFC, 0xB8, 0x32, 0x6D, 0xCB, 0x84,
  33789. 0x59, 0xBF, 0x4D, 0xF6, 0xE1, 0x53, 0x41, 0x61,
  33790. 0x5C, 0xFB, 0xD2, 0x48, 0xA6, 0x7F, 0x05, 0xB2,
  33791. 0xFC, 0xE8, 0xB2, 0x8A, 0x55, 0x7D, 0x19, 0xC0,
  33792. 0x69, 0x3B, 0x91, 0x5D, 0x71, 0xE7, 0xBB, 0x72,
  33793. 0x7D, 0xB9, 0x64, 0x6E, 0x8B, 0x5B, 0x70, 0x51,
  33794. 0xB5, 0x69, 0x8C, 0xC0, 0xFC, 0x95, 0xB2, 0x43,
  33795. 0x08, 0xF8, 0x70, 0xE4, 0x6F, 0x87, 0xA7, 0xDF,
  33796. 0x23, 0x84, 0xEE, 0xCF, 0x73, 0x38, 0xDE, 0x99,
  33797. 0x4C, 0xF8, 0xF1, 0x2D, 0xA2, 0x68, 0x99, 0xE3,
  33798. 0x9B, 0xB8, 0xF6, 0xC1, 0x5C, 0x83, 0x07, 0xE9,
  33799. 0xB9, 0xE2, 0x51, 0x62, 0xC8, 0x53, 0xF1, 0xC2,
  33800. 0xF7, 0x57, 0x8A, 0xA0, 0x42, 0x3C, 0x18, 0x36,
  33801. 0xF3, 0x99, 0xFD, 0x34, 0xB2, 0xF0, 0x1D, 0xBA,
  33802. 0x43, 0xEA, 0x72, 0x1C, 0x0B, 0x37, 0x47, 0xBC,
  33803. 0xAF, 0xDA, 0x22, 0x1F, 0x1C, 0x08, 0x16, 0x13,
  33804. 0xBD, 0xAA, 0x07, 0xFD, 0x7E, 0xCA, 0x70, 0x57,
  33805. 0x74, 0xDF, 0x68, 0x6B, 0x9F, 0x2D, 0x56, 0xBD,
  33806. 0x21, 0x89, 0xFA, 0x09, 0x04, 0xCA, 0x09, 0xBD,
  33807. 0x4F, 0xE6, 0x15, 0xF5, 0x89, 0xAB, 0xAC, 0xB2,
  33808. 0xC9, 0xBF, 0xC8, 0xBB, 0x87, 0x83, 0xB4, 0xD3,
  33809. 0xDC, 0xB1, 0x25, 0x9B, 0xAE, 0xC5, 0x75, 0x0C,
  33810. 0x9E, 0x6A, 0x83, 0x41, 0x85, 0x9D, 0x4B, 0xBF,
  33811. 0x62, 0x0C, 0x7D, 0x77, 0xC9, 0x89, 0xA6, 0xE1,
  33812. 0x28, 0xBD, 0x13, 0x5D, 0x41, 0x26, 0x80, 0x75,
  33813. 0x23, 0x57, 0xE7, 0x4F, 0x4D, 0x02, 0x8E, 0x0F,
  33814. 0x43, 0x67, 0xF6, 0xA6, 0xE6, 0xB6, 0x84, 0x8D,
  33815. 0xF5, 0x7B, 0x6A, 0x95, 0x73, 0x27, 0x86, 0x02,
  33816. 0x72, 0xCB, 0xDF, 0x77, 0x1C, 0x6C, 0x5E, 0xD3,
  33817. 0xF0, 0x1C, 0x82, 0x7A, 0x0D, 0xBB, 0x70, 0xA3,
  33818. 0x98, 0x8B, 0x7B, 0x4A, 0xFE, 0x2D, 0xB1, 0x5C,
  33819. 0x61, 0x89, 0x34, 0x4C, 0x81, 0x4B, 0x52, 0x17,
  33820. 0x03, 0x81, 0x54, 0x4F, 0x9E, 0x9E, 0x07, 0x16,
  33821. 0xF3, 0xD9, 0x18, 0x01, 0x11, 0xFD, 0x67, 0x18,
  33822. 0xA2, 0x64, 0x35, 0x42, 0x81, 0x80, 0x4A, 0xBA,
  33823. 0xCB, 0xD5, 0xF5, 0x4A, 0x10, 0x7F, 0xE2, 0xCF,
  33824. 0xA5, 0x1E, 0xCB, 0x0C, 0xAB, 0x3E, 0x03, 0x98,
  33825. 0x73, 0x89, 0xA4, 0x10, 0x75, 0xD5, 0xAC, 0x3D,
  33826. 0xCF, 0x56, 0x75, 0xD8, 0x86, 0xC2, 0x21, 0x42,
  33827. 0x99, 0x8D, 0x1B, 0x49, 0x09, 0xFE, 0x86, 0x41,
  33828. 0xC9, 0xDC, 0x87, 0x8D, 0x5A, 0xF0, 0xF5, 0xBE,
  33829. 0xF5, 0x49, 0x64, 0x5A, 0x7A, 0xC3, 0x5D, 0xE4,
  33830. 0xD6, 0xB7, 0x30, 0x92, 0x2A, 0x15, 0x86, 0x02,
  33831. 0xBE, 0xBA, 0x6E, 0xF6, 0x3D, 0x2D, 0x70, 0x89,
  33832. 0xFB, 0xB5, 0x1E, 0xBA, 0xDA, 0x20, 0x12, 0x49,
  33833. 0x22, 0xA0, 0xD8, 0x33, 0x9E, 0x4C, 0xC0, 0x27,
  33834. 0x0F, 0x9C, 0x1F, 0xD2, 0xA9, 0xF4, 0xD2, 0xA9,
  33835. 0x6D, 0xC5, 0x32, 0x16, 0x35, 0x9F, 0x19, 0x88,
  33836. 0xC1, 0xAA, 0xA4, 0x66, 0x33, 0xE6, 0x2C, 0x6A,
  33837. 0x6E, 0xA2, 0x1B, 0x33, 0xCB, 0xC3, 0x7E, 0xC5,
  33838. 0x31, 0x4D, 0x5C, 0x17, 0x4C, 0x33, 0x7F, 0x09,
  33839. 0x01, 0x33, 0x82, 0x84, 0x37, 0x03, 0xEB, 0x0E,
  33840. 0xB1, 0x5F, 0x1B, 0x60, 0x8A, 0x2C, 0x9F, 0x39
  33841. };
  33842. static const byte sk_87[] = {
  33843. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  33844. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  33845. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  33846. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  33847. 0x9A, 0xFE, 0xF5, 0x92, 0x58, 0xBB, 0x3C, 0xEB,
  33848. 0x4C, 0x5E, 0x83, 0xF9, 0xFF, 0xBC, 0x3B, 0x49,
  33849. 0xAE, 0xE1, 0xFC, 0x4B, 0x94, 0x4B, 0x8C, 0x75,
  33850. 0xD4, 0x67, 0x75, 0x66, 0x7D, 0x6B, 0xA4, 0xF2,
  33851. 0xDA, 0xC2, 0xB7, 0xC4, 0xD8, 0x50, 0x25, 0xCB,
  33852. 0x5A, 0xDB, 0xA4, 0xAD, 0xBB, 0x44, 0x20, 0x24,
  33853. 0x90, 0xEA, 0xA5, 0x2C, 0xAE, 0x80, 0x22, 0xC9,
  33854. 0x59, 0x02, 0xB7, 0x10, 0xB0, 0x5E, 0x1E, 0x5F,
  33855. 0x52, 0x7D, 0x88, 0xDA, 0xE2, 0x04, 0xBF, 0x45,
  33856. 0xA7, 0xA8, 0x49, 0x97, 0x7D, 0xAD, 0x7C, 0x7C,
  33857. 0x9E, 0x9C, 0x4A, 0xCC, 0x36, 0x33, 0x0F, 0x30,
  33858. 0xFA, 0xDE, 0x52, 0xE9, 0xAE, 0x23, 0x29, 0x13,
  33859. 0x10, 0x17, 0x8A, 0xD0, 0x08, 0x8E, 0xE1, 0x10,
  33860. 0x30, 0xD0, 0x84, 0x65, 0x92, 0x12, 0x2A, 0x81,
  33861. 0x26, 0x2E, 0x11, 0x14, 0x30, 0x61, 0x38, 0x61,
  33862. 0x64, 0x42, 0x05, 0x08, 0x91, 0x90, 0x4C, 0x06,
  33863. 0x82, 0xCC, 0x90, 0x45, 0x10, 0x39, 0x90, 0x22,
  33864. 0x40, 0x2A, 0x9B, 0x16, 0x26, 0x9A, 0xA8, 0x50,
  33865. 0x91, 0x12, 0x70, 0x91, 0x20, 0x4D, 0xC0, 0x34,
  33866. 0x90, 0x18, 0x28, 0x31, 0x10, 0x02, 0x11, 0x22,
  33867. 0xB3, 0x6C, 0x8B, 0xB8, 0x2C, 0x22, 0xB0, 0x69,
  33868. 0x53, 0x36, 0x31, 0x61, 0x42, 0x6C, 0xD9, 0x06,
  33869. 0x6A, 0xD9, 0x04, 0x45, 0xDB, 0x18, 0x05, 0x12,
  33870. 0x37, 0x4A, 0xD4, 0x06, 0x64, 0xD3, 0xA2, 0x85,
  33871. 0xA0, 0x38, 0x8A, 0x14, 0xA5, 0x85, 0x50, 0x20,
  33872. 0x85, 0xE4, 0xA8, 0x24, 0xC3, 0xC6, 0x31, 0xC9,
  33873. 0x34, 0x4E, 0xD2, 0x14, 0x68, 0x82, 0x90, 0x85,
  33874. 0xC4, 0x02, 0x61, 0x24, 0x38, 0x05, 0x01, 0xA3,
  33875. 0x50, 0x48, 0x08, 0x62, 0x20, 0xB0, 0x25, 0x5B,
  33876. 0xA6, 0x4D, 0x98, 0x92, 0x11, 0xC2, 0x06, 0x00,
  33877. 0xD1, 0xB0, 0x4D, 0x21, 0xA4, 0x8C, 0x01, 0x16,
  33878. 0x72, 0x11, 0xA6, 0x20, 0xD0, 0x16, 0x45, 0x10,
  33879. 0x31, 0x8E, 0xCB, 0xC2, 0x69, 0x02, 0x08, 0x91,
  33880. 0xD4, 0x30, 0x89, 0x03, 0x41, 0x05, 0x93, 0x16,
  33881. 0x8E, 0x5A, 0x18, 0x04, 0x41, 0x10, 0x6D, 0x18,
  33882. 0x42, 0x70, 0x53, 0x16, 0x31, 0x52, 0x30, 0x8E,
  33883. 0x0C, 0x49, 0x66, 0x0C, 0x90, 0x0C, 0xA4, 0x08,
  33884. 0x2E, 0x41, 0x92, 0x05, 0x24, 0x07, 0x30, 0x12,
  33885. 0x46, 0x72, 0x13, 0x99, 0x20, 0xE0, 0xA2, 0x4C,
  33886. 0x1B, 0x14, 0x52, 0x5A, 0x90, 0x05, 0x08, 0x82,
  33887. 0x31, 0x53, 0xC2, 0x90, 0xCC, 0x42, 0x68, 0x18,
  33888. 0xB0, 0x2C, 0x00, 0x80, 0x65, 0x58, 0x12, 0x84,
  33889. 0x19, 0x90, 0x08, 0x44, 0x26, 0x4A, 0x10, 0xA9,
  33890. 0x0C, 0x12, 0x25, 0x0C, 0x9C, 0x10, 0x25, 0x0C,
  33891. 0x28, 0x25, 0xD8, 0x46, 0x84, 0x1A, 0x22, 0x71,
  33892. 0x5B, 0x28, 0x6E, 0x98, 0x02, 0x51, 0x61, 0xB4,
  33893. 0x51, 0x01, 0xA1, 0x21, 0x24, 0x39, 0x12, 0xC8,
  33894. 0x08, 0x85, 0xD1, 0x34, 0x64, 0xA4, 0xA8, 0x04,
  33895. 0xA2, 0xC0, 0x09, 0x44, 0x48, 0x48, 0x03, 0x37,
  33896. 0x00, 0x20, 0x05, 0x4D, 0x20, 0xA4, 0x05, 0x11,
  33897. 0x18, 0x82, 0x42, 0x94, 0x4D, 0x24, 0x16, 0x01,
  33898. 0x02, 0x93, 0x4C, 0x00, 0x16, 0x06, 0xC1, 0xC0,
  33899. 0x0C, 0x8B, 0xC0, 0x41, 0x41, 0x06, 0x42, 0xA3,
  33900. 0xC6, 0x64, 0x1A, 0x85, 0x91, 0x41, 0x06, 0x49,
  33901. 0x04, 0xA7, 0x44, 0x82, 0x22, 0x6A, 0x50, 0x08,
  33902. 0x0E, 0x14, 0x18, 0x20, 0x4B, 0x88, 0x91, 0x01,
  33903. 0xA0, 0x49, 0x1A, 0x85, 0x4D, 0x94, 0x18, 0x10,
  33904. 0x0A, 0x05, 0x44, 0x94, 0x38, 0x05, 0x93, 0x40,
  33905. 0x68, 0x23, 0x07, 0x85, 0xE2, 0x12, 0x22, 0x9B,
  33906. 0xB8, 0x08, 0xD2, 0x10, 0x2A, 0x08, 0xA8, 0x10,
  33907. 0x92, 0x40, 0x2D, 0xD8, 0x44, 0x4C, 0xCC, 0x94,
  33908. 0x05, 0x24, 0x43, 0x4C, 0xD3, 0xC2, 0x48, 0x10,
  33909. 0x21, 0x2D, 0xC9, 0xB6, 0x08, 0xC9, 0x06, 0x4D,
  33910. 0xE1, 0x90, 0x20, 0x14, 0x24, 0x70, 0x5C, 0x84,
  33911. 0x28, 0xC0, 0xC2, 0x81, 0x22, 0x13, 0x50, 0x44,
  33912. 0x84, 0x91, 0xCA, 0xA2, 0x48, 0x12, 0x91, 0x05,
  33913. 0x5B, 0x92, 0x8D, 0x92, 0x92, 0x24, 0x82, 0x42,
  33914. 0x48, 0x03, 0x37, 0x46, 0xD8, 0x44, 0x86, 0x44,
  33915. 0x20, 0x89, 0xE4, 0xC2, 0x84, 0xC2, 0x04, 0x65,
  33916. 0x49, 0xA8, 0x4D, 0xA4, 0x38, 0x28, 0xDB, 0xA4,
  33917. 0x64, 0x24, 0x00, 0x51, 0xC8, 0x12, 0x6D, 0x19,
  33918. 0x82, 0x24, 0xCB, 0x00, 0x44, 0x4B, 0x20, 0x20,
  33919. 0x9B, 0x82, 0x4C, 0x5C, 0xA8, 0x08, 0xD2, 0xB6,
  33920. 0x8C, 0x08, 0x35, 0x20, 0xC0, 0x92, 0x45, 0xE3,
  33921. 0xB4, 0x2C, 0x50, 0x32, 0x0E, 0xD1, 0x82, 0x11,
  33922. 0x4A, 0x96, 0x08, 0x1C, 0x86, 0x29, 0x02, 0x19,
  33923. 0x71, 0x12, 0x03, 0x6E, 0x94, 0x08, 0x50, 0x12,
  33924. 0x27, 0x20, 0x0B, 0x10, 0x12, 0xA1, 0x18, 0x06,
  33925. 0x5A, 0x36, 0x4C, 0x93, 0xB4, 0x68, 0x21, 0xA7,
  33926. 0x28, 0x09, 0x34, 0x91, 0x18, 0x93, 0x49, 0x4A,
  33927. 0x32, 0x60, 0x00, 0x29, 0x2D, 0x94, 0x48, 0x44,
  33928. 0x09, 0x94, 0x2C, 0x21, 0x07, 0x6C, 0x41, 0x38,
  33929. 0x60, 0x8C, 0x10, 0x46, 0x11, 0x19, 0x65, 0x01,
  33930. 0x46, 0x60, 0x1A, 0x29, 0x42, 0x23, 0x30, 0x29,
  33931. 0x40, 0x96, 0x85, 0x81, 0xC6, 0x6C, 0x09, 0xA2,
  33932. 0x31, 0x23, 0xC9, 0x84, 0x18, 0x27, 0x61, 0x02,
  33933. 0xA6, 0x05, 0x1B, 0x11, 0x32, 0xD1, 0x80, 0x24,
  33934. 0x59, 0x22, 0x52, 0x21, 0x34, 0x64, 0x0A, 0x21,
  33935. 0x52, 0x10, 0xC2, 0x80, 0x5C, 0x98, 0x0D, 0x81,
  33936. 0xA0, 0x84, 0x14, 0x97, 0x04, 0xCC, 0xC2, 0x04,
  33937. 0x1A, 0x81, 0x45, 0x23, 0x44, 0x6C, 0x13, 0xC0,
  33938. 0x44, 0x59, 0xC2, 0x68, 0x64, 0x08, 0x52, 0x51,
  33939. 0x30, 0x71, 0x12, 0x49, 0x70, 0x12, 0x94, 0x84,
  33940. 0x80, 0x12, 0x12, 0x1B, 0x00, 0x50, 0x84, 0x10,
  33941. 0x45, 0x4A, 0x30, 0x10, 0x22, 0x95, 0x49, 0xC9,
  33942. 0x82, 0x24, 0x03, 0x35, 0x21, 0x18, 0x16, 0x72,
  33943. 0x09, 0x89, 0x65, 0x88, 0xB2, 0x89, 0x41, 0xB4,
  33944. 0x90, 0x92, 0x38, 0x8C, 0x08, 0x23, 0x26, 0x0B,
  33945. 0x80, 0x61, 0x84, 0x28, 0x6A, 0x4C, 0x98, 0x44,
  33946. 0x10, 0xB9, 0x30, 0x93, 0x02, 0x49, 0x22, 0x13,
  33947. 0x80, 0x1C, 0xC3, 0x48, 0x50, 0xA8, 0x20, 0x1C,
  33948. 0x05, 0x00, 0x5B, 0x02, 0x41, 0xD2, 0x84, 0x61,
  33949. 0x4B, 0x40, 0x46, 0x20, 0x21, 0x44, 0xD9, 0xC4,
  33950. 0x21, 0xD3, 0xA4, 0x4D, 0xC0, 0xC0, 0x09, 0x5B,
  33951. 0x28, 0x91, 0x18, 0x15, 0x41, 0x18, 0xC5, 0x4C,
  33952. 0x14, 0xB7, 0x61, 0xDB, 0x34, 0x25, 0x02, 0x06,
  33953. 0x41, 0x14, 0xA9, 0x65, 0x0B, 0x10, 0x04, 0x23,
  33954. 0xC7, 0x49, 0x13, 0x47, 0x0A, 0xD0, 0x30, 0x80,
  33955. 0x99, 0x32, 0x68, 0x50, 0x18, 0x06, 0xA2, 0x28,
  33956. 0x65, 0x13, 0x35, 0x82, 0xD3, 0x06, 0x81, 0x22,
  33957. 0x49, 0x4D, 0x48, 0x44, 0x30, 0xCA, 0x96, 0x2C,
  33958. 0x12, 0xC8, 0x08, 0xA1, 0x24, 0x2C, 0x52, 0xA8,
  33959. 0x28, 0x23, 0x14, 0x0A, 0xD4, 0x20, 0x4D, 0x18,
  33960. 0x12, 0x72, 0xD4, 0x80, 0x44, 0xDC, 0x26, 0x2C,
  33961. 0x88, 0x10, 0x0A, 0x04, 0x14, 0x51, 0xC1, 0x96,
  33962. 0x00, 0xA3, 0x40, 0x30, 0x99, 0x48, 0x92, 0x9B,
  33963. 0x08, 0x86, 0x81, 0x04, 0x20, 0x4C, 0xB2, 0x29,
  33964. 0x18, 0x31, 0x08, 0x09, 0x23, 0x8C, 0x4C, 0x02,
  33965. 0x6A, 0xCA, 0x00, 0x62, 0x09, 0x22, 0x2D, 0x21,
  33966. 0x00, 0x02, 0x0A, 0x39, 0x41, 0x04, 0xA3, 0x50,
  33967. 0x90, 0x80, 0x2D, 0x59, 0xB4, 0x71, 0x13, 0x16,
  33968. 0x31, 0x11, 0x90, 0x4C, 0xC3, 0x14, 0x20, 0x60,
  33969. 0xB2, 0x30, 0x0A, 0xB6, 0x24, 0x21, 0xA9, 0x10,
  33970. 0x89, 0x80, 0x88, 0x44, 0x06, 0x8A, 0x91, 0x22,
  33971. 0x8E, 0xD9, 0x36, 0x86, 0x10, 0x46, 0x0A, 0xE1,
  33972. 0x16, 0x85, 0x42, 0x40, 0x6C, 0x09, 0x49, 0x11,
  33973. 0xE0, 0x88, 0x68, 0x12, 0x08, 0x68, 0x5C, 0x26,
  33974. 0x24, 0x04, 0xA8, 0x70, 0xC8, 0x08, 0x05, 0x13,
  33975. 0x87, 0x41, 0x23, 0x29, 0x72, 0xC9, 0xB8, 0x88,
  33976. 0x1B, 0x22, 0x66, 0x11, 0xA5, 0x2D, 0x11, 0x29,
  33977. 0x12, 0x50, 0x12, 0x70, 0x03, 0x09, 0x6A, 0x4B,
  33978. 0x88, 0x4C, 0xD2, 0xC8, 0x31, 0x40, 0x26, 0x40,
  33979. 0x4C, 0x04, 0x50, 0x58, 0x16, 0x71, 0x90, 0xC2,
  33980. 0x00, 0x0A, 0x30, 0x8A, 0xDC, 0x24, 0x85, 0x19,
  33981. 0xB0, 0x65, 0x1A, 0xA3, 0x64, 0x13, 0xA3, 0x45,
  33982. 0xC8, 0x48, 0x91, 0x91, 0x12, 0x20, 0xDC, 0x42,
  33983. 0x40, 0x24, 0xC0, 0x4D, 0xA3, 0x98, 0x10, 0x40,
  33984. 0x26, 0x25, 0xDC, 0xB4, 0x68, 0x4B, 0xC2, 0x45,
  33985. 0x13, 0x06, 0x91, 0xC8, 0x92, 0x24, 0x82, 0xA8,
  33986. 0x20, 0x4C, 0x30, 0x48, 0x52, 0x06, 0x01, 0x0B,
  33987. 0x24, 0x51, 0x41, 0x36, 0x40, 0x93, 0xC4, 0x70,
  33988. 0x44, 0x40, 0x2C, 0x24, 0x28, 0x22, 0x81, 0xA4,
  33989. 0x4C, 0x43, 0x84, 0x60, 0x20, 0x23, 0x90, 0x01,
  33990. 0x94, 0x6C, 0xDB, 0x28, 0x21, 0x93, 0x30, 0x80,
  33991. 0x93, 0xC0, 0x25, 0xC8, 0xA6, 0x50, 0xCA, 0x24,
  33992. 0x26, 0xD1, 0x40, 0x31, 0x04, 0xC4, 0x8D, 0xE2,
  33993. 0xC0, 0x04, 0x08, 0x33, 0x8C, 0x18, 0x87, 0x91,
  33994. 0xC8, 0xC8, 0x71, 0x40, 0x46, 0x06, 0x00, 0x44,
  33995. 0x20, 0x22, 0x49, 0x70, 0x11, 0x45, 0x90, 0x02,
  33996. 0xC3, 0x61, 0x60, 0xB4, 0x25, 0x80, 0x16, 0x21,
  33997. 0x11, 0x09, 0x04, 0x88, 0x04, 0x05, 0xCC, 0x36,
  33998. 0x20, 0x01, 0xB1, 0x2C, 0x64, 0xB6, 0x50, 0x54,
  33999. 0x32, 0x42, 0x0B, 0x08, 0x8D, 0x12, 0x39, 0x0D,
  34000. 0x10, 0x29, 0x52, 0x88, 0xB0, 0x04, 0x11, 0x38,
  34001. 0x44, 0xD2, 0xA6, 0x71, 0x0B, 0x45, 0x48, 0x9C,
  34002. 0x34, 0x72, 0xA0, 0x28, 0x49, 0x82, 0x16, 0x86,
  34003. 0x12, 0x18, 0x61, 0x04, 0x41, 0x0D, 0x8A, 0xA6,
  34004. 0x41, 0x80, 0xA8, 0x61, 0xDA, 0x30, 0x65, 0x82,
  34005. 0x84, 0x30, 0x08, 0xA3, 0x29, 0x04, 0x33, 0x8E,
  34006. 0x02, 0x24, 0x0D, 0x9C, 0x44, 0x10, 0xC9, 0x02,
  34007. 0x81, 0x53, 0x06, 0x66, 0x8B, 0x06, 0x90, 0x03,
  34008. 0x87, 0x69, 0x21, 0xC9, 0x69, 0x83, 0x46, 0x4E,
  34009. 0x14, 0x24, 0x89, 0x8C, 0xA0, 0x6C, 0x99, 0xA2,
  34010. 0x2C, 0x11, 0x37, 0x66, 0x0C, 0xA6, 0x4D, 0xD3,
  34011. 0xC8, 0x70, 0x03, 0x02, 0x61, 0xC3, 0xB6, 0x65,
  34012. 0x23, 0xC1, 0x6C, 0x10, 0x34, 0x8D, 0x1A, 0xC1,
  34013. 0x31, 0x43, 0x40, 0x44, 0xD4, 0x08, 0x02, 0x0A,
  34014. 0x36, 0x20, 0xE3, 0x26, 0x42, 0x0A, 0x48, 0x26,
  34015. 0x1A, 0x13, 0x44, 0x0C, 0x18, 0x61, 0x91, 0x96,
  34016. 0x84, 0x02, 0x17, 0x46, 0x9C, 0x20, 0x40, 0x41,
  34017. 0xC6, 0x2D, 0x1B, 0x16, 0x0C, 0x98, 0xB2, 0x90,
  34018. 0x1A, 0x20, 0x84, 0xE2, 0x34, 0x2D, 0xCB, 0x14,
  34019. 0x44, 0x93, 0xC6, 0x8D, 0x58, 0xB2, 0x69, 0x22,
  34020. 0xB2, 0x88, 0xC0, 0xB8, 0x2D, 0xA2, 0xC2, 0x31,
  34021. 0x20, 0xA3, 0x24, 0x11, 0x46, 0x48, 0x4A, 0xA6,
  34022. 0x50, 0x24, 0x09, 0x21, 0x1A, 0x01, 0x0D, 0x20,
  34023. 0x36, 0x01, 0xC4, 0x34, 0x70, 0xDA, 0x16, 0x68,
  34024. 0x84, 0x22, 0x4C, 0x11, 0x14, 0x09, 0x13, 0xC4,
  34025. 0x68, 0x11, 0x41, 0x2D, 0x1C, 0x10, 0x31, 0xDC,
  34026. 0xB2, 0x64, 0x42, 0x36, 0x08, 0x5C, 0x10, 0x88,
  34027. 0x04, 0x91, 0x25, 0xE1, 0xA0, 0x20, 0x14, 0x18,
  34028. 0x12, 0x14, 0x94, 0x91, 0x4C, 0xC2, 0x24, 0xD4,
  34029. 0x06, 0x71, 0x21, 0x02, 0x8D, 0xD4, 0x88, 0x30,
  34030. 0xC9, 0x36, 0x0E, 0xE4, 0x82, 0x81, 0xC0, 0x04,
  34031. 0x6D, 0x24, 0x23, 0x09, 0x21, 0x45, 0x45, 0x20,
  34032. 0x06, 0x65, 0xC2, 0x30, 0x2A, 0x18, 0x30, 0x8E,
  34033. 0x24, 0x83, 0x89, 0x93, 0x32, 0x66, 0xC1, 0x48,
  34034. 0x45, 0x62, 0x48, 0x0A, 0x52, 0xB8, 0x80, 0x11,
  34035. 0x86, 0x21, 0x04, 0x34, 0x11, 0x24, 0xB5, 0x6C,
  34036. 0x50, 0x36, 0x0A, 0x19, 0xA7, 0x8C, 0x14, 0x90,
  34037. 0x0D, 0x1A, 0xA5, 0x68, 0x0B, 0xB1, 0x11, 0x50,
  34038. 0x40, 0x08, 0x48, 0xB6, 0x31, 0x14, 0x28, 0x8D,
  34039. 0xE3, 0x47, 0xB4, 0xA1, 0x44, 0x94, 0xCC, 0x9F,
  34040. 0x0B, 0x94, 0x9F, 0x25, 0x49, 0xD9, 0xB3, 0x8F,
  34041. 0x71, 0xF4, 0x17, 0xA4, 0xA6, 0xAC, 0x24, 0x58,
  34042. 0x14, 0x25, 0x03, 0xC8, 0x63, 0x3E, 0x10, 0xA8,
  34043. 0xD4, 0x10, 0xD7, 0x90, 0x4A, 0x28, 0x37, 0x90,
  34044. 0x70, 0x27, 0xE3, 0x56, 0x5F, 0x04, 0x67, 0x76,
  34045. 0xC3, 0x67, 0x3F, 0xF5, 0xA5, 0x11, 0xA2, 0x2C,
  34046. 0x11, 0x01, 0x5D, 0x63, 0x71, 0x1A, 0xE6, 0x70,
  34047. 0x86, 0x46, 0xAB, 0xCE, 0x03, 0xB6, 0x82, 0xAF,
  34048. 0x51, 0xBA, 0x81, 0x94, 0x9C, 0x82, 0x36, 0xA9,
  34049. 0x49, 0xA5, 0xA3, 0x11, 0x08, 0x8C, 0x4B, 0x13,
  34050. 0x41, 0xF0, 0x08, 0xFD, 0xB2, 0x99, 0xED, 0xA8,
  34051. 0x07, 0x61, 0x3C, 0x2E, 0xBC, 0x49, 0x7B, 0x1C,
  34052. 0xBC, 0x87, 0xBC, 0xAE, 0x5F, 0x5E, 0x8F, 0x5D,
  34053. 0xE7, 0xB9, 0x0C, 0x70, 0x36, 0x25, 0x61, 0xFD,
  34054. 0x95, 0x9F, 0xAE, 0x0F, 0x8D, 0xF3, 0xA2, 0x45,
  34055. 0x24, 0xA7, 0xDE, 0x60, 0xD1, 0x4E, 0x6D, 0xAC,
  34056. 0xC7, 0x6A, 0x32, 0x42, 0xC0, 0x73, 0xEB, 0x78,
  34057. 0x50, 0xF4, 0x49, 0x52, 0x5E, 0x6F, 0x81, 0x42,
  34058. 0x54, 0xF8, 0x82, 0x05, 0xC9, 0x64, 0x74, 0x6A,
  34059. 0x60, 0x5E, 0x36, 0x59, 0x40, 0x50, 0xA3, 0xFE,
  34060. 0xDA, 0xE2, 0x6D, 0x8D, 0x6E, 0xE4, 0x5A, 0x27,
  34061. 0x73, 0x89, 0xDB, 0x0C, 0x5B, 0x14, 0xD9, 0xED,
  34062. 0xB2, 0xC7, 0x1D, 0x71, 0x93, 0x91, 0x0A, 0x72,
  34063. 0x32, 0xBE, 0xA3, 0xD8, 0x95, 0x8C, 0x94, 0x7E,
  34064. 0x63, 0xEB, 0xCE, 0x8B, 0xFC, 0xB0, 0x3F, 0x77,
  34065. 0x5C, 0x43, 0x48, 0x18, 0x83, 0xFE, 0xC8, 0xDA,
  34066. 0x89, 0xF2, 0x3B, 0x54, 0x82, 0x44, 0xC6, 0x9C,
  34067. 0xCC, 0x77, 0x0A, 0xC1, 0x6F, 0xB9, 0x98, 0x10,
  34068. 0xD5, 0xF2, 0x60, 0xFF, 0x38, 0xD2, 0x0D, 0xD6,
  34069. 0x8C, 0x38, 0x54, 0x5B, 0xD8, 0x38, 0x84, 0x50,
  34070. 0x36, 0xF4, 0x02, 0xC1, 0x06, 0x0F, 0x15, 0x1B,
  34071. 0xC8, 0x90, 0x9B, 0x6E, 0x36, 0xC8, 0x3F, 0xE9,
  34072. 0x8B, 0x62, 0x15, 0x6F, 0xF0, 0xC2, 0x86, 0x7F,
  34073. 0xD1, 0xB5, 0x97, 0x53, 0xAE, 0x41, 0xAE, 0x21,
  34074. 0x84, 0xAC, 0x57, 0xA5, 0x1F, 0xA7, 0xC7, 0x24,
  34075. 0xDF, 0xDE, 0x2F, 0x3C, 0xCD, 0xA2, 0x7E, 0x1D,
  34076. 0x97, 0xE1, 0x96, 0xC5, 0xB4, 0x7D, 0xF9, 0x5F,
  34077. 0x7E, 0xEF, 0x09, 0xC4, 0xF3, 0x57, 0xF0, 0x51,
  34078. 0x73, 0xAB, 0x0E, 0x6A, 0xCA, 0x64, 0xE4, 0x99,
  34079. 0x0F, 0xD2, 0x20, 0xAC, 0x72, 0xF1, 0xA8, 0x23,
  34080. 0x8F, 0x94, 0x63, 0xDC, 0xB3, 0xBB, 0x62, 0x2C,
  34081. 0xEA, 0xA6, 0x27, 0x5A, 0x93, 0xC6, 0xCD, 0xCE,
  34082. 0x1E, 0x09, 0xAF, 0x89, 0xEC, 0x22, 0xE4, 0x30,
  34083. 0x2D, 0xB9, 0xCD, 0x08, 0x2E, 0x12, 0x76, 0x79,
  34084. 0x99, 0xBC, 0xA0, 0x34, 0x0B, 0xDA, 0x89, 0x08,
  34085. 0x14, 0x60, 0x7B, 0x98, 0xE6, 0xAF, 0xD2, 0xE1,
  34086. 0x87, 0xC8, 0xDA, 0x50, 0xF7, 0x10, 0x2C, 0x72,
  34087. 0x74, 0x50, 0xD0, 0x3C, 0x98, 0x06, 0xFE, 0xEB,
  34088. 0xC6, 0xC5, 0x69, 0x31, 0x06, 0xE2, 0x2E, 0x7E,
  34089. 0x7D, 0x3D, 0x2B, 0x1F, 0x48, 0x43, 0xC5, 0x95,
  34090. 0xDA, 0x84, 0x08, 0x1E, 0x2B, 0x50, 0x6D, 0x91,
  34091. 0xA6, 0x2B, 0xCD, 0x08, 0x43, 0x7B, 0xA2, 0xD8,
  34092. 0x60, 0x6E, 0xF7, 0x80, 0x08, 0xC3, 0x3F, 0x35,
  34093. 0xF3, 0x70, 0xA5, 0xC7, 0x56, 0xFC, 0xBD, 0x34,
  34094. 0x46, 0x7B, 0xBF, 0x63, 0x19, 0xAC, 0xB6, 0xC3,
  34095. 0x1B, 0x81, 0x84, 0x9F, 0xBB, 0x54, 0x05, 0x99,
  34096. 0xAE, 0x43, 0xE2, 0xA5, 0x20, 0xFD, 0x5C, 0xC7,
  34097. 0x25, 0x47, 0xB1, 0xFD, 0x80, 0xB5, 0x78, 0xC2,
  34098. 0x00, 0x98, 0x02, 0xB9, 0x61, 0x2A, 0xBA, 0x39,
  34099. 0xC7, 0x20, 0xB8, 0x7D, 0x7A, 0x03, 0x68, 0xE5,
  34100. 0x37, 0x71, 0x1F, 0x72, 0xAA, 0x41, 0x61, 0xB4,
  34101. 0xC0, 0xC2, 0xD3, 0x7A, 0xCD, 0xD2, 0xED, 0xC2,
  34102. 0xC5, 0x99, 0x8C, 0x62, 0xA3, 0x7D, 0xC8, 0x9C,
  34103. 0xD2, 0x50, 0x02, 0x0D, 0xCB, 0x68, 0x15, 0xB0,
  34104. 0xD6, 0x19, 0x03, 0xC8, 0x01, 0x12, 0x72, 0xA1,
  34105. 0x3A, 0xC2, 0xA6, 0x63, 0x51, 0x26, 0x03, 0x5D,
  34106. 0x3F, 0x1D, 0x3B, 0x0E, 0x30, 0x6B, 0xB7, 0xEC,
  34107. 0xB6, 0x8E, 0x2D, 0x76, 0xC8, 0xD7, 0xAE, 0x59,
  34108. 0x81, 0xFC, 0x5F, 0x57, 0x5E, 0xAD, 0xA0, 0x20,
  34109. 0xC8, 0xB4, 0x91, 0x2D, 0xEC, 0x03, 0xC4, 0xC6,
  34110. 0x55, 0x05, 0x87, 0xA4, 0xA2, 0x21, 0x09, 0x25,
  34111. 0x97, 0x21, 0xA4, 0x46, 0x45, 0x46, 0x40, 0x3B,
  34112. 0xDC, 0x6F, 0xCD, 0xFB, 0xFB, 0xD9, 0xF4, 0x2C,
  34113. 0xEC, 0xF1, 0xC4, 0x73, 0x41, 0x30, 0x60, 0x63,
  34114. 0x9A, 0xF2, 0xA5, 0x26, 0x78, 0x9A, 0x5E, 0x70,
  34115. 0x98, 0xDE, 0x35, 0x10, 0xA0, 0x5D, 0x45, 0xD5,
  34116. 0x95, 0xF7, 0x11, 0xBC, 0x99, 0xD3, 0x00, 0x67,
  34117. 0x9A, 0x30, 0x85, 0x36, 0x50, 0xDB, 0x18, 0xEA,
  34118. 0x6D, 0xB2, 0xF3, 0x14, 0xDA, 0x23, 0xE2, 0x8A,
  34119. 0x44, 0x21, 0x25, 0xD4, 0xA3, 0x28, 0x43, 0xA0,
  34120. 0xC6, 0x5C, 0x99, 0xB0, 0x72, 0x6B, 0xC2, 0x1A,
  34121. 0x30, 0xBE, 0x6B, 0x7B, 0xE0, 0x31, 0x54, 0x8C,
  34122. 0x29, 0xE5, 0xC6, 0x69, 0x53, 0xDE, 0x05, 0x1E,
  34123. 0x43, 0xCC, 0x7E, 0x9A, 0x82, 0x4A, 0xC4, 0x0A,
  34124. 0x50, 0x65, 0xDC, 0xD8, 0xF9, 0x01, 0x32, 0x65,
  34125. 0x1E, 0xF9, 0xA4, 0xCC, 0x07, 0xB9, 0x55, 0x97,
  34126. 0x45, 0xA9, 0x61, 0xF8, 0xBE, 0x99, 0x00, 0x12,
  34127. 0xD8, 0x17, 0x62, 0xFB, 0x89, 0xE7, 0x05, 0x5E,
  34128. 0x1B, 0xCD, 0x2B, 0x09, 0x6C, 0x5A, 0x5C, 0xA3,
  34129. 0x66, 0x4D, 0x02, 0x78, 0x0C, 0xC3, 0x63, 0x30,
  34130. 0xD0, 0xFA, 0x7B, 0x11, 0x00, 0x40, 0xDD, 0xF0,
  34131. 0x8C, 0x7C, 0xBA, 0x4C, 0x63, 0x78, 0xDA, 0xBB,
  34132. 0xDF, 0xF9, 0xC9, 0xA4, 0x40, 0x25, 0x86, 0xD1,
  34133. 0xBA, 0x22, 0xD7, 0x69, 0x98, 0x4E, 0x9D, 0x15,
  34134. 0x21, 0xA8, 0x56, 0xC0, 0xFF, 0x52, 0xE4, 0xB4,
  34135. 0x0F, 0xB2, 0x53, 0xE7, 0xA1, 0x34, 0x18, 0xEA,
  34136. 0x5B, 0x25, 0x42, 0x13, 0xE3, 0x13, 0xE7, 0xDF,
  34137. 0x54, 0x2B, 0x8D, 0x70, 0x51, 0xC7, 0x60, 0xB1,
  34138. 0x1E, 0x4D, 0x3A, 0x46, 0x04, 0xA1, 0x11, 0x43,
  34139. 0xAD, 0x24, 0x29, 0x90, 0xC9, 0x04, 0x15, 0xC5,
  34140. 0x07, 0xE5, 0x46, 0xB8, 0x50, 0x16, 0x6B, 0x66,
  34141. 0xFE, 0x1C, 0x8B, 0xFC, 0x20, 0x9C, 0xC4, 0x88,
  34142. 0x10, 0x36, 0x5E, 0x56, 0xE8, 0x45, 0x75, 0x89,
  34143. 0xFB, 0xD6, 0xD0, 0x8D, 0x9D, 0x53, 0xAE, 0x89,
  34144. 0x19, 0x54, 0xCF, 0xE1, 0xFF, 0x12, 0x13, 0xF2,
  34145. 0xC7, 0xBE, 0x4C, 0x1E, 0xB0, 0x70, 0x6E, 0xDC,
  34146. 0x0A, 0x64, 0x3B, 0x60, 0x3A, 0xEA, 0x0D, 0x41,
  34147. 0xDD, 0x8E, 0x09, 0xB9, 0x96, 0x8F, 0x6A, 0x49,
  34148. 0x50, 0xEF, 0xDF, 0xD7, 0x73, 0x8D, 0x16, 0x32,
  34149. 0xA8, 0x5C, 0x0A, 0x90, 0x18, 0xA1, 0xEB, 0x19,
  34150. 0xCC, 0x50, 0xD5, 0x59, 0xD7, 0x35, 0x3F, 0xBA,
  34151. 0x38, 0x1B, 0x5F, 0x71, 0x56, 0x70, 0xB3, 0x20,
  34152. 0x4D, 0x9E, 0x16, 0xA8, 0xF7, 0x35, 0x19, 0xD2,
  34153. 0x09, 0x0A, 0x22, 0x28, 0x81, 0x61, 0x26, 0x5B,
  34154. 0x9C, 0xEC, 0x9D, 0x4A, 0x61, 0xCF, 0x0D, 0x3C,
  34155. 0x88, 0xEA, 0x0B, 0x7A, 0xA7, 0xC6, 0xAE, 0x31,
  34156. 0xBE, 0xC2, 0xBA, 0x48, 0xBB, 0x9D, 0x06, 0xE1,
  34157. 0x32, 0x6D, 0x80, 0xCE, 0x27, 0x5C, 0x6F, 0x13,
  34158. 0x79, 0x35, 0x9F, 0x9C, 0x11, 0xEA, 0xDB, 0xF5,
  34159. 0x49, 0x15, 0xB6, 0x51, 0x86, 0xFC, 0x62, 0x34,
  34160. 0x3D, 0x58, 0x6B, 0x0E, 0xF8, 0x3B, 0xBB, 0x42,
  34161. 0xF6, 0x2D, 0x5C, 0xE2, 0xF3, 0xAA, 0x9F, 0x03,
  34162. 0x43, 0xE9, 0x9E, 0x90, 0xB9, 0xFF, 0x55, 0x93,
  34163. 0x60, 0xF8, 0x10, 0x2F, 0xFC, 0xBD, 0x40, 0x23,
  34164. 0xB8, 0x4F, 0x4C, 0x7A, 0x74, 0x9F, 0xDC, 0x55,
  34165. 0xDF, 0x5E, 0xCD, 0x23, 0xEB, 0xAC, 0x47, 0x4E,
  34166. 0x0D, 0x0F, 0xBE, 0xDE, 0x02, 0x64, 0x61, 0x7E,
  34167. 0x73, 0x78, 0x8E, 0x25, 0xE9, 0x7D, 0x66, 0xE5,
  34168. 0x82, 0xBF, 0x98, 0x5B, 0x36, 0xCE, 0x17, 0x72,
  34169. 0x56, 0x9C, 0xDA, 0x63, 0x77, 0x55, 0x8B, 0xA9,
  34170. 0x75, 0xF5, 0x28, 0xC3, 0x78, 0x6D, 0x8F, 0xC2,
  34171. 0x75, 0x5F, 0x28, 0x9E, 0x3F, 0xFB, 0xF1, 0xFD,
  34172. 0xB7, 0xDE, 0x05, 0x3C, 0xD3, 0xE8, 0xD7, 0x7A,
  34173. 0x7D, 0xC9, 0xF7, 0x9D, 0x58, 0xB4, 0xA6, 0x21,
  34174. 0x25, 0xFC, 0x52, 0x84, 0x21, 0xF6, 0x0B, 0x6D,
  34175. 0xA6, 0x62, 0x51, 0x97, 0xCD, 0xA9, 0xA1, 0x0C,
  34176. 0x88, 0x21, 0x67, 0xA5, 0xFB, 0x8C, 0x8A, 0x50,
  34177. 0xC5, 0x21, 0x91, 0x3A, 0xAB, 0x95, 0x96, 0xF3,
  34178. 0x30, 0x6D, 0x08, 0x42, 0x07, 0x4B, 0x78, 0x1F,
  34179. 0xC1, 0xD3, 0x41, 0x15, 0x68, 0xED, 0x93, 0x09,
  34180. 0xC7, 0x8B, 0xF9, 0x77, 0x25, 0xD3, 0xCE, 0x2B,
  34181. 0xA2, 0x0D, 0xB4, 0xC6, 0x84, 0x7F, 0x8E, 0xE5,
  34182. 0x24, 0x46, 0x59, 0x8D, 0x6F, 0x0F, 0x0C, 0xA8,
  34183. 0xFC, 0x04, 0x9B, 0x4D, 0x2B, 0xA7, 0x70, 0x1F,
  34184. 0x46, 0x7E, 0x76, 0x03, 0xC6, 0x7E, 0xA5, 0x3D,
  34185. 0x79, 0xE2, 0xF1, 0xAC, 0xBC, 0xDD, 0xF6, 0x91,
  34186. 0x69, 0x4C, 0x44, 0x1F, 0xC3, 0xBF, 0x9F, 0xFC,
  34187. 0x4E, 0xB0, 0x79, 0x30, 0x68, 0x89, 0xAC, 0xF2,
  34188. 0xD7, 0xC6, 0xE1, 0x6C, 0x37, 0xFB, 0xB3, 0x38,
  34189. 0x44, 0x2C, 0x97, 0xAB, 0xDA, 0x2C, 0x88, 0xC7,
  34190. 0xF2, 0x80, 0x08, 0x00, 0x4E, 0x44, 0xED, 0xBE,
  34191. 0xA4, 0x28, 0x3D, 0xC1, 0xCF, 0x9E, 0x83, 0xE7,
  34192. 0x2E, 0x7F, 0xF5, 0x08, 0x47, 0x26, 0xE0, 0xBD,
  34193. 0x1A, 0x17, 0xDB, 0x2F, 0xED, 0x19, 0x2E, 0x65,
  34194. 0x1B, 0x62, 0x5F, 0x08, 0x82, 0x10, 0x61, 0xCB,
  34195. 0xAA, 0xA7, 0xF8, 0x59, 0x4B, 0x46, 0xCB, 0xA2,
  34196. 0xCB, 0x41, 0x34, 0x30, 0x51, 0x58, 0x2A, 0xEE,
  34197. 0xE1, 0x5E, 0xAC, 0xCA, 0xBF, 0x37, 0x45, 0x98,
  34198. 0xBD, 0x93, 0x1B, 0x5A, 0x5E, 0x92, 0x14, 0x05,
  34199. 0x75, 0x2D, 0xFB, 0x8F, 0xBD, 0x24, 0x9B, 0x81,
  34200. 0xCD, 0xDD, 0xF5, 0xBE, 0x05, 0x0D, 0xBD, 0x4B,
  34201. 0x2B, 0x8C, 0x0A, 0xF0, 0x3A, 0x85, 0xD6, 0x74,
  34202. 0x65, 0x7F, 0x98, 0xF8, 0x57, 0xA2, 0x36, 0xA2,
  34203. 0xFE, 0xE4, 0xB4, 0xA4, 0x0D, 0xEA, 0x9A, 0xBE,
  34204. 0x41, 0x79, 0x68, 0x63, 0x70, 0x3F, 0x3E, 0x38,
  34205. 0x60, 0xC3, 0x40, 0x81, 0x72, 0xDD, 0x25, 0x34,
  34206. 0xB4, 0xFE, 0xAC, 0x41, 0x6E, 0x4A, 0xE7, 0xBF,
  34207. 0xE3, 0x87, 0xFA, 0x20, 0x8B, 0xBD, 0x68, 0x9E,
  34208. 0x06, 0xA9, 0x15, 0x23, 0x07, 0x04, 0x4B, 0xFA,
  34209. 0x45, 0x45, 0xB7, 0x75, 0xD3, 0x3E, 0x16, 0x70,
  34210. 0xF6, 0x26, 0xF2, 0x3A, 0x9D, 0xFB, 0xEA, 0xEB,
  34211. 0x47, 0xCE, 0x99, 0x6B, 0x0E, 0xB2, 0xE8, 0x2B,
  34212. 0x18, 0x15, 0x14, 0x2E, 0xF2, 0x14, 0x0D, 0x44,
  34213. 0x47, 0x1E, 0x63, 0x84, 0x5B, 0x3F, 0xA8, 0xEF,
  34214. 0x5F, 0xEB, 0xA0, 0x41, 0x77, 0xC1, 0xF4, 0x4F,
  34215. 0x8E, 0x2E, 0x29, 0xCD, 0xDB, 0xF2, 0x75, 0x24,
  34216. 0x24, 0x46, 0x73, 0xC3, 0x46, 0xB5, 0xCA, 0x13,
  34217. 0x35, 0x12, 0x0A, 0x8D, 0x88, 0x89, 0x17, 0x99,
  34218. 0x13, 0xCA, 0x66, 0x07, 0x67, 0x6B, 0x7B, 0x3B,
  34219. 0x20, 0xD3, 0x5F, 0x78, 0x1C, 0xC0, 0x99, 0x59,
  34220. 0x0A, 0xBA, 0x8F, 0xA0, 0xDB, 0xDF, 0xCC, 0x03,
  34221. 0xC4, 0xA6, 0xC7, 0x08, 0xB9, 0xFD, 0x95, 0xC2,
  34222. 0x45, 0xF9, 0xF3, 0x11, 0x62, 0xF7, 0x14, 0xB9,
  34223. 0xEB, 0x09, 0xB3, 0x7C, 0xF8, 0xF6, 0x67, 0xCC,
  34224. 0x03, 0xB3, 0x06, 0x6F, 0x60, 0xAC, 0x72, 0xF2,
  34225. 0xD3, 0x71, 0x6C, 0x4D, 0xAD, 0x3A, 0x99, 0x75,
  34226. 0x5C, 0x52, 0x2D, 0x87, 0x69, 0x3E, 0xD6, 0x7E,
  34227. 0x12, 0x96, 0xD3, 0x88, 0x8D, 0x11, 0x85, 0xAA,
  34228. 0x0A, 0xA5, 0x32, 0x90, 0x51, 0xC5, 0x65, 0x64,
  34229. 0xE0, 0xA9, 0x73, 0xA4, 0xF3, 0x8A, 0x32, 0x83,
  34230. 0xE5, 0x08, 0x09, 0x39, 0x6A, 0x90, 0x2C, 0xC3,
  34231. 0xFC, 0x92, 0x29, 0x7A, 0x45, 0xBE, 0x02, 0x79,
  34232. 0x15, 0x1B, 0xBB, 0x60, 0xBB, 0xD9, 0x42, 0xF1,
  34233. 0xE5, 0x14, 0xB4, 0xA5, 0xFF, 0x12, 0x42, 0x30,
  34234. 0xB0, 0xCB, 0xD0, 0x1D, 0xB4, 0x62, 0x49, 0xC5,
  34235. 0xB7, 0xDA, 0x37, 0x47, 0x2C, 0x8B, 0x16, 0xCA,
  34236. 0xD2, 0x2C, 0xA1, 0x24, 0xE6, 0x57, 0xFA, 0xEB,
  34237. 0x2C, 0x62, 0x2E, 0x12, 0x74, 0x37, 0x2B, 0x3F,
  34238. 0x56, 0x23, 0x9C, 0xED, 0x90, 0xDE, 0x0D, 0x6E,
  34239. 0x9E, 0x11, 0x78, 0xA4, 0x9C, 0xB3, 0xA1, 0x37,
  34240. 0xF7, 0x4B, 0x09, 0x61, 0xD8, 0x33, 0x1D, 0x80,
  34241. 0x68, 0x5C, 0xDD, 0xBD, 0x3E, 0xAE, 0x9D, 0xB8,
  34242. 0xBA, 0x42, 0x41, 0xDC, 0xC9, 0x93, 0xF1, 0x92,
  34243. 0x2F, 0x7A, 0xF9, 0xFE, 0x67, 0x13, 0x87, 0xBD,
  34244. 0x7D, 0x04, 0x17, 0x91, 0xB6, 0x03, 0x5E, 0xA0,
  34245. 0x5B, 0x23, 0xEA, 0x0C, 0xFA, 0x45, 0xCB, 0x1A,
  34246. 0xC5, 0x7F, 0x63, 0xD6, 0x3D, 0x3C, 0x66, 0x4A,
  34247. 0x83, 0x4E, 0x4E, 0x90, 0xA6, 0x63, 0xB0, 0x8A,
  34248. 0xD7, 0x0D, 0xB4, 0xB7, 0xA9, 0x0F, 0xC6, 0xC7,
  34249. 0x3B, 0xAD, 0x07, 0xA6, 0x94, 0x47, 0xDB, 0x63,
  34250. 0x26, 0x00, 0x18, 0x5E, 0x27, 0xB5, 0xE2, 0xE3,
  34251. 0xED, 0x8D, 0x97, 0x95, 0x38, 0x20, 0x24, 0x9F,
  34252. 0x40, 0x84, 0x44, 0x7E, 0x8C, 0x05, 0xAB, 0xB1,
  34253. 0x89, 0x26, 0x7D, 0x46, 0x2C, 0x9F, 0xE5, 0xC1,
  34254. 0x27, 0xCE, 0x1D, 0x5A, 0x9F, 0xF1, 0xF8, 0x57,
  34255. 0x8F, 0xCF, 0xB7, 0x4E, 0x07, 0xF3, 0xBA, 0x56,
  34256. 0xCF, 0xE9, 0x87, 0x21, 0x61, 0xD6, 0x97, 0x7B,
  34257. 0x26, 0x97, 0x07, 0xB4, 0x87, 0xFE, 0x25, 0x9C,
  34258. 0xA9, 0x8E, 0x06, 0x90, 0x17, 0x2C, 0x98, 0x26,
  34259. 0x23, 0xEE, 0xBB, 0x91, 0x8A, 0x15, 0x38, 0xA1,
  34260. 0x38, 0xCB, 0x8B, 0xA0, 0xF3, 0x4A, 0xF2, 0x12,
  34261. 0xA7, 0xB7, 0x05, 0xB6, 0x09, 0xD0, 0xEC, 0xDD,
  34262. 0x21, 0xB6, 0xFA, 0x29, 0x95, 0xB4, 0x08, 0xD5,
  34263. 0x95, 0xB7, 0xB8, 0x2E, 0x23, 0xAA, 0x89, 0x81,
  34264. 0xE2, 0xD0, 0xFD, 0x9C, 0x8D, 0xF0, 0xCA, 0x61,
  34265. 0xE3, 0x1E, 0x73, 0x9E, 0xD1, 0x72, 0x5C, 0x63,
  34266. 0xB8, 0x74, 0x0E, 0x2C, 0x27, 0x3A, 0x71, 0xF9,
  34267. 0xFE, 0x66, 0x33, 0xE9, 0x41, 0x27, 0x61, 0xA3,
  34268. 0xFA, 0xD8, 0x66, 0x2A, 0x52, 0x6D, 0xAB, 0xBF,
  34269. 0x32, 0xC2, 0x8E, 0x8F, 0xB0, 0x60, 0x52, 0xE1,
  34270. 0x96, 0xC8, 0x1E, 0x9A, 0x3E, 0x07, 0xFA, 0x34,
  34271. 0xFA, 0x9C, 0x4C, 0x0D, 0x29, 0x0F, 0x68, 0xA6,
  34272. 0x59, 0x28, 0x22, 0xB1, 0x99, 0x56, 0x2C, 0x01,
  34273. 0x04, 0x2F, 0x34, 0x65, 0xFD, 0xD4, 0xD0, 0xD5,
  34274. 0x17, 0x7C, 0x14, 0x92, 0x73, 0x6C, 0x31, 0xCE,
  34275. 0xD4, 0xB3, 0x59, 0x83, 0x6B, 0x34, 0x7C, 0x76,
  34276. 0x8C, 0xED, 0xD5, 0xE2, 0x4F, 0x39, 0x44, 0xBF,
  34277. 0x90, 0x53, 0x9A, 0xC7, 0xD4, 0x6A, 0x86, 0xA3,
  34278. 0xE2, 0x15, 0x59, 0xD0, 0x0F, 0x32, 0x92, 0xC2,
  34279. 0x9B, 0x9E, 0xE3, 0xF6, 0x94, 0x96, 0xFD, 0x0B,
  34280. 0xB6, 0x06, 0x8F, 0x0D, 0x1F, 0x38, 0xFC, 0x6F,
  34281. 0xA2, 0x78, 0xAC, 0xC5, 0xB5, 0x6A, 0x6B, 0xEC,
  34282. 0x78, 0x8A, 0x6F, 0xD8, 0x21, 0xB7, 0xCF, 0x66,
  34283. 0x73, 0x03, 0xCA, 0x2E, 0x3C, 0x7F, 0x2F, 0x29,
  34284. 0x41, 0xC9, 0x88, 0xFD, 0x0E, 0xA0, 0x43, 0xD6,
  34285. 0x9E, 0xB1, 0xE7, 0x13, 0x9C, 0xF0, 0x9C, 0xCF,
  34286. 0x33, 0x22, 0x57, 0xEF, 0xE5, 0xCE, 0xD9, 0xAC,
  34287. 0x7D, 0x34, 0x75, 0xBD, 0xAE, 0x84, 0xEE, 0xE8,
  34288. 0x5D, 0x8C, 0x55, 0x86, 0xBA, 0x19, 0xE5, 0x9D,
  34289. 0x35, 0x6D, 0xD8, 0x70, 0xC5, 0xE0, 0xEA, 0x77,
  34290. 0x3A, 0xE5, 0xB5, 0x2C, 0xD2, 0x28, 0xB5, 0xE8,
  34291. 0xAF, 0xB1, 0xD2, 0xC4, 0xE5, 0x59, 0x06, 0xB8,
  34292. 0x2E, 0xA6, 0x8F, 0xC4, 0x9B, 0x30, 0xF9, 0x37,
  34293. 0xDB, 0x29, 0xA1, 0x44, 0x0B, 0xB7, 0xB5, 0xB4,
  34294. 0x12, 0xD3, 0x4E, 0xB3, 0xB7, 0xD8, 0x2F, 0x19,
  34295. 0xDE, 0x3B, 0xC3, 0x53, 0xCE, 0x1C, 0x34, 0x4C,
  34296. 0xA4, 0x6A, 0xE2, 0xD0, 0x04, 0xDF, 0x3C, 0x53,
  34297. 0x8B, 0x06, 0x8F, 0x36, 0xE5, 0x77, 0xB2, 0x7A,
  34298. 0x1A, 0xC0, 0x0C, 0xBD, 0xA3, 0xA0, 0xEE, 0xB6,
  34299. 0x40, 0xAD, 0x5C, 0x04, 0xAE, 0xCF, 0x64, 0x2B,
  34300. 0x8A, 0x18, 0x58, 0x86, 0xDE, 0xC9, 0x3D, 0x7D,
  34301. 0x15, 0xBC, 0xEE, 0x4C, 0x22, 0xF4, 0x98, 0xD9,
  34302. 0x37, 0xEE, 0xE2, 0x40, 0x43, 0xFF, 0xB2, 0x6F,
  34303. 0x05, 0xC0, 0x0E, 0x30, 0xDE, 0xD8, 0x0C, 0x0B,
  34304. 0xAD, 0xED, 0xCC, 0xBC, 0x29, 0x95, 0x07, 0x40,
  34305. 0x10, 0x99, 0xA0, 0xD1, 0x08, 0xF7, 0xD5, 0xF1,
  34306. 0xAD, 0xC9, 0xDD, 0xC8, 0x6A, 0x1E, 0x9E, 0x06,
  34307. 0xDF, 0x12, 0xFF, 0x66, 0x33, 0x5E, 0x21, 0x47,
  34308. 0xC3, 0xDE, 0x36, 0x98, 0x5B, 0xBF, 0x42, 0x9E,
  34309. 0x30, 0xA0, 0x81, 0x5C, 0x28, 0x34, 0x1B, 0x3A,
  34310. 0x32, 0xBC, 0xDE, 0x52, 0x53, 0x25, 0x1E, 0xF6,
  34311. 0xE2, 0x99, 0x12, 0x92, 0x07, 0x1D, 0xEB, 0x08,
  34312. 0x36, 0xA7, 0xD5, 0x18, 0x1F, 0xDB, 0x44, 0xA7,
  34313. 0xE1, 0x13, 0x06, 0xB0, 0xDF, 0x63, 0x82, 0x68,
  34314. 0xEF, 0xF5, 0x2B, 0x04, 0x0B, 0x93, 0xE8, 0xB0,
  34315. 0x92, 0x7B, 0xDE, 0x1F, 0xC9, 0x39, 0x8F, 0x42,
  34316. 0x9D, 0x06, 0x22, 0x13, 0xC9, 0x97, 0x2F, 0x43,
  34317. 0x8A, 0xBA, 0xAF, 0xF9, 0x71, 0xE3, 0x55, 0x5D,
  34318. 0x06, 0x77, 0x38, 0x39, 0xA3, 0xED, 0x41, 0x63,
  34319. 0xFE, 0x2A, 0xB3, 0x23, 0x43, 0x0C, 0xF3, 0x17,
  34320. 0x3B, 0x69, 0xED, 0x32, 0x0A, 0x54, 0xF3, 0x8D,
  34321. 0x76, 0xC6, 0x09, 0xDD, 0x88, 0x5B, 0x23, 0x57,
  34322. 0x72, 0xC4, 0x87, 0xB8, 0x9D, 0xF7, 0xCA, 0xFB,
  34323. 0x7C, 0x61, 0x67, 0x5C, 0x65, 0xF8, 0xD6, 0xD7,
  34324. 0x1E, 0x95, 0xB9, 0x73, 0x4D, 0x2E, 0x1F, 0x43,
  34325. 0x3E, 0x2B, 0x58, 0x92, 0x15, 0x2E, 0xAA, 0x51,
  34326. 0xF0, 0xD4, 0xF2, 0xA6, 0xCD, 0x12, 0x21, 0xD6,
  34327. 0xCA, 0x46, 0x2A, 0xFF, 0xCB, 0x1B, 0x6B, 0xB4,
  34328. 0x09, 0x17, 0x3B, 0xA2, 0x94, 0xDF, 0x1D, 0x68,
  34329. 0x8B, 0x75, 0xEA, 0x11, 0xD6, 0x99, 0x04, 0xD1,
  34330. 0x00, 0xDB, 0x61, 0xBC, 0xF2, 0x3B, 0x88, 0x4B,
  34331. 0x33, 0xDF, 0x0F, 0xD4, 0xFB, 0x14, 0x0C, 0x6A,
  34332. 0x53, 0x61, 0x1F, 0xBD, 0x28, 0xB2, 0x11, 0x19,
  34333. 0x38, 0x71, 0x17, 0x76, 0x4D, 0xEE, 0x01, 0xC4,
  34334. 0x77, 0x53, 0x2A, 0xAF, 0xD3, 0x78, 0xFF, 0x45,
  34335. 0x7F, 0x97, 0x9D, 0x26, 0x92, 0x0E, 0xD9, 0x4E,
  34336. 0x34, 0x1D, 0xE8, 0xDD, 0xBF, 0x5F, 0x87, 0xE6,
  34337. 0x35, 0x9A, 0x39, 0x71, 0x59, 0x20, 0x01, 0xFB,
  34338. 0x53, 0x2C, 0x61, 0x38, 0x0C, 0x8C, 0x02, 0xD3,
  34339. 0xA0, 0x53, 0x95, 0x02, 0xED, 0x5C, 0xFE, 0x9B,
  34340. 0xD3, 0x6A, 0xF3, 0x3F, 0x92, 0x6F, 0x33, 0x37,
  34341. 0x19, 0x97, 0x81, 0x3A, 0x50, 0xE1, 0xD9, 0x27,
  34342. 0x7E, 0x64, 0xF8, 0x01, 0x52, 0x26, 0x51, 0xD1,
  34343. 0x06, 0xAF, 0x20, 0xA0, 0x28, 0x0F, 0x3F, 0xCB,
  34344. 0x21, 0xB7, 0x55, 0x1A, 0x76, 0xB8, 0x9B, 0x4D,
  34345. 0xED, 0x2A, 0x05, 0x0E, 0x6E, 0xAF, 0xCC, 0xA1,
  34346. 0x08, 0x9C, 0xBE, 0x3F, 0x98, 0xE6, 0xB4, 0xB9,
  34347. 0x83, 0xC9, 0x08, 0x41, 0x96, 0xDD, 0xD9, 0x0D,
  34348. 0x52, 0x66, 0x94, 0xA4, 0xEA, 0xFC, 0xE5, 0x48,
  34349. 0x04, 0x73, 0x64, 0x79, 0x68, 0xC9, 0x4A, 0x81,
  34350. 0xA8, 0x07, 0xF8, 0xD9, 0x4E, 0x07, 0x1E, 0xC1,
  34351. 0x8F, 0x62, 0xAB, 0xA6, 0xD7, 0x68, 0xFC, 0x57,
  34352. 0x5E, 0x75, 0x1B, 0xBF, 0x3D, 0xA6, 0x91, 0xC5,
  34353. 0x08, 0x14, 0x5E, 0xF2, 0x4C, 0x22, 0x8B, 0x4E,
  34354. 0x29, 0x2D, 0xC0, 0x46, 0x3A, 0x9C, 0x9D, 0x86,
  34355. 0xCF, 0x51, 0x85, 0x9D, 0x93, 0x23, 0xA1, 0xA1,
  34356. 0xF3, 0x76, 0xB1, 0x56, 0xB0, 0xF4, 0x1F, 0x39,
  34357. 0xDA, 0xDB, 0x13, 0x70, 0x29, 0x89, 0x95, 0xD2,
  34358. 0xC5, 0xF3, 0x76, 0xFE, 0xEE, 0x99, 0xCF, 0xA0,
  34359. 0x84, 0xEC, 0x70, 0xF0, 0xD3, 0xFA, 0x42, 0xDB,
  34360. 0xFD, 0x99, 0x65, 0x2F, 0x84, 0x11, 0x99, 0xCD,
  34361. 0x38, 0xB3, 0x1B, 0xAB, 0x8C, 0x2D, 0x33, 0x04,
  34362. 0xCA, 0xE1, 0xB3, 0x05, 0x9A, 0x20, 0x80, 0xDB,
  34363. 0xED, 0x59, 0x42, 0x30, 0x48, 0x37, 0xB3, 0x85,
  34364. 0x5C, 0xEE, 0x54, 0x06, 0x92, 0x97, 0x4E, 0xFC,
  34365. 0xFA, 0xF7, 0x25, 0xE0, 0x4E, 0x57, 0xC4, 0x72,
  34366. 0x38, 0x59, 0xCA, 0x3C, 0x4A, 0x3F, 0x09, 0xD6,
  34367. 0x09, 0x15, 0x83, 0xEF, 0x24, 0x21, 0xDD, 0xFD,
  34368. 0x66, 0x9E, 0xBF, 0xEE, 0xCC, 0xBF, 0x86, 0x20,
  34369. 0x29, 0x40, 0x5E, 0x42, 0xD2, 0xC0, 0x24, 0x2D,
  34370. 0x76, 0xE6, 0x64, 0xF9, 0x5D, 0xC2, 0x85, 0xB6,
  34371. 0x09, 0x41, 0x04, 0x62, 0x17, 0xDC, 0xF8, 0xFA,
  34372. 0x2A, 0x4C, 0xD1, 0x82, 0x31, 0x57, 0xB7, 0x2B,
  34373. 0x49, 0xE8, 0x40, 0x13, 0x2A, 0xA1, 0x86, 0xD2,
  34374. 0x9A, 0xB8, 0xA9, 0xBE, 0x39, 0xBE, 0xE9, 0xA5,
  34375. 0x35, 0x12, 0x08, 0xF1, 0xA9, 0x9E, 0x57, 0x46,
  34376. 0x3A, 0x55, 0x16, 0xA7, 0x41, 0xD9, 0x25, 0xB8,
  34377. 0x2F, 0xAF, 0xA8, 0x81, 0x5F, 0x5F, 0x46, 0xA4,
  34378. 0x3B, 0xB3, 0xE9, 0x1B, 0x74, 0xEF, 0x5D, 0x57,
  34379. 0x48, 0x4A, 0x72, 0x08, 0xDA, 0xFE, 0x1D, 0x55,
  34380. 0x6B, 0xAB, 0x8B, 0x13, 0x18, 0xBF, 0xDD, 0xF4,
  34381. 0x4E, 0x01, 0x5F, 0x4B, 0xF6, 0x80, 0xD4, 0x16,
  34382. 0x4B, 0x2F, 0x03, 0x4B, 0xF8, 0x93, 0x20, 0x21,
  34383. 0x55, 0x52, 0x49, 0x4A, 0x6C, 0x1F, 0x7D, 0xAD,
  34384. 0x04, 0xEF, 0xB3, 0x74, 0xEE, 0xC5, 0xB6, 0xBC,
  34385. 0x33, 0x7A, 0xCF, 0x64, 0xB9, 0xF9, 0x41, 0x70,
  34386. 0xAF, 0xE9, 0xC7, 0xD6, 0x25, 0x18, 0x17, 0xAB,
  34387. 0xBA, 0xC9, 0x05, 0xEF, 0x40, 0x89, 0xD5, 0x69,
  34388. 0x76, 0xAA, 0xA0, 0x3E, 0x4D, 0x1C, 0xE7, 0x9D,
  34389. 0x9E, 0x74, 0xF4, 0xF2, 0x7B, 0x40, 0xF6, 0x57,
  34390. 0x78, 0x66, 0xFC, 0xDA, 0xE3, 0x6B, 0xD2, 0x6E,
  34391. 0xC7, 0x9D, 0x65, 0x84, 0xAF, 0x7A, 0x1F, 0xE4,
  34392. 0x34, 0xD4, 0x1A, 0x17, 0xA2, 0x72, 0xB0, 0xEE,
  34393. 0x5A, 0x0C, 0xF4, 0x02, 0xAC, 0x1D, 0x6F, 0x4A,
  34394. 0xD0, 0xB2, 0x02, 0x3A, 0x7D, 0x2C, 0xF1, 0x43,
  34395. 0x0E, 0x1E, 0x96, 0xEB, 0x42, 0xF8, 0x3A, 0xF5,
  34396. 0x0B, 0x5D, 0xA9, 0x23, 0x02, 0x28, 0xE5, 0x26,
  34397. 0x5E, 0x69, 0x38, 0x2F, 0x85, 0x34, 0x32, 0x5E,
  34398. 0x5E, 0x29, 0x33, 0x94, 0x05, 0xBD, 0x58, 0xF8,
  34399. 0xE8, 0x9C, 0xBF, 0xB1, 0x5A, 0x05, 0xC6, 0x23,
  34400. 0x9B, 0xBB, 0x57, 0x69, 0x8C, 0xE6, 0x41, 0x97,
  34401. 0x48, 0x01, 0x95, 0xAF, 0xE9, 0x62, 0x8C, 0x6F,
  34402. 0x09, 0x43, 0xF3, 0x64, 0x50, 0x90, 0x2F, 0x14,
  34403. 0xF7, 0x30, 0x07, 0xE0, 0x4B, 0xA8, 0x39, 0xAC,
  34404. 0x21, 0xC4, 0x07, 0x45, 0x5F, 0xD9, 0x87, 0xB1,
  34405. 0x57, 0x47, 0x07, 0x66, 0xFF, 0xC7, 0xAB, 0xEE,
  34406. 0x1F, 0x55, 0x71, 0x50, 0x63, 0xCF, 0x58, 0x3B,
  34407. 0xC8, 0x1B, 0xEA, 0xA5, 0xE2, 0xF1, 0x57, 0xB3,
  34408. 0x77, 0x65, 0xA9, 0xBD, 0x23, 0xC8, 0x30, 0x86,
  34409. 0xC3, 0x5F, 0xBF, 0x16, 0x3F, 0x42, 0x28, 0x0A,
  34410. 0xC6, 0x5A, 0x57, 0x15, 0x2F, 0xA1, 0x96, 0xA9,
  34411. 0x25, 0xC5, 0x8E, 0x32, 0x11, 0x62, 0xB3, 0x54,
  34412. 0x18, 0x00, 0xA4, 0xA6, 0xD4, 0x0F, 0x68, 0x27,
  34413. 0x8F, 0x21, 0x78, 0x02, 0x37, 0x98, 0xBD, 0xCE,
  34414. 0x3F, 0xBC, 0xF2, 0x9C, 0x66, 0x8E, 0x79, 0xA1,
  34415. 0x54, 0x12, 0x55, 0x2E, 0xC0, 0x59, 0xC7, 0x18,
  34416. 0x18, 0x22, 0x4D, 0x27, 0x8B, 0x8D, 0xF3, 0x08,
  34417. 0x99, 0xE6, 0x35, 0x14, 0xB1, 0xE3, 0xB8, 0x7A,
  34418. 0x40, 0x7B, 0x68, 0x7B, 0xFF, 0xDC, 0x54, 0x41,
  34419. 0x06, 0xCA, 0x91, 0xFE, 0xDB, 0x2B, 0xDA, 0x9E,
  34420. 0xC5, 0x20, 0xD8, 0xBF, 0x42, 0xBC, 0xE6, 0x39,
  34421. 0xC4, 0x26, 0x9E, 0xF3, 0x82, 0xD9, 0xF1, 0xA0,
  34422. 0x04, 0xAF, 0xFB, 0x77, 0x13, 0x36, 0xAF, 0xD7,
  34423. 0x91, 0x9B, 0x3A, 0x57, 0x98, 0xFE, 0xAD, 0xCD,
  34424. 0x46, 0xF8, 0xF8, 0xF1, 0x87, 0x53, 0xBD, 0x57,
  34425. 0x3F, 0x99, 0xBC, 0xA6, 0xBD, 0x9B, 0x6E, 0xF4,
  34426. 0x17, 0x7A, 0x78, 0x30, 0x70, 0xA3, 0x43, 0xFF,
  34427. 0x92, 0xCD, 0x99, 0x73, 0xAE, 0x65, 0x6A, 0x10,
  34428. 0xFF, 0x70, 0x47, 0x0F, 0x16, 0x4C, 0x4A, 0x90,
  34429. 0xF4, 0x52, 0x05, 0x79, 0x33, 0x63, 0xDE, 0x14,
  34430. 0x65, 0xAF, 0x8A, 0x5E, 0x67, 0x20, 0x03, 0x9F,
  34431. 0xE6, 0x70, 0x13, 0x6B, 0xE0, 0xF3, 0x6A, 0x4C,
  34432. 0x6B, 0x5B, 0xCB, 0xE1, 0x7C, 0x5D, 0x7D, 0xE3,
  34433. 0x23, 0xFD, 0xB8, 0x6A, 0xDA, 0x56, 0x1E, 0xA8,
  34434. 0x36, 0xC4, 0x29, 0x2D, 0x70, 0x41, 0x03, 0x18,
  34435. 0x31, 0x40, 0x79, 0x2E, 0xC8, 0x22, 0x98, 0x5E,
  34436. 0x11, 0xED, 0xA6, 0xDD, 0xB9, 0xAF, 0x8C, 0x27,
  34437. 0x5C, 0x1B, 0x2E, 0xEA, 0xB8, 0xC6, 0x2F, 0xA0,
  34438. 0x40, 0xB2, 0x64, 0x61, 0xFC, 0x0A, 0x3A, 0x10,
  34439. 0x88, 0xC2, 0x58, 0xEC, 0xA5, 0x8D, 0x14, 0xE9,
  34440. 0x9D, 0x21, 0xAF, 0x64, 0xD6, 0xC2, 0x5D, 0xAA,
  34441. 0x0B, 0x8A, 0x57, 0x0F, 0x84, 0x3E, 0x60, 0x8D,
  34442. 0xED, 0x05, 0x1D, 0x98, 0xED, 0xAE, 0x11, 0xD9,
  34443. 0x27, 0x03, 0x55, 0xED, 0xF5, 0x34, 0x92, 0x52,
  34444. 0xF2, 0x6F, 0x30, 0x3E, 0x69, 0xA5, 0x54, 0xA7,
  34445. 0x2E, 0x1B, 0x85, 0xAB, 0xA2, 0x3B, 0xEC, 0xC8,
  34446. 0x9D, 0xA9, 0xA3, 0xE4, 0xEF, 0x58, 0xB5, 0x33,
  34447. 0x88, 0x55, 0x16, 0x5E, 0x7D, 0x7E, 0x69, 0xFC,
  34448. 0xCA, 0xBD, 0x9C, 0x65, 0xFA, 0x0B, 0xBD, 0x7B,
  34449. 0x16, 0xC4, 0xE2, 0x9C, 0xB4, 0xF1, 0x6A, 0x25,
  34450. 0x70, 0x30, 0x32, 0xED, 0xEA, 0xD3, 0x1D, 0xDB,
  34451. 0x6F, 0x29, 0x2E, 0x42, 0x14, 0xBE, 0x03, 0x29,
  34452. 0x0A, 0x8A, 0x98, 0x9A, 0xD7, 0xB7, 0x0C, 0xF8,
  34453. 0xB9, 0xCF, 0x37, 0xC6, 0xAC, 0xAC, 0x6D, 0xCC,
  34454. 0x03, 0x23, 0x9F, 0x66, 0x85, 0x4B, 0x70, 0x45
  34455. };
  34456. #endif /* WOLFSSL_NO_ML_DSA_87 */
  34457. #endif
  34458. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34459. ExpectNotNull(key);
  34460. if (key != NULL) {
  34461. XMEMSET(key, 0, sizeof(*key));
  34462. }
  34463. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  34464. #ifndef WOLFSSL_NO_ML_DSA_44
  34465. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  34466. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44), 0);
  34467. ExpectIntEQ(XMEMCMP(key->p, pk_44, sizeof(pk_44)), 0);
  34468. ExpectIntEQ(XMEMCMP(key->k, sk_44, sizeof(sk_44)), 0);
  34469. #endif
  34470. #ifndef WOLFSSL_NO_ML_DSA_65
  34471. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  34472. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65), 0);
  34473. ExpectIntEQ(XMEMCMP(key->p, pk_65, sizeof(pk_65)), 0);
  34474. ExpectIntEQ(XMEMCMP(key->k, sk_65, sizeof(sk_65)), 0);
  34475. #endif
  34476. #ifndef WOLFSSL_NO_ML_DSA_87
  34477. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  34478. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87), 0);
  34479. ExpectIntEQ(XMEMCMP(key->p, pk_87, sizeof(pk_87)), 0);
  34480. ExpectIntEQ(XMEMCMP(key->k, sk_87, sizeof(sk_87)), 0);
  34481. #endif
  34482. wc_dilithium_free(key);
  34483. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34484. #endif
  34485. return EXPECT_RESULT();
  34486. }
  34487. static int test_wc_dilithium_sig_kats(void)
  34488. {
  34489. EXPECT_DECLS;
  34490. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  34491. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \
  34492. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT)
  34493. dilithium_key* key;
  34494. #ifndef WOLFSSL_NO_ML_DSA_44
  34495. static const byte sk_44[] = {
  34496. 0x5D, 0xFB, 0x07, 0xA2, 0x04, 0x4B, 0x93, 0x16,
  34497. 0x75, 0xC7, 0x89, 0x43, 0xEA, 0xC3, 0xC4, 0xC5,
  34498. 0x7B, 0x07, 0x77, 0x8A, 0xD9, 0xAF, 0x2E, 0x87,
  34499. 0xC4, 0x70, 0xB9, 0xCC, 0x2C, 0x8D, 0xA1, 0xE3,
  34500. 0x75, 0xBC, 0xB3, 0xBC, 0xD1, 0x9E, 0x7B, 0xB9,
  34501. 0x83, 0xC9, 0x63, 0x66, 0xCC, 0xEA, 0x14, 0x1E,
  34502. 0xAE, 0x22, 0x07, 0x75, 0x52, 0x24, 0xC8, 0xC6,
  34503. 0xC6, 0x1F, 0x90, 0x89, 0x89, 0xCF, 0xF2, 0xF6,
  34504. 0x27, 0x98, 0xA6, 0x86, 0x45, 0x77, 0x95, 0x15,
  34505. 0xD4, 0x74, 0xDD, 0xA6, 0x1F, 0x33, 0x41, 0x42,
  34506. 0x4E, 0xDA, 0x24, 0x79, 0x60, 0x27, 0x34, 0x4E,
  34507. 0x36, 0x94, 0x14, 0x74, 0x81, 0x9A, 0x58, 0x44,
  34508. 0x2B, 0x74, 0xBF, 0x50, 0x60, 0xB8, 0x40, 0x94,
  34509. 0x4A, 0xEF, 0xDE, 0xA7, 0xA4, 0xCF, 0xFC, 0xB3,
  34510. 0x9D, 0xE2, 0x07, 0xFD, 0x9E, 0x6A, 0xC6, 0x2E,
  34511. 0x6D, 0x0D, 0xB2, 0xB4, 0x51, 0x2E, 0x20, 0x26,
  34512. 0x00, 0xB5, 0x30, 0x01, 0xA9, 0x2D, 0xE2, 0x42,
  34513. 0x02, 0x42, 0x12, 0x71, 0x24, 0xB7, 0x28, 0x94,
  34514. 0x30, 0x86, 0xDA, 0x22, 0x30, 0x00, 0x87, 0x65,
  34515. 0xCC, 0x22, 0x91, 0x1B, 0x05, 0x82, 0x03, 0x46,
  34516. 0x8A, 0xA0, 0x32, 0x26, 0x40, 0xB4, 0x84, 0xC3,
  34517. 0x14, 0x2D, 0x88, 0x14, 0x8C, 0x94, 0x92, 0x49,
  34518. 0x23, 0x15, 0x0E, 0xCA, 0x88, 0x09, 0x18, 0x94,
  34519. 0x68, 0x82, 0x38, 0x00, 0x21, 0x41, 0x28, 0x8C,
  34520. 0xB8, 0x80, 0x02, 0x09, 0x49, 0x5A, 0xB4, 0x11,
  34521. 0x9B, 0x28, 0x05, 0xE4, 0x42, 0x30, 0xCA, 0x24,
  34522. 0x80, 0xA4, 0x06, 0x2A, 0xD3, 0x92, 0x05, 0x1C,
  34523. 0x03, 0x6A, 0x22, 0x36, 0x4A, 0x92, 0x44, 0x52,
  34524. 0xE2, 0x48, 0x28, 0x19, 0x83, 0x68, 0x88, 0xC6,
  34525. 0x31, 0x41, 0x90, 0x50, 0x00, 0x43, 0x8E, 0x23,
  34526. 0x87, 0x60, 0x19, 0x43, 0x81, 0x50, 0x32, 0x69,
  34527. 0x81, 0xC0, 0x51, 0x12, 0x06, 0x08, 0x02, 0x08,
  34528. 0x82, 0xC4, 0xA6, 0x81, 0x03, 0xA5, 0x90, 0x8C,
  34529. 0xB6, 0x00, 0x90, 0x14, 0x66, 0x01, 0xB1, 0x08,
  34530. 0x12, 0x25, 0x48, 0x1A, 0x88, 0x11, 0x43, 0x38,
  34531. 0x60, 0x23, 0x26, 0x2E, 0x14, 0x45, 0x0D, 0x9C,
  34532. 0x92, 0x8C, 0xA2, 0x46, 0x12, 0x94, 0xA6, 0x05,
  34533. 0x88, 0xB0, 0x11, 0x0A, 0xB0, 0x28, 0xA4, 0x42,
  34534. 0x09, 0x9C, 0x82, 0x80, 0x1A, 0x80, 0x61, 0x59,
  34535. 0xB0, 0x8D, 0x40, 0xA6, 0x6D, 0x12, 0xC9, 0x0C,
  34536. 0xD9, 0x18, 0x68, 0xA3, 0x84, 0x2C, 0x02, 0xB6,
  34537. 0x25, 0x01, 0x40, 0x2C, 0xD8, 0x20, 0x4D, 0x1B,
  34538. 0x35, 0x30, 0x11, 0x10, 0x49, 0x63, 0x44, 0x31,
  34539. 0x8A, 0xB2, 0x70, 0x4B, 0x24, 0x28, 0xA0, 0x46,
  34540. 0x08, 0xC9, 0x06, 0x81, 0x08, 0xC5, 0x04, 0x4A,
  34541. 0xB2, 0x30, 0x08, 0x15, 0x04, 0x24, 0xA2, 0x65,
  34542. 0x9B, 0x88, 0x41, 0x19, 0x36, 0x2E, 0xE2, 0xB8,
  34543. 0x29, 0xD9, 0x12, 0x64, 0x41, 0xA6, 0x30, 0x22,
  34544. 0xB7, 0x8C, 0x93, 0x38, 0x69, 0x93, 0x30, 0x0A,
  34545. 0xC8, 0xB6, 0x85, 0x23, 0xB1, 0x8D, 0x01, 0x38,
  34546. 0x0A, 0x59, 0xA0, 0x09, 0x64, 0x12, 0x6E, 0x88,
  34547. 0x08, 0x22, 0xDB, 0x00, 0x08, 0x0C, 0x08, 0x12,
  34548. 0x99, 0x42, 0x44, 0x1B, 0x00, 0x68, 0x08, 0x13,
  34549. 0x26, 0x53, 0xA2, 0x40, 0x5A, 0x34, 0x25, 0x98,
  34550. 0x90, 0x8C, 0x00, 0x34, 0x2D, 0x93, 0x94, 0x48,
  34551. 0xC8, 0x22, 0x4C, 0xE2, 0x44, 0x29, 0xE2, 0x00,
  34552. 0x28, 0x14, 0x22, 0x40, 0x48, 0x28, 0x24, 0x22,
  34553. 0x49, 0x06, 0xCA, 0xC8, 0x0C, 0x4C, 0x12, 0x80,
  34554. 0x1B, 0xA5, 0x41, 0x11, 0x06, 0x48, 0x1B, 0x27,
  34555. 0x72, 0x20, 0x07, 0x31, 0x24, 0x10, 0x8E, 0x9C,
  34556. 0x94, 0x91, 0x1B, 0x37, 0x82, 0x51, 0x28, 0x2E,
  34557. 0x11, 0x06, 0x42, 0x01, 0x34, 0x6E, 0x8C, 0x22,
  34558. 0x25, 0x24, 0x34, 0x6A, 0x19, 0x47, 0x21, 0x23,
  34559. 0xB6, 0x09, 0x51, 0xB2, 0x31, 0x18, 0x34, 0x45,
  34560. 0x8C, 0xB8, 0x20, 0x1C, 0x19, 0x0A, 0x19, 0xB7,
  34561. 0x6D, 0x18, 0x97, 0x48, 0x09, 0x82, 0x04, 0x9C,
  34562. 0x12, 0x8A, 0x41, 0x08, 0x46, 0x24, 0x13, 0x31,
  34563. 0xD0, 0x42, 0x46, 0xC3, 0x16, 0x80, 0x51, 0x10,
  34564. 0x2E, 0x51, 0x48, 0x04, 0x5C, 0xC2, 0x64, 0x1A,
  34565. 0x10, 0x8E, 0xD9, 0x86, 0x64, 0x90, 0x24, 0x68,
  34566. 0x93, 0xB4, 0x45, 0x94, 0x30, 0x4A, 0xE3, 0x12,
  34567. 0x0C, 0x54, 0x04, 0x90, 0x03, 0x31, 0x40, 0x62,
  34568. 0x92, 0x4D, 0x5C, 0xC8, 0x10, 0x8A, 0xB8, 0x61,
  34569. 0x5C, 0x04, 0x6A, 0xC8, 0xB0, 0x85, 0x93, 0x00,
  34570. 0x05, 0xC3, 0x06, 0x69, 0x1B, 0x34, 0x8E, 0x03,
  34571. 0x84, 0x0C, 0x50, 0x00, 0x2C, 0x8C, 0x96, 0x90,
  34572. 0x08, 0x32, 0x68, 0x0B, 0x90, 0x8C, 0x02, 0x86,
  34573. 0x2D, 0x18, 0x38, 0x09, 0x1C, 0xB2, 0x21, 0x1B,
  34574. 0x48, 0x04, 0x5C, 0x10, 0x86, 0xD8, 0x34, 0x51,
  34575. 0x43, 0x84, 0x88, 0x43, 0xB2, 0x65, 0x12, 0xB6,
  34576. 0x8D, 0x03, 0x01, 0x45, 0x19, 0xB8, 0x8D, 0x92,
  34577. 0x26, 0x4E, 0x12, 0x12, 0x88, 0x52, 0xB2, 0x64,
  34578. 0x21, 0x09, 0x26, 0x49, 0x38, 0x05, 0x24, 0x11,
  34579. 0x0A, 0x22, 0x38, 0x32, 0x23, 0x31, 0x20, 0x4A,
  34580. 0x24, 0x42, 0xC4, 0xA2, 0x44, 0x20, 0x10, 0x0D,
  34581. 0xA1, 0xA8, 0x51, 0x23, 0x86, 0x84, 0x81, 0x38,
  34582. 0x8E, 0x02, 0x00, 0x4A, 0x1C, 0xB7, 0x24, 0x4C,
  34583. 0x06, 0x0A, 0x1C, 0x26, 0x4E, 0xCC, 0x22, 0x48,
  34584. 0x4C, 0x92, 0x2D, 0xC0, 0x20, 0x2D, 0xA1, 0x16,
  34585. 0x89, 0xC3, 0x44, 0x82, 0x19, 0xA7, 0x6D, 0xC4,
  34586. 0x90, 0x10, 0x01, 0x82, 0x89, 0xD8, 0x44, 0x22,
  34587. 0xD9, 0x98, 0x20, 0xC0, 0x88, 0x45, 0x88, 0x22,
  34588. 0x0C, 0x90, 0x36, 0x90, 0x90, 0xA4, 0x05, 0xD3,
  34589. 0x82, 0x21, 0xD0, 0xA6, 0x28, 0x00, 0x33, 0x25,
  34590. 0xA2, 0xC2, 0x6C, 0xD8, 0x10, 0x71, 0xD1, 0x96,
  34591. 0x50, 0xC3, 0x34, 0x08, 0x8B, 0x94, 0x2D, 0x61,
  34592. 0x88, 0x04, 0x1B, 0xC8, 0x2D, 0xE2, 0x30, 0x64,
  34593. 0x20, 0x28, 0x24, 0x1A, 0x34, 0x50, 0x10, 0x25,
  34594. 0x6A, 0x64, 0x36, 0x81, 0x09, 0xC1, 0x45, 0xE3,
  34595. 0x30, 0x80, 0xC3, 0xA6, 0x8C, 0xE0, 0xB6, 0x10,
  34596. 0xC3, 0x34, 0x8D, 0xD1, 0x06, 0x11, 0x88, 0x20,
  34597. 0x0A, 0x0A, 0xC8, 0x21, 0x20, 0x81, 0x30, 0x9C,
  34598. 0x14, 0x61, 0x9B, 0xC2, 0x50, 0x22, 0x15, 0x8D,
  34599. 0x80, 0xA0, 0x41, 0x89, 0x24, 0x41, 0x20, 0x93,
  34600. 0x40, 0x01, 0xA6, 0x09, 0x08, 0x25, 0x2E, 0xC1,
  34601. 0xC6, 0x85, 0x00, 0x17, 0x62, 0x41, 0x30, 0x32,
  34602. 0xDC, 0x06, 0x6D, 0x48, 0x88, 0x08, 0x84, 0xC8,
  34603. 0x30, 0x5B, 0x96, 0x8D, 0x42, 0xB4, 0x4C, 0xD0,
  34604. 0x34, 0x88, 0xD0, 0x04, 0x02, 0x18, 0x15, 0x52,
  34605. 0x52, 0x26, 0x30, 0x8C, 0x46, 0x28, 0x20, 0x94,
  34606. 0x4C, 0x21, 0x18, 0x00, 0xD0, 0xB2, 0x48, 0x1B,
  34607. 0x17, 0x0A, 0x09, 0x30, 0x4C, 0x44, 0xC2, 0x04,
  34608. 0x47, 0x5E, 0xF2, 0x33, 0x31, 0xFF, 0x66, 0x73,
  34609. 0xE2, 0x6E, 0x6A, 0x32, 0xF2, 0x94, 0xBE, 0xFB,
  34610. 0xD5, 0x96, 0x4F, 0xED, 0x98, 0x7A, 0x42, 0xA2,
  34611. 0x35, 0xFC, 0x5B, 0x16, 0x08, 0x61, 0x45, 0xC0,
  34612. 0xB8, 0xA8, 0x23, 0xFB, 0xC1, 0x4F, 0x1C, 0x8C,
  34613. 0xD0, 0x3F, 0xD6, 0xEE, 0xC4, 0x95, 0x28, 0x3E,
  34614. 0x03, 0x5C, 0x0D, 0xCA, 0xE5, 0x2E, 0x68, 0xF3,
  34615. 0x29, 0xDE, 0x7A, 0xDF, 0xD6, 0x4F, 0xEE, 0x0B,
  34616. 0x11, 0x6D, 0x4A, 0x14, 0xE1, 0x53, 0x94, 0xB3,
  34617. 0x1D, 0xF8, 0x8B, 0xCA, 0x10, 0xD1, 0xC9, 0x06,
  34618. 0xAA, 0x82, 0x28, 0x7C, 0x11, 0x74, 0x99, 0xE9,
  34619. 0xD8, 0xC7, 0x7D, 0x17, 0xA9, 0x5C, 0xCC, 0x14,
  34620. 0xAF, 0xF9, 0xC2, 0x05, 0xD2, 0x64, 0x80, 0xA5,
  34621. 0x70, 0xB5, 0x77, 0x0B, 0x04, 0x81, 0x99, 0xCF,
  34622. 0x3F, 0x0E, 0x1B, 0x91, 0xAB, 0x39, 0x4B, 0x1F,
  34623. 0x65, 0xD4, 0x7F, 0x92, 0x98, 0xD0, 0x96, 0xCA,
  34624. 0x25, 0xC0, 0x99, 0xBC, 0x67, 0xF4, 0x33, 0x42,
  34625. 0x63, 0xE3, 0x6B, 0xD9, 0xE6, 0x6B, 0x99, 0x8A,
  34626. 0x07, 0xDC, 0x1E, 0x18, 0x1E, 0x05, 0x38, 0x6E,
  34627. 0x96, 0x8F, 0x1C, 0xB0, 0xAB, 0x1E, 0x9A, 0x67,
  34628. 0xD5, 0xD3, 0x30, 0x11, 0x20, 0x37, 0x82, 0x24,
  34629. 0x88, 0x1F, 0x65, 0x17, 0x59, 0xEC, 0x7D, 0xBF,
  34630. 0x45, 0x78, 0x1E, 0xF8, 0xA8, 0x4D, 0xAD, 0xAF,
  34631. 0xE6, 0x13, 0xD6, 0x01, 0x69, 0x66, 0xBD, 0x88,
  34632. 0x44, 0xB6, 0xA6, 0x17, 0xAC, 0xA1, 0xEE, 0xF6,
  34633. 0x73, 0xB7, 0x74, 0xCC, 0x80, 0x7B, 0x36, 0xDD,
  34634. 0x02, 0xDD, 0x45, 0x21, 0x66, 0x86, 0x03, 0x7F,
  34635. 0x9A, 0xC0, 0xB1, 0x2F, 0x57, 0x26, 0xF2, 0x51,
  34636. 0xC5, 0x72, 0x43, 0xE2, 0xC1, 0x88, 0xF5, 0xEC,
  34637. 0xC0, 0x97, 0xE0, 0xB9, 0x89, 0xB5, 0x8A, 0x5D,
  34638. 0x80, 0x4A, 0xBF, 0xD7, 0x20, 0x25, 0x55, 0x77,
  34639. 0x66, 0x8E, 0xE3, 0x04, 0xD0, 0x1C, 0x50, 0xFE,
  34640. 0x8B, 0x6D, 0x90, 0x68, 0x53, 0xCF, 0x7A, 0x49,
  34641. 0x4F, 0xB4, 0x79, 0x91, 0xF1, 0x81, 0xB7, 0x42,
  34642. 0x0E, 0x74, 0x19, 0x9C, 0x82, 0xE7, 0x1A, 0x82,
  34643. 0x4B, 0xF8, 0xC6, 0x13, 0x1D, 0xF4, 0xD1, 0x85,
  34644. 0x6F, 0x11, 0xE7, 0x04, 0x07, 0x70, 0x72, 0x4D,
  34645. 0xE7, 0x2C, 0x81, 0x5A, 0xC0, 0x44, 0x3F, 0x2E,
  34646. 0x77, 0xEC, 0x22, 0xA1, 0x28, 0xDB, 0x18, 0xE1,
  34647. 0x18, 0x3E, 0xE7, 0x96, 0x82, 0xC4, 0x30, 0x24,
  34648. 0xC9, 0x07, 0x46, 0x6C, 0x35, 0x4B, 0x1C, 0x7B,
  34649. 0x0E, 0x0E, 0xF0, 0x9F, 0x16, 0x48, 0x7B, 0xD8,
  34650. 0xA9, 0x9C, 0x3A, 0x0A, 0x9E, 0xDB, 0xF0, 0x0F,
  34651. 0x15, 0xA5, 0xEB, 0x1C, 0x50, 0xD4, 0x27, 0x36,
  34652. 0xDB, 0x07, 0x63, 0xBD, 0x56, 0xBD, 0xFA, 0x81,
  34653. 0x09, 0x9A, 0xDE, 0xCE, 0xE8, 0x4A, 0xEA, 0x06,
  34654. 0x9C, 0x06, 0x5B, 0x67, 0x03, 0x14, 0xB9, 0xE4,
  34655. 0x8C, 0x66, 0x75, 0xA3, 0xCC, 0x69, 0x39, 0x57,
  34656. 0xDA, 0x1D, 0x21, 0xBA, 0xCE, 0xD8, 0x70, 0x02,
  34657. 0xFF, 0xF5, 0x6F, 0x25, 0x3A, 0x3D, 0xFC, 0x79,
  34658. 0xA3, 0xF0, 0x3A, 0x3F, 0x2B, 0x10, 0x51, 0x9A,
  34659. 0xCB, 0xC9, 0x1A, 0xF5, 0xF1, 0x98, 0x5B, 0x5C,
  34660. 0x87, 0x96, 0x4E, 0xC8, 0x00, 0x8A, 0x3A, 0x6E,
  34661. 0x85, 0x02, 0xA5, 0xF1, 0x69, 0x32, 0x6E, 0xC1,
  34662. 0x95, 0x68, 0xCF, 0xA8, 0xE8, 0x85, 0x55, 0x4D,
  34663. 0x6A, 0x68, 0x1F, 0x00, 0xDD, 0x26, 0xB3, 0x24,
  34664. 0xF4, 0x9D, 0xD2, 0x4D, 0x81, 0x06, 0xDA, 0xE6,
  34665. 0x4D, 0x11, 0x73, 0xDF, 0xFE, 0x4F, 0xA6, 0x22,
  34666. 0x5E, 0x6C, 0x6D, 0x5E, 0xE3, 0x59, 0xCF, 0xF4,
  34667. 0x35, 0xA0, 0x80, 0x86, 0x89, 0x49, 0xB2, 0xED,
  34668. 0x0C, 0xC7, 0x3B, 0x42, 0x06, 0x68, 0x8D, 0x90,
  34669. 0x04, 0x1A, 0xBD, 0x51, 0xF6, 0xB9, 0x29, 0x2E,
  34670. 0xB6, 0xF0, 0x79, 0x40, 0x1E, 0x6E, 0x59, 0x94,
  34671. 0xFB, 0xF5, 0x6B, 0x72, 0x82, 0x4C, 0xB6, 0xC7,
  34672. 0x2B, 0x12, 0x71, 0x77, 0xDD, 0x89, 0xCC, 0x2F,
  34673. 0x98, 0xB0, 0x93, 0x1C, 0x98, 0xCE, 0x5E, 0x89,
  34674. 0x0D, 0x95, 0x7B, 0x98, 0xE1, 0xEA, 0xDC, 0xB7,
  34675. 0xFF, 0x22, 0xC5, 0x31, 0x40, 0x9E, 0x1C, 0x80,
  34676. 0x59, 0x47, 0x01, 0x49, 0xEC, 0x81, 0xEF, 0x16,
  34677. 0x32, 0x6B, 0xB0, 0x4E, 0xE2, 0x3B, 0xA3, 0xC1,
  34678. 0x03, 0x12, 0x0D, 0xA6, 0x65, 0xDE, 0x8D, 0xB0,
  34679. 0xA0, 0xBB, 0x75, 0xEF, 0x5C, 0xDA, 0xF4, 0xEE,
  34680. 0x47, 0x6E, 0x55, 0x02, 0x38, 0xCD, 0xC1, 0xAC,
  34681. 0xDD, 0x71, 0xA6, 0x34, 0xAB, 0xCE, 0xA5, 0x5C,
  34682. 0x90, 0xFF, 0xF8, 0xE0, 0xA7, 0x87, 0xBD, 0x21,
  34683. 0x36, 0x91, 0x4F, 0x23, 0xD8, 0x75, 0x58, 0xC5,
  34684. 0xF6, 0xBA, 0xAC, 0x54, 0x6C, 0x24, 0xB1, 0x41,
  34685. 0x02, 0x02, 0xB9, 0x44, 0x31, 0x0E, 0xC4, 0xC9,
  34686. 0xC6, 0x87, 0x85, 0x36, 0x05, 0xC8, 0xAE, 0xC9,
  34687. 0xF1, 0xEF, 0x6B, 0x67, 0x52, 0xD3, 0x9A, 0x15,
  34688. 0xBF, 0xA2, 0x47, 0xEF, 0x89, 0xFC, 0x06, 0x99,
  34689. 0xA1, 0x1A, 0xE4, 0x5A, 0x75, 0xE5, 0x09, 0xD4,
  34690. 0x54, 0xE9, 0x89, 0xF2, 0x60, 0x6E, 0xAB, 0x10,
  34691. 0xF8, 0x42, 0xE4, 0xAD, 0x57, 0xC6, 0xE3, 0x65,
  34692. 0x48, 0x94, 0x14, 0x05, 0x4F, 0x62, 0x20, 0x0F,
  34693. 0x3A, 0x1E, 0xC7, 0x62, 0xDC, 0x5C, 0x8E, 0xFA,
  34694. 0x19, 0x88, 0x47, 0x5D, 0xE8, 0xC3, 0xD5, 0x8C,
  34695. 0x2B, 0x71, 0xBA, 0x11, 0x98, 0x7C, 0x0A, 0xC6,
  34696. 0x42, 0x08, 0x3B, 0xAC, 0x76, 0xFB, 0x50, 0x78,
  34697. 0x8C, 0x26, 0x8F, 0xEE, 0x7B, 0xE2, 0x59, 0x9B,
  34698. 0x34, 0x58, 0x09, 0x2A, 0x8B, 0xCB, 0x1F, 0x31,
  34699. 0x94, 0x8F, 0xE4, 0x82, 0xDF, 0x9A, 0x54, 0x5B,
  34700. 0x63, 0x85, 0x94, 0xD6, 0x7A, 0x44, 0x06, 0x91,
  34701. 0x5C, 0xCD, 0xC7, 0x55, 0x57, 0x47, 0xC0, 0x4E,
  34702. 0x72, 0xA5, 0x48, 0xAB, 0x8F, 0xEE, 0x87, 0x6B,
  34703. 0x25, 0x82, 0x61, 0x3C, 0xCA, 0xBD, 0xA9, 0x6C,
  34704. 0xF1, 0x4A, 0xAA, 0xF6, 0x71, 0x6B, 0x79, 0x0B,
  34705. 0xFE, 0x4D, 0x92, 0x32, 0xD9, 0x03, 0x70, 0xD6,
  34706. 0x0B, 0xBC, 0x18, 0x4B, 0xA3, 0x3B, 0xCF, 0x77,
  34707. 0x83, 0x16, 0xE3, 0x4B, 0x11, 0x83, 0x8D, 0x8F,
  34708. 0x71, 0xFE, 0xEA, 0xC0, 0x42, 0xF0, 0x35, 0xB0,
  34709. 0x76, 0xEA, 0xC1, 0xC2, 0x62, 0xFA, 0x9C, 0x32,
  34710. 0xBC, 0x8D, 0x69, 0xB1, 0x38, 0xB3, 0x51, 0x31,
  34711. 0x8E, 0xD1, 0xF3, 0x44, 0x95, 0x95, 0x11, 0x52,
  34712. 0x36, 0xF4, 0xCA, 0x7C, 0xBA, 0x2B, 0xA9, 0xE1,
  34713. 0x03, 0xF0, 0xF5, 0x09, 0xAB, 0x91, 0x6E, 0x48,
  34714. 0xB8, 0xAF, 0x03, 0x9B, 0xDC, 0xD5, 0x1C, 0xAB,
  34715. 0xFA, 0xCA, 0xDC, 0xEE, 0x8E, 0x49, 0x84, 0xF5,
  34716. 0x61, 0xF9, 0x7D, 0x17, 0xCB, 0xF1, 0xDE, 0x9A,
  34717. 0x7A, 0x7B, 0xDA, 0xF3, 0x26, 0xE6, 0xD8, 0xAD,
  34718. 0x90, 0xE9, 0x5B, 0xAF, 0x15, 0x45, 0xD3, 0xE2,
  34719. 0x46, 0x69, 0xD1, 0xC5, 0xF4, 0x28, 0xE0, 0x7E,
  34720. 0x2C, 0x71, 0x10, 0xFF, 0x43, 0x59, 0x80, 0x93,
  34721. 0xE6, 0xF9, 0x28, 0xA0, 0x34, 0xC6, 0x86, 0xBA,
  34722. 0xE7, 0x5A, 0x56, 0x7A, 0xE4, 0xF5, 0x20, 0xB4,
  34723. 0x4D, 0xAC, 0xB4, 0x95, 0xE5, 0xB2, 0xC6, 0x43,
  34724. 0x9E, 0x2E, 0x67, 0x8E, 0x7C, 0x05, 0x4F, 0xF7,
  34725. 0x60, 0x14, 0x88, 0xC6, 0xAE, 0x4A, 0x05, 0x36,
  34726. 0x99, 0x73, 0x55, 0x10, 0xF9, 0xDB, 0xC3, 0x4C,
  34727. 0xD7, 0x6A, 0x19, 0x94, 0xC0, 0xFE, 0x74, 0x12,
  34728. 0xC0, 0xCE, 0x95, 0x15, 0xBF, 0x60, 0x3A, 0x8E,
  34729. 0xB5, 0xFC, 0x8A, 0xBC, 0xAC, 0x9F, 0x15, 0x10,
  34730. 0x44, 0x73, 0x58, 0x60, 0x5D, 0xA1, 0x33, 0xFD,
  34731. 0xDE, 0xBD, 0xF2, 0x22, 0x69, 0xEE, 0x1D, 0x46,
  34732. 0x8E, 0x2E, 0xE8, 0x21, 0x62, 0x1D, 0x27, 0x84,
  34733. 0xC4, 0x6D, 0xA8, 0x30, 0x02, 0xA6, 0x26, 0x94,
  34734. 0xFA, 0xB1, 0xEF, 0xEC, 0x3B, 0x8D, 0x6F, 0x1B,
  34735. 0x2C, 0xCE, 0x2A, 0x4E, 0xC4, 0x28, 0x35, 0x4E,
  34736. 0x39, 0xA4, 0xF4, 0x5C, 0x96, 0x65, 0xC1, 0xB8,
  34737. 0x55, 0xA5, 0x09, 0x15, 0xBC, 0x4D, 0x3B, 0xD0,
  34738. 0x1F, 0x7F, 0xBA, 0x90, 0x20, 0xCD, 0xBD, 0xC2,
  34739. 0xC8, 0xE5, 0xC6, 0xB0, 0x6F, 0x14, 0x4E, 0x6B,
  34740. 0xEA, 0x8A, 0x24, 0x44, 0xE1, 0x0A, 0xCD, 0xB2,
  34741. 0x05, 0xF3, 0x15, 0x71, 0x7C, 0x86, 0xFC, 0xF1,
  34742. 0xFD, 0x6B, 0xA6, 0xE3, 0xFC, 0x86, 0xE3, 0xBA,
  34743. 0x56, 0x6B, 0x8F, 0xBE, 0x02, 0x9A, 0x03, 0x0C,
  34744. 0x8C, 0x69, 0xE5, 0x7C, 0x15, 0xAE, 0x13, 0x12,
  34745. 0x25, 0x2B, 0x36, 0xFB, 0x51, 0xA1, 0x61, 0x5E,
  34746. 0x37, 0x46, 0x92, 0x0C, 0x0B, 0x71, 0x5C, 0x1D,
  34747. 0xA4, 0xDB, 0x04, 0xC1, 0x08, 0xED, 0x5C, 0x44,
  34748. 0x80, 0x70, 0xC1, 0x0E, 0x63, 0x6D, 0x92, 0xC2,
  34749. 0x1E, 0x18, 0x8E, 0x71, 0x0E, 0x7C, 0x10, 0x21,
  34750. 0x1E, 0xC2, 0xCF, 0xD6, 0x38, 0x7A, 0x9B, 0x5C,
  34751. 0x9E, 0xE8, 0x82, 0x3D, 0xDD, 0x40, 0x0C, 0x96,
  34752. 0x17, 0xEF, 0xB1, 0x25, 0xBA, 0x84, 0x45, 0x4F,
  34753. 0x64, 0xA6, 0x8E, 0x2B, 0xBA, 0xF1, 0xED, 0xB3,
  34754. 0x4F, 0x92, 0x5F, 0x1A, 0x73, 0x2A, 0x2A, 0x22,
  34755. 0x68, 0x19, 0x4C, 0x8A, 0x87, 0x51, 0x75, 0x78,
  34756. 0xCF, 0x3C, 0xC5, 0x97, 0xFD, 0x77, 0x43, 0xCB,
  34757. 0xAE, 0x3D, 0x9C, 0xB6, 0x45, 0x54, 0x45, 0xF4,
  34758. 0x1B, 0x92, 0xEE, 0xF4, 0x9D, 0xC4, 0x32, 0x10,
  34759. 0x6A, 0x48, 0xAB, 0xE9, 0x47, 0xBF, 0x2B, 0x92,
  34760. 0x49, 0x84, 0x23, 0x52, 0x05, 0xA1, 0x92, 0x3B,
  34761. 0xD7, 0x78, 0x2D, 0x9A, 0x15, 0xB4, 0xD9, 0xD3,
  34762. 0x45, 0xD0, 0x69, 0xF1, 0x38, 0x4D, 0x39, 0xEA,
  34763. 0x49, 0x7E, 0xC0, 0xE7, 0x7A, 0x07, 0x88, 0x1D,
  34764. 0x1F, 0xA3, 0xAC, 0xE9, 0xC3, 0xFD, 0x6B, 0x5D,
  34765. 0xF6, 0xB2, 0xB9, 0xAA, 0x9A, 0xBE, 0xF4, 0x06,
  34766. 0xD9, 0x5E, 0x81, 0xE5, 0x68, 0xDF, 0xEA, 0x20,
  34767. 0x4C, 0xEE, 0xED, 0x42, 0xA4, 0xD3, 0x7B, 0xA8,
  34768. 0x82, 0x98, 0x0D, 0xB4, 0xC8, 0xC3, 0x43, 0x28,
  34769. 0x13, 0xE9, 0x6B, 0x11, 0x0E, 0x54, 0xE6, 0xCD,
  34770. 0x11, 0x0A, 0x01, 0x36, 0x41, 0x78, 0xC5, 0x7D,
  34771. 0x00, 0xC6, 0x8D, 0xE7, 0x7B, 0x4C, 0xE6, 0x35,
  34772. 0x57, 0x8F, 0x56, 0xA9, 0x73, 0x5A, 0xEF, 0x93,
  34773. 0xF0, 0xD8, 0x16, 0xE3, 0x44, 0x8A, 0xA0, 0xA9,
  34774. 0xF1, 0x9C, 0x2E, 0x02, 0xD1, 0x3C, 0x66, 0xDD,
  34775. 0xE5, 0x35, 0xFE, 0x81, 0x77, 0x8D, 0xC2, 0x46,
  34776. 0x64, 0x03, 0x23, 0xCC, 0x37, 0x22, 0x60, 0x68,
  34777. 0xCC, 0x7F, 0x79, 0xE8, 0x6B, 0xD0, 0xEE, 0x1C,
  34778. 0x6A, 0xC3, 0x3C, 0xEB, 0x51, 0x95, 0xFA, 0xE4,
  34779. 0x28, 0x17, 0x94, 0x49, 0x22, 0x69, 0x64, 0x98,
  34780. 0x82, 0x8B, 0x68, 0x9F, 0x69, 0x35, 0xF9, 0xBF,
  34781. 0x33, 0x22, 0xA4, 0x32, 0x0F, 0x4C, 0x26, 0xE4,
  34782. 0x8D, 0xDF, 0xAE, 0xBD, 0xF4, 0x4D, 0x01, 0xAF,
  34783. 0xA1, 0xFA, 0x3E, 0xCE, 0xD3, 0xB0, 0x5D, 0x02,
  34784. 0xDB, 0x3B, 0xB4, 0x23, 0xB8, 0x55, 0x97, 0xB5,
  34785. 0x1F, 0x25, 0x64, 0xA7, 0x5D, 0x4A, 0x8C, 0x90,
  34786. 0xD4, 0xB6, 0x85, 0x20, 0x32, 0x09, 0x37, 0x26,
  34787. 0x00, 0xD5, 0x4D, 0x98, 0x5A, 0xCF, 0x29, 0x3B,
  34788. 0x0E, 0xAF, 0x69, 0x88, 0x78, 0x18, 0xAD, 0xD1,
  34789. 0xE1, 0xB7, 0xC5, 0xD7, 0xB7, 0x5F, 0xFE, 0xB5,
  34790. 0x64, 0xE0, 0x68, 0x0B, 0x4F, 0x46, 0x7B, 0xDE,
  34791. 0x0B, 0x11, 0x7A, 0x42, 0x10, 0x86, 0x09, 0x60,
  34792. 0xB5, 0xE0, 0x22, 0x17, 0x28, 0x68, 0x7A, 0xE9,
  34793. 0xEB, 0xBC, 0x6B, 0xD5, 0x95, 0x4C, 0xE0, 0xAE,
  34794. 0x57, 0xB1, 0x45, 0xFF, 0xC2, 0x7E, 0xB6, 0xA0,
  34795. 0xD3, 0x8E, 0x46, 0x16, 0xCE, 0xBE, 0x76, 0xCE,
  34796. 0x59, 0x5B, 0xA4, 0x96, 0x1E, 0x9F, 0x80, 0xF0,
  34797. 0x06, 0x7E, 0xCD, 0x6E, 0x27, 0xB8, 0x7D, 0x26,
  34798. 0xB6, 0x60, 0xA3, 0xAB, 0x52, 0xC1, 0x37, 0x9A,
  34799. 0xDD, 0x46, 0xF5, 0xB9, 0x39, 0x75, 0xAA, 0x19,
  34800. 0xF3, 0xE4, 0xA8, 0x95, 0x4B, 0x25, 0x3F, 0x0B,
  34801. 0x44, 0x13, 0xF5, 0x82, 0x10, 0x68, 0x03, 0xD5,
  34802. 0x0F, 0x99, 0xB5, 0xB2, 0x8B, 0x85, 0x77, 0x2E,
  34803. 0x78, 0x3E, 0xEE, 0x21, 0x6E, 0xAD, 0x2D, 0xCF,
  34804. 0x95, 0x62, 0x94, 0x1C, 0x50, 0xAB, 0xC5, 0xFA,
  34805. 0x8E, 0x24, 0xB6, 0x14, 0x86, 0x46, 0x8A, 0xAA,
  34806. 0x20, 0xDF, 0x15, 0xD1, 0x72, 0xF6, 0xAC, 0x03,
  34807. 0xAF, 0xDF, 0xCD, 0x53, 0x81, 0xBA, 0xDB, 0x07,
  34808. 0x8B, 0x8E, 0xBB, 0x70, 0x91, 0x57, 0x04, 0xB9,
  34809. 0x88, 0xE5, 0x8F, 0x45, 0xD3, 0xD6, 0x31, 0x12,
  34810. 0xA5, 0xC1, 0x28, 0xC6, 0x49, 0x90, 0x0F, 0x1D,
  34811. 0x69, 0x66, 0xE3, 0x98, 0x56, 0x7D, 0xE3, 0x48,
  34812. 0xAC, 0xC0, 0xDE, 0xE4, 0x2B, 0x88, 0x01, 0x19,
  34813. 0x4E, 0x99, 0xBB, 0x1A, 0xAF, 0x02, 0x5A, 0x91,
  34814. 0xE3, 0x2C, 0xE6, 0x56, 0x4D, 0x05, 0x10, 0xB9,
  34815. 0x10, 0xF2, 0x2A, 0x27, 0xDE, 0xCF, 0x9D, 0x2E
  34816. };
  34817. static const byte msg_44[] = {
  34818. 0xB1, 0x34, 0x49, 0x15, 0xCC, 0xD6, 0x93, 0x41,
  34819. 0x6B, 0x37, 0xFE, 0xBD, 0x8D, 0xC7, 0xC7, 0xDB,
  34820. 0x9F, 0x25, 0x3E, 0x9D, 0xF5, 0x3C, 0xEC, 0x51,
  34821. 0x49, 0x23, 0xAA, 0xA2, 0x67, 0x6F, 0xBF, 0xA4,
  34822. 0xCC, 0x04, 0xFC, 0x68, 0xF9, 0xE3, 0x2F, 0x9E,
  34823. 0x86, 0x4C, 0x68, 0x95, 0xDB, 0x37, 0xE9, 0xFF,
  34824. 0xEB, 0x80, 0xF0, 0xF6, 0xB8, 0x6C, 0xB6, 0xAD,
  34825. 0x9C, 0x42, 0xF8, 0xFC, 0x75, 0x19, 0x8D, 0xD3,
  34826. 0xCC, 0xDA, 0xF5, 0x77, 0xC7, 0xB3, 0x5B, 0x8F,
  34827. 0x1B, 0xF6, 0x0A, 0xAB, 0xEA, 0x89, 0x94, 0x42,
  34828. 0x20, 0x1F, 0xBB, 0xF4, 0x42, 0x8C, 0x7E, 0xC1,
  34829. 0x7B, 0xC3, 0x1B, 0x54, 0x72, 0x4B, 0x95, 0x90,
  34830. 0xF7, 0x53, 0x1E, 0x6F, 0x79, 0x0A, 0x1F, 0xA7,
  34831. 0x74, 0x32, 0x83, 0x37, 0x2D, 0x31, 0x71, 0xB8,
  34832. 0x96, 0x6B, 0x47, 0x0A, 0xAA, 0x85, 0x26, 0xEB,
  34833. 0x4A, 0x6E, 0x81, 0xE6, 0x5A, 0xD0, 0xC2, 0x9F,
  34834. 0x2D, 0x37, 0xDD, 0x5B, 0x41, 0x2B, 0xAE, 0x68,
  34835. 0x2A, 0x66, 0x79, 0x68, 0x77, 0xC8, 0x2F, 0xFD,
  34836. 0xA9, 0x76, 0x24, 0x34, 0xEA, 0xC2, 0xC7, 0xD4,
  34837. 0xAF, 0x60, 0x9B, 0x27, 0x72, 0x49, 0x0D, 0xEE,
  34838. 0x9B, 0xFB, 0x00, 0x5D, 0x2F, 0x1A, 0x2E, 0xBB,
  34839. 0xA0, 0x32, 0xCD, 0x71, 0x59, 0xD5, 0x4B, 0xE5,
  34840. 0x96, 0xF3, 0x30, 0x68, 0xBE, 0x5D, 0x9A, 0x2D,
  34841. 0x94, 0x0C, 0x76, 0x70, 0xE6, 0x4E, 0x9A, 0xF7,
  34842. 0xD7, 0xD3, 0x3E, 0xC3, 0xAE, 0xC6, 0xF1, 0xD9,
  34843. 0xDE, 0xE3, 0x92, 0x84, 0xF0, 0x5C, 0xE0, 0x25,
  34844. 0xD1, 0x81, 0x76, 0x0D, 0x40, 0xE5, 0xC2, 0xD9,
  34845. 0xBE, 0xAE, 0x24, 0x20, 0xF4, 0x0D, 0x9F, 0x32,
  34846. 0xB7, 0xBD, 0xCD, 0x3A, 0xFB, 0x1C, 0x66, 0x0D,
  34847. 0x01, 0x71, 0x4D, 0x81, 0x37, 0x58, 0xDB, 0xB8,
  34848. 0x2C, 0x6B, 0x7E, 0x85, 0x80, 0x52, 0xB5, 0xA5,
  34849. 0x0E, 0x39, 0xE0, 0x15, 0xD3, 0xF2, 0x4A, 0x2C,
  34850. 0x64, 0xC9, 0xDD, 0xCC, 0x15, 0x0D, 0x90, 0x4F,
  34851. 0x07, 0xF6, 0x5F, 0xF6, 0x8A, 0xD0, 0x12, 0x9E,
  34852. 0xC3, 0xF8, 0x12, 0x3F, 0x3A, 0x03, 0xFC, 0x95,
  34853. 0x8A, 0xE2, 0x47, 0x8C, 0x6C, 0x6E, 0x03, 0x61,
  34854. 0x67, 0xD8, 0x51, 0x49, 0xF7, 0x9F, 0xB0, 0x3F,
  34855. 0xAA, 0xB9, 0x89, 0x7C, 0xE7, 0x3F, 0x88, 0x55,
  34856. 0xC5, 0x4C, 0x83, 0xD7, 0x53, 0xB1, 0x04, 0xB5,
  34857. 0x13, 0xD5, 0x6B, 0xC6, 0x4C, 0x3B, 0x08, 0x91,
  34858. 0x73, 0x47, 0x35, 0x13, 0x26, 0xD8, 0xEB, 0x47,
  34859. 0xCF, 0x66, 0xF1, 0x3F, 0xB9, 0x0F, 0x6A, 0xF5,
  34860. 0xA8, 0x94, 0xC7, 0x75, 0x00, 0x77, 0xA8, 0x9C,
  34861. 0xEB, 0x77, 0x22, 0xE2, 0xE6, 0x80, 0xA5, 0x9B,
  34862. 0xF8, 0x43, 0x8C, 0x52, 0x35, 0x31, 0xEA, 0x8C,
  34863. 0xC2, 0x83, 0x4F, 0xFC, 0x4E, 0xF0, 0x2D, 0x35,
  34864. 0xB8, 0x51, 0x46, 0xF2, 0xD6, 0x01, 0xD5, 0x00,
  34865. 0x99, 0x6A, 0x44, 0x10, 0x64, 0xAD, 0xCA, 0x1F,
  34866. 0x62, 0x3F, 0x2F, 0xE7, 0x45, 0x22, 0x47, 0xEF,
  34867. 0x86, 0x9D, 0x76, 0xD5, 0x78, 0x42, 0x07, 0x30,
  34868. 0x88, 0x86, 0x90, 0xB1, 0xA0, 0x08, 0xDA, 0x28,
  34869. 0x2A, 0xD1, 0x75, 0x7D, 0x21, 0x71, 0x29, 0x38,
  34870. 0x59, 0xC7, 0x3F, 0x55, 0x20, 0xB5, 0xBB, 0x48,
  34871. 0x03, 0xE7, 0xFA, 0xB0, 0x29, 0x00, 0xD2, 0x0F,
  34872. 0xE7, 0x65, 0x81, 0x8E, 0xE6, 0x24, 0xE7, 0xA1,
  34873. 0x94, 0x50, 0x9D, 0x01, 0x6B, 0x4B, 0xD7, 0x81,
  34874. 0x4E, 0xA0, 0xD5, 0x4A, 0x51, 0xEE, 0x95, 0x0A,
  34875. 0x14, 0x76, 0xD5, 0x87, 0xAA, 0x6F, 0x78, 0xC8,
  34876. 0xD2, 0xE0, 0xC8, 0xF8, 0xF2, 0x78, 0xD8, 0x2E,
  34877. 0x11, 0x90, 0x44, 0xB6, 0xBF, 0xD0, 0xBE, 0xD8,
  34878. 0x6F, 0xA4, 0x20, 0xA2, 0xC8, 0xA4, 0xEF, 0xB0,
  34879. 0x5D, 0x73, 0x06, 0xBE, 0x52, 0xF9, 0x32, 0xD8,
  34880. 0x06, 0x5D, 0xD1, 0x29, 0x23, 0x46, 0x25, 0x6E,
  34881. 0x42, 0x9D, 0xEE, 0x41, 0x9E, 0xF3, 0x7D, 0x1B,
  34882. 0x35, 0x28, 0x81, 0xDC, 0x47, 0x7F, 0x25, 0xA4,
  34883. 0x0A, 0xEB, 0x3E, 0x17, 0xE6, 0x1B, 0xCC, 0x00,
  34884. 0xD2, 0xE2, 0xA9, 0x3D, 0xEC, 0xF3, 0x00, 0xF0,
  34885. 0x81, 0x68, 0x21, 0xED, 0x49, 0xF9, 0x9B, 0x9B,
  34886. 0x8B, 0xED, 0xD9, 0x1E, 0xFA, 0x04, 0xBB, 0xB0,
  34887. 0x9A, 0xBD, 0x1D, 0x24, 0x36, 0xA7, 0xD6, 0x64,
  34888. 0x8A, 0x38, 0x3A, 0x3A, 0x8F, 0x09, 0x08, 0x0E,
  34889. 0x46, 0x7B, 0xE1, 0x03, 0x30, 0xBF, 0x62, 0x27,
  34890. 0x10, 0x74, 0xBE, 0xBD, 0x7F, 0x56, 0x39, 0x0D,
  34891. 0x1D, 0x39, 0x47, 0xF4, 0x02, 0x47, 0x6B, 0x62,
  34892. 0x6B, 0x52, 0xAC, 0xAB, 0x21, 0xAC, 0x10, 0x4A,
  34893. 0xAB, 0x59, 0x75, 0x33, 0x11, 0xD9, 0xE9, 0xE2,
  34894. 0xB2, 0x20, 0x6B, 0xA1, 0x09, 0x42, 0xB6, 0x37,
  34895. 0xE4, 0x5C, 0xE6, 0x9F, 0x54, 0xB4, 0x67, 0xBC,
  34896. 0xAE, 0xF3, 0xDC, 0x1A, 0xA2, 0x15, 0x47, 0x7B,
  34897. 0x15, 0xC8, 0x00, 0x35, 0x8E, 0x1D, 0x69, 0x04,
  34898. 0xD8, 0x9C, 0xA9, 0x6A, 0x03, 0x1A, 0x55, 0x48,
  34899. 0x6C, 0x4F, 0xC1, 0x68, 0x27, 0x26, 0x13, 0xAB,
  34900. 0x8E, 0x03, 0x50, 0x7B, 0xDD, 0xC2, 0x7E, 0x5C,
  34901. 0x8A, 0x6F, 0xBB, 0x5F, 0x8B, 0x22, 0x86, 0xA5,
  34902. 0xC5, 0x0E, 0xC5, 0x68, 0x60, 0xF6, 0xBF, 0xFF,
  34903. 0x6E, 0xBA, 0xDC, 0x21, 0x71, 0xD2, 0xEB, 0xD1,
  34904. 0x27, 0x8C, 0x58, 0x14, 0xC3, 0x2E, 0x13, 0x9E,
  34905. 0x04, 0x09, 0x61, 0xC3, 0x19, 0xC3, 0x03, 0x48,
  34906. 0x70, 0x33, 0x3B, 0x12, 0xF7, 0x3B, 0x38, 0xE7,
  34907. 0x18, 0x14, 0xA9, 0xF1, 0x60, 0x83, 0x65, 0xEB,
  34908. 0x32, 0xD5, 0x23, 0x8F, 0x6B, 0xF7, 0xD8, 0x00,
  34909. 0x21, 0xBD, 0xA3, 0x98, 0xDE, 0xD7, 0x13, 0x17,
  34910. 0xAB, 0x3C, 0xA4, 0xD7, 0xBE, 0x1D, 0xA7, 0x4A,
  34911. 0x1B, 0xC4, 0x0C, 0x9B, 0x2E, 0x34, 0x5B, 0xA7,
  34912. 0xA2, 0x3F, 0x9B, 0x2D, 0xDB, 0xAF, 0x85, 0x14,
  34913. 0x0A, 0xF9, 0x30, 0x9E, 0x86, 0x53, 0xAC, 0x24,
  34914. 0xAF, 0xD8, 0x25, 0xBC, 0x2A, 0x07, 0x2B, 0xCD,
  34915. 0x02, 0xFE, 0x3E, 0xF0, 0x0B, 0xE3, 0xF9, 0x51,
  34916. 0x5C, 0x29, 0xEB, 0x8A, 0xFB, 0xC3, 0xEF, 0xD1,
  34917. 0xF9, 0xCF, 0xDF, 0xE9, 0xEB, 0xA9, 0x49, 0x59,
  34918. 0xB5, 0x17, 0x7E, 0x28, 0x86, 0xB8, 0xD1, 0x8D,
  34919. 0xCA, 0x97, 0xF0, 0xCB, 0x80, 0x7E, 0xE3, 0xEA,
  34920. 0xE3, 0x1B, 0x48, 0xCF, 0xAC, 0x61, 0x3C, 0x2E,
  34921. 0x00, 0xAB, 0x74, 0xFB, 0x95, 0xF6, 0x64, 0xF3,
  34922. 0xCA, 0xBF, 0x6E, 0xEF, 0xCD, 0xDD, 0x6D, 0xA5,
  34923. 0xF8, 0x98, 0xEC, 0x38, 0xF2, 0xF0, 0x7D, 0x6D,
  34924. 0xCB, 0x75, 0xE0, 0x50, 0x9D, 0x13, 0x19, 0x24,
  34925. 0x07, 0x4C, 0x05, 0xF4, 0x5D, 0xCA, 0x25, 0xB7,
  34926. 0xCF, 0xE2, 0xBC, 0xFE, 0xEC, 0xAF, 0x5F, 0xC3,
  34927. 0x6C, 0xE6, 0xE3, 0xC5, 0x85, 0x43, 0x7B, 0x06,
  34928. 0x9F, 0xD2, 0xC6, 0xBB, 0xAD, 0x33, 0xD6, 0x86,
  34929. 0xBD, 0x5B, 0x9E, 0x2C, 0xA0, 0xD9, 0x8B, 0xDC,
  34930. 0x5E, 0x71, 0x7B, 0x6D, 0xF7, 0x1D, 0x40, 0x91,
  34931. 0x30, 0x8E, 0x84, 0x73, 0x9A, 0xD6, 0x7F, 0xA6,
  34932. 0x79, 0xA6, 0xCE, 0xE9, 0xA6, 0x83, 0x28, 0x4B,
  34933. 0x4F, 0xB3, 0x1B, 0x2C, 0x40, 0x8F, 0x52, 0xF0,
  34934. 0x59, 0x7D, 0x9C, 0x04, 0xEA, 0xF4, 0xAC, 0x6D,
  34935. 0xBB, 0x6C, 0x3F, 0xD6, 0x7F, 0x25, 0x39, 0xD8,
  34936. 0x87, 0xDF, 0xBC, 0xF3, 0xCA, 0xE4, 0x59, 0xFA,
  34937. 0x76, 0x66, 0x61, 0xA4, 0x8B, 0xFC, 0xFD, 0x6F,
  34938. 0x64, 0x03, 0x99, 0xD3, 0xAF, 0x07, 0x86, 0x35,
  34939. 0x99, 0x98, 0xCE, 0xFF, 0x7E, 0x9E, 0xB1, 0xB0,
  34940. 0x57, 0xA6, 0x29, 0x3D, 0xFF, 0xB7, 0xF3, 0xF2,
  34941. 0x51, 0x4B, 0x0B, 0x70, 0x29, 0x46, 0x06, 0x8A,
  34942. 0x6B, 0xBD, 0x75, 0x30, 0xD6, 0x91, 0x7F, 0xB1,
  34943. 0x1D, 0xBB, 0xAA, 0xBE, 0xD7, 0xAA, 0x46, 0x81,
  34944. 0xD7, 0x8A, 0xEA, 0x91, 0x86, 0x69, 0x2D, 0xDA,
  34945. 0x34, 0x70, 0x65, 0x2E, 0xB8, 0xA3, 0xF1, 0x44,
  34946. 0x56, 0xA5, 0xAA, 0xC4, 0x20, 0x88, 0x3B, 0x42,
  34947. 0x37, 0xB0, 0xA7, 0x2D, 0x91, 0x27, 0x63, 0xB6,
  34948. 0x7A, 0xC4, 0x13, 0x1A, 0x8A, 0x5D, 0x2F, 0x16,
  34949. 0x82, 0x96, 0xB9, 0x12, 0xD3, 0xB6, 0x61, 0xC4,
  34950. 0xE8, 0x3C, 0xE6, 0x3A, 0x61, 0xC0, 0x45, 0xEB,
  34951. 0xA5, 0x75, 0xEE, 0xB6, 0x7F, 0xB0, 0x70, 0xED,
  34952. 0x82, 0x39, 0xE5, 0x1A, 0x67, 0xD9, 0x80, 0x3C,
  34953. 0xE0, 0x0B, 0x85, 0x66, 0x74, 0xE0, 0xB7, 0x26,
  34954. 0x66, 0x26, 0xDD, 0x02, 0x15, 0xE5, 0xEF, 0x5F,
  34955. 0xDE, 0x7B, 0xF4, 0x0B, 0x99, 0x10, 0x21, 0x08,
  34956. 0xFC, 0x2D, 0xF2, 0x8B, 0xDC, 0xC8, 0xEA, 0xC6,
  34957. 0x3E, 0xFB, 0x20, 0x50, 0x1F, 0x24, 0x66, 0x99,
  34958. 0x80, 0x88, 0xC7, 0xA0, 0xB9, 0x6D, 0x1B, 0x75,
  34959. 0xC4, 0xC2, 0xE2, 0x52, 0xA0, 0xBF, 0x38, 0x01,
  34960. 0x5C, 0xA5, 0x8A, 0xDA, 0x79, 0x38, 0xAE, 0x2E,
  34961. 0xC7, 0x96, 0x6F, 0x30, 0x5B, 0xB4, 0x21, 0xC0,
  34962. 0xCD, 0x95, 0xCA, 0xD2, 0x12, 0x7D, 0xAD, 0x87,
  34963. 0x08, 0x6C, 0xC3, 0x8B, 0xF6, 0xB1, 0x5D, 0xAD,
  34964. 0x2C, 0x7C, 0x04, 0x41, 0xE5, 0x34, 0x2E, 0x4B,
  34965. 0x5A, 0xD9, 0x1E, 0x66, 0xF4, 0x23, 0xE2, 0x88,
  34966. 0x4D, 0xD9, 0x03, 0xFE, 0x6C, 0x64, 0x7D, 0x61,
  34967. 0xE6, 0x70, 0x0E, 0xA8, 0x83, 0x08, 0x07, 0xE6,
  34968. 0xFD, 0x64, 0x54, 0x3E, 0x3C, 0x6E, 0x9A, 0xD1,
  34969. 0x93, 0x37, 0x36, 0x90, 0xDE, 0x94, 0xF7, 0x16,
  34970. 0x15, 0x47, 0x94, 0xFE, 0x97, 0x5B, 0x11, 0x80,
  34971. 0xBA, 0x40, 0xAF, 0x7F, 0x05, 0xC1, 0x82, 0x91,
  34972. 0x69, 0xFD, 0xFB, 0xEC, 0x3A, 0xF7, 0xCF, 0xE1,
  34973. 0xD7, 0x9B, 0x59, 0x7E, 0xE4, 0x38, 0xA2, 0x96,
  34974. 0xEF, 0x14, 0x6A, 0x05, 0x99, 0x71, 0xE3, 0xF9,
  34975. 0x50, 0x8E, 0x35, 0x0B, 0x50, 0x71, 0x6D, 0xEC,
  34976. 0xB5, 0x1B, 0xC8, 0x80, 0x2A, 0xE6, 0x2A, 0x7F,
  34977. 0x4C, 0x2E, 0x6F, 0x7B, 0x54, 0x62, 0x0E, 0xF0,
  34978. 0x4C, 0x00, 0xF0, 0x72, 0xAE, 0x37, 0xAC, 0x32,
  34979. 0x7E, 0x26, 0xD3, 0x65, 0x76, 0x1C, 0x10, 0x46,
  34980. 0x17, 0xAE, 0xE0, 0xF3, 0x28, 0xEE, 0x97, 0xE0,
  34981. 0x86, 0x18, 0x3D, 0x46, 0xA3, 0x62, 0x1F, 0x23,
  34982. 0xF3, 0xAC, 0x27, 0x60, 0xB8, 0x85, 0x9A, 0x96,
  34983. 0x0E, 0xF1, 0x6F, 0xC1, 0xC6, 0xB1, 0x97, 0x8A,
  34984. 0x74, 0x12, 0xDD, 0x73, 0x85, 0x02, 0x9C, 0x73,
  34985. 0x61, 0xA8, 0xF7, 0x49, 0xCE, 0xBA, 0x23, 0xED,
  34986. 0xE7, 0x9A, 0x17, 0x0E, 0xA6, 0x84, 0x59, 0xF5,
  34987. 0x21, 0x66, 0xF5, 0xC5, 0x61, 0xF8, 0x88, 0x7E,
  34988. 0x62, 0x0C, 0x00, 0xC6, 0x4F, 0x06, 0xBD, 0x0A,
  34989. 0xBB, 0xCD, 0xE5, 0x11, 0x7A, 0xBC, 0xFD, 0x03,
  34990. 0xB6, 0xD1, 0xBA, 0x4F, 0x30, 0xFA, 0x96, 0x75,
  34991. 0xD8, 0x2D, 0x7A, 0x43, 0x0D, 0x58, 0x41, 0x46,
  34992. 0xBA, 0x72, 0x06, 0xCB, 0xBD, 0xD9, 0xBE, 0xA1,
  34993. 0xEA, 0x47, 0x08, 0x3D, 0xF9, 0x32, 0x23, 0x9C,
  34994. 0xAA, 0x02, 0x1D, 0xA3, 0x3E, 0x43, 0xF1, 0x68,
  34995. 0xD8, 0xBE, 0x9F, 0x0E, 0xA8, 0xA8, 0x52, 0xC4,
  34996. 0x0A, 0xDE, 0x43, 0x9D, 0x58, 0xA8, 0x05, 0xD4,
  34997. 0x74, 0xF8, 0x93, 0x21, 0x62, 0x6E, 0x33, 0x78,
  34998. 0x3C, 0x23, 0xEB, 0x60, 0x1C, 0x4C, 0x25, 0xFE,
  34999. 0x0F, 0x5E, 0x73, 0xC3, 0xAD, 0x33, 0x9A, 0x7D,
  35000. 0x69, 0x6B, 0xAB, 0x2C, 0xAA, 0x5F, 0xBF, 0x96,
  35001. 0x62, 0x3A, 0xF0, 0x63, 0x41, 0x00, 0xC7, 0x4C,
  35002. 0x81, 0x4D, 0x42, 0x43, 0x25, 0xBC, 0x30, 0xB6,
  35003. 0x0B, 0xEE, 0xFC, 0x18, 0x3E, 0x68, 0x0E, 0x64,
  35004. 0x5C, 0xD4, 0x22, 0x2A, 0xBA, 0xB5, 0xC6, 0x7E,
  35005. 0x67, 0x11, 0x1C, 0x4C, 0x03, 0x30, 0xEC, 0x0C,
  35006. 0x77, 0xB2, 0x2B, 0xBC, 0x98, 0xF7, 0x52, 0x8C,
  35007. 0x95, 0x66, 0xE1, 0x71, 0xDD, 0x26, 0xA7, 0x7F,
  35008. 0x87, 0xF3, 0x94, 0x2E, 0x0D, 0x3E, 0xFE, 0xAD,
  35009. 0x0A, 0xDA, 0x3B, 0x77, 0x49, 0xC5, 0x1D, 0xED,
  35010. 0x5F, 0xDA, 0x3F, 0xE6, 0xE7, 0x96, 0x58, 0xF1,
  35011. 0x02, 0x30, 0x68, 0xB9, 0x62, 0xD0, 0x58, 0xA2,
  35012. 0x89, 0x65, 0x12, 0x20, 0x1E, 0x4C, 0xE7, 0xB6,
  35013. 0x98, 0x12, 0x52, 0xF0, 0xE8, 0x55, 0xBC, 0xFE,
  35014. 0x1F, 0x44, 0x42, 0x36, 0xC9, 0x30, 0xE4, 0x9A,
  35015. 0x13, 0xB3, 0x7A, 0xF4, 0xF5, 0x97, 0xC0, 0x5D,
  35016. 0xCA, 0x23, 0xCC, 0x05, 0xC4, 0x3C, 0x32, 0xA2,
  35017. 0x11, 0x08, 0x17, 0xCB, 0x30, 0x6B, 0xA4, 0x7D,
  35018. 0x24, 0x5E, 0x50, 0x22, 0x2E, 0x23, 0xC6, 0x55,
  35019. 0x6B, 0xD7, 0x5D, 0x50, 0xEE, 0xF8, 0xBE, 0xB0,
  35020. 0xDE, 0x83, 0x5C, 0x8D, 0xD2, 0xE1, 0x5C, 0x70,
  35021. 0x66, 0x70, 0x59, 0x8F, 0x86, 0x50, 0x71, 0x71,
  35022. 0x04, 0x69, 0xEC, 0xB3, 0x47, 0x9E, 0xE0, 0x26,
  35023. 0xB1, 0x9F, 0xE6, 0x21, 0xAC, 0x99, 0x12, 0x6B,
  35024. 0x97, 0x9E, 0x1B, 0xA1, 0xDD, 0xA8, 0xE6, 0x11,
  35025. 0x12, 0x97, 0xC1, 0x0E, 0x4A, 0x77, 0xF5, 0x52,
  35026. 0xF8, 0x09, 0xE9, 0x01, 0x63, 0x56, 0x4E, 0xFA,
  35027. 0x24, 0x39, 0x36, 0xB9, 0xF2, 0x6E, 0x07, 0x28,
  35028. 0x7F, 0xA4, 0x07, 0x7C, 0xA2, 0x69, 0x7B, 0xED,
  35029. 0x6A, 0x4F, 0x0A, 0x95, 0x99, 0x05, 0x60, 0xE7,
  35030. 0x58, 0xD9, 0x90, 0xB4, 0xC1, 0x92, 0x0F, 0x9E,
  35031. 0x1A, 0xBE, 0x0B, 0x58, 0x96, 0x50, 0x61, 0x1C,
  35032. 0x2D, 0x5A, 0x13, 0xAA, 0x5F, 0x4E, 0x2B, 0x88,
  35033. 0xBE, 0xAB, 0x93, 0x72, 0xF4, 0x68, 0xB8, 0x30,
  35034. 0x91, 0xCD, 0x0A, 0x53, 0x8A, 0x35, 0x82, 0x93,
  35035. 0x4F, 0x66, 0xCA, 0xCD, 0xF2, 0x39, 0x98, 0xFE,
  35036. 0xC2, 0xFE, 0xFE, 0x51, 0x35, 0xF1, 0xB5, 0x62,
  35037. 0x2D, 0x1A, 0xE9, 0x43, 0x25, 0x5E, 0x05, 0xE4,
  35038. 0x8B, 0xFE, 0x91, 0x2F, 0x4F, 0x24, 0x1B, 0x2B,
  35039. 0xAC, 0x49, 0x9C, 0x14, 0xB0, 0x58, 0xA3, 0xA8,
  35040. 0xEE, 0xB9, 0xD1, 0xFA, 0x4D, 0x44, 0x2E, 0x23,
  35041. 0xFC, 0x59, 0x77, 0xA5, 0x60, 0x2E, 0xDC, 0xEB,
  35042. 0x7B, 0x7B, 0x26, 0x95, 0xE1, 0x87, 0xB7, 0x94,
  35043. 0xF8, 0x4B, 0x96, 0x63, 0x15, 0xB1, 0xBB, 0xA5,
  35044. 0xC0, 0x4A, 0x72, 0x02, 0x4A, 0x80, 0x5F, 0xB1,
  35045. 0x94, 0x73, 0xB7, 0x06, 0xB8, 0x13, 0x76, 0x42,
  35046. 0xAD, 0xB1, 0xC6, 0x6C, 0xFD, 0x64, 0xF2, 0x60,
  35047. 0xBB, 0x1B, 0x7A, 0xAD, 0xF6, 0xC2, 0x96, 0xB3,
  35048. 0x5F, 0x30, 0xB9, 0xD7, 0x70, 0x8A, 0x9D, 0x41,
  35049. 0xE7, 0x23, 0xFA, 0xD4, 0xE8, 0x72, 0xAF, 0x73,
  35050. 0xF8, 0x8C, 0x26, 0xAB, 0x65, 0x1B, 0xD5, 0x7A,
  35051. 0x21, 0xE2, 0x8C, 0xE8, 0xC2, 0x47, 0xD5, 0x8E,
  35052. 0x47, 0x9F, 0x79, 0x68, 0x87, 0x6F, 0xCE, 0xD3,
  35053. 0x5D, 0x2B, 0x87, 0xD2, 0xDF, 0x14, 0x43, 0x47,
  35054. 0x03, 0x3D, 0xF4, 0xCB, 0x50, 0xDE, 0x52, 0xD8,
  35055. 0x98, 0x41, 0x46, 0x3F, 0x5D, 0xFB, 0x6D, 0x6F,
  35056. 0xF6, 0xD9, 0xE8, 0x2B, 0xBA, 0xB3, 0xB1, 0xEC,
  35057. 0x58, 0x77, 0x8A, 0xB8, 0xF3, 0x6D, 0xBC, 0x68,
  35058. 0x22, 0xEA, 0xE3, 0x2F, 0xB6, 0xCB, 0x67, 0x30,
  35059. 0xCB, 0x33, 0x1C, 0x39, 0x5C, 0x27, 0x4A, 0xE7,
  35060. 0xE3, 0x7B, 0x40, 0x9B, 0x7C, 0x66, 0x32, 0xE7,
  35061. 0x6D, 0xAA, 0x97, 0xB8, 0x0F, 0x1E, 0x0C, 0xB4,
  35062. 0x7A, 0xA3, 0x66, 0xA8, 0xE3, 0x50, 0xEA, 0x36,
  35063. 0x74, 0x65, 0x92, 0xEC, 0x9B, 0x1E, 0x97, 0xF0,
  35064. 0x2F, 0x99, 0xD6, 0x00, 0x21, 0x37, 0x0B, 0x89,
  35065. 0x93, 0xC6, 0x80, 0xA1, 0x02, 0xDC, 0x96, 0x5D,
  35066. 0x20, 0xB7, 0x57, 0xF4, 0x17, 0x7A, 0x81, 0xBA,
  35067. 0x7B, 0x61, 0xD2, 0x88, 0xEF, 0xC5, 0xAD, 0xED,
  35068. 0x4C, 0x9A, 0x94, 0xA5, 0x7B, 0x2C, 0x6B, 0xD2,
  35069. 0x97, 0x7E, 0x23, 0x64, 0x0A, 0x66, 0x98, 0x47,
  35070. 0xEE, 0x81, 0xB1, 0x49, 0x0B, 0xE3, 0x8A, 0xC4,
  35071. 0x3E, 0x52, 0x2C, 0x8D, 0x09, 0xA2, 0x07, 0xB6,
  35072. 0x2A, 0x8B, 0x07, 0x9A, 0x24, 0x84, 0xDE, 0xD1,
  35073. 0x00, 0x63, 0xD7, 0xA1, 0x3F, 0xBF, 0x0C, 0xA8,
  35074. 0xEE, 0xDC, 0x2B, 0xF6, 0x7B, 0xD8, 0x78, 0x53,
  35075. 0x35, 0xB8, 0x29, 0x5A, 0xFE, 0x6B, 0x35, 0x6E,
  35076. 0x20, 0x62, 0x24, 0x17, 0x0E, 0x87, 0x23, 0x1A,
  35077. 0x77, 0x2D, 0x21, 0x84, 0x37, 0xBF, 0x7D, 0x68,
  35078. 0xAC, 0x2A, 0xF9, 0x3F, 0x11, 0x27, 0x18, 0x4F,
  35079. 0xA2, 0x15, 0x21, 0x47, 0x9E, 0x56, 0xFF, 0x22,
  35080. 0xE8, 0x0F, 0x61, 0xBC, 0x28, 0xB8, 0xD2, 0xE7,
  35081. 0x1B, 0x3D, 0x1D, 0x94, 0x28, 0x1B, 0x69, 0x56,
  35082. 0x00, 0xC8, 0xB0, 0xFD, 0x8E, 0x1D, 0x7E, 0x81,
  35083. 0x1F, 0x4C, 0xCF, 0xE1, 0x6E, 0x3F, 0x57, 0x95,
  35084. 0xC2, 0x4A, 0xA0, 0xA0, 0x16, 0x7E, 0x30, 0x5C,
  35085. 0x28, 0x87, 0x5C, 0x8F, 0xA9, 0x38, 0x9B, 0x72,
  35086. 0xF7, 0x90, 0x86, 0xF6, 0xEC, 0xC1, 0x6C, 0x88,
  35087. 0xB0, 0x78, 0x3A, 0x58, 0x15, 0xFB, 0x6F, 0x77,
  35088. 0xCD, 0xC7, 0xCC, 0xC3, 0x8D, 0x60, 0xE7, 0x87,
  35089. 0xBE, 0x9C, 0xBF, 0xFA, 0xA6, 0x2E, 0xF9, 0x59,
  35090. 0xA5, 0xE5, 0xDC, 0xDE, 0xB6, 0x25, 0x5C, 0x8E,
  35091. 0x0D, 0x2E, 0x01, 0xFE, 0x05, 0xEF, 0xF9, 0xE7,
  35092. 0x81, 0x02, 0xBE, 0xA2, 0x91, 0x40, 0x57, 0xD3,
  35093. 0x6E, 0x3D, 0x1B, 0x48, 0x50, 0x7A, 0xB6, 0xB1,
  35094. 0x76, 0x40, 0x47, 0x0F, 0xE3, 0xF1, 0x7A, 0x8B,
  35095. 0x6A, 0x5E, 0x04, 0xE5, 0x34, 0x56, 0xC5, 0xD9,
  35096. 0xE5, 0x0F, 0x74, 0x5D, 0xE0, 0x6F, 0x9A, 0xED,
  35097. 0xF4, 0xBF, 0xCF, 0x31, 0xB0, 0xC6, 0xED, 0x12,
  35098. 0x13, 0x36, 0x54, 0xCB, 0xC8, 0xDE, 0xF7, 0xF6,
  35099. 0x60, 0x9E, 0x12, 0x2C, 0x2E, 0x4C, 0x93, 0x3E,
  35100. 0x6F, 0xCB, 0x0F, 0x3D, 0x8C, 0xCA, 0xE8, 0xCA,
  35101. 0x0B, 0x10, 0xED, 0xDA, 0xE8, 0xDB, 0x29, 0x7C,
  35102. 0x8B, 0x32, 0x31, 0xC8, 0x94, 0x34, 0xA5, 0xF5,
  35103. 0x4D, 0x01, 0x28, 0xC8, 0x3A, 0xA6, 0xFD, 0xE2,
  35104. 0x9A, 0xB7, 0x0C, 0xDA, 0x43, 0x78, 0x45, 0x45,
  35105. 0xFE, 0xE9, 0xFF, 0x6E, 0xD4, 0x44, 0xF8, 0x88,
  35106. 0x66, 0x4D, 0xD2, 0x2B, 0x2E, 0x2D, 0xF5, 0x7C,
  35107. 0xA6, 0x53, 0xB6, 0xD2, 0x10, 0xE6, 0xB4, 0x0B,
  35108. 0x7F, 0xC2, 0x1F, 0xE0, 0x63, 0x90, 0xCA, 0x5D,
  35109. 0x5E, 0x60, 0xF5, 0x8A, 0xB1, 0x4C, 0x49, 0x03,
  35110. 0xD4, 0x38, 0xAE, 0xEF, 0xB1, 0x7C, 0xA4, 0xB9,
  35111. 0x98, 0x70, 0x6A, 0x0E, 0xD6, 0xA4, 0xA6, 0xF4,
  35112. 0x74, 0xB1, 0xBA, 0x1D, 0x48, 0xCC, 0xC1, 0x14,
  35113. 0x3C, 0x84, 0xA8, 0xD2, 0xE7, 0x8D, 0xEC, 0x11,
  35114. 0x61, 0x8C, 0x76, 0xB6, 0xDA, 0x28, 0xBC, 0x39,
  35115. 0xDF, 0x68, 0xAD, 0x24, 0xA4, 0x07, 0xE1, 0x07,
  35116. 0x33, 0xDD, 0x18, 0x9D, 0x5D, 0xAA, 0x90, 0x4B,
  35117. 0xEF, 0x88, 0x18, 0x6E, 0xB6, 0x83, 0x21, 0x45,
  35118. 0x94, 0x0F, 0x15, 0xB8, 0xAC, 0xD9, 0xD1, 0x8D,
  35119. 0x4F, 0x17, 0xC8, 0xD9, 0x17, 0xB0, 0x9D, 0x54,
  35120. 0xF2, 0x5F, 0x56, 0x09, 0xD3, 0x80, 0x20, 0x77,
  35121. 0x44, 0x23, 0x90, 0xAB, 0xB6, 0x0B, 0x51, 0xA7,
  35122. 0x41, 0xC5, 0xD4, 0x42, 0x5B, 0xD4, 0x67, 0x89,
  35123. 0xE6, 0xEC, 0x1E, 0x7D, 0x22, 0xD5, 0x6E, 0x7F,
  35124. 0x34, 0xCE, 0x7A, 0x07, 0x2B, 0x63, 0x0A, 0x69,
  35125. 0x51, 0x71, 0x8C, 0x13, 0x63, 0xB8, 0x79, 0x6D,
  35126. 0x94, 0xEA, 0xAF, 0x86, 0x30, 0xD2, 0x22, 0x6C,
  35127. 0x67, 0x82, 0x6C, 0xDE, 0xEA, 0x71, 0xE8, 0xD1,
  35128. 0x36, 0xF3, 0x64, 0x2F, 0x79, 0xE6, 0x92, 0xF0,
  35129. 0x4B, 0x05, 0x14, 0x7E, 0x40, 0xCE, 0x0C, 0x53,
  35130. 0xCA, 0x08, 0xEF, 0x0A, 0xA6, 0xA5, 0x73, 0x99,
  35131. 0xFD, 0xF3, 0xED, 0xBD, 0x54, 0x56, 0x6E, 0x66,
  35132. 0xEF, 0xCC, 0xE1, 0x6F, 0x0C, 0x44, 0x76, 0x84,
  35133. 0xF5, 0x55, 0x2B, 0xA3, 0x6B, 0x20, 0x60, 0x54,
  35134. 0x3F, 0xC1, 0x35, 0x58, 0xD8, 0xD8, 0x9E, 0x18,
  35135. 0x63, 0x70, 0x73, 0xEF, 0x6A, 0x87, 0x46, 0x77,
  35136. 0xA9, 0x7F, 0x9F, 0xA0, 0x23, 0x4B, 0x14, 0x00,
  35137. 0x61, 0xC7, 0xE3, 0x44, 0xBE, 0xD6, 0x09, 0x71,
  35138. 0xE3, 0x58, 0x44, 0x9A, 0xCD, 0x17, 0xE5, 0x8E,
  35139. 0x6D, 0x05, 0xBB, 0x21, 0x44, 0xD7, 0x4B, 0xD8,
  35140. 0x9A, 0xE9, 0x7A, 0x75, 0x91, 0x43, 0xAD, 0x84,
  35141. 0x5B, 0x02, 0x70, 0xBE, 0x67, 0x0B, 0x1E, 0x1E,
  35142. 0x92, 0xB8, 0xC7, 0xB6, 0x5F, 0xE1, 0x60, 0x23,
  35143. 0xF5, 0x30, 0xE4, 0xD0, 0xCF, 0x70, 0x03, 0xD1,
  35144. 0x85, 0x4A, 0x50, 0xDC, 0xF4, 0x9C, 0x29, 0xAB,
  35145. 0x0E, 0xA4, 0x7B, 0x2E, 0x3B, 0xDB, 0xBF, 0x52,
  35146. 0xD5, 0x8A, 0x91, 0x47, 0xA9, 0xD1, 0x23, 0xEB,
  35147. 0xC5, 0x6F, 0x11, 0xBB, 0xEE, 0xBB, 0x29, 0xD7,
  35148. 0x31, 0xAB, 0x99, 0x27, 0x5E, 0xF3, 0xA9, 0x23,
  35149. 0xFF, 0x70, 0x87, 0x83, 0xCC, 0x26, 0x92, 0x06,
  35150. 0xEC, 0xD3, 0x8C, 0xF9, 0x47, 0x34, 0x7D, 0x1E,
  35151. 0x71, 0xAF, 0xCF, 0x9D, 0xBF, 0x29, 0x1B, 0x95,
  35152. 0x27, 0x48, 0x55, 0xCE, 0xE2, 0xAC, 0x25, 0x61,
  35153. 0x83, 0xD9, 0x7B, 0x26, 0xEF, 0x94, 0x9A, 0x95,
  35154. 0x0C, 0xD1, 0xE4, 0x0A, 0x51, 0x50, 0x1F, 0x86,
  35155. 0x7A, 0x7B, 0xD3, 0x83, 0x55, 0x2D, 0xFC, 0x7B,
  35156. 0x97, 0x77, 0x17, 0x67, 0xBB, 0x9F, 0xD7, 0xD1,
  35157. 0xDD, 0xDD, 0x49, 0x67, 0xBB, 0xF7, 0x9A, 0x45,
  35158. 0x33, 0x24, 0xCA, 0xBC, 0xA5, 0xB2, 0x0D, 0x3F,
  35159. 0xB0, 0x10, 0x6D, 0xB9, 0x7D, 0x03, 0x3F, 0xCD,
  35160. 0x40, 0x37, 0x1E, 0x8A, 0xDA, 0xCD, 0xBA, 0xD7,
  35161. 0x8D, 0x89, 0xBD, 0x5E, 0x90, 0xCF, 0x97, 0xE8,
  35162. 0x35, 0x51, 0x87, 0x94, 0xFA, 0x3D, 0xB2, 0xB5,
  35163. 0x01, 0xF2, 0x35, 0x75, 0x77, 0x65, 0x5B, 0x9A,
  35164. 0x3C, 0xDA, 0x36, 0x52, 0xDF, 0xCF, 0x96, 0xBA,
  35165. 0xB9, 0xC5, 0xF9, 0x57, 0x67, 0x0E, 0x32, 0xE5,
  35166. 0x86, 0xE5, 0x1F, 0xD8, 0x9D, 0x7B, 0xA8, 0x76,
  35167. 0x89, 0xFD, 0x59, 0x70, 0x88, 0x73, 0x9D, 0x87,
  35168. 0xE1, 0x24, 0x6D, 0xC2, 0xB5, 0x1E, 0xCD, 0x54,
  35169. 0x29, 0x25, 0x10, 0xA3, 0xB4, 0x3C, 0xB2, 0x5A,
  35170. 0x62, 0xBD, 0xE9, 0x14, 0xEC, 0x3C, 0xBF, 0xA9,
  35171. 0x9D, 0xEC, 0x70, 0xAC, 0x23, 0xC0, 0xDF, 0xC9,
  35172. 0x69, 0xAD, 0x94, 0x1A, 0x69, 0x94, 0xA3, 0x70,
  35173. 0xF9, 0x0B, 0x15, 0x5D, 0x25, 0x45, 0x63, 0xFA,
  35174. 0xAA, 0x7D, 0x30, 0x67, 0x3C, 0x06, 0x34, 0x75,
  35175. 0x3F, 0xD6, 0x57, 0x58, 0x8E, 0xC6, 0x60, 0x3F,
  35176. 0x82, 0x35, 0xE9, 0x17, 0x36, 0x5D, 0xD8, 0x93,
  35177. 0x25, 0x25, 0x1B, 0x21, 0xB2, 0xFF, 0x80, 0xF5,
  35178. 0x44, 0xFE, 0x73, 0x84, 0xFF, 0x62, 0xFE, 0x52,
  35179. 0xC4, 0xCA, 0x77, 0x41, 0x28, 0xC8, 0x95, 0x15,
  35180. 0x2C, 0xC7, 0x5C, 0xA6, 0x3B, 0xA8, 0xF8, 0x1E,
  35181. 0x01, 0x30, 0xC9, 0x3B, 0x59, 0xF9, 0x40, 0xB7,
  35182. 0x18, 0x80, 0x21, 0x24, 0xDB, 0x8D, 0x07, 0xDF,
  35183. 0xDC, 0x24, 0xBF, 0x2F, 0x7B, 0xD9, 0xC4, 0xEF,
  35184. 0x61, 0x74, 0x1A, 0xF2, 0xB6, 0x98, 0x75, 0x66,
  35185. 0x22, 0x4F, 0x11, 0x06, 0x41, 0xDB, 0x77, 0x83,
  35186. 0xFA, 0xF3, 0x1B, 0xEC, 0xB8, 0xF7, 0x89, 0x47,
  35187. 0xBA, 0x12, 0x3F, 0xB0, 0x0E, 0x1B, 0x6D, 0x13,
  35188. 0x36, 0x0B, 0x16, 0xD0, 0x7C, 0x3A, 0xAA, 0x33,
  35189. 0x6D, 0xDA, 0x1B, 0x65, 0xD4, 0xC2, 0xF2, 0x1B,
  35190. 0xD5, 0xCD, 0x4B, 0xE9, 0xED, 0xFA, 0xFA, 0x78,
  35191. 0x45, 0x97, 0x2D, 0x60, 0xCC, 0xE3, 0x40, 0x3E,
  35192. 0xB5, 0xE5, 0xC8, 0x33, 0xF6, 0x4C, 0x51, 0x45,
  35193. 0xDC, 0x08, 0xE7, 0xB3, 0x6F, 0xCF, 0xDE, 0xE8,
  35194. 0x73, 0x0B, 0x94, 0x4F, 0x5A, 0x23, 0xF9, 0xFF,
  35195. 0x3F, 0x0D, 0x1D, 0xCE, 0x80, 0x86, 0x3B, 0x55,
  35196. 0x8D, 0x8A, 0x35, 0xB2, 0xAA, 0x65, 0x27, 0x69,
  35197. 0x1D, 0xA5, 0x0C, 0xE6, 0xFA, 0x39, 0x85, 0x62,
  35198. 0x65, 0xAD, 0xE6, 0x08, 0x38, 0xCE, 0xC9, 0xEA,
  35199. 0x98, 0x73, 0x99, 0x1D, 0xB5, 0x6F, 0xEA, 0xE8,
  35200. 0xEE, 0xE2, 0xEC, 0xF4, 0x32, 0x44, 0x96, 0x5A,
  35201. 0x13, 0xCC, 0x1D, 0x23, 0x0E, 0x91, 0x72, 0xD8,
  35202. 0x2A, 0xD2, 0x3D, 0x6A, 0x6E, 0x2A, 0x37, 0x7A,
  35203. 0x7F, 0x67, 0xF6, 0x40, 0xBF, 0x3A, 0x36, 0x3B,
  35204. 0xC8, 0x1A, 0x78, 0x6D, 0x12, 0xB0, 0x35, 0xA3,
  35205. 0x18, 0x55, 0x33, 0x70, 0x48, 0x48, 0x52, 0x8F,
  35206. 0xB4, 0x59, 0x58, 0xEB, 0xAA, 0xB3, 0x03, 0x67,
  35207. 0x4F, 0xFF, 0xA5, 0x68, 0xE7, 0xAE, 0xAF, 0x46,
  35208. 0x3D, 0x66, 0x6B, 0x60, 0x21, 0x26, 0x31, 0x83,
  35209. 0xBE, 0xE8, 0x1E, 0x72, 0x92, 0x87, 0x79, 0x24,
  35210. 0xCF, 0xDE, 0xEF, 0x6F, 0x81, 0x73, 0xA1, 0x34,
  35211. 0x7B, 0x99, 0x94, 0x43, 0x33, 0xF4, 0x8B, 0x36,
  35212. 0xC8, 0xC5, 0xF8, 0xC1, 0x6D, 0x22, 0x6D, 0xA3,
  35213. 0xC9, 0xDA, 0x5F, 0x4C, 0xE7, 0x7F, 0x00, 0xE4,
  35214. 0x42, 0xD8, 0x5C, 0x73, 0xE5, 0x78, 0x0C, 0x36,
  35215. 0x28, 0xD9, 0x83, 0x8F, 0xCA, 0xFA, 0x5D, 0x1D,
  35216. 0x34, 0x05, 0xF1, 0x93, 0x6C, 0xBC, 0xFD, 0x2C,
  35217. 0x52, 0xD4, 0xE8, 0x8D, 0xA9, 0xC9, 0x0D, 0xFF,
  35218. 0x28, 0x5E, 0x3E, 0x91, 0x12, 0xC0, 0x3C, 0xBA,
  35219. 0x58, 0x64, 0x7E, 0x6B, 0x4E, 0xC0, 0x77, 0xB1,
  35220. 0x67, 0x08, 0x16, 0xF5, 0x7E, 0x29, 0x42, 0x81,
  35221. 0x6A, 0x6F, 0x34, 0x21, 0x32, 0x64, 0x9A, 0xA6,
  35222. 0x44, 0xD1, 0x4F, 0x41, 0xAB, 0xC5, 0x26, 0x4A,
  35223. 0xFA, 0x70, 0xBC, 0xAE, 0x3D, 0x67, 0x9B, 0x86,
  35224. 0xF5, 0x1A, 0xF2, 0x44, 0x70, 0x52, 0xD0, 0x78,
  35225. 0xA0, 0xEA, 0x56, 0x39, 0x0B, 0x37, 0x2A, 0x15,
  35226. 0x13, 0xBC, 0xD2, 0xEA, 0x46, 0x6D, 0xCB, 0x5A,
  35227. 0x4D, 0x86, 0x47, 0x4F, 0xA1, 0xE2, 0x6B, 0xC0,
  35228. 0xA8, 0x3F, 0x58, 0x5C, 0x79, 0xAD, 0x62, 0x17,
  35229. 0xBC, 0x96, 0xAF, 0x77, 0x1F, 0x74, 0xD1, 0x42,
  35230. 0xBF, 0x5E, 0x91, 0xA9, 0x28, 0x44, 0xC5, 0x4E,
  35231. 0x76, 0x6B, 0xF2, 0xD3, 0x69, 0x8C, 0x0E, 0x4F,
  35232. 0x61, 0x76, 0xAD, 0xDC, 0x79, 0xE9, 0x74, 0xA4,
  35233. 0x66, 0xFB, 0x2E, 0x0C, 0xBB, 0x42, 0xC5, 0x3F,
  35234. 0x59, 0xB0, 0xDC, 0xB0, 0x32, 0xCD, 0x37, 0x56,
  35235. 0x1B, 0xD2, 0x46, 0xED, 0x52, 0xC8, 0x12, 0xEA,
  35236. 0xA3, 0x6B, 0xB9, 0xE5, 0xB3, 0x2A, 0xF3, 0x9B,
  35237. 0x0F, 0xC3, 0x77, 0x5F, 0x9A, 0xE1, 0x20, 0xBC,
  35238. 0x59, 0x44, 0x9B, 0x7B, 0x77, 0xB1, 0xBA, 0x1A,
  35239. 0x5B, 0x60, 0x06, 0x6C, 0x85, 0x83, 0x68, 0xDD,
  35240. 0x5A, 0xC8, 0xEE, 0xDC, 0xFE, 0x1F, 0x83, 0xF5,
  35241. 0x2C, 0x53, 0x62, 0xED, 0xE8, 0x93, 0xB7, 0x22,
  35242. 0x3E, 0xCB, 0x70, 0xBA, 0xA6, 0x6D, 0xB2, 0x91,
  35243. 0x47, 0xB8, 0x04, 0x37, 0x20, 0x1F, 0xEF, 0x71,
  35244. 0xB0, 0x5F, 0xF2, 0x51, 0x03, 0x5F, 0x88, 0xCA,
  35245. 0xFF, 0x42, 0xE8, 0x2A, 0x43, 0x02, 0xD3, 0x60,
  35246. 0x98, 0x26, 0x8B, 0x74, 0xF4, 0x18, 0x3D, 0x4D,
  35247. 0x19, 0xF1, 0x3B, 0x87, 0xE9, 0x83, 0x37, 0x15,
  35248. 0x7D, 0xA5, 0xEF, 0xBB, 0xF3, 0x4F, 0x48, 0xCA,
  35249. 0x40, 0x65, 0xD3, 0xE3, 0xBA, 0xCC, 0x83, 0x83,
  35250. 0x3F, 0xEE, 0xBA, 0x57, 0x34, 0x6D, 0x16, 0x9F,
  35251. 0x1B, 0xE6, 0xA0, 0x4C, 0x29, 0xC8, 0x2F, 0xD2,
  35252. 0x25, 0xA3, 0xF7, 0xC6, 0x85, 0x12, 0x4F, 0x53,
  35253. 0x7E, 0xC0, 0xE1, 0x0A, 0xB8, 0x58, 0x34, 0xBA,
  35254. 0x3E, 0x65, 0x4F, 0x19, 0x55, 0x5C, 0xB9, 0x74,
  35255. 0x6B, 0x74, 0xCE, 0x43, 0xA2, 0xC7, 0x8B, 0x21,
  35256. 0x70, 0x8C, 0x3B, 0xEF, 0x87, 0xC1, 0xE8, 0x8F,
  35257. 0x08, 0x10, 0xB4, 0xED, 0xE1, 0x81, 0x14, 0xE9,
  35258. 0x2A, 0x43, 0x13, 0xB4, 0xEA, 0xA0, 0x5F, 0x60,
  35259. 0x93, 0x7E, 0x87, 0x6D, 0xA2, 0x57, 0x63, 0x32,
  35260. 0xAE, 0xC3, 0x8C, 0xCD, 0x42, 0x5E, 0xFD, 0x51,
  35261. 0x1A, 0x39, 0xB9, 0xB4, 0xBD, 0x4C, 0xF3, 0xF2,
  35262. 0xE2, 0x70, 0x9A, 0x05, 0xF9, 0x39, 0xE5, 0xFC,
  35263. 0x59, 0x7D, 0x4E, 0x85, 0x12, 0x02, 0xC9, 0xC2,
  35264. 0xC5, 0x71, 0x3A, 0xD5, 0x73, 0xF7, 0x5A, 0xC5,
  35265. 0x49, 0x0D, 0xEE, 0xCF, 0x9D, 0xB8, 0xDE, 0xE2,
  35266. 0x03, 0x99, 0x70, 0x6B, 0x19, 0x29, 0xA4, 0xE8,
  35267. 0x99, 0x00, 0xC4, 0x9C, 0x24, 0x46, 0x5E, 0x08,
  35268. 0x09, 0x56, 0x6D, 0x9C, 0x2E, 0xF7, 0x8C, 0x52,
  35269. 0xDB, 0xB4, 0x2F, 0x9E, 0x22, 0x7E, 0xFD, 0x1E,
  35270. 0x1A, 0x72, 0xCB, 0x71, 0x0B, 0xD2, 0x19, 0x33,
  35271. 0x0E, 0x69, 0xCC, 0x00, 0x49, 0x36, 0x79, 0x78,
  35272. 0xAB, 0x11, 0x4D, 0x9A, 0xD7, 0xF9, 0x55, 0xCF,
  35273. 0x0B, 0x7B, 0x3D, 0x32, 0x5C, 0xB3, 0x51, 0x65,
  35274. 0x00, 0x0E, 0xD2, 0x9D, 0xBE, 0x0A, 0x19, 0x56,
  35275. 0xF1, 0x45, 0x95, 0x83, 0xC6, 0x97, 0xCD, 0x19,
  35276. 0xE7, 0x8B, 0x51, 0x74, 0xE4, 0xFD, 0x2C, 0xEC,
  35277. 0x10, 0x8A, 0x7C, 0x24, 0x28, 0x0A, 0x78, 0xA3,
  35278. 0xEC, 0x93, 0x97, 0x16, 0x4F, 0x60, 0x03, 0xFD,
  35279. 0x85, 0x31, 0x98, 0x04, 0xE5, 0x65, 0x5A, 0x87,
  35280. 0x9F, 0x66, 0x3D, 0xD4, 0x56, 0x3E, 0xF9, 0x98,
  35281. 0x25, 0x21, 0xFE, 0xC2, 0x07, 0x9E, 0x88, 0x89,
  35282. 0x49, 0x7B, 0xE9, 0x20, 0x1F, 0x6D, 0x7F, 0x24,
  35283. 0x60, 0xA8, 0xB2, 0xDD, 0x96, 0x51, 0x0E, 0x0E,
  35284. 0x4C, 0x83, 0xC3, 0xB1, 0x93, 0xC1, 0x1F, 0xD6,
  35285. 0xB4, 0xB6, 0x84, 0xCE, 0x85, 0x63, 0xA5, 0x38,
  35286. 0x0F, 0x2E, 0x55, 0xF4, 0x74, 0xA6, 0x0B, 0x63,
  35287. 0x17, 0xD0, 0x96, 0x76, 0x15, 0xAD, 0x4F, 0xA9,
  35288. 0xF0, 0x83, 0x25, 0xAD, 0xD7, 0x97, 0xB7, 0x9E,
  35289. 0x6F, 0x5D, 0xC7, 0x2A, 0xD1, 0x97, 0xF5, 0xF6,
  35290. 0x1E, 0xC8, 0x8B, 0xE5, 0xFB, 0xFF, 0x92, 0x72,
  35291. 0x31, 0x9A, 0x49, 0x4B, 0x60, 0x8F, 0x34, 0x7C,
  35292. 0xE1, 0x55, 0x66, 0x7A, 0x59, 0xC3, 0x00, 0x9A,
  35293. 0x14, 0x50, 0xF3, 0x06, 0x19, 0x3C, 0xFE, 0x61,
  35294. 0x1C, 0xF7, 0x05, 0x49, 0x2A, 0x30, 0xFF, 0x56,
  35295. 0xFE, 0x7F, 0x71, 0xD7, 0x32, 0xCC, 0xEF, 0x63,
  35296. 0x64, 0xE1, 0x66, 0xCF, 0xF8, 0x12, 0xED, 0x23,
  35297. 0x11, 0xB5, 0x16, 0xFA, 0x56, 0x90, 0xF2, 0xA2,
  35298. 0x72, 0x7B, 0x18, 0x50, 0xF2, 0x98, 0x5D, 0x48,
  35299. 0x25, 0x5E, 0x8C, 0x47, 0xE7, 0x11, 0x50, 0x2A,
  35300. 0x4B, 0x4A, 0x97, 0x0B, 0xDF, 0x70, 0xDC, 0x34,
  35301. 0x47, 0xF8, 0xE2, 0x88, 0x78, 0x24, 0xB5, 0x8A,
  35302. 0xC7, 0x58, 0xE8, 0x83, 0xF7, 0x3B, 0xAD, 0xFC,
  35303. 0xED, 0x46, 0x40, 0xD5, 0x46, 0x35, 0x1B, 0xF3,
  35304. 0x3E, 0x8F, 0x1E, 0x0B, 0x1B, 0xB9, 0xFB, 0x5A,
  35305. 0xFF, 0x0F, 0x8B, 0xA0, 0x95, 0x4A, 0x8E, 0x65,
  35306. 0x33, 0xD3, 0x7C, 0x03, 0x04, 0x8E, 0xBA, 0x6A,
  35307. 0x55, 0xB3, 0xC5, 0xDA, 0xCB, 0xDC, 0x44, 0xD3,
  35308. 0x98, 0x77, 0xD3, 0x07, 0x8A, 0xE9, 0x5E, 0x44,
  35309. 0x5B, 0xED, 0x12, 0xB1, 0xA5, 0x03, 0xAF, 0xB2,
  35310. 0x20, 0x0C, 0xB1, 0x8B, 0x08, 0xB4, 0x6A, 0x11,
  35311. 0x96, 0xA9, 0xF5, 0x7A, 0xFD, 0x56, 0x48, 0x11,
  35312. 0xC0, 0x30, 0xA4, 0x45, 0xFC, 0xAE, 0x72, 0xE5,
  35313. 0x5E, 0x85, 0xB7, 0x6F, 0xA0, 0x50, 0x13, 0x4B,
  35314. 0x2E, 0xC2, 0x31, 0x13, 0xED, 0x04, 0x04, 0x3D,
  35315. 0xBC, 0xD0, 0xB6, 0xFC, 0xCE, 0xBD, 0xC9, 0x13,
  35316. 0x5C, 0xB2, 0x02, 0xB8, 0x4F, 0xDD, 0x74, 0x51,
  35317. 0x1F, 0x9E, 0x8F, 0x0C, 0xF2, 0x26, 0xE1, 0x4C,
  35318. 0xA5, 0xC4, 0x38, 0xC7, 0x6A, 0xA5, 0xC3, 0xC2,
  35319. 0xE9, 0xF3, 0x22, 0x71, 0x00, 0x91, 0x83, 0xEE,
  35320. 0x92, 0xA9, 0x95, 0x81, 0x9D, 0xB9, 0x0F, 0x66,
  35321. 0x89, 0x9B, 0xB9, 0xB0, 0xC7, 0xED, 0x31, 0xDF,
  35322. 0x41, 0xB6, 0x8E, 0x52, 0xAC, 0x5B, 0xBD, 0xF2,
  35323. 0x33, 0x9F, 0x71, 0x5E, 0x43, 0xFE, 0xED, 0xD9,
  35324. 0x4F, 0x57, 0xF9, 0x23, 0x05, 0x23, 0x03, 0x34,
  35325. 0x17, 0xE4, 0x22, 0x27, 0x97, 0xF7, 0x62, 0x5B,
  35326. 0x52, 0x66, 0x70, 0xEE, 0x6B, 0xD3, 0x46, 0x8C,
  35327. 0xCD, 0x9B, 0xA4, 0xA1, 0xED, 0x26, 0x4A, 0xAC,
  35328. 0xC2, 0x50, 0xA8, 0x2A, 0x48, 0x83, 0x46, 0xB2,
  35329. 0xA5, 0xF9, 0x26, 0xF2, 0xE7, 0x8A, 0x8E, 0xD8,
  35330. 0x40, 0x5F, 0x85, 0x8E, 0xAB, 0xB0, 0x29, 0xF7,
  35331. 0x81, 0x42, 0xA7, 0x4B, 0xD5, 0xA8, 0x2D, 0x3D,
  35332. 0xD7, 0x0A, 0xB1, 0x26, 0xCF, 0xA3, 0xBA, 0xD7,
  35333. 0xF5, 0x1B, 0x9E, 0x95, 0xCB, 0xC8, 0xCE, 0x75,
  35334. 0xE7, 0x7A, 0x4A, 0x1B, 0x63, 0x21, 0xB7, 0x74,
  35335. 0x77, 0x78, 0xCD, 0x03, 0x5B, 0x3B, 0xCD, 0x44,
  35336. 0x8E, 0xF1, 0xBB, 0xB6, 0xFF, 0x75, 0x52, 0x8A,
  35337. 0x7A, 0xE9, 0xAF, 0x62, 0x24, 0xA1, 0x6F, 0x4F,
  35338. 0x45, 0x03, 0x87, 0xA3, 0xED, 0xBC, 0x2E, 0x92,
  35339. 0xC0, 0xB1, 0x9C, 0x22, 0x2E, 0x35, 0xC1, 0xA5,
  35340. 0x7E, 0xC3, 0x36, 0x3B, 0x18, 0x14, 0x78, 0x6E,
  35341. 0x1D, 0x37, 0xD7, 0x92, 0xB3, 0x78, 0x26, 0x13,
  35342. 0x9A, 0xFB, 0x38, 0x1D, 0xE0, 0x4C, 0x07, 0xC4,
  35343. 0x2C, 0xD3, 0xCA, 0x78, 0xE4, 0x70, 0xC2, 0x52,
  35344. 0x7C, 0x63, 0xDB, 0x4B, 0xB4, 0x0A, 0x4B, 0x7D,
  35345. 0x20, 0x67, 0xF0, 0xF4, 0x80, 0x5B, 0x65, 0x8B,
  35346. 0x29, 0x80, 0x92, 0xF0, 0x87, 0x3D, 0x09, 0x5A,
  35347. 0x0E, 0xEA, 0x45, 0x63, 0x92, 0x99, 0xD6, 0x0D,
  35348. 0x2B, 0x58, 0xEE, 0x19, 0x03, 0x4F, 0x94, 0x2D,
  35349. 0xEC, 0xBF, 0x5A, 0xE9, 0xA6, 0x16, 0xAF, 0x72,
  35350. 0x37, 0x5C, 0x12, 0xBB, 0x7D, 0xED, 0xAA, 0x6A,
  35351. 0x7D, 0xDF, 0x9A, 0x48, 0x37, 0x37, 0x3D, 0x7B,
  35352. 0x51, 0x96, 0x0B, 0x30, 0xCE, 0x9C, 0xE7, 0x3B,
  35353. 0x3C, 0x10, 0xDE, 0x32, 0xA7, 0x86, 0x39, 0xA9,
  35354. 0x33, 0x7D, 0x9B, 0xCF, 0x15, 0x27, 0xA4, 0x36,
  35355. 0x88, 0xBD, 0xB6, 0xEB, 0x8B, 0xD0, 0x3D, 0xCA,
  35356. 0xF1, 0x02, 0x70, 0xDF, 0xC0, 0xE2, 0xF0, 0xD2,
  35357. 0x2C, 0x27, 0xE3, 0x22, 0x24, 0x33, 0x27, 0x34,
  35358. 0xCA, 0x26, 0x19, 0x74, 0x02, 0x2F, 0x7E, 0xC1,
  35359. 0x76, 0xCB, 0x12, 0xBE, 0x6F, 0x13, 0x62, 0x1F,
  35360. 0x32, 0x03, 0x65, 0xCF, 0xBB, 0x03, 0xD0, 0x4C,
  35361. 0xF2, 0x9E, 0xFE, 0x93, 0xE9, 0x1B, 0x02, 0x9B,
  35362. 0x7B, 0x26, 0xFF, 0xEE, 0xF0, 0x6F, 0xCE, 0x57,
  35363. 0xD1, 0x2B, 0xE3, 0x90, 0x2E, 0xE2, 0x71, 0x2A,
  35364. 0xBA, 0xCC, 0x3D, 0x27, 0xCE, 0xA3, 0x5A, 0xCA,
  35365. 0x15, 0x09, 0xE4, 0xD0, 0x86, 0x4F, 0xEC, 0x5A,
  35366. 0x5B, 0x41, 0xA0, 0xE0, 0x3E, 0x1D, 0xEC, 0x6F,
  35367. 0x2A, 0x33, 0x72, 0x15, 0xCD, 0xE5, 0x55, 0xD6,
  35368. 0x6F, 0x84, 0xE3, 0xD6, 0x75, 0x5D, 0xDC, 0x1C,
  35369. 0x07, 0x3D, 0x0C, 0xDC, 0xDE, 0xF8, 0x8A, 0x44,
  35370. 0x40, 0xB1, 0x76, 0x84, 0xB8, 0xE0, 0xAF, 0x9D,
  35371. 0xA2, 0xB2, 0x84, 0xAA, 0xBF, 0x61, 0x08, 0x21,
  35372. 0xE5, 0xC2, 0xC9, 0x11, 0x94, 0x2D, 0x0B, 0xD1,
  35373. 0xC6, 0x59, 0xC1, 0xEE, 0xBA, 0x8E, 0x21, 0xAF,
  35374. 0xDE, 0x32, 0x77, 0xD5, 0x07, 0x3B, 0x98, 0x39,
  35375. 0x95, 0x77, 0x03, 0x80, 0x2F, 0xA2, 0x76, 0xC8,
  35376. 0x2C, 0xC6, 0x6A, 0x00, 0xA8, 0x69, 0x77, 0xB8,
  35377. 0x87, 0x7D, 0xC0, 0x51, 0x19, 0x45, 0x14, 0xA6,
  35378. 0x33, 0xB3, 0x4D, 0x36, 0x29, 0x34, 0xE8, 0x50,
  35379. 0xC2, 0x71, 0x7A, 0x0B, 0xE5, 0x92, 0x4E, 0x86,
  35380. 0xAA, 0xDA, 0x33, 0xCF, 0x34, 0x54, 0x63, 0x2C,
  35381. 0x68, 0xA1, 0x0A, 0xEF, 0x8B, 0x5B, 0xAA, 0x10,
  35382. 0x83, 0xE9, 0x13, 0x7D, 0x29, 0x20, 0xA2, 0x5F,
  35383. 0x96, 0x9F, 0x54, 0x0B, 0x95, 0xDF, 0x59, 0x91,
  35384. 0x6C, 0x4C, 0xAC, 0xC4, 0x55, 0x98, 0x8F, 0x46,
  35385. 0x31, 0x77, 0x56, 0xCC, 0x93, 0x7E, 0xF0, 0x17,
  35386. 0x7C, 0x0F, 0xEB, 0x3F, 0x23, 0xBB, 0xD3, 0x56,
  35387. 0x9E, 0x89, 0x67, 0xC4, 0x9B, 0x95, 0xA3, 0xBF,
  35388. 0x6D, 0x9D, 0x6D, 0x7C, 0x72, 0x27, 0x20, 0x6E,
  35389. 0x28, 0x37, 0x39, 0xFC, 0x77, 0x41, 0xE9, 0xFE,
  35390. 0x64, 0xEF, 0xA0, 0x38, 0x9F, 0xC7, 0x2F, 0xDA,
  35391. 0xC8, 0x1F, 0xEB, 0x75, 0x07, 0xB8, 0x7E, 0x6B,
  35392. 0x73, 0xCE, 0x0E, 0x7C, 0x7C, 0x54, 0x06, 0x1D,
  35393. 0x48, 0x8A, 0x06, 0x53, 0x95, 0x9B, 0x75, 0x8A,
  35394. 0xFF, 0x6F, 0x7D, 0x19, 0x00, 0x17, 0x8D, 0x7C,
  35395. 0x1A, 0xEA, 0xD0, 0x79, 0x45, 0x68, 0xF9, 0x2F,
  35396. 0x8A, 0xCE, 0x98, 0xED, 0xCC, 0xE8, 0x6D, 0xE1,
  35397. 0x08, 0xA0, 0x50, 0x2C, 0x43, 0x49, 0xC4, 0x99,
  35398. 0x98, 0x31, 0xDE, 0x00, 0xE8, 0x08, 0x39, 0x0B,
  35399. 0xBB, 0xDB, 0x65, 0xEA, 0x36, 0x0F, 0xBE, 0x98,
  35400. 0xB7, 0x4A, 0x9C, 0x59, 0x34, 0x0E, 0xBB, 0xDD,
  35401. 0x6F, 0x65, 0x21, 0x39, 0x23, 0x48, 0x57, 0x7F,
  35402. 0xD4, 0x07, 0x89, 0x03, 0x01, 0xB0, 0x79, 0x27,
  35403. 0x28, 0xCC, 0xFB, 0x88, 0xC5, 0xDD, 0x47, 0x2A,
  35404. 0xDA, 0x73, 0x75, 0x9B, 0xC9, 0x99, 0xA0, 0x21,
  35405. 0x34, 0xDF, 0xB1, 0x62, 0x2F, 0x61, 0xD8, 0xB7,
  35406. 0x63, 0x2A, 0xC7, 0x7E, 0x3A, 0x98, 0x0B, 0x2C,
  35407. 0xE5, 0x66, 0xF3, 0xD5, 0x30, 0xF0, 0xBC, 0x21,
  35408. 0xC7, 0x51, 0x9B, 0xFB, 0x00, 0xBB, 0xAA, 0x9C,
  35409. 0x85, 0xC3, 0x9B, 0x0C, 0xDC, 0x5F, 0x8D, 0x1B,
  35410. 0xA1, 0x2B, 0x78, 0x82, 0xFE, 0x0F, 0x7C, 0x75,
  35411. 0x6E, 0x75, 0x56, 0x74, 0x35, 0x25, 0xE5, 0xD0,
  35412. 0xEC, 0x8E, 0xC1, 0xBD, 0x7D, 0x7A, 0xE3, 0xDC,
  35413. 0xAD, 0xC6, 0x8D, 0xB6, 0x0D, 0x7A, 0xA1, 0x3C,
  35414. 0xDB, 0x29, 0xFA, 0x15, 0xC0, 0xA9, 0xAF, 0x89,
  35415. 0x0F, 0x18, 0x75, 0xE3, 0x97, 0x58, 0x62, 0x12,
  35416. 0x79, 0xA9, 0x87, 0x7D, 0x9C, 0x69, 0x44, 0x9C,
  35417. 0x41, 0x39, 0x2C, 0xAD, 0x98, 0x8B, 0x8D, 0xE4,
  35418. 0x58, 0xEE, 0xCD, 0x98, 0x38, 0x5F, 0x79, 0x73,
  35419. 0x0B, 0x5E, 0x26, 0xC1, 0x16, 0x24, 0x15, 0xD9,
  35420. 0x73, 0x26, 0x41, 0x9B, 0x5F, 0xF9, 0x2A, 0xA8,
  35421. 0xC1, 0x33, 0x74, 0x39, 0x1D, 0xBB, 0xE7, 0x36,
  35422. 0xD9, 0x8C, 0x07, 0xAD, 0x32, 0xD6, 0x38, 0xBB,
  35423. 0x44, 0xE6, 0x77, 0xC7, 0x11, 0x05, 0xCF, 0xB5,
  35424. 0x72, 0x49, 0x68, 0x80, 0xC1, 0x67, 0x71, 0x5F,
  35425. 0x9B, 0xFF, 0x6E, 0x71, 0x1A, 0xBE, 0x5A, 0x83,
  35426. 0x25, 0x38, 0xC7, 0xE6, 0xDA, 0x88, 0x22, 0xDC,
  35427. 0xA6, 0x03, 0x02, 0xD1, 0x59, 0xC6, 0xA8, 0x2F,
  35428. 0xA4, 0x8F, 0xF8, 0x77, 0x3E, 0x0C, 0x6F, 0xA1,
  35429. 0x73, 0xE1, 0x35, 0x55, 0xB2, 0xDF, 0xBF, 0x47,
  35430. 0xB7, 0xD0, 0x8D, 0xBA, 0x35, 0x74, 0x44, 0x6B,
  35431. 0xC0, 0xA7, 0x8D, 0x30, 0x08, 0xE4, 0x41, 0xD1,
  35432. 0x55, 0x21, 0x50, 0xD9, 0x06, 0x12, 0x54, 0xB2,
  35433. 0xF3, 0xFC, 0x5A, 0x1E, 0xF3, 0xE3, 0x84, 0x33,
  35434. 0x34, 0x0B, 0xB5, 0x9A, 0x97, 0xFD, 0x51, 0xF4,
  35435. 0x68, 0xFE, 0x8A, 0x92, 0xBF, 0x62, 0x9D, 0xCD,
  35436. 0x00, 0x29, 0x39, 0x37, 0x12, 0xF3, 0x53, 0x6D,
  35437. 0x6B, 0x24, 0xB8, 0x86, 0x68, 0xAD, 0x6A, 0x4B,
  35438. 0x3A, 0x4C, 0x93, 0xA6, 0xB1, 0x41, 0xFA, 0x8E,
  35439. 0x58, 0x63, 0xCD, 0x59, 0x80, 0xBF, 0xD7, 0xAB,
  35440. 0x83, 0xC3, 0xCC, 0x5D, 0x2F, 0xBE, 0x80, 0xC7,
  35441. 0xB1, 0x67, 0xDC, 0x92, 0x8C, 0xA9, 0x57, 0x36,
  35442. 0x58, 0x0A, 0x52, 0x96, 0x0E, 0x20, 0x90, 0xCD,
  35443. 0x87, 0x68, 0xF5, 0x93, 0xBB, 0x04, 0xD4, 0x48,
  35444. 0xB6, 0x45, 0x30, 0xC0, 0xE3, 0xC2, 0x56, 0x8C,
  35445. 0xE3, 0xA2, 0xC6, 0x42, 0x0F, 0x81, 0xF7, 0x4D,
  35446. 0xF6, 0x88, 0x5D, 0x55, 0x07, 0x8E, 0xF1, 0xB3,
  35447. 0x83, 0xB0, 0x20, 0x85, 0x4A, 0x63, 0x6A, 0x78,
  35448. 0xA9, 0xEC, 0x13, 0x84, 0xF7, 0x4E, 0xBE, 0xB6,
  35449. 0x5F, 0x5A, 0x25, 0xFF, 0xD4, 0x14, 0x7D, 0xA7,
  35450. 0xEE, 0x40, 0xF6, 0x25, 0x7C, 0x7E, 0x34, 0xCA,
  35451. 0xC9, 0x27, 0x0E, 0xA2, 0x78, 0xB6, 0xE6, 0x08,
  35452. 0xA1, 0x9B, 0x56, 0x8D, 0x29, 0xE5, 0x8D, 0xEC,
  35453. 0xAD, 0xDA, 0xD3, 0x3C, 0x59, 0xBA, 0xDB, 0x92,
  35454. 0x52, 0x99, 0x3B, 0x31, 0x6B, 0x0B, 0x13, 0x00,
  35455. 0x79, 0x3D, 0x69, 0x85, 0x3A, 0x6B, 0x90, 0x33,
  35456. 0x96
  35457. };
  35458. static const byte rnd_44[] = {
  35459. 0x08, 0x34, 0x57, 0xD4, 0x0E, 0x25, 0x04, 0x88,
  35460. 0xA6, 0x0E, 0x76, 0x34, 0xA0, 0x1D, 0x43, 0x0A,
  35461. 0x60, 0xE8, 0x57, 0x2B, 0xA8, 0x8A, 0xED, 0xC5,
  35462. 0x54, 0x49, 0x18, 0x81, 0x37, 0x13, 0xA0, 0xB1
  35463. };
  35464. static const byte sig_44[] = {
  35465. 0x63, 0xA8, 0x23, 0x20, 0xD4, 0xCE, 0x09, 0xC4,
  35466. 0x7A, 0xD1, 0x27, 0xC5, 0xBB, 0x7F, 0x6C, 0x2D,
  35467. 0xFF, 0x15, 0x29, 0xCD, 0xAF, 0x9F, 0x74, 0x56,
  35468. 0xFF, 0xC2, 0xC6, 0xED, 0x90, 0x51, 0x17, 0xDC,
  35469. 0xAD, 0x8C, 0x08, 0x7A, 0xC0, 0xD8, 0x9E, 0x0C,
  35470. 0xE9, 0x61, 0xC0, 0x94, 0xFA, 0x9C, 0x2E, 0xDE,
  35471. 0x27, 0x9C, 0x65, 0xE6, 0x99, 0xD1, 0xD1, 0x7E,
  35472. 0xA6, 0x95, 0x98, 0x8F, 0xA1, 0xC4, 0x98, 0x3F,
  35473. 0x7E, 0x1F, 0x18, 0x86, 0x2A, 0xFE, 0xB2, 0xEC,
  35474. 0x9D, 0x0F, 0x5B, 0x0C, 0x11, 0xB2, 0xAA, 0x0B,
  35475. 0xDE, 0x95, 0x7C, 0x40, 0xA1, 0x5B, 0xFF, 0x97,
  35476. 0xD7, 0xCB, 0xCF, 0x4E, 0x59, 0xDA, 0xE9, 0xD5,
  35477. 0xA3, 0xC9, 0xF8, 0x7D, 0xDD, 0xA5, 0xB9, 0x06,
  35478. 0x9D, 0x82, 0xCC, 0x18, 0x10, 0x20, 0x80, 0x92,
  35479. 0xBC, 0xBA, 0x1C, 0x43, 0x73, 0xF2, 0xA8, 0x3E,
  35480. 0x19, 0x15, 0x80, 0x9E, 0x81, 0xD8, 0xD2, 0x06,
  35481. 0xEA, 0x78, 0x10, 0x3F, 0x68, 0x66, 0x3D, 0xBE,
  35482. 0xB1, 0x79, 0xB0, 0x28, 0x83, 0xCD, 0xD3, 0x33,
  35483. 0xEE, 0xFE, 0x6D, 0x02, 0x39, 0x17, 0xC6, 0xF2,
  35484. 0xA4, 0x6E, 0x5A, 0x5C, 0x45, 0x14, 0xF5, 0x7D,
  35485. 0xCA, 0x7B, 0x62, 0x4A, 0xF4, 0xE7, 0x71, 0x7B,
  35486. 0xD7, 0x1B, 0x51, 0x26, 0xE6, 0xDE, 0x2D, 0xC9,
  35487. 0x65, 0x24, 0x30, 0x2C, 0x08, 0x04, 0xD7, 0xBE,
  35488. 0x3A, 0xDA, 0x64, 0xAF, 0x11, 0x6F, 0xC6, 0xE7,
  35489. 0x38, 0xEF, 0xA6, 0xE6, 0x5E, 0x87, 0x90, 0xB4,
  35490. 0x0E, 0xB1, 0xB4, 0x83, 0x64, 0xD2, 0x15, 0xEF,
  35491. 0xD6, 0x1F, 0x7A, 0x44, 0x75, 0x3A, 0x95, 0x50,
  35492. 0x6E, 0x52, 0xC9, 0x9C, 0xE9, 0xB4, 0x56, 0xDC,
  35493. 0x93, 0x85, 0x92, 0xF1, 0x35, 0xEC, 0x50, 0x1B,
  35494. 0x3B, 0xCF, 0x82, 0xDA, 0x69, 0xA1, 0xDD, 0x44,
  35495. 0xE8, 0xB3, 0xC1, 0xCB, 0x8D, 0xD5, 0x13, 0xD0,
  35496. 0xF3, 0x14, 0x2C, 0x80, 0x82, 0x2C, 0x31, 0xBF,
  35497. 0x75, 0x20, 0x14, 0x39, 0x9F, 0x81, 0x79, 0x76,
  35498. 0x0F, 0xB6, 0x7D, 0xB6, 0x58, 0x1C, 0xF3, 0xE6,
  35499. 0x93, 0x5A, 0x9B, 0xE1, 0x8B, 0x92, 0xC2, 0xDB,
  35500. 0xF1, 0x89, 0xAA, 0x46, 0x67, 0xFA, 0x80, 0x45,
  35501. 0x72, 0xAA, 0xB4, 0xE2, 0x5E, 0xE9, 0xD1, 0xA7,
  35502. 0xA0, 0xD7, 0x05, 0x5C, 0xC6, 0xC7, 0x6D, 0x1D,
  35503. 0x66, 0x3D, 0x35, 0x0C, 0xB7, 0x1A, 0xFA, 0xB1,
  35504. 0xDB, 0xD0, 0xCB, 0x3A, 0x8B, 0xB7, 0x1B, 0x03,
  35505. 0x60, 0xA0, 0xA4, 0xDA, 0xD0, 0xE2, 0x3A, 0x1E,
  35506. 0xB5, 0xE4, 0x59, 0x68, 0x6A, 0x02, 0x94, 0x66,
  35507. 0x05, 0x60, 0x08, 0x64, 0xB4, 0xEE, 0x0F, 0x3A,
  35508. 0xCE, 0xFD, 0x40, 0x7B, 0x6F, 0xF5, 0x8D, 0x1E,
  35509. 0xFF, 0x0C, 0x75, 0xAF, 0xC1, 0x41, 0xC6, 0x24,
  35510. 0x1D, 0xF3, 0x76, 0x02, 0x48, 0x6B, 0xBA, 0x58,
  35511. 0xBC, 0xBB, 0xFE, 0xD3, 0x51, 0xC2, 0x68, 0x21,
  35512. 0x4B, 0x20, 0x4E, 0xAF, 0x8A, 0x0C, 0x74, 0x7F,
  35513. 0x5F, 0xB7, 0xAA, 0x43, 0xFC, 0x5A, 0x77, 0xA1,
  35514. 0x81, 0xCD, 0xBA, 0xE1, 0x31, 0x87, 0x1F, 0xA8,
  35515. 0x1F, 0x76, 0x30, 0x6C, 0xE0, 0x84, 0xCD, 0x14,
  35516. 0x4A, 0xDB, 0x67, 0xFD, 0x65, 0x8C, 0x35, 0xC0,
  35517. 0x91, 0x6C, 0x2B, 0xCF, 0x5B, 0x89, 0x29, 0x58,
  35518. 0x42, 0x9B, 0x65, 0xDB, 0x34, 0x7D, 0xD8, 0x31,
  35519. 0xC9, 0xB8, 0x0D, 0x07, 0xD1, 0x94, 0x60, 0x63,
  35520. 0x65, 0xDC, 0xB3, 0x70, 0x48, 0x46, 0x37, 0x18,
  35521. 0x4D, 0x5D, 0xE0, 0xAC, 0x77, 0xD0, 0x9E, 0xE1,
  35522. 0xD9, 0xB2, 0x2D, 0x09, 0xD6, 0xF8, 0x94, 0x96,
  35523. 0x7B, 0x43, 0xD9, 0x76, 0x36, 0xE6, 0x24, 0xA4,
  35524. 0x4A, 0xFF, 0x12, 0xFE, 0x30, 0x95, 0xD7, 0xCB,
  35525. 0xA9, 0xA0, 0x3A, 0xCA, 0xFC, 0x52, 0x57, 0xB8,
  35526. 0x20, 0x80, 0xF2, 0xD8, 0xAE, 0x3E, 0x18, 0xFC,
  35527. 0x0D, 0xE0, 0x9D, 0x01, 0x7B, 0x03, 0xAD, 0x6B,
  35528. 0xEE, 0xA4, 0xEC, 0x38, 0x40, 0xAC, 0x85, 0x42,
  35529. 0xF8, 0xCF, 0x93, 0x10, 0x8F, 0x8C, 0xFE, 0xF8,
  35530. 0x22, 0x64, 0xFC, 0xDD, 0x2C, 0xDD, 0x86, 0x97,
  35531. 0x5B, 0x3F, 0x8F, 0xDF, 0x1F, 0x58, 0x22, 0x08,
  35532. 0x26, 0x8A, 0x76, 0xE6, 0xC9, 0xFE, 0xDF, 0x42,
  35533. 0x90, 0x8D, 0x52, 0x78, 0xA2, 0xBF, 0xBD, 0x3F,
  35534. 0xD5, 0xD5, 0xDB, 0xAF, 0xDD, 0x5E, 0x2C, 0x2B,
  35535. 0x9F, 0x2E, 0xDC, 0xC1, 0xC4, 0x52, 0x96, 0x38,
  35536. 0x49, 0xCB, 0x34, 0xEC, 0x51, 0x00, 0x8D, 0x1B,
  35537. 0xF6, 0xDA, 0x50, 0xA0, 0xD1, 0x9D, 0x82, 0x34,
  35538. 0x5B, 0x78, 0x8C, 0x05, 0x40, 0xE1, 0x7B, 0x25,
  35539. 0xFF, 0xDC, 0xE8, 0xD4, 0x45, 0x3B, 0xBE, 0x75,
  35540. 0x1E, 0xDA, 0x96, 0xA4, 0x4C, 0x75, 0xFD, 0xD9,
  35541. 0x00, 0x81, 0x85, 0x7D, 0xC0, 0xF8, 0x26, 0x2A,
  35542. 0x30, 0x7B, 0x34, 0xCB, 0xEC, 0xD1, 0x56, 0x58,
  35543. 0x69, 0xA3, 0x14, 0xD6, 0x4C, 0x09, 0xDC, 0x9D,
  35544. 0x4A, 0x80, 0x26, 0x52, 0x2F, 0xDF, 0xE4, 0xCB,
  35545. 0x5B, 0x8B, 0x11, 0x05, 0xDA, 0xE0, 0xDB, 0x66,
  35546. 0xC8, 0x5B, 0xB4, 0x32, 0x1D, 0xBE, 0x76, 0x84,
  35547. 0xEB, 0x6B, 0x6F, 0x85, 0x87, 0xD8, 0x32, 0x0C,
  35548. 0x6D, 0xB3, 0x8D, 0xED, 0xD6, 0x18, 0x96, 0xED,
  35549. 0x51, 0xAB, 0x0C, 0x7F, 0x42, 0x8F, 0x19, 0xD2,
  35550. 0x55, 0xC6, 0xB0, 0xFD, 0xF5, 0x89, 0x51, 0xE5,
  35551. 0xCD, 0xB1, 0x96, 0x9C, 0xD9, 0xA7, 0x93, 0x4E,
  35552. 0xFD, 0xB9, 0xC8, 0x2E, 0x1E, 0x8D, 0x2A, 0x59,
  35553. 0xC9, 0xF7, 0x9D, 0xF1, 0xAA, 0x93, 0xE5, 0x07,
  35554. 0x1E, 0x3F, 0xAC, 0x73, 0x19, 0xFF, 0x68, 0x87,
  35555. 0x8C, 0xF2, 0x49, 0xDC, 0xBD, 0xCD, 0x10, 0x46,
  35556. 0x16, 0xCC, 0xC1, 0xC1, 0xFB, 0xD7, 0x85, 0x56,
  35557. 0x9F, 0x55, 0x87, 0x10, 0x44, 0x1B, 0x31, 0xCA,
  35558. 0xE3, 0x16, 0x7A, 0x4C, 0xD7, 0xDD, 0xD1, 0x86,
  35559. 0x26, 0xC5, 0x43, 0x62, 0x96, 0x20, 0x32, 0xE6,
  35560. 0xB7, 0xA2, 0x76, 0x05, 0x61, 0x96, 0xFC, 0x22,
  35561. 0x96, 0x7E, 0x90, 0x7C, 0x32, 0x0A, 0x7A, 0xF5,
  35562. 0x8C, 0xE3, 0xF5, 0x01, 0xC4, 0xCD, 0x31, 0x8A,
  35563. 0x70, 0x75, 0x04, 0xF1, 0xC2, 0x59, 0xE5, 0x07,
  35564. 0xA0, 0xD4, 0x7D, 0x25, 0x8E, 0x2F, 0x38, 0xE2,
  35565. 0x6A, 0x53, 0x41, 0x34, 0x7A, 0x06, 0xB5, 0x8B,
  35566. 0xB0, 0xBF, 0x21, 0xDE, 0xE6, 0x5F, 0x55, 0x6A,
  35567. 0xD4, 0x88, 0xA7, 0x36, 0xD4, 0xC6, 0x5C, 0x82,
  35568. 0xC6, 0x73, 0xC0, 0x60, 0xD7, 0xA6, 0xA0, 0x77,
  35569. 0x5C, 0xF8, 0xC3, 0x9A, 0xA1, 0x31, 0xFD, 0x64,
  35570. 0xDB, 0xB1, 0x7B, 0x72, 0x70, 0x4B, 0x7D, 0x1D,
  35571. 0x24, 0xBC, 0x5F, 0x84, 0x08, 0x3B, 0xF8, 0xA6,
  35572. 0x47, 0xEB, 0xED, 0xCF, 0xDD, 0xA0, 0x91, 0x14,
  35573. 0x26, 0x7D, 0x77, 0xCF, 0xBF, 0x39, 0x9B, 0xD9,
  35574. 0x2F, 0x3B, 0x2A, 0xA7, 0x2B, 0xBC, 0xF7, 0xDE,
  35575. 0x9D, 0x69, 0xBF, 0x90, 0xA4, 0xDE, 0x2C, 0xF8,
  35576. 0x24, 0x92, 0x7D, 0xE2, 0xB8, 0xBD, 0xF4, 0x6B,
  35577. 0x10, 0x9E, 0xD6, 0x08, 0x51, 0xC5, 0x9C, 0x44,
  35578. 0x8E, 0xCB, 0x44, 0x3F, 0x00, 0x26, 0x3C, 0x9C,
  35579. 0x25, 0xF4, 0x62, 0x74, 0xD1, 0x7C, 0x29, 0x4C,
  35580. 0xEB, 0xF2, 0x53, 0x7D, 0x8F, 0xEA, 0xBD, 0x78,
  35581. 0xEE, 0xBC, 0xBA, 0x72, 0x64, 0xA5, 0xB9, 0x45,
  35582. 0x08, 0xE0, 0xBF, 0x62, 0xEF, 0xC2, 0x1E, 0x06,
  35583. 0xE1, 0xE2, 0xFB, 0x14, 0x44, 0xC5, 0xAB, 0x6F,
  35584. 0x84, 0x7F, 0x52, 0x2F, 0x8A, 0xBE, 0xED, 0x04,
  35585. 0x6D, 0x6D, 0xDC, 0xFF, 0xBC, 0xB8, 0xC8, 0x1F,
  35586. 0xD0, 0x5D, 0x4D, 0x7F, 0x2E, 0x1B, 0xC9, 0x9B,
  35587. 0xEA, 0xF8, 0xC1, 0xAF, 0xE3, 0xE0, 0x5B, 0x36,
  35588. 0x90, 0xFE, 0xE4, 0xAA, 0x37, 0x5A, 0x3D, 0xCB,
  35589. 0x77, 0x57, 0x7C, 0xCC, 0x6E, 0x3E, 0xBE, 0x8A,
  35590. 0x98, 0x7C, 0x6D, 0x7E, 0x89, 0x60, 0x73, 0xC0,
  35591. 0xCC, 0x0C, 0x48, 0x25, 0x46, 0xB5, 0x39, 0xB4,
  35592. 0xFD, 0xF0, 0x4E, 0xED, 0x8E, 0x87, 0xF8, 0x5B,
  35593. 0x00, 0xBE, 0x43, 0xA6, 0x0B, 0x21, 0x7E, 0x96,
  35594. 0x88, 0x3B, 0x91, 0xD7, 0x88, 0x1A, 0xA0, 0xDD,
  35595. 0x3E, 0xBF, 0x5B, 0x0D, 0x08, 0xD0, 0x85, 0x4E,
  35596. 0xD4, 0x27, 0x8F, 0xC9, 0x02, 0xE0, 0x60, 0xEA,
  35597. 0x16, 0xFB, 0xC2, 0x54, 0xA5, 0x08, 0xC8, 0x6F,
  35598. 0x7A, 0xE7, 0x54, 0x93, 0xB8, 0xDD, 0xA0, 0x86,
  35599. 0xE9, 0xC1, 0xB2, 0x17, 0xF5, 0xC9, 0x11, 0x97,
  35600. 0x83, 0x66, 0x88, 0xCD, 0x2D, 0x0B, 0xB8, 0xE5,
  35601. 0x52, 0xD1, 0x13, 0x7A, 0xA7, 0xEB, 0xD5, 0xD5,
  35602. 0x60, 0x53, 0x8E, 0x9B, 0xB6, 0xB4, 0x1D, 0x06,
  35603. 0x90, 0xB0, 0x6C, 0x66, 0xD1, 0x57, 0x5B, 0x86,
  35604. 0x1C, 0x8A, 0x7D, 0x3A, 0x88, 0x4C, 0xC9, 0x88,
  35605. 0x1A, 0xC3, 0x00, 0x1F, 0x30, 0x0D, 0xF3, 0x47,
  35606. 0x62, 0x79, 0x85, 0x89, 0xF9, 0xEE, 0x5C, 0x92,
  35607. 0x43, 0x61, 0x53, 0xD8, 0xC7, 0x32, 0x55, 0x9B,
  35608. 0x33, 0x3D, 0x69, 0x8F, 0x3E, 0xC5, 0x82, 0x0E,
  35609. 0x8A, 0xA5, 0xF2, 0xE5, 0xA7, 0x69, 0xC2, 0xB4,
  35610. 0x7A, 0xFA, 0x27, 0x5F, 0xE4, 0x74, 0xAF, 0x81,
  35611. 0x37, 0xC7, 0x01, 0x9A, 0xF2, 0xE6, 0x0C, 0xA7,
  35612. 0x5E, 0xDB, 0xE4, 0x8F, 0x81, 0xA6, 0x51, 0xCE,
  35613. 0x6B, 0xAB, 0xD3, 0x37, 0x4C, 0x07, 0x72, 0xA8,
  35614. 0xAC, 0x36, 0x77, 0xB1, 0x0F, 0x54, 0x77, 0x17,
  35615. 0xC9, 0x67, 0x50, 0xDA, 0x44, 0x8B, 0xD9, 0xC7,
  35616. 0x93, 0x8C, 0x66, 0xCD, 0x6F, 0xB7, 0x5D, 0x73,
  35617. 0x2D, 0xAC, 0x83, 0x1A, 0xDC, 0xE9, 0x17, 0x6D,
  35618. 0x94, 0x85, 0x6E, 0x1B, 0xF6, 0x08, 0x38, 0xD0,
  35619. 0x9E, 0x63, 0x23, 0xA2, 0x7B, 0x16, 0x09, 0xF9,
  35620. 0xC1, 0x21, 0xF4, 0x98, 0xD2, 0xBB, 0x68, 0x58,
  35621. 0x18, 0xA0, 0x0D, 0xE7, 0xBA, 0x6B, 0x28, 0x47,
  35622. 0xC5, 0x16, 0x14, 0x9F, 0x35, 0x6E, 0xCE, 0xF0,
  35623. 0x4F, 0x34, 0xEA, 0x48, 0x35, 0x46, 0xFE, 0xEB,
  35624. 0x12, 0xEA, 0x40, 0x77, 0x62, 0x04, 0x30, 0xC3,
  35625. 0x9D, 0xBF, 0x47, 0xC0, 0x5E, 0xED, 0x5E, 0xD5,
  35626. 0x87, 0xFF, 0xF5, 0x92, 0x21, 0x7C, 0xA9, 0x5A,
  35627. 0x2C, 0x3D, 0x1E, 0x6F, 0x6F, 0xF9, 0xFF, 0x20,
  35628. 0x9F, 0x8B, 0x30, 0xA9, 0x9D, 0x56, 0xA3, 0x97,
  35629. 0x7A, 0x33, 0x17, 0x49, 0x0B, 0x2B, 0x00, 0x1F,
  35630. 0x43, 0xCD, 0x8D, 0xDD, 0x1D, 0x8F, 0xC1, 0x6A,
  35631. 0x3F, 0xA9, 0xB4, 0x31, 0x54, 0x62, 0x84, 0x5B,
  35632. 0x99, 0x5D, 0x2A, 0xB7, 0x6E, 0xA5, 0x39, 0xC7,
  35633. 0xF0, 0x4C, 0x31, 0x6C, 0x71, 0xD6, 0x00, 0xE1,
  35634. 0xAC, 0x4F, 0xD5, 0xC8, 0xC6, 0x34, 0x3B, 0xC8,
  35635. 0x05, 0x5F, 0x17, 0x00, 0xB4, 0x0E, 0xA2, 0xF1,
  35636. 0xAB, 0xE9, 0x4B, 0xE0, 0x06, 0x01, 0x3A, 0xA2,
  35637. 0x61, 0xF0, 0x72, 0x0A, 0xB7, 0x99, 0xD0, 0xFC,
  35638. 0x6D, 0xB5, 0xE9, 0xA4, 0xC3, 0xC5, 0xA7, 0xF8,
  35639. 0x2D, 0x70, 0xD2, 0x8E, 0x41, 0x0D, 0xD1, 0x64,
  35640. 0xE3, 0xE4, 0x61, 0xA4, 0x6E, 0x81, 0xFB, 0xDC,
  35641. 0xB8, 0x10, 0x84, 0x8B, 0xCE, 0xE0, 0x6F, 0x88,
  35642. 0x33, 0x25, 0x64, 0x6E, 0x1E, 0x2A, 0x69, 0x3F,
  35643. 0xA5, 0xDA, 0x7C, 0x25, 0xEB, 0x21, 0xC4, 0xEA,
  35644. 0xB8, 0x7D, 0xC7, 0x87, 0xA2, 0x67, 0x7C, 0xEB,
  35645. 0x6A, 0x26, 0xE1, 0x06, 0xFE, 0x78, 0xE1, 0x18,
  35646. 0xFF, 0x54, 0x71, 0x3E, 0x00, 0x59, 0x7B, 0xFA,
  35647. 0x52, 0x8C, 0x2A, 0xED, 0x06, 0x9A, 0x12, 0x6D,
  35648. 0xE3, 0x74, 0x6F, 0x06, 0x65, 0xE1, 0x75, 0x80,
  35649. 0x63, 0x0F, 0x70, 0x2F, 0xAB, 0xC0, 0xF1, 0xCD,
  35650. 0x7F, 0x57, 0xAA, 0x71, 0xF6, 0x38, 0xD8, 0xAF,
  35651. 0x37, 0xD3, 0xD9, 0xE0, 0xA7, 0xE9, 0x05, 0x5D,
  35652. 0xA3, 0xDF, 0x86, 0x48, 0x3F, 0x25, 0xDE, 0xBA,
  35653. 0x18, 0xCE, 0xF6, 0x99, 0xEB, 0x87, 0x70, 0xC7,
  35654. 0x85, 0x84, 0x79, 0x8A, 0xD8, 0x02, 0x8B, 0xAD,
  35655. 0xC5, 0x9D, 0x2A, 0xF9, 0xAE, 0xAE, 0x37, 0xEC,
  35656. 0x93, 0x91, 0x16, 0x10, 0x5F, 0x9F, 0x64, 0xEF,
  35657. 0x82, 0x78, 0xC6, 0x4D, 0xED, 0x3F, 0xD4, 0x33,
  35658. 0xA7, 0xB8, 0x82, 0x09, 0x16, 0xBE, 0xDC, 0x6B,
  35659. 0x7A, 0x75, 0x69, 0x8A, 0xDE, 0xD3, 0xFD, 0xE8,
  35660. 0x86, 0x75, 0x42, 0x83, 0x03, 0x57, 0x30, 0x70,
  35661. 0xA5, 0xA3, 0x85, 0x1F, 0x9F, 0x21, 0xEA, 0xC7,
  35662. 0x80, 0xFA, 0x8A, 0xA4, 0x02, 0x3E, 0x39, 0x11,
  35663. 0x48, 0x7D, 0x85, 0x2A, 0x53, 0x77, 0x43, 0x5A,
  35664. 0x5F, 0xFF, 0x9C, 0x60, 0x4B, 0x5D, 0x95, 0xB0,
  35665. 0x96, 0x8A, 0xE0, 0xEC, 0xF4, 0x43, 0x1B, 0x10,
  35666. 0x3F, 0xA6, 0xBA, 0x71, 0xC4, 0xDC, 0x81, 0x73,
  35667. 0xA2, 0xDE, 0x1F, 0x79, 0xDD, 0xB6, 0x0D, 0x2D,
  35668. 0x0C, 0x8E, 0x56, 0x55, 0xD0, 0x94, 0x44, 0x29,
  35669. 0x16, 0x92, 0x99, 0x2D, 0x99, 0xFC, 0x48, 0xF2,
  35670. 0x16, 0x0E, 0xC0, 0xAC, 0xE4, 0xC4, 0x92, 0x07,
  35671. 0xBB, 0xB7, 0x6D, 0x7F, 0x2A, 0x85, 0xE1, 0x81,
  35672. 0x02, 0xB9, 0x5A, 0x51, 0x45, 0x88, 0xF5, 0x9F,
  35673. 0x16, 0x2D, 0x33, 0xCE, 0xD6, 0x18, 0x07, 0x03,
  35674. 0xED, 0xC3, 0x6C, 0x8B, 0x33, 0x94, 0x88, 0x81,
  35675. 0x0D, 0x2E, 0xAE, 0x96, 0x25, 0xCE, 0xE3, 0x83,
  35676. 0x27, 0x1C, 0x71, 0x72, 0xEE, 0xD6, 0xB5, 0x48,
  35677. 0x69, 0x60, 0xE8, 0x99, 0x18, 0x74, 0xB0, 0x13,
  35678. 0x53, 0x59, 0x3D, 0x70, 0x70, 0xBD, 0xEB, 0x7A,
  35679. 0x9F, 0x92, 0x29, 0xAB, 0x77, 0x0E, 0xEB, 0x46,
  35680. 0x37, 0x8D, 0x57, 0xD9, 0x56, 0xDF, 0x7A, 0x86,
  35681. 0x40, 0x04, 0x02, 0x98, 0xF7, 0x00, 0xF4, 0x41,
  35682. 0x5B, 0xDD, 0x3A, 0x96, 0x15, 0xA4, 0x65, 0xDB,
  35683. 0x01, 0x28, 0x22, 0x12, 0xCF, 0x1A, 0xEC, 0x4B,
  35684. 0x0B, 0x8C, 0xB3, 0xB1, 0x7E, 0x5E, 0xFA, 0x28,
  35685. 0x6C, 0x6C, 0x04, 0x5B, 0x43, 0x9C, 0x74, 0x9F,
  35686. 0xE1, 0xD4, 0x50, 0x75, 0xD8, 0xE7, 0xA0, 0x0F,
  35687. 0xBE, 0x84, 0x48, 0xFC, 0xAC, 0xAA, 0x15, 0x3D,
  35688. 0x69, 0x70, 0x9D, 0x9F, 0xF2, 0xB9, 0x7C, 0xDB,
  35689. 0x26, 0xC0, 0xC3, 0x79, 0x28, 0x7C, 0xE6, 0x48,
  35690. 0x61, 0xAD, 0xD7, 0x89, 0xD0, 0xC8, 0x93, 0x9A,
  35691. 0x14, 0x21, 0xB0, 0x85, 0xD6, 0x23, 0x4C, 0xE1,
  35692. 0xA7, 0x49, 0xDE, 0x3D, 0xCB, 0xE8, 0xE0, 0x61,
  35693. 0x5C, 0xB3, 0xBC, 0xDC, 0x6A, 0x81, 0xA5, 0xC4,
  35694. 0x9D, 0x92, 0x85, 0x74, 0x5F, 0x1C, 0xA8, 0xA0,
  35695. 0x64, 0x1E, 0x32, 0x68, 0x83, 0x41, 0x93, 0x34,
  35696. 0x82, 0x18, 0x3E, 0x24, 0x5C, 0x1F, 0x9C, 0xD2,
  35697. 0x80, 0x28, 0xC3, 0x8A, 0x23, 0x18, 0x1A, 0x44,
  35698. 0x5A, 0xA6, 0xEA, 0xCC, 0xE2, 0x06, 0x06, 0xE6,
  35699. 0xF7, 0xF1, 0xDF, 0x70, 0x68, 0x83, 0xCD, 0xA5,
  35700. 0x2F, 0x3F, 0x2B, 0x68, 0xDE, 0x26, 0xDD, 0x37,
  35701. 0x71, 0xE9, 0x50, 0x03, 0x2C, 0xC7, 0x20, 0x0C,
  35702. 0x20, 0x23, 0xC8, 0x24, 0x96, 0x50, 0x82, 0x82,
  35703. 0xCD, 0x3B, 0xC4, 0x7F, 0xEC, 0xE5, 0xD9, 0x7C,
  35704. 0xA1, 0xCE, 0x35, 0x74, 0x4D, 0x03, 0xD7, 0xA4,
  35705. 0x28, 0xB7, 0xAF, 0x12, 0xB0, 0xCB, 0x8E, 0x65,
  35706. 0x7C, 0x01, 0x30, 0xF8, 0xA3, 0xA2, 0x54, 0x97,
  35707. 0x6E, 0xC8, 0xF7, 0xDC, 0xCF, 0x3A, 0xBF, 0x31,
  35708. 0xF4, 0xB0, 0xB3, 0xF7, 0x12, 0x6F, 0xFC, 0x48,
  35709. 0x77, 0xF3, 0xD1, 0xA0, 0x66, 0xD2, 0x6A, 0x23,
  35710. 0x2F, 0xA9, 0x99, 0x21, 0x61, 0x22, 0x54, 0x11,
  35711. 0xED, 0x7D, 0xDB, 0x93, 0xC3, 0x5C, 0x6A, 0x37,
  35712. 0x7F, 0x30, 0xCF, 0x22, 0xAA, 0x39, 0x2D, 0x5C,
  35713. 0x4F, 0xEE, 0x4F, 0x73, 0xC9, 0xEF, 0x6E, 0xD3,
  35714. 0xA0, 0x27, 0x97, 0x14, 0x52, 0x3B, 0x19, 0x18,
  35715. 0x65, 0x1E, 0x9B, 0x0F, 0xFA, 0x55, 0x0F, 0x16,
  35716. 0x10, 0x53, 0xEE, 0x78, 0x01, 0x39, 0x7B, 0x4C,
  35717. 0x18, 0x49, 0x98, 0x7C, 0x17, 0x9E, 0x76, 0x3E,
  35718. 0xCC, 0x60, 0xA4, 0xE4, 0xC5, 0x36, 0xB7, 0xE2,
  35719. 0x66, 0x3E, 0x4C, 0x72, 0x67, 0x14, 0xB0, 0x2E,
  35720. 0xC3, 0x16, 0x9E, 0x84, 0x07, 0xBA, 0x59, 0x2B,
  35721. 0x0E, 0xB8, 0x46, 0xF3, 0x69, 0x2D, 0xD4, 0x46,
  35722. 0x51, 0xEE, 0x08, 0x47, 0x21, 0xCA, 0xC0, 0xFE,
  35723. 0x1C, 0xCC, 0x30, 0x27, 0x07, 0xEF, 0xE2, 0x46,
  35724. 0x64, 0xE0, 0x5B, 0xDC, 0x69, 0xC8, 0x39, 0x04,
  35725. 0xAC, 0xB8, 0xCF, 0x97, 0x12, 0x1C, 0x7E, 0x5C,
  35726. 0x6D, 0xB2, 0x7E, 0xA2, 0x8E, 0x77, 0xBC, 0xDA,
  35727. 0x55, 0xD2, 0xBC, 0xC1, 0xC5, 0xFC, 0xC5, 0x52,
  35728. 0xAB, 0x83, 0xBC, 0xE4, 0x23, 0x8C, 0xA1, 0x80,
  35729. 0x62, 0xC2, 0xD2, 0x3A, 0x8B, 0x80, 0x0C, 0x82,
  35730. 0x09, 0xC3, 0xA4, 0xCD, 0xDA, 0xF1, 0x16, 0x16,
  35731. 0x57, 0x8A, 0x84, 0x55, 0x66, 0xFC, 0x28, 0x9A,
  35732. 0x8E, 0x3C, 0x88, 0xF5, 0x54, 0xC4, 0x92, 0x60,
  35733. 0x71, 0xDA, 0x89, 0x32, 0x6B, 0xEB, 0x25, 0x9A,
  35734. 0x0E, 0x1F, 0x6D, 0x84, 0x4E, 0xBF, 0x7B, 0x28,
  35735. 0x1F, 0x9F, 0xC3, 0x74, 0x3A, 0x65, 0x49, 0x9E,
  35736. 0x73, 0x94, 0x63, 0x48, 0x18, 0xE1, 0x33, 0xFA,
  35737. 0xC6, 0x64, 0xFA, 0x0C, 0x88, 0xF1, 0x01, 0xCE,
  35738. 0xC3, 0xFE, 0xD8, 0x79, 0x29, 0x50, 0xBF, 0x6E,
  35739. 0x49, 0x74, 0x84, 0x9E, 0x1E, 0xBD, 0x27, 0x69,
  35740. 0x1B, 0xF5, 0x51, 0x9B, 0x70, 0x2E, 0x1A, 0xA4,
  35741. 0xB3, 0xDB, 0xAD, 0xAB, 0x5D, 0xFA, 0x34, 0xFB,
  35742. 0x0E, 0xD9, 0xD4, 0xA9, 0xDF, 0x4B, 0x6B, 0x63,
  35743. 0xCA, 0x71, 0x65, 0xE2, 0xA9, 0x08, 0x27, 0x40,
  35744. 0x8C, 0x48, 0x2D, 0x9D, 0xBC, 0x97, 0x24, 0x68,
  35745. 0x58, 0x4F, 0x42, 0x37, 0x60, 0x04, 0xE7, 0x8B,
  35746. 0xE0, 0x67, 0x00, 0x9E, 0x43, 0x30, 0x4B, 0xED,
  35747. 0xC1, 0x07, 0xA4, 0xE2, 0xA8, 0x9C, 0xAF, 0x18,
  35748. 0x5C, 0x9B, 0xB7, 0xE9, 0xFD, 0x2C, 0xB9, 0x2A,
  35749. 0xEF, 0x36, 0x3B, 0xD7, 0x96, 0xF3, 0x60, 0x4E,
  35750. 0xDC, 0x08, 0xA7, 0xC5, 0x45, 0xB8, 0x37, 0x02,
  35751. 0xD3, 0xCF, 0x80, 0x88, 0x52, 0x10, 0x3E, 0x01,
  35752. 0x3B, 0xFE, 0xA1, 0x61, 0xAF, 0x25, 0x0B, 0xCC,
  35753. 0x72, 0x77, 0x1D, 0x0C, 0x48, 0x4D, 0xD5, 0x55,
  35754. 0x41, 0x72, 0x3A, 0x21, 0x0D, 0x68, 0x3B, 0x99,
  35755. 0x8C, 0xDB, 0xAF, 0x3D, 0x9A, 0x5E, 0x71, 0x78,
  35756. 0x6F, 0x1C, 0xF4, 0x7B, 0x86, 0x22, 0x51, 0xB5,
  35757. 0x16, 0x33, 0x60, 0x87, 0x9A, 0xC0, 0x20, 0x2D,
  35758. 0x33, 0x49, 0x51, 0x54, 0x5C, 0x5F, 0x71, 0x76,
  35759. 0x7C, 0x8F, 0x96, 0xA9, 0xD6, 0xE4, 0xF2, 0x1F,
  35760. 0x28, 0x43, 0x4D, 0x7E, 0x96, 0xBB, 0xC5, 0xE3,
  35761. 0xEF, 0xF3, 0xFD, 0x02, 0x0C, 0x17, 0x23, 0x3E,
  35762. 0x7F, 0x99, 0xB0, 0xE3, 0xE8, 0xF5, 0x00, 0x00,
  35763. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35764. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35765. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35766. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35767. 0x06, 0x17, 0x23, 0x2E
  35768. };
  35769. #endif
  35770. #ifndef WOLFSSL_NO_ML_DSA_65
  35771. static const byte sk_65[] = {
  35772. 0xF2, 0x6B, 0xFE, 0x12, 0x68, 0x86, 0xF4, 0x82,
  35773. 0x22, 0x94, 0x4D, 0x02, 0x18, 0xFA, 0xC1, 0x7C,
  35774. 0xD8, 0xA9, 0xCC, 0x6D, 0x67, 0xA0, 0x23, 0xFD,
  35775. 0xC0, 0x7A, 0xFF, 0xC2, 0xD0, 0x25, 0xF7, 0x70,
  35776. 0x63, 0x85, 0x0D, 0x88, 0x0E, 0x98, 0xFE, 0xE5,
  35777. 0x02, 0xE0, 0x17, 0x32, 0x70, 0x00, 0xCC, 0xAF,
  35778. 0x61, 0x45, 0x73, 0xB3, 0x5A, 0xDE, 0xFE, 0xBC,
  35779. 0xAC, 0xEE, 0xA4, 0xB2, 0xC4, 0xD0, 0x45, 0xE5,
  35780. 0xBB, 0xFD, 0x3E, 0x5A, 0x72, 0xE3, 0x71, 0xAD,
  35781. 0x83, 0xB9, 0x94, 0x98, 0x77, 0xD8, 0xE6, 0x56,
  35782. 0xD4, 0x6B, 0x47, 0x75, 0x0F, 0x73, 0x0F, 0x96,
  35783. 0xDB, 0x43, 0x0B, 0x18, 0x60, 0x88, 0x67, 0x5D,
  35784. 0x9A, 0x9B, 0xD7, 0x8E, 0x47, 0xB8, 0x9D, 0x04,
  35785. 0xA8, 0x51, 0x7E, 0xD2, 0x22, 0x06, 0x95, 0x33,
  35786. 0x9F, 0x99, 0xA9, 0x7F, 0x35, 0x3C, 0xE4, 0x20,
  35787. 0x47, 0x77, 0x20, 0x9F, 0x5F, 0x3C, 0x9E, 0x9A,
  35788. 0x36, 0x14, 0x54, 0x01, 0x57, 0x48, 0x60, 0x50,
  35789. 0x75, 0x28, 0x64, 0x61, 0x72, 0x60, 0x54, 0x20,
  35790. 0x75, 0x48, 0x60, 0x32, 0x73, 0x85, 0x34, 0x24,
  35791. 0x68, 0x63, 0x71, 0x73, 0x81, 0x26, 0x71, 0x68,
  35792. 0x32, 0x61, 0x24, 0x71, 0x14, 0x18, 0x26, 0x15,
  35793. 0x05, 0x77, 0x36, 0x27, 0x50, 0x35, 0x21, 0x82,
  35794. 0x50, 0x15, 0x31, 0x47, 0x48, 0x24, 0x43, 0x76,
  35795. 0x18, 0x85, 0x66, 0x18, 0x05, 0x64, 0x27, 0x01,
  35796. 0x06, 0x06, 0x01, 0x45, 0x42, 0x60, 0x80, 0x68,
  35797. 0x25, 0x08, 0x08, 0x36, 0x13, 0x05, 0x04, 0x32,
  35798. 0x34, 0x87, 0x00, 0x70, 0x71, 0x70, 0x02, 0x51,
  35799. 0x37, 0x15, 0x08, 0x28, 0x25, 0x72, 0x61, 0x67,
  35800. 0x08, 0x52, 0x63, 0x44, 0x07, 0x88, 0x60, 0x42,
  35801. 0x03, 0x17, 0x24, 0x64, 0x80, 0x08, 0x70, 0x23,
  35802. 0x56, 0x41, 0x46, 0x17, 0x46, 0x01, 0x57, 0x74,
  35803. 0x02, 0x76, 0x31, 0x64, 0x73, 0x83, 0x50, 0x62,
  35804. 0x72, 0x61, 0x62, 0x75, 0x45, 0x73, 0x46, 0x33,
  35805. 0x65, 0x14, 0x36, 0x46, 0x12, 0x26, 0x04, 0x34,
  35806. 0x02, 0x81, 0x20, 0x34, 0x41, 0x88, 0x26, 0x77,
  35807. 0x33, 0x40, 0x18, 0x58, 0x03, 0x41, 0x16, 0x58,
  35808. 0x88, 0x04, 0x88, 0x32, 0x71, 0x05, 0x85, 0x83,
  35809. 0x42, 0x55, 0x34, 0x20, 0x18, 0x46, 0x12, 0x54,
  35810. 0x28, 0x03, 0x67, 0x10, 0x84, 0x31, 0x76, 0x00,
  35811. 0x40, 0x85, 0x46, 0x71, 0x71, 0x56, 0x00, 0x50,
  35812. 0x15, 0x33, 0x43, 0x13, 0x37, 0x57, 0x13, 0x86,
  35813. 0x43, 0x77, 0x85, 0x57, 0x54, 0x81, 0x75, 0x60,
  35814. 0x37, 0x31, 0x28, 0x52, 0x20, 0x78, 0x65, 0x53,
  35815. 0x76, 0x10, 0x84, 0x87, 0x57, 0x13, 0x66, 0x03,
  35816. 0x56, 0x81, 0x36, 0x66, 0x68, 0x41, 0x55, 0x64,
  35817. 0x63, 0x70, 0x26, 0x21, 0x02, 0x30, 0x28, 0x35,
  35818. 0x02, 0x45, 0x88, 0x80, 0x02, 0x06, 0x44, 0x58,
  35819. 0x24, 0x13, 0x88, 0x83, 0x22, 0x34, 0x22, 0x50,
  35820. 0x47, 0x11, 0x01, 0x86, 0x45, 0x60, 0x67, 0x36,
  35821. 0x82, 0x22, 0x18, 0x74, 0x11, 0x60, 0x58, 0x60,
  35822. 0x87, 0x26, 0x31, 0x85, 0x12, 0x70, 0x84, 0x83,
  35823. 0x88, 0x68, 0x88, 0x51, 0x00, 0x55, 0x02, 0x57,
  35824. 0x77, 0x42, 0x13, 0x23, 0x14, 0x04, 0x76, 0x80,
  35825. 0x72, 0x25, 0x51, 0x56, 0x10, 0x63, 0x12, 0x21,
  35826. 0x03, 0x86, 0x27, 0x30, 0x28, 0x12, 0x01, 0x37,
  35827. 0x48, 0x32, 0x53, 0x86, 0x15, 0x46, 0x50, 0x05,
  35828. 0x34, 0x87, 0x61, 0x04, 0x88, 0x18, 0x35, 0x85,
  35829. 0x44, 0x46, 0x24, 0x67, 0x43, 0x83, 0x02, 0x26,
  35830. 0x56, 0x41, 0x41, 0x77, 0x86, 0x56, 0x41, 0x75,
  35831. 0x25, 0x61, 0x36, 0x05, 0x47, 0x65, 0x00, 0x14,
  35832. 0x32, 0x38, 0x16, 0x81, 0x06, 0x30, 0x61, 0x25,
  35833. 0x16, 0x30, 0x50, 0x44, 0x13, 0x08, 0x75, 0x00,
  35834. 0x50, 0x20, 0x68, 0x21, 0x55, 0x74, 0x61, 0x18,
  35835. 0x62, 0x05, 0x15, 0x51, 0x08, 0x24, 0x01, 0x13,
  35836. 0x81, 0x33, 0x64, 0x83, 0x23, 0x00, 0x55, 0x73,
  35837. 0x62, 0x40, 0x61, 0x75, 0x15, 0x78, 0x21, 0x14,
  35838. 0x13, 0x64, 0x21, 0x47, 0x07, 0x76, 0x80, 0x76,
  35839. 0x76, 0x17, 0x75, 0x50, 0x61, 0x14, 0x40, 0x82,
  35840. 0x87, 0x83, 0x50, 0x87, 0x30, 0x86, 0x35, 0x30,
  35841. 0x28, 0x20, 0x10, 0x01, 0x48, 0x18, 0x34, 0x65,
  35842. 0x23, 0x10, 0x25, 0x42, 0x40, 0x22, 0x54, 0x34,
  35843. 0x35, 0x33, 0x71, 0x70, 0x20, 0x61, 0x55, 0x74,
  35844. 0x33, 0x01, 0x02, 0x60, 0x58, 0x24, 0x80, 0x12,
  35845. 0x46, 0x41, 0x38, 0x10, 0x76, 0x67, 0x34, 0x63,
  35846. 0x48, 0x85, 0x06, 0x48, 0x04, 0x23, 0x22, 0x66,
  35847. 0x57, 0x71, 0x68, 0x18, 0x04, 0x32, 0x01, 0x31,
  35848. 0x01, 0x55, 0x22, 0x27, 0x55, 0x72, 0x10, 0x00,
  35849. 0x43, 0x88, 0x76, 0x62, 0x84, 0x77, 0x07, 0x77,
  35850. 0x14, 0x07, 0x20, 0x53, 0x74, 0x17, 0x51, 0x17,
  35851. 0x66, 0x84, 0x47, 0x83, 0x61, 0x03, 0x52, 0x10,
  35852. 0x05, 0x40, 0x46, 0x55, 0x61, 0x47, 0x26, 0x70,
  35853. 0x40, 0x22, 0x10, 0x34, 0x41, 0x01, 0x03, 0x48,
  35854. 0x33, 0x05, 0x72, 0x32, 0x75, 0x82, 0x45, 0x85,
  35855. 0x20, 0x70, 0x80, 0x82, 0x20, 0x23, 0x62, 0x81,
  35856. 0x15, 0x47, 0x80, 0x23, 0x67, 0x23, 0x73, 0x34,
  35857. 0x44, 0x33, 0x85, 0x10, 0x05, 0x50, 0x30, 0x03,
  35858. 0x48, 0x13, 0x01, 0x36, 0x45, 0x11, 0x06, 0x33,
  35859. 0x82, 0x22, 0x78, 0x75, 0x42, 0x02, 0x40, 0x45,
  35860. 0x04, 0x47, 0x43, 0x05, 0x30, 0x44, 0x42, 0x02,
  35861. 0x28, 0x26, 0x64, 0x24, 0x74, 0x75, 0x86, 0x11,
  35862. 0x85, 0x43, 0x25, 0x46, 0x10, 0x62, 0x82, 0x71,
  35863. 0x08, 0x27, 0x45, 0x13, 0x73, 0x18, 0x84, 0x73,
  35864. 0x51, 0x51, 0x67, 0x14, 0x70, 0x11, 0x07, 0x08,
  35865. 0x62, 0x16, 0x25, 0x27, 0x36, 0x68, 0x44, 0x01,
  35866. 0x18, 0x63, 0x74, 0x50, 0x31, 0x13, 0x43, 0x65,
  35867. 0x80, 0x11, 0x16, 0x52, 0x86, 0x42, 0x51, 0x81,
  35868. 0x51, 0x17, 0x05, 0x68, 0x05, 0x73, 0x60, 0x37,
  35869. 0x63, 0x85, 0x86, 0x11, 0x23, 0x23, 0x38, 0x13,
  35870. 0x87, 0x48, 0x82, 0x74, 0x71, 0x81, 0x87, 0x65,
  35871. 0x58, 0x26, 0x60, 0x34, 0x76, 0x16, 0x15, 0x24,
  35872. 0x06, 0x78, 0x16, 0x40, 0x03, 0x45, 0x72, 0x31,
  35873. 0x63, 0x73, 0x31, 0x85, 0x02, 0x66, 0x44, 0x36,
  35874. 0x24, 0x82, 0x56, 0x38, 0x86, 0x10, 0x40, 0x54,
  35875. 0x72, 0x70, 0x24, 0x22, 0x72, 0x78, 0x47, 0x07,
  35876. 0x86, 0x30, 0x48, 0x72, 0x84, 0x57, 0x06, 0x34,
  35877. 0x78, 0x37, 0x63, 0x25, 0x56, 0x64, 0x81, 0x30,
  35878. 0x62, 0x77, 0x22, 0x84, 0x20, 0x10, 0x74, 0x25,
  35879. 0x04, 0x21, 0x76, 0x47, 0x72, 0x35, 0x05, 0x06,
  35880. 0x22, 0x50, 0x34, 0x11, 0x26, 0x67, 0x03, 0x05,
  35881. 0x42, 0x04, 0x16, 0x01, 0x27, 0x17, 0x86, 0x67,
  35882. 0x70, 0x51, 0x53, 0x13, 0x12, 0x62, 0x03, 0x25,
  35883. 0x05, 0x38, 0x37, 0x44, 0x02, 0x66, 0x84, 0x74,
  35884. 0x14, 0x40, 0x35, 0x20, 0x40, 0x30, 0x44, 0x64,
  35885. 0x27, 0x50, 0x77, 0x47, 0x06, 0x15, 0x84, 0x48,
  35886. 0x13, 0x14, 0x32, 0x48, 0x11, 0x74, 0x80, 0x68,
  35887. 0x85, 0x81, 0x17, 0x67, 0x38, 0x22, 0x76, 0x16,
  35888. 0x18, 0x44, 0x55, 0x47, 0x85, 0x36, 0x44, 0x11,
  35889. 0x52, 0x01, 0x81, 0x50, 0x41, 0x00, 0x00, 0x25,
  35890. 0x83, 0x41, 0x62, 0x22, 0x12, 0x54, 0x88, 0x77,
  35891. 0x70, 0x48, 0x84, 0x25, 0x77, 0x75, 0x40, 0x16,
  35892. 0x46, 0x24, 0x88, 0x81, 0x65, 0x70, 0x02, 0x66,
  35893. 0x28, 0x64, 0x12, 0x40, 0x30, 0x60, 0x53, 0x06,
  35894. 0x44, 0x02, 0x48, 0x78, 0x75, 0x68, 0x21, 0x23,
  35895. 0x30, 0x05, 0x81, 0x17, 0x72, 0x66, 0x88, 0x71,
  35896. 0x50, 0x25, 0x03, 0x51, 0x42, 0x27, 0x20, 0x81,
  35897. 0x03, 0x52, 0x73, 0x53, 0x63, 0x57, 0x13, 0x60,
  35898. 0x41, 0x20, 0x47, 0x12, 0x55, 0x57, 0x58, 0x16,
  35899. 0x38, 0x63, 0x21, 0x34, 0x51, 0x76, 0x33, 0x26,
  35900. 0x70, 0x41, 0x18, 0x11, 0x07, 0x37, 0x16, 0x12,
  35901. 0x01, 0x14, 0x28, 0x56, 0x78, 0x10, 0x86, 0x24,
  35902. 0x24, 0x32, 0x01, 0x13, 0x57, 0x53, 0x46, 0x46,
  35903. 0x24, 0x05, 0x20, 0x16, 0x56, 0x83, 0x30, 0x30,
  35904. 0x61, 0x20, 0x75, 0x07, 0x05, 0x74, 0x14, 0x17,
  35905. 0x43, 0x72, 0x23, 0x04, 0x18, 0x61, 0x50, 0x13,
  35906. 0x67, 0x31, 0x75, 0x36, 0x71, 0x02, 0x38, 0x74,
  35907. 0x21, 0x80, 0x20, 0x48, 0x66, 0x23, 0x52, 0x54,
  35908. 0x77, 0x27, 0x45, 0x73, 0x23, 0x88, 0x60, 0x50,
  35909. 0x88, 0x82, 0x70, 0x23, 0x72, 0x08, 0x44, 0x66,
  35910. 0x44, 0x36, 0x12, 0x57, 0x66, 0x14, 0x25, 0x12,
  35911. 0x17, 0x34, 0x64, 0x82, 0x01, 0x54, 0x61, 0x57,
  35912. 0x50, 0x31, 0x65, 0x64, 0x75, 0x44, 0x76, 0x48,
  35913. 0x16, 0x44, 0x46, 0x55, 0x80, 0x64, 0x26, 0x53,
  35914. 0x27, 0x22, 0x10, 0x87, 0x84, 0x03, 0x15, 0x35,
  35915. 0x15, 0x20, 0x86, 0x14, 0x04, 0x03, 0x26, 0x43,
  35916. 0x31, 0x43, 0x31, 0x45, 0x46, 0x34, 0x36, 0x87,
  35917. 0x44, 0x41, 0x21, 0x77, 0x61, 0x20, 0x85, 0x06,
  35918. 0x28, 0x51, 0x15, 0x62, 0x77, 0x20, 0x38, 0x58,
  35919. 0x78, 0x27, 0x12, 0x22, 0x46, 0x71, 0x51, 0x38,
  35920. 0x11, 0x15, 0x40, 0x03, 0x78, 0x36, 0x15, 0x57,
  35921. 0x34, 0x28, 0x53, 0x21, 0x37, 0x35, 0x04, 0x76,
  35922. 0x00, 0x56, 0x72, 0x48, 0x46, 0x01, 0x56, 0x67,
  35923. 0x62, 0x36, 0x14, 0x51, 0x23, 0x54, 0x32, 0x35,
  35924. 0x82, 0x83, 0x21, 0x60, 0x38, 0x62, 0x21, 0x03,
  35925. 0x62, 0x76, 0x40, 0x34, 0x66, 0x88, 0x50, 0x73,
  35926. 0x00, 0x53, 0x87, 0x31, 0x37, 0x50, 0x11, 0x32,
  35927. 0x86, 0x52, 0x18, 0x64, 0x16, 0x63, 0x48, 0x71,
  35928. 0x70, 0x47, 0x24, 0x85, 0x31, 0x86, 0x60, 0x86,
  35929. 0x33, 0x52, 0x85, 0x82, 0x68, 0x17, 0x70, 0x88,
  35930. 0x84, 0x56, 0x52, 0x77, 0x04, 0x48, 0x22, 0x22,
  35931. 0x54, 0x57, 0x20, 0x31, 0x76, 0x47, 0x26, 0x25,
  35932. 0x04, 0x35, 0x38, 0x44, 0x55, 0x21, 0x14, 0x02,
  35933. 0x13, 0x64, 0x74, 0x87, 0x68, 0x68, 0x73, 0x05,
  35934. 0x22, 0x45, 0x54, 0x45, 0x83, 0x46, 0x64, 0x54,
  35935. 0x80, 0x07, 0x32, 0x87, 0x52, 0x43, 0x54, 0x54,
  35936. 0x14, 0x73, 0x24, 0x87, 0x36, 0x41, 0x74, 0x84,
  35937. 0x06, 0x35, 0x13, 0x40, 0x61, 0x54, 0x21, 0x31,
  35938. 0x48, 0x63, 0x05, 0x74, 0x24, 0x84, 0x74, 0x76,
  35939. 0x11, 0x10, 0x16, 0x63, 0x77, 0x12, 0x26, 0x61,
  35940. 0x31, 0x28, 0x70, 0x34, 0x25, 0x01, 0x30, 0x76,
  35941. 0x76, 0x06, 0x21, 0x58, 0x42, 0x87, 0x31, 0x72,
  35942. 0x76, 0x03, 0x76, 0x26, 0x78, 0x05, 0x88, 0x25,
  35943. 0x25, 0x86, 0x17, 0x02, 0x85, 0x88, 0x76, 0x20,
  35944. 0x36, 0x57, 0x30, 0x81, 0x83, 0x61, 0x05, 0x80,
  35945. 0x21, 0x45, 0x74, 0x01, 0x12, 0x74, 0x51, 0x28,
  35946. 0x77, 0x26, 0x30, 0x14, 0x54, 0x84, 0x13, 0x78,
  35947. 0x06, 0x00, 0x12, 0x64, 0x00, 0x37, 0x44, 0x68,
  35948. 0x40, 0x57, 0x05, 0x27, 0x07, 0x41, 0x56, 0x22,
  35949. 0x31, 0x40, 0x23, 0x26, 0x55, 0x42, 0x55, 0x16,
  35950. 0x02, 0x65, 0x32, 0x16, 0x33, 0x44, 0x46, 0x48,
  35951. 0x04, 0x52, 0x06, 0x53, 0x44, 0x40, 0x11, 0x28,
  35952. 0x46, 0x67, 0x56, 0x81, 0x72, 0x75, 0x51, 0x38,
  35953. 0x21, 0x86, 0x46, 0x03, 0x22, 0x87, 0x21, 0x70,
  35954. 0x68, 0x50, 0x75, 0x13, 0x11, 0x44, 0x35, 0x12,
  35955. 0x60, 0x02, 0x13, 0x47, 0x18, 0x38, 0x78, 0x86,
  35956. 0x38, 0x58, 0x45, 0x57, 0x23, 0x03, 0x88, 0x66,
  35957. 0x56, 0x82, 0x18, 0x31, 0x20, 0x08, 0x61, 0x47,
  35958. 0x78, 0x08, 0x68, 0x37, 0x21, 0x04, 0x65, 0x47,
  35959. 0x58, 0x70, 0x34, 0x58, 0x73, 0x24, 0x22, 0x30,
  35960. 0x66, 0x05, 0x01, 0x28, 0x87, 0x85, 0x77, 0x74,
  35961. 0x23, 0x86, 0x65, 0x84, 0x85, 0x57, 0x85, 0x63,
  35962. 0x06, 0x55, 0x61, 0x75, 0x46, 0x22, 0x87, 0x00,
  35963. 0x18, 0x53, 0x08, 0x03, 0x07, 0x50, 0x42, 0x70,
  35964. 0xFC, 0xB8, 0x7B, 0x22, 0x3D, 0x24, 0xAE, 0x5D,
  35965. 0xB1, 0x89, 0x04, 0x21, 0xC3, 0xFF, 0x1D, 0x59,
  35966. 0xB8, 0x4B, 0x19, 0xE2, 0x4D, 0x14, 0x36, 0x99,
  35967. 0x19, 0x1C, 0x7E, 0x9A, 0x46, 0x48, 0x42, 0x20,
  35968. 0x6B, 0xBA, 0x24, 0x7E, 0x8C, 0x6B, 0x27, 0xBA,
  35969. 0x26, 0xE6, 0x8A, 0xD5, 0xA7, 0x1D, 0x03, 0x61,
  35970. 0xCD, 0x5C, 0x74, 0xCE, 0x50, 0xC2, 0xCE, 0xF1,
  35971. 0x91, 0x31, 0xEF, 0x54, 0x66, 0x23, 0x7F, 0xFE,
  35972. 0xF7, 0xFE, 0x6B, 0x5F, 0xD1, 0x98, 0x23, 0x8E,
  35973. 0x1C, 0xA0, 0xB1, 0x01, 0x30, 0xC6, 0x29, 0xCC,
  35974. 0x91, 0x91, 0xF5, 0x78, 0x6F, 0x5C, 0xD6, 0x28,
  35975. 0xA4, 0x22, 0x56, 0xCB, 0x6F, 0xC7, 0xD7, 0x09,
  35976. 0x56, 0x88, 0xAF, 0x1B, 0xC8, 0x43, 0x51, 0xA4,
  35977. 0x7B, 0x4B, 0x38, 0x2E, 0xF6, 0x1F, 0xD6, 0x5C,
  35978. 0x9E, 0xC2, 0x26, 0xF4, 0x2B, 0x0A, 0x19, 0x7C,
  35979. 0x6A, 0xD8, 0xF0, 0xB0, 0x15, 0xD0, 0xB1, 0xC7,
  35980. 0xE0, 0x14, 0x28, 0x95, 0x6A, 0x9B, 0xB2, 0xDE,
  35981. 0x9A, 0x97, 0xE5, 0x75, 0x66, 0xF8, 0xF5, 0x66,
  35982. 0x86, 0xA1, 0xF4, 0x68, 0x0C, 0xEC, 0xEA, 0x87,
  35983. 0x3B, 0x69, 0x1C, 0xF8, 0xBD, 0x63, 0xAB, 0x73,
  35984. 0x73, 0xBA, 0xE8, 0x09, 0x5B, 0xA7, 0x76, 0x3E,
  35985. 0x50, 0xD6, 0x83, 0x9D, 0x00, 0x35, 0xBB, 0xFB,
  35986. 0x91, 0xBA, 0x60, 0x72, 0x17, 0x98, 0xFB, 0x2C,
  35987. 0x80, 0x2C, 0x60, 0x3A, 0x08, 0xA1, 0x24, 0x05,
  35988. 0xE0, 0xB5, 0x20, 0xEA, 0x41, 0x43, 0x8F, 0xEA,
  35989. 0xEF, 0xA5, 0x62, 0xDC, 0x78, 0x92, 0xF4, 0x58,
  35990. 0x9F, 0x8D, 0x2B, 0x96, 0x5E, 0xE5, 0x49, 0x73,
  35991. 0xA7, 0x2C, 0x8D, 0x33, 0x5C, 0x62, 0x61, 0x98,
  35992. 0x80, 0x64, 0x13, 0x31, 0x03, 0x10, 0xE3, 0x2E,
  35993. 0xFE, 0x6B, 0x39, 0xB5, 0xCF, 0xB1, 0xD1, 0x33,
  35994. 0xAD, 0xE0, 0x1B, 0xCE, 0x94, 0x21, 0x6C, 0xF4,
  35995. 0xCD, 0x8F, 0x86, 0x43, 0x03, 0x1D, 0xB8, 0xC2,
  35996. 0x47, 0xB5, 0x73, 0x21, 0xCA, 0x1E, 0xFB, 0xB8,
  35997. 0x53, 0x63, 0x7D, 0x0C, 0x57, 0x52, 0x14, 0xFC,
  35998. 0x77, 0xA5, 0xA6, 0x84, 0xD5, 0x0A, 0xBF, 0xE4,
  35999. 0xE9, 0x71, 0x99, 0x8E, 0x06, 0x6E, 0x50, 0x24,
  36000. 0xDA, 0x02, 0x76, 0x8A, 0xED, 0xE1, 0x3E, 0x83,
  36001. 0xF0, 0x51, 0x54, 0xA9, 0x99, 0x29, 0x48, 0x42,
  36002. 0x7A, 0xA9, 0x8C, 0x87, 0x42, 0x51, 0xAF, 0x56,
  36003. 0x94, 0x23, 0x53, 0x89, 0x44, 0xFA, 0xD8, 0x93,
  36004. 0xFC, 0x65, 0x6E, 0x9C, 0xED, 0x80, 0x6A, 0x85,
  36005. 0xD9, 0xC3, 0x36, 0x71, 0x02, 0x25, 0x29, 0x36,
  36006. 0x8E, 0x7E, 0xC7, 0x0C, 0x9E, 0xE9, 0x74, 0x30,
  36007. 0x1C, 0x08, 0xCB, 0xE6, 0xAC, 0x5E, 0x88, 0xE6,
  36008. 0x37, 0x79, 0x5C, 0xB2, 0xA2, 0x15, 0xFF, 0xAA,
  36009. 0x08, 0xED, 0xDE, 0x40, 0xAC, 0xFA, 0xEE, 0x2A,
  36010. 0x40, 0xD5, 0x05, 0xCF, 0x58, 0xA6, 0x69, 0x66,
  36011. 0x31, 0x5A, 0x68, 0x98, 0x24, 0x03, 0xD8, 0x1B,
  36012. 0xFA, 0x89, 0xE3, 0x7C, 0x9E, 0x42, 0x1D, 0xA5,
  36013. 0x88, 0xBA, 0x7E, 0x42, 0x2A, 0xC7, 0x44, 0x6A,
  36014. 0x1E, 0x61, 0xC8, 0x22, 0x29, 0x9D, 0xFC, 0x34,
  36015. 0xEC, 0xFA, 0xBE, 0x5C, 0xB6, 0x26, 0xB9, 0x6C,
  36016. 0x8E, 0xA6, 0xC9, 0x3B, 0xDB, 0xD2, 0xD5, 0xBD,
  36017. 0x70, 0xC5, 0xF8, 0x26, 0x7A, 0x84, 0xE0, 0x07,
  36018. 0xA7, 0x11, 0x5E, 0x5B, 0xE5, 0xF1, 0x20, 0x32,
  36019. 0xA3, 0x7C, 0xAB, 0x05, 0xD5, 0x41, 0xE3, 0xDE,
  36020. 0xA5, 0x1A, 0x83, 0x2E, 0xDE, 0x8D, 0x34, 0x9A,
  36021. 0xFD, 0xD5, 0xE6, 0xFC, 0xFC, 0x83, 0x46, 0xE3,
  36022. 0xD4, 0x7C, 0xF1, 0x7F, 0xEA, 0x87, 0x5E, 0x38,
  36023. 0x5D, 0xB9, 0x8A, 0xC2, 0xDB, 0xE8, 0xB4, 0xF8,
  36024. 0x05, 0x37, 0x31, 0x0D, 0xD9, 0x4C, 0xD0, 0xB6,
  36025. 0x25, 0xE9, 0x97, 0x85, 0xDB, 0x04, 0x9A, 0x01,
  36026. 0xF5, 0x4B, 0xA1, 0xF4, 0x2A, 0xDF, 0xEC, 0xAE,
  36027. 0x24, 0x11, 0xD3, 0x2B, 0x2F, 0x84, 0x6C, 0x88,
  36028. 0xA3, 0x0C, 0x76, 0xEA, 0x0A, 0x38, 0xB2, 0x71,
  36029. 0xB6, 0xAC, 0xA8, 0x23, 0x6E, 0x61, 0xEB, 0xB8,
  36030. 0x4A, 0x9D, 0xC4, 0x9E, 0x5C, 0x5B, 0xEE, 0x7E,
  36031. 0x7D, 0x8D, 0xA2, 0xC1, 0xA1, 0xA0, 0xA3, 0x14,
  36032. 0x50, 0xE0, 0x8F, 0xAB, 0xBB, 0x1B, 0x1F, 0x05,
  36033. 0xAA, 0xE3, 0x00, 0xD8, 0xCD, 0xE7, 0x35, 0xB4,
  36034. 0x7B, 0xBD, 0xB0, 0x5C, 0xCC, 0x0C, 0x05, 0x33,
  36035. 0x6B, 0xE4, 0x51, 0x73, 0x1B, 0x6B, 0x77, 0x7B,
  36036. 0xE5, 0xCB, 0xAF, 0x98, 0x53, 0x5F, 0x7E, 0x08,
  36037. 0xFF, 0xCD, 0x8A, 0x44, 0x9E, 0x1D, 0x43, 0x6A,
  36038. 0x4F, 0x05, 0x99, 0x01, 0xF5, 0x6F, 0x01, 0x30,
  36039. 0xBD, 0x15, 0xD7, 0x51, 0x16, 0x45, 0x40, 0x6B,
  36040. 0xF3, 0x13, 0xCA, 0x1F, 0x22, 0x02, 0xA4, 0xA8,
  36041. 0x6A, 0x1D, 0x04, 0x7F, 0xD5, 0x8A, 0x3E, 0x87,
  36042. 0x7F, 0x1D, 0x5A, 0x79, 0x75, 0xD1, 0x6D, 0x67,
  36043. 0xB3, 0x23, 0xC6, 0x28, 0x7B, 0x9C, 0xCE, 0xEE,
  36044. 0x98, 0x9E, 0xE8, 0x44, 0xA9, 0x3E, 0x7E, 0xFD,
  36045. 0x3B, 0xD9, 0xD8, 0x31, 0x6D, 0xA3, 0x77, 0xDF,
  36046. 0x0B, 0xB9, 0xE2, 0x61, 0xA2, 0x71, 0xD5, 0x0C,
  36047. 0xB7, 0x01, 0x67, 0xC3, 0x0D, 0x19, 0x2D, 0xAA,
  36048. 0xDE, 0x96, 0x0E, 0xEA, 0x33, 0x5E, 0xEC, 0x52,
  36049. 0xE5, 0x2D, 0x95, 0x39, 0xE1, 0xF9, 0x5D, 0x9E,
  36050. 0xB6, 0x5E, 0x54, 0x8F, 0x16, 0x60, 0x99, 0xED,
  36051. 0x88, 0x2C, 0x30, 0x72, 0x53, 0x6A, 0x6C, 0xAA,
  36052. 0x05, 0x21, 0xA5, 0xAA, 0x7C, 0x64, 0x72, 0xA0,
  36053. 0xC0, 0x4F, 0x80, 0xDA, 0x20, 0x5D, 0x52, 0x18,
  36054. 0x77, 0x07, 0xDF, 0x5C, 0x2F, 0x2E, 0xA2, 0x5F,
  36055. 0xEF, 0x00, 0xCA, 0x7B, 0xF0, 0xD3, 0xB7, 0xF8,
  36056. 0x1E, 0x31, 0x9E, 0x61, 0xCA, 0x2C, 0xC5, 0xA5,
  36057. 0x25, 0xA2, 0x7B, 0x56, 0xAA, 0xBA, 0xE4, 0xD5,
  36058. 0x35, 0xE5, 0xEC, 0x24, 0x2D, 0x81, 0x1A, 0x24,
  36059. 0xD7, 0x45, 0x76, 0xBF, 0x4B, 0x8A, 0x72, 0xFA,
  36060. 0x5F, 0xAE, 0xC1, 0xA2, 0x83, 0xB6, 0x1D, 0x60,
  36061. 0x28, 0x7E, 0x1E, 0x2E, 0xC8, 0xC6, 0xAB, 0x04,
  36062. 0x56, 0x5F, 0xD5, 0xCD, 0x64, 0x26, 0x34, 0x94,
  36063. 0xE8, 0x03, 0x41, 0x63, 0x35, 0x5B, 0x45, 0x84,
  36064. 0xCE, 0xFA, 0x0B, 0x66, 0x40, 0x85, 0x1A, 0xE1,
  36065. 0x23, 0xE9, 0x8F, 0xBD, 0xA9, 0x23, 0xFC, 0xA3,
  36066. 0x8E, 0x38, 0xB3, 0x84, 0xE2, 0xB9, 0x54, 0x41,
  36067. 0x4B, 0x36, 0x4F, 0xB8, 0xB0, 0x87, 0x56, 0x04,
  36068. 0x8B, 0x75, 0xC7, 0x85, 0x31, 0xD4, 0xA5, 0x12,
  36069. 0x99, 0xC4, 0x9D, 0xEA, 0x4B, 0x36, 0x8C, 0x19,
  36070. 0x82, 0xFE, 0xAD, 0x4A, 0xB1, 0xAA, 0x52, 0x35,
  36071. 0xA4, 0xA1, 0x7F, 0xB0, 0x64, 0x6F, 0x04, 0x04,
  36072. 0x7B, 0xF0, 0x80, 0x48, 0xA1, 0x1C, 0xF8, 0x95,
  36073. 0x8B, 0x68, 0x34, 0xB7, 0xFD, 0x00, 0x31, 0x30,
  36074. 0x6A, 0x39, 0xC8, 0xAE, 0x68, 0xC3, 0x53, 0x65,
  36075. 0x19, 0x7C, 0x1E, 0x57, 0x97, 0xFC, 0x47, 0x3E,
  36076. 0xB1, 0x94, 0x54, 0x48, 0x6F, 0xEB, 0xAA, 0xEC,
  36077. 0x5C, 0x2E, 0xE9, 0x2C, 0xCC, 0x3A, 0xF3, 0xC7,
  36078. 0x43, 0x08, 0x7D, 0x2D, 0x56, 0x4B, 0x7D, 0xE9,
  36079. 0xE5, 0x96, 0xF3, 0x12, 0x4B, 0xE9, 0x08, 0xF3,
  36080. 0x04, 0x5A, 0x75, 0x1A, 0x7D, 0x7E, 0x37, 0xE6,
  36081. 0xC8, 0xC1, 0xFE, 0xF3, 0x32, 0x63, 0x2D, 0x0B,
  36082. 0xBE, 0x05, 0x13, 0x6A, 0x44, 0x58, 0x7F, 0x54,
  36083. 0x5F, 0x5F, 0xF5, 0x2F, 0xB8, 0x0B, 0xF2, 0xBF,
  36084. 0x0B, 0xF4, 0x30, 0x2F, 0xCF, 0xEC, 0xFE, 0x08,
  36085. 0xEC, 0x51, 0xF2, 0x29, 0xD7, 0xAC, 0x28, 0xE1,
  36086. 0x75, 0x42, 0x61, 0xBC, 0xE7, 0xB1, 0x53, 0x4F,
  36087. 0x7D, 0x3B, 0xB0, 0x8D, 0x01, 0x15, 0x1E, 0xBE,
  36088. 0xEC, 0xD9, 0x54, 0xC2, 0x4E, 0x70, 0x3E, 0xEA,
  36089. 0x39, 0x14, 0x26, 0xB7, 0x01, 0x79, 0x5D, 0x06,
  36090. 0x93, 0x85, 0x99, 0xAA, 0x7D, 0xDC, 0xF9, 0x2E,
  36091. 0x44, 0x56, 0x9B, 0xFA, 0x9D, 0x91, 0x2A, 0x8E,
  36092. 0x89, 0x48, 0x51, 0xE3, 0xD0, 0x53, 0xB3, 0xAD,
  36093. 0x43, 0x29, 0xB7, 0x6A, 0x50, 0xC0, 0x78, 0x4D,
  36094. 0x42, 0xF3, 0x7C, 0x5F, 0x90, 0x06, 0xAC, 0x2A,
  36095. 0x9D, 0x5D, 0xE5, 0x18, 0x3F, 0xA3, 0xC6, 0x5E,
  36096. 0xCD, 0xB6, 0xCF, 0x31, 0x67, 0xA4, 0x7A, 0x8F,
  36097. 0x5C, 0x59, 0xBD, 0xD7, 0x9B, 0x7C, 0x24, 0x06,
  36098. 0x97, 0xE1, 0x59, 0x72, 0x85, 0x02, 0x74, 0xFE,
  36099. 0x41, 0xAD, 0x84, 0xD9, 0x0D, 0xCB, 0x34, 0x16,
  36100. 0x11, 0xE7, 0x66, 0xD2, 0x12, 0xDC, 0x76, 0x3C,
  36101. 0xF9, 0x4C, 0x8C, 0x41, 0x94, 0xCC, 0xA9, 0x1B,
  36102. 0x21, 0x03, 0x28, 0xE4, 0xA3, 0x37, 0x4E, 0x29,
  36103. 0xD2, 0x48, 0x11, 0x2B, 0xB6, 0x68, 0xA3, 0x92,
  36104. 0xC2, 0x0D, 0x87, 0x91, 0x03, 0x76, 0xB5, 0x00,
  36105. 0x1F, 0x3F, 0xFB, 0xBE, 0xC3, 0xE0, 0x08, 0xBF,
  36106. 0x2F, 0x46, 0xF7, 0x40, 0x73, 0x83, 0xA8, 0x0D,
  36107. 0xDA, 0x08, 0x2B, 0xDB, 0x8F, 0xE9, 0x25, 0xE4,
  36108. 0xF1, 0x2B, 0x37, 0x92, 0x27, 0x0E, 0x5A, 0x46,
  36109. 0xB8, 0xC5, 0x7B, 0x6E, 0x5A, 0x4B, 0x95, 0x58,
  36110. 0x4E, 0xF3, 0x80, 0xED, 0x49, 0x93, 0xEC, 0x52,
  36111. 0x9F, 0xF2, 0xAA, 0x39, 0xDD, 0x6D, 0xFE, 0x88,
  36112. 0xFD, 0xEB, 0x6E, 0xDA, 0x0E, 0x8D, 0xA7, 0x95,
  36113. 0x66, 0xB0, 0x7D, 0x37, 0xAE, 0xCC, 0x64, 0x37,
  36114. 0x25, 0x95, 0x18, 0xF9, 0x7E, 0x6C, 0x86, 0x12,
  36115. 0xB3, 0xC3, 0x57, 0x03, 0xBF, 0xF9, 0x92, 0x15,
  36116. 0x3E, 0x66, 0x0E, 0x2E, 0x20, 0x77, 0xA0, 0x5F,
  36117. 0x26, 0x5F, 0xB5, 0x12, 0x1D, 0xD7, 0x9F, 0x0A,
  36118. 0x33, 0xBC, 0x38, 0xEC, 0x83, 0x08, 0xE2, 0xA9,
  36119. 0x84, 0xCD, 0x3D, 0x8A, 0xC6, 0x09, 0x30, 0x6F,
  36120. 0x77, 0x93, 0xD7, 0xDE, 0x08, 0xD8, 0x45, 0xA4,
  36121. 0x21, 0x28, 0x26, 0x4E, 0x5C, 0x17, 0x77, 0x74,
  36122. 0xE3, 0x5D, 0x58, 0x7C, 0x96, 0xB2, 0x47, 0x05,
  36123. 0x42, 0x21, 0x78, 0x5D, 0xB3, 0x8D, 0xDC, 0x6F,
  36124. 0xDB, 0xF7, 0xBF, 0x6F, 0x66, 0x4B, 0xD6, 0x30,
  36125. 0x14, 0xC0, 0xBF, 0x94, 0x2A, 0x83, 0x91, 0x6C,
  36126. 0xBF, 0x2C, 0x42, 0x85, 0x41, 0xED, 0xA2, 0xBB,
  36127. 0xCB, 0xFC, 0xF9, 0x35, 0xDE, 0xFC, 0xB3, 0x63,
  36128. 0xE1, 0x64, 0xAA, 0x51, 0x2D, 0xD5, 0xFA, 0x79,
  36129. 0x53, 0x31, 0x40, 0x0B, 0x9B, 0xD0, 0x3C, 0xE3,
  36130. 0xD7, 0x2D, 0x91, 0x05, 0x62, 0xC3, 0x81, 0xFE,
  36131. 0x93, 0x1E, 0x8C, 0x37, 0x9E, 0x30, 0x23, 0x73,
  36132. 0x3A, 0xB9, 0x18, 0x6E, 0x5D, 0xEF, 0x31, 0xE9,
  36133. 0xF6, 0x25, 0x7F, 0xB8, 0x47, 0x74, 0xCE, 0x28,
  36134. 0x23, 0xD4, 0x4F, 0xC1, 0x42, 0xCB, 0xEB, 0x59,
  36135. 0x8A, 0x68, 0xFD, 0x39, 0x48, 0x37, 0x1A, 0x5D,
  36136. 0x0C, 0x09, 0x64, 0xC6, 0xE1, 0x21, 0x5D, 0x89,
  36137. 0xF6, 0x58, 0xE5, 0x50, 0x4A, 0xD0, 0x93, 0xBC,
  36138. 0x86, 0x02, 0xBA, 0xD2, 0x36, 0x24, 0x9D, 0x7E,
  36139. 0xAF, 0xB6, 0xA1, 0xA0, 0x7C, 0xA7, 0xC7, 0x4D,
  36140. 0xAC, 0x30, 0x7A, 0x70, 0x0F, 0x2F, 0x81, 0x40,
  36141. 0xC1, 0x08, 0x6B, 0x21, 0xF2, 0xE1, 0x51, 0x9C,
  36142. 0x1D, 0x46, 0x94, 0x93, 0x2A, 0x1C, 0x18, 0xCB,
  36143. 0xED, 0x0D, 0x0E, 0x29, 0xDE, 0xFC, 0x52, 0x52,
  36144. 0x97, 0x93, 0x70, 0x85, 0xE2, 0x63, 0x0D, 0xC6,
  36145. 0x2C, 0x0C, 0x05, 0x0C, 0x4F, 0xF2, 0x70, 0x87,
  36146. 0x2B, 0xE7, 0xBB, 0x52, 0x2D, 0xD6, 0x99, 0x1B,
  36147. 0x59, 0x6F, 0xC2, 0x92, 0x11, 0x72, 0x5D, 0x99,
  36148. 0x60, 0xB1, 0x6A, 0x52, 0xEA, 0x91, 0x78, 0x19,
  36149. 0x23, 0xC0, 0x3B, 0x71, 0x9D, 0x09, 0xD6, 0xE7,
  36150. 0x10, 0x6D, 0xC5, 0x70, 0x55, 0xC1, 0x9E, 0xF8,
  36151. 0x76, 0xE5, 0xEC, 0x23, 0x17, 0xE7, 0xE4, 0x23,
  36152. 0xC9, 0x71, 0x45, 0x40, 0x72, 0x01, 0x9E, 0x28,
  36153. 0xE6, 0x5C, 0x81, 0xED, 0x52, 0x7A, 0xF1, 0x89,
  36154. 0xBD, 0xFC, 0xF5, 0x21, 0xC9, 0x23, 0x40, 0x75,
  36155. 0x54, 0xAC, 0xBF, 0x69, 0x45, 0xD1, 0x85, 0x44,
  36156. 0x3D, 0xAC, 0x1A, 0x1A, 0x08, 0x8A, 0x68, 0xB5,
  36157. 0x17, 0xD5, 0xD9, 0x90, 0xE1, 0x10, 0x30, 0xDE,
  36158. 0x4F, 0x75, 0x09, 0xE8, 0x7A, 0x77, 0xB3, 0x7C,
  36159. 0xF2, 0x0A, 0x78, 0xE2, 0xCD, 0x48, 0x94, 0x17,
  36160. 0x3C, 0x32, 0xA3, 0x27, 0x35, 0x51, 0x16, 0xB7,
  36161. 0x18, 0x51, 0x44, 0x42, 0x65, 0x60, 0x6A, 0x0A,
  36162. 0x9A, 0x6D, 0x94, 0x61, 0xCC, 0x5D, 0xD8, 0x3B,
  36163. 0x52, 0x7E, 0x4D, 0xBD, 0x6A, 0xEE, 0x03, 0x3D,
  36164. 0x66, 0x1C, 0x3D, 0xE8, 0xC1, 0x82, 0x97, 0xE5,
  36165. 0xD1, 0x31, 0xDB, 0xC8, 0xF6, 0x96, 0xE9, 0x47,
  36166. 0xC9, 0x5C, 0x71, 0x77, 0x2B, 0x62, 0x44, 0x74,
  36167. 0x4D, 0x06, 0x1E, 0x14, 0x45, 0x3B, 0x9F, 0xB1,
  36168. 0x17, 0x34, 0x80, 0x2D, 0xBA, 0x6F, 0x81, 0x79,
  36169. 0xB8, 0x0D, 0xAC, 0xFE, 0xB6, 0xBA, 0xDF, 0xD1,
  36170. 0x4E, 0x05, 0x76, 0x73, 0x6F, 0x80, 0x10, 0xC5,
  36171. 0x32, 0x87, 0xA3, 0xD3, 0x93, 0x18, 0x79, 0xEF,
  36172. 0x27, 0x3B, 0xBF, 0xCD, 0xB5, 0xDE, 0x5B, 0x88,
  36173. 0xAF, 0x51, 0xFD, 0x8A, 0x8C, 0x8F, 0x0A, 0x58,
  36174. 0x94, 0xE2, 0x25, 0xDF, 0xE8, 0x73, 0xFC, 0xC0,
  36175. 0x3C, 0xB1, 0xC9, 0xB5, 0x78, 0x25, 0xF1, 0x11,
  36176. 0x75, 0xC8, 0x7D, 0x08, 0x78, 0xB9, 0xE6, 0x15,
  36177. 0x6B, 0x40, 0x1B, 0x2F, 0xBE, 0x30, 0x03, 0x6B,
  36178. 0xFC, 0x7D, 0xB1, 0x00, 0x02, 0x71, 0xB7, 0xFF,
  36179. 0x5D, 0x63, 0xA8, 0x09, 0x50, 0x75, 0xEF, 0xBD,
  36180. 0x34, 0xEE, 0x73, 0xDE, 0x60, 0x14, 0x95, 0x2D,
  36181. 0x15, 0xBC, 0x30, 0x23, 0x07, 0x02, 0xD8, 0x7C,
  36182. 0x9A, 0x96, 0xD5, 0xE9, 0xF1, 0xF0, 0xF9, 0x26,
  36183. 0x25, 0x96, 0xAA, 0x58, 0xB7, 0xE4, 0x1A, 0xD9,
  36184. 0xA0, 0x9E, 0xAD, 0xB9, 0x44, 0xB6, 0x3F, 0xD9,
  36185. 0x8B, 0x34, 0x7D, 0x11, 0xBD, 0x52, 0x97, 0xC3,
  36186. 0xBE, 0x28, 0x23, 0x85, 0x9F, 0x2F, 0x35, 0xA4,
  36187. 0xE5, 0x4E, 0x13, 0x68, 0x89, 0x09, 0xC3, 0x1A,
  36188. 0x83, 0xE7, 0xDE, 0xCE, 0x4B, 0xDF, 0x31, 0x03,
  36189. 0x9C, 0x72, 0xBA, 0x54, 0xA1, 0x20, 0x2D, 0x17,
  36190. 0x2A, 0x6B, 0x8A, 0x2C, 0xE9, 0x6D, 0xED, 0xCA,
  36191. 0x5B, 0x24, 0xF7, 0xB9, 0x42, 0xC1, 0x4E, 0x13,
  36192. 0x3D, 0xAA, 0x8A, 0xB8, 0xCB, 0xD2, 0x4C, 0x1F,
  36193. 0x0B, 0xBE, 0xB1, 0x27, 0x97, 0x67, 0x26, 0x72,
  36194. 0xE2, 0x2C, 0xE6, 0xC2, 0x12, 0x37, 0xB2, 0x79,
  36195. 0x7D, 0x8E, 0x54, 0xCC, 0x8F, 0xC7, 0x6C, 0x43,
  36196. 0xB4, 0x75, 0x29, 0x66, 0xA3, 0xA4, 0x09, 0x44,
  36197. 0xE7, 0x2D, 0x37, 0x3F, 0x0D, 0x3E, 0x84, 0xF9,
  36198. 0xA3, 0x30, 0x1E, 0xAE, 0x9E, 0xDA, 0x35, 0x44,
  36199. 0x4B, 0x1E, 0x49, 0xE6, 0x61, 0x18, 0x20, 0x6A,
  36200. 0x56, 0xEB, 0x46, 0xD4, 0x8D, 0x20, 0x95, 0x4A,
  36201. 0x77, 0x9A, 0x1E, 0x74, 0xE3, 0xE3, 0xB2, 0xBD,
  36202. 0x40, 0x3D, 0x46, 0xB3, 0x35, 0x10, 0x11, 0xCB,
  36203. 0x6F, 0x8A, 0x86, 0x72, 0xB2, 0xF3, 0xD9, 0x90,
  36204. 0x31, 0x47, 0x55, 0x77, 0x6C, 0xE3, 0x23, 0x7F,
  36205. 0x0A, 0x50, 0xE7, 0x71, 0x20, 0x53, 0x09, 0xC0,
  36206. 0x5D, 0x9A, 0x78, 0xD3, 0x68, 0x88, 0xA8, 0x3B,
  36207. 0xAD, 0x78, 0xE8, 0x6E, 0xDF, 0x36, 0xA8, 0x8D,
  36208. 0xC7, 0x1C, 0x5F, 0x11, 0x56, 0x83, 0x90, 0xD0,
  36209. 0xB5, 0x92, 0x02, 0xE2, 0x9E, 0xE1, 0x1E, 0xCB,
  36210. 0x9F, 0x56, 0x89, 0x63, 0xE8, 0x17, 0x70, 0x83,
  36211. 0x9F, 0xF2, 0x39, 0xAD, 0x03, 0x15, 0x6C, 0xC0,
  36212. 0x71, 0xE8, 0xB7, 0x40, 0x15, 0x95, 0xEC, 0xEE,
  36213. 0x62, 0x34, 0xAC, 0x34, 0xB7, 0x11, 0x70, 0x3D,
  36214. 0x68, 0xC6, 0x7A, 0x28, 0x83, 0xBE, 0x9C, 0x18,
  36215. 0xAB, 0x7F, 0x1A, 0x1B, 0x2E, 0x5C, 0x90, 0xA2,
  36216. 0x32, 0x3C, 0xDF, 0x1E, 0xD4, 0x98, 0x50, 0xB8,
  36217. 0x39, 0x38, 0x19, 0x2F, 0x62, 0x8C, 0x9E, 0xF6,
  36218. 0x5B, 0x77, 0x93, 0x95, 0xEE, 0x37, 0x34, 0xC7,
  36219. 0xA9, 0x01, 0xF7, 0x47, 0x38, 0x86, 0xD7, 0x12,
  36220. 0xD2, 0x15, 0x41, 0x68, 0x16, 0xC3, 0x01, 0x6C,
  36221. 0xC2, 0x83, 0x83, 0xD4, 0x78, 0x7B, 0x46, 0xF6,
  36222. 0x89, 0xDC, 0xE1, 0x11, 0xDA, 0x4D, 0xB8, 0xAC,
  36223. 0x10, 0xE8, 0x4F, 0x66, 0xA5, 0xC2, 0xBD, 0xA1,
  36224. 0xB3, 0xFC, 0x97, 0x7F, 0x6A, 0x0F, 0x73, 0x2E,
  36225. 0xDA, 0x4F, 0x69, 0xB9, 0x75, 0x51, 0xA4, 0xB8,
  36226. 0xB2, 0x61, 0xD6, 0x88, 0x71, 0x94, 0xD3, 0xAF,
  36227. 0xE7, 0xF4, 0xB8, 0x7F, 0xB3, 0xD4, 0x1A, 0xC6,
  36228. 0xDC, 0xDB, 0x8F, 0xD3, 0x9B, 0xE5, 0x0F, 0x2F,
  36229. 0x38, 0x2B, 0xAA, 0x4D, 0x19, 0xC7, 0x45, 0x0A,
  36230. 0xB3, 0xA1, 0xAC, 0x4C, 0x63, 0xCF, 0x93, 0x0A,
  36231. 0xAA, 0x51, 0x7A, 0x15, 0xD5, 0xC0, 0xD5, 0x49,
  36232. 0xFE, 0x03, 0x22, 0x00, 0x71, 0xD3, 0x69, 0x22,
  36233. 0x3E, 0x51, 0x29, 0x6E, 0xCB, 0xF8, 0x0D, 0xCD,
  36234. 0x79, 0xFB, 0xDF, 0xB8, 0xDF, 0x62, 0x90, 0x4D,
  36235. 0x5A, 0x36, 0x20, 0x0F, 0x29, 0xCC, 0x47, 0xE8,
  36236. 0x0C, 0x86, 0x15, 0xEF, 0x1B, 0x78, 0xDB, 0xB2,
  36237. 0x6A, 0x1A, 0xA7, 0xA6, 0x6E, 0x4D, 0x9A, 0x51,
  36238. 0xC9, 0x72, 0xAC, 0x9C, 0x94, 0xEA, 0xB9, 0x95,
  36239. 0x14, 0xB5, 0xAD, 0xAE, 0x62, 0x51, 0xE8, 0xAA,
  36240. 0x30, 0xA5, 0xE5, 0x87, 0x42, 0x4E, 0x3B, 0x7B,
  36241. 0xCC, 0x42, 0xEB, 0xE7, 0x33, 0x3D, 0x92, 0x10,
  36242. 0x97, 0x26, 0x53, 0xF8, 0x11, 0x8B, 0x83, 0xAB,
  36243. 0xE1, 0xBF, 0x7E, 0x9E, 0xE9, 0xCD, 0xAC, 0x28,
  36244. 0x99, 0x7D, 0x14, 0x4C, 0x34, 0xDE, 0xA6, 0x5B,
  36245. 0x59, 0x51, 0x2C, 0x73, 0x29, 0x27, 0xDB, 0xA8,
  36246. 0x20, 0x7D, 0x56, 0x91, 0x98, 0x47, 0x21, 0xB7,
  36247. 0x27, 0x9A, 0xFC, 0xDD, 0xE0, 0x6A, 0x6B, 0xD2,
  36248. 0x68, 0x0E, 0xBB, 0x9B, 0x2E, 0x3C, 0xFE, 0xE9,
  36249. 0xA6, 0x6D, 0x73, 0xD0, 0xC0, 0xDE, 0xD6, 0x53,
  36250. 0x70, 0x8B, 0x09, 0x0B, 0x82, 0x30, 0x65, 0xF9,
  36251. 0x70, 0x78, 0x49, 0xE3, 0xB3, 0x7D, 0x41, 0x25,
  36252. 0xCA, 0x69, 0x3E, 0x74, 0x2E, 0x02, 0x3F, 0x05,
  36253. 0x8A, 0xDC, 0x95, 0x07, 0x9B, 0xB0, 0x0C, 0x56,
  36254. 0xBE, 0x0D, 0x2F, 0x07, 0x81, 0x82, 0xEF, 0xAB,
  36255. 0x30, 0x72, 0xB0, 0xFD, 0x09, 0x76, 0x7B, 0x8A,
  36256. 0x13, 0xC2, 0x80, 0x5A, 0x75, 0x91, 0xB5, 0xB2,
  36257. 0xE1, 0x24, 0x75, 0xB5, 0xC8, 0x24, 0xDB, 0xEB,
  36258. 0x15, 0x79, 0x30, 0xAB, 0x38, 0x9F, 0x91, 0x5F,
  36259. 0xCC, 0xEC, 0x8F, 0x48, 0x64, 0x7E, 0xE4, 0xB6,
  36260. 0x6A, 0xB6, 0xB5, 0x36, 0xC2, 0x2D, 0xE3, 0xE5,
  36261. 0xEE, 0x4A, 0xBB, 0x42, 0xF8, 0xE0, 0x00, 0x9A,
  36262. 0xF0, 0x45, 0x54, 0xF1, 0x28, 0xAC, 0xA3, 0xCC,
  36263. 0xE4, 0x03, 0xBB, 0x01, 0xFD, 0xB7, 0xB5, 0xE2,
  36264. 0xA7, 0x2B, 0x82, 0x91, 0x1C, 0x1F, 0xD0, 0x65,
  36265. 0x23, 0xFF, 0x90, 0x19, 0x21, 0x41, 0xC6, 0x89,
  36266. 0xEC, 0xCB, 0x0B, 0xE6, 0x1B, 0x4C, 0x6D, 0x77,
  36267. 0x06, 0x29, 0x59, 0x02, 0x18, 0xA4, 0x01, 0x1A,
  36268. 0x68, 0xB8, 0x6F, 0xF5, 0x0D, 0x23, 0x03, 0x9C,
  36269. 0x9B, 0xCD, 0x43, 0x61, 0xF6, 0x98, 0x0A, 0x60,
  36270. 0xEF, 0x88, 0xD1, 0x44, 0x0D, 0x30, 0x4C, 0x5B,
  36271. 0x4B, 0x52, 0xD6, 0xED, 0xC2, 0x91, 0x12, 0xDC,
  36272. 0x3A, 0x8A, 0xF2, 0x85, 0x89, 0xE8, 0xF6, 0x29,
  36273. 0x48, 0xED, 0xB6, 0xBE, 0x76, 0x64, 0x6D, 0x59,
  36274. 0x66, 0x06, 0xB9, 0xE7, 0x05, 0xFE, 0xE3, 0xF1,
  36275. 0x44, 0xA0, 0x7B, 0xC9, 0xED, 0x1D, 0x40, 0x0C
  36276. };
  36277. static const byte msg_65[] = {
  36278. 0x88, 0x5A, 0x0B, 0xDD, 0x8D, 0xE7, 0x4B, 0xC7,
  36279. 0x11, 0x69, 0x0A, 0xA6, 0x14, 0xDD, 0xA5, 0x32,
  36280. 0xF4, 0xD8, 0xC7, 0xEA, 0x2C, 0x27, 0x85, 0x5A,
  36281. 0x57, 0x8E, 0x63, 0x61, 0xCA, 0xAE, 0x2C, 0x0B,
  36282. 0xF7, 0xE7, 0x73, 0xB4, 0x90, 0x0A, 0x32, 0x93,
  36283. 0x12, 0x1A, 0x6E, 0x0D, 0xD6, 0x10, 0x10, 0x7A,
  36284. 0x7A, 0x65, 0xBD, 0x6E, 0x11, 0xF6, 0x19, 0xFC,
  36285. 0x0E, 0x9C, 0xE7, 0xBF, 0x7B, 0x5D, 0xE1, 0x80,
  36286. 0x76, 0xE1, 0xB7, 0x25, 0x57, 0x20, 0x97, 0xB2,
  36287. 0x47, 0xD8, 0xE0, 0x46, 0x24, 0x94, 0xF6, 0x3F,
  36288. 0x4E, 0xDF, 0xBE, 0xAC, 0x2F, 0xA2, 0xEC, 0xAE,
  36289. 0x0C, 0xCA, 0xD4, 0x28, 0xBD, 0x79, 0x6C, 0xF2,
  36290. 0x60, 0x92, 0xA1, 0xCD, 0x50, 0x5F, 0x59, 0x39,
  36291. 0x11, 0xED, 0x10, 0xFD, 0xA4, 0x26, 0xC7, 0xE3,
  36292. 0xC5, 0xA4, 0x39, 0xE8, 0x50, 0x42, 0x13, 0x18,
  36293. 0xAE, 0x07, 0x85, 0xB0, 0x5A, 0xA9, 0x9F, 0x58,
  36294. 0xD6, 0x85, 0x6D, 0xEB, 0x78, 0xBB, 0xE4, 0x88,
  36295. 0xC7, 0x0E, 0xEE, 0x42, 0xBB, 0x9A, 0xB5, 0x92,
  36296. 0x7B, 0x2E, 0xD2, 0x5C, 0xD1, 0x43, 0x77, 0xCD,
  36297. 0x7E, 0x1A, 0x88, 0x34, 0xE8, 0x21, 0x48, 0x00,
  36298. 0x2F, 0xCB, 0x98, 0x5A, 0xB9, 0x43, 0x12, 0x97,
  36299. 0x01, 0x0B, 0x2B, 0xC7, 0x0F, 0x91, 0x32, 0x37,
  36300. 0x3C, 0x6D, 0xD2, 0xA2, 0xA9, 0xCF, 0x24, 0x6F,
  36301. 0xE0, 0x26, 0x2E, 0x8B, 0x53, 0xE6, 0x93, 0xF3,
  36302. 0xD6, 0xFE, 0xD3, 0xED, 0xD1, 0xF2, 0x00, 0x4E,
  36303. 0xD1, 0x7C, 0x2C, 0xF5, 0xB2, 0x57, 0xF4, 0xAD,
  36304. 0xA5, 0xDC, 0x1A, 0x7C, 0x15, 0x1F, 0xFE, 0x03,
  36305. 0xB9, 0x6A, 0x4D, 0xB9, 0x91, 0xE4, 0x13, 0x2D,
  36306. 0x01, 0xDE, 0x1F, 0x03, 0x3E, 0xD8, 0x13, 0x57,
  36307. 0xEA, 0xE7, 0xC1, 0xA8, 0xD2, 0xDD, 0xD9, 0x2D,
  36308. 0xDF, 0xC0, 0x6F, 0x67, 0x13, 0x94, 0xD2, 0xF6,
  36309. 0x02, 0x12, 0xC6, 0xE4, 0x49, 0xEA, 0x35, 0x93,
  36310. 0x24, 0xFE, 0xD3, 0x8C, 0x84, 0xD3, 0x6D, 0x15,
  36311. 0x43, 0x2E, 0x11, 0xE7, 0x15, 0x00, 0x15, 0x80,
  36312. 0x4F, 0x97, 0xA3, 0xC6, 0x77, 0x38, 0x2C, 0xD4,
  36313. 0x6A, 0xA4, 0xD7, 0xAC, 0xEE, 0x56, 0x86, 0xFB,
  36314. 0xCE, 0xD7, 0xA9, 0xE8, 0x5D, 0x29, 0xC4, 0x83,
  36315. 0x86, 0xE6, 0x9F, 0x40, 0x69, 0x3D, 0x9A, 0xDA,
  36316. 0xBE, 0xB4, 0x3B, 0xD0, 0xE5, 0x03, 0x6A, 0xCD,
  36317. 0xE6, 0x31, 0xB5, 0x49, 0x57, 0xF4, 0xFC, 0xE2,
  36318. 0x6F, 0x7A, 0x24, 0xB0, 0xDA, 0xD4, 0x34, 0x8A,
  36319. 0x67, 0x89, 0xCA, 0xE1, 0x06, 0x13, 0x06, 0x20,
  36320. 0xED, 0x2F, 0xA0, 0xEA, 0x38, 0xF5, 0x75, 0xF2,
  36321. 0x87, 0x83, 0xBC, 0x92, 0xB3, 0x2B, 0x0C, 0x51,
  36322. 0xC8, 0xA6, 0x54, 0x6F, 0x5D, 0x88, 0x09, 0x5F,
  36323. 0x9F, 0x73, 0xC6, 0x5B, 0xF6, 0xF2, 0x51, 0xA2,
  36324. 0xC4, 0x69, 0x74, 0x64, 0x45, 0xC5, 0x88, 0xC3,
  36325. 0xEA, 0x81, 0x39, 0xE4, 0x33, 0xD4, 0xFE, 0x2D,
  36326. 0xE4, 0xC0, 0xD3, 0x58, 0xB6, 0xCA, 0x8A, 0x62,
  36327. 0x94, 0xE6, 0xAF, 0xC1, 0xB9, 0x60, 0x74, 0xC0,
  36328. 0x68, 0xEF, 0x67, 0xB1, 0x58, 0xF1, 0x12, 0x9C,
  36329. 0xFE, 0x0A, 0x3A, 0xE7, 0xEB, 0x9D, 0x45, 0x4F,
  36330. 0x35, 0x7F, 0xBB, 0x6A, 0xB3, 0xB9, 0x92, 0x2B,
  36331. 0x1B, 0xCD, 0x55, 0x58, 0x61, 0x87, 0xCD, 0x24,
  36332. 0x69, 0x24, 0x82, 0x78, 0x23, 0x34, 0xAC, 0x9F,
  36333. 0x2B, 0x86, 0x12, 0x48, 0xF6, 0xA5, 0x30, 0xE9,
  36334. 0x3E, 0x11, 0x48, 0x87, 0x84, 0xDD, 0xE5, 0xEA,
  36335. 0x67, 0x8A, 0xE5, 0x05, 0x90, 0x3E, 0x23, 0x10,
  36336. 0x53, 0x30, 0x8C, 0x1B, 0x87, 0x84, 0x60, 0x7E,
  36337. 0x06, 0x3F, 0x48, 0x98, 0xA4, 0xFA, 0xB6, 0x01,
  36338. 0xD3, 0xE6, 0x96, 0x85, 0x97, 0x21, 0x55, 0xF6,
  36339. 0x3F, 0x09, 0xFD, 0x84, 0xB2, 0xB3, 0xDF, 0x74,
  36340. 0x1F, 0xB6, 0x42, 0xAC, 0xA6, 0x03, 0xD0, 0xD5,
  36341. 0x96, 0xE0, 0xA8, 0xDA, 0xD4, 0x24, 0xF4, 0x64,
  36342. 0x0F, 0x98, 0xB9, 0x6F, 0xB2, 0x42, 0xC6, 0x95,
  36343. 0xDC, 0x33, 0x1F, 0x57, 0x59, 0xF7, 0x5E, 0xAF,
  36344. 0x19, 0x1C, 0xBD, 0x98, 0x5E, 0xC5, 0x99, 0x8D,
  36345. 0x56, 0x48, 0xC8, 0x5E, 0xB6, 0x31, 0x29, 0x5F,
  36346. 0x61, 0x56, 0x7C, 0x11, 0x63, 0xF9, 0x90, 0xDC,
  36347. 0x4F, 0xA1, 0x71, 0x40, 0x91, 0x26, 0x1E, 0x5F,
  36348. 0x3E, 0x5F, 0x0B, 0xFE, 0x84, 0x55, 0xBB, 0x8B,
  36349. 0xAA, 0x1D, 0x69, 0x42, 0x1F, 0x15, 0x37, 0x4E,
  36350. 0x73, 0xB0, 0x7E, 0x78, 0x57, 0x9D, 0x0E, 0x25,
  36351. 0x1A, 0x41, 0xEE, 0x1A, 0x50, 0x43, 0xAA, 0xBF,
  36352. 0x8B, 0xE7, 0x73, 0xEE, 0x7F, 0x9D, 0x0F, 0xDF,
  36353. 0xCF, 0xD3, 0xAE, 0x71, 0x1F, 0xAB, 0x1D, 0x3D,
  36354. 0xBC, 0xC2, 0x84, 0x3B, 0xE5, 0xA9, 0x46, 0xB2,
  36355. 0x4D, 0x8B, 0x9B, 0x94, 0x35, 0x8B, 0x5F, 0x59,
  36356. 0x8E, 0x88, 0xED, 0x3D, 0x53, 0xF3, 0x10, 0xF8,
  36357. 0xEC, 0x63, 0x22, 0x9D, 0x4F, 0x5B, 0xB1, 0xB6,
  36358. 0xD5, 0x24, 0xA5, 0xAF, 0x9C, 0x39, 0x47, 0x79,
  36359. 0x25, 0xC7, 0xE2, 0x90, 0x95, 0xFC, 0x43, 0xF1,
  36360. 0x71, 0xFE, 0xCD, 0xD0, 0x61, 0xF3, 0x62, 0x62,
  36361. 0x71, 0x21, 0x75, 0x2C, 0x23, 0x6B, 0x79, 0x2F,
  36362. 0x1B, 0x31, 0x90, 0x79, 0x7C, 0xD0, 0x57, 0x5C,
  36363. 0x58, 0x4F, 0x30, 0xB5, 0x56, 0x81, 0x19, 0x61,
  36364. 0x90, 0x45, 0x09, 0xC9, 0x8B, 0xCD, 0xE8, 0x65,
  36365. 0x9D, 0x22, 0x80, 0xF4, 0x95, 0xA0, 0xC9, 0x55,
  36366. 0x7D, 0x38, 0x11, 0xAF, 0x5E, 0xD4, 0x37, 0x7B,
  36367. 0xC7, 0x59, 0x9E, 0x49, 0x59, 0xFF, 0x85, 0xF2,
  36368. 0x15, 0x0A, 0xCD, 0xEC, 0xC1, 0xF7, 0x67, 0x2D,
  36369. 0xE1, 0xEE, 0x4D, 0xB4, 0x4C, 0x1F, 0xB5, 0xF7,
  36370. 0x99, 0x8A, 0xB5, 0xDB, 0x74, 0x2F, 0x6C, 0x5D,
  36371. 0x32, 0xCB, 0xC0, 0xF2, 0xFB, 0xC9, 0x54, 0xEA,
  36372. 0xD6, 0xCC, 0x13, 0x4B, 0x97, 0x62, 0xDF, 0x33,
  36373. 0x13, 0x86, 0xDE, 0xCA, 0x31, 0x69, 0x47, 0x88,
  36374. 0x4B, 0x9A, 0x13, 0xAD, 0xEA, 0x5C, 0xBE, 0x29,
  36375. 0x56, 0x64, 0x4F, 0xA1, 0x2A, 0x7B, 0xB3, 0xBF,
  36376. 0xB9, 0x7E, 0x1D, 0x93, 0xA7, 0x01, 0x91, 0xAC,
  36377. 0x38, 0xA0, 0x37, 0x32, 0x58, 0xC2, 0xC2, 0x81,
  36378. 0x6D, 0xEA, 0x6E, 0xAF, 0x88, 0x0D, 0x69, 0xF4,
  36379. 0x5F, 0xBA, 0x4C, 0x29, 0x0F, 0x18, 0xD3, 0x4B,
  36380. 0xB8, 0x36, 0x8C, 0xF4, 0xEB, 0xB4, 0x72, 0xBA,
  36381. 0x49, 0x9C, 0xBB, 0x54, 0x50, 0x1E, 0xE3, 0xA2,
  36382. 0x8E, 0x5F, 0xB9, 0xFD, 0xC6, 0x6C, 0xF6, 0x45,
  36383. 0x72, 0x09, 0x47, 0x19, 0xBB, 0xDB, 0x48, 0xF3,
  36384. 0xF4, 0x88, 0x51, 0x3B, 0x65, 0x50, 0xE1, 0x27,
  36385. 0xE8, 0x34, 0x1C, 0x7E, 0x53, 0xDC, 0xFD, 0xA7,
  36386. 0xD4, 0x08, 0x05, 0x58, 0x0B, 0xC7, 0xD3, 0x0A,
  36387. 0x72, 0xF2, 0x44, 0xCC, 0xDB, 0x5A, 0xEF, 0x66,
  36388. 0x1B, 0x0F, 0x30, 0x4E, 0xC5, 0xB7, 0xAB, 0x93,
  36389. 0xB8, 0xC5, 0xC4, 0x9A, 0x77, 0x68, 0x38, 0xB7,
  36390. 0xD5, 0x23, 0x74, 0xAA, 0x41, 0x63, 0x02, 0x24,
  36391. 0xD6, 0x16, 0xF3, 0x10, 0xE4, 0x99, 0xEC, 0xAD,
  36392. 0xCE, 0x93, 0xE7, 0x8B, 0x94, 0xD3, 0xCA, 0x48,
  36393. 0xB3, 0x47, 0xBC, 0x0E, 0xEC, 0xAA, 0x20, 0x66,
  36394. 0x02, 0x29, 0x65, 0xC8, 0x07, 0xBE, 0xF9, 0x02,
  36395. 0x9B, 0xC5, 0x22, 0x8F, 0x00, 0x5E, 0xDB, 0x74,
  36396. 0xD4, 0xB1, 0x44, 0x98, 0xCE, 0x3A, 0xE1, 0x3B,
  36397. 0xEB, 0x7C, 0x69, 0x3B, 0x66, 0x9E, 0xE9, 0xF9,
  36398. 0xA6, 0xF4, 0x6F, 0xC0, 0x0E, 0xC0, 0x5E, 0x13,
  36399. 0x2B, 0xB6, 0xC6, 0x76, 0x0F, 0xB5, 0xC5, 0x1C,
  36400. 0x83, 0x23, 0xAC, 0xD6, 0xA3, 0xC7, 0x5A, 0x72,
  36401. 0xE9, 0x73, 0x89, 0x66, 0xD1, 0x25, 0xB9, 0x61,
  36402. 0x3B, 0x31, 0x45, 0xC6, 0x7B, 0x5E, 0x98, 0x81,
  36403. 0x87, 0xE8, 0x5F, 0x29, 0xAD, 0xCB, 0xAF, 0x74,
  36404. 0xE3, 0x3A, 0x61, 0x1F, 0xFF, 0x25, 0x2A, 0xEB,
  36405. 0xBA, 0xEB, 0x1E, 0xA6, 0x41, 0xE6, 0xFC, 0x8B,
  36406. 0xDF, 0x73, 0x41, 0xBE, 0x2A, 0xA8, 0x57, 0xE4,
  36407. 0x43, 0xAC, 0xFB, 0xCE, 0xB2, 0x15, 0x5D, 0x08,
  36408. 0x1A, 0xCB, 0x4C, 0xCD, 0xB0, 0x98, 0xD5, 0x7C,
  36409. 0xEF, 0x6F, 0x6F, 0xD3, 0x42, 0xDB, 0x2D, 0x83,
  36410. 0xB6, 0x12, 0x3E, 0x0A, 0xD3, 0xC9, 0x3F, 0x30,
  36411. 0x08, 0x11, 0xB8, 0xD5, 0xA1, 0x1A, 0x5A, 0x29,
  36412. 0xBE, 0x60, 0x81, 0x6F, 0x69, 0xB2, 0x9D, 0x1D,
  36413. 0x7E, 0x15, 0x88, 0x69, 0xD8, 0x60, 0xF6, 0xFB,
  36414. 0x82, 0x9D, 0xE8, 0x0D, 0x3E, 0x1B, 0x69, 0x9C,
  36415. 0x3A, 0xB6, 0x80, 0x4E, 0xB6, 0x54, 0x91, 0x78,
  36416. 0xD9, 0x47, 0x33, 0x38, 0xD6, 0xAF, 0x20, 0x9E,
  36417. 0x1F, 0x7D, 0x26, 0x3C, 0x66, 0x7A, 0xE6, 0x89,
  36418. 0x5F, 0x6E, 0x29, 0x33, 0x92, 0x34, 0x71, 0xF1,
  36419. 0x99, 0x58, 0x1F, 0x8A, 0x51, 0xBD, 0x9A, 0xA4,
  36420. 0x52, 0xEE, 0xE4, 0xBF, 0xE9, 0x56, 0x69, 0xAC,
  36421. 0xD0, 0x7B, 0x41, 0xB0, 0x0C, 0x03, 0xF5, 0x5A,
  36422. 0x40, 0xD1, 0x0B, 0x50, 0xF8, 0xE4, 0x67, 0xBD,
  36423. 0x07, 0x1C, 0x8F, 0x40, 0x5C, 0xF1, 0x19, 0x61,
  36424. 0x2D, 0x32, 0x40, 0x5B, 0xD5, 0x27, 0x5A, 0x6B,
  36425. 0xBF, 0x22, 0x17, 0xF9, 0xF1, 0x79, 0x0D, 0x29,
  36426. 0x99, 0x7B, 0x7B, 0x6B, 0x1E, 0xC8, 0xD7, 0x92,
  36427. 0x4A, 0xB9, 0xE6, 0x44, 0xC1, 0x29, 0xCE, 0xE8,
  36428. 0x74, 0x33, 0x29, 0x1A, 0x2C, 0x8E, 0xD6, 0xBC,
  36429. 0x3C, 0x2A, 0x19, 0xD0, 0x76, 0xB1, 0x77, 0xEE,
  36430. 0x60, 0x50, 0x69, 0x2A, 0xDA, 0x8E, 0x95, 0x57,
  36431. 0x4D, 0x6C, 0xE9, 0xAB, 0xE4, 0x97, 0x95, 0xD8,
  36432. 0xF2, 0x8E, 0xAB, 0x69, 0x67, 0x6E, 0x79, 0x03,
  36433. 0xA6, 0x56, 0xFA, 0xB3, 0x20, 0x25, 0xFE, 0x34,
  36434. 0x65, 0xCB, 0xDB, 0x57, 0x01, 0xC1, 0x77, 0x20,
  36435. 0x9D, 0x91, 0x89, 0xA5, 0x91, 0x7C, 0x13, 0x37,
  36436. 0xDE, 0x39, 0xF5, 0x75, 0xE5, 0xDD, 0xB9, 0x3C,
  36437. 0xA7, 0x6B, 0xEB, 0x52, 0xAF, 0x32, 0xE8, 0xD7,
  36438. 0x12, 0x7B, 0x28, 0xF7, 0xCE, 0x73, 0x12, 0xE8,
  36439. 0x03, 0x90, 0x47, 0x21, 0xAB, 0x21, 0x6E, 0x92,
  36440. 0xA8, 0xA9, 0xE6, 0x09, 0xFC, 0x10, 0xAF, 0x8D,
  36441. 0xC2, 0xAA, 0xCA, 0x14, 0xA9, 0x7B, 0xB0, 0xE4,
  36442. 0xB2, 0x34, 0xC7, 0x00, 0x0E, 0xBB, 0xE0, 0xC4,
  36443. 0x42, 0xF1, 0x85, 0x94, 0x6B, 0x7C, 0xE7, 0x72,
  36444. 0x80, 0x95, 0xCD, 0x60, 0x16, 0x9B, 0x0B, 0xD9,
  36445. 0x7B, 0x36, 0xB3, 0xAE, 0x38, 0x55, 0xD9, 0x89,
  36446. 0x25, 0xB2, 0x9D, 0x92, 0x94, 0xEF, 0x27, 0x75,
  36447. 0x09, 0xFC, 0xA4, 0x07, 0xEA, 0x2B, 0xC4, 0x76,
  36448. 0x59, 0x02, 0x6A, 0x82, 0x04, 0xD6, 0x96, 0x4F,
  36449. 0xC6, 0x5B, 0xEF, 0x35, 0x31, 0xE9, 0xC1, 0xE6,
  36450. 0xF9, 0x70, 0xBF, 0x2F, 0xF2, 0x40, 0x75, 0xEA,
  36451. 0x17, 0xD1, 0x36, 0xAD, 0xEA, 0xD2, 0x35, 0x6B,
  36452. 0x6C, 0xE4, 0x98, 0xF9, 0x3C, 0xD2, 0xF9, 0xE5,
  36453. 0xE1, 0x90, 0xD2, 0x09, 0xD9, 0x3E, 0x47, 0x3F,
  36454. 0xAA, 0x8E, 0xD9, 0x20, 0x96, 0x31, 0x5B, 0xF1,
  36455. 0xFC, 0xA6, 0x55, 0xFE, 0xBC, 0x78, 0xE0, 0x99,
  36456. 0x65, 0xC9, 0x74, 0x78, 0x29, 0x6B, 0x75, 0xD3,
  36457. 0x90, 0x56, 0x60, 0x4D, 0x32, 0x71, 0x91, 0x6D,
  36458. 0xCF, 0xF2, 0x25, 0xCB, 0x6B, 0x9A, 0x34, 0xE1,
  36459. 0x5D, 0xC1, 0x64, 0xB2, 0xA6, 0x8A, 0x3B, 0x42,
  36460. 0xDE, 0x05, 0x7A, 0x6B, 0xAC, 0x17, 0x32, 0xCF,
  36461. 0x59, 0x45, 0xBB, 0xCA, 0x12, 0xB8, 0xB3, 0x61,
  36462. 0x59, 0xFB, 0x89, 0xF7, 0xBB, 0xBE, 0x9F, 0xE0,
  36463. 0x34, 0x21, 0x8F, 0x5B, 0x3B, 0xCF, 0x18, 0x4C,
  36464. 0x20, 0x73, 0x06, 0xE6, 0xD2, 0xEA, 0x69, 0x59,
  36465. 0xEA, 0xE0, 0x89, 0x0A, 0x7B, 0x68, 0x02, 0xEC,
  36466. 0x1D, 0xA0, 0x82, 0xBE, 0xD6, 0x5B, 0xB6, 0xE4,
  36467. 0xEB, 0x4D, 0x56, 0x15, 0x70, 0x1C, 0xB0, 0xE3,
  36468. 0x50, 0x36, 0x33, 0x14, 0xA4, 0xD1, 0x01, 0xDB,
  36469. 0xBA, 0x60, 0x53, 0x71, 0xA3, 0x8B, 0x2D, 0x8A,
  36470. 0x37, 0xFF, 0x78, 0xEB, 0xB3, 0x69, 0x82, 0x53,
  36471. 0x88, 0xAA, 0xB7, 0xD3, 0xC6, 0x23, 0xB9, 0x3E,
  36472. 0x51, 0x2D, 0x96, 0xA9, 0xF3, 0x39, 0xEC, 0x96,
  36473. 0x8B, 0x35, 0x27, 0x59, 0xAF, 0x3E, 0x8F, 0xA3,
  36474. 0x21, 0x1C, 0x39, 0x29, 0x5B, 0x01, 0x10, 0xE6,
  36475. 0xDF, 0x26, 0x4E, 0x90, 0x67, 0x8C, 0x11, 0xE2,
  36476. 0xB9, 0x03, 0xAF, 0x32, 0x2E, 0x4F, 0xA7, 0x70,
  36477. 0x28, 0xD3, 0xEC, 0xC4, 0x4F, 0x62, 0x79, 0xD6,
  36478. 0x3B, 0x1E, 0x60, 0xD8, 0x06, 0x72, 0x41, 0x01,
  36479. 0x5F, 0xC4, 0xF8, 0x9B, 0xAA, 0x15, 0x6A, 0x78,
  36480. 0xFA, 0x77, 0xBB, 0x29, 0x14, 0xCA, 0xC2, 0x81,
  36481. 0xF4, 0x40, 0x9C, 0x9C, 0x03, 0x70, 0xAB, 0xD7,
  36482. 0xC1, 0xF8, 0xA5, 0xD1, 0x04, 0x0B, 0x59, 0x75,
  36483. 0x2C, 0xC4, 0xFD, 0xF0, 0xD1, 0x9C, 0xB0, 0xC5,
  36484. 0x6F, 0xEF, 0x34, 0xFA, 0x3A, 0x3B, 0xCE, 0xE1,
  36485. 0xF0, 0x64, 0xE3, 0x60, 0xE8, 0x6D, 0xC5, 0x5D,
  36486. 0xB5, 0xC9, 0x37, 0x5B, 0xDA, 0xDA, 0x67, 0x2E,
  36487. 0x72, 0xF6, 0x64, 0xE3, 0xAC, 0xB2, 0xE6, 0xD8,
  36488. 0xA0, 0x84, 0x09, 0xC8, 0xCD, 0x60, 0xA1, 0xF9,
  36489. 0x53, 0x80, 0xAB, 0x6C, 0x3A, 0xCB, 0x6B, 0x91,
  36490. 0xA8, 0xA9, 0xA3, 0xB7, 0x75, 0x50, 0x49, 0x79,
  36491. 0xB8, 0x02, 0x5A, 0xDB, 0x34, 0x22, 0x61, 0x9B,
  36492. 0xD1, 0x1E, 0x2B, 0x54, 0xFE, 0x6D, 0x07, 0x58,
  36493. 0x81, 0xAC, 0xAC, 0x24, 0x53, 0x20, 0x31, 0xCC,
  36494. 0xD2, 0x99, 0x06, 0x0E, 0x4E, 0xB7, 0xF7, 0xCB,
  36495. 0xD8, 0x08, 0x36, 0xD4, 0xB8, 0x23, 0xA5, 0xFF,
  36496. 0xA4, 0xFE, 0x8C, 0x6B, 0x98, 0x3D, 0x2A, 0xAE,
  36497. 0xB8, 0xF1, 0x6F, 0x6C, 0x1C, 0x22, 0x81, 0xEF,
  36498. 0xD7, 0x13, 0xFF, 0xDA, 0x22, 0x06, 0x9A, 0x5D,
  36499. 0x8A, 0xC4, 0x91, 0x29, 0x1C, 0xBF, 0x49, 0xF1,
  36500. 0x18, 0xC9, 0x46, 0xD5, 0x0F, 0x08, 0xE0, 0xD1,
  36501. 0x73, 0x28, 0x14, 0xE8, 0x15, 0x81, 0x90, 0x6A,
  36502. 0x31, 0x53, 0x94, 0x01, 0x14, 0xBE, 0xC8, 0xEB,
  36503. 0xD4, 0x9C, 0x73, 0x79, 0x0F, 0x9E, 0xD7, 0xCC,
  36504. 0xD9, 0x85, 0xED, 0xAD, 0x8D, 0xB3, 0x42, 0x6B,
  36505. 0x15, 0x13, 0x98, 0xEB, 0xF1, 0x6E, 0xFA, 0xFE,
  36506. 0x3D, 0xA0, 0xC7, 0xF3, 0x8B, 0x22, 0x76, 0x05,
  36507. 0x76, 0xD4, 0x88, 0x52, 0x73, 0xF5, 0xE4, 0x0B,
  36508. 0x14, 0x05, 0x57, 0x10, 0x7F, 0xCE, 0x0B, 0xF8,
  36509. 0x46, 0x1F, 0x24, 0x8B, 0xC4, 0x3F, 0xBF, 0x5C,
  36510. 0xEE, 0xE7, 0x6E, 0xF3, 0xA9, 0xEB, 0xD2, 0x30,
  36511. 0x95, 0x6C, 0x7B, 0x98, 0xAC, 0x89, 0x8A, 0x39,
  36512. 0x9E, 0x5C, 0x2A, 0xB0, 0xCB, 0xE9, 0xE5, 0xAB,
  36513. 0x94, 0x71, 0xDF, 0x5E, 0x53, 0x0C, 0x72, 0xF2,
  36514. 0x6C, 0x34, 0xDB, 0xFE, 0x2F, 0x83, 0x68, 0x3E,
  36515. 0xB6, 0x22, 0xF9, 0x64, 0x7A, 0xA0, 0x6A, 0x26,
  36516. 0x7D, 0x78, 0x97, 0x36, 0x31, 0x2C, 0x90, 0xC9,
  36517. 0xE5, 0x9D, 0x77, 0x12, 0x2A, 0x88, 0x53, 0x8F,
  36518. 0xD0, 0xF5, 0x39, 0x16, 0xAF, 0x08, 0xB2, 0x36,
  36519. 0x93, 0x5C, 0xDC, 0x5B, 0xB3, 0xCB, 0x49, 0x0C,
  36520. 0x83, 0x09, 0xE6, 0xA7, 0x9B, 0x43, 0xE7, 0xA5,
  36521. 0x4A, 0x8A, 0x07, 0xE1, 0xBA, 0xFB, 0x9B, 0x93,
  36522. 0x7E, 0xAC, 0x2F, 0xC3, 0xAC, 0xED, 0x30, 0x64,
  36523. 0x1F, 0x33, 0x79, 0x19, 0xD2, 0xDB, 0x54, 0xEC,
  36524. 0x7F, 0x32, 0x0E, 0xC5, 0x1C, 0xD1, 0x3C, 0x00,
  36525. 0xB9, 0xE6, 0x03, 0xDF, 0x6D, 0xD2, 0x69, 0x0C,
  36526. 0x75, 0xAF, 0x37, 0x07, 0xB7, 0xC9, 0x3E, 0x91,
  36527. 0xCF, 0x02, 0x78, 0xD7, 0x43, 0xA1, 0x8B, 0x4E,
  36528. 0x69, 0x74, 0xB4, 0x24, 0x08, 0x10, 0x42, 0xB5,
  36529. 0xB4, 0xE7, 0x8C, 0xEB, 0x7F, 0xFF, 0x67, 0x98,
  36530. 0x0B, 0xBC, 0xBA, 0x5E, 0x29, 0xBE, 0x61, 0x33,
  36531. 0x56, 0x16, 0xD6, 0x5E, 0x86, 0xF0, 0xE7, 0x46,
  36532. 0xD1, 0x83, 0xDF, 0xD4, 0x6B, 0x75, 0xC9, 0x30,
  36533. 0x0D, 0x60, 0xC5, 0x19, 0xFD, 0x95, 0xA8, 0xA6,
  36534. 0x61, 0xFF, 0xC8, 0x2A, 0xE7, 0x5D, 0xD1, 0x49,
  36535. 0x49, 0x1F, 0x99, 0xD1, 0x41, 0x4F, 0x15, 0x79,
  36536. 0x00, 0x8A, 0x80, 0x27, 0xA6, 0xC9, 0x98, 0xD3,
  36537. 0xE7, 0xA2, 0xBB, 0xFA, 0x07, 0xAB, 0x53, 0xEF,
  36538. 0xE8, 0x17, 0xAE, 0x9C, 0x6A, 0xE8, 0xD0, 0x52,
  36539. 0xAA, 0x85, 0x9D, 0x03, 0x48, 0xB0, 0xD2, 0xC8,
  36540. 0x5B, 0xCC, 0xC4, 0x50, 0x84, 0x90, 0xBE, 0x0F,
  36541. 0x9B, 0x32, 0x13, 0xB8, 0xAF, 0x7C, 0xCE, 0xE7,
  36542. 0x22, 0xE2, 0x82, 0x13, 0x18, 0x71, 0x46, 0xC5,
  36543. 0xDA, 0x05, 0xB7, 0x65, 0xD8, 0x33, 0x06, 0xFA,
  36544. 0x5A, 0x6B, 0x76, 0xD6, 0x92, 0x76, 0xD1, 0x6A,
  36545. 0x2B, 0xC6, 0x0D, 0xB1, 0xAD, 0xAB, 0x57, 0x62,
  36546. 0xEA, 0x76, 0x37, 0x4E, 0xAB, 0x2D, 0x34, 0xD2,
  36547. 0xA3, 0x57, 0xC7, 0x56, 0xFB, 0xEA, 0xD6, 0xA9,
  36548. 0xE3, 0xC1, 0x63, 0x07, 0xDE, 0xB9, 0x5E, 0x5A,
  36549. 0x30, 0x2E, 0x41, 0x4D, 0x43, 0xE9, 0x1C, 0xA1,
  36550. 0x5B, 0xB2, 0x4F, 0xAF, 0xDC, 0xE9, 0xBB, 0xBE,
  36551. 0x73, 0x55, 0x90, 0xF0, 0xD0, 0x02, 0x98, 0x6D,
  36552. 0x13, 0x50, 0x9A, 0xCA, 0x4C, 0xB3, 0x15, 0x3A,
  36553. 0x26, 0x14, 0x38, 0x67, 0xEB, 0xA7, 0x27, 0x33,
  36554. 0x48, 0x97, 0x58, 0x94, 0x57, 0xEA, 0xF9, 0x7E,
  36555. 0x8B, 0xB0, 0xBB, 0xF3, 0xF4, 0x84, 0x6E, 0x69,
  36556. 0x95, 0x2C, 0xF4, 0x6B, 0x1C, 0x65, 0x39, 0xB4,
  36557. 0x46, 0xA7, 0x99, 0xD6, 0x68, 0x47, 0x6E, 0x2E,
  36558. 0x49, 0x84, 0x75, 0x3E, 0x6C, 0x2E, 0x9A, 0x08,
  36559. 0xBC, 0xB7, 0x2F, 0x86, 0x68, 0x5C, 0xE1, 0xBF,
  36560. 0xEA, 0xA1, 0xAF, 0x59, 0xD6, 0x71, 0xB7, 0xBD,
  36561. 0xD6, 0xC5, 0xC2, 0xF2, 0xF3, 0xB5, 0x36, 0xBB,
  36562. 0x36, 0x23, 0x4F, 0xD6, 0x44, 0x59, 0x0A, 0x44,
  36563. 0x86, 0xCA, 0xDC, 0xD4, 0x22, 0x0F, 0x79, 0x09,
  36564. 0x99, 0x8C, 0x8C, 0x9E, 0x03, 0xA4, 0x51, 0x99,
  36565. 0x5A, 0xB9, 0x97, 0x76, 0x73, 0x20, 0xD3, 0x98,
  36566. 0x8C, 0x52, 0x96, 0xE1, 0x65, 0x7B, 0x4C, 0x77,
  36567. 0x40, 0xB2, 0xFE, 0x27, 0x0A, 0x11, 0x76, 0x6E,
  36568. 0x3B, 0x35, 0x12, 0xC6, 0x4E, 0xC2, 0x0E, 0xCC,
  36569. 0x04, 0xB5, 0x51, 0x91, 0xD0, 0x4A, 0xF7, 0x84,
  36570. 0xF2, 0xE7, 0xE5, 0x99, 0x7E, 0xB5, 0x3E, 0xAC,
  36571. 0x53, 0xDB, 0x61, 0x11, 0x71, 0x56, 0x4E, 0xAB,
  36572. 0x4A, 0x68, 0xC1, 0x6A, 0xA5, 0xC5, 0x7F, 0x72,
  36573. 0xEB, 0x14, 0x97, 0xA4, 0x27, 0xA0, 0x53, 0xA1,
  36574. 0xC4, 0x70, 0x7D, 0x58, 0xBD, 0xC1, 0xD7, 0xFD,
  36575. 0x9F, 0xB8, 0x8C, 0xCE, 0x34, 0xF9, 0xE1, 0x9C,
  36576. 0x59, 0x79, 0x31, 0x24, 0xEC, 0xBB, 0xF5, 0x6F,
  36577. 0x3F, 0xA3, 0x5A, 0x55, 0xB3, 0xDE, 0x64, 0xDF,
  36578. 0xA9, 0x95, 0x0B, 0x53, 0xF2, 0xA7, 0x25, 0x7B,
  36579. 0x8C, 0xAD, 0x25, 0x9A, 0x35, 0xBF, 0x15, 0x46,
  36580. 0x69, 0x4A, 0x83, 0x8C, 0x80, 0xFC, 0x37, 0xD0,
  36581. 0xC3, 0x6F, 0x00, 0xE2, 0x3C, 0x63, 0xAB, 0xC5,
  36582. 0x53, 0xC1, 0x8D, 0x4A, 0x40, 0x4B, 0xE6, 0xDC,
  36583. 0x05, 0xB1, 0x20, 0x23, 0x8B, 0xB8, 0xDF, 0x40,
  36584. 0x86, 0x97, 0xB9, 0x5E, 0xA4, 0xB7, 0xA1, 0x37,
  36585. 0xE0, 0x4B, 0x9E, 0xD9, 0x84, 0x2B, 0x2D, 0xAD,
  36586. 0xD1, 0xB1, 0x52, 0x15, 0x00, 0x9B, 0xDD, 0x23,
  36587. 0xA9, 0x27, 0x44, 0x21, 0x33, 0x17, 0x1C, 0x61,
  36588. 0x49, 0x84, 0x0D, 0x6A, 0x11, 0x7C, 0x77, 0xA5,
  36589. 0xD6, 0x8E, 0xE6, 0x1D, 0x6E, 0x90, 0x04, 0x4A,
  36590. 0xD3, 0x54, 0x3A, 0xA7, 0x1A, 0x28, 0xC5, 0x94,
  36591. 0x01, 0xCA, 0xDB, 0x1B, 0x5D, 0x78, 0xC5, 0xC6,
  36592. 0x69, 0x0D, 0x69, 0x88, 0x75, 0x00, 0x02, 0x0B,
  36593. 0x59, 0x6C, 0x3E, 0xC5, 0x30, 0xDF, 0xEE, 0x85,
  36594. 0x43, 0xA2, 0x9A, 0xF9, 0xDD, 0x85, 0x6E, 0xB3,
  36595. 0x0D, 0x83, 0x6A, 0x13, 0x88, 0xD0, 0x12, 0x15,
  36596. 0x53, 0x16, 0xFC, 0x5C, 0x15, 0x47, 0xEC, 0x6D,
  36597. 0x4D, 0x18, 0x2D, 0x88, 0xDB, 0xD2, 0x17, 0x6C,
  36598. 0xDE, 0x64, 0xEC, 0x70, 0x8D, 0x19, 0xDC, 0x66,
  36599. 0x69, 0x7F, 0xCF, 0x61, 0x6E, 0x4F, 0x23, 0x86,
  36600. 0xF5, 0x1A, 0x98, 0x47, 0x4B, 0xCC, 0xE9, 0x2F,
  36601. 0x12, 0x28, 0x12, 0xB9, 0xEB, 0xD8, 0x32, 0xDC,
  36602. 0xE4, 0xD8, 0x63, 0xAC, 0x56, 0x08, 0x2F, 0xEC,
  36603. 0x5E, 0x47, 0x29, 0xFF, 0x76, 0xFE, 0x95, 0x60,
  36604. 0xD2, 0x19, 0x61, 0x0E, 0xAF, 0xFC, 0x44, 0x42,
  36605. 0x11, 0x42, 0x79, 0xBC, 0x06, 0x3A, 0xAD, 0x93,
  36606. 0x7E, 0x46, 0x60, 0x03, 0xB0, 0xF5, 0x9F, 0x57,
  36607. 0x28, 0x48, 0x44, 0x8F, 0x0E, 0xFA, 0x72, 0x8C,
  36608. 0xE4, 0x18, 0xF4, 0x99, 0x6B, 0xB1, 0x23, 0x45,
  36609. 0xDC, 0x13, 0xA2, 0xF6, 0x5F, 0x57, 0x35, 0xA2,
  36610. 0xD7, 0x38, 0xF9, 0xE9, 0x8A, 0x7A, 0x79, 0xC6,
  36611. 0xB2, 0xCD, 0xBF, 0xD3, 0x41, 0x21, 0x56, 0xB3,
  36612. 0x39, 0xD9, 0x14, 0x3B, 0xDD, 0x85, 0xCB, 0x78,
  36613. 0x2F, 0xEB, 0x7E, 0x29, 0xBC, 0x52, 0x24, 0xE7,
  36614. 0x1B, 0x85, 0xB1, 0x65, 0xAE, 0xAB, 0x65, 0xF9,
  36615. 0x54, 0xD2, 0x1F, 0x37, 0x29, 0x52, 0x30, 0x5B,
  36616. 0x3D, 0x5F, 0x48, 0x84, 0x3F, 0x51, 0x27, 0x88,
  36617. 0x9D, 0xA7, 0x94, 0xF0, 0x73, 0xCD, 0x98, 0xD2,
  36618. 0x05, 0xE8, 0x25, 0x71, 0x7C, 0x93, 0x13, 0x82,
  36619. 0x5D, 0x53, 0x8D, 0x05, 0x0E, 0x69, 0x20, 0xC4,
  36620. 0xDB, 0xF2, 0xF6, 0x55, 0x24, 0x29, 0xD0, 0x41,
  36621. 0xF6, 0x2D, 0xF8, 0xC1, 0x2E, 0xC2, 0x4D, 0xE1,
  36622. 0xD7, 0x2D, 0xA0, 0x49, 0x16, 0x0B, 0x4D, 0x34,
  36623. 0xB5, 0x6D, 0xAE, 0x10, 0x93, 0x1E, 0xB6, 0x95,
  36624. 0x69, 0xC2, 0xB3, 0xC0, 0xAF, 0x6F, 0xFF, 0xA5,
  36625. 0x32, 0x3C, 0x7D, 0xC9, 0xC7, 0xC8, 0xEF, 0x0C,
  36626. 0x64, 0x20, 0x23, 0xC4, 0xFE, 0x89, 0x87, 0x8E,
  36627. 0xB3, 0xA6, 0xC5, 0x24, 0xCF, 0x03, 0x7E, 0x74,
  36628. 0xF7, 0xBF, 0x89, 0x1E, 0xCF, 0xB1, 0x02, 0xFA,
  36629. 0xF2, 0x9F, 0xD3, 0x9D, 0x99, 0x00, 0xDA, 0x7A,
  36630. 0x92, 0x7D, 0x13, 0x11, 0x92, 0xAD, 0x55, 0xF2,
  36631. 0xE1, 0x82, 0x72, 0xB1, 0x6A, 0xF1, 0x45, 0x05,
  36632. 0xDA, 0x17, 0xC9, 0xA1, 0x42, 0x82, 0x89, 0x77,
  36633. 0x31, 0xB6, 0x72, 0x54, 0x7C, 0x68, 0x10, 0x25,
  36634. 0x57, 0x30, 0x16, 0x15, 0x08, 0x58, 0x8B, 0xC1,
  36635. 0x61, 0xCB, 0xA0, 0x58, 0x29, 0x33, 0xB1, 0x64,
  36636. 0xF4, 0x4F, 0x06, 0xAA, 0x25, 0x31, 0xAA, 0xA8,
  36637. 0x92, 0x1C, 0x69, 0x1E, 0x6E, 0xB6, 0xBE, 0x81,
  36638. 0xDA, 0x9B, 0xE5, 0x1C, 0x56, 0x39, 0x55, 0xE0,
  36639. 0xC1, 0xEF, 0xD3, 0xED, 0x2A, 0x1C, 0x94, 0x9B,
  36640. 0xD4, 0xE0, 0x0B, 0x3A, 0xE9, 0xEB, 0xC1, 0x3C,
  36641. 0x4C, 0x6C, 0x4E, 0x5E, 0x39, 0x4C, 0xB0, 0x34,
  36642. 0xB9, 0xCB, 0x75, 0xBE, 0xCE, 0x86, 0x44, 0xFF,
  36643. 0x89, 0xEF, 0x95, 0xE7, 0x6E, 0xF7, 0x15, 0xE1,
  36644. 0x7A, 0xA2, 0x6B, 0x1F, 0xEB, 0x77, 0x4C, 0x50,
  36645. 0x59, 0xB3, 0xA3, 0x9A, 0x38, 0xDF, 0xD0, 0x57,
  36646. 0xD6, 0x41, 0xE4, 0x3F, 0xFE, 0x0F, 0x3E, 0x40,
  36647. 0xFF, 0xF6, 0xB2, 0x36, 0x3C, 0x1B, 0xF0, 0xEF,
  36648. 0x07, 0x87, 0x3D, 0x09, 0xA4, 0x87, 0x76, 0x9D,
  36649. 0x0A, 0x73, 0xCD, 0x0C, 0xC6, 0x44, 0xF5, 0x3C,
  36650. 0x25, 0xD2, 0x02, 0x5E, 0xE7, 0x1C, 0x69, 0xB7,
  36651. 0xAC, 0x0F, 0xA6, 0x61, 0x15, 0x57, 0xC4, 0x27,
  36652. 0xC0, 0x69, 0xDF, 0x2E, 0x1B, 0xF6, 0x29, 0xD9,
  36653. 0xA0, 0xCB, 0x5C, 0x67, 0xC7, 0xEA, 0x4F, 0xA6,
  36654. 0x58, 0xC7, 0x8D, 0x00, 0x42, 0xB0, 0x59, 0xE6,
  36655. 0xB6, 0x58, 0xFF, 0xCE, 0x60, 0x16, 0x69, 0x67,
  36656. 0xDB, 0x94, 0xF7, 0x16, 0xEB, 0x4D, 0x04, 0xB3,
  36657. 0xD2, 0x45, 0x0F, 0x40, 0x03, 0x1F, 0x10, 0xAC,
  36658. 0xDD, 0x07, 0x77, 0x7F, 0xBE, 0x9F, 0xBB, 0xB7,
  36659. 0x7F, 0xCB, 0x7C, 0x1F, 0xA9, 0xFC, 0x1E, 0xAF,
  36660. 0x0C, 0x5F, 0x86, 0xD7, 0x96, 0x2D, 0xAE, 0xD0,
  36661. 0x47, 0x4B, 0xA0, 0xFE, 0x68, 0xD9, 0xB2, 0x32,
  36662. 0x77, 0xA9, 0xCA, 0x7F, 0xC6, 0x76, 0xC6, 0x61,
  36663. 0x6B, 0x8E, 0x43, 0x9A, 0x1D, 0x4B, 0xFF, 0x72,
  36664. 0x43, 0x78, 0x19, 0xB5, 0x51, 0x87, 0x56, 0xA7,
  36665. 0x87, 0x3E, 0xF5, 0x84, 0x01, 0x26, 0x46, 0xC3,
  36666. 0x65, 0x9A, 0x6B, 0xA8, 0x6E, 0x62, 0x27, 0x26,
  36667. 0x14, 0xD8, 0x5E, 0xEC, 0xD5, 0x35, 0x0E, 0x3C,
  36668. 0xD0, 0xA1, 0x25, 0xAE, 0x9C, 0x17, 0xCC, 0xE2,
  36669. 0x52, 0x39, 0xE1, 0xEE, 0x9C, 0xDB, 0x39, 0xCA,
  36670. 0x7B, 0x18, 0xCF, 0x2C, 0x88, 0xCF, 0x14, 0x68,
  36671. 0x26, 0xB6, 0xCC, 0x1E, 0x6A, 0xA8, 0xE1, 0x69,
  36672. 0x2C, 0x91, 0x5F, 0x3B, 0xF1, 0xC1, 0xDB, 0x34,
  36673. 0xC6, 0xF3, 0x78, 0x83, 0xCB, 0x4E, 0xDC, 0xE0,
  36674. 0xF7, 0xC9, 0x95, 0xB6, 0x9E, 0x3A, 0xCE, 0x30,
  36675. 0xDC, 0x16, 0x6F, 0x78, 0x4C, 0x93, 0xD6, 0xCB,
  36676. 0xBC, 0xAC, 0x3C, 0x79, 0xBC, 0x31, 0x93, 0x10,
  36677. 0xCE, 0x6E, 0x66, 0x57, 0x00, 0xF1, 0x7F, 0x96,
  36678. 0x2F, 0x18, 0xB2, 0x40, 0x73, 0x9D, 0x15, 0x69,
  36679. 0x0B, 0x1B, 0x6C, 0x85, 0xD1, 0xAA, 0xA3, 0x2D,
  36680. 0x4A, 0x79, 0x74, 0x4A, 0xE5, 0x0C, 0xF9, 0xA9,
  36681. 0x0A, 0x09, 0x54, 0xB4, 0xA4, 0xD9, 0x4C, 0x49,
  36682. 0x9B, 0x41, 0x23, 0xEF, 0xC0, 0x20, 0x44, 0x31,
  36683. 0xF7, 0x22, 0x85, 0xB5, 0xDA, 0x9E, 0x19, 0x22,
  36684. 0x23, 0x0A, 0x30, 0x4D, 0x3A, 0x1B, 0xD8, 0x52,
  36685. 0x08, 0x72, 0x61, 0xB7, 0xCF, 0x0D, 0x8B, 0x90,
  36686. 0xD1, 0x46, 0x23, 0xEB, 0xCD, 0xC6, 0x38, 0x7B,
  36687. 0xC6, 0xAF, 0x65, 0xBE, 0x5F, 0x01, 0x1B, 0x6B,
  36688. 0xC1, 0x23, 0xC1, 0x30, 0x6A, 0x1E, 0x8F, 0xBF,
  36689. 0x2D, 0xF0, 0xB6, 0xF8, 0x9B, 0x0A, 0xE0, 0x5D,
  36690. 0xE0, 0xE4, 0xB7, 0xF5, 0x0A, 0xDA, 0x46, 0xE5,
  36691. 0x3A, 0x9B, 0x6B, 0xCA, 0xDA, 0x06, 0x43, 0xBE,
  36692. 0x6B, 0xFD, 0xC2, 0xB0, 0x6A, 0x6C, 0x75, 0x88,
  36693. 0x3C, 0x2D, 0xC6, 0x13, 0xAC, 0x72, 0x16, 0x31,
  36694. 0x7A, 0x40, 0xC4, 0xA2, 0xC0, 0x86, 0x69, 0x83,
  36695. 0xD3, 0x2C, 0x9C, 0xE0, 0xA6, 0xCC, 0xED, 0xF4,
  36696. 0x03, 0x62, 0x6B, 0xB2, 0x3B, 0x5B, 0x9D, 0xA5,
  36697. 0x86, 0x77, 0x7C, 0x73, 0x5E, 0x19, 0x11, 0xD7,
  36698. 0x7B, 0x11, 0x96, 0xC8, 0xFA, 0x47, 0x21, 0xD6,
  36699. 0xB0, 0xFE, 0x0B, 0x08, 0x11, 0xFC, 0x00, 0xB9,
  36700. 0xA1, 0x24, 0x2C, 0xBD, 0x4A, 0x92, 0x43, 0x10,
  36701. 0x08, 0xBE, 0xE9, 0xE1, 0x5D, 0x19, 0x82, 0xDE,
  36702. 0x34, 0xAE, 0xDC, 0xA6, 0x85, 0x8F, 0x19, 0x30,
  36703. 0x20, 0xB6, 0x44, 0x7F, 0x6B, 0xA6, 0x63, 0x70,
  36704. 0x59, 0xDA, 0x8D, 0xE0, 0xF8, 0x46, 0x86, 0x57,
  36705. 0xB8, 0x1C, 0x57, 0x13, 0x78, 0x41, 0x8C, 0xF5,
  36706. 0x7D, 0x77, 0xAE, 0x75, 0x6C, 0x59, 0x93, 0x2E,
  36707. 0x05, 0x25, 0x03, 0xD1, 0xEA, 0xFB, 0x2D, 0x60,
  36708. 0xD2, 0x61, 0x23, 0xEA, 0x0E, 0xFF, 0x55, 0xE3,
  36709. 0x24, 0x49, 0x00, 0x19, 0xBD, 0x1E, 0x56, 0x24,
  36710. 0x87, 0x2F, 0x7B, 0x98, 0x07, 0x36, 0xD2, 0x7C,
  36711. 0xC5, 0x9B, 0xE0, 0x4E, 0x29, 0xAB, 0xA1, 0xB8,
  36712. 0x35, 0x15, 0x31, 0xCE, 0x65, 0x14, 0x24, 0xF8,
  36713. 0x10, 0xB5, 0xAB, 0x3E, 0xD5, 0x58, 0xCA, 0xE5,
  36714. 0x73, 0x2D, 0x7C, 0x8B, 0xB4, 0x62, 0x75, 0x03,
  36715. 0x30, 0x89, 0xFE, 0x32, 0xF8, 0x65, 0x99, 0xD0,
  36716. 0x88, 0xD5, 0x72, 0x88, 0x03, 0xC9, 0x51, 0x03,
  36717. 0xBA, 0x2F, 0xFB, 0x7C, 0x39, 0x02, 0x05, 0xC4,
  36718. 0xCE, 0xD8, 0xB3, 0xC2, 0x7B, 0x29, 0x8E, 0xA7,
  36719. 0x9D, 0x35, 0x97, 0xB7, 0x17, 0xDE, 0x28, 0x0B,
  36720. 0x32, 0xE5, 0x41, 0xDA, 0x1D, 0x98, 0xBD, 0x27,
  36721. 0xEF, 0xF7, 0xB4, 0x43, 0x09, 0x13, 0x39, 0xC7,
  36722. 0x40, 0x16, 0x11, 0x20, 0x71, 0xCB, 0xB6, 0xC9,
  36723. 0xB0, 0x8F, 0x20, 0xC1, 0xF0, 0x40, 0xFB, 0x6E,
  36724. 0x73, 0x04, 0x8F, 0x73, 0xCA, 0x45, 0xDB, 0xE0,
  36725. 0xF9, 0x25, 0x8D, 0x32, 0xF2, 0x3E, 0x36, 0xBE,
  36726. 0xF7, 0x88, 0xF8, 0x13, 0x4D, 0x9B, 0x10, 0xC2,
  36727. 0x58, 0x0B, 0x20, 0xF8, 0x78, 0xB6, 0x4C, 0x7D,
  36728. 0x2A, 0xA6, 0x81, 0x40, 0xD1, 0x30, 0x50, 0x38,
  36729. 0x2A, 0x5F, 0xBC, 0x81, 0x8E, 0x0F, 0xD4, 0xD0,
  36730. 0x87, 0x99, 0x78, 0x3D, 0xBE, 0x25, 0x15, 0xF4,
  36731. 0x45, 0x61, 0xA3, 0x1A, 0x7D, 0x05, 0x3F, 0xB5,
  36732. 0xA6, 0x1C, 0x41, 0xC6, 0x0E, 0xBE, 0x57, 0x6F,
  36733. 0xC5, 0xB6, 0x38, 0x63, 0x90, 0x55, 0x23, 0xFC,
  36734. 0x26, 0x9E, 0xFD, 0xB8, 0x6C, 0xF2, 0x99, 0x6B,
  36735. 0x6D, 0x90, 0xFE, 0x28, 0xA0, 0x16, 0xEE, 0x63,
  36736. 0xC2, 0x4C, 0xD6, 0xB2, 0x0C, 0xFA, 0x6E, 0x85,
  36737. 0x51, 0xE4, 0x2F, 0x57, 0x91, 0x82, 0x84, 0x43,
  36738. 0x8A, 0x44, 0x31, 0x6C, 0x68, 0x02, 0x01, 0x7C,
  36739. 0xCE, 0x4D, 0xC0, 0x7C, 0x43, 0xA9, 0x54, 0xF5,
  36740. 0x0E, 0xCA, 0xE6, 0x15, 0x98, 0xAE, 0x41, 0x57,
  36741. 0x0A, 0x66, 0xBA, 0x6D, 0x6E, 0x68, 0xB9, 0x2E,
  36742. 0x0D, 0x42, 0xD2, 0xF5, 0x0B, 0xFC, 0x2D, 0xA8,
  36743. 0x61, 0x6E, 0x60, 0x4E, 0x51, 0x78, 0xEB, 0x0C,
  36744. 0x52, 0x9E, 0xC0, 0x4A, 0xB0, 0x92, 0x85, 0x5C,
  36745. 0x3A, 0x3D, 0x69, 0x95, 0xAB, 0x62, 0xEB, 0x2F,
  36746. 0x9B, 0x12, 0xF5, 0x2E, 0xB5, 0xA6, 0x93, 0xCE,
  36747. 0x14, 0x97, 0xA7, 0x1E, 0x0A, 0x7B, 0x94, 0x74,
  36748. 0xFB, 0x65, 0xD0, 0x5A, 0x97, 0x55, 0x40, 0x02,
  36749. 0x71, 0x87, 0x9C, 0x9F, 0xCB, 0x41, 0x3F, 0x08,
  36750. 0x8D, 0x6A, 0xCA, 0xE6, 0xEC, 0xE6, 0x71, 0x22,
  36751. 0xF8, 0x58, 0x9F, 0xF1, 0x94, 0xF6, 0xE4, 0xD6,
  36752. 0xDC, 0x35, 0xD7, 0xEB, 0x6B, 0x78, 0x99, 0x66,
  36753. 0xF9, 0xE2, 0x15, 0x27, 0xC9, 0x8C, 0x27, 0xB4,
  36754. 0x89, 0x3C, 0x15, 0xEE, 0x52, 0x71, 0xA9, 0xD2,
  36755. 0x50, 0x3C, 0xD2, 0x31, 0xBB, 0x3A, 0xE5, 0x87,
  36756. 0xAF, 0x65, 0x2B, 0xF2, 0xF5, 0xC9, 0x44, 0xA2,
  36757. 0x59, 0x1C, 0x57, 0x96, 0xB9, 0xC2, 0x5E, 0xCB,
  36758. 0x8A, 0x5B, 0x2B, 0x7A, 0x7E, 0x93, 0x3C, 0x08,
  36759. 0x27, 0xCD, 0xB4, 0xB0, 0x1B, 0xF3, 0x82, 0x50,
  36760. 0x78, 0xCF, 0xEA, 0x28, 0x57, 0xB1, 0x0F, 0xB4,
  36761. 0xB6, 0x93, 0x82, 0x8E, 0x7A, 0xD1, 0x9F, 0x04,
  36762. 0xEC, 0xEE, 0x24, 0x3D, 0x8A, 0x5E, 0x56, 0x99,
  36763. 0x8D, 0x83, 0xA4, 0x05, 0x7D, 0xFB, 0x36, 0xDB,
  36764. 0xAB, 0xD1, 0x67, 0x59, 0xC7, 0x4A, 0xB9, 0xAF,
  36765. 0x99, 0xB6, 0xD8, 0xD4, 0x2C, 0xCA, 0x8C, 0xCC,
  36766. 0xD2, 0x32, 0xAB, 0x51, 0xCE, 0x2D, 0x22, 0xE0,
  36767. 0x29, 0xB1, 0x73, 0x10, 0x60, 0xA8, 0x6B, 0x8F,
  36768. 0x68, 0xAF, 0x58, 0x06, 0x9D, 0x72, 0x36, 0x98,
  36769. 0x3F, 0xF3, 0x6B, 0xAD, 0x3E, 0x7F, 0x4A, 0x00,
  36770. 0x94, 0x04, 0xAE, 0xE9, 0x8A, 0x9E, 0x8A, 0x03,
  36771. 0xD8, 0x04, 0xCC, 0xFE, 0xE3, 0xF8, 0xA2, 0x04,
  36772. 0x64, 0x17, 0x54, 0x77, 0xCA, 0x20, 0xD0, 0x80,
  36773. 0x1B, 0x36, 0xEF, 0x59, 0x31, 0xFA, 0xE4, 0xF5,
  36774. 0xAF, 0x56, 0x09, 0x02, 0xAD, 0xCF, 0xA6, 0xBC,
  36775. 0x26, 0x23, 0x27, 0x6D, 0xF3, 0x52, 0xCE, 0x2F,
  36776. 0x4C, 0x9C, 0xA8, 0x23, 0x75, 0xFA, 0x56, 0x9E,
  36777. 0x07, 0x5B, 0xB9, 0x30, 0x5A, 0xB1, 0x27, 0xFF,
  36778. 0x72, 0xBF, 0x50, 0xB1, 0x27, 0xEF, 0xA1, 0x0C,
  36779. 0x3A, 0xC9, 0x72, 0x21, 0xBE, 0xD8, 0xDC, 0xD5,
  36780. 0x66, 0x4A, 0x0A, 0x58, 0xFA, 0x57, 0xB4, 0x00,
  36781. 0x07, 0x31, 0xF2, 0x4E, 0xDC, 0xE0, 0x86, 0x99,
  36782. 0x45, 0xE5, 0x45, 0xCF, 0x27, 0x35, 0x79, 0x57,
  36783. 0xF5, 0xA2, 0x7A, 0x29, 0xFA, 0x5E, 0xCF, 0xF9,
  36784. 0xA9, 0x96, 0x11, 0xE1, 0x4A, 0x6C, 0xE5, 0xB8,
  36785. 0x8E, 0x78, 0xE6, 0xA1, 0x46, 0x97, 0xAE, 0xB4,
  36786. 0xF3, 0x6D, 0x7F, 0x8E, 0xD1, 0x86, 0x6B, 0x78,
  36787. 0x2B, 0x55, 0xC5, 0xDF, 0x0F, 0x43, 0x78, 0xED,
  36788. 0xD2, 0x38, 0xE5, 0x8B, 0x94, 0x7A, 0x06, 0xC5,
  36789. 0x73, 0x17, 0x55, 0x93, 0xAD, 0xA5, 0xAC, 0xBA,
  36790. 0x81, 0x8A, 0x6D, 0x73, 0x4B, 0xA1, 0x32, 0x8F,
  36791. 0x21, 0xA6, 0x5B, 0x51, 0x31, 0x58, 0xD0, 0xE4,
  36792. 0x0B, 0x93, 0x46, 0xF2, 0x51, 0x30, 0x3E, 0x60,
  36793. 0xE1, 0xCB, 0x30, 0x04, 0x15, 0x8D, 0x1E, 0x87,
  36794. 0xA6, 0xF6, 0x38, 0xE0, 0x27, 0x84, 0x81, 0x18,
  36795. 0x2B, 0x37, 0xBB, 0xD3, 0xDB, 0xE7, 0x91, 0xA3,
  36796. 0x1B, 0x6B, 0x20, 0xCB, 0x2C, 0x52, 0xB1, 0xB9,
  36797. 0x6A, 0x94, 0xF8, 0xCD, 0xBA, 0x5D, 0xC7, 0xDD,
  36798. 0x79, 0x36, 0x38, 0xC2, 0xFC, 0xEC, 0x4F, 0x2B,
  36799. 0x5F, 0x73, 0x44, 0x03, 0xE9, 0xA9, 0xF5, 0xD9,
  36800. 0x99, 0xEA, 0x61, 0xDC, 0x6A, 0x98, 0xBE, 0xDE,
  36801. 0xB9, 0x34, 0xCC, 0x76, 0xB0, 0xE1, 0x8C, 0x70,
  36802. 0x3A, 0xA5, 0x7C, 0xD1, 0xC0, 0x2A, 0x8E, 0x7D,
  36803. 0x47, 0x8A, 0x63, 0xEA, 0x30, 0x6B, 0xEE, 0x36,
  36804. 0x0B, 0xA8, 0xAE, 0x46, 0xCD, 0x01, 0x83, 0xF6,
  36805. 0x07, 0xF9, 0xED, 0x8B, 0x69, 0x97, 0xB6, 0xC3,
  36806. 0x5D, 0x75, 0x6E, 0xD8, 0xDF, 0x01, 0x82, 0x48,
  36807. 0x31, 0x2F, 0xDE, 0xED, 0x8E, 0xC5, 0xD8, 0xA6,
  36808. 0xC0, 0x36, 0x0E, 0x66, 0xA4, 0xE9, 0xE5, 0xA9,
  36809. 0x7D, 0x5C, 0xD2, 0x43, 0x72, 0xC0, 0xAD, 0x26,
  36810. 0x78, 0xF2, 0xB0, 0x08, 0x12, 0xAE, 0x6C, 0x1A,
  36811. 0x0F, 0x53, 0x30, 0xB3, 0xAB, 0x01, 0x53, 0xDA,
  36812. 0x3C, 0x5F, 0x4C, 0x17, 0xBD, 0x2F, 0xB6, 0x0E,
  36813. 0x7E, 0x80, 0x87, 0x4C, 0x1B, 0x92, 0x9B, 0x62,
  36814. 0xE3, 0x89, 0xEE, 0xE2, 0xA0, 0x14, 0x06, 0x0D,
  36815. 0x4D, 0xCC, 0x96, 0x5A, 0xF8, 0x64, 0x2A, 0x05,
  36816. 0xA9, 0xEE, 0xD5, 0x0D, 0x23, 0x90, 0xB0, 0x67,
  36817. 0xD5, 0x51, 0x1D, 0x18, 0xBC, 0xBA, 0xE6, 0xA5,
  36818. 0xAD, 0x29, 0x18, 0xD5, 0x06, 0xFC, 0xC9, 0x12,
  36819. 0x6D, 0x70, 0xA8, 0x6E, 0x96, 0x8B, 0x5F, 0x9C,
  36820. 0x99, 0x43, 0x07, 0x02, 0x37, 0x48, 0x8C, 0xFB,
  36821. 0x5F, 0xF5, 0xDE, 0x69, 0x26, 0x73, 0x7D, 0xF6,
  36822. 0x3A, 0x2C, 0xE5, 0x58, 0x01, 0xC3, 0x48, 0xB0,
  36823. 0xF0, 0x0D, 0x56, 0xAF, 0x8C, 0x0F, 0x5C, 0xB3,
  36824. 0xBA, 0x44, 0x8C, 0x39, 0xB0, 0x20, 0xD2, 0x93,
  36825. 0x81, 0x19, 0x99, 0x4E, 0xAC, 0xB9, 0x1F, 0xC3,
  36826. 0x1F, 0x34, 0x7D, 0xF3, 0x3E, 0x1A, 0xE1, 0x26,
  36827. 0x7C, 0xB7, 0x22, 0x0A, 0xDC, 0x0D, 0x14, 0xF8,
  36828. 0x43, 0x8A, 0x23, 0x46, 0x37, 0x9C, 0x2A, 0xB8,
  36829. 0x1F, 0x24, 0x72, 0xE2, 0xEA, 0xC4, 0x67, 0x13,
  36830. 0x17, 0x33, 0xBD, 0xA0, 0x07, 0xA0, 0x3E, 0xDE,
  36831. 0x8B, 0xC4, 0xD6, 0xDB, 0xD9, 0xF1, 0xB8, 0xF4,
  36832. 0xFB, 0x83, 0x13, 0x14, 0xCD, 0x36, 0xF6, 0xDC,
  36833. 0xD5, 0x85, 0x93, 0x7C, 0xF9, 0x6C, 0xEA, 0x52,
  36834. 0x92, 0xFB, 0xFC, 0x95, 0x02, 0x10, 0x7B, 0x57,
  36835. 0x9F, 0xF0, 0x7C, 0x2E, 0x79, 0x00, 0x3D, 0xB2,
  36836. 0xA1, 0x6C, 0x4E, 0xD4, 0x17, 0xFA, 0x0F, 0x13,
  36837. 0xC8, 0xBF, 0xB1, 0x82, 0xF7, 0xDD, 0xCF, 0x08,
  36838. 0xF2, 0x50, 0xDB, 0x16, 0xA4, 0x5A, 0x60, 0x4A,
  36839. 0x57, 0x2B, 0x0E, 0xDC, 0x4A, 0xBF, 0x9C, 0x86,
  36840. 0x08, 0x8A, 0x5A, 0xC8, 0x74, 0xDD, 0xA2, 0x6E,
  36841. 0x12, 0xA0, 0xEF, 0x63, 0x5A, 0xD2, 0x82, 0xAD,
  36842. 0xCD, 0xC7, 0xED, 0x16, 0x86, 0x45, 0x3D, 0xFB,
  36843. 0x35, 0xC3, 0xB1, 0xBA, 0x68, 0x21, 0xB4, 0xB7,
  36844. 0x22, 0x0B, 0x55, 0x79, 0x8B, 0x9C, 0xCF, 0xE0,
  36845. 0x66, 0x61, 0x5C, 0xE2, 0x55, 0x96, 0x0D, 0x09,
  36846. 0xE6, 0x77, 0xFE, 0xFE, 0x76, 0xBE, 0x91, 0x5E,
  36847. 0x04, 0xE5, 0x65, 0x44, 0xBD, 0x09, 0xD0, 0x6F,
  36848. 0x83, 0x44, 0xF9, 0x68, 0xDC, 0x68, 0x25, 0xCB,
  36849. 0xC6, 0x64, 0xD5, 0x18, 0xA4, 0x41, 0xE1, 0x9B,
  36850. 0x07, 0x6F, 0xC3, 0x38, 0x91, 0x37, 0xFC, 0x1B,
  36851. 0x73, 0x32, 0xE2, 0xB0, 0x68, 0x95, 0x44, 0x3B,
  36852. 0x7A, 0x00, 0x23, 0x36, 0x31, 0x15, 0x79, 0xA9,
  36853. 0xB0, 0x8F, 0x36, 0x73, 0xDA, 0x05, 0x90, 0xE6,
  36854. 0x96, 0xCE, 0xD9, 0x01, 0x44, 0x4A, 0x70, 0xA6,
  36855. 0x7B, 0x2A, 0x7D, 0x55, 0x12, 0xD6, 0x5B, 0xFC,
  36856. 0xD7, 0xAF, 0x1E, 0x34, 0x27, 0x77, 0x69, 0xE1,
  36857. 0x71, 0x08, 0x83, 0x01, 0xDE, 0x78, 0x46, 0xF0,
  36858. 0x88, 0xF4, 0x87, 0xC4, 0x92, 0x1B, 0xEB, 0x98,
  36859. 0x35, 0x4B, 0xAE, 0x9A, 0xF6, 0xEA, 0xB2, 0x34,
  36860. 0x91, 0x14, 0xEB, 0x21, 0xF6, 0x18, 0xDB, 0x1D,
  36861. 0x92, 0x6C, 0x1D, 0x2F, 0xE3, 0xA5, 0xF2, 0x29,
  36862. 0xC5, 0x73, 0x40, 0xC4, 0x0A, 0xEC, 0x11, 0xC2,
  36863. 0xD0, 0x14, 0x4D, 0x03, 0x94, 0xFC, 0x4D, 0x8E,
  36864. 0x38, 0x66, 0xA7, 0xD0, 0xA1, 0x0B, 0x64, 0xC8,
  36865. 0xB9, 0x92, 0xB0, 0xA4, 0xDD, 0xBC, 0xAD, 0x82,
  36866. 0x4E, 0x43, 0x97, 0x43, 0x78, 0xEA, 0x9A, 0x38,
  36867. 0xE5, 0x8C, 0x2C, 0x5A, 0xE1, 0x94, 0xAF, 0x43,
  36868. 0x10, 0xFB, 0xEC, 0x90, 0x28, 0x41, 0x6C, 0x5C,
  36869. 0xB7, 0xB8, 0xAF, 0xA5, 0x24, 0xF7, 0x4F, 0xFD,
  36870. 0x6F, 0x2E, 0x98, 0x44, 0x3F, 0x5E, 0x89, 0x24,
  36871. 0xF6, 0xCF, 0x11, 0x0E, 0x67, 0x1B, 0x81, 0x68,
  36872. 0x37, 0xD5, 0x9B, 0x2D, 0xB9, 0x1C, 0xB1, 0xE6,
  36873. 0x87, 0xD6, 0xA2, 0x02, 0x0F, 0x91, 0x08, 0xF6,
  36874. 0x9B, 0x94, 0x76, 0x62, 0xFD, 0xE7, 0x18, 0xAC,
  36875. 0x28, 0xA6, 0xAC, 0xDA, 0x27, 0xF4, 0x33, 0x59,
  36876. 0xBB, 0xBE, 0x36, 0x2C, 0xEE, 0xEA, 0x91, 0xE6,
  36877. 0x91, 0x95, 0x2C, 0x58, 0x0A, 0xB2, 0xCA, 0xA3,
  36878. 0xAA, 0x39, 0x03, 0x9A, 0x75, 0x3C, 0x27, 0x6E,
  36879. 0x02, 0x89, 0x17, 0x4B, 0x02, 0x42, 0x7C, 0xB4,
  36880. 0x2E, 0xAD, 0xB4, 0xD9, 0x35, 0xB2, 0x30, 0x9E,
  36881. 0x2F, 0xEC, 0x9F, 0x25, 0x56, 0x1A, 0x35, 0x40,
  36882. 0xF1, 0xAF, 0x1D, 0xA4, 0xA8, 0x62, 0x07, 0x70,
  36883. 0x98, 0x6C, 0xDE, 0x1E, 0x89, 0xC1, 0xD3, 0x30,
  36884. 0xBB, 0x82, 0x72, 0x40, 0xF2, 0xBC, 0x53, 0xC7,
  36885. 0xDE, 0xAB, 0xFC, 0x7D, 0xAD, 0xBF, 0xDA, 0xE0,
  36886. 0xA7, 0xA1, 0x0C, 0xD6, 0x73, 0x37, 0x36, 0xA1,
  36887. 0xEE, 0xA6, 0x96, 0x88, 0x79, 0x0E, 0x4A, 0x2C,
  36888. 0x69, 0x4C, 0xE5, 0x30, 0xFB, 0xDD, 0xE1, 0xFE,
  36889. 0x86, 0x90, 0xDC, 0xDF, 0x03, 0xF5, 0x17, 0x2F,
  36890. 0xF4, 0x58, 0x2D, 0xD3, 0xED, 0x3D, 0x7D, 0xA0,
  36891. 0xB3, 0x6E, 0x1E, 0xD3, 0xBB, 0xD9, 0x57, 0xBA,
  36892. 0x8B, 0x00, 0x72, 0xC4, 0xEE, 0xCF, 0x39, 0xD5,
  36893. 0x74, 0xFA, 0x13, 0xF0, 0xD7, 0xE9, 0x10, 0x0C,
  36894. 0x7A, 0x52, 0x62, 0xD0, 0xC9, 0xD5, 0x2D, 0xDC,
  36895. 0x11, 0xD4, 0xFF, 0x34, 0xB2, 0x55, 0xF9, 0x99,
  36896. 0x81, 0xB4, 0xC9, 0x14, 0x02, 0x91, 0x81, 0x56,
  36897. 0x29, 0xF6, 0xA9, 0x1A, 0x19, 0x8E, 0x74, 0xB3,
  36898. 0xA3, 0xD1, 0x28, 0xB5, 0x72, 0xD8, 0x6F, 0x54,
  36899. 0x15, 0x74, 0x55, 0x70, 0x26, 0x62, 0xCB, 0x1D,
  36900. 0x15, 0x2C, 0x7F, 0x4C, 0x9C, 0xB4, 0xDE, 0xA2,
  36901. 0x07, 0xD5, 0xA9, 0x38, 0x29, 0x42, 0x51, 0x67,
  36902. 0x44, 0x26, 0x97, 0x7E, 0x73, 0x0E, 0xC6, 0x01,
  36903. 0x00, 0x65, 0xC8, 0xE0, 0x34, 0x88, 0x2B, 0xD3,
  36904. 0x2F, 0xD3, 0x5C, 0x6A, 0xF6, 0xB8, 0xD9, 0x3A,
  36905. 0x50, 0x9C, 0xC3, 0x39, 0xD9, 0x6F, 0xB9, 0xDD,
  36906. 0x55, 0x8A, 0xF9, 0x52, 0x35, 0xFB, 0xF1, 0x71,
  36907. 0x97, 0x76, 0x04, 0x75, 0xEE, 0x2E, 0x3F, 0xCA,
  36908. 0x0E, 0x83, 0xA8, 0xE3, 0x1F, 0xA7, 0xF1, 0x3D,
  36909. 0x78, 0xCC, 0x79, 0x64, 0x80, 0x5E, 0x77, 0x05,
  36910. 0xDB, 0xB7, 0x0F, 0x73, 0x53, 0x3A, 0x56, 0xD8,
  36911. 0xB7, 0x7C, 0x12, 0xE8, 0xF6, 0x51, 0x07, 0xC9,
  36912. 0x01, 0x43, 0x97, 0x51, 0x75, 0x95, 0x94, 0x65,
  36913. 0xFD, 0x4D, 0x8C, 0x8C, 0xD3, 0xA8, 0xEE, 0xA9,
  36914. 0x5E, 0xFB, 0xC7, 0xF6, 0xF8, 0x40, 0x0E, 0xA5,
  36915. 0xD5, 0x1E, 0x79, 0xB4, 0x0C, 0xEF, 0x8B, 0x04,
  36916. 0x59, 0x4D, 0x0C, 0x6F, 0x08, 0xD5, 0x00, 0xA2,
  36917. 0xAD, 0x08, 0xB4, 0x62, 0xE0, 0x2C, 0xF6, 0x30,
  36918. 0x31, 0x1E, 0xD7, 0x81, 0x56, 0x61, 0x17, 0x0D,
  36919. 0xB3, 0x9F, 0x27, 0x75, 0x38, 0x42, 0x6E, 0xB2,
  36920. 0xB0, 0x6C, 0xB8, 0xC9, 0xD8, 0x20, 0xC8, 0x36,
  36921. 0x7D, 0x1D, 0x57, 0x10, 0x4E, 0xC1, 0x45, 0xFC,
  36922. 0x93, 0xB1, 0xF7, 0x7B, 0xA1, 0x3B, 0x71, 0x12,
  36923. 0x16, 0xE5, 0x8F, 0xD0, 0x0C, 0x7D, 0xC0, 0x05,
  36924. 0x18, 0x02, 0x24, 0x25, 0x28, 0x8A, 0xE1, 0x29,
  36925. 0x9A, 0x79, 0xBD, 0xC7, 0x73, 0x2D, 0xF3, 0x42,
  36926. 0x70, 0x33, 0xF3, 0xF8, 0x48, 0x87, 0xB4, 0xD4,
  36927. 0x91, 0xE1, 0x53, 0xBA, 0x4A, 0x63, 0xAF, 0x3A,
  36928. 0xE5, 0xCB, 0x3D, 0x41, 0x04, 0xB5, 0x30, 0x87,
  36929. 0xAA, 0x40, 0x03, 0x56, 0x10, 0x02, 0xF3, 0x6A,
  36930. 0x9F, 0xDA, 0x33, 0xBC, 0xB8, 0xA5, 0xD0, 0x56,
  36931. 0x43, 0x29, 0xDA, 0x58, 0x12, 0x8B, 0x6A, 0x9D,
  36932. 0xCF, 0xCD, 0xCA, 0x66, 0x98, 0x92, 0x1D, 0xA4,
  36933. 0xEF, 0xAC, 0x9E, 0x19, 0xDE, 0xF7, 0xFE, 0x6C,
  36934. 0x3A, 0x66, 0x46, 0xB4, 0x00, 0x7F, 0x08, 0xAF,
  36935. 0x31, 0xD6, 0xD3, 0x22, 0x59, 0x1F, 0x34, 0x48,
  36936. 0x5A, 0xE1, 0x4E, 0x0F, 0x6F, 0x2D, 0xD0, 0xE5,
  36937. 0x8E, 0x34, 0x3B, 0xC0, 0x55, 0x02, 0x2D, 0x17,
  36938. 0x4B, 0x34, 0x78, 0x46, 0xD4, 0xC4, 0x7F, 0x1D,
  36939. 0xDC, 0x39, 0x94, 0x69, 0x78, 0xAB, 0xD8, 0x2B,
  36940. 0x6D, 0xF3, 0x1C, 0x0B, 0x0F, 0x4A, 0xA0, 0xB2,
  36941. 0xAC, 0x1A, 0x79, 0x7F, 0x9D, 0xE5, 0xE8, 0xC6,
  36942. 0x40, 0x4B, 0xCE, 0x32, 0x4B, 0xA1, 0x3C, 0x77,
  36943. 0xED, 0x5D, 0x59, 0x0F, 0xE0, 0x7D, 0x00, 0x07,
  36944. 0xB4, 0xD8, 0xA6, 0x3E, 0xC9, 0x6D, 0x62, 0x19,
  36945. 0x66, 0xC3, 0xE7, 0x10, 0x3B, 0x6C, 0x7A, 0x36,
  36946. 0x49, 0x75, 0xE6, 0x78, 0xB3, 0x8D, 0x04, 0x13,
  36947. 0x31, 0xE6, 0x79, 0x72, 0x64, 0x07, 0x76, 0x94,
  36948. 0x2B, 0xB4, 0xEC, 0x18, 0x1C, 0x32, 0x3C, 0x26,
  36949. 0xC4, 0x81, 0xBF, 0x4F, 0xB5, 0x6E, 0x5D, 0x67,
  36950. 0xCF, 0xBE, 0x17, 0x57, 0x11, 0x2B, 0xBC, 0xA0,
  36951. 0xF0, 0xC2, 0x70, 0x06, 0x94, 0x26, 0x9B, 0x26,
  36952. 0x12, 0x9C, 0x7F, 0x99, 0xD4, 0x4A, 0xF5, 0x60,
  36953. 0xCD, 0xF7, 0xA4, 0x70, 0x2E, 0xF5, 0xD6, 0xA2,
  36954. 0xEC, 0x0E, 0x99, 0x00, 0x2E, 0x89, 0x30, 0xAA,
  36955. 0x4E, 0xC0, 0x62, 0x11, 0x93, 0x0A, 0x1E, 0x68,
  36956. 0xF2, 0xED, 0x44, 0x8B, 0x10, 0x4A, 0x75, 0x68,
  36957. 0xBF, 0x46, 0xE1, 0x41, 0xD6, 0x0B, 0x61, 0x53,
  36958. 0xD4, 0x03, 0x10, 0xB3, 0x8F, 0x8E, 0x14, 0x57,
  36959. 0x27, 0x8F, 0xE3, 0x49, 0xB2, 0xB4, 0xA7, 0xAE,
  36960. 0x39, 0x7A, 0x7B, 0x8F, 0x48, 0xAA, 0xA5, 0xFD,
  36961. 0xC1, 0x28, 0x8E, 0x43, 0xE0, 0x58, 0x39, 0x32,
  36962. 0x0A, 0x14, 0xC6, 0x3A, 0xB8, 0x58, 0xE2, 0x6E,
  36963. 0x7D, 0x8C, 0x35, 0xB6, 0x47, 0x37, 0x90, 0x4D,
  36964. 0x89, 0xC1, 0x9A, 0x10, 0x3D, 0x6B, 0x68, 0x9A,
  36965. 0x3D, 0xC9, 0x0C, 0x72, 0xFC, 0x92, 0xE3, 0x5D,
  36966. 0x45, 0x2B, 0x81, 0x43, 0x02, 0x30, 0x70, 0xD4,
  36967. 0x8B, 0xB9, 0xFB, 0xB0, 0x45, 0xE3, 0xC6, 0xCE,
  36968. 0x9A, 0x8B, 0xD5, 0xC4, 0xB6, 0x7F, 0x5D, 0x8B,
  36969. 0x58, 0xC9, 0x6A, 0x28, 0x2D, 0x6E, 0x27, 0x78,
  36970. 0x3D, 0x7B, 0x99, 0x0E, 0x05, 0x2B, 0xD9, 0x5E,
  36971. 0x86, 0x50, 0x8F, 0x9B, 0xF7, 0xC0, 0x64, 0xA8,
  36972. 0xF2, 0x39, 0xE0, 0x24, 0x0A, 0x20, 0xD8, 0xDF,
  36973. 0x3A, 0x87, 0x6E, 0xDC, 0x8F, 0xF6, 0x24, 0x1B,
  36974. 0x54, 0xF2, 0x70, 0xA9, 0x8C, 0xB8, 0x07, 0x7A,
  36975. 0xAF, 0xE0, 0xE5, 0x8E, 0x5E, 0x98, 0x13, 0xC6,
  36976. 0xA5, 0xF9, 0x1F, 0x52, 0x89, 0x7B, 0x6A, 0xAD,
  36977. 0x24, 0x26, 0xC6, 0x0D, 0xA5, 0x88, 0x3E, 0x6B,
  36978. 0xDF, 0xEE, 0x33, 0x0A, 0x86, 0x09, 0xA2, 0x11,
  36979. 0x8B, 0x69, 0x9F, 0x75, 0xCE, 0xFD, 0x05, 0x01,
  36980. 0x95, 0x14, 0x64, 0xCD, 0x62, 0x04, 0x09, 0x87,
  36981. 0xFC, 0xF6, 0xB2, 0x2E, 0xCA, 0x92, 0xE4, 0x4F,
  36982. 0x55, 0xB3, 0x8C, 0x64, 0x99, 0xA8, 0xDA, 0x0A,
  36983. 0xC7, 0x82, 0x56, 0x93, 0x03, 0x67, 0xA4, 0xD7,
  36984. 0x54, 0x91, 0xA0, 0x89, 0xD8, 0x94, 0x1F, 0x6C,
  36985. 0x53, 0xCC, 0xB2, 0x60, 0x13, 0x6A, 0x93, 0xE1,
  36986. 0xFC, 0xA3, 0xDD, 0x72, 0xD5, 0x5A, 0x92, 0x35,
  36987. 0x9E, 0x3D, 0x62, 0x82, 0x70, 0x5D, 0x54, 0xAF,
  36988. 0x57, 0xC6, 0x98, 0x5E, 0x74, 0xE0, 0xF2, 0x33,
  36989. 0x26, 0x61, 0xBF, 0x2B, 0xDD, 0x78, 0x47, 0x29,
  36990. 0x04, 0xC7, 0xF0, 0x58, 0x17, 0xFC, 0x9D, 0xED,
  36991. 0xEF, 0x15, 0x6A, 0xCA, 0xC7, 0x46, 0xCE, 0x12,
  36992. 0xF8, 0x90, 0xD8, 0x5A, 0x93, 0x98, 0xA9, 0xED,
  36993. 0xFB, 0xF4, 0x6E, 0x73, 0x48, 0x81, 0x4A, 0x08,
  36994. 0x07, 0x29, 0xC8, 0x3E, 0x70, 0x4C, 0x40, 0x30,
  36995. 0x20, 0x2C, 0xF6, 0x1E, 0xCD, 0xEE, 0x27, 0x95,
  36996. 0xD5, 0x07, 0xAC, 0x28, 0x81, 0x4F, 0x53, 0xCD,
  36997. 0x06, 0x60, 0xA5, 0x57, 0x2C, 0xBE, 0x1A, 0xE5,
  36998. 0x33, 0x38, 0xB8, 0xEF, 0xDC, 0xA3, 0x1A, 0xA5,
  36999. 0xB9, 0x5A, 0xA9, 0xE7, 0x65, 0xAF, 0x4D, 0xA0,
  37000. 0x4C, 0x9B, 0x31, 0x62, 0x67, 0x7E, 0x41, 0xC0,
  37001. 0x18, 0xA5, 0xE1, 0x8A, 0xF2, 0xF9, 0x8A, 0xCA,
  37002. 0x14, 0x5C, 0xCD, 0x1B, 0x8F, 0x74, 0x31, 0x07,
  37003. 0x6A, 0x14, 0xA7, 0xC2, 0x0F, 0x6C, 0x72, 0xE8,
  37004. 0xEB, 0x97, 0x51, 0xB7, 0x89, 0x2E, 0x41, 0x01,
  37005. 0x54, 0x47, 0x63, 0x0E, 0xAA, 0x84, 0xB9, 0x60,
  37006. 0x1C, 0xB9, 0x54, 0xD8, 0x97, 0x39, 0x38, 0x9D,
  37007. 0x52, 0xBB, 0x91, 0xA9, 0x7F, 0x96, 0x08, 0x7C,
  37008. 0xB3, 0x8B, 0x0E, 0xAB, 0x59, 0xA7, 0x84, 0x68,
  37009. 0x34, 0x65, 0x55, 0xC7, 0x12, 0x84, 0xC2, 0xFB,
  37010. 0xBD, 0x27, 0x58, 0x18, 0xE9, 0x26, 0x73, 0xFA,
  37011. 0x42, 0xAB, 0x5E, 0x0D, 0x97, 0x76, 0x67, 0xA9,
  37012. 0x0F, 0x75, 0x92, 0x6C, 0x80, 0x76, 0x87, 0x75,
  37013. 0xD2, 0x3D, 0xFE, 0x0B, 0x33, 0x7B, 0x48, 0xB0,
  37014. 0xC8, 0x28, 0x1F, 0xE6, 0x3F, 0x18, 0xF2, 0x45,
  37015. 0xF8, 0x8F, 0x21, 0xE1, 0x1C, 0x56, 0xA5, 0x33,
  37016. 0x71, 0x88, 0x42, 0x5A, 0x34, 0x8B, 0x24, 0xDD,
  37017. 0x0E, 0x98, 0x30, 0xDB, 0x6B, 0x6C, 0x89, 0x64,
  37018. 0x8C, 0x7A, 0x63, 0x3C, 0xA9, 0xD8, 0x32, 0x51,
  37019. 0xD0, 0xC6, 0xF7, 0xA4, 0x53, 0x95, 0x0D, 0x02,
  37020. 0x19, 0x6A, 0x77, 0xBC, 0xDF, 0xD5, 0x2B, 0x2C,
  37021. 0x65, 0xC9, 0xBF, 0x72, 0x69, 0xC3, 0x0C, 0xEF,
  37022. 0x34, 0x75, 0x76, 0x29, 0x59, 0xBE, 0x9D, 0xE9,
  37023. 0x44, 0x21, 0x2F, 0x5F, 0xB7, 0x89, 0xA6, 0xCD,
  37024. 0x0A, 0x9A, 0x9E, 0x77, 0x5B, 0xBD, 0xDA, 0x03,
  37025. 0xA4, 0xBC, 0xFB, 0x47, 0xC1, 0x77, 0x73, 0x00,
  37026. 0x26, 0xAE, 0x2E, 0xFA, 0x62, 0x18, 0x9D, 0xB8,
  37027. 0xE2, 0xD3, 0x7A, 0xB9, 0xD8, 0xCF, 0xE9, 0x61,
  37028. 0x11, 0x80, 0xE9, 0xDC, 0xC3, 0x32, 0x9E, 0x63,
  37029. 0x6F, 0xD9, 0x42, 0xF6, 0x76, 0x7F, 0xBC, 0xBF,
  37030. 0xDB, 0x08, 0x2F, 0xA0, 0xEB, 0xB8, 0x4D, 0xF3,
  37031. 0x76, 0x62, 0xAA, 0xFA, 0x20, 0x4A, 0xDD, 0xE6,
  37032. 0xB3, 0x72, 0xC7, 0x7D, 0x36, 0x4F, 0x08, 0x56,
  37033. 0x4F, 0x19, 0xB2, 0xB0, 0x0C, 0x13, 0x1A, 0x8C,
  37034. 0xCE, 0x9A, 0x04, 0xB5, 0xB6, 0x9C, 0xD3, 0xD8,
  37035. 0xFE, 0x1F, 0x2C, 0xCC, 0x89, 0xEE, 0x7D, 0x22,
  37036. 0x8A, 0x4E, 0x0A, 0x91, 0x0C, 0x8B, 0x5A, 0xE0,
  37037. 0xBD, 0xE5, 0x3D, 0xBE, 0x90, 0x4B, 0x13, 0xA3,
  37038. 0x2F, 0x33, 0xE9, 0x9D, 0x6C, 0x67, 0x35, 0xBD,
  37039. 0x03, 0xD4, 0x09, 0x90, 0x2F, 0xC6, 0x3C, 0x8D,
  37040. 0xD8, 0x43, 0xFC, 0x1F, 0xB7, 0x49, 0xC0, 0xB7,
  37041. 0x38, 0x70, 0x1D, 0xEB, 0x5A, 0xD7, 0xAC, 0x07,
  37042. 0xAF, 0x5B, 0x93, 0xC5, 0x7B, 0x55, 0x65, 0x86,
  37043. 0x6E, 0xC1, 0xDB, 0xCD, 0x42, 0x92, 0x50, 0xDB,
  37044. 0xD1, 0x97, 0x95, 0x3D, 0x53, 0xC3, 0xFE, 0xC2,
  37045. 0xF9, 0x65, 0xF3, 0xD2, 0xEE, 0xA4, 0x7E, 0xDE,
  37046. 0xA1, 0x4B, 0x23, 0x7F, 0xA1, 0x0D, 0x25, 0x6E,
  37047. 0x80, 0x4F, 0xE3, 0xB5, 0x0C, 0xBA, 0x1C, 0x2B,
  37048. 0x42, 0x0B, 0x8F, 0xD9, 0xB6, 0x4E, 0x52, 0xD2,
  37049. 0xDB, 0x35, 0xD2, 0xA1, 0xC4, 0xE6, 0xD6, 0x51,
  37050. 0x76, 0xE7, 0x87, 0x5E, 0xBE, 0x93, 0xE6, 0x61,
  37051. 0x71, 0x4C, 0x8B, 0xA6, 0x96, 0xDA, 0xF7, 0xCB,
  37052. 0x06, 0xB7, 0xB8, 0xC4, 0xF6, 0xF5, 0xC6, 0x29,
  37053. 0xAA, 0xE1, 0x13, 0x87, 0x6F, 0x96, 0xBA, 0x0C,
  37054. 0xF6, 0x79, 0x8F, 0x03, 0x86, 0x22, 0xE3, 0xFB,
  37055. 0xCF, 0x86, 0xCF, 0x7C, 0x77, 0xFD, 0xB4, 0xEE,
  37056. 0xBD, 0x42, 0x38, 0x7F, 0xF2, 0xCC, 0xCB, 0x06,
  37057. 0xEA, 0x0D, 0x81, 0xA1, 0x8E, 0xB5, 0xE7, 0x40,
  37058. 0xC8, 0x03, 0xA3, 0x4B, 0xC8, 0xB4, 0x0E, 0x3E,
  37059. 0x36, 0xAB, 0x90, 0xC1, 0xFC, 0xB0, 0x37, 0x2B,
  37060. 0x83, 0xA1, 0x3D, 0x56, 0xD6, 0x83, 0x0F, 0x99,
  37061. 0xC4, 0x58, 0xB8, 0x94, 0x61, 0x19, 0xA6, 0x60,
  37062. 0x47, 0xCB, 0x2D, 0xAF, 0x29, 0x38, 0x90, 0xFA,
  37063. 0x99, 0x0F, 0x02, 0x02, 0x65, 0x90, 0x5F, 0xA2,
  37064. 0xA2, 0xE3, 0xBB, 0x34, 0x15, 0x2F, 0x0B, 0xF5,
  37065. 0xB2, 0xCC, 0x83, 0x59, 0xAF, 0xA7, 0x4D, 0x38,
  37066. 0xAD, 0xF6, 0x52, 0x5C, 0x53, 0xD9, 0x0E, 0x3F,
  37067. 0xD6, 0x53, 0x86, 0xE2, 0x79, 0xC2, 0x65, 0x48,
  37068. 0xB2, 0x67, 0x3B, 0xAF, 0x52, 0x53, 0x57, 0x9A,
  37069. 0x27, 0x80, 0x88, 0x37, 0x77, 0x67, 0x4E, 0x1F,
  37070. 0xF1, 0x7B, 0xC5, 0xCB, 0xD8, 0x11, 0x0A, 0xDD,
  37071. 0x92, 0x0E, 0x88, 0x6C, 0xCA, 0x33, 0x76, 0x3B,
  37072. 0x04, 0xFA, 0xC0, 0xFD, 0xC6, 0x3F, 0xB4, 0x72,
  37073. 0xC2, 0x2B, 0x6D, 0x5E, 0xB6, 0xA1, 0x4E, 0x5F,
  37074. 0xC0, 0x50, 0x16, 0xEF, 0xFE, 0x6A, 0x42, 0x72,
  37075. 0x65, 0x02, 0xEE, 0x07, 0xC6, 0x19, 0xC6, 0x95,
  37076. 0xDE, 0x3F, 0xD9, 0xC5, 0xC6, 0x0E, 0x70, 0x07,
  37077. 0x6A, 0xC3, 0x36, 0x1B, 0x84, 0x6F, 0xDF, 0x80,
  37078. 0x16, 0x4E, 0x86, 0x90, 0xC8, 0x55, 0x7B, 0xDD,
  37079. 0xC0, 0x86, 0x0C, 0x37, 0x47, 0x1F, 0x35, 0xF8,
  37080. 0x47, 0xF2, 0xCD, 0x96, 0x21, 0x64, 0xAD, 0x46,
  37081. 0xE1, 0xDF, 0x44, 0x79, 0x48, 0x02, 0xF9, 0x71,
  37082. 0x39, 0x35, 0x26, 0xFC, 0x12, 0x0D, 0x88, 0xAC,
  37083. 0xD6, 0xFA, 0x29, 0x74, 0x55, 0x51, 0xE7, 0xAF,
  37084. 0x3D, 0x7E, 0x1E, 0x7E, 0xE0, 0x18, 0xB6, 0x3C,
  37085. 0x4B, 0x99, 0x9D, 0x51, 0x02, 0x51, 0xD8, 0xE9,
  37086. 0xFA, 0x61, 0x88, 0x2E, 0xCF, 0x73, 0x77, 0x65,
  37087. 0x71, 0xAE, 0xAE, 0xD7, 0xA1, 0xF9, 0xE0, 0x7F,
  37088. 0x30, 0x46, 0xCB, 0x20, 0xEC, 0xF4, 0xD2, 0xC1,
  37089. 0x63, 0xF5, 0x6F, 0x8A, 0x72, 0xF9, 0x5B, 0x85,
  37090. 0xD2, 0xCA, 0x6D, 0x35, 0xD1, 0x17, 0xF6, 0x08,
  37091. 0x9E, 0x0A, 0x73, 0xB3, 0xDA, 0x1A, 0x32, 0xBA,
  37092. 0x23, 0x10, 0x4A, 0x5D, 0xD7, 0xAA, 0xB4, 0x68,
  37093. 0x97, 0x59, 0x45, 0xC5, 0x7C, 0x16, 0x6F, 0xE4,
  37094. 0x62, 0x89, 0xF1, 0xD3, 0xB4, 0x03, 0x90, 0x7B,
  37095. 0xA4, 0xA2, 0xCA, 0xA0, 0x5D, 0x69, 0x1B, 0xA9,
  37096. 0xBB, 0xEB, 0xA0, 0xE2, 0xDE, 0xBE, 0x0E, 0xC4,
  37097. 0x9E, 0x21, 0x38, 0x61, 0x92, 0x9B, 0xAB, 0x69,
  37098. 0xAA, 0xD0, 0x1D, 0xF6, 0xC3, 0xEE, 0xA6, 0xC3,
  37099. 0xF3, 0x29, 0x1B, 0xE5, 0x6E, 0x52, 0x89, 0xD0,
  37100. 0xBA, 0xD8, 0x60, 0x27, 0x80, 0x1A, 0xB5, 0x7F,
  37101. 0x7F, 0xB5, 0xC2, 0x5A, 0xC6, 0x83, 0xA4, 0xC0,
  37102. 0x88, 0x39, 0xF3, 0xE7, 0x39, 0xD6, 0x81, 0x1C,
  37103. 0x13, 0x20, 0xFD, 0x93, 0x3D, 0x8E, 0x79, 0x60,
  37104. 0x7C, 0xFF, 0xE4, 0x37, 0x5B, 0x33, 0xA3, 0x9D,
  37105. 0xB7, 0x57, 0xCD, 0x45, 0x0A, 0xB9, 0xE4, 0xF1,
  37106. 0xBC, 0x59, 0x74, 0xE8, 0xB3, 0x06, 0xD0, 0x9F,
  37107. 0x0F, 0xBC, 0x5B, 0x23, 0xB8, 0x6C, 0xD6, 0x4D,
  37108. 0xFA, 0xCC, 0x14, 0xAB, 0x74, 0x61, 0x1A, 0xFC,
  37109. 0x22, 0xA6, 0xED, 0x09, 0x76, 0x91, 0xD8, 0x6E,
  37110. 0x44, 0xB6, 0x00, 0x14, 0xDC, 0x74, 0x2D, 0x90,
  37111. 0xAA, 0x59, 0x98, 0x76, 0x30, 0xC5, 0x44, 0xA4,
  37112. 0x61, 0x43, 0xD6, 0xE2, 0x28, 0x28, 0xA7, 0xBD,
  37113. 0x6E, 0x50, 0x5C, 0xE1, 0x96, 0x7A, 0xF8, 0xA8,
  37114. 0x32, 0x8C, 0xE9, 0xFD, 0x11, 0x37, 0x91, 0xD1,
  37115. 0xAF, 0x3C, 0xD3, 0x1C, 0x1E, 0x88, 0x4D, 0x7E,
  37116. 0x87, 0x84, 0x84, 0x6F, 0x39, 0x0B, 0xFB, 0x2D,
  37117. 0xB3, 0x12, 0x4C, 0x6D, 0x45, 0xDD, 0xCD, 0x7D,
  37118. 0x75, 0xB7, 0xFE, 0x7E, 0x44, 0xCC, 0x29, 0xE5,
  37119. 0xB3, 0x10, 0xEE, 0x23, 0x55, 0x5B, 0xCF, 0xBA,
  37120. 0xBD, 0xA1, 0xBE, 0x64, 0xF8, 0x6E, 0x60, 0x31,
  37121. 0x0A, 0x2D, 0xC9, 0x3B, 0x1D, 0x44, 0xE1, 0x9D,
  37122. 0x60, 0x28, 0x77, 0xEE
  37123. };
  37124. static const byte rnd_65[] = {
  37125. 0x4E, 0x7A, 0x01, 0x7C, 0x15, 0x03, 0x9D, 0xC2,
  37126. 0x00, 0x51, 0xD2, 0x96, 0x0E, 0x5E, 0x15, 0x59,
  37127. 0xCC, 0x27, 0xED, 0x46, 0x87, 0x7C, 0xB9, 0x81,
  37128. 0x16, 0x19, 0x9A, 0x0F, 0x41, 0x05, 0xFE, 0x32
  37129. };
  37130. static const byte sig_65[] = {
  37131. 0xB8, 0x65, 0xB0, 0x0B, 0x21, 0x18, 0xDB, 0xB0,
  37132. 0x0B, 0x70, 0x1C, 0x66, 0x45, 0x65, 0x5E, 0x8A,
  37133. 0xCF, 0xA8, 0x4E, 0xA7, 0x92, 0xB4, 0x48, 0x64,
  37134. 0x2E, 0x18, 0x32, 0xC3, 0x70, 0x7C, 0x87, 0xCF,
  37135. 0x09, 0xFB, 0xE7, 0x72, 0xF1, 0xD4, 0x38, 0x5B,
  37136. 0xFB, 0xE5, 0xE6, 0xCF, 0xBB, 0xE2, 0x6C, 0x10,
  37137. 0xED, 0x6E, 0xB8, 0x65, 0xC8, 0x87, 0xF8, 0x69,
  37138. 0x39, 0x43, 0x9A, 0x9B, 0xF7, 0x68, 0xBF, 0x03,
  37139. 0x9D, 0x73, 0xE3, 0xEA, 0x83, 0xBD, 0xF1, 0x85,
  37140. 0x03, 0xB5, 0xD1, 0xB3, 0x91, 0x79, 0xA8, 0x27,
  37141. 0xB0, 0xD7, 0x80, 0x5F, 0x98, 0x42, 0x8B, 0xD8,
  37142. 0x7C, 0xEA, 0x6B, 0x06, 0x96, 0x0C, 0x78, 0xB4,
  37143. 0xB5, 0x86, 0xFB, 0x0D, 0x5E, 0xDA, 0x9F, 0xAA,
  37144. 0xC0, 0x25, 0x6E, 0x38, 0x82, 0x35, 0x62, 0xA3,
  37145. 0x07, 0x96, 0x61, 0x17, 0x00, 0x5A, 0xA4, 0x2F,
  37146. 0x1B, 0x65, 0x54, 0xA0, 0x48, 0x75, 0xF8, 0x5C,
  37147. 0x2E, 0x3F, 0xAF, 0xA6, 0x52, 0x47, 0x1D, 0x4E,
  37148. 0x98, 0x06, 0x54, 0x82, 0xFC, 0x7D, 0xF4, 0x9B,
  37149. 0x2C, 0x40, 0xD0, 0xE7, 0xB9, 0x82, 0x38, 0xDF,
  37150. 0xBE, 0x85, 0x3D, 0x16, 0xBF, 0x99, 0x92, 0xBB,
  37151. 0x08, 0xC1, 0x92, 0x59, 0xF9, 0xB5, 0x75, 0xEA,
  37152. 0x7A, 0x4A, 0x80, 0x09, 0x3A, 0x64, 0xA9, 0x26,
  37153. 0x71, 0x85, 0x7A, 0x50, 0x89, 0x20, 0xD6, 0x0F,
  37154. 0xF6, 0xFB, 0xF3, 0x83, 0x41, 0xC5, 0x59, 0x01,
  37155. 0x05, 0x63, 0x3A, 0x42, 0x6D, 0x60, 0x2D, 0xAC,
  37156. 0x06, 0x4D, 0xD7, 0xA7, 0xF1, 0x1A, 0x60, 0x21,
  37157. 0x5C, 0x35, 0xB7, 0xB9, 0xC0, 0x0E, 0x9D, 0x84,
  37158. 0x63, 0x98, 0x8C, 0xF4, 0x72, 0xCD, 0x6A, 0xCF,
  37159. 0xB7, 0xF7, 0x22, 0xB8, 0xC4, 0xC6, 0x27, 0x02,
  37160. 0x60, 0x7A, 0x67, 0x48, 0x80, 0xAC, 0xB3, 0xD6,
  37161. 0xC6, 0x25, 0x3E, 0x71, 0x17, 0x5A, 0x05, 0xB3,
  37162. 0x92, 0xCA, 0xB4, 0xBB, 0x14, 0xCE, 0x86, 0xA5,
  37163. 0x98, 0xAB, 0xC7, 0x88, 0xD0, 0xFF, 0x4D, 0x82,
  37164. 0x77, 0x5E, 0x4E, 0xA0, 0xFC, 0x36, 0x36, 0x3C,
  37165. 0xD0, 0xE9, 0x7B, 0x78, 0xA6, 0xAE, 0x4D, 0xA8,
  37166. 0xE9, 0x8C, 0xA6, 0x12, 0x77, 0x2D, 0x56, 0xB5,
  37167. 0x82, 0xF8, 0x2C, 0x07, 0x09, 0xBE, 0xAE, 0x46,
  37168. 0x67, 0x3B, 0xDD, 0x80, 0x42, 0x86, 0x5C, 0xFA,
  37169. 0x95, 0xBF, 0x53, 0x38, 0xCF, 0xEA, 0x60, 0x6A,
  37170. 0x6E, 0xF3, 0x16, 0x38, 0x46, 0xAE, 0x83, 0xB2,
  37171. 0x5E, 0x5F, 0x5B, 0xD3, 0x1C, 0x83, 0xF1, 0x36,
  37172. 0x72, 0x9A, 0x8E, 0xA6, 0x27, 0x4F, 0x99, 0x4F,
  37173. 0xA9, 0x04, 0x5F, 0xA8, 0xA9, 0x0F, 0xF8, 0x54,
  37174. 0xB8, 0x71, 0xCF, 0x82, 0xE2, 0xB7, 0x01, 0xE8,
  37175. 0xF4, 0xAC, 0x04, 0xFE, 0x9E, 0x28, 0x49, 0x1B,
  37176. 0x9A, 0x25, 0xFF, 0x26, 0x3E, 0x2C, 0xF7, 0x54,
  37177. 0x99, 0xE0, 0x09, 0xFD, 0x02, 0x29, 0xFB, 0xF7,
  37178. 0xE5, 0xE4, 0x60, 0x44, 0x34, 0x4B, 0x07, 0xD7,
  37179. 0x22, 0x14, 0xA9, 0xAC, 0xB4, 0xFF, 0x61, 0x02,
  37180. 0xAB, 0xC1, 0x26, 0x2B, 0xC2, 0xE1, 0xCD, 0x24,
  37181. 0x91, 0x60, 0x7A, 0xE7, 0xAA, 0xEC, 0xF4, 0xC3,
  37182. 0x51, 0x75, 0xCF, 0xA4, 0x38, 0x3A, 0xA8, 0x6A,
  37183. 0xF1, 0xE6, 0x2E, 0xD0, 0x63, 0x87, 0xCC, 0x59,
  37184. 0x48, 0x36, 0x46, 0x7F, 0x41, 0xDF, 0xCA, 0x8F,
  37185. 0xA0, 0xCA, 0x71, 0x28, 0x0B, 0xFB, 0x1C, 0x25,
  37186. 0x60, 0xC8, 0x99, 0x55, 0x36, 0xF8, 0x42, 0x74,
  37187. 0x70, 0x45, 0x59, 0x14, 0x53, 0x74, 0x5F, 0x26,
  37188. 0x03, 0x82, 0xE3, 0xDA, 0x50, 0x79, 0x3F, 0xD7,
  37189. 0xCA, 0x76, 0x27, 0x18, 0x5D, 0xBD, 0xCE, 0xDD,
  37190. 0xF6, 0x9B, 0x2D, 0x3E, 0x15, 0x1C, 0x7F, 0x97,
  37191. 0x28, 0x8A, 0x38, 0x2A, 0x92, 0xB0, 0x50, 0xF7,
  37192. 0x91, 0xF9, 0x58, 0x7D, 0x77, 0xC6, 0x4D, 0x8B,
  37193. 0x5D, 0x40, 0xAA, 0x19, 0x9D, 0x49, 0x66, 0xBE,
  37194. 0x2D, 0x52, 0x4F, 0x96, 0x10, 0xF2, 0xFA, 0x02,
  37195. 0xED, 0x23, 0x17, 0x63, 0x69, 0xDB, 0x93, 0x93,
  37196. 0x50, 0xDA, 0x60, 0x1E, 0xA6, 0x67, 0x70, 0x95,
  37197. 0x2E, 0x0F, 0x23, 0xED, 0xA6, 0x8A, 0x73, 0x75,
  37198. 0x6E, 0xFF, 0x61, 0x0E, 0x8D, 0x6A, 0x9F, 0x49,
  37199. 0x34, 0x56, 0x58, 0x54, 0x42, 0x82, 0x45, 0x3B,
  37200. 0x5E, 0x73, 0xA3, 0x22, 0xA0, 0x32, 0x67, 0xC9,
  37201. 0x69, 0xB5, 0x07, 0x34, 0xF2, 0xEC, 0xD4, 0xEC,
  37202. 0x90, 0x55, 0x76, 0x0D, 0x92, 0x86, 0x10, 0xE9,
  37203. 0x4E, 0x0B, 0x16, 0x28, 0xD6, 0xAF, 0x1B, 0x27,
  37204. 0xAB, 0x13, 0x82, 0x9F, 0x7F, 0x8E, 0xF5, 0x0D,
  37205. 0x9E, 0x29, 0x96, 0xFC, 0x64, 0xB0, 0x6A, 0xC8,
  37206. 0x94, 0x61, 0x14, 0x76, 0x6D, 0xAD, 0x8D, 0xFF,
  37207. 0xE6, 0x34, 0xF4, 0x7E, 0x9D, 0x85, 0x69, 0x96,
  37208. 0x6C, 0x6F, 0x69, 0x68, 0x21, 0x8C, 0x5B, 0x86,
  37209. 0x33, 0x61, 0x1B, 0xF4, 0x2B, 0x4F, 0xC0, 0xE7,
  37210. 0x8D, 0x0C, 0x02, 0x9E, 0xAB, 0x85, 0xF2, 0x2F,
  37211. 0x16, 0x17, 0x19, 0x80, 0xCC, 0x65, 0xF2, 0x84,
  37212. 0x45, 0xA1, 0x1A, 0x08, 0x3A, 0xA0, 0x29, 0x77,
  37213. 0xC2, 0xE8, 0x88, 0x6E, 0xD2, 0x70, 0x67, 0x2E,
  37214. 0x51, 0x2A, 0xE8, 0x9C, 0x6A, 0x26, 0xFC, 0xAD,
  37215. 0x1E, 0xC7, 0x2B, 0x9E, 0xCF, 0xA5, 0xA5, 0xEF,
  37216. 0xC7, 0x0F, 0xF0, 0xBA, 0xB2, 0x8F, 0x11, 0x4F,
  37217. 0x4D, 0xA8, 0x17, 0x0F, 0xE8, 0xB6, 0x3C, 0x2E,
  37218. 0x11, 0xBE, 0x7A, 0x35, 0x46, 0x6E, 0x97, 0x9A,
  37219. 0x12, 0x7E, 0xC0, 0xD2, 0x03, 0x23, 0xD5, 0x02,
  37220. 0x73, 0x0A, 0xBC, 0xE6, 0x40, 0xA2, 0x44, 0x1C,
  37221. 0xDD, 0xAB, 0xA3, 0x26, 0xD6, 0x78, 0x3D, 0x01,
  37222. 0x92, 0xDB, 0xA9, 0xE9, 0x3F, 0xE5, 0x07, 0xC6,
  37223. 0xA7, 0x37, 0x67, 0xBE, 0x56, 0xE2, 0x77, 0x65,
  37224. 0x76, 0xEF, 0xEF, 0xF1, 0xCA, 0x17, 0x9D, 0x83,
  37225. 0x34, 0x3E, 0x38, 0xC6, 0xA9, 0xC2, 0xFE, 0x72,
  37226. 0x5D, 0xDE, 0x80, 0x7D, 0x21, 0x72, 0x5E, 0x73,
  37227. 0x08, 0x72, 0xE2, 0xAB, 0x3D, 0x90, 0x11, 0x61,
  37228. 0xF4, 0x55, 0xBC, 0xAD, 0x23, 0xA8, 0x43, 0x3A,
  37229. 0x41, 0x31, 0x51, 0xFD, 0x22, 0x17, 0x14, 0x31,
  37230. 0x0E, 0x4D, 0x0B, 0x6A, 0x1E, 0x1B, 0x2C, 0xAC,
  37231. 0xA4, 0x99, 0xEE, 0xE8, 0x05, 0xA1, 0x64, 0xF2,
  37232. 0x91, 0xD5, 0x07, 0x5E, 0x6B, 0x65, 0xA7, 0x9C,
  37233. 0x2B, 0xCA, 0xD9, 0x17, 0xB1, 0x22, 0xFE, 0x1A,
  37234. 0xC4, 0xFB, 0xB4, 0x10, 0x21, 0x1B, 0xA0, 0xA1,
  37235. 0x99, 0x7A, 0x31, 0x30, 0x7C, 0x01, 0xF0, 0xFE,
  37236. 0xD3, 0xB3, 0x14, 0x3D, 0x28, 0x34, 0x0F, 0xAC,
  37237. 0xF0, 0x93, 0x37, 0xC4, 0xEF, 0x04, 0x74, 0x80,
  37238. 0xA2, 0x90, 0xAE, 0x02, 0xB2, 0xF7, 0xD8, 0x7B,
  37239. 0x8C, 0x29, 0xA0, 0xAE, 0xAE, 0x2E, 0x92, 0xC9,
  37240. 0xC5, 0x44, 0x7D, 0x66, 0xC5, 0x5C, 0x1D, 0x1E,
  37241. 0x25, 0x88, 0x5D, 0x10, 0x37, 0xFB, 0x5F, 0xCC,
  37242. 0x80, 0x15, 0x4F, 0x1D, 0x23, 0xB4, 0xF2, 0x7B,
  37243. 0x5B, 0xAC, 0x89, 0xBE, 0x1C, 0x36, 0x3C, 0xFF,
  37244. 0x8E, 0xA7, 0x58, 0x73, 0xAC, 0x3F, 0x63, 0x33,
  37245. 0xE8, 0x6C, 0x53, 0xEC, 0xA5, 0x5D, 0xBE, 0xD5,
  37246. 0xE1, 0xF1, 0x12, 0x6B, 0x12, 0x78, 0xC7, 0x29,
  37247. 0xC9, 0xA8, 0x4C, 0x4A, 0x1B, 0x7F, 0x15, 0x11,
  37248. 0x93, 0x01, 0xC8, 0x0B, 0xE2, 0x2F, 0xE9, 0xBE,
  37249. 0xBA, 0x17, 0x59, 0x45, 0xB2, 0x61, 0x2B, 0x66,
  37250. 0xDD, 0xCE, 0xDF, 0x9A, 0x2A, 0x4D, 0x5F, 0x24,
  37251. 0xF9, 0x02, 0xBB, 0xA6, 0x8D, 0xA7, 0x5D, 0x95,
  37252. 0x97, 0x2E, 0x28, 0xD6, 0xCB, 0x70, 0x17, 0xCA,
  37253. 0x51, 0xED, 0x58, 0x73, 0xAB, 0x03, 0xDD, 0x2E,
  37254. 0x92, 0x6C, 0x15, 0x64, 0x2C, 0x9D, 0x6E, 0x64,
  37255. 0x27, 0xFC, 0xE8, 0x0F, 0xC3, 0x8B, 0x34, 0xFE,
  37256. 0xB3, 0xC1, 0x55, 0x13, 0xA6, 0x87, 0xC3, 0x5B,
  37257. 0x94, 0xEB, 0x83, 0xE4, 0xAB, 0x3E, 0x18, 0x76,
  37258. 0x67, 0x92, 0x70, 0xF5, 0xA9, 0x8F, 0x18, 0xA6,
  37259. 0x5F, 0x57, 0x41, 0x76, 0x55, 0xFD, 0xA9, 0x99,
  37260. 0x4E, 0x8F, 0xCC, 0x61, 0x6C, 0x6C, 0x60, 0x06,
  37261. 0x10, 0x40, 0x26, 0xD6, 0xCD, 0x7A, 0xA0, 0x56,
  37262. 0x3D, 0x51, 0x07, 0x25, 0x76, 0x00, 0x05, 0xF5,
  37263. 0xFD, 0x39, 0xE7, 0x59, 0x24, 0x90, 0x29, 0xF0,
  37264. 0x3D, 0x9F, 0x00, 0x67, 0x10, 0x3F, 0xA0, 0x45,
  37265. 0x21, 0x14, 0xDF, 0x24, 0x40, 0xE8, 0xC6, 0xDB,
  37266. 0x65, 0xE2, 0x39, 0x56, 0xEB, 0x1B, 0xEE, 0xB2,
  37267. 0xC3, 0x4E, 0x5B, 0x20, 0xAC, 0x31, 0x6A, 0x03,
  37268. 0xA9, 0x54, 0x36, 0x66, 0x62, 0x68, 0xC3, 0xD8,
  37269. 0x22, 0x8F, 0x62, 0xEB, 0x56, 0x67, 0xB3, 0xB6,
  37270. 0xBB, 0x85, 0x7D, 0xD0, 0x73, 0x7B, 0x69, 0x05,
  37271. 0x1E, 0x9F, 0x26, 0xEE, 0x02, 0x36, 0x71, 0xCE,
  37272. 0xAD, 0xFA, 0xCA, 0xF9, 0x49, 0x7F, 0x1A, 0xDE,
  37273. 0x58, 0x7A, 0x69, 0x3E, 0xEF, 0xFB, 0xFC, 0xD5,
  37274. 0x50, 0xEC, 0x20, 0x8C, 0x23, 0x56, 0x91, 0xE8,
  37275. 0xE3, 0x66, 0xD9, 0x65, 0xB6, 0x2B, 0xEC, 0x16,
  37276. 0xA6, 0x61, 0xCD, 0x5D, 0xE2, 0x87, 0x93, 0x22,
  37277. 0x0D, 0x66, 0xF2, 0x64, 0x55, 0x05, 0xB8, 0x52,
  37278. 0x41, 0x2F, 0xAE, 0x7B, 0x9D, 0x98, 0x29, 0xBF,
  37279. 0x61, 0x5F, 0x7C, 0xBD, 0x59, 0xA7, 0xBC, 0x1D,
  37280. 0x03, 0x4E, 0x6A, 0x25, 0x52, 0x9C, 0xFB, 0x48,
  37281. 0x6A, 0xF2, 0x01, 0xDE, 0xB7, 0xEA, 0x95, 0xBA,
  37282. 0x70, 0x8A, 0x31, 0x59, 0x17, 0x16, 0x74, 0x34,
  37283. 0x53, 0x09, 0xDB, 0x81, 0x50, 0xE6, 0x7E, 0xBB,
  37284. 0x30, 0xA7, 0xFF, 0x80, 0xCA, 0xC9, 0xAB, 0x13,
  37285. 0x92, 0x50, 0x0A, 0x83, 0xE6, 0x3B, 0xBF, 0x7C,
  37286. 0x42, 0xEB, 0x94, 0x53, 0xC2, 0xC9, 0xAC, 0xDA,
  37287. 0x02, 0xBE, 0x53, 0x82, 0x34, 0xAA, 0xA7, 0xDB,
  37288. 0x5A, 0x7F, 0x58, 0x8F, 0xC9, 0x1B, 0x90, 0xEE,
  37289. 0x24, 0x77, 0xF2, 0xB6, 0x1C, 0xD1, 0x06, 0x2A,
  37290. 0x7E, 0xF1, 0xE6, 0xE4, 0xDC, 0x54, 0xB3, 0x6D,
  37291. 0x0E, 0x19, 0x93, 0x3E, 0x98, 0x1C, 0xB7, 0x63,
  37292. 0xA9, 0xE1, 0x07, 0xE0, 0x1D, 0xA9, 0x42, 0x0F,
  37293. 0x82, 0xCA, 0x79, 0x35, 0x92, 0xA4, 0x7C, 0x4B,
  37294. 0x97, 0x7F, 0xF2, 0xC8, 0x84, 0x98, 0xDA, 0x95,
  37295. 0xC4, 0x3D, 0x23, 0x2F, 0x42, 0xAF, 0x99, 0x48,
  37296. 0x0B, 0xF0, 0xA4, 0xF8, 0xB7, 0xC4, 0x94, 0x9D,
  37297. 0x1A, 0xE1, 0xD4, 0xFA, 0x8E, 0x1D, 0x1A, 0x8C,
  37298. 0xD0, 0xF9, 0xED, 0x00, 0xDA, 0x59, 0x5E, 0xFD,
  37299. 0x2B, 0x76, 0x6F, 0x0B, 0x79, 0xD4, 0x49, 0x0D,
  37300. 0xB9, 0x28, 0xEC, 0x44, 0xB5, 0x03, 0x0A, 0x74,
  37301. 0xCA, 0x42, 0x81, 0x1A, 0x5B, 0x5A, 0xE5, 0x22,
  37302. 0xC7, 0x76, 0x4D, 0xDF, 0xD9, 0xFD, 0x92, 0xF0,
  37303. 0x06, 0xE9, 0x4B, 0x35, 0xA7, 0xEF, 0x01, 0x42,
  37304. 0xDA, 0x71, 0x78, 0xC2, 0xF5, 0x30, 0x74, 0xD0,
  37305. 0x74, 0x51, 0xB1, 0x55, 0x65, 0xA9, 0xE0, 0xC5,
  37306. 0x7E, 0xA1, 0xB9, 0x4C, 0x88, 0xEA, 0xE7, 0x41,
  37307. 0xB1, 0xF5, 0x01, 0xC4, 0xD3, 0x70, 0x72, 0x7D,
  37308. 0xAD, 0x27, 0x65, 0xF7, 0x95, 0xAD, 0x41, 0x46,
  37309. 0x35, 0x80, 0x0E, 0xC1, 0x94, 0x9D, 0x03, 0x71,
  37310. 0x39, 0xDE, 0x26, 0xAF, 0xCF, 0x93, 0x3D, 0x9A,
  37311. 0x09, 0xC1, 0x27, 0xFC, 0x6B, 0x36, 0xE5, 0x18,
  37312. 0xC6, 0xDE, 0x94, 0x92, 0xBA, 0x70, 0x82, 0x7B,
  37313. 0x68, 0x1C, 0x2D, 0x18, 0xA4, 0x01, 0x23, 0xB6,
  37314. 0xC5, 0xF6, 0x17, 0x37, 0xCB, 0x9D, 0xC6, 0xAA,
  37315. 0x9C, 0xE1, 0x7D, 0x16, 0x8E, 0xBB, 0xDD, 0xD6,
  37316. 0x3C, 0x07, 0x60, 0x19, 0x3C, 0x97, 0x49, 0x33,
  37317. 0xDB, 0x47, 0x4A, 0xA8, 0x9A, 0xF3, 0x0E, 0x16,
  37318. 0x29, 0x38, 0xF6, 0xDB, 0x78, 0x65, 0xDE, 0x23,
  37319. 0x1F, 0x86, 0x16, 0x9C, 0x9E, 0x2A, 0x30, 0x2F,
  37320. 0xC4, 0x1F, 0x1B, 0xE5, 0xF3, 0x6C, 0x55, 0x83,
  37321. 0xFC, 0xD9, 0x1E, 0x21, 0xCB, 0x8A, 0x67, 0x57,
  37322. 0xD3, 0x0A, 0x4B, 0xAC, 0xDB, 0x67, 0xE7, 0xA6,
  37323. 0x1B, 0x0C, 0x8E, 0x21, 0x7E, 0x0C, 0xCB, 0xF5,
  37324. 0x0E, 0xA6, 0x42, 0xCD, 0xE3, 0xFC, 0x74, 0xC7,
  37325. 0xF9, 0xFF, 0xBD, 0xA9, 0xA1, 0xE6, 0x84, 0xBB,
  37326. 0xC9, 0xA8, 0xF7, 0xCD, 0x3F, 0x1B, 0xD0, 0xDB,
  37327. 0x63, 0xDD, 0xDF, 0x4E, 0xA4, 0x79, 0xC2, 0x35,
  37328. 0x65, 0x2C, 0x5D, 0xCB, 0xCA, 0x7B, 0xDD, 0x4E,
  37329. 0x2F, 0x33, 0xE8, 0x71, 0x72, 0xC1, 0x8B, 0x5F,
  37330. 0xF3, 0x90, 0x99, 0x40, 0x8D, 0x27, 0x2F, 0xD0,
  37331. 0xFB, 0x0D, 0x6A, 0x23, 0xB1, 0x43, 0x00, 0xDF,
  37332. 0xC6, 0x4C, 0x02, 0x74, 0x3E, 0x52, 0x36, 0x08,
  37333. 0xE9, 0x73, 0x61, 0x3D, 0xCA, 0xAC, 0x9D, 0x1D,
  37334. 0x14, 0xB3, 0xA6, 0x24, 0x0E, 0xC2, 0xF2, 0x29,
  37335. 0x39, 0x91, 0xF6, 0x90, 0x6A, 0xE3, 0x6C, 0x04,
  37336. 0x69, 0xF3, 0x09, 0x11, 0x34, 0x8E, 0xC1, 0x2D,
  37337. 0xDB, 0xA6, 0xC3, 0xCA, 0x19, 0xBC, 0x69, 0x5F,
  37338. 0xCD, 0x16, 0xE5, 0xAE, 0xF2, 0xAD, 0x7C, 0x73,
  37339. 0x25, 0x15, 0x70, 0xB5, 0xD0, 0x49, 0xA6, 0xC3,
  37340. 0xA5, 0x2F, 0xA3, 0xFC, 0x9E, 0xD5, 0x4E, 0x54,
  37341. 0x97, 0x3A, 0xE7, 0x89, 0xB0, 0xBF, 0xD6, 0xF8,
  37342. 0xCC, 0x26, 0x44, 0xA9, 0xF8, 0x5A, 0xCE, 0x06,
  37343. 0x78, 0xD8, 0x9E, 0xFC, 0x12, 0xB6, 0x11, 0xC3,
  37344. 0xDF, 0xAE, 0x3F, 0x94, 0x50, 0x34, 0xB8, 0x99,
  37345. 0xBE, 0x99, 0xA7, 0x32, 0x88, 0x9F, 0x17, 0xD2,
  37346. 0x08, 0xDC, 0xD7, 0xEE, 0x95, 0x9D, 0x1A, 0xC7,
  37347. 0x61, 0xDB, 0xA4, 0x86, 0x4C, 0x14, 0xB0, 0xA3,
  37348. 0x5E, 0x4C, 0x7B, 0xBD, 0xA0, 0x96, 0xFB, 0x8A,
  37349. 0xB3, 0x22, 0x69, 0x26, 0xC8, 0x9E, 0x7C, 0xDA,
  37350. 0x92, 0x9E, 0xF1, 0x30, 0xC6, 0x92, 0xC9, 0x26,
  37351. 0x59, 0xE6, 0xF4, 0x65, 0x2B, 0xF2, 0x15, 0x63,
  37352. 0x61, 0xC7, 0x7D, 0xBE, 0xEF, 0x5A, 0x06, 0x23,
  37353. 0xA0, 0x67, 0x04, 0x99, 0x0E, 0x19, 0x8A, 0x13,
  37354. 0x67, 0x30, 0x54, 0x32, 0x4B, 0xBB, 0xAA, 0x64,
  37355. 0x36, 0x92, 0xF2, 0x43, 0xD6, 0x7C, 0x1B, 0x4F,
  37356. 0x95, 0xB9, 0x28, 0xAC, 0xF1, 0x68, 0x6F, 0x60,
  37357. 0xC1, 0x44, 0x87, 0xD6, 0xDD, 0x7F, 0x88, 0x01,
  37358. 0xEF, 0x20, 0x93, 0x9E, 0x03, 0xA1, 0xCA, 0x7D,
  37359. 0x74, 0x32, 0xDC, 0xF5, 0x95, 0xF1, 0xE9, 0xED,
  37360. 0xF2, 0xB2, 0x93, 0x57, 0xA1, 0xD4, 0xC7, 0xDA,
  37361. 0x33, 0x51, 0x2C, 0x45, 0x1A, 0x7C, 0x66, 0x04,
  37362. 0x38, 0x2D, 0x90, 0xC3, 0x30, 0x79, 0xD9, 0x57,
  37363. 0x38, 0xE4, 0x71, 0x89, 0xD8, 0x54, 0x9E, 0x43,
  37364. 0xD2, 0x94, 0xE7, 0x3D, 0x1C, 0xA7, 0x48, 0x7B,
  37365. 0x50, 0xD0, 0xED, 0x7C, 0xC6, 0xF9, 0x6B, 0xEE,
  37366. 0xA7, 0x6C, 0xCE, 0xB9, 0x6D, 0x37, 0x92, 0x00,
  37367. 0x4E, 0xB3, 0xE5, 0x49, 0x16, 0x35, 0xA6, 0x7F,
  37368. 0x6F, 0xFA, 0x1F, 0x1D, 0xF6, 0xA1, 0xF2, 0xFD,
  37369. 0xEE, 0x77, 0x84, 0x17, 0x80, 0xAE, 0x08, 0x09,
  37370. 0xD2, 0x92, 0xED, 0x7B, 0x00, 0xF4, 0x2D, 0x80,
  37371. 0x91, 0x19, 0x09, 0xB5, 0x1C, 0x9A, 0x3A, 0xE5,
  37372. 0x4B, 0x7A, 0x6D, 0x7D, 0x29, 0xD2, 0x00, 0x05,
  37373. 0x22, 0xD4, 0xF8, 0x76, 0xE2, 0x5C, 0x0D, 0x6A,
  37374. 0x15, 0x77, 0x22, 0x18, 0x85, 0xFD, 0x30, 0x74,
  37375. 0xF3, 0x3B, 0xDC, 0xD9, 0x6C, 0xDE, 0x80, 0x40,
  37376. 0x4A, 0x37, 0xE1, 0x60, 0x9F, 0x26, 0xCF, 0xBE,
  37377. 0x24, 0xA1, 0xFB, 0xF9, 0x76, 0x2A, 0x1A, 0x23,
  37378. 0x32, 0xE7, 0xA2, 0xD8, 0x2D, 0xF9, 0xD2, 0x0F,
  37379. 0x08, 0x3A, 0xDB, 0x35, 0x35, 0x33, 0x59, 0x0B,
  37380. 0xB1, 0xF9, 0x54, 0x33, 0x49, 0x36, 0x9E, 0x21,
  37381. 0xEC, 0xF5, 0x94, 0xE2, 0x78, 0x07, 0xA5, 0x63,
  37382. 0x50, 0xD6, 0x23, 0x84, 0xDE, 0xAD, 0xA7, 0x89,
  37383. 0xBE, 0x92, 0xF0, 0x12, 0xC1, 0xF8, 0xA7, 0x2D,
  37384. 0x8B, 0xE0, 0x79, 0xF8, 0xD7, 0xBD, 0x04, 0x0B,
  37385. 0xC5, 0xF2, 0x23, 0x36, 0x11, 0x6D, 0x6F, 0x37,
  37386. 0xDB, 0xFB, 0xD2, 0xC7, 0x44, 0xC3, 0xAE, 0x78,
  37387. 0xEC, 0xB4, 0xE0, 0x5A, 0x55, 0xB3, 0xFC, 0xC3,
  37388. 0x1B, 0x8C, 0xA6, 0xDB, 0xE8, 0x95, 0x72, 0x44,
  37389. 0x90, 0x8F, 0x4E, 0xD1, 0xD3, 0x46, 0x6C, 0x9E,
  37390. 0x00, 0xC6, 0xCC, 0xAE, 0xFC, 0x95, 0x4D, 0x85,
  37391. 0x7C, 0x65, 0x5F, 0x74, 0x71, 0xE3, 0x80, 0x88,
  37392. 0xCF, 0x1E, 0xB8, 0xBE, 0xED, 0x8D, 0xC4, 0xFB,
  37393. 0x3E, 0x36, 0xF3, 0xB8, 0x42, 0x1F, 0x37, 0x31,
  37394. 0x8D, 0xA2, 0x35, 0x36, 0x9E, 0x92, 0x3D, 0xD8,
  37395. 0xEA, 0xA7, 0xA2, 0x29, 0x0E, 0x14, 0xBF, 0x59,
  37396. 0x1E, 0x1D, 0x98, 0x27, 0x30, 0x3B, 0xF3, 0x57,
  37397. 0x69, 0x75, 0xCC, 0x3A, 0xB3, 0x49, 0x99, 0x70,
  37398. 0x19, 0x50, 0xAB, 0xF6, 0x7F, 0xF6, 0x55, 0x1A,
  37399. 0xCA, 0x2D, 0xA0, 0x73, 0x50, 0xE0, 0x9C, 0xEE,
  37400. 0x07, 0xEC, 0x37, 0x26, 0x6B, 0xAA, 0xA5, 0x34,
  37401. 0xFD, 0x7B, 0x1A, 0x92, 0x4E, 0xE7, 0x36, 0x1A,
  37402. 0xEB, 0x35, 0xCC, 0x5A, 0x5C, 0x06, 0x7F, 0x77,
  37403. 0xCE, 0x52, 0x33, 0x57, 0x73, 0x9D, 0xEC, 0x2D,
  37404. 0x28, 0x0C, 0xC9, 0xBF, 0x06, 0x9E, 0xA7, 0x7C,
  37405. 0x36, 0xF9, 0x0B, 0xC6, 0x7F, 0x0F, 0x66, 0x24,
  37406. 0x65, 0x2D, 0x30, 0x2B, 0xD7, 0x7F, 0x07, 0xD3,
  37407. 0x57, 0xC8, 0x4B, 0xC3, 0x0C, 0xA3, 0x5B, 0xAA,
  37408. 0xAF, 0xEA, 0xF3, 0xA3, 0x9E, 0x9E, 0xD4, 0x63,
  37409. 0xCD, 0x82, 0x8B, 0xBC, 0x5D, 0xEF, 0xE6, 0x2A,
  37410. 0x4D, 0x5B, 0x95, 0x13, 0x17, 0x98, 0xD3, 0x67,
  37411. 0x66, 0x04, 0x9E, 0x71, 0x71, 0xE6, 0xBD, 0x44,
  37412. 0x15, 0x6B, 0x29, 0x76, 0xE4, 0x62, 0x01, 0x99,
  37413. 0xEB, 0xF4, 0x2E, 0x14, 0x29, 0x0D, 0xBF, 0x8A,
  37414. 0x02, 0x30, 0x4A, 0xE7, 0x0D, 0x25, 0x42, 0x9E,
  37415. 0xD7, 0x0C, 0xAD, 0x30, 0xC6, 0xA3, 0x49, 0xF9,
  37416. 0x90, 0x0C, 0x46, 0x5B, 0x77, 0x67, 0x5F, 0x0B,
  37417. 0xE9, 0xA9, 0xFE, 0xFA, 0xC8, 0x5F, 0x19, 0xF7,
  37418. 0x35, 0x09, 0xF7, 0xB5, 0x6D, 0x51, 0x32, 0x17,
  37419. 0xBE, 0xE6, 0xC3, 0xBE, 0x4A, 0x9A, 0x33, 0xDA,
  37420. 0xC6, 0x90, 0xB7, 0xA7, 0x6F, 0x97, 0x9E, 0xD5,
  37421. 0x80, 0xE5, 0x02, 0x9E, 0x58, 0xD6, 0x45, 0x34,
  37422. 0x4D, 0x61, 0x71, 0x19, 0x07, 0x69, 0x1F, 0xAF,
  37423. 0xFF, 0x9F, 0xDE, 0x97, 0x13, 0xA1, 0xDF, 0x47,
  37424. 0x0E, 0x8B, 0xD6, 0xD0, 0x75, 0x40, 0x08, 0x59,
  37425. 0x7D, 0xFB, 0x74, 0x74, 0xF2, 0x48, 0xF4, 0x23,
  37426. 0x1B, 0x5E, 0x18, 0x4E, 0x2D, 0x2D, 0xC5, 0x40,
  37427. 0xD0, 0x90, 0x4F, 0x95, 0x69, 0xC4, 0xDA, 0xFB,
  37428. 0x39, 0x4B, 0x12, 0x7D, 0x22, 0x1E, 0x9A, 0x68,
  37429. 0x5B, 0x68, 0x2E, 0x47, 0x23, 0xB9, 0x6A, 0xBF,
  37430. 0xF7, 0xE2, 0x56, 0x79, 0xDD, 0x7A, 0x72, 0xF9,
  37431. 0x5F, 0x20, 0x6B, 0x29, 0x56, 0xEE, 0x04, 0x11,
  37432. 0x4C, 0x16, 0x34, 0x04, 0x14, 0x54, 0xB5, 0x21,
  37433. 0xAA, 0x6A, 0x46, 0x40, 0xE4, 0xF1, 0x78, 0x7C,
  37434. 0x50, 0xF3, 0x4D, 0xBC, 0x57, 0x34, 0x7C, 0x6A,
  37435. 0xBD, 0x9B, 0xEF, 0x03, 0x80, 0x7D, 0xAB, 0x20,
  37436. 0x0F, 0x77, 0x87, 0x6F, 0x93, 0xFB, 0x24, 0x20,
  37437. 0x82, 0xC7, 0x7E, 0xFB, 0x43, 0x2D, 0xC6, 0xD4,
  37438. 0xE9, 0x27, 0x8C, 0x66, 0xA8, 0x5A, 0x58, 0xC8,
  37439. 0xD8, 0x9A, 0xA8, 0x50, 0x5F, 0x3A, 0x3D, 0x0B,
  37440. 0xC3, 0x4F, 0xCE, 0x94, 0xE0, 0x0D, 0x16, 0xCB,
  37441. 0x20, 0xE0, 0xF5, 0x1A, 0x13, 0x6E, 0x28, 0xA6,
  37442. 0x42, 0xB2, 0xB1, 0x30, 0x1D, 0x56, 0x28, 0xCD,
  37443. 0xF3, 0x4E, 0xA7, 0x3E, 0x74, 0x04, 0x7D, 0xA5,
  37444. 0x86, 0xD9, 0x1A, 0xDF, 0x07, 0xBC, 0x2C, 0x59,
  37445. 0xB1, 0x91, 0x6D, 0x9B, 0xA2, 0xD0, 0x72, 0xE7,
  37446. 0xA5, 0x56, 0x4A, 0x27, 0x56, 0x1F, 0x65, 0xCD,
  37447. 0x90, 0x7B, 0xB7, 0x5A, 0x51, 0x25, 0x75, 0x1B,
  37448. 0xD9, 0xD4, 0xC7, 0x19, 0x8A, 0xB0, 0x3D, 0x38,
  37449. 0x22, 0x61, 0xCF, 0xD9, 0x66, 0xED, 0xF5, 0xB8,
  37450. 0xF5, 0x86, 0xFF, 0x98, 0x1A, 0xB7, 0xFB, 0x67,
  37451. 0xED, 0x25, 0x52, 0xD9, 0x2F, 0x84, 0xDC, 0x96,
  37452. 0x89, 0x2C, 0x52, 0xCF, 0x5F, 0xA0, 0xEA, 0xD0,
  37453. 0xB3, 0x38, 0x98, 0xFC, 0xD7, 0x50, 0x84, 0xCF,
  37454. 0xA5, 0xE9, 0x53, 0x8B, 0x44, 0x38, 0xB5, 0x7D,
  37455. 0xD8, 0xAD, 0x0A, 0xE5, 0x35, 0x78, 0x29, 0xBF,
  37456. 0x9F, 0x6B, 0x2C, 0xBB, 0x97, 0x9D, 0xD3, 0x64,
  37457. 0x23, 0x2B, 0xA8, 0xA4, 0x71, 0xE3, 0xF1, 0x2F,
  37458. 0x61, 0xC9, 0x68, 0xD2, 0x06, 0xD0, 0x4E, 0x87,
  37459. 0x03, 0x99, 0xCC, 0xB1, 0x83, 0xB6, 0x94, 0x61,
  37460. 0x3C, 0xE9, 0xE0, 0x7D, 0x13, 0xAF, 0xCF, 0xE4,
  37461. 0xA6, 0x42, 0x7F, 0x62, 0x8F, 0xFC, 0x10, 0xF1,
  37462. 0x08, 0x4D, 0x1D, 0xFC, 0x0F, 0x37, 0x11, 0xBE,
  37463. 0xD7, 0xF1, 0x80, 0x46, 0xAF, 0xFA, 0x13, 0x65,
  37464. 0x99, 0xAE, 0xF9, 0xD0, 0x13, 0xA7, 0xC7, 0x3A,
  37465. 0xD2, 0xC1, 0x9B, 0x5A, 0xB8, 0xC3, 0x08, 0x13,
  37466. 0x49, 0x40, 0x33, 0x0D, 0x1F, 0x93, 0x5D, 0x10,
  37467. 0x49, 0x3E, 0x4F, 0x90, 0x34, 0xC5, 0xEA, 0xF7,
  37468. 0x24, 0xFF, 0xF3, 0xC5, 0x95, 0xF7, 0x1F, 0x13,
  37469. 0x9A, 0xE0, 0x0C, 0xCD, 0x61, 0x93, 0x39, 0xE6,
  37470. 0xAF, 0xD5, 0x3E, 0xA9, 0xD8, 0xC4, 0x8F, 0x64,
  37471. 0x05, 0x09, 0x45, 0x2A, 0xEB, 0x12, 0xC5, 0x51,
  37472. 0x58, 0x1C, 0x55, 0x20, 0xE9, 0x29, 0x74, 0xC7,
  37473. 0x10, 0x01, 0xF3, 0xA4, 0x56, 0xB4, 0x14, 0xFE,
  37474. 0x9C, 0x10, 0x2F, 0xF8, 0xBF, 0xB5, 0x9C, 0x6E,
  37475. 0xBB, 0xE6, 0x52, 0xE7, 0xAC, 0xA7, 0xCE, 0x41,
  37476. 0x6E, 0x00, 0x66, 0x0A, 0x2F, 0x46, 0x71, 0xB8,
  37477. 0x8F, 0x45, 0x89, 0x26, 0x68, 0xCD, 0x49, 0xDF,
  37478. 0xCB, 0xCD, 0xD6, 0x66, 0xC6, 0xA7, 0x8E, 0xB3,
  37479. 0xE4, 0x72, 0xEF, 0xBA, 0xA6, 0x6D, 0x7A, 0xB7,
  37480. 0xE9, 0xD9, 0xB2, 0x60, 0xB5, 0x82, 0x77, 0x20,
  37481. 0x2A, 0xFA, 0xE3, 0xCB, 0xF5, 0x30, 0x50, 0x30,
  37482. 0xC6, 0x19, 0x67, 0xA8, 0xB8, 0xFA, 0xFE, 0xB6,
  37483. 0xDA, 0xB6, 0xB6, 0xBF, 0x07, 0x90, 0x40, 0xD8,
  37484. 0x5B, 0x15, 0x48, 0x39, 0xCD, 0x99, 0x0F, 0x3A,
  37485. 0x28, 0xD2, 0x2E, 0xBA, 0xAC, 0x6D, 0xA3, 0xF8,
  37486. 0x53, 0x88, 0xF0, 0x86, 0x87, 0x70, 0xF5, 0x07,
  37487. 0xD2, 0x99, 0xC4, 0xCA, 0xDD, 0xD8, 0x8C, 0xEB,
  37488. 0x00, 0x96, 0xB4, 0x62, 0xA3, 0x7B, 0x79, 0x31,
  37489. 0xB2, 0x85, 0xB0, 0x61, 0x39, 0xF2, 0xBC, 0x1D,
  37490. 0x31, 0xC3, 0x0C, 0x7F, 0x70, 0x9A, 0x63, 0x74,
  37491. 0xC6, 0xCB, 0xD3, 0x93, 0x0D, 0x43, 0x7F, 0x80,
  37492. 0x85, 0x87, 0x72, 0x98, 0xE1, 0x6E, 0x9A, 0x59,
  37493. 0x2E, 0x6C, 0xA8, 0x9E, 0xC2, 0xC0, 0x72, 0xFE,
  37494. 0x26, 0xE8, 0xAF, 0x89, 0x61, 0xCA, 0x0D, 0x15,
  37495. 0xCC, 0xB0, 0xBA, 0x10, 0xB8, 0x9D, 0x77, 0x2C,
  37496. 0x6C, 0x28, 0xCC, 0x70, 0x5B, 0x1F, 0x5D, 0x68,
  37497. 0xD4, 0xC8, 0x1F, 0x0F, 0x67, 0xF5, 0x3E, 0x5C,
  37498. 0x70, 0x50, 0x4B, 0x32, 0x12, 0xE6, 0x1A, 0xCE,
  37499. 0xB8, 0x32, 0x5F, 0x1D, 0xC5, 0xFB, 0x07, 0x77,
  37500. 0xAD, 0x85, 0x45, 0x95, 0x04, 0x0D, 0x94, 0x7A,
  37501. 0x1F, 0xDD, 0x05, 0x74, 0x14, 0xA5, 0x9A, 0x66,
  37502. 0xF4, 0x93, 0xBE, 0xF2, 0xA9, 0x5B, 0xCD, 0xAB,
  37503. 0xC7, 0x82, 0xF7, 0xE7, 0x4A, 0x1C, 0x90, 0x6B,
  37504. 0x9A, 0xBD, 0x93, 0xDD, 0x41, 0x56, 0xDA, 0xA5,
  37505. 0x0F, 0x5D, 0x57, 0x2C, 0xBA, 0x07, 0x07, 0x4B,
  37506. 0x91, 0x33, 0xE6, 0x1B, 0x0E, 0x25, 0x9E, 0x36,
  37507. 0xBF, 0xCA, 0x21, 0xCE, 0xC6, 0x82, 0x33, 0x4D,
  37508. 0x42, 0x4F, 0x2E, 0x71, 0xC2, 0xE7, 0x6F, 0x16,
  37509. 0xF6, 0xB7, 0x30, 0x1C, 0xA1, 0xA8, 0xE3, 0xE7,
  37510. 0xB1, 0x71, 0xDD, 0x9F, 0x90, 0x1F, 0x01, 0x1D,
  37511. 0x0A, 0xBD, 0x2C, 0x4A, 0x22, 0x84, 0x5C, 0xBF,
  37512. 0x61, 0x07, 0x24, 0xC4, 0x0D, 0x23, 0xDB, 0xC6,
  37513. 0x28, 0xB1, 0x27, 0xCB, 0x7E, 0x06, 0xF8, 0x3C,
  37514. 0x42, 0xF9, 0x51, 0x2F, 0x21, 0xC5, 0x80, 0x98,
  37515. 0x08, 0x2F, 0x56, 0x58, 0xD7, 0xE0, 0xDA, 0xC4,
  37516. 0x24, 0x0C, 0xE8, 0xFA, 0x94, 0x23, 0x57, 0xA6,
  37517. 0xD8, 0xE2, 0xC5, 0xCC, 0x16, 0x70, 0x55, 0x57,
  37518. 0xC4, 0x52, 0x2D, 0x94, 0xCE, 0x5B, 0x22, 0x8E,
  37519. 0x6C, 0x3D, 0x8E, 0x74, 0x9D, 0xFD, 0x47, 0xC7,
  37520. 0x42, 0x11, 0x41, 0x9F, 0x6A, 0x0A, 0xF6, 0x16,
  37521. 0x97, 0xB1, 0x24, 0xC4, 0x6C, 0x98, 0xF8, 0x62,
  37522. 0x51, 0xE9, 0x67, 0x6D, 0x39, 0x2B, 0x76, 0x19,
  37523. 0x5F, 0x41, 0xF4, 0x82, 0x51, 0x87, 0xFF, 0xAA,
  37524. 0x87, 0xE3, 0x46, 0x87, 0xC0, 0xC9, 0xBB, 0xB5,
  37525. 0xAC, 0xA0, 0xD1, 0x56, 0x54, 0xC2, 0x2C, 0x59,
  37526. 0x9E, 0x78, 0xF9, 0xA6, 0xBA, 0xCB, 0xE2, 0x45,
  37527. 0x8A, 0xC1, 0xE5, 0xDF, 0xC3, 0x81, 0x91, 0xDB,
  37528. 0xDB, 0x9E, 0xE2, 0x9C, 0xB9, 0x44, 0x5F, 0x5D,
  37529. 0x6D, 0x83, 0x8D, 0x2D, 0x3E, 0x72, 0x2F, 0x98,
  37530. 0xFC, 0xFA, 0x5F, 0xC0, 0xF0, 0x03, 0x4A, 0x42,
  37531. 0x19, 0x67, 0x48, 0x24, 0x70, 0x35, 0xAE, 0x37,
  37532. 0x34, 0x27, 0xAB, 0xD6, 0x92, 0xB8, 0xB4, 0x52,
  37533. 0xC9, 0xD1, 0xF0, 0x5C, 0xAC, 0xFA, 0xB9, 0x2D,
  37534. 0xCE, 0xF2, 0x24, 0xE3, 0x53, 0xF4, 0x2D, 0x65,
  37535. 0x8D, 0xBF, 0x27, 0x3F, 0xAF, 0x62, 0xE0, 0x27,
  37536. 0xBE, 0x12, 0xCB, 0x40, 0xA4, 0x99, 0xAF, 0x47,
  37537. 0x19, 0x5F, 0x68, 0x69, 0x7F, 0x8C, 0xD2, 0x1E,
  37538. 0x4A, 0xA1, 0xA4, 0x3D, 0x5A, 0x62, 0x6F, 0x78,
  37539. 0x87, 0x8E, 0xA0, 0xC0, 0xF3, 0x2C, 0x60, 0xC3,
  37540. 0xCE, 0xDD, 0xED, 0x7C, 0xAF, 0xE0, 0x0B, 0x72,
  37541. 0x9D, 0xBA, 0xC6, 0xEE, 0x00, 0x00, 0x00, 0x00,
  37542. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37543. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
  37544. 0x0B, 0x15, 0x1B, 0x1E, 0x24
  37545. };
  37546. #endif
  37547. #ifndef WOLFSSL_NO_ML_DSA_87
  37548. static const byte sk_87[] = {
  37549. 0xF1, 0x79, 0x16, 0xD9, 0x5C, 0x51, 0x2F, 0xEC,
  37550. 0x0C, 0xEF, 0xA6, 0xA1, 0x5C, 0x9F, 0xB3, 0xBF,
  37551. 0x84, 0xFF, 0x8D, 0x7F, 0xA3, 0x55, 0x22, 0xEB,
  37552. 0x1C, 0x91, 0x5C, 0x4D, 0x25, 0x4E, 0x89, 0x35,
  37553. 0x24, 0x8E, 0x3C, 0x08, 0x58, 0x2B, 0x74, 0x5E,
  37554. 0xB2, 0xFD, 0x13, 0x15, 0x2B, 0x5D, 0xAE, 0xEA,
  37555. 0xB0, 0x72, 0x80, 0x42, 0xB0, 0x08, 0x85, 0xBB,
  37556. 0x92, 0xF8, 0x44, 0xA8, 0x6B, 0x42, 0x62, 0x03,
  37557. 0x5C, 0x9F, 0x44, 0x8A, 0x2B, 0x78, 0xEF, 0x5D,
  37558. 0xB3, 0x47, 0xE0, 0x25, 0x04, 0x15, 0xE1, 0x01,
  37559. 0x5F, 0xBB, 0x34, 0x31, 0x91, 0x24, 0x07, 0xC8,
  37560. 0x5A, 0x2F, 0x36, 0x2A, 0x85, 0xA9, 0xAE, 0x42,
  37561. 0x77, 0x23, 0xBF, 0x62, 0x69, 0x7B, 0x77, 0x99,
  37562. 0x1B, 0x3E, 0x93, 0xA3, 0x81, 0x13, 0x3F, 0x95,
  37563. 0x0D, 0x40, 0xE7, 0xC1, 0xAC, 0xBC, 0x17, 0xE4,
  37564. 0xF1, 0xD1, 0x0C, 0xD1, 0x27, 0x4C, 0x8D, 0x3C,
  37565. 0x84, 0x02, 0x02, 0x0A, 0xC5, 0x10, 0x1C, 0xC3,
  37566. 0x4D, 0xD0, 0x94, 0x70, 0x24, 0xC0, 0x89, 0x94,
  37567. 0x08, 0x4D, 0xC2, 0x30, 0x20, 0x63, 0xC0, 0x24,
  37568. 0xE1, 0x80, 0x40, 0xD0, 0x26, 0x68, 0x10, 0x97,
  37569. 0x01, 0x83, 0xC2, 0x91, 0x5A, 0x90, 0x2D, 0x44,
  37570. 0x94, 0x6D, 0x10, 0x09, 0x50, 0x11, 0xA7, 0x0D,
  37571. 0xE4, 0x04, 0x89, 0x9B, 0x80, 0x8D, 0x40, 0xB8,
  37572. 0x45, 0x4B, 0x86, 0x0D, 0xC8, 0xB6, 0x05, 0xC0,
  37573. 0xC0, 0x71, 0x02, 0x09, 0x06, 0xA2, 0x00, 0x2D,
  37574. 0x0B, 0x24, 0x86, 0xA0, 0x90, 0x11, 0x20, 0x16,
  37575. 0x82, 0x1B, 0x24, 0x42, 0xCB, 0xB6, 0x70, 0x43,
  37576. 0x36, 0x05, 0xDA, 0x16, 0x25, 0x9A, 0x34, 0x6C,
  37577. 0xCB, 0xB4, 0x08, 0xC4, 0x16, 0x90, 0x24, 0x29,
  37578. 0x6C, 0x42, 0x90, 0x04, 0x24, 0x06, 0x46, 0x84,
  37579. 0x12, 0x6D, 0xC2, 0x26, 0x00, 0x88, 0x40, 0x02,
  37580. 0x51, 0xC8, 0x40, 0x9C, 0x16, 0x24, 0x82, 0x18,
  37581. 0x26, 0x21, 0x06, 0x0C, 0x12, 0xC2, 0x71, 0x50,
  37582. 0x98, 0x91, 0x4A, 0x40, 0x28, 0x48, 0x48, 0x21,
  37583. 0x5A, 0x18, 0x49, 0x1B, 0xB7, 0x01, 0x5A, 0xC6,
  37584. 0x48, 0xA1, 0x90, 0x2C, 0x14, 0x18, 0x2D, 0xD2,
  37585. 0x20, 0x62, 0xDC, 0xB6, 0x49, 0x00, 0x09, 0x6D,
  37586. 0x40, 0xA8, 0x4D, 0x24, 0xC8, 0x24, 0x4C, 0x06,
  37587. 0x08, 0x80, 0x40, 0x4E, 0xD3, 0x18, 0x88, 0x12,
  37588. 0x09, 0x91, 0x8B, 0x12, 0x31, 0xC9, 0x16, 0x04,
  37589. 0x64, 0x10, 0x72, 0xDA, 0x84, 0x91, 0x92, 0xC6,
  37590. 0x65, 0x22, 0x10, 0x48, 0x18, 0xC9, 0x00, 0x14,
  37591. 0x44, 0x62, 0x24, 0xC1, 0x60, 0x40, 0xC6, 0x10,
  37592. 0x4A, 0x48, 0x28, 0x9B, 0x44, 0x66, 0x91, 0x10,
  37593. 0x52, 0xD3, 0x26, 0x52, 0xD8, 0xA6, 0x0C, 0x0A,
  37594. 0xA8, 0x44, 0xD8, 0x26, 0x0C, 0x64, 0x86, 0x45,
  37595. 0x44, 0x20, 0x00, 0xD2, 0x48, 0x85, 0xDC, 0x46,
  37596. 0x32, 0xC8, 0x22, 0x45, 0x5B, 0x00, 0x8D, 0x20,
  37597. 0xA5, 0x45, 0x01, 0xC1, 0x91, 0xA2, 0x12, 0x84,
  37598. 0x20, 0x47, 0x0E, 0x98, 0xA8, 0x25, 0xD9, 0xA0,
  37599. 0x4D, 0xA4, 0x06, 0x2D, 0x5B, 0xB0, 0x08, 0x21,
  37600. 0xB0, 0x80, 0x4C, 0x10, 0x2C, 0xC4, 0x98, 0x71,
  37601. 0x99, 0x24, 0x24, 0xA4, 0x36, 0x71, 0x4B, 0xB6,
  37602. 0x49, 0xE1, 0x92, 0x00, 0x09, 0x92, 0x4C, 0x89,
  37603. 0x12, 0x49, 0x1A, 0x39, 0x2A, 0xE0, 0x22, 0x69,
  37604. 0x61, 0xB2, 0x50, 0x40, 0x26, 0x8E, 0xC9, 0xA2,
  37605. 0x08, 0x0A, 0x90, 0x24, 0x13, 0x35, 0x06, 0x21,
  37606. 0x24, 0x62, 0x60, 0xB0, 0x01, 0xE3, 0xC6, 0x29,
  37607. 0x5B, 0x28, 0x89, 0x20, 0x90, 0x70, 0xC4, 0xA4,
  37608. 0x31, 0x08, 0x42, 0x11, 0x10, 0xC0, 0x71, 0x98,
  37609. 0x98, 0x20, 0xC4, 0xA8, 0x29, 0x1A, 0x15, 0x32,
  37610. 0xC4, 0x86, 0x6C, 0x18, 0x14, 0x6A, 0x02, 0x46,
  37611. 0x46, 0xDC, 0xC2, 0x4C, 0x81, 0x02, 0x6D, 0x49,
  37612. 0x16, 0x48, 0x10, 0x94, 0x6C, 0x0A, 0x85, 0x90,
  37613. 0x9C, 0x34, 0x84, 0x54, 0x24, 0x25, 0x49, 0xA8,
  37614. 0x21, 0x04, 0xA6, 0x2C, 0x61, 0x00, 0x01, 0x61,
  37615. 0x46, 0x92, 0xE0, 0xA6, 0x44, 0xE2, 0x00, 0x90,
  37616. 0xC8, 0x06, 0x06, 0x90, 0xB8, 0x2D, 0x0B, 0x85,
  37617. 0x85, 0x20, 0x23, 0x0D, 0x83, 0x94, 0x04, 0x54,
  37618. 0x26, 0x50, 0x41, 0x92, 0x29, 0x09, 0x16, 0x20,
  37619. 0x54, 0xC6, 0x2D, 0x81, 0xC8, 0x8C, 0x09, 0x44,
  37620. 0x44, 0xE2, 0x06, 0x30, 0x13, 0x92, 0x49, 0x0B,
  37621. 0x17, 0x48, 0x93, 0x28, 0x86, 0xD8, 0xA4, 0x50,
  37622. 0xD1, 0x32, 0x91, 0x08, 0xB8, 0x05, 0xA4, 0x02,
  37623. 0x62, 0x01, 0x15, 0x82, 0xE3, 0x18, 0x42, 0x83,
  37624. 0xC6, 0x44, 0x43, 0x02, 0x81, 0x53, 0x88, 0x04,
  37625. 0x04, 0x98, 0x31, 0x19, 0x18, 0x46, 0xDB, 0x02,
  37626. 0x89, 0x10, 0x23, 0x81, 0x03, 0x90, 0x71, 0x83,
  37627. 0x26, 0x89, 0x1A, 0x01, 0x05, 0xCA, 0xB0, 0x01,
  37628. 0x4C, 0x84, 0x09, 0x10, 0x11, 0x84, 0x13, 0xB1,
  37629. 0x20, 0x61, 0xB8, 0x41, 0x1B, 0x02, 0x8C, 0x09,
  37630. 0x98, 0x61, 0x83, 0x18, 0x61, 0x08, 0xC1, 0x6D,
  37631. 0x44, 0x86, 0x09, 0xCB, 0x88, 0x8D, 0x93, 0xB4,
  37632. 0x41, 0x58, 0x90, 0x81, 0x04, 0x31, 0x08, 0xD1,
  37633. 0xC4, 0x04, 0x19, 0xB4, 0x4C, 0x1C, 0x88, 0x20,
  37634. 0xCA, 0x30, 0x72, 0x1C, 0xB5, 0x85, 0x13, 0x27,
  37635. 0x32, 0x84, 0xB4, 0x44, 0x04, 0x42, 0x20, 0x61,
  37636. 0x18, 0x52, 0x50, 0x96, 0x44, 0x03, 0x38, 0x86,
  37637. 0xE3, 0x48, 0x31, 0x02, 0x82, 0x68, 0x98, 0x06,
  37638. 0x90, 0x23, 0x28, 0x04, 0x10, 0x18, 0x0D, 0x10,
  37639. 0x28, 0x45, 0x4C, 0x84, 0x6C, 0x09, 0x36, 0x71,
  37640. 0x82, 0x26, 0x64, 0x18, 0xC6, 0x21, 0x90, 0x18,
  37641. 0x22, 0x0A, 0x37, 0x08, 0xC4, 0x94, 0x28, 0xE2,
  37642. 0x30, 0x2C, 0x92, 0xB4, 0x24, 0x63, 0x46, 0x70,
  37643. 0x52, 0x96, 0x0C, 0x8B, 0xA4, 0x05, 0xD3, 0x02,
  37644. 0x85, 0x09, 0x32, 0x92, 0x49, 0x12, 0x21, 0x18,
  37645. 0x43, 0x28, 0x01, 0x32, 0x45, 0x0B, 0xA5, 0x50,
  37646. 0x14, 0x16, 0x65, 0x91, 0x80, 0x65, 0x0A, 0x44,
  37647. 0x66, 0x13, 0xB6, 0x4C, 0x01, 0x38, 0x71, 0x11,
  37648. 0x49, 0x28, 0x22, 0x43, 0x02, 0x0B, 0x34, 0x04,
  37649. 0x01, 0x16, 0x91, 0x80, 0x14, 0x0E, 0x12, 0x93,
  37650. 0x01, 0x00, 0x11, 0x80, 0xDC, 0x28, 0x51, 0x11,
  37651. 0x87, 0x85, 0xC1, 0x34, 0x28, 0x02, 0xA2, 0x11,
  37652. 0x02, 0x38, 0x44, 0x52, 0x14, 0x64, 0xC2, 0xA0,
  37653. 0x01, 0x1B, 0x42, 0x8C, 0xC2, 0xB2, 0x71, 0xCB,
  37654. 0x16, 0x00, 0xCC, 0x10, 0x21, 0x04, 0x12, 0x52,
  37655. 0x84, 0x24, 0x2A, 0xD3, 0x48, 0x12, 0x08, 0x44,
  37656. 0x08, 0x81, 0x88, 0x44, 0x01, 0x23, 0x50, 0xC0,
  37657. 0xA2, 0x09, 0x81, 0x94, 0x50, 0x02, 0x89, 0x61,
  37658. 0x01, 0x31, 0x88, 0x1B, 0xA2, 0x61, 0x90, 0x94,
  37659. 0x84, 0x91, 0x24, 0x09, 0x03, 0x18, 0x22, 0xA3,
  37660. 0x46, 0x60, 0x10, 0x16, 0x4D, 0x48, 0x84, 0x89,
  37661. 0x11, 0x00, 0x2E, 0xCC, 0xC0, 0x40, 0x8C, 0xC0,
  37662. 0x51, 0xE4, 0x42, 0x62, 0xDA, 0x24, 0x11, 0x13,
  37663. 0x19, 0x46, 0x93, 0x34, 0x4C, 0x42, 0x42, 0x24,
  37664. 0xC4, 0x48, 0x90, 0x00, 0x35, 0x80, 0x1B, 0x98,
  37665. 0x51, 0x0B, 0x41, 0x60, 0x0C, 0x25, 0x46, 0x9A,
  37666. 0xA8, 0x89, 0x12, 0x86, 0x4C, 0xE3, 0x16, 0x09,
  37667. 0x14, 0x27, 0x24, 0x51, 0x26, 0x4D, 0x1B, 0x02,
  37668. 0x10, 0x00, 0x17, 0x28, 0xD4, 0xA8, 0x45, 0x48,
  37669. 0x88, 0x48, 0x01, 0xC7, 0x0D, 0x93, 0xC8, 0x40,
  37670. 0x5B, 0x02, 0x49, 0x51, 0x02, 0x4A, 0x01, 0x42,
  37671. 0x10, 0xE1, 0x08, 0x90, 0x03, 0x85, 0x48, 0x11,
  37672. 0xA8, 0x68, 0x8B, 0x90, 0x08, 0x5A, 0x02, 0x0C,
  37673. 0x5A, 0x18, 0x50, 0x11, 0x87, 0x51, 0x9C, 0x38,
  37674. 0x92, 0xD0, 0x44, 0x82, 0x10, 0x33, 0x21, 0x88,
  37675. 0x44, 0x2D, 0x24, 0x28, 0x0D, 0x22, 0xA3, 0x30,
  37676. 0x49, 0x88, 0x25, 0xA1, 0xB2, 0x01, 0x5C, 0x40,
  37677. 0x20, 0x1C, 0x03, 0x72, 0xCC, 0x96, 0x8C, 0x51,
  37678. 0xA6, 0x88, 0xE3, 0x92, 0x08, 0x13, 0xB0, 0x08,
  37679. 0x5C, 0x38, 0x44, 0x03, 0x47, 0x8E, 0x93, 0x12,
  37680. 0x4A, 0x88, 0x20, 0x48, 0xE0, 0x42, 0x20, 0x81,
  37681. 0x90, 0x09, 0x4B, 0x06, 0x6D, 0xD2, 0x90, 0x10,
  37682. 0x01, 0x82, 0x49, 0x19, 0x28, 0x91, 0xDA, 0x20,
  37683. 0x2A, 0x20, 0x85, 0x40, 0x0A, 0x16, 0x8A, 0x1C,
  37684. 0x83, 0x60, 0xCA, 0x48, 0x4A, 0xA2, 0xC8, 0x50,
  37685. 0xE4, 0x02, 0x31, 0x88, 0x86, 0x88, 0x53, 0x00,
  37686. 0x89, 0x60, 0x08, 0x8A, 0xA2, 0x02, 0x0A, 0x0A,
  37687. 0x34, 0x45, 0x03, 0x04, 0x42, 0x1B, 0x40, 0x09,
  37688. 0x89, 0xA0, 0x69, 0x42, 0x18, 0x49, 0x4A, 0xA8,
  37689. 0x8C, 0x99, 0x90, 0x30, 0xCA, 0x38, 0x91, 0x09,
  37690. 0x31, 0x72, 0x8B, 0x44, 0x29, 0x52, 0xA2, 0x8D,
  37691. 0x08, 0x14, 0x6E, 0xA1, 0x84, 0x50, 0x1C, 0x31,
  37692. 0x46, 0x19, 0xB7, 0x01, 0xCC, 0x06, 0x29, 0x11,
  37693. 0x09, 0x20, 0x4B, 0x40, 0x66, 0x40, 0xC4, 0x49,
  37694. 0x00, 0x13, 0x24, 0xD0, 0xA2, 0x84, 0xCA, 0x16,
  37695. 0x29, 0xD0, 0xC0, 0x84, 0xC8, 0x88, 0x44, 0xE1,
  37696. 0x20, 0x29, 0x1A, 0x97, 0x05, 0x90, 0x42, 0x90,
  37697. 0x04, 0x40, 0x71, 0x9C, 0x32, 0x4E, 0x64, 0x26,
  37698. 0x22, 0x93, 0x36, 0x66, 0xD3, 0x06, 0x49, 0xA3,
  37699. 0x26, 0x51, 0x4C, 0xA6, 0x89, 0x84, 0x36, 0x84,
  37700. 0x93, 0x46, 0x6D, 0x14, 0x07, 0x8D, 0x18, 0x29,
  37701. 0x42, 0x52, 0x34, 0x72, 0x44, 0x10, 0x90, 0x12,
  37702. 0x37, 0x81, 0xD4, 0x10, 0x64, 0x04, 0xA5, 0x08,
  37703. 0x84, 0x24, 0x09, 0x1C, 0x08, 0x8D, 0x02, 0x99,
  37704. 0x6C, 0x1B, 0x30, 0x50, 0x09, 0x89, 0x81, 0x19,
  37705. 0x30, 0x48, 0x5B, 0x14, 0x4D, 0xD9, 0x20, 0x20,
  37706. 0x0C, 0x01, 0x2A, 0x00, 0x90, 0x4D, 0xA1, 0x02,
  37707. 0x64, 0x1C, 0x03, 0x01, 0xC2, 0x26, 0x8C, 0x14,
  37708. 0x08, 0x45, 0xE3, 0x12, 0x48, 0x09, 0x20, 0x09,
  37709. 0x41, 0x40, 0x61, 0x90, 0x44, 0x21, 0x49, 0x06,
  37710. 0x91, 0x4B, 0xC0, 0x84, 0x22, 0x95, 0x51, 0x23,
  37711. 0x38, 0x0E, 0x5C, 0x28, 0x70, 0xC2, 0x40, 0x2C,
  37712. 0x94, 0x18, 0x62, 0x9A, 0x30, 0x4A, 0xE2, 0x86,
  37713. 0x4C, 0x5C, 0x10, 0x8D, 0xC2, 0x12, 0x21, 0x9C,
  37714. 0xC4, 0x4D, 0xD9, 0x96, 0x88, 0x0C, 0x29, 0x45,
  37715. 0x1B, 0x45, 0x6A, 0x1A, 0x00, 0x60, 0x91, 0x30,
  37716. 0x0C, 0x12, 0x00, 0x69, 0xA2, 0xA0, 0x04, 0x81,
  37717. 0x00, 0x65, 0x5C, 0x38, 0x8A, 0x18, 0x05, 0x89,
  37718. 0x48, 0x32, 0x24, 0x81, 0xC6, 0x4D, 0x60, 0x90,
  37719. 0x31, 0x83, 0x22, 0x12, 0xE1, 0xC2, 0x6C, 0x89,
  37720. 0x00, 0x90, 0x14, 0xB4, 0x40, 0xD3, 0xB8, 0x45,
  37721. 0x89, 0x24, 0x70, 0x09, 0x26, 0x6C, 0xD9, 0x32,
  37722. 0x8A, 0x83, 0x44, 0x0E, 0x21, 0x44, 0x61, 0x99,
  37723. 0xA4, 0x20, 0x44, 0x16, 0x2E, 0x1A, 0xC2, 0x08,
  37724. 0x09, 0x98, 0x6C, 0x8C, 0x18, 0x8C, 0x0C, 0x30,
  37725. 0x62, 0x8B, 0x46, 0x45, 0x80, 0x10, 0x21, 0x20,
  37726. 0x33, 0x32, 0x5A, 0x38, 0x4C, 0x98, 0x06, 0x45,
  37727. 0x1A, 0x33, 0x09, 0x82, 0x34, 0x44, 0x02, 0x20,
  37728. 0x09, 0x59, 0x00, 0x41, 0x08, 0x13, 0x08, 0xDC,
  37729. 0x18, 0x68, 0x12, 0x47, 0x86, 0x43, 0xB8, 0x21,
  37730. 0x62, 0x02, 0x8D, 0x5C, 0x10, 0x0D, 0x60, 0x96,
  37731. 0x65, 0xA2, 0x22, 0x4C, 0x83, 0x18, 0x09, 0x41,
  37732. 0x08, 0x41, 0x63, 0xC2, 0x80, 0x13, 0x81, 0x65,
  37733. 0x22, 0x03, 0x92, 0x04, 0xA9, 0x4D, 0x1C, 0xB0,
  37734. 0x44, 0x80, 0xC6, 0x24, 0x00, 0x01, 0x44, 0x22,
  37735. 0x11, 0x80, 0x21, 0x95, 0x64, 0x09, 0x99, 0x8C,
  37736. 0xD3, 0x14, 0x4A, 0xD1, 0x98, 0x2D, 0x19, 0x31,
  37737. 0x4C, 0x0A, 0x92, 0x40, 0x13, 0x98, 0x48, 0x14,
  37738. 0x89, 0x20, 0x23, 0xB3, 0x0D, 0x14, 0x98, 0x6D,
  37739. 0x12, 0x98, 0x05, 0x9B, 0x14, 0x06, 0x5B, 0x26,
  37740. 0x91, 0x0A, 0x38, 0x09, 0x08, 0x98, 0x2C, 0x19,
  37741. 0xA0, 0x45, 0x44, 0x26, 0x00, 0x0A, 0x05, 0x21,
  37742. 0xDB, 0xA0, 0x69, 0x51, 0x42, 0x92, 0x0B, 0x43,
  37743. 0x00, 0xD1, 0x42, 0x0D, 0x81, 0x30, 0x28, 0x13,
  37744. 0xC2, 0x20, 0x03, 0x27, 0x60, 0x10, 0x83, 0x91,
  37745. 0x0A, 0x53, 0x7E, 0xA1, 0x4F, 0x11, 0x54, 0x5E,
  37746. 0x25, 0x4F, 0xCF, 0x28, 0x03, 0x95, 0x2A, 0x58,
  37747. 0x0A, 0x4B, 0x6C, 0x9B, 0x29, 0x10, 0x3D, 0x97,
  37748. 0x43, 0x6C, 0x00, 0x3E, 0x2E, 0xCE, 0xAE, 0x20,
  37749. 0x28, 0x01, 0x7F, 0xF1, 0xD5, 0x18, 0xB0, 0xB5,
  37750. 0xD5, 0xE6, 0x24, 0x26, 0x64, 0xED, 0x33, 0x7C,
  37751. 0xCA, 0x45, 0x26, 0xED, 0x5D, 0xB5, 0xEA, 0xD8,
  37752. 0xBB, 0x31, 0x16, 0x94, 0x1C, 0xD0, 0xC8, 0xF0,
  37753. 0xA7, 0xED, 0x5A, 0x1A, 0x5A, 0x00, 0xB9, 0x8C,
  37754. 0x33, 0x6A, 0x9B, 0xC8, 0xEB, 0x6B, 0x3A, 0x30,
  37755. 0x83, 0x16, 0xF1, 0x17, 0xEA, 0xA8, 0x0D, 0x4B,
  37756. 0x77, 0x56, 0xDD, 0x4A, 0x91, 0xDA, 0xA5, 0x8E,
  37757. 0x80, 0xD7, 0xB5, 0x77, 0x55, 0x83, 0x97, 0xAF,
  37758. 0x90, 0x5B, 0x67, 0xC5, 0x9F, 0x14, 0xE1, 0x2C,
  37759. 0x15, 0x8D, 0x29, 0x2C, 0xA6, 0xB6, 0x41, 0xED,
  37760. 0x0C, 0x75, 0xE3, 0x9A, 0x91, 0x4F, 0xFA, 0x1A,
  37761. 0x9F, 0x24, 0xCA, 0x28, 0xF2, 0x00, 0xC7, 0x48,
  37762. 0xDE, 0x70, 0x9D, 0x15, 0xD7, 0x22, 0xE7, 0xED,
  37763. 0x2C, 0x91, 0x8D, 0xEF, 0x08, 0xCF, 0xAF, 0x9B,
  37764. 0x7E, 0x24, 0xDE, 0xF2, 0xD5, 0x1A, 0x4D, 0x42,
  37765. 0x0E, 0x7E, 0x89, 0x06, 0xFA, 0xCD, 0x9A, 0x5A,
  37766. 0x98, 0xB0, 0xD1, 0xD5, 0x34, 0x5C, 0x8B, 0x9A,
  37767. 0xC0, 0xBB, 0xF4, 0xB1, 0x5E, 0xF0, 0xB4, 0x6A,
  37768. 0x8E, 0x3B, 0x6B, 0xAE, 0x0C, 0x6E, 0x9F, 0x09,
  37769. 0x2E, 0xB3, 0xEF, 0x1D, 0x49, 0x62, 0x0B, 0x65,
  37770. 0xE7, 0xDE, 0xDB, 0xEF, 0x68, 0x7E, 0xBD, 0x0E,
  37771. 0xA0, 0x95, 0x97, 0x2A, 0x56, 0xA0, 0xEA, 0xFB,
  37772. 0x2D, 0x75, 0xF4, 0x32, 0x1B, 0x80, 0xAC, 0xBC,
  37773. 0xA3, 0x2B, 0x1B, 0x11, 0xAA, 0x57, 0x6F, 0xE4,
  37774. 0xE0, 0xCC, 0xCC, 0x20, 0x52, 0x12, 0x65, 0x42,
  37775. 0x96, 0xF0, 0x60, 0x8F, 0xF3, 0x83, 0x69, 0xAF,
  37776. 0x19, 0x80, 0x75, 0x68, 0xDB, 0xE1, 0x71, 0xDB,
  37777. 0x79, 0xEB, 0x8C, 0x1C, 0xB7, 0x6A, 0x8E, 0xB9,
  37778. 0x5B, 0x28, 0x8C, 0x9D, 0xCC, 0x62, 0x0B, 0xEF,
  37779. 0xCE, 0x96, 0x06, 0x0F, 0x45, 0xA6, 0xA2, 0xDA,
  37780. 0xC2, 0x2F, 0x55, 0xE4, 0x7D, 0xC7, 0xBA, 0xB4,
  37781. 0xA7, 0x93, 0xD9, 0x65, 0x8F, 0xE2, 0x7C, 0x66,
  37782. 0x2C, 0xA6, 0x37, 0x00, 0x81, 0x30, 0xF1, 0x00,
  37783. 0xD9, 0x65, 0xB4, 0x78, 0x17, 0x7A, 0xC6, 0xDC,
  37784. 0x35, 0x93, 0x1A, 0x5E, 0xCC, 0x5F, 0x93, 0x31,
  37785. 0x22, 0x40, 0x2C, 0x17, 0x0E, 0xB8, 0xE0, 0xA4,
  37786. 0x1C, 0xB6, 0x3F, 0xE5, 0x60, 0x2F, 0x7B, 0x18,
  37787. 0xE1, 0xDB, 0xB6, 0xDB, 0x30, 0xA7, 0x61, 0x55,
  37788. 0xC6, 0xCF, 0x03, 0x0F, 0x73, 0x8D, 0xC0, 0x91,
  37789. 0x6D, 0xB1, 0x80, 0xF8, 0x3F, 0x02, 0x90, 0x93,
  37790. 0x11, 0xCB, 0x6B, 0x3B, 0x9E, 0x55, 0x3F, 0xAC,
  37791. 0xA0, 0x52, 0x23, 0xB3, 0x3C, 0x69, 0x60, 0x2D,
  37792. 0x0F, 0x05, 0xA0, 0x8B, 0xEB, 0x84, 0x80, 0x96,
  37793. 0x51, 0x99, 0x9A, 0x55, 0x26, 0xE7, 0x76, 0xF3,
  37794. 0xDE, 0x39, 0x30, 0x4A, 0x5F, 0xEF, 0x00, 0x95,
  37795. 0x0A, 0x9A, 0x81, 0x0D, 0x12, 0xE0, 0x1D, 0x15,
  37796. 0xD8, 0x86, 0xDB, 0x26, 0x75, 0xF6, 0x54, 0xCA,
  37797. 0x17, 0xFA, 0xAE, 0xEB, 0xD1, 0xF5, 0x61, 0xF9,
  37798. 0xD1, 0xA9, 0x5E, 0x0B, 0xAD, 0xF7, 0xC3, 0x31,
  37799. 0x5A, 0xFA, 0xBA, 0x8D, 0x4B, 0xEC, 0x1F, 0x05,
  37800. 0x42, 0xA8, 0xF1, 0x0A, 0xC6, 0x66, 0xFD, 0x8D,
  37801. 0x0C, 0x5A, 0xF1, 0xD6, 0x86, 0x7A, 0x9D, 0x82,
  37802. 0x6B, 0xFB, 0x6B, 0x03, 0x0B, 0x58, 0xEC, 0xEF,
  37803. 0x67, 0x78, 0xD2, 0xC5, 0x2B, 0xF6, 0x2C, 0xB3,
  37804. 0x4B, 0x81, 0xFF, 0x93, 0x6D, 0xA3, 0x3E, 0xDA,
  37805. 0xB3, 0x1D, 0xB3, 0x9A, 0xB7, 0x63, 0x66, 0xD0,
  37806. 0x94, 0x36, 0x2F, 0x04, 0x6D, 0x50, 0x78, 0xB4,
  37807. 0x22, 0x35, 0x04, 0xA1, 0x2B, 0xA0, 0xC7, 0xB8,
  37808. 0xE8, 0x83, 0x72, 0x77, 0x18, 0x50, 0x9B, 0xD4,
  37809. 0x7A, 0x69, 0x6E, 0xE9, 0x88, 0x0C, 0xAF, 0xF6,
  37810. 0x63, 0x61, 0x2B, 0x95, 0x86, 0x30, 0x3D, 0x6D,
  37811. 0xE0, 0xD2, 0x1F, 0x9A, 0x21, 0x96, 0x22, 0x78,
  37812. 0xEB, 0xCE, 0x60, 0xA6, 0xD4, 0x68, 0x44, 0x09,
  37813. 0x5C, 0x5F, 0x89, 0x2D, 0xAC, 0xA4, 0x8D, 0x78,
  37814. 0x28, 0x22, 0x45, 0x38, 0x34, 0xB4, 0xE4, 0x2C,
  37815. 0xD3, 0xA1, 0xFE, 0x39, 0x87, 0x35, 0x6E, 0xAB,
  37816. 0x11, 0xEF, 0xB8, 0xEE, 0xCD, 0x8E, 0x9C, 0xC8,
  37817. 0xF3, 0x9A, 0x0F, 0xF1, 0xFF, 0xB8, 0x06, 0x9A,
  37818. 0x44, 0x1F, 0x85, 0x1E, 0xB4, 0x38, 0xE9, 0xC0,
  37819. 0xB5, 0x7E, 0x88, 0x18, 0xA3, 0x22, 0x65, 0x1E,
  37820. 0x60, 0xF4, 0xB6, 0x78, 0x90, 0xE5, 0xED, 0x7A,
  37821. 0x0F, 0xBF, 0x75, 0x36, 0xC3, 0xFD, 0x50, 0xD0,
  37822. 0xB0, 0x65, 0x8D, 0x7C, 0xCF, 0x27, 0x5E, 0x8A,
  37823. 0x9E, 0x9F, 0xBB, 0x99, 0xBE, 0x2E, 0x5F, 0x5E,
  37824. 0x16, 0x7B, 0xE2, 0x90, 0xB7, 0xE9, 0x67, 0x32,
  37825. 0xF8, 0x9E, 0x40, 0xD7, 0x85, 0xAF, 0x25, 0xC1,
  37826. 0xBA, 0x61, 0xA7, 0x78, 0x6D, 0x3E, 0xF2, 0xD0,
  37827. 0xC1, 0x14, 0xD1, 0x04, 0x8E, 0x76, 0x46, 0xDF,
  37828. 0xA3, 0x03, 0x2B, 0xFB, 0x7A, 0x51, 0xA6, 0x36,
  37829. 0x05, 0xDC, 0xE3, 0xE1, 0xD8, 0x98, 0x95, 0x00,
  37830. 0xD6, 0xE5, 0x8E, 0x96, 0x05, 0x19, 0x93, 0x1D,
  37831. 0xAC, 0x9F, 0x14, 0xDD, 0xA4, 0x28, 0xF5, 0xA2,
  37832. 0xC9, 0xC7, 0x4D, 0x91, 0x6D, 0x90, 0x77, 0x07,
  37833. 0xB5, 0x3E, 0xB5, 0x2C, 0x44, 0xAD, 0x71, 0xD7,
  37834. 0x27, 0x82, 0x6E, 0xB2, 0xCA, 0x68, 0x07, 0x0A,
  37835. 0x6F, 0x0E, 0x47, 0xFA, 0x16, 0xE5, 0x2E, 0x96,
  37836. 0x29, 0xB7, 0xAA, 0x82, 0x41, 0xDA, 0xAB, 0xB1,
  37837. 0x94, 0x97, 0xA5, 0x82, 0x4E, 0x58, 0xD7, 0x26,
  37838. 0x75, 0xC3, 0xA6, 0x7E, 0x10, 0xA1, 0x19, 0xB2,
  37839. 0x74, 0xB8, 0x4D, 0x9B, 0xEE, 0x28, 0x71, 0x72,
  37840. 0x8E, 0xD2, 0xF9, 0x4F, 0x85, 0x59, 0xB9, 0x7F,
  37841. 0x97, 0x9A, 0xE8, 0x82, 0xEA, 0x54, 0x99, 0x28,
  37842. 0xD6, 0xB1, 0xA9, 0xA4, 0xE4, 0xA2, 0x29, 0xF6,
  37843. 0xEB, 0x3F, 0xB1, 0xA4, 0x34, 0xA0, 0xFA, 0xED,
  37844. 0xAD, 0x62, 0xB7, 0x03, 0x30, 0xCF, 0xCB, 0x24,
  37845. 0xCB, 0x34, 0x98, 0x80, 0x2A, 0x67, 0x9F, 0x8F,
  37846. 0x54, 0xBF, 0x83, 0xEF, 0x34, 0x47, 0x22, 0x96,
  37847. 0x91, 0x98, 0x31, 0xCA, 0xAD, 0x59, 0xEB, 0xE8,
  37848. 0x30, 0x82, 0xEA, 0xB6, 0x7D, 0x4A, 0xBD, 0x90,
  37849. 0x22, 0x9A, 0x5E, 0x93, 0xA0, 0xB5, 0x80, 0x97,
  37850. 0x7F, 0x08, 0x13, 0xCC, 0xB1, 0x5E, 0xCD, 0x74,
  37851. 0xFF, 0x71, 0x5F, 0xE8, 0xDB, 0x5B, 0x05, 0xCE,
  37852. 0xF3, 0x7D, 0x34, 0x93, 0xBE, 0xDA, 0x27, 0x05,
  37853. 0x84, 0x94, 0x4C, 0x02, 0x09, 0x86, 0x34, 0x51,
  37854. 0x4D, 0xAA, 0xCE, 0x70, 0x47, 0xE4, 0x74, 0x32,
  37855. 0xF9, 0x2A, 0xDC, 0xA4, 0x91, 0xA3, 0xE0, 0x96,
  37856. 0x1A, 0x5D, 0x9F, 0x01, 0x44, 0x85, 0x2E, 0x46,
  37857. 0x32, 0x63, 0x35, 0xE2, 0x15, 0x24, 0x3D, 0xAA,
  37858. 0xE8, 0x37, 0x92, 0x7F, 0xBF, 0xDC, 0xE6, 0x91,
  37859. 0xF4, 0x98, 0x59, 0x26, 0x6E, 0x90, 0x08, 0x16,
  37860. 0x8C, 0x6A, 0x5E, 0x2F, 0x60, 0x9C, 0x80, 0xC6,
  37861. 0x8E, 0x08, 0x20, 0xE7, 0x27, 0x19, 0xE9, 0xB5,
  37862. 0x87, 0x3F, 0xA1, 0x99, 0xE1, 0x97, 0xF9, 0xC4,
  37863. 0x94, 0xAA, 0x8A, 0x3A, 0x65, 0x26, 0x9E, 0x95,
  37864. 0xB7, 0x61, 0xB6, 0x7B, 0xEC, 0x61, 0x13, 0xC1,
  37865. 0x44, 0xA5, 0x69, 0x89, 0xC5, 0x75, 0x0D, 0x45,
  37866. 0x05, 0x42, 0xCC, 0xF8, 0x1B, 0x24, 0x62, 0x09,
  37867. 0x2F, 0x70, 0x71, 0x5D, 0x49, 0x14, 0xEB, 0x2C,
  37868. 0xAA, 0x31, 0x74, 0xBC, 0x9E, 0xEB, 0x20, 0xAA,
  37869. 0xB6, 0xC6, 0x40, 0xF8, 0xB5, 0xD9, 0xC6, 0xA0,
  37870. 0xDC, 0xC6, 0xF0, 0xAE, 0xC9, 0x7B, 0x3A, 0xF6,
  37871. 0x47, 0xEB, 0xF8, 0x00, 0x34, 0xA4, 0x3B, 0xF3,
  37872. 0x19, 0xBF, 0x40, 0xAD, 0xF7, 0x9A, 0xFE, 0xAB,
  37873. 0x58, 0x90, 0xD2, 0x02, 0x3B, 0xAE, 0x02, 0xC9,
  37874. 0xFD, 0x02, 0xC5, 0xBB, 0x65, 0x87, 0x9C, 0x1B,
  37875. 0x5E, 0xA4, 0x06, 0x02, 0x9A, 0xE7, 0x78, 0x45,
  37876. 0xCB, 0x99, 0x4D, 0xB8, 0xC3, 0x52, 0x11, 0xCA,
  37877. 0x1D, 0xC8, 0x81, 0xF7, 0xF2, 0x0A, 0x47, 0x06,
  37878. 0x50, 0x5F, 0x29, 0xD9, 0xCD, 0x19, 0x89, 0xAD,
  37879. 0x42, 0xB0, 0x7E, 0xF5, 0x2D, 0x96, 0x54, 0xE2,
  37880. 0x8E, 0x3D, 0xCB, 0x83, 0x00, 0x08, 0xA1, 0xBE,
  37881. 0x31, 0x99, 0x38, 0x7E, 0x06, 0x6B, 0x28, 0xB3,
  37882. 0x15, 0xCA, 0x19, 0x02, 0xF4, 0xBB, 0x0E, 0xE6,
  37883. 0x3F, 0xDC, 0x4C, 0x93, 0xE1, 0xAB, 0x88, 0x6F,
  37884. 0xD7, 0x42, 0x52, 0x61, 0xC3, 0x7A, 0xC5, 0x87,
  37885. 0x62, 0xD0, 0x3D, 0xB6, 0x07, 0x06, 0x88, 0x7E,
  37886. 0x72, 0xCF, 0x74, 0x5A, 0x44, 0x6D, 0xF6, 0xC6,
  37887. 0x66, 0x2F, 0x53, 0xDD, 0x61, 0x24, 0x71, 0xA4,
  37888. 0x34, 0xAC, 0x56, 0xC4, 0xBE, 0xDB, 0x3C, 0x9F,
  37889. 0x36, 0x47, 0xE6, 0x03, 0x2B, 0x3C, 0xC0, 0x99,
  37890. 0x0A, 0x3A, 0x2E, 0x87, 0x05, 0x2B, 0x36, 0xD4,
  37891. 0xA1, 0x62, 0x42, 0x4E, 0x2D, 0x39, 0x9E, 0x1B,
  37892. 0xC2, 0x37, 0x92, 0x8D, 0x0B, 0xD7, 0x71, 0x58,
  37893. 0x07, 0x9C, 0xCB, 0x20, 0x8B, 0x71, 0x95, 0x07,
  37894. 0x96, 0x55, 0xBD, 0xB7, 0x6C, 0xBA, 0xFF, 0x44,
  37895. 0x7C, 0x34, 0xC5, 0x82, 0x9F, 0xAC, 0x19, 0x9B,
  37896. 0xB0, 0x27, 0xA0, 0x80, 0x06, 0x50, 0x8D, 0x56,
  37897. 0xC8, 0x1D, 0x18, 0x70, 0x90, 0xE7, 0x10, 0x24,
  37898. 0xDB, 0x7F, 0xBF, 0x3A, 0x7D, 0x64, 0xD8, 0xFA,
  37899. 0x48, 0x74, 0xA8, 0xF4, 0x70, 0x37, 0x7B, 0x15,
  37900. 0x38, 0x00, 0x96, 0x82, 0x2F, 0xFE, 0x46, 0x55,
  37901. 0x71, 0xB5, 0x0C, 0x54, 0x05, 0x58, 0xBA, 0x50,
  37902. 0xE9, 0x0E, 0xB8, 0x14, 0x52, 0xF4, 0x12, 0x75,
  37903. 0xC2, 0x51, 0x5B, 0xAE, 0x05, 0x92, 0xD5, 0x3F,
  37904. 0x6A, 0x6A, 0x34, 0xD2, 0xA3, 0x4D, 0x8E, 0xAC,
  37905. 0x6E, 0x7A, 0x03, 0xFB, 0xDB, 0x52, 0x49, 0x4F,
  37906. 0x4B, 0x98, 0x1B, 0x56, 0xC0, 0x96, 0x26, 0x08,
  37907. 0x48, 0x50, 0xC7, 0xCF, 0x96, 0x2F, 0x93, 0x10,
  37908. 0x72, 0x25, 0x15, 0xA6, 0x2A, 0xC0, 0x85, 0xA6,
  37909. 0x18, 0x9A, 0xDD, 0xEA, 0x38, 0x12, 0x91, 0x13,
  37910. 0x57, 0x31, 0xB2, 0xEE, 0x83, 0xA4, 0xF1, 0xEB,
  37911. 0xFA, 0x09, 0xAF, 0x80, 0xA9, 0x12, 0x68, 0xA8,
  37912. 0x76, 0x23, 0xCB, 0x55, 0x7C, 0x9F, 0x66, 0xDE,
  37913. 0xB4, 0x54, 0xFB, 0x2F, 0x4F, 0xC2, 0x64, 0x8F,
  37914. 0x44, 0x41, 0x5A, 0x7B, 0xEF, 0x29, 0x96, 0x2D,
  37915. 0x5F, 0x7C, 0x16, 0xE7, 0x85, 0x79, 0xF5, 0x26,
  37916. 0xDD, 0x20, 0xE9, 0x20, 0x9B, 0x6C, 0xA6, 0xDF,
  37917. 0xD1, 0x30, 0xF9, 0x2E, 0xF7, 0x24, 0x64, 0x5B,
  37918. 0x5B, 0x84, 0xD8, 0x72, 0x4F, 0x3C, 0xF6, 0xF3,
  37919. 0xA3, 0xB2, 0xA9, 0xCF, 0x61, 0x24, 0x7A, 0x54,
  37920. 0xBA, 0x92, 0x8F, 0x53, 0xEA, 0xCB, 0xA7, 0xE6,
  37921. 0xD6, 0xB8, 0x12, 0xC4, 0xCE, 0x21, 0xA1, 0x8B,
  37922. 0xA8, 0xD1, 0x14, 0x50, 0xE7, 0x04, 0x89, 0xBA,
  37923. 0x57, 0x2E, 0x5E, 0xB9, 0xA7, 0x72, 0x2D, 0x9D,
  37924. 0xC6, 0xAA, 0xE4, 0xF9, 0x57, 0x93, 0x60, 0x09,
  37925. 0xE2, 0x6E, 0xB3, 0xE7, 0x4D, 0x9F, 0x99, 0x33,
  37926. 0xF3, 0xDB, 0x4D, 0xA0, 0xA1, 0xF5, 0x44, 0x93,
  37927. 0x99, 0xB5, 0xE1, 0x01, 0x03, 0x11, 0xF8, 0x7D,
  37928. 0x92, 0xC1, 0x87, 0xAD, 0x2E, 0xFA, 0xBB, 0x0A,
  37929. 0x2C, 0x86, 0xB7, 0xD7, 0xF9, 0xA0, 0x72, 0xAB,
  37930. 0xC0, 0xC6, 0x60, 0x6D, 0xBC, 0xD9, 0x20, 0x17,
  37931. 0x7A, 0x22, 0x57, 0x20, 0xA7, 0x05, 0x76, 0xB8,
  37932. 0xE8, 0x2D, 0x7D, 0x53, 0xC1, 0xDF, 0xA4, 0x8E,
  37933. 0xA7, 0x31, 0x81, 0xAF, 0x0A, 0xF0, 0x86, 0xB6,
  37934. 0xAA, 0xF8, 0x0A, 0xB2, 0x49, 0x81, 0xF2, 0x75,
  37935. 0xD6, 0x6D, 0x4F, 0xBD, 0xE2, 0xC5, 0x1A, 0xE8,
  37936. 0xE8, 0xD4, 0x58, 0x33, 0x72, 0x9F, 0x45, 0x03,
  37937. 0x01, 0x30, 0xBC, 0x85, 0xB2, 0xBD, 0x9A, 0x14,
  37938. 0xC8, 0x13, 0xA3, 0x7F, 0x1F, 0xA1, 0x47, 0xF8,
  37939. 0x15, 0x48, 0x8D, 0x7A, 0x17, 0xC0, 0xC0, 0x39,
  37940. 0xEA, 0xF8, 0x66, 0xCE, 0xA7, 0x5F, 0x5B, 0x2E,
  37941. 0xBE, 0x05, 0xEF, 0x31, 0x09, 0x47, 0x2B, 0xA5,
  37942. 0xF7, 0xCF, 0xCE, 0x4C, 0x35, 0x8B, 0x60, 0x80,
  37943. 0x40, 0x0C, 0x5C, 0xC0, 0x85, 0x15, 0x14, 0x92,
  37944. 0xD1, 0x3A, 0x5B, 0x00, 0x96, 0xA0, 0x63, 0x1F,
  37945. 0xAA, 0x30, 0xCB, 0x48, 0xF2, 0xDA, 0x87, 0x3B,
  37946. 0x85, 0x7D, 0xFD, 0xB3, 0x86, 0xD9, 0x33, 0x98,
  37947. 0x18, 0x07, 0x34, 0x92, 0x55, 0x9A, 0x0E, 0xC2,
  37948. 0xDA, 0xF3, 0x73, 0x8E, 0x15, 0x88, 0xB0, 0x98,
  37949. 0x75, 0x1F, 0xF0, 0xFA, 0x1C, 0x87, 0x1B, 0x22,
  37950. 0x23, 0x7E, 0x5C, 0xD1, 0x5B, 0x0E, 0x17, 0x28,
  37951. 0xEA, 0x26, 0x71, 0x66, 0xC3, 0x8A, 0x71, 0x97,
  37952. 0xB6, 0xCC, 0x7D, 0xAD, 0x39, 0x11, 0x6B, 0xE6,
  37953. 0x1D, 0xF4, 0x33, 0x3C, 0xD7, 0xC2, 0xA4, 0x13,
  37954. 0xDB, 0x30, 0x63, 0xD7, 0xF0, 0x22, 0x8C, 0x61,
  37955. 0xFA, 0xDA, 0xC3, 0xF8, 0xC3, 0x31, 0xF4, 0x45,
  37956. 0x09, 0xB4, 0xD6, 0x08, 0x53, 0x1F, 0x99, 0x5D,
  37957. 0x15, 0xFA, 0xB1, 0x19, 0xD8, 0x47, 0xE6, 0xD8,
  37958. 0x54, 0x95, 0x75, 0xB7, 0xD8, 0x50, 0xB2, 0x60,
  37959. 0x0E, 0x4D, 0x13, 0x64, 0x6C, 0xF9, 0x6B, 0x6B,
  37960. 0x9D, 0xA6, 0xC6, 0x2F, 0x2A, 0x80, 0xAE, 0x02,
  37961. 0x58, 0xA8, 0xCD, 0x6E, 0xF4, 0xC5, 0x5E, 0xEA,
  37962. 0x7E, 0x78, 0xD2, 0x0A, 0x46, 0x4A, 0x19, 0x4C,
  37963. 0xEC, 0xBB, 0x01, 0xE7, 0x3F, 0x32, 0x76, 0xD6,
  37964. 0x6E, 0x12, 0xAD, 0x37, 0x74, 0x51, 0xBB, 0xB9,
  37965. 0x4E, 0x5C, 0x94, 0x88, 0x32, 0x59, 0x5F, 0x6B,
  37966. 0x6E, 0x38, 0x2A, 0xD1, 0x42, 0xD9, 0xF1, 0xB8,
  37967. 0x68, 0x97, 0x95, 0xE9, 0xEB, 0xC3, 0x2A, 0x5A,
  37968. 0x10, 0x1E, 0x69, 0x6C, 0xA3, 0x4A, 0xBA, 0x00,
  37969. 0x5B, 0x4C, 0xED, 0xA2, 0x7D, 0x12, 0x00, 0xFE,
  37970. 0x48, 0xFD, 0x82, 0xC1, 0x72, 0x17, 0xE5, 0x08,
  37971. 0xA8, 0x48, 0x4F, 0x03, 0x88, 0x34, 0x5C, 0x9D,
  37972. 0xED, 0xE2, 0xA1, 0x39, 0x28, 0xFA, 0xC3, 0x29,
  37973. 0x21, 0x84, 0x2F, 0x6E, 0x6A, 0xA5, 0xCF, 0xBF,
  37974. 0x57, 0xFA, 0xA2, 0x8F, 0x43, 0xE0, 0x5E, 0x9A,
  37975. 0x45, 0x23, 0x12, 0x50, 0x29, 0x11, 0xEF, 0x9C,
  37976. 0x33, 0xC8, 0x11, 0xEB, 0xE7, 0xCA, 0xD7, 0x30,
  37977. 0x62, 0x3D, 0xB7, 0x04, 0x8E, 0xC2, 0x18, 0xC7,
  37978. 0xEA, 0x9D, 0xFC, 0x6E, 0x19, 0x65, 0xA9, 0x85,
  37979. 0x7E, 0x92, 0x94, 0xC4, 0xE4, 0x7F, 0x4D, 0x96,
  37980. 0x23, 0xCB, 0x74, 0xB6, 0x5F, 0x7B, 0xB5, 0x86,
  37981. 0x22, 0x83, 0x8D, 0xC4, 0x4E, 0x16, 0xD9, 0x15,
  37982. 0xD9, 0x59, 0x65, 0x55, 0xCA, 0x3D, 0x26, 0x1C,
  37983. 0x9C, 0x2A, 0xFC, 0xCB, 0xAF, 0x5A, 0xC0, 0x3D,
  37984. 0xE0, 0x91, 0xF0, 0xDB, 0xEA, 0xE1, 0xB4, 0xA7,
  37985. 0xE3, 0xDE, 0xC4, 0x39, 0x09, 0x89, 0x67, 0x65,
  37986. 0x77, 0xA0, 0x53, 0x68, 0x4F, 0x57, 0x86, 0x8D,
  37987. 0x91, 0xFE, 0x6A, 0x5B, 0x7D, 0x3D, 0x7C, 0x79,
  37988. 0x50, 0x78, 0x9E, 0x89, 0xD8, 0x38, 0x83, 0xBC,
  37989. 0x3D, 0xAE, 0x55, 0xCA, 0x30, 0x78, 0xB0, 0x8D,
  37990. 0x99, 0x18, 0x31, 0xBA, 0x91, 0x50, 0x2A, 0x5A,
  37991. 0x33, 0x54, 0xB8, 0x8E, 0x15, 0x9B, 0x0A, 0xFF,
  37992. 0xD2, 0x5B, 0x0D, 0xBB, 0x72, 0xBC, 0xD6, 0xF4,
  37993. 0x04, 0x65, 0xDD, 0xFC, 0x00, 0xFF, 0x8B, 0x63,
  37994. 0x39, 0xC0, 0x67, 0x09, 0x5D, 0x6C, 0x7C, 0xB0,
  37995. 0x6F, 0x3B, 0xE7, 0x59, 0xC5, 0x27, 0x40, 0x39,
  37996. 0x5D, 0xD1, 0x08, 0x29, 0x6F, 0x2B, 0xBC, 0x2E,
  37997. 0x7A, 0x5D, 0xDD, 0xE3, 0xD1, 0xC3, 0x5D, 0x18,
  37998. 0xBF, 0xBE, 0x39, 0x68, 0xEC, 0x59, 0xAB, 0xF8,
  37999. 0x5C, 0x1B, 0xD2, 0x92, 0x8A, 0xB2, 0xAA, 0x67,
  38000. 0x8A, 0x78, 0x91, 0x74, 0x6E, 0x88, 0xF4, 0x39,
  38001. 0xF8, 0xB4, 0x38, 0x40, 0x31, 0xC3, 0xED, 0xB7,
  38002. 0x31, 0x97, 0xE5, 0x2A, 0x4E, 0x77, 0x3D, 0x2D,
  38003. 0x8B, 0x7B, 0xAD, 0xDC, 0x5D, 0xD0, 0xA7, 0xE4,
  38004. 0x4C, 0x80, 0x8D, 0x73, 0xB8, 0x18, 0x1D, 0x19,
  38005. 0x1C, 0x3C, 0x89, 0xFE, 0x15, 0xEA, 0x90, 0xD7,
  38006. 0x56, 0x7E, 0x89, 0x16, 0xA3, 0x37, 0x83, 0x03,
  38007. 0x05, 0x04, 0x1B, 0x1E, 0x94, 0xB3, 0xB4, 0x06,
  38008. 0xDA, 0x4C, 0x36, 0xBE, 0xF0, 0x5D, 0x91, 0x00,
  38009. 0xAB, 0x99, 0x2A, 0x4D, 0x56, 0x25, 0x33, 0x73,
  38010. 0x0E, 0x0D, 0x8C, 0x05, 0x2B, 0x3A, 0x62, 0xD3,
  38011. 0xF6, 0x9A, 0x83, 0xA0, 0xC9, 0xB2, 0x12, 0x4F,
  38012. 0x12, 0xAE, 0x7D, 0xAC, 0xC9, 0x78, 0xC4, 0xA0,
  38013. 0xAD, 0xCC, 0x2E, 0xBA, 0x2D, 0x80, 0xF4, 0x94,
  38014. 0xAA, 0x16, 0xEC, 0x1E, 0x8E, 0x71, 0xC7, 0x9B,
  38015. 0x02, 0xF3, 0x26, 0x1B, 0x6F, 0x98, 0x68, 0xB8,
  38016. 0xD5, 0x7E, 0x9D, 0x16, 0xF4, 0x2B, 0x7C, 0xC6,
  38017. 0x64, 0x06, 0x54, 0x9A, 0x27, 0x6D, 0x37, 0x14,
  38018. 0x37, 0xDE, 0x88, 0xB7, 0xF3, 0x9E, 0x74, 0x08,
  38019. 0x7C, 0xBB, 0xC5, 0x61, 0x16, 0x80, 0x31, 0x2D,
  38020. 0xE8, 0xF0, 0xC3, 0x68, 0x14, 0xE1, 0x74, 0xF9,
  38021. 0x1E, 0xB6, 0x00, 0xCC, 0x96, 0xE3, 0xCF, 0x51,
  38022. 0xBB, 0x20, 0x25, 0x88, 0x77, 0xA2, 0xAA, 0xEB,
  38023. 0x82, 0x7F, 0x7F, 0x5A, 0xDA, 0x80, 0x78, 0x6B,
  38024. 0x50, 0x84, 0xC8, 0x02, 0xE6, 0x06, 0xDE, 0xF3,
  38025. 0x88, 0xA3, 0x9C, 0xE4, 0xF0, 0xD5, 0xBC, 0x19,
  38026. 0x39, 0x4C, 0xE8, 0x41, 0xE2, 0xD2, 0xAA, 0x74,
  38027. 0x25, 0x23, 0x05, 0x80, 0xFA, 0x66, 0x75, 0xC5,
  38028. 0x17, 0x41, 0xD1, 0x75, 0x87, 0x9B, 0x4D, 0x03,
  38029. 0xC3, 0x90, 0xF6, 0x52, 0xA5, 0x03, 0xA7, 0x51,
  38030. 0x6A, 0x1F, 0x07, 0x5E, 0x30, 0x82, 0xD5, 0x2C,
  38031. 0x60, 0xB8, 0x64, 0x2A, 0x82, 0x40, 0xEE, 0x94,
  38032. 0x4D, 0x5F, 0xB4, 0x27, 0x37, 0x6B, 0x40, 0xB0,
  38033. 0xB2, 0x82, 0xE1, 0x9A, 0xB9, 0x08, 0xCC, 0xF2,
  38034. 0x0C, 0xA9, 0x26, 0x11, 0x64, 0x90, 0xAF, 0xED,
  38035. 0x57, 0xEA, 0xD0, 0xDC, 0x0C, 0x8E, 0x29, 0x6C,
  38036. 0x79, 0xA4, 0x8D, 0x08, 0x8E, 0x83, 0x7A, 0xF0,
  38037. 0x67, 0xDC, 0x02, 0x9E, 0xC6, 0x31, 0xF9, 0x93,
  38038. 0x3E, 0xE4, 0xD2, 0x07, 0x46, 0xE6, 0x4E, 0x5F,
  38039. 0x21, 0x67, 0x55, 0xA1, 0x38, 0x97, 0x4D, 0x30,
  38040. 0x82, 0x93, 0x73, 0x6D, 0xC1, 0x86, 0x04, 0x27,
  38041. 0x6C, 0xC4, 0x18, 0xBA, 0x69, 0xF8, 0x72, 0xB5,
  38042. 0x8E, 0x7F, 0x6E, 0x3A, 0x8B, 0x84, 0x6E, 0xBA,
  38043. 0xAE, 0xB3, 0x83, 0xE7, 0xF8, 0x90, 0xF5, 0x4E,
  38044. 0x77, 0xF5, 0xD7, 0xF5, 0xD4, 0xA5, 0x8D, 0xB7,
  38045. 0x83, 0xEC, 0xA0, 0x49, 0xF1, 0x86, 0x17, 0x12,
  38046. 0x82, 0xBA, 0xC2, 0x60, 0x7D, 0x51, 0xB2, 0x98,
  38047. 0xB1, 0x49, 0x38, 0xEF, 0xB1, 0x92, 0x8F, 0xC8,
  38048. 0xD0, 0x78, 0x06, 0xE8, 0xC3, 0xE7, 0x3B, 0x46,
  38049. 0x46, 0xBC, 0xF1, 0x68, 0x90, 0xCC, 0x13, 0x80,
  38050. 0xE7, 0xB6, 0x33, 0x50, 0x2B, 0x3E, 0xAD, 0xA4,
  38051. 0x47, 0x75, 0x02, 0xE2, 0x46, 0x7C, 0xFD, 0xB9,
  38052. 0xAC, 0xBD, 0x1C, 0x72, 0xBC, 0x6A, 0xEB, 0x4F,
  38053. 0x41, 0xE1, 0xC2, 0x3C, 0x63, 0x68, 0x39, 0xE3,
  38054. 0x57, 0x13, 0x5F, 0x76, 0xBC, 0x39, 0xC4, 0xF9,
  38055. 0xAC, 0x1C, 0xE8, 0xF1, 0xBE, 0xEF, 0xEB, 0xFF,
  38056. 0x87, 0x59, 0xE8, 0xF7, 0x19, 0x65, 0xD4, 0x85,
  38057. 0x4B, 0xEA, 0xAD, 0x0A, 0xFE, 0xDC, 0xA9, 0xD4,
  38058. 0xD6, 0xBD, 0x1E, 0x63, 0xD3, 0x48, 0xA4, 0x2C,
  38059. 0xEE, 0xFF, 0xC1, 0x70, 0xD0, 0xEE, 0x9F, 0x13,
  38060. 0x6F, 0x5B, 0xE9, 0x90, 0x14, 0x66, 0x92, 0x61,
  38061. 0x22, 0xF9, 0x48, 0xBD, 0xDE, 0x2A, 0x91, 0x07,
  38062. 0xD2, 0xA9, 0x8B, 0xA2, 0xDE, 0xA6, 0xD6, 0xF2,
  38063. 0xDA, 0x17, 0x72, 0x47, 0x02, 0xEC, 0x51, 0x8C,
  38064. 0x03, 0x75, 0x3D, 0x51, 0xEA, 0x83, 0x1E, 0x95,
  38065. 0xCB, 0x87, 0x08, 0xD5, 0xDE, 0xC8, 0x22, 0xDB,
  38066. 0x73, 0x7E, 0x44, 0x14, 0x3C, 0x86, 0xF4, 0x71,
  38067. 0x77, 0xD8, 0x5C, 0xD0, 0x98, 0xC2, 0x1B, 0x9B,
  38068. 0xC8, 0x00, 0xDF, 0xA9, 0xDC, 0x26, 0xFD, 0xC2,
  38069. 0x61, 0xE9, 0x21, 0xDE, 0x00, 0x2D, 0x81, 0xC1,
  38070. 0x59, 0xF8, 0xEB, 0x1F, 0xEE, 0x67, 0x67, 0x9D,
  38071. 0x62, 0x1E, 0xCE, 0x6B, 0x36, 0xD0, 0x1C, 0x77,
  38072. 0x5A, 0x16, 0x45, 0xD5, 0x22, 0x92, 0xB4, 0xB2,
  38073. 0xB8, 0x22, 0x73, 0x18, 0x77, 0x2A, 0x80, 0x91,
  38074. 0xE9, 0xEC, 0x01, 0x70, 0x13, 0xB1, 0x95, 0xEB,
  38075. 0xF4, 0xEF, 0x20, 0x1F, 0x4E, 0x88, 0x1C, 0x49,
  38076. 0x36, 0x33, 0xC0, 0x7F, 0x27, 0xC9, 0x79, 0x0D,
  38077. 0xD8, 0xAE, 0xCC, 0x94, 0x49, 0xCF, 0x63, 0xBC,
  38078. 0xB1, 0x19, 0x46, 0x16, 0x9A, 0xCF, 0xF3, 0x95,
  38079. 0x42, 0x26, 0x6B, 0x0C, 0x66, 0x85, 0xBB, 0xB0,
  38080. 0x80, 0xB5, 0x9F, 0x11, 0x7E, 0xEB, 0x2A, 0x73,
  38081. 0x38, 0x2B, 0x3D, 0x18, 0x7C, 0x06, 0x80, 0xC5,
  38082. 0xAE, 0x70, 0x90, 0x70, 0xDF, 0x03, 0xA0, 0x08,
  38083. 0xA7, 0xAD, 0x13, 0x22, 0x6F, 0x3C, 0x37, 0x15,
  38084. 0x39, 0x20, 0x52, 0xF2, 0x44, 0x1B, 0x4A, 0x17,
  38085. 0x8D, 0x7C, 0xF7, 0x05, 0x18, 0x33, 0x9C, 0xFF,
  38086. 0xBB, 0x54, 0xA6, 0xD9, 0xB9, 0xCD, 0xE3, 0xB0,
  38087. 0xB5, 0x7D, 0xBC, 0x79, 0xF4, 0xE4, 0x7A, 0xD6,
  38088. 0x27, 0x4C, 0xE2, 0x18, 0x0C, 0x92, 0xAC, 0x64,
  38089. 0x10, 0xE5, 0x0D, 0x05, 0xF6, 0x66, 0x5A, 0x57,
  38090. 0xD4, 0xD4, 0x47, 0x6C, 0x2C, 0x0E, 0x6E, 0xE0,
  38091. 0x75, 0x7A, 0x3A, 0xFE, 0xA2, 0xB1, 0xBF, 0x86,
  38092. 0xA5, 0x51, 0xEF, 0x98, 0xAA, 0x1D, 0xFC, 0xBA,
  38093. 0x96, 0x31, 0x59, 0x59, 0x45, 0x2B, 0x2B, 0x3A,
  38094. 0x2F, 0xCB, 0xBB, 0x95, 0x5C, 0xB3, 0xFA, 0x1E,
  38095. 0xEB, 0xBB, 0x83, 0xBD, 0x17, 0x87, 0x67, 0xC0,
  38096. 0x2E, 0xFB, 0xBE, 0xFF, 0x6C, 0x7E, 0xEF, 0x94,
  38097. 0xB5, 0x5D, 0xF8, 0x83, 0x1D, 0xDF, 0xB7, 0xB2,
  38098. 0x02, 0xCE, 0x7D, 0xE0, 0x55, 0xEA, 0xF9, 0x92,
  38099. 0x8A, 0xDA, 0xF6, 0xED, 0x0E, 0x31, 0x59, 0xCA,
  38100. 0x56, 0xC4, 0x83, 0xFA, 0x3B, 0xA3, 0xD2, 0x47,
  38101. 0x8C, 0xA3, 0x94, 0x82, 0x4C, 0xEE, 0x6A, 0xBD,
  38102. 0x59, 0x67, 0x09, 0x53, 0xEE, 0x80, 0xD3, 0x83,
  38103. 0xAA, 0xA6, 0x08, 0xE1, 0x58, 0x51, 0x13, 0x5C,
  38104. 0x1C, 0xDE, 0xEE, 0xB5, 0xF6, 0xA8, 0x89, 0x7C,
  38105. 0x3C, 0x9E, 0x06, 0x6A, 0xB4, 0x73, 0x4F, 0xDD,
  38106. 0xFA, 0xBC, 0x3B, 0xC3, 0xBA, 0x12, 0x06, 0xBA,
  38107. 0x54, 0x34, 0xDC, 0xDE, 0xDB, 0x9D, 0x8B, 0x3A,
  38108. 0x81, 0xA2, 0xE6, 0x38, 0x14, 0x6D, 0x83, 0xF1,
  38109. 0x4F, 0x06, 0xE5, 0x60, 0x99, 0xC0, 0xC8, 0xA0,
  38110. 0xFC, 0xCD, 0xB9, 0xEC, 0xF0, 0xF3, 0xD8, 0x8D,
  38111. 0xE3, 0x79, 0x2F, 0x2D, 0x0B, 0x65, 0x1B, 0x61,
  38112. 0x9C, 0x57, 0x1B, 0x69, 0xF4, 0xBF, 0x8E, 0x7C,
  38113. 0xD1, 0x91, 0x0F, 0x26, 0x6A, 0x4D, 0xAD, 0xF8,
  38114. 0xC2, 0xAB, 0xB4, 0xAC, 0x05, 0xBD, 0x1F, 0xBA,
  38115. 0x05, 0x8C, 0x03, 0x94, 0xC0, 0x16, 0xDE, 0xE6,
  38116. 0x0C, 0x66, 0x40, 0x1A, 0x17, 0xD1, 0x34, 0x59,
  38117. 0x54, 0x79, 0x33, 0x38, 0x9A, 0x35, 0x65, 0x69,
  38118. 0xAD, 0xA5, 0x32, 0xC9, 0xF4, 0x87, 0x69, 0x88,
  38119. 0x55, 0xA4, 0xD7, 0xBC, 0xCD, 0x0E, 0xF6, 0x95,
  38120. 0x31, 0x09, 0x4D, 0xA4, 0x08, 0x6F, 0x52, 0xBF,
  38121. 0x98, 0xCD, 0xC9, 0xA4, 0xB0, 0xBC, 0x88, 0x8D,
  38122. 0xC3, 0x89, 0x1A, 0x76, 0x09, 0x6C, 0x7C, 0x48,
  38123. 0x34, 0x90, 0xE9, 0x52, 0x32, 0x6A, 0xE4, 0x02,
  38124. 0xD8, 0xDF, 0xD2, 0xF3, 0xDC, 0xCF, 0x1A, 0xA5,
  38125. 0xD7, 0xBD, 0x69, 0x8E, 0x2A, 0xA8, 0x8D, 0x29,
  38126. 0x48, 0x13, 0xA8, 0x8F, 0xD3, 0x18, 0x66, 0xBC,
  38127. 0xA1, 0x1B, 0x3B, 0x91, 0xC0, 0x09, 0xEE, 0xB6,
  38128. 0x67, 0x60, 0x1C, 0xEE, 0xAF, 0xAF, 0xE9, 0x7C,
  38129. 0x56, 0xFA, 0x33, 0xF9, 0x38, 0x1F, 0x3E, 0x43,
  38130. 0x29, 0x90, 0x1A, 0xC3, 0xB7, 0xEA, 0x70, 0x32,
  38131. 0xC0, 0x19, 0xE5, 0xC8, 0xA8, 0xEF, 0xD7, 0x04,
  38132. 0x4C, 0x97, 0x36, 0x44, 0xAF, 0x2B, 0xE4, 0x20,
  38133. 0xA0, 0x33, 0xC6, 0xC2, 0xC7, 0xCE, 0x0C, 0xEA,
  38134. 0x39, 0x34, 0xDC, 0x18, 0xB4, 0x2A, 0xDF, 0xD7,
  38135. 0xA8, 0x46, 0xF4, 0x2D, 0xD4, 0x06, 0x86, 0x6A,
  38136. 0x39, 0x09, 0x29, 0x02, 0x6A, 0xDE, 0x5C, 0x79,
  38137. 0x1B, 0x5F, 0x61, 0xF9, 0x42, 0xB1, 0x55, 0x07,
  38138. 0x7D, 0x82, 0xF2, 0xAF, 0xCC, 0xFF, 0xF8, 0x5B,
  38139. 0x04, 0x06, 0x64, 0x7A, 0x96, 0x27, 0xE3, 0x69,
  38140. 0x5D, 0x4B, 0xEA, 0x3D, 0x58, 0xA6, 0x3E, 0x17,
  38141. 0x18, 0xD1, 0x84, 0xE4, 0x6B, 0x5F, 0x4B, 0xC8,
  38142. 0x41, 0x03, 0x34, 0xA4, 0x09, 0x5D, 0x0F, 0xAF,
  38143. 0x30, 0x6F, 0xB9, 0xDC, 0x10, 0x94, 0x25, 0xC3,
  38144. 0x16, 0x52, 0xD0, 0x6F, 0xF0, 0x51, 0xA1, 0x62,
  38145. 0xEE, 0x2B, 0x7B, 0x1C, 0x54, 0xD6, 0xC7, 0xDE,
  38146. 0xD6, 0xE3, 0x95, 0xAA, 0xD1, 0xA8, 0x6D, 0x03,
  38147. 0xB1, 0xB6, 0xC8, 0x00, 0x76, 0x7E, 0xC1, 0x44,
  38148. 0x12, 0xEE, 0xCE, 0x13, 0x46, 0x20, 0xA6, 0x1D,
  38149. 0x36, 0x9A, 0xF4, 0x9E, 0x21, 0xB0, 0xD1, 0x4B,
  38150. 0xC4, 0x23, 0x06, 0x49, 0xCD, 0xD3, 0xE9, 0xFD,
  38151. 0x84, 0x7A, 0xE5, 0x0B, 0xE9, 0x62, 0xEF, 0xC8,
  38152. 0xCB, 0x0F, 0x33, 0x9F, 0x9E, 0x6D, 0x32, 0x47,
  38153. 0x53, 0x3B, 0xDE, 0xD8, 0x71, 0x1D, 0x46, 0x1D,
  38154. 0x4A, 0xF2, 0xAE, 0x3F, 0xDD, 0x1D, 0x7D, 0x2A,
  38155. 0x28, 0x9C, 0x78, 0xCB, 0x19, 0xF3, 0xCD, 0xC2,
  38156. 0x14, 0x2B, 0xF5, 0x2B, 0x23, 0xE6, 0xA2, 0x7B,
  38157. 0x39, 0xD6, 0x99, 0x54, 0x3C, 0x3D, 0x63, 0x9B,
  38158. 0x9C, 0x72, 0xCA, 0x80, 0xB3, 0x7E, 0xA2, 0x77,
  38159. 0x5B, 0x5E, 0x26, 0x81, 0xF0, 0xDD, 0x01, 0xDF,
  38160. 0xF0, 0xC0, 0x55, 0x13, 0x36, 0x90, 0x62, 0xFE
  38161. };
  38162. static const byte msg_87[] = {
  38163. 0x9E, 0xFF, 0x34, 0x15, 0x06, 0xD1, 0x8B, 0xCB,
  38164. 0x27, 0xA7, 0xFC, 0x4E, 0xAA, 0xBF, 0x5A, 0x7C,
  38165. 0x4A, 0x59, 0x37, 0x77, 0x19, 0x6F, 0x66, 0x4B,
  38166. 0xCE, 0x31, 0x6C, 0x95, 0x5B, 0x83, 0x5A, 0xD4,
  38167. 0xC9, 0xF5, 0xDE, 0x9A, 0x2B, 0xF8, 0x96, 0x15,
  38168. 0xDA, 0xCB, 0x9C, 0x1E, 0x61, 0x8C, 0x78, 0xE7,
  38169. 0x11, 0x44, 0xCD, 0x4B, 0x70, 0x46, 0xF4, 0x7D,
  38170. 0x9A, 0x60, 0x0E, 0x9C, 0xE6, 0x65, 0x96, 0xC4,
  38171. 0xC5, 0x5E, 0xDA, 0x23, 0xA6, 0x6C, 0xC1, 0x18,
  38172. 0xA4, 0xA7, 0xBD, 0x0D, 0xED, 0x00, 0xAB, 0xDD,
  38173. 0xCE, 0x53, 0xFB, 0xF2, 0x48, 0x20, 0x33, 0xA4,
  38174. 0x18, 0x85, 0x06, 0xEC, 0x11, 0x3B, 0xBD, 0x98,
  38175. 0xD9, 0x89, 0x1F, 0x0D, 0x69, 0x46, 0x3A, 0x0D,
  38176. 0x36, 0x15, 0x6B, 0xA3, 0xEA, 0x0D, 0x02, 0xA1,
  38177. 0x4C, 0x1F, 0xD7, 0xA3, 0xFE, 0x70, 0x4E, 0xE5,
  38178. 0x6B, 0x44, 0x6A, 0xE1, 0x79, 0xF7, 0x2E, 0x10,
  38179. 0x4A, 0xA8, 0x1A, 0xF0, 0xA2, 0xF8, 0xFC, 0xA6,
  38180. 0xF6, 0xF9, 0x62, 0x96, 0x05, 0x9E, 0xE8, 0x82,
  38181. 0x66, 0x80, 0xE4, 0x3F, 0x4B, 0x07, 0x40, 0xF4,
  38182. 0x7A, 0xC1, 0x05, 0x66, 0xED, 0x31, 0x07, 0x99,
  38183. 0xAC, 0x71, 0x41, 0xD3, 0x8F, 0x69, 0x21, 0x31,
  38184. 0x5F, 0x23, 0xAB, 0x3E, 0x64, 0xC8, 0xA7, 0x70,
  38185. 0xAA, 0x57, 0x12, 0x80, 0x90, 0xDB, 0x82, 0x8C,
  38186. 0x7B, 0xAA, 0x59, 0xC3, 0x29, 0x5C, 0xCA, 0xA2,
  38187. 0x38, 0xC7, 0x5F, 0xAC, 0x0F, 0x93, 0xDA, 0x79,
  38188. 0x00, 0x74, 0x1B, 0xCD, 0x94, 0xBB, 0x9F, 0xD3,
  38189. 0x85, 0x2E, 0xC2, 0xB7, 0xD3, 0x3F, 0x60, 0x0B,
  38190. 0x1D, 0x51, 0x66, 0x6A, 0xE2, 0x22, 0xA5, 0x7A,
  38191. 0xF1, 0x40, 0xFA, 0x04, 0x9C, 0x2C, 0x9F, 0x6D,
  38192. 0x0F, 0xE6, 0xC0, 0xF1, 0xE7, 0xA0, 0xDD, 0xE1,
  38193. 0x14, 0x3B, 0xE5, 0xCE, 0xD7, 0xBB, 0xE2, 0x32,
  38194. 0xCB, 0xFB, 0xD8, 0xAE, 0x00, 0xEA, 0x5F, 0xC1,
  38195. 0x65, 0x02, 0x6D, 0x72, 0x9D, 0xB3, 0x0F, 0x6A,
  38196. 0xFD, 0x99, 0x73, 0xB6, 0x72, 0x2C, 0x07, 0xF6,
  38197. 0x00, 0x66, 0x54, 0x41, 0xE3, 0x0B, 0x7C, 0x5F,
  38198. 0xB2, 0x97, 0xB8, 0xAB, 0x96, 0x9C, 0x06, 0x83,
  38199. 0x9D, 0x33, 0x1D, 0xEE, 0x96, 0xDE, 0x48, 0x68,
  38200. 0x7D, 0xC9, 0xDA, 0x53, 0x1A, 0x95, 0xCA, 0x83,
  38201. 0xA7, 0x6F, 0x4B, 0x07, 0x6D, 0xFC, 0xF4, 0x83,
  38202. 0xF0, 0x04, 0x50, 0xE5, 0x1C, 0x8D, 0x34, 0xD8,
  38203. 0xED, 0x8E, 0x4B, 0x3D, 0xAF, 0xAE, 0x66, 0x4B,
  38204. 0x6D, 0xC1, 0x3E, 0xD8, 0x8E, 0x6D, 0x63, 0x02,
  38205. 0x7D, 0xD4, 0x38, 0xCB, 0x74, 0xF4, 0x12, 0xE8,
  38206. 0x70, 0xCC, 0x9D, 0xFD, 0x29, 0xB5, 0x2A, 0xBC,
  38207. 0xA1, 0x69, 0xC1, 0x7E, 0x97, 0x47, 0x58, 0xE0,
  38208. 0x3A, 0xC0, 0xFB, 0x7F, 0xE5, 0x64, 0x50, 0x8E,
  38209. 0x01, 0x7A, 0x9B, 0x47, 0x49, 0xD6, 0x41, 0xAF,
  38210. 0x0D, 0xE3, 0x84, 0x08, 0x8F, 0xA0, 0x0C, 0x69,
  38211. 0x40, 0x23, 0x3D, 0xDE, 0xFB, 0x65, 0x7C, 0x18,
  38212. 0x1C, 0x82, 0xA1, 0xB6, 0xA3, 0x1F, 0xCC, 0xF4,
  38213. 0xD5, 0x2C, 0x9D, 0x35, 0x1E, 0x6B, 0xDF, 0xDF,
  38214. 0x48, 0xBC, 0xE4, 0x14, 0x60, 0x74, 0x62, 0xDB,
  38215. 0x76, 0x9F, 0x9E, 0xB1, 0x59, 0x25, 0xBA, 0x9F,
  38216. 0xAF, 0xBA, 0xB2, 0x29, 0xB5, 0x89, 0x6B, 0xF1,
  38217. 0xF8, 0xE4, 0x7D, 0xF1, 0x7C, 0x82, 0x08, 0xDF,
  38218. 0xD5, 0x96, 0x04, 0xB6, 0x05, 0x2C, 0xD2, 0xCE,
  38219. 0xAB, 0x56, 0x40, 0x0F, 0x11, 0xC4, 0xD9, 0x52,
  38220. 0x1E, 0x1A, 0xB8, 0x27, 0x4A, 0xB5, 0x76, 0x4C,
  38221. 0x73, 0xE9, 0x41, 0x32, 0x42, 0x0E, 0x32, 0xB6,
  38222. 0xAE, 0xB0, 0x76, 0x33, 0x78, 0xD9, 0xBA, 0x68,
  38223. 0xE1, 0xFC, 0xDE, 0x2B, 0xD6, 0xDE, 0xDA, 0x39,
  38224. 0x17, 0xC0, 0x00, 0xAF, 0x39, 0xB7, 0x8F, 0x4C,
  38225. 0xCA, 0x7C, 0x8F, 0xBF, 0x94, 0xB4, 0xCB, 0x8A,
  38226. 0x81, 0x16, 0xEE, 0xEC, 0xFE, 0xF0, 0x13, 0x1E,
  38227. 0xC9, 0xF2, 0xDE, 0xDA, 0x01, 0x40, 0xC9, 0x02,
  38228. 0xA8, 0xD6, 0xE6, 0x0E, 0x98, 0xB3, 0xCD, 0x9D,
  38229. 0x9C, 0x75, 0x24, 0x8B, 0xF8, 0x84, 0x5A, 0xC0,
  38230. 0xD7, 0xE0, 0x6B, 0xA0, 0xE1, 0x83, 0x10, 0xFE,
  38231. 0xCE, 0x98, 0x62, 0x07, 0x54, 0x2C, 0xC1, 0xEE,
  38232. 0x08, 0x88, 0x43, 0xEF, 0x74, 0xA2, 0x6A, 0xEC,
  38233. 0xB6, 0xD0, 0x6F, 0x0F, 0xEF, 0xE1, 0xB7, 0x2C,
  38234. 0xF9, 0x33, 0x06, 0xC3, 0x2E, 0xD2, 0x8A, 0xEC,
  38235. 0xC5, 0x5B, 0xB1, 0x03, 0xA0, 0x84, 0x6D, 0x0C,
  38236. 0x84, 0x13, 0x6D, 0xB0, 0xB0, 0x54, 0xF3, 0xDE,
  38237. 0xA3, 0x9A, 0x72, 0x6C, 0x6F, 0xD6, 0x59, 0x7F,
  38238. 0x9B, 0x03, 0x8C, 0xC2, 0x38, 0x46, 0x01, 0x76,
  38239. 0x38, 0xF4, 0x43, 0x68, 0x81, 0x0D, 0x86, 0x29,
  38240. 0x3D, 0xDF, 0xE5, 0x48, 0x61, 0x53, 0x2F, 0x85,
  38241. 0xF5, 0x3F, 0x09, 0x30, 0x48, 0xC3, 0xE0, 0x09,
  38242. 0xC4, 0x32, 0x11, 0x27, 0xAD, 0xAA, 0xEC, 0x6A,
  38243. 0x5C, 0xCE, 0x03, 0xE0, 0xD9, 0xE9, 0x1D, 0xAC,
  38244. 0xCA, 0xBB, 0x2F, 0x50, 0xE0, 0x1E, 0xB2, 0xAC,
  38245. 0x2B, 0x39, 0x6D, 0x24, 0xB0, 0x5D, 0x45, 0x3B,
  38246. 0xD5, 0x1D, 0x52, 0x9F, 0xBA, 0x51, 0xE4, 0x6D,
  38247. 0x30, 0xC5, 0x66, 0x13, 0x00, 0x5A, 0xBF, 0x62,
  38248. 0x63, 0xB9, 0x8D, 0x8D, 0xFE, 0xB5, 0x26, 0x16,
  38249. 0xD1, 0xCB, 0x78, 0x92, 0x18, 0x1C, 0x2F, 0xC2,
  38250. 0xE2, 0x04, 0x3B, 0x99, 0x4C, 0x81, 0x66, 0x58,
  38251. 0x48, 0x2E, 0x06, 0x06, 0x34, 0x83, 0x78, 0xA3,
  38252. 0xCC, 0x85, 0x40, 0xE0, 0x20, 0x27, 0x3F, 0x10,
  38253. 0xB6, 0x9E, 0x20, 0x21, 0xA9, 0x2D, 0x9C, 0x36,
  38254. 0xCC, 0x9B, 0x97, 0x79, 0xFE, 0x8C, 0xE7, 0xA4,
  38255. 0x99, 0xAE, 0xB5, 0x3E, 0xC6, 0xDD, 0xB4, 0xF2,
  38256. 0xEC, 0x22, 0xBF, 0xB4, 0x52, 0xFC, 0x5E, 0x79,
  38257. 0x7D, 0x3A, 0x25, 0x33, 0x26, 0x00, 0x06, 0xFE,
  38258. 0x6D, 0xCC, 0xE4, 0xE9, 0x76, 0x65, 0xC6, 0x8C,
  38259. 0x39, 0x93, 0xDC, 0x7E, 0xA0, 0xBD, 0x4B, 0xDC,
  38260. 0xD2, 0x47, 0x21, 0xB0, 0x2B, 0x09, 0x02, 0xB1,
  38261. 0x84, 0x0D, 0xDE, 0xC5, 0x18, 0x20, 0x38, 0x76,
  38262. 0x2D, 0x55, 0xFC, 0x11, 0xB9, 0x87, 0x3A, 0x0D,
  38263. 0xD2, 0xEB, 0xBD, 0x55, 0xAD, 0xE3, 0x86, 0x5C,
  38264. 0xFF, 0x3D, 0x54, 0x5F, 0x76, 0x33, 0x53, 0x69,
  38265. 0xDD, 0x9E, 0x70, 0xB0, 0x73, 0x99, 0x77, 0xF6,
  38266. 0xE9, 0x8A, 0x61, 0x27, 0x19, 0x4A, 0x19, 0x26,
  38267. 0xA6, 0x97, 0xE4, 0x7F, 0x73, 0xE0, 0x4F, 0xF5,
  38268. 0xBD, 0x52, 0x5E, 0x8F, 0x17, 0x22, 0x00, 0x8F,
  38269. 0x7C, 0x15, 0x5C, 0xD3, 0xAD, 0xE0, 0xA5, 0xB6,
  38270. 0x6A, 0x31, 0x36, 0xFD, 0xD8, 0x44, 0xAE, 0x5E,
  38271. 0xCD, 0x6C, 0x82, 0x77, 0xC3, 0xD0, 0x7F, 0x39,
  38272. 0x72, 0x1E, 0x91, 0x19, 0x50, 0xE1, 0x28, 0x20,
  38273. 0x88, 0x3A, 0x6B, 0xC8, 0xA9, 0xE7, 0x93, 0x28,
  38274. 0x0F, 0xA7, 0x4F, 0xF2, 0x1A, 0xC2, 0x13, 0x4E,
  38275. 0x6B, 0xAE, 0x71, 0x3F, 0x43, 0x89, 0xC9, 0xE7,
  38276. 0xDD, 0x05, 0xBB, 0x41, 0x09, 0xB5, 0x5E, 0xB9,
  38277. 0x23, 0x51, 0xC0, 0xEB, 0x92, 0x1A, 0x0C, 0x3F,
  38278. 0xAC, 0xC5, 0x00, 0x8C, 0xB8, 0x5C, 0x3F, 0x2D,
  38279. 0x5F, 0x9A, 0xCE, 0xAE, 0x9B, 0x4B, 0x71, 0x48,
  38280. 0x25, 0xFD, 0xE2, 0xB6, 0x26, 0x3F, 0xEE, 0x10,
  38281. 0x33, 0x07, 0x4F, 0x59, 0xF0, 0x73, 0xE9, 0x39,
  38282. 0x5C, 0x0D, 0x8B, 0xB5, 0xD1, 0xEF, 0xE5, 0xBF,
  38283. 0xBB, 0xE1, 0x80, 0xF7, 0xC5, 0x91, 0xC1, 0x72,
  38284. 0xAA, 0xB0, 0x5E, 0x7C, 0x53, 0x69, 0x4C, 0x37,
  38285. 0x7A, 0xD2, 0x7B, 0x9D, 0x1C, 0xFA, 0x0F, 0xE0,
  38286. 0x92, 0x93, 0x40, 0x5D, 0xBE, 0x1C, 0xF8, 0x84,
  38287. 0x7A, 0x35, 0x1F, 0x72, 0x77, 0x68, 0xE2, 0xAF,
  38288. 0xA5, 0x6B, 0x54, 0xFF, 0x53, 0x7C, 0xCD, 0x9D,
  38289. 0x6A, 0x49, 0xD1, 0xCA, 0x74, 0x5F, 0xF5, 0xDB,
  38290. 0x54, 0xF8, 0x60, 0xA7, 0x41, 0x66, 0xDE, 0xFF,
  38291. 0xB0, 0xB2, 0xF9, 0x21, 0x06, 0xB7, 0x81, 0x4C,
  38292. 0x9C, 0xEF, 0xFD, 0x11, 0xD5, 0x63, 0xD8, 0xF3,
  38293. 0x3A, 0x81, 0xC4, 0x9D, 0x1B, 0xA8, 0x37, 0x73,
  38294. 0x57, 0x26, 0x29, 0xF8, 0xB4, 0x7F, 0x9F, 0xA2,
  38295. 0x7D, 0x2A, 0x63, 0x2C, 0x70, 0x08, 0x1E, 0x2E,
  38296. 0xE7, 0xED, 0x73, 0xAB, 0xD2, 0x4C, 0x02, 0x7E,
  38297. 0xF1, 0x15, 0x26, 0xE1, 0x09, 0x5C, 0x29, 0x13,
  38298. 0xDF, 0x69, 0x29, 0x25, 0xE5, 0x68, 0x39, 0x10,
  38299. 0x9B, 0xD0, 0x5E, 0xD8, 0xE2, 0xC9, 0x08, 0x61,
  38300. 0x63, 0xCD, 0xF9, 0x45, 0xBC, 0x16, 0xDC, 0x80,
  38301. 0x4C, 0x0F, 0x61, 0xEE, 0x8F, 0x3B, 0x72, 0xDB,
  38302. 0x02, 0x45, 0xF6, 0x78, 0x69, 0x81, 0xFC, 0xE0,
  38303. 0x32, 0x2F, 0xC2, 0xAF, 0xCD, 0x4E, 0x8E, 0x52,
  38304. 0x03, 0xB5, 0x1C, 0x7C, 0x37, 0x2C, 0x58, 0xD5,
  38305. 0xE2, 0x92, 0xA7, 0xE2, 0x49, 0x6C, 0x3F, 0x5D,
  38306. 0x7F, 0x2B, 0x26, 0x70, 0x1C, 0x0C, 0x16, 0x7F,
  38307. 0x49, 0x30, 0x71, 0x14, 0xEB, 0xBE, 0x13, 0xF4,
  38308. 0xF1, 0xAA, 0x5A, 0xCF, 0x98, 0xF2, 0x07, 0x29,
  38309. 0xB5, 0x12, 0x84, 0x80, 0x01, 0x46, 0x11, 0xA4,
  38310. 0x44, 0xAE, 0x6D, 0xE0, 0x43, 0x7F, 0xFD, 0x5D,
  38311. 0x84, 0xB5, 0x6E, 0x3E, 0x55, 0x0D, 0xE8, 0x66,
  38312. 0x13, 0xA9, 0x28, 0x5A, 0x10, 0x84, 0x0B, 0xED,
  38313. 0x0B, 0x69, 0xF0, 0x19, 0x69, 0x9B, 0x34, 0xB8,
  38314. 0x6F, 0xC6, 0x22, 0xD3, 0x25, 0x26, 0x9D, 0x1A,
  38315. 0x04, 0x6B, 0x53, 0xA4, 0xDF, 0x12, 0x93, 0xA5,
  38316. 0x2C, 0xEE, 0x1C, 0x35, 0xFE, 0x81, 0x6B, 0x67,
  38317. 0x81, 0x92, 0x07, 0xE0, 0x9A, 0x02, 0xC9, 0xD8,
  38318. 0x59, 0x4D, 0x51, 0xE8, 0xB3, 0x14, 0x55, 0x2F,
  38319. 0xDE, 0x26, 0xDB, 0x7C, 0xEB, 0x8D, 0x80, 0x12,
  38320. 0x4A, 0x8A, 0x1C, 0x33, 0x74, 0x8E, 0x05, 0xC1,
  38321. 0xAF, 0xD6, 0xE8, 0x7B, 0x56, 0x7C, 0x41, 0xE0,
  38322. 0xE7, 0x3F, 0x32, 0x5F, 0x25, 0xDD, 0x2F, 0x48,
  38323. 0x21, 0x90, 0xC4, 0x04, 0x42, 0x1A, 0x3D, 0x6A,
  38324. 0x0E, 0x5D, 0x5C, 0xDB, 0xE2, 0xB0, 0x18, 0x8B,
  38325. 0xAC, 0x77, 0xC6, 0xE3, 0x5D, 0x77, 0xC0, 0xA3,
  38326. 0x2B, 0x1D, 0x96, 0x29, 0xF8, 0x8E, 0x70, 0xA7,
  38327. 0x65, 0xFE, 0xE3, 0x8C, 0x1A, 0xB2, 0x39, 0x75,
  38328. 0xB9, 0x45, 0xF2, 0x16, 0x1F, 0x6C, 0xFE, 0x7E,
  38329. 0x68, 0x2A, 0xED, 0x96, 0x84, 0x95, 0x47, 0x05,
  38330. 0x1D, 0xDE, 0xB7, 0x7B, 0x90, 0xF6, 0xAF, 0x00,
  38331. 0x74, 0x7C, 0x47, 0xE0, 0x2E, 0x80, 0xB6, 0x9A,
  38332. 0x0D, 0x4B, 0x78, 0xA4, 0x7D, 0xDD, 0x81, 0xE2,
  38333. 0x99, 0x27, 0x1F, 0xA7, 0x8F, 0xE4, 0x23, 0xAD,
  38334. 0xDF, 0x12, 0x0D, 0xD0, 0x4D, 0x46, 0xC1, 0x32,
  38335. 0xE9, 0x70, 0xF4, 0xA0, 0x4E, 0x97, 0xA5, 0x88,
  38336. 0xD2, 0x7C, 0x7B, 0xA8, 0x43, 0x26, 0x18, 0x2A,
  38337. 0xAE, 0x04, 0xC2, 0x51, 0x28, 0x99, 0x71, 0x69,
  38338. 0x1D, 0x96, 0x78, 0xD4, 0x09, 0x88, 0x16, 0x88,
  38339. 0xF3, 0xBC, 0xCB, 0x95, 0x08, 0x30, 0xE6, 0x5B,
  38340. 0x78, 0x48, 0x41, 0x00, 0x4E, 0x40, 0x44, 0x58,
  38341. 0xE6, 0x16, 0x59, 0x63, 0xCF, 0xB4, 0xEE, 0xB5,
  38342. 0x05, 0xFD, 0xD1, 0x35, 0xF3, 0x1E, 0xD0, 0x14,
  38343. 0x7C, 0xC9, 0xE9, 0x87, 0x7F, 0xFF, 0x41, 0x07,
  38344. 0x68, 0x91, 0x06, 0x17, 0x4E, 0x76, 0x66, 0xEE,
  38345. 0xCB, 0x6C, 0xF2, 0xDA, 0x9C, 0x93, 0x51, 0xDC,
  38346. 0x43, 0x4A, 0x94, 0x49, 0x38, 0x4E, 0xED, 0x7F,
  38347. 0x5F, 0x90, 0x77, 0xB4, 0x2F, 0x0F, 0xC5, 0xD9,
  38348. 0xF0, 0xF5, 0xF7, 0x21, 0x91, 0x32, 0xFF, 0x9A,
  38349. 0x47, 0x09, 0x83, 0xE1, 0x9D, 0x30, 0xA4, 0xF3,
  38350. 0x7D, 0x18, 0x97, 0x44, 0xD8, 0x32, 0xFD, 0x5F,
  38351. 0xB3, 0x97, 0x49, 0x4E, 0x11, 0xAD, 0xF7, 0x4F,
  38352. 0x4E, 0x90, 0x0A, 0x41, 0x87, 0xCF, 0xF5, 0xDA,
  38353. 0x8F, 0x6D, 0x7B, 0x35, 0xAE, 0xA0, 0x16, 0xA8,
  38354. 0xDE, 0x88, 0x62, 0x26, 0x5F, 0x13, 0x69, 0xFB,
  38355. 0x36, 0x7E, 0xF1, 0x86, 0x0C, 0x8E, 0x07, 0xC3,
  38356. 0x3F, 0x32, 0x82, 0xB4, 0xD9, 0x83, 0x7C, 0xDF,
  38357. 0x3E, 0xF6, 0x58, 0x42, 0x2D, 0x34, 0xDE, 0xA4,
  38358. 0x1E, 0x56, 0xDD, 0x18, 0x70, 0x36, 0x81, 0xD0,
  38359. 0x44, 0xE3, 0xC4, 0x03, 0xAF, 0x33, 0xD1, 0xE7,
  38360. 0xAF, 0xA9, 0x6A, 0x8C, 0x44, 0x35, 0xFE, 0xBB,
  38361. 0xA0, 0xD2, 0x5D, 0xE0, 0xE4, 0xAE, 0xDF, 0xFB,
  38362. 0x82, 0xA0, 0xBA, 0xDE, 0x76, 0xB6, 0x6C, 0xA9,
  38363. 0xBE, 0xC7, 0xE9, 0xD7, 0x3F, 0x1C, 0xB2, 0x9C,
  38364. 0xD7, 0x3C, 0xF0, 0x0C, 0x2F, 0x60, 0x44, 0xD8,
  38365. 0x34, 0x53, 0xCE, 0xDD, 0xE0, 0x3F, 0x97, 0x2E,
  38366. 0xBB, 0x03, 0x20, 0x62, 0xD0, 0xA8, 0x23, 0x9F,
  38367. 0xB6, 0x99, 0xEC, 0x89, 0x0D, 0x32, 0x0F, 0x6F,
  38368. 0xAF, 0x3D, 0x20, 0x7B, 0xDC, 0x9A, 0xFE, 0xA2,
  38369. 0x02, 0x8B, 0x86, 0x99, 0x56, 0x23, 0x43, 0xAA,
  38370. 0x50, 0xF7, 0x0A, 0x4E, 0x8C, 0x62, 0xDA, 0xF8,
  38371. 0xB8, 0xCC, 0xA7, 0x2D, 0x02, 0x47, 0x63, 0xBA,
  38372. 0xEC, 0x25, 0x00, 0x23, 0xEA, 0xE8, 0x25, 0xC6,
  38373. 0x51, 0xAC, 0xC4, 0xAA, 0xA0, 0xDB, 0x6C, 0x5E,
  38374. 0xC7, 0xEF, 0xD0, 0x71, 0xED, 0xFB, 0x95, 0xAF,
  38375. 0x61, 0x0B, 0x64, 0x01, 0x61, 0x4F, 0x4F, 0xC6,
  38376. 0x36, 0x27, 0x75, 0xC3, 0x81, 0x0A, 0x9A, 0x21,
  38377. 0x69, 0xF8, 0x4A, 0x21, 0x12, 0x3B, 0x03, 0x1C,
  38378. 0xCE, 0x08, 0x7D, 0x52, 0x0E, 0x99, 0xE2, 0x62,
  38379. 0xE8, 0x81, 0x2E, 0x84, 0x09, 0x8E, 0xBE, 0x9B,
  38380. 0xCE, 0xD6, 0xE6, 0xA4, 0xF7, 0x3B, 0x67, 0x45,
  38381. 0x41, 0xDE, 0x0B, 0xCF, 0x5E, 0x7E, 0x31, 0x8F,
  38382. 0x90, 0x6D, 0x90, 0x1F, 0xEB, 0x1D, 0x9D, 0x1C,
  38383. 0xCB, 0x6C, 0xFF, 0xE8, 0x50, 0xDB, 0xFF, 0x75,
  38384. 0xC8, 0xA8, 0x9F, 0x43, 0xCB, 0x94, 0x89, 0x5F,
  38385. 0x28, 0x69, 0x6F, 0xAB, 0xB6, 0xAD, 0xCE, 0xE7,
  38386. 0x69, 0x7E, 0x60, 0x09, 0x03, 0x87, 0x43, 0x6E,
  38387. 0x19, 0xB1, 0x38, 0x81, 0x9B, 0x90, 0xAE, 0xB1,
  38388. 0x8A, 0xC2, 0x7D, 0x2C, 0x65, 0x9B, 0x0D, 0xF1,
  38389. 0x77, 0x94, 0xA7, 0x2F, 0x8B, 0xB7, 0xCE, 0x03,
  38390. 0xEE, 0x9A, 0x78, 0xFE, 0x8C, 0x8A, 0x37, 0x45,
  38391. 0xD5, 0x05, 0xDE, 0xD8, 0x85, 0x00, 0xF4, 0xCF,
  38392. 0x98, 0xFB, 0x62, 0x85, 0xB0, 0xBD, 0x82, 0xE2,
  38393. 0x7D, 0xED, 0x93, 0x3B, 0xCC, 0x18, 0x73, 0xF8,
  38394. 0x8A, 0xBD, 0x82, 0x8F, 0x60, 0x47, 0xAC, 0xEC,
  38395. 0x47, 0x2D, 0xEA, 0xE8, 0x7D, 0x8A, 0xDE, 0x0A,
  38396. 0xD0, 0x73, 0x48, 0xFF, 0xAF, 0x59, 0xC1, 0x70,
  38397. 0x29, 0xD8, 0x45, 0x38, 0x77, 0x7F, 0x73, 0xBF,
  38398. 0xED, 0x5C, 0x63, 0x63, 0x0B, 0xC4, 0x43, 0xE0,
  38399. 0xFA, 0x12, 0xDE, 0x72, 0x2D, 0xAB, 0xBB, 0xC2,
  38400. 0x25, 0x0A, 0xBA, 0x3F, 0xD8, 0x61, 0x54, 0xEE,
  38401. 0x20, 0x8D, 0x53, 0xA3, 0x27, 0xA7, 0xFF, 0x26,
  38402. 0xA0, 0x17, 0x93, 0x39, 0x4D, 0x04, 0x15, 0x8B,
  38403. 0xB3, 0x20, 0x60, 0x04, 0x47, 0xE2, 0xFD, 0x7D,
  38404. 0x7C, 0x6D, 0xE0, 0x76, 0xA5, 0x13, 0xD6, 0x81,
  38405. 0x95, 0xB0, 0x67, 0x20, 0x4F, 0xF6, 0x00, 0x5B,
  38406. 0x16, 0x25, 0x54, 0x2B, 0x28, 0x37, 0x2F, 0x06,
  38407. 0x80, 0x60, 0x53, 0xAE, 0xE2, 0xEA, 0x9F, 0x88,
  38408. 0xAE, 0xA2, 0x9A, 0x27, 0x02, 0x15, 0x4B, 0xF4,
  38409. 0x43, 0xBC, 0x70, 0x7D, 0x0A, 0x96, 0xEB, 0x06,
  38410. 0xCE, 0x43, 0xEF, 0xE6, 0x6A, 0xAC, 0x1F, 0x16,
  38411. 0x95, 0xE2, 0x8C, 0xF1, 0x07, 0x19, 0x3D, 0x06,
  38412. 0x2E, 0x71, 0xB6, 0x3A, 0xFD, 0xCF, 0x9E, 0x05,
  38413. 0x0B, 0xBE, 0xD7, 0x48, 0x4E, 0xC5, 0xE8, 0x0C,
  38414. 0x51, 0x5A, 0xC8, 0x20, 0xF0, 0xCD, 0xF9, 0x65,
  38415. 0xDD, 0x97, 0xF7, 0xA1, 0x1B, 0x57, 0xB2, 0x1A,
  38416. 0x04, 0xBF, 0x42, 0xF2, 0xA3, 0x3D, 0x61, 0x97,
  38417. 0x64, 0xDF, 0xB3, 0x63, 0x11, 0xFD, 0xAD, 0x8C,
  38418. 0x83, 0xA7, 0x48, 0xBA, 0x34, 0x42, 0xC5, 0x70,
  38419. 0x64, 0x5A, 0x78, 0x5E, 0x67, 0x03, 0xE5, 0xBF,
  38420. 0x22, 0xE8, 0x46, 0xFC, 0x51, 0x6C, 0xB4, 0x99,
  38421. 0x15, 0xFD, 0x63, 0xB6, 0x3E, 0x5D, 0xBF, 0x56,
  38422. 0xF5, 0x5E, 0xA4, 0x01, 0x16, 0xD5, 0x03, 0x4B,
  38423. 0xBB, 0x94, 0x5F, 0x58, 0xD6, 0x76, 0x95, 0xC7,
  38424. 0x96, 0xF1, 0xC1, 0xD0, 0x53, 0xA3, 0xEB, 0x28,
  38425. 0xA9, 0x5E, 0x8F, 0x38, 0x8E, 0x80, 0x04, 0xC3,
  38426. 0xB2, 0x4F, 0xD5, 0xFC, 0xCA, 0x7B, 0xB1, 0xE3,
  38427. 0xB9, 0x9A, 0x9F, 0x3C, 0x94, 0x5E, 0xF8, 0xA5,
  38428. 0x35, 0xF1, 0x37, 0x43, 0x20, 0x71, 0xA5, 0xCA,
  38429. 0x5B, 0x6F, 0x7D, 0xC7, 0xB8, 0xBC, 0xE5, 0x5A,
  38430. 0xD0, 0xF3, 0xB6, 0xCF, 0x1B, 0xCB, 0xB9, 0xCD,
  38431. 0x35, 0xE2, 0x41, 0xF8, 0x6E, 0x46, 0x97, 0x27,
  38432. 0x26, 0x48, 0xF4, 0x73, 0xDB, 0xD5, 0xB7, 0x68,
  38433. 0x1E, 0xF0, 0xC7, 0x84, 0x49, 0xE6, 0xC5, 0xFA,
  38434. 0x93, 0x0D, 0x83, 0x2C, 0x85, 0x1E, 0xED, 0x2A,
  38435. 0x65, 0x12, 0x19, 0xD7, 0xD9, 0xC3, 0xBB, 0x23,
  38436. 0xF3, 0xC6, 0xAD, 0x7E, 0xB7, 0x78, 0x68, 0x54,
  38437. 0x1F, 0x3C, 0xEE, 0x09, 0xF5, 0x1E, 0xE0, 0x4E,
  38438. 0xBA, 0x1B, 0xBC, 0x29, 0x69, 0x8A, 0xED, 0xD3,
  38439. 0xC7, 0xAC, 0xEC, 0x44, 0x29, 0xD7, 0xA4, 0x0C,
  38440. 0xFA, 0xBD, 0xA2, 0x29, 0x34, 0x80, 0x16, 0x4F,
  38441. 0x37, 0xEC, 0xB6, 0x73, 0xF2, 0xB5, 0xD7, 0x51,
  38442. 0x57, 0x43, 0xAF, 0x7E, 0xD0, 0xB6, 0xE0, 0x96,
  38443. 0xF0, 0xE2, 0xFE, 0xCE, 0xC8, 0x9F, 0x40, 0xD6,
  38444. 0xAF, 0xE0, 0xBF, 0xCD, 0x70, 0x37, 0x91, 0x69,
  38445. 0x99, 0x8C, 0xDF, 0x4A, 0x20, 0xDE, 0xB6, 0xC6,
  38446. 0x7A, 0xB4, 0xE3, 0x6A, 0xAD, 0x53, 0xED, 0xB9,
  38447. 0x8A, 0x13, 0x61, 0xC5, 0xE9, 0xB0, 0xDC, 0x16,
  38448. 0x36, 0xD7, 0x51, 0xA8, 0x7B, 0x52, 0x05, 0x3B,
  38449. 0xAD, 0x5C, 0xD2, 0xBD, 0x6F, 0x6B, 0xA9, 0x51,
  38450. 0xA7, 0xE8, 0x7E, 0xA4, 0xB6, 0x77, 0xAE, 0x00,
  38451. 0x89, 0x3A, 0x1F, 0x76, 0x72, 0x3F, 0xC5, 0x6C,
  38452. 0x49, 0x4F, 0xB5, 0xCA, 0x2F, 0x5D, 0xAE, 0xF8,
  38453. 0x58, 0x9A, 0xE2, 0x5B, 0x54, 0x76, 0xF4, 0xAA,
  38454. 0x89, 0xD4, 0x04, 0xAF, 0x1C, 0x26, 0x65, 0xEC,
  38455. 0xA1, 0x81, 0x06, 0x2A, 0x4B, 0x5E, 0xD5, 0x90,
  38456. 0xB8, 0x26, 0x33, 0x64, 0x15, 0x33, 0x25, 0xAC,
  38457. 0x97, 0x9A, 0xCA, 0x1B, 0x64, 0x50, 0x82, 0x8F,
  38458. 0x65, 0x6A, 0xD4, 0x47, 0xCF, 0x7E, 0x93, 0x7D,
  38459. 0xB3, 0xCB, 0xFE, 0x55, 0x0A, 0x46, 0x93, 0x22,
  38460. 0xB5, 0x46, 0xAB, 0xD6, 0x05, 0x59, 0x14, 0x5E,
  38461. 0x1B, 0xD4, 0x2D, 0xAF, 0xA3, 0x18, 0xB7, 0xA0,
  38462. 0xD7, 0x11, 0x70, 0xDE, 0x81, 0x8B, 0xD6, 0x64,
  38463. 0xFD, 0x38, 0xBD, 0x29, 0x92, 0x41, 0x80, 0xC4,
  38464. 0x4A, 0x6D, 0x34, 0x1B, 0xF0, 0x59, 0xA0, 0xD6,
  38465. 0x48, 0x55, 0xD2, 0xA5, 0xE2, 0x91, 0xB6, 0x71,
  38466. 0xF4, 0x90, 0x97, 0x8B, 0x0A, 0xDD, 0x90, 0xEA,
  38467. 0x61, 0x9B, 0x30, 0xA6, 0x2F, 0x5D, 0xB4, 0xEE,
  38468. 0x7A, 0x10, 0x40, 0x59, 0x89, 0xAC, 0x30, 0x6E,
  38469. 0x9C, 0x7B, 0xBC, 0x11, 0x75, 0x38, 0x00, 0x2E,
  38470. 0xDF, 0xED, 0x87, 0x47, 0x30, 0xFB, 0xD4, 0x8A,
  38471. 0xC6, 0xBE, 0xC7, 0x20, 0xC8, 0x3D, 0x51, 0x05,
  38472. 0x67, 0x48, 0xDE, 0xE2, 0xBF, 0x95, 0x5E, 0x7B,
  38473. 0xD7, 0xC7, 0x86, 0xDF, 0x68, 0x57, 0xA9, 0x29,
  38474. 0xBC, 0xF8, 0xE3, 0x81, 0x62, 0x1B, 0x37, 0x58,
  38475. 0xF2, 0xFF, 0xEE, 0xE8, 0x28, 0x08, 0x36, 0x23,
  38476. 0x5B, 0x24, 0x68, 0x1E, 0x62, 0xBD, 0x27, 0xC2,
  38477. 0x6F, 0xE9, 0x63, 0x67, 0x53, 0xC7, 0x8A, 0xB5,
  38478. 0xA7, 0xEF, 0x29, 0xFE, 0x60, 0xAC, 0x29, 0xCF,
  38479. 0x67, 0x40, 0x9F, 0xE6, 0x57, 0xCE, 0x65, 0x3A,
  38480. 0x2F, 0xDA, 0xA7, 0xF2, 0x0C, 0x50, 0x19, 0xE6,
  38481. 0xF7, 0x43, 0x2E, 0x8C, 0xEB, 0x9E, 0x99, 0x92,
  38482. 0xE6, 0x46, 0xB7, 0x8D, 0x43, 0x65, 0xFD, 0x02,
  38483. 0x17, 0x74, 0x6F, 0x7B, 0xA3, 0x1E, 0x06, 0x9D,
  38484. 0x75, 0x4E, 0x05, 0xED, 0x5A, 0x71, 0xFC, 0x5E,
  38485. 0x7D, 0x6D, 0x64, 0x5E, 0xAF, 0x41, 0x44, 0xD6,
  38486. 0xBC, 0x43, 0x05, 0x5E, 0x6C, 0xDB, 0x89, 0x34,
  38487. 0xC7, 0x02, 0x64, 0x08, 0xAE, 0x96, 0x53, 0x5B,
  38488. 0xA2, 0xDE, 0xCD, 0x2F, 0x74, 0x56, 0xD6, 0xEC,
  38489. 0xA4, 0x23, 0x68, 0xCD, 0x9A, 0xC5, 0x05, 0x7B,
  38490. 0x7D, 0x1E, 0x12, 0xF7, 0x7A, 0xA8, 0x7C, 0x43,
  38491. 0x7E, 0x7A, 0x43, 0x31, 0x5D, 0xA0, 0x81, 0xE5,
  38492. 0x3A, 0xFE, 0x23, 0xB5, 0xBC, 0xC2, 0xF4, 0xCE,
  38493. 0x3A, 0x80, 0x06, 0xE8, 0x1E, 0x08, 0xAF, 0x0A,
  38494. 0x33, 0xC1, 0xA9, 0x30, 0x7C, 0x8D, 0x5A, 0xC5,
  38495. 0x93, 0x89, 0xF2, 0x69, 0x24, 0x11, 0x6C, 0xAB,
  38496. 0x0B, 0x87, 0xD5, 0x49, 0xD0, 0x38, 0x3C, 0x27,
  38497. 0x4E, 0x8E, 0x85, 0xD4, 0x6E, 0x0F, 0xCD, 0x70,
  38498. 0xE3, 0x68, 0x42, 0xCA, 0x4C, 0x8D, 0x6D, 0x0F,
  38499. 0x48, 0xF3, 0xED, 0xF9, 0xE9, 0x43, 0x5D, 0xBF,
  38500. 0x55, 0x75, 0xF8, 0xEB, 0x78, 0x93, 0x72, 0x75,
  38501. 0x8B, 0xF5, 0xBD, 0xE9, 0x9D, 0xA2, 0xB9, 0x81,
  38502. 0x83, 0xDB, 0xAC, 0x82, 0xD1, 0xC1, 0x20, 0x03,
  38503. 0x72, 0x4D, 0xDC, 0x42, 0xAE, 0xC8, 0x1C, 0x0C,
  38504. 0x78, 0x22, 0x77, 0x27, 0x91, 0x50, 0x4C, 0x90,
  38505. 0xEA, 0x13, 0x8B, 0x6C, 0x91, 0xDF, 0x5D, 0x25,
  38506. 0x36, 0x9C, 0xC2, 0x06, 0x4F, 0xD5, 0xE2, 0xCC,
  38507. 0x9D, 0x89, 0x3B, 0xC4, 0x23, 0x5D, 0x88, 0x17,
  38508. 0x62, 0x4E, 0xC9, 0xFA, 0xC8, 0xEF, 0x1D, 0x45,
  38509. 0xE1, 0xFB, 0x58, 0xB3, 0x8E, 0xBD, 0x8D, 0xAE,
  38510. 0x12, 0xFF, 0xA0, 0x37, 0xE0, 0x7F, 0x5B, 0x41,
  38511. 0x1D, 0x40, 0x17, 0xAF, 0x95, 0x2D, 0x8C, 0x42,
  38512. 0xC6, 0x1A, 0x2A, 0x1E, 0x8E, 0x70, 0x25, 0xD6,
  38513. 0xD3, 0xA2, 0x85, 0xAA, 0x17, 0xFF, 0x0D, 0xB4,
  38514. 0x39, 0xD0, 0xF2, 0xAF, 0xA0, 0x4F, 0x31, 0x8D,
  38515. 0x6D, 0x57, 0x6A, 0xED, 0xC6, 0xF1, 0xE7, 0x67,
  38516. 0xA6, 0x6F, 0xB3, 0x9B, 0x72, 0xC6, 0x7F, 0x05,
  38517. 0xAF, 0x40, 0x87, 0x12, 0x0D, 0xC8, 0x98, 0x88,
  38518. 0x2D, 0xDE, 0xA1, 0x7C, 0x95, 0x32, 0xB2, 0x7A,
  38519. 0xB5, 0x9D, 0xE4, 0x0D, 0x75, 0xD4, 0x17, 0x5B,
  38520. 0xB4, 0x92, 0x73, 0xAF, 0x87, 0x3A, 0x92, 0xDA,
  38521. 0x4D, 0x87, 0xE2, 0x53, 0xCA, 0xE7, 0x2A, 0x52,
  38522. 0x64, 0xE0, 0xC1, 0xDE, 0x4C, 0x9C, 0xF9, 0x1A,
  38523. 0x1F, 0x3A, 0xD6, 0x05, 0xA0, 0xCC, 0x8D, 0x91,
  38524. 0x93, 0x51, 0xF9, 0x37, 0x1A, 0xFC, 0x68, 0xEF,
  38525. 0xBC, 0xED, 0x19, 0x8E, 0x4C, 0xD1, 0xB5, 0x8C,
  38526. 0xA2, 0x85, 0xDA, 0x02, 0x65, 0xAB, 0xAC, 0xAE,
  38527. 0xCA, 0x8E, 0xAC, 0xF0, 0x2A, 0x4F, 0xC7, 0x67,
  38528. 0x16, 0x2E, 0x24, 0x7F, 0x73, 0xCD, 0xD7, 0x3E,
  38529. 0xE3, 0x27, 0x8A, 0xF9, 0x4A, 0xC4, 0xA8, 0xCB,
  38530. 0x2B, 0x01, 0x55, 0x68, 0x34, 0xA3, 0xC0, 0xB8,
  38531. 0xD0, 0x6D, 0x05, 0xF2, 0x3B, 0x4C, 0x17, 0x47,
  38532. 0xE7, 0x64, 0x53, 0xF4, 0x9D, 0xE0, 0x8D, 0xF8,
  38533. 0xEE, 0x0E, 0xA6, 0x25, 0x64, 0x7D, 0x1B, 0xD0,
  38534. 0x80, 0xE7, 0x3C, 0x41, 0x97, 0xAE, 0xCB, 0x6A,
  38535. 0x23, 0xC2, 0x5F, 0x00, 0xC6, 0xC5, 0x4C, 0x8A,
  38536. 0x4C, 0xEF, 0x76, 0x65, 0x95, 0x28, 0xB3, 0x67,
  38537. 0x42, 0xEC, 0x17, 0xFF, 0x0E, 0xE3, 0x7B, 0x30,
  38538. 0x6D, 0xCC, 0xB8, 0x87, 0xD6, 0x63, 0x36, 0x5D,
  38539. 0xC9, 0xE8, 0x1D, 0x51, 0x47, 0xCF, 0xE5, 0x05,
  38540. 0x0D, 0xB4, 0x09, 0xDF, 0xAD, 0x88, 0x9C, 0x38,
  38541. 0x6F, 0x12, 0xA5, 0xCD, 0x0C, 0x95, 0x53, 0x41,
  38542. 0x13, 0xA6, 0xD0, 0xAB, 0xCB, 0x5A, 0x3F, 0x56,
  38543. 0xCE, 0x23, 0xEE, 0x32, 0x61, 0x22, 0x79, 0xE8,
  38544. 0xBA, 0x23, 0x94, 0x61, 0x25, 0x8E, 0xD6, 0x3E,
  38545. 0x78, 0x83, 0xE1, 0x15, 0xBA, 0x05, 0x81, 0xB8,
  38546. 0x1A, 0x7F, 0x73, 0xC1, 0xB7, 0x9F, 0x29, 0xA1,
  38547. 0x16, 0x2E, 0x6E, 0x84, 0xC7, 0x15, 0xBC, 0x50,
  38548. 0x28, 0x5F, 0xD3, 0x8D, 0x4D, 0x6D, 0xC0, 0x87,
  38549. 0x68, 0x88, 0x4B, 0xF4, 0xFB, 0x55, 0x85, 0x3D,
  38550. 0xA7, 0xB5, 0x47, 0x1E, 0x73, 0xA1, 0x47, 0x8D,
  38551. 0xB1, 0xE1, 0xCF, 0xE6, 0x15, 0x3E, 0xC6, 0xC3,
  38552. 0x78, 0xDD, 0x6A, 0x3F, 0x42, 0x29, 0x6E, 0x61,
  38553. 0x9D, 0xE7, 0x63, 0xFF, 0x2D, 0xDB, 0x83, 0xE5,
  38554. 0x15, 0x84, 0xC2, 0x8D, 0xD8, 0x34, 0x2E, 0x92,
  38555. 0x9E, 0x15, 0xB7, 0xBB, 0xCF, 0x5D, 0x6E, 0xCB,
  38556. 0x87, 0x79, 0xCF, 0x7F, 0x3A, 0x9A, 0xC1, 0x6A,
  38557. 0x43, 0x1F, 0x52, 0xA2, 0x34, 0xE6, 0xA3, 0x69,
  38558. 0x9D, 0x9E, 0x44, 0x84, 0x0A, 0x4D, 0x3D, 0x48,
  38559. 0x5D, 0xA5, 0xD9, 0x03, 0x94, 0xB1, 0x81, 0xEF,
  38560. 0x89, 0x98, 0xE6, 0xD1, 0x44, 0x21, 0x83, 0x59,
  38561. 0x09, 0xCD, 0xDB, 0x16, 0x7C, 0x8C, 0x38, 0x78,
  38562. 0x19, 0x4B, 0x6D, 0x51, 0x4D, 0xF8, 0x63, 0x6D,
  38563. 0x4A, 0x14, 0xA1, 0xBE, 0xF3, 0xCA, 0x38, 0x1E,
  38564. 0x36, 0xCF, 0x2E, 0x6D, 0x5F, 0xBC, 0xB4, 0x0A,
  38565. 0xF0, 0x91, 0x7D, 0x6D, 0xBB, 0x87, 0x5C, 0xFF,
  38566. 0x64, 0xCD, 0xCE, 0xCC, 0xCF, 0xB8, 0xBF, 0xB8,
  38567. 0x05, 0x45, 0x8D, 0xF8, 0x2C, 0x74, 0xEB, 0x86,
  38568. 0x3A, 0x96, 0x9E, 0xD9, 0x8B, 0x9C, 0x46, 0xE7,
  38569. 0x17, 0x3C, 0x09, 0x0D, 0xB0, 0x68, 0xB2, 0xD8,
  38570. 0x0C, 0xCE, 0x32, 0xDE, 0x51, 0x72, 0xB5, 0xD4,
  38571. 0xA8, 0xB9, 0x09, 0xA5, 0xA4, 0xCC, 0x47, 0xFA,
  38572. 0x9F, 0x2E, 0xD6, 0x6E, 0x60, 0x69, 0xCD, 0x96,
  38573. 0xAB, 0x1F, 0x3E, 0x84, 0x8C, 0x68, 0x72, 0x0F,
  38574. 0xEA, 0x32, 0xC5, 0x73, 0x6E, 0x8A, 0xB5, 0x10,
  38575. 0x05, 0xFE, 0x42, 0x58, 0x33, 0xF2, 0x07, 0x56,
  38576. 0xC1, 0x96, 0x76, 0x23, 0x77, 0x9D, 0x0A, 0xD2,
  38577. 0x42, 0xA1, 0x69, 0x06, 0x83, 0xBA, 0xD2, 0xEB,
  38578. 0x12, 0x3D, 0x97, 0xAB, 0x23, 0x08, 0x90, 0x15,
  38579. 0x51, 0x4D, 0x0C, 0x6A, 0x3B, 0x0F, 0x37, 0x15,
  38580. 0x25, 0xC2, 0x3E, 0x5F, 0x53, 0x84, 0x4C, 0x81,
  38581. 0xDD, 0xE8, 0x7C, 0xFE, 0x9F, 0x06, 0x5E, 0x11,
  38582. 0x68, 0x7D, 0x68, 0x6B, 0x07, 0x2C, 0x19, 0x00,
  38583. 0xF5, 0xC9, 0xA7, 0xC3, 0x1F, 0xE8, 0xBA, 0xBE,
  38584. 0x9F, 0x09, 0x0C, 0xE2, 0xCB, 0x3B, 0x68, 0x7B,
  38585. 0xA8, 0x9E, 0xD8, 0x3C, 0x08, 0x85, 0xDF, 0xF9,
  38586. 0x11, 0x2B, 0x52, 0xF6, 0xCE, 0xD7, 0x1E, 0x32,
  38587. 0xA4, 0x0A, 0x9A, 0xBC, 0xFF, 0xF4, 0x20, 0xB6,
  38588. 0x24, 0x85, 0x84, 0x7F, 0xFF, 0x70, 0x3C, 0xBB,
  38589. 0x74, 0x36, 0x42, 0x25, 0x5F, 0xBD, 0x0A, 0x90,
  38590. 0x86, 0xA7, 0xB8, 0x3F, 0x9E, 0xDF, 0x43, 0x24,
  38591. 0x88, 0x0C, 0x52, 0x08, 0xF7, 0xDC, 0xB1, 0xEA,
  38592. 0xC3, 0x38, 0xF9, 0x13, 0x16, 0x65, 0xA0, 0xCA,
  38593. 0x6B, 0xF0, 0xD6, 0x12, 0xFB, 0xA6, 0x3F, 0xF7,
  38594. 0x13, 0x91, 0x99, 0xB1, 0xDE, 0xE4, 0xEE, 0x1E,
  38595. 0x98, 0x9B, 0xE4, 0xA0, 0x3A, 0xA8, 0xAC, 0x4A,
  38596. 0x48, 0x3E, 0xCB, 0x9E, 0xB4, 0x1D, 0x22, 0x1F,
  38597. 0x59, 0x97, 0x24, 0x8C, 0xFE, 0xDC, 0xBF, 0x6C,
  38598. 0xAD, 0x8D, 0xB0, 0xA3, 0x27, 0xFA, 0x28, 0x8F,
  38599. 0xD6, 0xAE, 0x31, 0x39, 0x84, 0xFA, 0x61, 0x8F,
  38600. 0x7D, 0xD4, 0xEE, 0xBB, 0x13, 0xED, 0x85, 0xC4,
  38601. 0x35, 0xC0, 0xAB, 0x07, 0x73, 0xC5, 0xCD, 0xCA,
  38602. 0xD4, 0x69, 0x9B, 0x9C, 0x38, 0x2A, 0x1F, 0x37,
  38603. 0xF9, 0xDF, 0x8C, 0x3A, 0xE1, 0x57, 0xDF, 0x05,
  38604. 0x9F, 0x97, 0x51, 0xCC, 0xA6, 0x93, 0xD5, 0x49,
  38605. 0x2A, 0xE9, 0xCD, 0x46, 0x31, 0x22, 0x6E, 0x62,
  38606. 0xE8, 0x13, 0x90, 0x64, 0xFF, 0x00, 0x27, 0xCF,
  38607. 0xA1, 0x95, 0x4E, 0xE9, 0x36, 0xAF, 0xAD, 0x02,
  38608. 0x06, 0xDD, 0x2A, 0xE2, 0x28, 0xB6, 0xDD, 0x65,
  38609. 0xCD, 0x9A, 0x9D, 0x5F, 0xF9, 0xC0, 0xCC, 0x48,
  38610. 0xC8, 0xC2, 0xE9, 0x8F, 0x5A, 0xE6, 0xE2, 0xC9,
  38611. 0x79, 0x7A, 0x83, 0x84, 0xF8, 0xA3, 0xE3, 0xC7,
  38612. 0x48, 0xC7, 0x06, 0xFE, 0x6A, 0x36, 0x25, 0xD2,
  38613. 0xA2, 0xEB, 0x4A, 0xE2, 0xCA, 0xA0, 0x49, 0x24,
  38614. 0x1A, 0x47, 0x8C, 0x1A, 0x77, 0xF5, 0xC9, 0x0D,
  38615. 0xDC, 0x94, 0x18, 0x4D, 0x89, 0x80, 0x50, 0x18,
  38616. 0x7D, 0x67, 0x00, 0x43, 0xE4, 0xE7, 0x8F, 0x54,
  38617. 0xDC, 0x60, 0x84, 0x24, 0xF3, 0xBF, 0x5E, 0x92,
  38618. 0xC7, 0x0C, 0x05, 0x49, 0xBB, 0x61, 0x2F, 0x48,
  38619. 0x0A, 0xEB, 0xE5, 0xFA, 0x8B, 0x01, 0x33, 0x27,
  38620. 0x10, 0x3E, 0xA1, 0x28, 0x33, 0x11, 0x30, 0x1F,
  38621. 0x91, 0x47, 0x7B, 0xA6, 0x3E, 0xD4, 0xF9, 0xC2,
  38622. 0x8F, 0xA3, 0x4E, 0xBC, 0xA7, 0x61, 0x56, 0x1F,
  38623. 0x90, 0x33, 0x54, 0x15, 0x06, 0x21, 0x9C, 0x57,
  38624. 0x07, 0xC2, 0xF8, 0xED, 0x81, 0xED, 0x36, 0x15,
  38625. 0xC8, 0xAC, 0xAB, 0x12, 0x80, 0xBF, 0x7C, 0x5E,
  38626. 0x00, 0xEC, 0x1B, 0x27, 0x58, 0x3A, 0xE9, 0x09,
  38627. 0x2B, 0x23, 0x16, 0x69, 0x26, 0xF9, 0xCC, 0x3C,
  38628. 0x5A, 0xFB, 0x66, 0xBA, 0x32, 0xF9, 0xAF, 0xAB,
  38629. 0xCB, 0xA7, 0xF7, 0x91, 0x6A, 0x82, 0x42, 0xA7,
  38630. 0x9D, 0x7B, 0x0E, 0xD3, 0x5D, 0xF6, 0x52, 0x6D,
  38631. 0x7D, 0x2B, 0xE6, 0x30, 0x99, 0x01, 0xBD, 0xC0,
  38632. 0x3D, 0x15, 0x95, 0xC2, 0x67, 0x19, 0xD9, 0x0F,
  38633. 0xC0, 0x79, 0x1E, 0xAB, 0xA7, 0x67, 0x35, 0x12,
  38634. 0x53, 0xB0, 0x6A, 0xE4, 0xB9, 0x0A, 0x52, 0xEF,
  38635. 0xBD, 0xCD, 0xD4, 0x0C, 0x09, 0x6F, 0x24, 0xE9,
  38636. 0x52, 0x9F, 0xF8, 0x9F, 0x95, 0x95, 0x57, 0x07,
  38637. 0x5F, 0xC8, 0xDD, 0xAF, 0xE6, 0x10, 0x3A, 0x51,
  38638. 0x38, 0xF0, 0x9F, 0xBD, 0xEB, 0x0F, 0x5F, 0x36,
  38639. 0xB5, 0x2A, 0x57, 0xBE, 0x21, 0x39, 0xD8, 0x9D,
  38640. 0x29, 0x04, 0xBC, 0xE2, 0xB8, 0x6D, 0x03, 0xF2,
  38641. 0x6D, 0x56, 0xF4, 0x18, 0x40, 0x07, 0x1A, 0x15,
  38642. 0x8B, 0xF5, 0x46, 0xE1, 0x0C, 0x4D, 0xED, 0x0E,
  38643. 0x81, 0xB0, 0x0D, 0x98, 0x88, 0xC5, 0x5D, 0x53,
  38644. 0xE1, 0x1D, 0xB7, 0x00, 0x26, 0xC6, 0x46, 0x7E,
  38645. 0xD2, 0xAB, 0x0B, 0xD9, 0x1E, 0xE0, 0xE7, 0xC3,
  38646. 0xC3, 0xE0, 0x83, 0x7F, 0x8C, 0xB9, 0xBA, 0xE0,
  38647. 0x04, 0xE2, 0xA8, 0xFF, 0xEC, 0xD5, 0x9E, 0x79,
  38648. 0x2F, 0x13, 0xF9, 0x27, 0xCA, 0xDD, 0xF5, 0x0F,
  38649. 0x74, 0xD2, 0x9B, 0xC6, 0x2E, 0xF2, 0xF0, 0x2A,
  38650. 0xB0, 0xF9, 0x6E, 0x27, 0x3E, 0x8D, 0x66, 0xDB,
  38651. 0x44, 0x82, 0xDD, 0x1B, 0xD5, 0xBB, 0x51, 0x6E,
  38652. 0x72, 0x3A, 0xCB, 0x0F, 0x0B, 0x97, 0xBC, 0x32,
  38653. 0x07, 0xC1, 0x0C, 0xF3, 0x94, 0xFF, 0x62, 0xE2,
  38654. 0xFD, 0x7D, 0xBB, 0x3D, 0x43, 0x11, 0xB3, 0xFA,
  38655. 0x22, 0x05, 0xBF, 0x87, 0x0F, 0xFD, 0xD1, 0x81,
  38656. 0xC6, 0x30, 0xC6, 0x91, 0xD4, 0xEE, 0xA8, 0x6B,
  38657. 0x37, 0xB2, 0x38, 0xF1, 0x87, 0x89, 0xE0, 0x04,
  38658. 0x09, 0xED, 0x18, 0xA6, 0x3C, 0x18, 0x9E, 0x38,
  38659. 0xCB, 0x9F, 0xFE, 0xB3, 0x03, 0xF4, 0xE4, 0x3F,
  38660. 0xB3, 0x94, 0x7C, 0x74, 0x03, 0x6C, 0xCF, 0x16,
  38661. 0x24, 0xF8, 0x56, 0xE2, 0x4A, 0x7E, 0x9A, 0x21,
  38662. 0xB8, 0xC2, 0x7C, 0xF4, 0x3D, 0x85, 0x15, 0x43,
  38663. 0xA5, 0xCA, 0xFD, 0xA3, 0x05, 0xCC, 0x63, 0x8D,
  38664. 0x94, 0x82, 0x70
  38665. };
  38666. static const byte rnd_87[] = {
  38667. 0x16, 0xB8, 0x2B, 0x9B, 0x0A, 0x90, 0x5B, 0xB3,
  38668. 0xD8, 0x7B, 0x4A, 0x1E, 0x40, 0xAE, 0xAD, 0x3C,
  38669. 0xDE, 0x63, 0xB2, 0x2C, 0xB7, 0x16, 0xBD, 0x46,
  38670. 0x7A, 0x7B, 0xE8, 0x4A, 0xF1, 0x9B, 0x7C, 0xFE
  38671. };
  38672. static const byte sig_87[] = {
  38673. 0xE5, 0x5D, 0x62, 0x56, 0x92, 0x73, 0x72, 0x13,
  38674. 0xDD, 0x3D, 0x7F, 0x51, 0x42, 0xF3, 0xAA, 0x33,
  38675. 0x87, 0x12, 0x2F, 0x20, 0xC9, 0x50, 0x93, 0x0A,
  38676. 0x7E, 0x7C, 0xCC, 0x0C, 0x6D, 0x21, 0xB9, 0x5D,
  38677. 0x62, 0x47, 0xD5, 0xFB, 0x3A, 0xCC, 0xBC, 0xB8,
  38678. 0xA1, 0x5A, 0xDF, 0x97, 0x58, 0xBA, 0x7E, 0x40,
  38679. 0x9A, 0x76, 0xD0, 0x1C, 0xBF, 0x0F, 0x14, 0xC3,
  38680. 0x23, 0x3B, 0x21, 0xB0, 0x5D, 0x11, 0x3B, 0x1F,
  38681. 0x70, 0xCB, 0x21, 0x78, 0x51, 0x68, 0xE2, 0x3A,
  38682. 0x29, 0x4A, 0x0D, 0xD0, 0x32, 0x50, 0xDC, 0xBB,
  38683. 0xD1, 0xCF, 0x80, 0x19, 0x7A, 0xC7, 0xFC, 0x37,
  38684. 0x2D, 0x5A, 0x5A, 0xDF, 0x3E, 0x7E, 0x89, 0x2D,
  38685. 0xC6, 0x0E, 0x75, 0x9A, 0xBB, 0xDF, 0x69, 0x82,
  38686. 0x28, 0xB6, 0xD0, 0xF3, 0xF4, 0xCB, 0x4F, 0xD5,
  38687. 0xDC, 0x5D, 0xFE, 0x8D, 0x01, 0xB4, 0x93, 0x9F,
  38688. 0x89, 0x53, 0x18, 0x74, 0x29, 0x20, 0x36, 0xBF,
  38689. 0x34, 0xCA, 0x71, 0x2B, 0x01, 0x14, 0xFB, 0x66,
  38690. 0x94, 0x28, 0x81, 0xF1, 0xF1, 0x7E, 0x80, 0xB6,
  38691. 0x4E, 0x0E, 0x9E, 0x9E, 0x60, 0xD7, 0x6A, 0xFB,
  38692. 0x59, 0xC7, 0x96, 0x9F, 0xB4, 0x9C, 0x98, 0x72,
  38693. 0x06, 0xC1, 0x6C, 0xAA, 0x8E, 0xC7, 0x48, 0xE6,
  38694. 0xC3, 0xAD, 0x8B, 0x4E, 0xF7, 0x81, 0x92, 0x74,
  38695. 0xC0, 0x5A, 0x2B, 0x54, 0x8D, 0x47, 0x15, 0xAC,
  38696. 0xED, 0x45, 0x69, 0xD0, 0x7C, 0x28, 0x80, 0x18,
  38697. 0xA3, 0x9F, 0xB7, 0x14, 0xC6, 0x51, 0xF9, 0x02,
  38698. 0x70, 0x98, 0xD9, 0xC1, 0x09, 0xC0, 0xD7, 0xCE,
  38699. 0x8B, 0x81, 0x7B, 0x30, 0x99, 0x4C, 0x85, 0x1C,
  38700. 0xFA, 0xAE, 0xBF, 0x05, 0x95, 0xBB, 0x6E, 0x01,
  38701. 0xE4, 0xFC, 0xE7, 0x11, 0x16, 0x90, 0x28, 0xC3,
  38702. 0xC4, 0x36, 0x9F, 0x11, 0xCD, 0xEB, 0xEB, 0x71,
  38703. 0x15, 0x08, 0x1D, 0x43, 0x2B, 0x12, 0xA6, 0x4E,
  38704. 0xB6, 0xF9, 0x35, 0xE4, 0x37, 0x0D, 0xF7, 0x49,
  38705. 0xDF, 0x73, 0x4D, 0xE3, 0x57, 0x33, 0x96, 0x7B,
  38706. 0x72, 0x45, 0x2F, 0x92, 0x70, 0xBB, 0x6F, 0xCD,
  38707. 0x90, 0x82, 0x67, 0xBB, 0x31, 0x9D, 0x9E, 0x38,
  38708. 0x75, 0xCD, 0x5B, 0x55, 0x10, 0x6B, 0xFC, 0x00,
  38709. 0x15, 0xC8, 0xCB, 0xFC, 0xE1, 0x18, 0x41, 0xE8,
  38710. 0x6E, 0x92, 0xEC, 0x1A, 0x26, 0x88, 0x6C, 0xF6,
  38711. 0x2A, 0x5C, 0x05, 0x94, 0xD7, 0xB8, 0xD0, 0x78,
  38712. 0x52, 0x68, 0x8D, 0xC5, 0xBD, 0xD6, 0x29, 0xF8,
  38713. 0x21, 0xDF, 0xB3, 0x28, 0x43, 0x74, 0xC7, 0x0E,
  38714. 0x99, 0xD3, 0x0C, 0xDE, 0xE9, 0x06, 0x44, 0xCD,
  38715. 0x77, 0x13, 0x34, 0x82, 0xBA, 0x36, 0x20, 0x71,
  38716. 0x02, 0xB1, 0x6E, 0xBA, 0xCF, 0x9F, 0x15, 0x36,
  38717. 0xC8, 0xF1, 0x4E, 0x36, 0x30, 0x34, 0x2D, 0x23,
  38718. 0x6C, 0x77, 0xEC, 0xCA, 0xBA, 0x7C, 0x17, 0x4F,
  38719. 0x3F, 0x22, 0x4A, 0x34, 0xA1, 0x5C, 0xB3, 0x8F,
  38720. 0xD8, 0x48, 0xD5, 0x8A, 0x2C, 0x8B, 0x1B, 0xFB,
  38721. 0x87, 0xDA, 0xBC, 0xB6, 0xD9, 0x59, 0xD6, 0x9B,
  38722. 0xF0, 0x6E, 0x8D, 0xB1, 0x52, 0xE1, 0x8A, 0x36,
  38723. 0x31, 0xA7, 0x83, 0xCE, 0xDF, 0x36, 0xEB, 0xBE,
  38724. 0xEA, 0xC3, 0xC6, 0xA6, 0x52, 0x2D, 0x89, 0x0B,
  38725. 0xF9, 0x5B, 0x1D, 0x14, 0xA9, 0xBF, 0x37, 0x31,
  38726. 0xE0, 0x1C, 0xF5, 0x29, 0x95, 0xF0, 0xC0, 0x08,
  38727. 0xE8, 0x97, 0xEE, 0x53, 0x27, 0x85, 0x81, 0x7D,
  38728. 0x47, 0xE5, 0xAC, 0xC5, 0x1B, 0x48, 0xA5, 0x36,
  38729. 0x1E, 0x8A, 0xD7, 0xF5, 0xC9, 0x93, 0x74, 0xCE,
  38730. 0x06, 0xEA, 0xC3, 0x26, 0x45, 0xFF, 0xED, 0x39,
  38731. 0xC1, 0x0B, 0x7A, 0x59, 0x3C, 0x0F, 0xEE, 0x89,
  38732. 0xEF, 0xA4, 0xEC, 0xD0, 0x72, 0x34, 0x95, 0xC9,
  38733. 0xC4, 0x78, 0x47, 0xB6, 0xB7, 0xCE, 0xA4, 0xD9,
  38734. 0xA1, 0xB6, 0x37, 0xC1, 0xF1, 0xFB, 0x4E, 0x4C,
  38735. 0x38, 0xB0, 0x4A, 0xE5, 0x13, 0x63, 0xDC, 0x44,
  38736. 0xC4, 0x7E, 0x86, 0x9C, 0xAD, 0x69, 0x29, 0xFD,
  38737. 0xA1, 0xFE, 0xAD, 0x3B, 0x59, 0x24, 0x2F, 0x70,
  38738. 0xAE, 0x5F, 0x2C, 0x00, 0xFE, 0x01, 0x09, 0xA3,
  38739. 0x10, 0x87, 0xF0, 0xAD, 0xFA, 0x9B, 0x83, 0x8F,
  38740. 0x48, 0x96, 0x8B, 0x9A, 0x35, 0xE7, 0x4D, 0xAA,
  38741. 0xEC, 0xA4, 0xCD, 0x26, 0x7C, 0x3E, 0xAC, 0x93,
  38742. 0x26, 0x9D, 0x6B, 0x83, 0x34, 0xC4, 0x71, 0xE1,
  38743. 0xC8, 0x93, 0x88, 0x09, 0xAF, 0x00, 0xB5, 0x7F,
  38744. 0xD9, 0x5A, 0x8E, 0x36, 0xC1, 0x2E, 0x7E, 0xF1,
  38745. 0x0C, 0xC5, 0x2A, 0xB3, 0xE4, 0x48, 0xDF, 0xFB,
  38746. 0xFF, 0x99, 0xC9, 0x66, 0xD2, 0x28, 0x46, 0x7C,
  38747. 0x43, 0x39, 0x96, 0x69, 0x95, 0x42, 0xAC, 0xE0,
  38748. 0xC2, 0x0C, 0x65, 0x99, 0xC8, 0xB0, 0xAE, 0x76,
  38749. 0xE8, 0x18, 0x3E, 0xA9, 0x1D, 0x44, 0x81, 0x14,
  38750. 0x65, 0xF7, 0xDF, 0xD1, 0xD1, 0x7B, 0x7C, 0x28,
  38751. 0xE0, 0x77, 0x9D, 0x79, 0x9C, 0xE4, 0x1A, 0xF1,
  38752. 0xD0, 0xFF, 0x8E, 0xEA, 0x58, 0x84, 0xB3, 0x47,
  38753. 0xBC, 0xA1, 0x47, 0x48, 0xB7, 0xC3, 0xD5, 0xD1,
  38754. 0xF3, 0xDD, 0xA6, 0x3B, 0x15, 0x4C, 0xB3, 0xB5,
  38755. 0xFD, 0x52, 0x9D, 0x7E, 0xF0, 0xC7, 0x40, 0x2C,
  38756. 0x34, 0xBC, 0xCF, 0x1C, 0x67, 0x30, 0xC0, 0x4D,
  38757. 0xA1, 0xC7, 0x5E, 0xAD, 0xAF, 0xCD, 0xFA, 0x21,
  38758. 0xE4, 0xB5, 0x33, 0x8B, 0x37, 0x2D, 0xCF, 0x4D,
  38759. 0x07, 0x48, 0x61, 0xB0, 0xB6, 0x8B, 0x27, 0x05,
  38760. 0xA0, 0x8C, 0x71, 0x95, 0x84, 0x02, 0xB2, 0x1E,
  38761. 0x59, 0xBC, 0xB6, 0xE2, 0x2C, 0x3C, 0x20, 0x4C,
  38762. 0xDE, 0x1E, 0x35, 0x24, 0xC1, 0x5B, 0x3C, 0xB4,
  38763. 0x2A, 0x8C, 0xA7, 0x2D, 0xE3, 0xDC, 0x45, 0x26,
  38764. 0x6E, 0x29, 0x52, 0x5D, 0x24, 0x8A, 0xC2, 0x16,
  38765. 0x73, 0xDB, 0x80, 0xF2, 0x91, 0xEC, 0x05, 0x3E,
  38766. 0x2E, 0x9E, 0x39, 0x12, 0x5E, 0x11, 0x80, 0x24,
  38767. 0xF5, 0xFC, 0x86, 0x4C, 0xD9, 0xF9, 0x70, 0x59,
  38768. 0xC8, 0xC8, 0x57, 0x5D, 0x0F, 0x68, 0x75, 0x3C,
  38769. 0x7A, 0x3D, 0x1B, 0xF7, 0xD0, 0xDF, 0xE2, 0xF9,
  38770. 0xBD, 0x44, 0xFD, 0x21, 0x75, 0x86, 0x77, 0x25,
  38771. 0xAF, 0xD3, 0x28, 0x55, 0x2A, 0x60, 0x7D, 0x79,
  38772. 0x9C, 0x72, 0x2F, 0x6E, 0xAB, 0x2F, 0x26, 0x44,
  38773. 0x0C, 0xFF, 0x52, 0xBD, 0xA1, 0xA9, 0x07, 0xBD,
  38774. 0x9D, 0x2A, 0x64, 0x2E, 0x0B, 0xA1, 0xB8, 0x78,
  38775. 0xD3, 0xC4, 0x84, 0x9A, 0xE1, 0xDB, 0xB4, 0x4A,
  38776. 0x4C, 0x45, 0x7A, 0x8E, 0xD5, 0xA3, 0x6B, 0x09,
  38777. 0x8D, 0x72, 0x8E, 0x6D, 0x17, 0x34, 0xFF, 0xD6,
  38778. 0xED, 0x24, 0x19, 0x7D, 0xC6, 0x2D, 0x5B, 0x82,
  38779. 0x68, 0xAE, 0x25, 0x33, 0xBB, 0xCB, 0x7D, 0xFD,
  38780. 0x00, 0x15, 0x83, 0xEA, 0xBB, 0xE7, 0x40, 0x3D,
  38781. 0x80, 0xD5, 0x9E, 0x6C, 0xE0, 0x3C, 0x7E, 0x3E,
  38782. 0x12, 0xC7, 0x36, 0x7E, 0x41, 0x84, 0xE8, 0xB4,
  38783. 0x16, 0xCA, 0x4A, 0xB7, 0xEB, 0x16, 0xEC, 0xAB,
  38784. 0x5A, 0x69, 0x24, 0x7F, 0x5E, 0x81, 0x86, 0x7D,
  38785. 0x30, 0x61, 0x4E, 0x0F, 0x75, 0x39, 0xEE, 0xF2,
  38786. 0xF4, 0xDC, 0x5E, 0x23, 0x40, 0xE8, 0x3C, 0xC0,
  38787. 0x10, 0xAD, 0x5E, 0xE6, 0x06, 0x8E, 0x5F, 0x55,
  38788. 0xC5, 0x69, 0x65, 0x5F, 0xA3, 0x6E, 0x73, 0x86,
  38789. 0x82, 0x32, 0x5F, 0x36, 0xA7, 0x6B, 0x2C, 0x26,
  38790. 0xCD, 0x64, 0xC8, 0x57, 0x1F, 0x06, 0x7A, 0xAB,
  38791. 0x8B, 0xA7, 0xDB, 0x53, 0x48, 0x1A, 0x06, 0x8D,
  38792. 0x36, 0xF1, 0x77, 0x74, 0xE6, 0xF5, 0x18, 0x62,
  38793. 0x8E, 0x8A, 0xBF, 0xB7, 0x7F, 0x72, 0x44, 0xAC,
  38794. 0xC8, 0x9A, 0x0E, 0x60, 0x4B, 0xAB, 0xB2, 0x9E,
  38795. 0x95, 0xDF, 0x95, 0x28, 0x98, 0x78, 0xBB, 0xA9,
  38796. 0x5D, 0x8E, 0xEE, 0xB4, 0x84, 0xF5, 0x81, 0x7E,
  38797. 0xA1, 0x53, 0x3E, 0xBB, 0x43, 0xF6, 0xD4, 0xB7,
  38798. 0x60, 0xFD, 0xF4, 0xF8, 0x68, 0xB6, 0x1D, 0x9A,
  38799. 0xF7, 0xDA, 0x77, 0xFA, 0xBB, 0x74, 0x44, 0xDE,
  38800. 0x7C, 0x32, 0x2D, 0x5C, 0x24, 0xD8, 0x4D, 0xBF,
  38801. 0xE0, 0x5C, 0x70, 0x12, 0x3C, 0x43, 0xCC, 0x5F,
  38802. 0x00, 0xD5, 0x1F, 0xEA, 0x5D, 0xC9, 0x3A, 0x5C,
  38803. 0x32, 0xED, 0xE0, 0xF1, 0x59, 0xA0, 0xB7, 0x71,
  38804. 0xDC, 0x65, 0xD2, 0x88, 0x20, 0x20, 0xD8, 0x59,
  38805. 0x53, 0x2D, 0x30, 0x2D, 0xFC, 0xA9, 0xEA, 0x45,
  38806. 0xB0, 0xF3, 0x1E, 0x66, 0x9F, 0xF6, 0xF1, 0x5E,
  38807. 0x9B, 0x67, 0x1D, 0xBF, 0x5E, 0x19, 0xB3, 0x2A,
  38808. 0xE8, 0xCE, 0xE5, 0x90, 0xFE, 0x82, 0x5C, 0x19,
  38809. 0x7B, 0x84, 0x3E, 0x45, 0xFF, 0x5D, 0xC2, 0x2E,
  38810. 0x49, 0x6A, 0xB1, 0x2D, 0x50, 0x2D, 0x21, 0xF7,
  38811. 0x2A, 0xA2, 0x39, 0x47, 0x8D, 0xB5, 0x17, 0x64,
  38812. 0x3E, 0x96, 0x13, 0x90, 0x53, 0xEA, 0x57, 0x4C,
  38813. 0xDB, 0x3D, 0x43, 0xC3, 0xE7, 0xD6, 0x5C, 0x54,
  38814. 0x89, 0xDF, 0x6E, 0xF9, 0xE4, 0xC6, 0x64, 0xF0,
  38815. 0x88, 0x1C, 0xD0, 0xF6, 0x9D, 0x9E, 0xD7, 0xCD,
  38816. 0x2C, 0xFB, 0xCC, 0x54, 0x0E, 0x96, 0xD7, 0x4E,
  38817. 0x05, 0xD2, 0xB3, 0x88, 0x85, 0xD8, 0x60, 0xA4,
  38818. 0xF2, 0xE4, 0xD7, 0xFF, 0xAF, 0x12, 0x2E, 0xBA,
  38819. 0xC4, 0x5A, 0x3A, 0x3E, 0xC5, 0xD7, 0xF3, 0x60,
  38820. 0x4F, 0x27, 0xEF, 0xE0, 0x35, 0xAC, 0x4A, 0x8B,
  38821. 0x14, 0x7D, 0xC4, 0xEF, 0x61, 0x9A, 0x69, 0x2E,
  38822. 0x49, 0x80, 0x04, 0x0C, 0x18, 0xB9, 0x42, 0xC6,
  38823. 0x8C, 0x8A, 0x99, 0x43, 0xA6, 0x5A, 0xCD, 0x72,
  38824. 0x20, 0xAD, 0xFD, 0x9C, 0xC4, 0xAA, 0xDF, 0x6C,
  38825. 0x6C, 0x03, 0xEF, 0x48, 0x3E, 0xFB, 0x4A, 0xBC,
  38826. 0xAA, 0x44, 0xEE, 0xC4, 0x25, 0x8F, 0xF9, 0x8A,
  38827. 0xC2, 0x24, 0x73, 0x15, 0xFA, 0x0E, 0xCB, 0x00,
  38828. 0xEE, 0x9B, 0x39, 0x3F, 0x60, 0x1F, 0x00, 0x95,
  38829. 0xCA, 0xFE, 0xC2, 0x2C, 0x35, 0x5F, 0xD9, 0xD1,
  38830. 0x29, 0xB5, 0x4D, 0xC1, 0x66, 0x51, 0x8F, 0x17,
  38831. 0x3B, 0xF4, 0xF1, 0x49, 0x42, 0x36, 0x0C, 0x5B,
  38832. 0x58, 0xF2, 0x9B, 0x59, 0x01, 0xFB, 0x15, 0x7F,
  38833. 0x21, 0x90, 0x1F, 0x56, 0x69, 0x8B, 0xE2, 0xA5,
  38834. 0x44, 0xCB, 0x84, 0x98, 0x4B, 0x75, 0xA8, 0xCB,
  38835. 0x83, 0x0D, 0xE8, 0x1C, 0x91, 0x7F, 0xE4, 0x57,
  38836. 0x81, 0x16, 0x34, 0x2F, 0xCE, 0x01, 0xAA, 0x62,
  38837. 0x54, 0x44, 0xB7, 0xD6, 0xC7, 0xF1, 0x68, 0x9A,
  38838. 0x00, 0x3B, 0x71, 0x16, 0xF9, 0x96, 0x6A, 0x90,
  38839. 0x6C, 0x2C, 0x4E, 0x58, 0xBC, 0xDD, 0xE9, 0x3B,
  38840. 0x60, 0xB7, 0xA0, 0x97, 0xEE, 0xD6, 0x34, 0xDD,
  38841. 0x49, 0x4A, 0xD9, 0x85, 0xD1, 0xB7, 0x95, 0x14,
  38842. 0xEC, 0x6A, 0x40, 0xE8, 0x31, 0x80, 0xF1, 0xD8,
  38843. 0x5F, 0x75, 0xF6, 0x92, 0x3A, 0x4F, 0xCD, 0x0A,
  38844. 0x6E, 0xBF, 0xA1, 0x27, 0x48, 0x79, 0x27, 0x04,
  38845. 0x76, 0x2C, 0xAB, 0x25, 0x06, 0xEB, 0x43, 0xDD,
  38846. 0x1B, 0x4B, 0x24, 0xFC, 0x93, 0x51, 0x1C, 0x45,
  38847. 0xF6, 0xAE, 0x77, 0xCF, 0xC9, 0xE6, 0x20, 0xE4,
  38848. 0xA5, 0x2B, 0x3D, 0x7D, 0xF0, 0xEB, 0x51, 0x7C,
  38849. 0xCA, 0xFE, 0x58, 0xBA, 0xC4, 0x07, 0x95, 0x75,
  38850. 0x62, 0x0C, 0x50, 0x68, 0x88, 0x1A, 0x8A, 0x0D,
  38851. 0x1B, 0x5C, 0x53, 0x1A, 0x9C, 0xA8, 0x4E, 0xFE,
  38852. 0x63, 0x9B, 0xDB, 0x05, 0x70, 0x01, 0x75, 0xA1,
  38853. 0x3A, 0x08, 0xFA, 0x51, 0xD5, 0xF6, 0x81, 0xDE,
  38854. 0x69, 0xE5, 0x40, 0xB3, 0xF8, 0x7C, 0x46, 0x97,
  38855. 0xA6, 0x4E, 0xA8, 0x51, 0x47, 0x9C, 0xB9, 0x25,
  38856. 0xCD, 0x4E, 0xED, 0xFC, 0xEE, 0x03, 0x6A, 0xCD,
  38857. 0x93, 0x65, 0xB3, 0x68, 0x09, 0x6F, 0xE8, 0x00,
  38858. 0x6A, 0x3F, 0xBF, 0xE8, 0x6F, 0x09, 0xE9, 0xF2,
  38859. 0x6F, 0x44, 0x2E, 0xB1, 0x81, 0x76, 0x04, 0xDD,
  38860. 0x6E, 0xF4, 0x93, 0x61, 0xE5, 0x78, 0xD4, 0xDA,
  38861. 0xBF, 0x05, 0xA1, 0xF4, 0x9D, 0xFD, 0x57, 0x06,
  38862. 0x9C, 0x13, 0x45, 0x97, 0xF2, 0x48, 0xE6, 0x1A,
  38863. 0xB5, 0xAD, 0x09, 0x11, 0x04, 0xBB, 0xA0, 0xA8,
  38864. 0xA3, 0xA3, 0x33, 0xCD, 0x42, 0x2C, 0x66, 0xC2,
  38865. 0x94, 0x80, 0x15, 0x9D, 0x56, 0x74, 0x02, 0xEE,
  38866. 0xA7, 0xE4, 0x90, 0xDD, 0xFB, 0x0B, 0x3B, 0xF0,
  38867. 0x7A, 0x02, 0x44, 0xE8, 0x11, 0xC4, 0x3A, 0xFE,
  38868. 0x73, 0x2A, 0x4C, 0x92, 0x3C, 0x23, 0x37, 0x8B,
  38869. 0x4F, 0x28, 0x8E, 0x1C, 0x4E, 0x7D, 0x0D, 0x6B,
  38870. 0xFD, 0x20, 0xB5, 0x93, 0xB3, 0x75, 0x30, 0x28,
  38871. 0xC7, 0x7E, 0x67, 0xC4, 0xDE, 0xDA, 0x27, 0xA9,
  38872. 0xE3, 0xF2, 0xF5, 0x25, 0x98, 0x5F, 0x6B, 0xBE,
  38873. 0x11, 0x80, 0x23, 0x49, 0x30, 0xC8, 0x8A, 0x63,
  38874. 0xF9, 0xC4, 0x14, 0x77, 0x2A, 0xE2, 0x21, 0x42,
  38875. 0x28, 0x1C, 0xEB, 0x9F, 0x7B, 0x70, 0xA8, 0x2B,
  38876. 0xFB, 0x25, 0x36, 0xA6, 0xAC, 0xFE, 0x8E, 0xFF,
  38877. 0xB6, 0x86, 0x09, 0x15, 0x7E, 0xD9, 0x26, 0x8F,
  38878. 0xDB, 0xF2, 0x2D, 0xC2, 0xFA, 0xAE, 0xDA, 0x50,
  38879. 0xF6, 0x24, 0x53, 0xDB, 0xBF, 0x92, 0x9D, 0x7E,
  38880. 0x48, 0xCC, 0x75, 0xAC, 0xD0, 0xD3, 0x45, 0x09,
  38881. 0x2F, 0x01, 0x60, 0xBB, 0xAE, 0xCB, 0xE6, 0xB3,
  38882. 0x30, 0xDA, 0xD9, 0xB6, 0x12, 0xCD, 0xF5, 0x11,
  38883. 0xCF, 0x2B, 0x2A, 0xC6, 0x61, 0x9A, 0x05, 0x59,
  38884. 0x08, 0x58, 0x64, 0xEC, 0xDB, 0x77, 0xCF, 0x64,
  38885. 0xE2, 0x4B, 0x6E, 0xF4, 0x07, 0x68, 0x5E, 0xE9,
  38886. 0x31, 0xB1, 0x38, 0x67, 0xF9, 0x29, 0x2E, 0x7A,
  38887. 0xD2, 0x03, 0xA6, 0x29, 0x3F, 0x22, 0x58, 0x66,
  38888. 0x6A, 0x07, 0xD8, 0xFD, 0xC5, 0x03, 0xEE, 0x66,
  38889. 0xD4, 0x66, 0x70, 0x6D, 0xA4, 0xC4, 0xA1, 0xEE,
  38890. 0xCD, 0x4D, 0xFA, 0x3C, 0x34, 0x36, 0xC2, 0xC5,
  38891. 0x1E, 0x86, 0xB8, 0x7B, 0x7C, 0xBC, 0x67, 0x16,
  38892. 0xF3, 0x6E, 0xF2, 0xB7, 0xEA, 0x96, 0x1B, 0x0D,
  38893. 0xA2, 0xC8, 0x42, 0xBF, 0x30, 0x09, 0x2A, 0x6D,
  38894. 0x9D, 0x35, 0xB3, 0x92, 0xBA, 0x3E, 0xE2, 0xE9,
  38895. 0xE2, 0xAA, 0x90, 0x70, 0xCE, 0x0F, 0x07, 0xFA,
  38896. 0x7C, 0x3B, 0xF7, 0x66, 0x7F, 0x5C, 0xFE, 0xD9,
  38897. 0x72, 0x1C, 0x4E, 0xFE, 0x7E, 0x86, 0x8E, 0x7F,
  38898. 0x62, 0x8D, 0x41, 0x46, 0x7B, 0x43, 0x17, 0xB9,
  38899. 0x44, 0xED, 0x39, 0x1B, 0x3E, 0xF9, 0x2D, 0xC7,
  38900. 0x5C, 0x9D, 0xAC, 0x05, 0x00, 0xC6, 0x85, 0x4E,
  38901. 0xB8, 0xBC, 0x29, 0xDF, 0x6D, 0x6A, 0xCC, 0xEB,
  38902. 0xD6, 0x44, 0x86, 0xAA, 0xC9, 0x55, 0x49, 0xA1,
  38903. 0x3F, 0x59, 0x5E, 0xAF, 0xD5, 0xC9, 0x96, 0x19,
  38904. 0x84, 0xC0, 0x4D, 0x1B, 0xE5, 0x2C, 0x42, 0x8D,
  38905. 0x2C, 0xC8, 0x83, 0x00, 0x26, 0xBF, 0x46, 0x9F,
  38906. 0x20, 0x97, 0xEC, 0x2C, 0xA9, 0x2C, 0xF0, 0xA7,
  38907. 0x11, 0xED, 0xE2, 0xA2, 0x57, 0x83, 0x40, 0x92,
  38908. 0xF3, 0x58, 0xB7, 0x4E, 0xD6, 0x3A, 0x9D, 0xF0,
  38909. 0xDD, 0xD4, 0x5F, 0x82, 0x58, 0xD3, 0x72, 0x05,
  38910. 0x69, 0xFF, 0x1E, 0xBC, 0x74, 0x90, 0x87, 0xB5,
  38911. 0x7A, 0xEE, 0xF8, 0xCE, 0x3F, 0x59, 0xE1, 0xC0,
  38912. 0x46, 0x24, 0xF8, 0x9D, 0x93, 0x51, 0x4A, 0x44,
  38913. 0xFB, 0xEA, 0x58, 0xA6, 0xAC, 0x9A, 0x7C, 0xA3,
  38914. 0x11, 0xA3, 0x47, 0x44, 0x24, 0x11, 0xF5, 0x56,
  38915. 0x1A, 0x3B, 0xCF, 0xEC, 0xD9, 0x2B, 0x6C, 0xBA,
  38916. 0xA6, 0xA2, 0x67, 0xB9, 0xE0, 0xCB, 0x3F, 0x8D,
  38917. 0xA8, 0xC4, 0x8A, 0x45, 0xAB, 0xE2, 0x10, 0x19,
  38918. 0x10, 0xC9, 0xDB, 0x01, 0x64, 0xC0, 0x0B, 0x6F,
  38919. 0x3B, 0xA1, 0xE9, 0xEB, 0x74, 0x9A, 0x63, 0x93,
  38920. 0xE5, 0x74, 0x3F, 0xD3, 0x7B, 0xEA, 0x8C, 0xD6,
  38921. 0x7D, 0x66, 0xDD, 0x90, 0x6C, 0x69, 0x67, 0x05,
  38922. 0xAD, 0x70, 0xF1, 0xFA, 0x52, 0xBB, 0xD5, 0x3D,
  38923. 0x0E, 0x7E, 0x87, 0xE0, 0x98, 0xAF, 0xA6, 0xE6,
  38924. 0x0E, 0x25, 0x91, 0x70, 0xCA, 0x36, 0xE4, 0xF8,
  38925. 0xF7, 0x95, 0x1C, 0x48, 0xF6, 0x62, 0x9A, 0x4D,
  38926. 0xE4, 0xE7, 0x3A, 0x92, 0xC6, 0x2E, 0xAB, 0x8A,
  38927. 0x75, 0x7C, 0x45, 0xDA, 0x54, 0xB1, 0x6D, 0x2E,
  38928. 0xCC, 0x13, 0x46, 0x67, 0x8F, 0xFF, 0xDA, 0x18,
  38929. 0xE1, 0x4C, 0xE4, 0x6A, 0xB6, 0xAC, 0x65, 0x32,
  38930. 0x0C, 0x63, 0xD5, 0x43, 0xB5, 0x8B, 0xB1, 0x52,
  38931. 0xEE, 0x0C, 0xBB, 0x62, 0x34, 0x30, 0xDB, 0xF7,
  38932. 0x08, 0xC6, 0xE8, 0x5B, 0x07, 0x66, 0x6D, 0x4B,
  38933. 0x39, 0xC6, 0x94, 0x2B, 0x22, 0x9E, 0x3E, 0x45,
  38934. 0x62, 0x3D, 0x05, 0x03, 0x2B, 0x16, 0x71, 0xBB,
  38935. 0x85, 0x1B, 0x6E, 0x84, 0xD3, 0x48, 0x4D, 0x63,
  38936. 0x26, 0x60, 0x97, 0x45, 0xB8, 0xEA, 0x43, 0x96,
  38937. 0x00, 0xFE, 0x0B, 0x85, 0xBD, 0x22, 0x40, 0xA4,
  38938. 0xA7, 0x2F, 0xC1, 0xEB, 0xFD, 0xB5, 0x22, 0xD5,
  38939. 0x1F, 0xB3, 0xEA, 0x7C, 0x6D, 0x20, 0xFB, 0x98,
  38940. 0xA5, 0xF2, 0x84, 0x70, 0xF7, 0xB9, 0x2A, 0x12,
  38941. 0x63, 0x0C, 0x2D, 0x97, 0x6C, 0xC2, 0x76, 0xAC,
  38942. 0x32, 0xE2, 0xB1, 0x3A, 0xB3, 0xAB, 0x9E, 0xBB,
  38943. 0x61, 0xB4, 0x6A, 0x5F, 0x2D, 0x4D, 0xCE, 0x0D,
  38944. 0xFB, 0x97, 0x80, 0x89, 0x4A, 0x81, 0xFB, 0xB2,
  38945. 0x72, 0x37, 0x66, 0xB9, 0x08, 0xBF, 0xCD, 0x9F,
  38946. 0x63, 0xB2, 0xBA, 0x54, 0xF1, 0x9E, 0xEC, 0x11,
  38947. 0x67, 0x26, 0xC7, 0x98, 0xDD, 0xA3, 0xC5, 0x50,
  38948. 0x86, 0x17, 0xD5, 0xCF, 0x51, 0x97, 0x22, 0x65,
  38949. 0x2B, 0x71, 0xF7, 0x34, 0x84, 0x55, 0xC9, 0xD1,
  38950. 0xFE, 0x75, 0x42, 0x0A, 0x5A, 0x31, 0x59, 0xE8,
  38951. 0x8A, 0x0D, 0xE5, 0x77, 0x1C, 0xF5, 0xFD, 0x27,
  38952. 0x05, 0x05, 0xF7, 0x28, 0xDA, 0x54, 0xAB, 0xBD,
  38953. 0xDC, 0x50, 0xB8, 0xDB, 0x2E, 0xB4, 0x28, 0x41,
  38954. 0x30, 0x04, 0x40, 0xD5, 0xF0, 0x12, 0xD7, 0x16,
  38955. 0x3D, 0x8F, 0x41, 0xE7, 0x70, 0x76, 0x82, 0xB9,
  38956. 0xC4, 0xB2, 0x1F, 0x57, 0x10, 0xB6, 0xC4, 0x84,
  38957. 0x0D, 0xB1, 0xB8, 0x21, 0xB2, 0x77, 0x09, 0xF6,
  38958. 0xD5, 0x9C, 0xE4, 0xA2, 0xFA, 0x83, 0x13, 0x56,
  38959. 0x94, 0x3F, 0x37, 0x6D, 0x0D, 0x7C, 0x7E, 0xA0,
  38960. 0xE5, 0xC8, 0xD9, 0x42, 0x0F, 0x35, 0xB1, 0xDC,
  38961. 0xB9, 0x49, 0xD5, 0xED, 0xA8, 0x90, 0x09, 0x14,
  38962. 0xAE, 0x63, 0xB5, 0xEA, 0x62, 0x0D, 0x9E, 0x6D,
  38963. 0x93, 0xBD, 0x3A, 0xEA, 0x24, 0xB5, 0xAC, 0xC9,
  38964. 0xD1, 0x7B, 0xBC, 0xC6, 0xC4, 0xBA, 0x68, 0xB1,
  38965. 0x65, 0xFE, 0xAB, 0x30, 0xD4, 0x92, 0xD9, 0xC1,
  38966. 0x94, 0x84, 0xE1, 0x20, 0x4E, 0x28, 0x7C, 0x3A,
  38967. 0x3E, 0x8B, 0x44, 0x79, 0xC7, 0xB5, 0xA5, 0x95,
  38968. 0xC2, 0xC9, 0xA8, 0x3F, 0x92, 0x67, 0x06, 0x9A,
  38969. 0x12, 0xD3, 0xAE, 0x78, 0x87, 0x0E, 0x31, 0x54,
  38970. 0x26, 0xDF, 0x97, 0xEB, 0x6C, 0xF3, 0xC9, 0x53,
  38971. 0x39, 0xED, 0x50, 0x5A, 0xF9, 0x6A, 0x03, 0x27,
  38972. 0x8E, 0xC6, 0x79, 0x5B, 0xD4, 0xD3, 0x57, 0x97,
  38973. 0xFD, 0xF5, 0xCB, 0x14, 0xDB, 0xBE, 0x39, 0xB9,
  38974. 0x64, 0x8A, 0x75, 0xAA, 0xE3, 0x4A, 0x19, 0x59,
  38975. 0x69, 0x7D, 0xF8, 0x7D, 0x8C, 0xB8, 0x2F, 0x32,
  38976. 0x57, 0xBF, 0x84, 0x9E, 0x45, 0x4E, 0xC4, 0xA0,
  38977. 0x65, 0xA4, 0x0B, 0x73, 0x36, 0xC5, 0xD1, 0x07,
  38978. 0xF8, 0x1C, 0x91, 0x07, 0xB8, 0x0B, 0x4B, 0xE5,
  38979. 0x4F, 0xE6, 0xA1, 0xDF, 0x29, 0x03, 0xE7, 0x68,
  38980. 0xA4, 0x32, 0x8E, 0x21, 0x8F, 0x15, 0x51, 0x57,
  38981. 0x65, 0x16, 0xF0, 0x55, 0x71, 0x8C, 0x28, 0xD8,
  38982. 0x82, 0xDC, 0x8A, 0xC1, 0xE7, 0x5C, 0xF2, 0xD5,
  38983. 0xB8, 0x18, 0x16, 0x9F, 0x63, 0x89, 0x21, 0xF1,
  38984. 0xA6, 0xED, 0x21, 0xDA, 0xC8, 0x0A, 0x10, 0x21,
  38985. 0x18, 0x98, 0xD0, 0xF2, 0x9E, 0xDE, 0x5A, 0xA1,
  38986. 0x51, 0xC9, 0x18, 0x3B, 0x68, 0x79, 0x75, 0xE7,
  38987. 0xF4, 0xF9, 0xBF, 0x5F, 0xBE, 0x61, 0x35, 0xA9,
  38988. 0x02, 0x56, 0x2D, 0x99, 0xD8, 0x95, 0xFA, 0x78,
  38989. 0x8A, 0x67, 0x24, 0x1D, 0xDF, 0x13, 0x14, 0xD0,
  38990. 0xB4, 0xB6, 0x21, 0x11, 0xB7, 0xA4, 0x06, 0x8D,
  38991. 0x1D, 0xF6, 0xD5, 0x50, 0x2A, 0x0A, 0x42, 0x3C,
  38992. 0x7C, 0xF1, 0x1F, 0x15, 0x1C, 0x81, 0x69, 0xDA,
  38993. 0xCC, 0xAC, 0x8F, 0xB9, 0x08, 0x4E, 0xF8, 0x4E,
  38994. 0x3E, 0x77, 0x26, 0x4A, 0x1F, 0x72, 0x89, 0xCA,
  38995. 0x91, 0x77, 0x99, 0xBF, 0x28, 0xD2, 0x31, 0x65,
  38996. 0x30, 0x37, 0x84, 0x66, 0x8A, 0x1C, 0xC6, 0x59,
  38997. 0x7D, 0x48, 0x9B, 0x4D, 0xDC, 0x87, 0x4F, 0xD2,
  38998. 0x04, 0xA0, 0x8B, 0x8B, 0x37, 0x3B, 0x1A, 0xDB,
  38999. 0xCF, 0x63, 0x39, 0x07, 0xF3, 0x37, 0xCF, 0x0E,
  39000. 0x2F, 0xEB, 0xE6, 0x2A, 0xA1, 0x4C, 0xE0, 0x75,
  39001. 0x3F, 0xAB, 0xF7, 0xDE, 0x48, 0x83, 0x79, 0x89,
  39002. 0x30, 0xA7, 0x1B, 0xE8, 0x73, 0x8E, 0x9D, 0x1D,
  39003. 0xF6, 0x5C, 0x91, 0x4F, 0x44, 0x7C, 0x04, 0xA7,
  39004. 0x07, 0xC8, 0xCC, 0x4A, 0x5C, 0x81, 0xAD, 0x48,
  39005. 0x7C, 0xE5, 0x19, 0x5A, 0xC4, 0x29, 0x80, 0x14,
  39006. 0xFA, 0xC2, 0x26, 0x1C, 0x50, 0x28, 0xB9, 0xF6,
  39007. 0x7F, 0x8D, 0x51, 0x9A, 0xDA, 0xBB, 0x8E, 0x90,
  39008. 0xBA, 0x3B, 0xD9, 0x4D, 0x61, 0xBE, 0xFD, 0x33,
  39009. 0xC0, 0xCA, 0x7B, 0x09, 0xFF, 0x36, 0x84, 0x70,
  39010. 0x11, 0xB4, 0xBE, 0x81, 0xFE, 0x71, 0xEE, 0x81,
  39011. 0xD7, 0x61, 0xBB, 0x83, 0xA6, 0xA0, 0xDC, 0x20,
  39012. 0x04, 0x02, 0x4C, 0x1B, 0x4D, 0xED, 0x8A, 0xC1,
  39013. 0x38, 0x70, 0xC3, 0x69, 0xC9, 0x50, 0xC2, 0x17,
  39014. 0x64, 0xAD, 0x9D, 0x44, 0x63, 0x44, 0xE5, 0x32,
  39015. 0x7B, 0x90, 0xE3, 0xEF, 0x45, 0x28, 0xA6, 0x23,
  39016. 0x92, 0xCB, 0xA1, 0xFC, 0xA8, 0xB4, 0x39, 0xF1,
  39017. 0xB1, 0x00, 0x1F, 0x06, 0xD4, 0x91, 0x5D, 0xDB,
  39018. 0xAC, 0x7D, 0x87, 0xD4, 0xEE, 0xCD, 0x4A, 0x06,
  39019. 0x3E, 0xB4, 0x84, 0x65, 0xAA, 0x47, 0x05, 0x41,
  39020. 0x7C, 0x95, 0x47, 0x3A, 0x49, 0x80, 0xC5, 0xAC,
  39021. 0x32, 0x41, 0x6A, 0x3A, 0x2B, 0xB9, 0xD9, 0x21,
  39022. 0x80, 0xC7, 0xC1, 0xD0, 0xC9, 0x95, 0x4B, 0xC3,
  39023. 0xEA, 0x0D, 0x3F, 0x0E, 0xE4, 0x5A, 0xD8, 0xBD,
  39024. 0x11, 0xD0, 0x76, 0x6D, 0x3C, 0xA7, 0x64, 0xD8,
  39025. 0xCA, 0x4C, 0x8F, 0x58, 0x2C, 0xDD, 0x95, 0x1F,
  39026. 0xBB, 0x76, 0x8D, 0x10, 0xFD, 0xAD, 0x45, 0xCE,
  39027. 0x71, 0x6E, 0x27, 0x92, 0xC4, 0xA6, 0x17, 0x46,
  39028. 0x95, 0xDB, 0xD8, 0xEA, 0x9A, 0x5F, 0x0E, 0xE0,
  39029. 0x0A, 0xA2, 0xF5, 0x79, 0xC3, 0x74, 0xA7, 0x70,
  39030. 0x99, 0x3B, 0x23, 0xD7, 0x3E, 0xA4, 0x96, 0xB5,
  39031. 0x54, 0x77, 0x71, 0x8D, 0x78, 0x2E, 0xCC, 0x0A,
  39032. 0x4E, 0xF8, 0xA9, 0x96, 0xEE, 0xB4, 0x4B, 0x5B,
  39033. 0xDC, 0x52, 0x6D, 0xE1, 0x61, 0x36, 0xE1, 0x32,
  39034. 0xD6, 0xA2, 0x7B, 0x2E, 0xCC, 0x78, 0x92, 0xA1,
  39035. 0x81, 0x59, 0xB8, 0xC7, 0x04, 0x11, 0x3D, 0xF0,
  39036. 0xF9, 0xF9, 0x3E, 0x47, 0x3C, 0xEA, 0xD5, 0x30,
  39037. 0x2D, 0xAE, 0xC0, 0x47, 0xC8, 0x61, 0xCC, 0x9C,
  39038. 0x2E, 0xC0, 0x40, 0x16, 0x11, 0x73, 0x13, 0xF3,
  39039. 0x19, 0xAE, 0x72, 0x44, 0x72, 0xC5, 0x59, 0x51,
  39040. 0x2E, 0x9F, 0xE3, 0x07, 0xB0, 0xCA, 0x6B, 0xB0,
  39041. 0x15, 0x20, 0xB4, 0x25, 0x00, 0xED, 0xFD, 0xAC,
  39042. 0xD6, 0x34, 0x8B, 0xCA, 0xE8, 0xC6, 0x3B, 0xFD,
  39043. 0x02, 0x22, 0xE6, 0x91, 0x2B, 0x4B, 0x61, 0xDF,
  39044. 0x63, 0x5C, 0x2B, 0x5F, 0x82, 0x07, 0x23, 0x59,
  39045. 0x82, 0x5E, 0x0E, 0x21, 0xF7, 0x9C, 0x37, 0x1C,
  39046. 0x7E, 0x6F, 0xD4, 0xFA, 0x91, 0x40, 0x8B, 0x98,
  39047. 0x68, 0xBD, 0x60, 0x2F, 0x0A, 0xC8, 0xC8, 0x99,
  39048. 0xA1, 0xC6, 0x10, 0xF1, 0x27, 0x53, 0xD3, 0xFB,
  39049. 0x23, 0x02, 0xE7, 0x8E, 0x95, 0xB1, 0xF0, 0x21,
  39050. 0xCB, 0x90, 0xEE, 0x8D, 0xE0, 0x27, 0x57, 0xDE,
  39051. 0x40, 0xA3, 0xE7, 0x8F, 0x61, 0xC1, 0x8F, 0xC5,
  39052. 0x0C, 0x0F, 0xBA, 0x05, 0xA0, 0x58, 0x8E, 0x86,
  39053. 0x8A, 0xF5, 0x72, 0xE1, 0x34, 0xB4, 0xF6, 0x8E,
  39054. 0x6E, 0xA4, 0x21, 0x75, 0x43, 0x73, 0xE7, 0x32,
  39055. 0x72, 0x80, 0x9B, 0xE7, 0x1D, 0x78, 0x8F, 0x0D,
  39056. 0x06, 0x47, 0x9E, 0x4D, 0xB4, 0xAC, 0x3E, 0x0D,
  39057. 0xB8, 0x11, 0x23, 0xFF, 0xAD, 0xB9, 0x23, 0xE0,
  39058. 0xA4, 0x37, 0xA6, 0x3D, 0xC2, 0x15, 0xF4, 0x64,
  39059. 0x03, 0x1F, 0x0A, 0x68, 0xED, 0x37, 0x37, 0xE8,
  39060. 0x3E, 0x5B, 0x49, 0x78, 0xFC, 0xFC, 0x12, 0x06,
  39061. 0xE8, 0xC7, 0xCD, 0x3A, 0xAF, 0xD4, 0x54, 0xA7,
  39062. 0x04, 0x7B, 0xFC, 0x66, 0xA6, 0xA8, 0x1C, 0x38,
  39063. 0x0C, 0x26, 0x08, 0xE6, 0xEE, 0x47, 0x25, 0x80,
  39064. 0x59, 0xA5, 0x39, 0x81, 0x20, 0xEE, 0x5F, 0x49,
  39065. 0x9A, 0x01, 0x37, 0xE9, 0x96, 0x18, 0xD0, 0x05,
  39066. 0x2D, 0xE3, 0x73, 0xD5, 0x08, 0x3B, 0x18, 0x46,
  39067. 0xFE, 0x9E, 0x67, 0x5B, 0x9E, 0xF8, 0x53, 0x05,
  39068. 0x2F, 0x96, 0x18, 0x9C, 0x09, 0x0D, 0xA6, 0x05,
  39069. 0xB3, 0x9E, 0x2F, 0x0B, 0x5A, 0xF3, 0x93, 0xFF,
  39070. 0x29, 0xF3, 0x4F, 0x62, 0xD5, 0x9A, 0xCE, 0x74,
  39071. 0x64, 0xD0, 0xBC, 0xB3, 0x08, 0xF1, 0xD3, 0x22,
  39072. 0xA5, 0xBE, 0x64, 0x0A, 0xEB, 0xA5, 0xF5, 0x1B,
  39073. 0x7E, 0x0A, 0x44, 0x3B, 0x1D, 0xA9, 0x48, 0x9A,
  39074. 0x2F, 0xED, 0x05, 0x0F, 0x44, 0xB3, 0x6D, 0xAD,
  39075. 0x39, 0x2C, 0xBA, 0x8E, 0x2B, 0xDE, 0x17, 0x38,
  39076. 0xD1, 0x69, 0xEA, 0xAE, 0x4E, 0x97, 0xCD, 0x61,
  39077. 0xBA, 0x75, 0x39, 0xF2, 0x81, 0xBB, 0xA9, 0x0F,
  39078. 0x6F, 0x82, 0xD4, 0xCB, 0xE4, 0x93, 0x82, 0x11,
  39079. 0x72, 0x9A, 0xE9, 0x87, 0xEC, 0xCC, 0x6D, 0xA1,
  39080. 0x7D, 0x47, 0x60, 0x20, 0xB6, 0xEE, 0xC6, 0xAA,
  39081. 0xC0, 0x3C, 0x95, 0x08, 0xA0, 0x8B, 0xFA, 0x04,
  39082. 0xF6, 0x6F, 0x65, 0x48, 0xCA, 0xA7, 0xA3, 0xA8,
  39083. 0xBB, 0x3B, 0x80, 0x91, 0xB6, 0x6D, 0x2F, 0x9D,
  39084. 0x97, 0xBB, 0x52, 0xE6, 0xC4, 0x24, 0x99, 0x97,
  39085. 0x63, 0xAD, 0xD2, 0xFD, 0xB3, 0x94, 0x6D, 0xC1,
  39086. 0xFB, 0xFA, 0x89, 0x45, 0x78, 0x80, 0x3C, 0xAA,
  39087. 0x3F, 0xC0, 0x7E, 0x8D, 0x37, 0x00, 0xA7, 0x70,
  39088. 0xD6, 0x57, 0x2A, 0xD3, 0x17, 0xB1, 0x9E, 0xDF,
  39089. 0x96, 0x98, 0x40, 0xB8, 0x1C, 0xCC, 0xC6, 0xCD,
  39090. 0xCD, 0xB0, 0xF3, 0x23, 0x53, 0xB6, 0x45, 0x78,
  39091. 0xA6, 0xA0, 0x88, 0x61, 0x06, 0x04, 0x8E, 0x1B,
  39092. 0xCD, 0x12, 0x29, 0x50, 0x0F, 0xD2, 0x8C, 0x89,
  39093. 0x51, 0xD1, 0x74, 0x0B, 0xE3, 0xA7, 0x75, 0x8A,
  39094. 0x60, 0x95, 0xEF, 0x6A, 0x98, 0xC7, 0x35, 0xA5,
  39095. 0xC0, 0xFB, 0x4C, 0x88, 0xA1, 0xDA, 0xCE, 0x79,
  39096. 0x3D, 0x4E, 0x4F, 0x91, 0x75, 0x88, 0xE0, 0x5F,
  39097. 0x17, 0xF5, 0xEF, 0xF8, 0x49, 0xFE, 0xB1, 0xDB,
  39098. 0x0D, 0xE8, 0xB2, 0xF7, 0xD4, 0x90, 0xBD, 0xB0,
  39099. 0x6B, 0x3A, 0x1B, 0xB5, 0xC6, 0xFB, 0x93, 0xEF,
  39100. 0xF3, 0xDD, 0x60, 0xEA, 0x67, 0x11, 0xFE, 0x6A,
  39101. 0xCC, 0x2C, 0x64, 0x2A, 0x85, 0x2E, 0x24, 0x39,
  39102. 0x34, 0x6B, 0xBC, 0xF8, 0x89, 0xB3, 0x49, 0x82,
  39103. 0x9C, 0xC0, 0x04, 0x29, 0x6D, 0x25, 0xCB, 0x19,
  39104. 0xE1, 0x53, 0xC6, 0x10, 0x7D, 0x62, 0x07, 0xD2,
  39105. 0x83, 0x8B, 0x89, 0x04, 0x70, 0x06, 0x60, 0x4F,
  39106. 0xB6, 0x10, 0x2B, 0xA0, 0x92, 0xF4, 0x1A, 0x7A,
  39107. 0xD6, 0x4F, 0xDC, 0x6C, 0x6C, 0x27, 0xE5, 0xEC,
  39108. 0x68, 0x1B, 0x95, 0x7C, 0x1C, 0x95, 0x2C, 0xB7,
  39109. 0x0A, 0x8D, 0xC7, 0x57, 0x92, 0x00, 0x4D, 0xC0,
  39110. 0x5F, 0xD4, 0xF4, 0x88, 0x3F, 0x8D, 0x43, 0x12,
  39111. 0x05, 0xE2, 0x14, 0x0E, 0xDD, 0x2C, 0xEC, 0xD5,
  39112. 0x2F, 0x1A, 0xE6, 0x97, 0xDC, 0xFE, 0x96, 0x80,
  39113. 0x67, 0x3B, 0xD4, 0x63, 0x73, 0xFA, 0xC8, 0x4F,
  39114. 0x4C, 0x4F, 0x2D, 0x68, 0x76, 0x44, 0x8E, 0xC2,
  39115. 0x19, 0x99, 0x44, 0xEA, 0xF2, 0x33, 0x23, 0x83,
  39116. 0xC8, 0xB1, 0x7C, 0x27, 0x43, 0x9B, 0x67, 0xF9,
  39117. 0xDE, 0xE1, 0xAE, 0x03, 0xA5, 0xA5, 0x2B, 0x96,
  39118. 0xB2, 0xEC, 0x4A, 0x43, 0xA7, 0x6D, 0xF4, 0xDB,
  39119. 0x32, 0x5B, 0x54, 0xD6, 0x63, 0xEA, 0x65, 0xC2,
  39120. 0xA8, 0x4B, 0x80, 0xCC, 0x65, 0x2D, 0xCE, 0x6F,
  39121. 0x61, 0x2F, 0x58, 0xD1, 0xE5, 0x64, 0x8A, 0x42,
  39122. 0x8D, 0xBA, 0xFA, 0x35, 0x5C, 0x9E, 0xD5, 0x80,
  39123. 0x2D, 0x5C, 0xC3, 0x47, 0xFB, 0x0D, 0x43, 0x20,
  39124. 0x7A, 0xA4, 0x37, 0xB2, 0x2F, 0x0B, 0x43, 0xB9,
  39125. 0x94, 0xD3, 0xD9, 0xC2, 0xD7, 0x02, 0x5D, 0x6A,
  39126. 0x12, 0x99, 0xE7, 0x32, 0x6C, 0xF0, 0x0C, 0x73,
  39127. 0x51, 0x33, 0x84, 0xA9, 0x0C, 0x66, 0xC9, 0x19,
  39128. 0x88, 0x9A, 0xF1, 0xB6, 0xF8, 0x41, 0xB1, 0xDC,
  39129. 0x60, 0xA4, 0x80, 0x73, 0x0B, 0x21, 0xF9, 0xB8,
  39130. 0x01, 0x7E, 0x66, 0x0D, 0xB4, 0x2B, 0x53, 0x8D,
  39131. 0x7D, 0x0B, 0xE1, 0xA3, 0x0C, 0x27, 0xF6, 0x2F,
  39132. 0x27, 0x34, 0x53, 0x75, 0x54, 0xF7, 0x5E, 0x05,
  39133. 0x1C, 0x5A, 0x94, 0x08, 0x14, 0xDE, 0xAA, 0x98,
  39134. 0xD9, 0xA5, 0xA0, 0xBE, 0x80, 0xC1, 0xEB, 0x3C,
  39135. 0xCF, 0x78, 0x88, 0xA4, 0xA2, 0x03, 0xF8, 0x79,
  39136. 0x1F, 0x84, 0x84, 0xA7, 0x0E, 0x95, 0x1A, 0x85,
  39137. 0xEF, 0x4C, 0xBE, 0xA2, 0x99, 0xAB, 0x10, 0xDD,
  39138. 0x85, 0x3F, 0x10, 0x6A, 0x9C, 0xD5, 0xDD, 0x7A,
  39139. 0xFB, 0xF5, 0xD9, 0xD9, 0xAA, 0xDF, 0x03, 0x78,
  39140. 0xAF, 0x1D, 0xEC, 0x18, 0xEB, 0x00, 0xB6, 0x64,
  39141. 0xB5, 0x75, 0xA5, 0x00, 0xDC, 0x36, 0x45, 0xBD,
  39142. 0x0C, 0x66, 0xCE, 0xA9, 0xBB, 0xD1, 0xF7, 0xE4,
  39143. 0x6A, 0xDA, 0x0E, 0x81, 0x0F, 0x6A, 0x71, 0x60,
  39144. 0x5C, 0x41, 0xD2, 0x12, 0x45, 0x14, 0xEF, 0x6F,
  39145. 0xEC, 0x22, 0x73, 0x4C, 0xA7, 0x94, 0xDD, 0x1A,
  39146. 0x42, 0x22, 0x58, 0x14, 0x0C, 0x4E, 0x6D, 0x77,
  39147. 0x7F, 0xF5, 0xC9, 0x69, 0x81, 0xA3, 0xB8, 0x6D,
  39148. 0x1C, 0x39, 0x47, 0xA5, 0xC4, 0x61, 0x1C, 0x91,
  39149. 0x2F, 0x67, 0xC3, 0x5E, 0x87, 0x1A, 0x85, 0x81,
  39150. 0x7D, 0x76, 0xF2, 0xE0, 0xB9, 0xD0, 0x43, 0x33,
  39151. 0xF1, 0xC1, 0xBA, 0x48, 0x6F, 0x48, 0xD5, 0xAE,
  39152. 0xB6, 0xDC, 0xAA, 0xCA, 0xEB, 0x0B, 0x6B, 0xFE,
  39153. 0xF4, 0xF1, 0x6E, 0x5D, 0xE4, 0x90, 0x53, 0xCF,
  39154. 0x9E, 0x13, 0x80, 0xCE, 0xE5, 0xDD, 0xA4, 0x01,
  39155. 0xBC, 0x16, 0x50, 0xD0, 0x78, 0x96, 0x3F, 0x2B,
  39156. 0x7A, 0x71, 0x8E, 0x86, 0xFD, 0x14, 0x21, 0xDF,
  39157. 0x4D, 0xD7, 0xDD, 0x42, 0x59, 0xB3, 0xED, 0x81,
  39158. 0xE3, 0xAF, 0x71, 0x57, 0xE7, 0x04, 0xD2, 0x26,
  39159. 0xA8, 0x83, 0xFC, 0x03, 0x90, 0x8C, 0x88, 0xC4,
  39160. 0xBF, 0x74, 0x54, 0x59, 0xD8, 0x66, 0x9F, 0xE2,
  39161. 0x7A, 0xCE, 0x5B, 0x9C, 0xC4, 0x37, 0xFA, 0xDB,
  39162. 0x40, 0x9A, 0xDD, 0x73, 0x9C, 0x06, 0x5A, 0x21,
  39163. 0x43, 0xFB, 0xFA, 0x1B, 0x41, 0x31, 0x9F, 0xF4,
  39164. 0x24, 0x09, 0x05, 0xFE, 0x56, 0x17, 0x52, 0x9C,
  39165. 0xC7, 0xE2, 0xCA, 0xC9, 0x1F, 0xBE, 0xE2, 0xEB,
  39166. 0x92, 0xEE, 0xD4, 0x76, 0x44, 0x9A, 0xFA, 0xFB,
  39167. 0x07, 0x62, 0x98, 0xEC, 0xA0, 0xCF, 0xBF, 0xFA,
  39168. 0x5E, 0x1B, 0x8B, 0xCD, 0x33, 0xFB, 0x1A, 0x97,
  39169. 0xFE, 0x50, 0x65, 0x22, 0x08, 0x9E, 0xC3, 0x87,
  39170. 0x88, 0xCA, 0xDD, 0x11, 0x5E, 0xA7, 0xCF, 0xF3,
  39171. 0x07, 0x0A, 0x34, 0x0E, 0x30, 0x1B, 0xC5, 0xCE,
  39172. 0xF7, 0xA6, 0xA4, 0x31, 0xB5, 0x40, 0xB8, 0x81,
  39173. 0xAC, 0xAA, 0x07, 0xE0, 0x7D, 0x5E, 0x6A, 0x25,
  39174. 0x85, 0x8D, 0x1D, 0x82, 0x45, 0x82, 0x76, 0xB2,
  39175. 0x65, 0x69, 0x3E, 0x88, 0xFE, 0x21, 0xFE, 0x6A,
  39176. 0x6B, 0x97, 0xD6, 0x70, 0x70, 0x00, 0x83, 0x18,
  39177. 0x39, 0xA6, 0x91, 0x3F, 0xB1, 0xB7, 0xED, 0x11,
  39178. 0xD3, 0xF9, 0x74, 0x31, 0xEC, 0x21, 0xA2, 0xEE,
  39179. 0x69, 0x04, 0xC0, 0xEA, 0x4A, 0x17, 0x1A, 0xF8,
  39180. 0xDA, 0xF1, 0x52, 0xB2, 0x78, 0x69, 0x4F, 0xDF,
  39181. 0xE6, 0xB9, 0xF3, 0xE7, 0x48, 0x8B, 0x09, 0x5F,
  39182. 0x4A, 0x7A, 0x05, 0x8E, 0xA8, 0xF6, 0x69, 0x3D,
  39183. 0x91, 0x7A, 0x6F, 0x6C, 0xAD, 0x03, 0x16, 0xEA,
  39184. 0xE0, 0x04, 0xFE, 0x54, 0x71, 0x50, 0x6D, 0x31,
  39185. 0xE4, 0x37, 0x76, 0xD6, 0x1B, 0xA9, 0xEE, 0x56,
  39186. 0x7A, 0x39, 0x34, 0x24, 0x00, 0x58, 0xE3, 0x2F,
  39187. 0xD4, 0x97, 0x57, 0x6F, 0xD8, 0x0E, 0x8B, 0xD3,
  39188. 0x88, 0x7F, 0xE8, 0x74, 0x72, 0xF7, 0xBA, 0x26,
  39189. 0x25, 0xE4, 0xD5, 0x86, 0xCD, 0xA8, 0x1E, 0x8D,
  39190. 0x49, 0xCF, 0x04, 0x92, 0x5B, 0x50, 0xD0, 0x73,
  39191. 0x3C, 0xC9, 0x17, 0xC3, 0x0E, 0x67, 0x02, 0xC5,
  39192. 0xDE, 0x48, 0x88, 0x0D, 0x2C, 0x0D, 0x68, 0x04,
  39193. 0xD5, 0x51, 0xDF, 0x4F, 0x23, 0x89, 0x7A, 0x29,
  39194. 0x41, 0xB2, 0x7A, 0xCA, 0x86, 0xA5, 0xCC, 0xC4,
  39195. 0xF5, 0xD3, 0xE1, 0xEF, 0xB8, 0xCD, 0x84, 0xB5,
  39196. 0x6D, 0xB6, 0x51, 0x1B, 0x81, 0x26, 0x97, 0xAC,
  39197. 0x00, 0xFC, 0x76, 0x8D, 0x99, 0xD9, 0x35, 0x8E,
  39198. 0x4D, 0x3E, 0xC0, 0xC1, 0x0E, 0x8D, 0x9B, 0xE5,
  39199. 0x79, 0xF3, 0xC7, 0xA0, 0xA4, 0xA6, 0xA2, 0xE9,
  39200. 0x8B, 0xCD, 0x36, 0x79, 0x76, 0xF1, 0x6A, 0xEE,
  39201. 0xCF, 0x91, 0x8D, 0x91, 0xB1, 0xAF, 0xF2, 0xF5,
  39202. 0x43, 0xF6, 0xB2, 0x3A, 0x39, 0x9F, 0xBF, 0xDE,
  39203. 0x16, 0x03, 0x52, 0x18, 0x62, 0x93, 0xB5, 0x09,
  39204. 0xC4, 0xEE, 0x27, 0x9C, 0x56, 0x6F, 0x0C, 0x1C,
  39205. 0x12, 0x42, 0xF0, 0x34, 0xBD, 0x44, 0x52, 0x4C,
  39206. 0x32, 0x7E, 0x64, 0xDF, 0x78, 0x16, 0xD9, 0x9E,
  39207. 0xD7, 0x8A, 0x11, 0x33, 0x65, 0x42, 0xEC, 0x36,
  39208. 0x07, 0xEE, 0x3F, 0x19, 0x97, 0x9B, 0x92, 0x9D,
  39209. 0x3A, 0xE4, 0x98, 0x83, 0xDB, 0x0C, 0x85, 0x39,
  39210. 0xFA, 0x8D, 0x73, 0xF5, 0xBF, 0xE0, 0x75, 0x40,
  39211. 0x50, 0x9B, 0xF2, 0xE6, 0xB6, 0xA5, 0x33, 0xD0,
  39212. 0xC4, 0xD6, 0xAB, 0xFF, 0x16, 0xDE, 0x30, 0x9C,
  39213. 0x68, 0x90, 0xE0, 0x5E, 0xD3, 0xD5, 0xA9, 0xB0,
  39214. 0xD9, 0x6B, 0x0A, 0x43, 0x45, 0x9A, 0x3D, 0xE8,
  39215. 0xB6, 0x66, 0xE4, 0x57, 0x05, 0x8E, 0x5B, 0x72,
  39216. 0xFE, 0x50, 0x44, 0x8C, 0xE4, 0x68, 0x43, 0x51,
  39217. 0x0D, 0x9A, 0xD3, 0x36, 0xA9, 0xC7, 0xF6, 0xCF,
  39218. 0x6D, 0x2C, 0x95, 0x46, 0x98, 0x6D, 0x9E, 0x78,
  39219. 0x90, 0x87, 0x19, 0x64, 0xD5, 0xDE, 0x1D, 0x9B,
  39220. 0x37, 0x4E, 0x52, 0xF5, 0x14, 0xAA, 0xEE, 0x31,
  39221. 0x83, 0x55, 0x7C, 0x38, 0x0F, 0xB3, 0xF6, 0xF2,
  39222. 0x1C, 0x60, 0x71, 0x68, 0x1F, 0x06, 0xBD, 0x99,
  39223. 0xFD, 0x42, 0x12, 0x54, 0x3E, 0xBA, 0x4B, 0x60,
  39224. 0xFB, 0xFB, 0x51, 0x4D, 0x02, 0xCE, 0xE5, 0x9E,
  39225. 0x59, 0xB2, 0xE6, 0x98, 0x67, 0xBB, 0xAB, 0xC8,
  39226. 0x08, 0xE4, 0x08, 0x0D, 0xF5, 0x3B, 0x47, 0x78,
  39227. 0x39, 0x24, 0x56, 0x80, 0xF0, 0x6A, 0x1D, 0x33,
  39228. 0x05, 0x5F, 0xF2, 0xA2, 0x38, 0xAD, 0xDF, 0x5C,
  39229. 0xC5, 0xEA, 0x9C, 0xC7, 0x0A, 0x1B, 0x5B, 0x43,
  39230. 0xE9, 0x59, 0x3D, 0x68, 0x00, 0x23, 0x32, 0x5D,
  39231. 0x25, 0xFD, 0xA7, 0xCA, 0xDA, 0xA1, 0xFD, 0x22,
  39232. 0x4E, 0x34, 0x96, 0xE7, 0x0D, 0xFF, 0x89, 0x3B,
  39233. 0xA6, 0x56, 0x0D, 0x11, 0x13, 0xA6, 0x9D, 0x3B,
  39234. 0xBC, 0x12, 0x97, 0x9A, 0x2B, 0xAA, 0xE9, 0xE2,
  39235. 0xCF, 0xD2, 0xD3, 0xEF, 0x95, 0xFC, 0x40, 0x80,
  39236. 0x94, 0x48, 0x80, 0x5A, 0x3F, 0x4A, 0xD2, 0xB5,
  39237. 0x7D, 0x61, 0xA2, 0x26, 0x7B, 0xDC, 0x32, 0xCB,
  39238. 0x84, 0x2E, 0x9B, 0x29, 0x63, 0x45, 0x74, 0x0D,
  39239. 0x85, 0x54, 0xB2, 0x16, 0x77, 0x9B, 0x47, 0x51,
  39240. 0x63, 0x33, 0xE9, 0x1A, 0x52, 0x9D, 0xEB, 0x26,
  39241. 0x06, 0x7F, 0x97, 0xA0, 0xA1, 0xAA, 0x07, 0x0F,
  39242. 0x1E, 0x23, 0xAB, 0xCC, 0xD5, 0x0F, 0x3E, 0x88,
  39243. 0xAA, 0xC3, 0xED, 0x06, 0x25, 0x3A, 0x4A, 0x62,
  39244. 0x85, 0x9F, 0xA7, 0xD3, 0xF5, 0x1C, 0x9A, 0xCC,
  39245. 0x52, 0x87, 0x9F, 0xB8, 0xC7, 0xDD, 0xF1, 0x50,
  39246. 0x66, 0x70, 0xAC, 0xC6, 0x2C, 0x2E, 0x8C, 0xC9,
  39247. 0xD9, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39248. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39249. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39250. 0x00, 0x00, 0x00, 0x06, 0x0D, 0x13, 0x1D, 0x20,
  39251. 0x27, 0x2C, 0x32
  39252. };
  39253. #endif
  39254. byte sig[DILITHIUM_MAX_SIG_SIZE];
  39255. word32 sigLen;
  39256. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39257. ExpectNotNull(key);
  39258. if (key != NULL) {
  39259. XMEMSET(key, 0, sizeof(*key));
  39260. }
  39261. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  39262. #ifndef WOLFSSL_NO_ML_DSA_44
  39263. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  39264. ExpectIntEQ(wc_dilithium_import_private(sk_44, (word32)sizeof(sk_44), key),
  39265. 0);
  39266. sigLen = PARAMS_ML_DSA_44_SIG_SIZE;
  39267. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_44, (word32)sizeof(msg_44),
  39268. sig, &sigLen, key, rnd_44), 0);
  39269. ExpectIntEQ(sigLen, PARAMS_ML_DSA_44_SIG_SIZE);
  39270. ExpectIntEQ(XMEMCMP(sig, sig_44, sizeof(sig_44)), 0);
  39271. #endif
  39272. #ifndef WOLFSSL_NO_ML_DSA_65
  39273. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  39274. ExpectIntEQ(wc_dilithium_import_private(sk_65, (word32)sizeof(sk_65), key),
  39275. 0);
  39276. sigLen = PARAMS_ML_DSA_65_SIG_SIZE;
  39277. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_65, (word32)sizeof(msg_65),
  39278. sig, &sigLen, key, rnd_65), 0);
  39279. ExpectIntEQ(sigLen, PARAMS_ML_DSA_65_SIG_SIZE);
  39280. ExpectIntEQ(XMEMCMP(sig, sig_65, sizeof(sig_65)), 0);
  39281. #endif
  39282. #ifndef WOLFSSL_NO_ML_DSA_87
  39283. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  39284. ExpectIntEQ(wc_dilithium_import_private(sk_87, (word32)sizeof(sk_87), key),
  39285. 0);
  39286. sigLen = PARAMS_ML_DSA_87_SIG_SIZE;
  39287. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_87, (word32)sizeof(msg_87),
  39288. sig, &sigLen, key, rnd_87), 0);
  39289. ExpectIntEQ(sigLen, PARAMS_ML_DSA_87_SIG_SIZE);
  39290. ExpectIntEQ(XMEMCMP(sig, sig_87, sizeof(sig_87)), 0);
  39291. #endif
  39292. wc_dilithium_free(key);
  39293. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39294. #endif
  39295. return EXPECT_RESULT();
  39296. }
  39297. static int test_wc_dilithium_verify_kats(void)
  39298. {
  39299. EXPECT_DECLS;
  39300. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  39301. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  39302. dilithium_key* key;
  39303. int res;
  39304. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39305. #ifndef WOLFSSL_NO_ML_DSA_44
  39306. static const byte pk_44[] = {
  39307. 0x09, 0xB4, 0x88, 0x7D, 0x97, 0xBC, 0xF6, 0x37,
  39308. 0x9C, 0xC5, 0x9B, 0x61, 0x62, 0xC1, 0xE8, 0xBF,
  39309. 0x05, 0x60, 0xBF, 0x44, 0xD6, 0x18, 0x09, 0x17,
  39310. 0x0E, 0x6E, 0x28, 0xF7, 0x06, 0x69, 0xA3, 0xE9,
  39311. 0x49, 0x64, 0x38, 0xE8, 0x91, 0x57, 0x35, 0xAD,
  39312. 0xAE, 0xB4, 0x45, 0xCF, 0xDB, 0x7D, 0x89, 0xB3,
  39313. 0x8C, 0x04, 0x8F, 0x4C, 0x3E, 0x00, 0x58, 0x15,
  39314. 0x14, 0xC5, 0xFD, 0x19, 0x8B, 0x2D, 0x17, 0x39,
  39315. 0xE8, 0x83, 0xB8, 0x78, 0xD5, 0x6B, 0xB4, 0x12,
  39316. 0x64, 0xBE, 0x41, 0xD3, 0xD5, 0x15, 0x65, 0xE2,
  39317. 0xE9, 0xCA, 0xE3, 0x31, 0x84, 0xA8, 0x99, 0xF6,
  39318. 0x2D, 0xD5, 0x7D, 0x07, 0x40, 0x0E, 0x98, 0xE5,
  39319. 0x86, 0x87, 0xA9, 0xB2, 0x2F, 0xA3, 0x17, 0xEE,
  39320. 0xD1, 0x34, 0xCA, 0x72, 0x14, 0xBF, 0xF0, 0x21,
  39321. 0xDD, 0x21, 0x62, 0xB1, 0x83, 0x09, 0x1D, 0x15,
  39322. 0xF2, 0x63, 0xB7, 0x29, 0x82, 0x14, 0x42, 0x3C,
  39323. 0x6B, 0xB6, 0x96, 0xD7, 0x5C, 0x20, 0xD9, 0xEA,
  39324. 0xCD, 0x0A, 0x03, 0xE4, 0x26, 0x2C, 0x4B, 0x08,
  39325. 0xBE, 0x39, 0xFA, 0x21, 0x54, 0xBD, 0x6E, 0x50,
  39326. 0x25, 0xFF, 0x79, 0x1E, 0x88, 0x5F, 0x22, 0x26,
  39327. 0xE3, 0xCF, 0x48, 0xF7, 0xB5, 0xEB, 0x04, 0xFB,
  39328. 0xE9, 0xEC, 0xF7, 0x5B, 0x19, 0xE1, 0xD1, 0x5C,
  39329. 0x30, 0x5E, 0x92, 0x26, 0x0A, 0xB0, 0xD6, 0xAE,
  39330. 0x7D, 0xBA, 0x7B, 0xBE, 0x73, 0xB6, 0xBC, 0x18,
  39331. 0x1C, 0xF9, 0x33, 0x84, 0x0C, 0xC1, 0x0A, 0x00,
  39332. 0x05, 0x02, 0x28, 0xFA, 0x46, 0xA2, 0x63, 0x6D,
  39333. 0xD9, 0xA9, 0x09, 0x47, 0xE9, 0xF1, 0x3A, 0x93,
  39334. 0xEF, 0x4C, 0x62, 0xBE, 0x37, 0x4D, 0x76, 0xD1,
  39335. 0xFD, 0xBB, 0xC5, 0xD8, 0xB5, 0x5E, 0x72, 0x9F,
  39336. 0xA5, 0x86, 0x65, 0xAA, 0x07, 0xB9, 0x0C, 0x8C,
  39337. 0xDD, 0xD6, 0x1C, 0x56, 0x6B, 0x0D, 0x7E, 0xD6,
  39338. 0x57, 0x70, 0x49, 0x2E, 0xA0, 0x71, 0x3E, 0x1E,
  39339. 0xD4, 0x6A, 0xC7, 0xAD, 0x15, 0x03, 0xC5, 0x6D,
  39340. 0x90, 0x52, 0xD2, 0xC9, 0x4D, 0x49, 0xE4, 0x41,
  39341. 0x6A, 0xC9, 0x2B, 0x70, 0x39, 0x6F, 0x76, 0xF6,
  39342. 0xFB, 0x48, 0x10, 0x45, 0x68, 0x17, 0x25, 0xA6,
  39343. 0x8C, 0xB3, 0x56, 0x37, 0x7F, 0xB2, 0x31, 0xAB,
  39344. 0x8F, 0x3E, 0xB9, 0xA4, 0x98, 0x2F, 0xFF, 0x18,
  39345. 0x36, 0x47, 0x3B, 0xCB, 0xDA, 0xB6, 0x87, 0x2D,
  39346. 0x22, 0x94, 0x67, 0xEF, 0xB9, 0x36, 0x62, 0x61,
  39347. 0xFE, 0xB1, 0x48, 0xBA, 0x9B, 0x7D, 0xB9, 0xC4,
  39348. 0xFE, 0x0B, 0xB8, 0x86, 0x12, 0xAB, 0xB8, 0xFD,
  39349. 0x61, 0x09, 0x6F, 0x18, 0x19, 0x60, 0x4D, 0x55,
  39350. 0xDF, 0x60, 0x20, 0x46, 0x4D, 0x3F, 0x09, 0x2C,
  39351. 0xFC, 0xA5, 0x98, 0x12, 0x08, 0x22, 0x18, 0x56,
  39352. 0x68, 0x99, 0xA5, 0x6A, 0x3C, 0x63, 0x3C, 0xC8,
  39353. 0x1F, 0x88, 0xAD, 0xB2, 0xE1, 0x41, 0x4E, 0xF3,
  39354. 0x85, 0x0D, 0x10, 0xBF, 0x5A, 0x77, 0xAC, 0xE7,
  39355. 0x24, 0xD6, 0xC1, 0xF3, 0x88, 0x92, 0x87, 0x44,
  39356. 0xB3, 0xE5, 0x42, 0xAE, 0x49, 0x1C, 0xD5, 0x6A,
  39357. 0x64, 0x21, 0x3F, 0x1D, 0x3C, 0xC9, 0x0B, 0x29,
  39358. 0x10, 0x5F, 0x43, 0xD2, 0x37, 0xC8, 0x3D, 0x5F,
  39359. 0xB8, 0x29, 0x32, 0x5C, 0x83, 0xE6, 0x54, 0x57,
  39360. 0x77, 0x76, 0x39, 0x2F, 0x85, 0x36, 0xAA, 0x9D,
  39361. 0xAE, 0x87, 0x24, 0x07, 0xAB, 0xAA, 0xA9, 0xAC,
  39362. 0xC2, 0x2A, 0x68, 0x12, 0xCE, 0xA7, 0x4C, 0x0B,
  39363. 0xA6, 0x7E, 0xAF, 0x4A, 0x41, 0x01, 0x52, 0x97,
  39364. 0x5E, 0x9A, 0x83, 0xEE, 0x44, 0x69, 0x29, 0x53,
  39365. 0x17, 0xBE, 0xD1, 0x05, 0x51, 0xBA, 0x32, 0xE6,
  39366. 0x5A, 0xFC, 0x8C, 0x8E, 0x68, 0xDD, 0x55, 0x42,
  39367. 0x0C, 0x50, 0x2D, 0x93, 0x7D, 0xAD, 0xD2, 0xEF,
  39368. 0xA2, 0xCB, 0xFD, 0x1F, 0x73, 0x9F, 0xC0, 0xAB,
  39369. 0x2B, 0x26, 0x54, 0xFA, 0xE0, 0x8C, 0x0C, 0x7F,
  39370. 0x8E, 0xDD, 0x43, 0xCF, 0x9F, 0xF0, 0xB0, 0x1D,
  39371. 0x98, 0x4D, 0x49, 0x18, 0x52, 0xA3, 0x72, 0xE9,
  39372. 0xFE, 0xFD, 0xCC, 0x1B, 0xC1, 0x6C, 0xDB, 0x52,
  39373. 0x39, 0xAE, 0x10, 0x01, 0x15, 0x5F, 0x89, 0x56,
  39374. 0x30, 0x51, 0xCE, 0x47, 0x99, 0x6C, 0x5A, 0xEE,
  39375. 0xB2, 0x19, 0x0E, 0xA1, 0x8F, 0x7F, 0x73, 0x40,
  39376. 0x42, 0xDE, 0x68, 0xE9, 0x88, 0x36, 0x7D, 0x89,
  39377. 0x35, 0x5D, 0x9D, 0x83, 0x77, 0xBA, 0xF9, 0x64,
  39378. 0x79, 0x78, 0xEB, 0x2E, 0x49, 0x2A, 0xD0, 0x21,
  39379. 0xC5, 0x69, 0xAE, 0x8B, 0xA6, 0x9B, 0x15, 0xF1,
  39380. 0xFC, 0xF7, 0x03, 0x9A, 0x7E, 0x64, 0xAF, 0x10,
  39381. 0xAB, 0xF3, 0xEA, 0x45, 0xB7, 0x22, 0x2F, 0x96,
  39382. 0x59, 0xE3, 0x33, 0x73, 0x37, 0x2E, 0x1D, 0xB1,
  39383. 0x86, 0xD2, 0xC2, 0xA0, 0xD7, 0x54, 0x51, 0xC4,
  39384. 0x78, 0xAE, 0xF3, 0x3E, 0x59, 0x49, 0xF2, 0x40,
  39385. 0x04, 0x0C, 0x2A, 0xFC, 0x44, 0xB1, 0xD3, 0xA0,
  39386. 0x2A, 0x6D, 0x2F, 0x87, 0x90, 0x2A, 0x28, 0x0E,
  39387. 0x27, 0xA2, 0x0D, 0x4E, 0x57, 0xF8, 0x89, 0x66,
  39388. 0x27, 0x00, 0xDB, 0x8A, 0x9D, 0x24, 0x99, 0x57,
  39389. 0xA7, 0xDB, 0x43, 0x7C, 0xD4, 0x80, 0xDD, 0xC0,
  39390. 0x58, 0x84, 0xFB, 0x23, 0xF8, 0x68, 0x26, 0x8E,
  39391. 0xAC, 0xE3, 0x4E, 0xED, 0x27, 0x4A, 0x92, 0x7D,
  39392. 0x9D, 0x84, 0xF1, 0xEA, 0x57, 0xEA, 0xB1, 0xA8,
  39393. 0x13, 0xB5, 0xE6, 0xAA, 0xBE, 0x9E, 0xD2, 0x61,
  39394. 0x0B, 0xC6, 0xF7, 0x2E, 0x32, 0x0C, 0xDE, 0xC4,
  39395. 0xF9, 0x95, 0x23, 0xF9, 0x3F, 0xA4, 0x48, 0xDC,
  39396. 0x1F, 0xBB, 0xDD, 0x25, 0x9B, 0x10, 0x2F, 0x5D,
  39397. 0xC9, 0x95, 0x5A, 0xFA, 0x0C, 0x41, 0x60, 0x4D,
  39398. 0x83, 0xDD, 0x1C, 0x2D, 0x22, 0x95, 0xEF, 0x44,
  39399. 0x61, 0x45, 0x6B, 0xAE, 0x86, 0x90, 0x5C, 0x4C,
  39400. 0x30, 0xD8, 0xA9, 0xFA, 0x48, 0xC9, 0x0F, 0x37,
  39401. 0xA1, 0x9C, 0x41, 0xA2, 0xD5, 0x98, 0x8F, 0x13,
  39402. 0xD5, 0x13, 0x44, 0xEC, 0x30, 0xA4, 0xA4, 0x62,
  39403. 0x19, 0xFE, 0x84, 0x11, 0x37, 0xD5, 0xAA, 0x1F,
  39404. 0x51, 0xE6, 0xC4, 0x44, 0x16, 0x8A, 0xF3, 0x98,
  39405. 0x90, 0xB6, 0xFA, 0x40, 0x0D, 0x67, 0xF4, 0x80,
  39406. 0x6F, 0x5B, 0xBD, 0x44, 0x47, 0x03, 0x07, 0x4A,
  39407. 0x7A, 0x11, 0x39, 0xC7, 0x17, 0x46, 0xD7, 0xC4,
  39408. 0xCE, 0xB3, 0xC9, 0x11, 0xF5, 0x25, 0x7E, 0x3E,
  39409. 0x53, 0xEB, 0xFA, 0x5A, 0xA8, 0xF2, 0x27, 0x80,
  39410. 0x9D, 0x44, 0xEE, 0x7D, 0xE1, 0x3C, 0x02, 0x79,
  39411. 0x24, 0xDD, 0x60, 0x15, 0x3B, 0x30, 0xAA, 0x76,
  39412. 0xDD, 0x96, 0xA7, 0xC5, 0xAC, 0xC5, 0x9B, 0x62,
  39413. 0x79, 0x19, 0x50, 0x7B, 0xF1, 0x42, 0x57, 0xAE,
  39414. 0x7A, 0x26, 0x24, 0x3C, 0x16, 0x83, 0xB2, 0x8D,
  39415. 0x1B, 0x14, 0xB5, 0x01, 0xAD, 0x05, 0x9B, 0x4D,
  39416. 0x52, 0x2A, 0x57, 0x99, 0x1E, 0x55, 0x39, 0xCE,
  39417. 0xF1, 0x8C, 0xEB, 0x5C, 0x26, 0xD6, 0x60, 0xB8,
  39418. 0x82, 0x24, 0x54, 0xC9, 0xC4, 0x2A, 0x95, 0xE6,
  39419. 0xF7, 0x2B, 0x84, 0xF7, 0x8A, 0xB9, 0x9F, 0x51,
  39420. 0xEC, 0x49, 0x78, 0x9F, 0x9D, 0xB4, 0xC1, 0x28,
  39421. 0xB0, 0x31, 0x8F, 0xFF, 0xC8, 0x2D, 0x95, 0xCA,
  39422. 0xD2, 0x77, 0xF1, 0x1E, 0x14, 0xF1, 0xEF, 0x87,
  39423. 0x14, 0x14, 0x88, 0x11, 0x22, 0xA9, 0xB1, 0x1B,
  39424. 0xDF, 0xAE, 0x4A, 0x7A, 0xBC, 0x8E, 0x75, 0x75,
  39425. 0x5A, 0xB1, 0x37, 0x41, 0xDF, 0xAC, 0xD6, 0x64,
  39426. 0x29, 0x3D, 0x1A, 0x32, 0x6B, 0xF5, 0xED, 0x5A,
  39427. 0xBB, 0xB1, 0x53, 0xEB, 0xE6, 0x99, 0x6D, 0xD6,
  39428. 0x22, 0xF0, 0xA8, 0xCB, 0x47, 0x39, 0x69, 0xA5,
  39429. 0x03, 0x66, 0xBD, 0x0B, 0x01, 0xC5, 0xC7, 0x3A,
  39430. 0x89, 0x2B, 0x8E, 0x26, 0xCE, 0x08, 0xF7, 0x5F,
  39431. 0xF8, 0x01, 0xB6, 0xDE, 0xF0, 0x41, 0xE1, 0x71,
  39432. 0x3B, 0xE6, 0xDF, 0x0E, 0xFB, 0x51, 0x58, 0x7B,
  39433. 0xE5, 0xFB, 0xEA, 0x72, 0x7E, 0x00, 0xD7, 0x17,
  39434. 0x64, 0x7D, 0xD5, 0x39, 0x07, 0x9D, 0xE1, 0x8A,
  39435. 0xE7, 0xBE, 0xD1, 0x2B, 0x91, 0xAF, 0x8D, 0xBB,
  39436. 0x1B, 0x8B, 0x32, 0xD2, 0x86, 0x0B, 0xAF, 0x40,
  39437. 0xAF, 0x8A, 0x0B, 0xBF, 0xE0, 0x28, 0x87, 0xEB,
  39438. 0x5D, 0xBE, 0x7A, 0xB1, 0xAF, 0xC4, 0x1D, 0xA7,
  39439. 0x9B, 0x01, 0x6A, 0xA1, 0x6E, 0xDA, 0x28, 0x13,
  39440. 0x21, 0xCA, 0xA5, 0xDA, 0x64, 0x4F, 0xD8, 0x65,
  39441. 0x8A, 0x7B, 0x70, 0x21, 0x81, 0x00, 0x14, 0x31,
  39442. 0x56, 0x0D, 0xD6, 0x3C, 0xB2, 0x1E, 0x5F, 0xF7,
  39443. 0x5C, 0x3F, 0x72, 0x50, 0x45, 0x6B, 0xE0, 0x8C,
  39444. 0x0D, 0x5E, 0x34, 0xC3, 0xBD, 0xE2, 0xF6, 0x06,
  39445. 0xA2, 0xBF, 0x34, 0x17, 0x76, 0x8D, 0x24, 0xB2,
  39446. 0x37, 0x39, 0xEA, 0x86, 0xCB, 0xEF, 0xDD, 0xA3,
  39447. 0x43, 0x88, 0xBC, 0x1F, 0x91, 0x8F, 0x95, 0x1E,
  39448. 0x15, 0xE4, 0x3B, 0x13, 0x85, 0xA7, 0xBC, 0xC5,
  39449. 0x59, 0xF9, 0x49, 0x2C, 0x72, 0x13, 0xA1, 0x42,
  39450. 0x27, 0xE0, 0x93, 0xE9, 0x29, 0xF3, 0x2D, 0x1E,
  39451. 0xFB, 0xE7, 0xF1, 0xEE, 0x57, 0xC4, 0x9C, 0x90,
  39452. 0x55, 0x62, 0x3E, 0xA4, 0x2E, 0xC6, 0xC7, 0x9D,
  39453. 0x7F, 0xCE, 0x71, 0xFA, 0x74, 0x76, 0x07, 0x56,
  39454. 0x6D, 0xDA, 0x69, 0xF6, 0x9D, 0xAF, 0x68, 0x11,
  39455. 0x59, 0x19, 0xC6, 0x32, 0x2E, 0xBB, 0x42, 0xC8,
  39456. 0xC0, 0x89, 0x33, 0x8C, 0x9E, 0x0C, 0x53, 0x56,
  39457. 0x5B, 0xCB, 0xE7, 0x2F, 0xBE, 0x47, 0x26, 0x68,
  39458. 0x7B, 0x07, 0x87, 0x07, 0x18, 0x06, 0xC5, 0xA6,
  39459. 0xC1, 0x49, 0xC8, 0x2B, 0x66, 0x8A, 0xA6, 0x4A,
  39460. 0x7B, 0xA0, 0xCC, 0xC1, 0xCC, 0x49, 0xA1, 0xEE,
  39461. 0xE9, 0x45, 0x3D, 0x04, 0x33, 0x6E, 0x5D, 0xC8,
  39462. 0x11, 0xE0, 0x38, 0x92, 0xF7, 0xF4, 0x66, 0x88,
  39463. 0xEC, 0xEF, 0xD0, 0x4F, 0x18, 0x76, 0xF7, 0x11,
  39464. 0x17, 0x12, 0xB5, 0x95, 0xED, 0x62, 0xDA, 0x00,
  39465. 0x67, 0x8F, 0x9E, 0x37, 0x86, 0xB5, 0xC1, 0xA5,
  39466. 0x09, 0x5B, 0xE8, 0x71, 0x0D, 0xCF, 0xA4, 0x16,
  39467. 0x52, 0x56, 0x50, 0x9E, 0x00, 0x14, 0x3A, 0x6F,
  39468. 0x11, 0x72, 0xFA, 0xBE, 0x8B, 0xF2, 0x1E, 0x5F,
  39469. 0xCE, 0x7C, 0x79, 0xC1, 0xA4, 0x4B, 0x4B, 0x15,
  39470. 0x25, 0xA0, 0x76, 0xFF, 0xB8, 0xDD, 0x90, 0x66
  39471. };
  39472. static const byte msg_44[] = {
  39473. 0x3A, 0xFD, 0x7F, 0xF8, 0xCA, 0xD3, 0xAC, 0xBD,
  39474. 0xF9, 0x77, 0x31, 0x26, 0x1C, 0x7A, 0x1C, 0x96,
  39475. 0x9D, 0x50, 0x16, 0xF1, 0x7D, 0x3E, 0x7F, 0x83,
  39476. 0xD2, 0x44, 0x1A, 0xF9, 0x01, 0x4B, 0x63, 0x47,
  39477. 0x7B, 0x14, 0xA6, 0x41, 0x31, 0x50, 0xFA, 0xD7,
  39478. 0xC8, 0x44, 0x39, 0xBC, 0x88, 0x66, 0x2C, 0x5E,
  39479. 0x93, 0x1F, 0x06, 0xB9, 0x51, 0x41, 0x90, 0xE1,
  39480. 0x3F, 0xB0, 0x49, 0xC4, 0xAB, 0x74, 0x01, 0x32,
  39481. 0x33, 0xB9, 0x8D, 0x48, 0xD9, 0xAF, 0xB6, 0xA3,
  39482. 0x0A, 0x67, 0x33, 0x0E, 0x1F, 0xBE, 0x33, 0x1B,
  39483. 0x09, 0xC5, 0x6D, 0x03, 0x7E, 0x97, 0x01, 0x08,
  39484. 0x5D, 0x80, 0xF1, 0xE7, 0xF4, 0x04, 0x3E, 0xFB,
  39485. 0x53, 0x58, 0x7A, 0xBB, 0x82, 0x36, 0x24, 0x01,
  39486. 0x23, 0x84, 0x51, 0x52, 0x49, 0xEE, 0x61, 0x30,
  39487. 0x97, 0x3D, 0xC9, 0xEA, 0x6F, 0x55, 0x8B, 0xAE,
  39488. 0x75, 0x10, 0x7E, 0xFD, 0xB1, 0xD9, 0x28, 0x5B
  39489. };
  39490. static const byte sig_44[] = {
  39491. 0x4A, 0x2B, 0x16, 0xCD, 0xB5, 0x52, 0xF9, 0x29,
  39492. 0x7F, 0x8E, 0x39, 0x1A, 0xD8, 0xF5, 0xAD, 0xC8,
  39493. 0xCC, 0x5D, 0x2C, 0x56, 0xC4, 0x6B, 0x80, 0x0F,
  39494. 0x9B, 0x3E, 0xE4, 0xBB, 0xD2, 0xF2, 0xE8, 0xA8,
  39495. 0x9D, 0x59, 0x9D, 0x7B, 0x5C, 0xC2, 0xD8, 0x8C,
  39496. 0x80, 0xF2, 0x71, 0x85, 0x9B, 0xBC, 0x83, 0x04,
  39497. 0x3E, 0xC4, 0xE5, 0x48, 0x12, 0xF5, 0x93, 0x6B,
  39498. 0x44, 0x6C, 0x95, 0x13, 0xC8, 0x55, 0x28, 0x9C,
  39499. 0x94, 0xB1, 0x15, 0x51, 0xA0, 0xC7, 0x65, 0x3E,
  39500. 0x7B, 0xA7, 0x4F, 0xFB, 0x6F, 0x72, 0xD4, 0x65,
  39501. 0x2C, 0x91, 0xD3, 0x8D, 0xD1, 0xF9, 0x0D, 0xFE,
  39502. 0x44, 0x39, 0xBC, 0x21, 0xCA, 0x53, 0xE0, 0xCC,
  39503. 0x7A, 0x7A, 0xA5, 0xB8, 0x75, 0xA5, 0xB9, 0xBA,
  39504. 0x42, 0x36, 0x6E, 0xB8, 0xEC, 0xBA, 0x24, 0x36,
  39505. 0xDA, 0xF0, 0x8A, 0x91, 0x97, 0x8D, 0xD0, 0x93,
  39506. 0xF2, 0x0F, 0x1E, 0xFB, 0x6B, 0x0B, 0xCB, 0x90,
  39507. 0xDA, 0x99, 0xCC, 0xA0, 0x5E, 0x8F, 0x6F, 0x82,
  39508. 0xB8, 0x6D, 0x3C, 0x6E, 0xE2, 0x4B, 0xA5, 0xD5,
  39509. 0x0A, 0xEA, 0x10, 0xB2, 0x30, 0x7F, 0x57, 0xF8,
  39510. 0x9E, 0xD7, 0x8D, 0xB4, 0xA7, 0x4F, 0xBB, 0xF6,
  39511. 0xEB, 0x33, 0x2A, 0xFB, 0x08, 0xD0, 0x74, 0xAC,
  39512. 0xF0, 0xDE, 0x5C, 0xD7, 0xFE, 0xC1, 0x2F, 0x76,
  39513. 0xF3, 0xAB, 0x61, 0x9C, 0x81, 0x5B, 0x9E, 0xDD,
  39514. 0x28, 0x7E, 0xAD, 0x67, 0xF0, 0x4F, 0x14, 0x79,
  39515. 0x7F, 0x8D, 0xCF, 0x2C, 0xDE, 0x9A, 0x87, 0x53,
  39516. 0xB5, 0xAD, 0x0A, 0xFA, 0x12, 0x87, 0x41, 0x97,
  39517. 0xD1, 0x74, 0x40, 0x92, 0x87, 0x25, 0x21, 0xE8,
  39518. 0x68, 0xAF, 0x9E, 0x64, 0x45, 0x23, 0x73, 0xFE,
  39519. 0xB6, 0xFE, 0x25, 0xD5, 0x27, 0x3D, 0x63, 0xC0,
  39520. 0xEB, 0xD6, 0xD3, 0xB1, 0x02, 0x8C, 0x1C, 0xD0,
  39521. 0x6A, 0xF3, 0x2C, 0xEC, 0xA2, 0x62, 0x13, 0x10,
  39522. 0x83, 0x7C, 0x72, 0x78, 0x8C, 0x8A, 0xDA, 0xB5,
  39523. 0xA0, 0xF0, 0x38, 0x17, 0x12, 0x8E, 0xB7, 0xB7,
  39524. 0x66, 0xFA, 0x81, 0x2C, 0x69, 0x6C, 0xF8, 0x86,
  39525. 0xF0, 0x0A, 0x10, 0x44, 0xCD, 0xD0, 0x6B, 0xB2,
  39526. 0x8C, 0xB2, 0xE5, 0x78, 0x0C, 0x8D, 0x8C, 0xC7,
  39527. 0xE6, 0x0A, 0xB6, 0x99, 0xDD, 0x78, 0x66, 0x8B,
  39528. 0xE4, 0xFF, 0x9F, 0x46, 0x90, 0xC6, 0xFC, 0x98,
  39529. 0xAA, 0xC9, 0xC0, 0x2B, 0x66, 0xB9, 0xB9, 0x82,
  39530. 0x6A, 0x30, 0x61, 0xFD, 0x32, 0x22, 0xDA, 0x84,
  39531. 0x82, 0x66, 0x79, 0x60, 0xA3, 0x16, 0x52, 0xEE,
  39532. 0x88, 0xEB, 0x32, 0xB0, 0x46, 0x9A, 0xB7, 0x1C,
  39533. 0xAA, 0x25, 0x19, 0xF2, 0x3D, 0x1A, 0x24, 0x42,
  39534. 0xD5, 0xB1, 0x31, 0x62, 0x62, 0x13, 0x1D, 0xCE,
  39535. 0xC5, 0xF2, 0x87, 0xE3, 0x2F, 0xD3, 0x43, 0xFE,
  39536. 0xB4, 0x42, 0x9E, 0x54, 0x25, 0x8D, 0x69, 0x0D,
  39537. 0x9D, 0x20, 0xA1, 0x0A, 0xBD, 0x75, 0xA5, 0x36,
  39538. 0xDF, 0xF8, 0xCF, 0x1D, 0x6D, 0xDF, 0x19, 0x29,
  39539. 0x1E, 0x27, 0x49, 0xA7, 0xD1, 0x6E, 0xB9, 0x0A,
  39540. 0xB5, 0x09, 0x3B, 0xAD, 0x38, 0xE1, 0x16, 0xA8,
  39541. 0x6B, 0x73, 0x0E, 0x65, 0x57, 0x4C, 0x06, 0x8C,
  39542. 0x38, 0xBA, 0x94, 0x57, 0xC9, 0xD6, 0xD9, 0x13,
  39543. 0xEA, 0xFF, 0x57, 0xFE, 0x23, 0xBF, 0x3D, 0xD2,
  39544. 0x4D, 0x8C, 0xA5, 0x11, 0xEF, 0xA3, 0x76, 0xA5,
  39545. 0xDF, 0x08, 0x46, 0x70, 0x25, 0xFF, 0x51, 0xBE,
  39546. 0xAD, 0x3E, 0xDE, 0x0A, 0x84, 0xED, 0xC5, 0x32,
  39547. 0x16, 0x20, 0x99, 0x80, 0x61, 0xE8, 0xA1, 0xA7,
  39548. 0x3D, 0x67, 0xB7, 0x02, 0x1B, 0x81, 0x0C, 0x78,
  39549. 0x67, 0xFF, 0x39, 0x18, 0x7B, 0x59, 0xD4, 0x03,
  39550. 0xBF, 0x7C, 0x75, 0x06, 0x30, 0x0C, 0x73, 0x45,
  39551. 0xB1, 0xFE, 0x07, 0xC1, 0x12, 0x78, 0xB0, 0xAB,
  39552. 0xA6, 0x1D, 0xBB, 0x4F, 0x2B, 0x8C, 0x43, 0xE7,
  39553. 0x4F, 0xEF, 0xA5, 0x5E, 0xD5, 0x2C, 0x10, 0xA8,
  39554. 0xC4, 0x90, 0x88, 0x2B, 0xBF, 0xE3, 0xE3, 0xB3,
  39555. 0xCE, 0x57, 0x9E, 0x81, 0x16, 0xA9, 0xB6, 0x68,
  39556. 0x6C, 0x1A, 0x10, 0x0A, 0xA1, 0xF6, 0x59, 0x1F,
  39557. 0x19, 0x1F, 0x77, 0x2B, 0x5A, 0x5A, 0x50, 0xDD,
  39558. 0x6C, 0xC1, 0x55, 0xCB, 0x5A, 0x1B, 0xE5, 0xBA,
  39559. 0x12, 0x2E, 0x91, 0xF0, 0x44, 0x42, 0x01, 0x56,
  39560. 0xCD, 0x63, 0x08, 0x0F, 0x0A, 0x45, 0xD6, 0x62,
  39561. 0xE7, 0x6D, 0xD5, 0x7B, 0xD0, 0xF6, 0x89, 0xD0,
  39562. 0xB2, 0x99, 0x04, 0x2B, 0xFF, 0x48, 0x5E, 0x8A,
  39563. 0x38, 0x2D, 0x86, 0x5C, 0x26, 0xCD, 0x46, 0xB4,
  39564. 0xA5, 0x47, 0x28, 0xBD, 0x48, 0x45, 0x83, 0x62,
  39565. 0xD7, 0x9A, 0xC3, 0xEB, 0x75, 0x6F, 0xC6, 0xC5,
  39566. 0x18, 0xC9, 0xE2, 0xF0, 0xE7, 0xD5, 0xA3, 0x03,
  39567. 0xAF, 0x11, 0x59, 0xEE, 0x6D, 0xBE, 0x7D, 0xD5,
  39568. 0x6B, 0xA0, 0x71, 0x28, 0x57, 0xA6, 0x88, 0x36,
  39569. 0xC3, 0xC7, 0x8C, 0x6C, 0x9F, 0x74, 0x88, 0x57,
  39570. 0x28, 0x13, 0xC0, 0xF6, 0xA8, 0x14, 0x70, 0x9D,
  39571. 0x2B, 0xC1, 0x42, 0xFE, 0xF0, 0x25, 0x27, 0xCA,
  39572. 0xE7, 0x71, 0x23, 0x58, 0x37, 0x1C, 0x54, 0x26,
  39573. 0x52, 0x2C, 0xCC, 0x64, 0x30, 0x0C, 0x2C, 0xD9,
  39574. 0xFB, 0xE2, 0x0C, 0x65, 0x62, 0xE3, 0x48, 0x35,
  39575. 0x20, 0x5F, 0xCD, 0xD5, 0xA8, 0x98, 0x2C, 0x92,
  39576. 0x0B, 0xB4, 0x77, 0xFB, 0x88, 0x17, 0x02, 0x82,
  39577. 0x7B, 0x49, 0x11, 0x87, 0x13, 0x94, 0xC0, 0x6B,
  39578. 0x5F, 0xEC, 0xD0, 0xC7, 0x40, 0xAF, 0x7B, 0x27,
  39579. 0x63, 0x7B, 0xAC, 0x1A, 0x0C, 0xBC, 0xA5, 0x37,
  39580. 0xE4, 0x43, 0x3E, 0xA8, 0x47, 0x45, 0x4C, 0x69,
  39581. 0x38, 0x97, 0xA3, 0x2E, 0x4D, 0x18, 0x44, 0x19,
  39582. 0x54, 0x26, 0xA0, 0xC6, 0xAE, 0xD6, 0x74, 0x72,
  39583. 0xBD, 0x2C, 0x4E, 0xEE, 0x17, 0x9F, 0x3F, 0x60,
  39584. 0x84, 0xA3, 0x6A, 0x76, 0x89, 0xF4, 0xCB, 0x1F,
  39585. 0x8E, 0x5D, 0xB2, 0xDD, 0xE5, 0x4A, 0xCC, 0x06,
  39586. 0x66, 0xBA, 0x98, 0x41, 0x54, 0x31, 0xA4, 0xB2,
  39587. 0x02, 0xF4, 0x02, 0xFB, 0x1F, 0x1B, 0xCC, 0xDC,
  39588. 0x23, 0xBF, 0xF1, 0x31, 0x48, 0xC7, 0xB8, 0xF6,
  39589. 0x1F, 0xBF, 0x62, 0x43, 0xB2, 0x96, 0xA7, 0x8E,
  39590. 0xB6, 0x98, 0x18, 0x9D, 0xA9, 0x5B, 0xDA, 0x85,
  39591. 0xDB, 0xC1, 0x1D, 0x15, 0xFF, 0xDC, 0x6B, 0xF4,
  39592. 0x6C, 0x53, 0xF6, 0xE4, 0x72, 0xA8, 0x71, 0x40,
  39593. 0x1E, 0x9A, 0x9A, 0xB7, 0xF9, 0xFB, 0x46, 0x7E,
  39594. 0xB4, 0xEC, 0xB1, 0xF0, 0xDA, 0x7E, 0x63, 0xEE,
  39595. 0x86, 0x19, 0xCB, 0xC4, 0x86, 0xEB, 0xB0, 0xF2,
  39596. 0x12, 0x0A, 0x78, 0x11, 0xBF, 0xB0, 0x55, 0x7D,
  39597. 0x13, 0x93, 0x05, 0x74, 0x29, 0x7C, 0x94, 0x64,
  39598. 0xFC, 0x59, 0x5B, 0x27, 0x56, 0x9A, 0xDF, 0x5F,
  39599. 0x4A, 0x8D, 0xF6, 0x69, 0xC9, 0xEE, 0xA0, 0xA2,
  39600. 0x50, 0xF4, 0xD2, 0x2C, 0x2E, 0x8C, 0x64, 0x1B,
  39601. 0xA3, 0x90, 0x2B, 0xA8, 0x08, 0x00, 0x48, 0x99,
  39602. 0x65, 0xF1, 0x1A, 0xF1, 0xE1, 0xA8, 0x57, 0x17,
  39603. 0xC6, 0x24, 0xE7, 0x42, 0xF1, 0x61, 0x55, 0x08,
  39604. 0x19, 0xD1, 0xF0, 0x37, 0x2C, 0x5C, 0xAE, 0x8B,
  39605. 0xC6, 0x2B, 0x54, 0x9E, 0xFE, 0x87, 0x44, 0x61,
  39606. 0x08, 0x0D, 0x06, 0x34, 0x6E, 0x1F, 0xA6, 0xF0,
  39607. 0x15, 0x14, 0xFB, 0xEC, 0xCB, 0x06, 0xE3, 0x4E,
  39608. 0xE2, 0x71, 0xA0, 0xF0, 0x03, 0x17, 0x90, 0xBD,
  39609. 0xAB, 0xE0, 0xF0, 0x2B, 0xBA, 0x4A, 0xEA, 0x4B,
  39610. 0x73, 0x97, 0xFE, 0x33, 0x33, 0xEB, 0x81, 0x21,
  39611. 0x82, 0x07, 0x57, 0x28, 0x1F, 0x96, 0xA5, 0x83,
  39612. 0x1F, 0x9E, 0x49, 0x03, 0x66, 0x54, 0x9D, 0x16,
  39613. 0x76, 0x3F, 0xF1, 0x9F, 0xF7, 0x73, 0x58, 0x0E,
  39614. 0xD5, 0xE3, 0xE1, 0xE2, 0xAA, 0x3E, 0x38, 0xF8,
  39615. 0x84, 0x74, 0xDE, 0x6D, 0x9B, 0xA6, 0x99, 0x4F,
  39616. 0x8E, 0x62, 0x91, 0x60, 0x48, 0x8C, 0xB4, 0xCD,
  39617. 0x5B, 0x87, 0x8C, 0xDA, 0x37, 0xAA, 0xEC, 0x9B,
  39618. 0x56, 0x36, 0x9A, 0x7E, 0x73, 0xF7, 0x3B, 0x42,
  39619. 0x86, 0x39, 0xA0, 0x5C, 0x13, 0x78, 0x44, 0x8A,
  39620. 0xDB, 0x7F, 0x07, 0x4D, 0xC8, 0x15, 0x4D, 0x92,
  39621. 0xE1, 0x3C, 0x63, 0x56, 0xB5, 0xF4, 0x66, 0xD6,
  39622. 0x64, 0x77, 0x15, 0x9B, 0x2A, 0x94, 0x37, 0x99,
  39623. 0xAD, 0x61, 0x9A, 0x02, 0x9F, 0x30, 0x10, 0xD0,
  39624. 0x37, 0x67, 0x2D, 0xBB, 0x68, 0x20, 0xE5, 0x13,
  39625. 0x23, 0xAD, 0xA9, 0x88, 0x81, 0xC6, 0xDE, 0x85,
  39626. 0x9D, 0xF8, 0x75, 0xAB, 0xAF, 0x11, 0xDA, 0x5D,
  39627. 0xDC, 0xA5, 0xA7, 0x77, 0x62, 0x2B, 0xDA, 0xE8,
  39628. 0xFA, 0xCE, 0x2E, 0x0C, 0xED, 0x3B, 0x6A, 0x77,
  39629. 0xB8, 0x8A, 0x87, 0x29, 0xFB, 0x7C, 0x50, 0x93,
  39630. 0x3D, 0xA6, 0xC5, 0x2E, 0x3F, 0x4D, 0x94, 0x8F,
  39631. 0x9D, 0xC1, 0x53, 0xB5, 0xB1, 0x29, 0x9C, 0xD8,
  39632. 0x62, 0x1D, 0xDF, 0xBA, 0x48, 0xAF, 0x44, 0xE4,
  39633. 0xB6, 0xF6, 0x10, 0x6E, 0xE7, 0x77, 0x95, 0x01,
  39634. 0xDD, 0x5F, 0xB3, 0xC5, 0x78, 0xEA, 0x4D, 0x32,
  39635. 0xC5, 0xC2, 0xF0, 0x36, 0xA7, 0x35, 0x27, 0x03,
  39636. 0xAD, 0xD1, 0x35, 0xAB, 0x84, 0x46, 0x01, 0x62,
  39637. 0x41, 0x7E, 0x50, 0xBF, 0x91, 0xE6, 0x07, 0x97,
  39638. 0xD5, 0x9B, 0x9E, 0x18, 0xD3, 0x24, 0xDA, 0x97,
  39639. 0x1F, 0x4F, 0xF4, 0x28, 0xAE, 0xAF, 0x23, 0xAC,
  39640. 0x0B, 0xA4, 0xE2, 0xE2, 0xFC, 0x7A, 0xBA, 0xA6,
  39641. 0xC8, 0x98, 0x4F, 0xE9, 0xE2, 0xD8, 0x5B, 0x8A,
  39642. 0xDA, 0x40, 0x86, 0xB3, 0xC1, 0x3A, 0xBD, 0x43,
  39643. 0xCF, 0xD1, 0xC7, 0x11, 0xD8, 0x32, 0x6B, 0x18,
  39644. 0xAD, 0xC3, 0x4C, 0xC1, 0x4C, 0xF8, 0x95, 0x7E,
  39645. 0xC3, 0x95, 0x94, 0x98, 0xFC, 0x2A, 0x7B, 0xE0,
  39646. 0x6B, 0xD1, 0x84, 0x0D, 0xE1, 0x70, 0x36, 0x65,
  39647. 0x66, 0xE5, 0x07, 0x41, 0x95, 0x77, 0x63, 0xC2,
  39648. 0xDD, 0x27, 0xAC, 0xF8, 0xC3, 0xF1, 0x02, 0x6F,
  39649. 0xAE, 0xE1, 0xD2, 0x56, 0x2F, 0xA1, 0x05, 0x2E,
  39650. 0x69, 0xAF, 0xDD, 0x42, 0xF4, 0x46, 0xF0, 0x59,
  39651. 0x88, 0x66, 0xD5, 0xD3, 0x06, 0xBF, 0x1B, 0x77,
  39652. 0x50, 0x42, 0xB0, 0x35, 0x92, 0x73, 0x72, 0x82,
  39653. 0x7F, 0x43, 0x86, 0x31, 0x65, 0x34, 0xFA, 0x1B,
  39654. 0x7E, 0xE6, 0x33, 0xBA, 0x95, 0x8C, 0xED, 0x8F,
  39655. 0x0D, 0x24, 0x1D, 0x46, 0x88, 0xE3, 0xC7, 0x91,
  39656. 0x8E, 0x2A, 0x75, 0x62, 0x63, 0x77, 0xC3, 0x42,
  39657. 0xA5, 0x90, 0x69, 0x2B, 0xBF, 0xB8, 0x27, 0xBF,
  39658. 0x90, 0x51, 0x41, 0x82, 0xD4, 0x09, 0x0D, 0xF8,
  39659. 0xD7, 0x32, 0x35, 0x19, 0xA1, 0xAB, 0x6C, 0xD0,
  39660. 0x22, 0x73, 0x67, 0x41, 0x0D, 0xD1, 0x4D, 0x37,
  39661. 0x86, 0xA2, 0x6D, 0xDF, 0x91, 0x72, 0x4F, 0xC8,
  39662. 0x2D, 0x06, 0xA2, 0x5D, 0x5F, 0x56, 0x68, 0x39,
  39663. 0x53, 0xE8, 0xE0, 0xF2, 0x0E, 0x3C, 0x17, 0x71,
  39664. 0xDA, 0xF4, 0x2E, 0x52, 0x02, 0x4C, 0x11, 0x6E,
  39665. 0xD8, 0xA4, 0xC0, 0xA6, 0x11, 0x68, 0x0F, 0x5F,
  39666. 0xE0, 0x0E, 0xD9, 0xB1, 0x48, 0xD1, 0x5F, 0x12,
  39667. 0xAA, 0x95, 0xB9, 0xBD, 0x5A, 0x9F, 0xD8, 0x10,
  39668. 0x16, 0x42, 0xB3, 0x69, 0x11, 0xF3, 0x10, 0xB0,
  39669. 0xDE, 0x18, 0x17, 0x1D, 0x62, 0x37, 0xD9, 0xBE,
  39670. 0x17, 0x25, 0xDC, 0x29, 0x9A, 0x1A, 0x3A, 0xAA,
  39671. 0xE9, 0x85, 0x40, 0xCE, 0xED, 0x26, 0x95, 0x3D,
  39672. 0x10, 0xCE, 0x85, 0x47, 0xF1, 0xC3, 0xE4, 0x6A,
  39673. 0x86, 0x2B, 0xED, 0x42, 0x8D, 0x1E, 0x10, 0x60,
  39674. 0x1B, 0xF3, 0x28, 0xC7, 0x27, 0xFD, 0x95, 0x34,
  39675. 0x3E, 0x2D, 0xB4, 0xD9, 0xAC, 0xD5, 0xD1, 0xCB,
  39676. 0x47, 0x15, 0xF6, 0x00, 0x40, 0x96, 0xED, 0xA0,
  39677. 0x93, 0xD1, 0xB0, 0xA3, 0x3B, 0x1E, 0x56, 0xF1,
  39678. 0x6D, 0x73, 0xAD, 0xB8, 0x73, 0x2C, 0xB4, 0xA3,
  39679. 0x11, 0x60, 0xA4, 0x49, 0x1F, 0xAA, 0x0C, 0x86,
  39680. 0xE6, 0x80, 0xE3, 0xD7, 0xC0, 0x2C, 0xCE, 0xA8,
  39681. 0xFE, 0x92, 0xF1, 0xE0, 0x01, 0x01, 0x6D, 0x22,
  39682. 0x02, 0x21, 0xDD, 0x10, 0xED, 0x62, 0x60, 0x17,
  39683. 0x96, 0x6C, 0x34, 0x50, 0xAD, 0x12, 0x13, 0x65,
  39684. 0x91, 0x8C, 0x93, 0x09, 0x1F, 0x14, 0x71, 0x2B,
  39685. 0xA4, 0x77, 0xCF, 0x2E, 0x26, 0x32, 0x96, 0xC7,
  39686. 0x78, 0xA2, 0xBA, 0xEE, 0xF5, 0x84, 0x94, 0x55,
  39687. 0xFA, 0x35, 0xCB, 0x61, 0x72, 0x51, 0xE0, 0x2A,
  39688. 0x22, 0xDA, 0xF5, 0xC3, 0x3E, 0x5A, 0xAA, 0x9F,
  39689. 0x00, 0xE8, 0xAC, 0xDC, 0x50, 0xEC, 0xF4, 0x7C,
  39690. 0x52, 0x15, 0x03, 0xC5, 0x2F, 0x27, 0xD6, 0xB5,
  39691. 0x7C, 0x8F, 0x2B, 0x3D, 0x8F, 0x12, 0x22, 0x41,
  39692. 0x3E, 0x7F, 0xA4, 0xEC, 0x59, 0x29, 0x63, 0x38,
  39693. 0x09, 0x8C, 0x9A, 0xB5, 0xA1, 0xD8, 0xA5, 0x78,
  39694. 0x84, 0xBD, 0x86, 0x00, 0x41, 0x40, 0x6D, 0x96,
  39695. 0x55, 0xD1, 0x73, 0x82, 0x94, 0x9A, 0x03, 0xD5,
  39696. 0x0F, 0x11, 0x08, 0xD0, 0x5B, 0xDB, 0x31, 0xCA,
  39697. 0x08, 0xE6, 0x6F, 0x2D, 0x8D, 0xE4, 0x80, 0xC6,
  39698. 0x79, 0x35, 0x18, 0xD4, 0x9A, 0x60, 0xD4, 0x76,
  39699. 0x2A, 0x9E, 0xDD, 0xC0, 0x24, 0x9B, 0x42, 0x2E,
  39700. 0x84, 0x02, 0x0E, 0xD5, 0x39, 0xA1, 0x4E, 0x24,
  39701. 0x78, 0xF6, 0x8B, 0xAB, 0x1F, 0x2B, 0x00, 0xE2,
  39702. 0x2A, 0x5C, 0xBB, 0x62, 0x97, 0x9A, 0xC7, 0x44,
  39703. 0xE0, 0x8B, 0x57, 0xD5, 0xB5, 0x78, 0xC4, 0x01,
  39704. 0xA8, 0xD2, 0x6D, 0x9A, 0xDD, 0x15, 0x05, 0x23,
  39705. 0x60, 0x82, 0x86, 0x36, 0x72, 0xD9, 0x11, 0xCF,
  39706. 0x3A, 0x09, 0x66, 0xD3, 0x03, 0xF8, 0x91, 0x70,
  39707. 0x93, 0xBF, 0x97, 0xAF, 0x90, 0xA7, 0xE1, 0xF9,
  39708. 0xD5, 0x9B, 0x09, 0x20, 0x6B, 0x9C, 0xAC, 0x35,
  39709. 0x11, 0x0F, 0xA3, 0x8D, 0x58, 0x90, 0xED, 0x21,
  39710. 0x16, 0x83, 0x5C, 0xE3, 0x73, 0x84, 0xF5, 0x63,
  39711. 0x0F, 0x1C, 0x42, 0x8E, 0x21, 0x36, 0x05, 0x87,
  39712. 0x2E, 0xCF, 0x91, 0x1B, 0x01, 0x4B, 0x91, 0xC2,
  39713. 0xC6, 0x00, 0xE8, 0xA4, 0x07, 0x29, 0xD0, 0x7B,
  39714. 0xF9, 0x18, 0x79, 0x07, 0x42, 0xC9, 0x27, 0x9F,
  39715. 0x31, 0x14, 0xF6, 0x8C, 0xDF, 0x65, 0x94, 0xCD,
  39716. 0xA3, 0xCA, 0x66, 0x94, 0x22, 0x3A, 0x82, 0xF6,
  39717. 0x6C, 0x2B, 0x4B, 0xDF, 0x3E, 0x51, 0xC6, 0xFF,
  39718. 0xDC, 0x55, 0xE0, 0xFF, 0x51, 0xEF, 0xD6, 0xC9,
  39719. 0x34, 0x36, 0x2B, 0xE7, 0xD6, 0xFA, 0xBC, 0x11,
  39720. 0xB8, 0xB0, 0xDA, 0xDD, 0xD5, 0x21, 0x08, 0xFA,
  39721. 0x5F, 0xB5, 0xCA, 0x75, 0x8A, 0x64, 0x37, 0x7D,
  39722. 0x38, 0x6D, 0x45, 0xCE, 0x70, 0x60, 0x5B, 0x46,
  39723. 0x0E, 0x81, 0x57, 0x03, 0x7B, 0x5B, 0x1B, 0x2E,
  39724. 0x0A, 0xED, 0xD1, 0x2A, 0x63, 0x31, 0x15, 0xD6,
  39725. 0xC4, 0x3B, 0xC6, 0xC7, 0xC8, 0x36, 0xFF, 0xF3,
  39726. 0x3E, 0x7D, 0x03, 0x3F, 0x2E, 0x58, 0x00, 0x52,
  39727. 0x71, 0x64, 0xC0, 0xC4, 0x78, 0x1C, 0x37, 0xDF,
  39728. 0x50, 0xB6, 0x6B, 0xBA, 0x5C, 0x81, 0x94, 0x73,
  39729. 0xA1, 0xC5, 0x30, 0x20, 0x83, 0xA1, 0x6F, 0x01,
  39730. 0x43, 0x72, 0x79, 0xD2, 0xF2, 0xDF, 0x14, 0xC8,
  39731. 0x78, 0x26, 0x9A, 0x2F, 0x3F, 0xA4, 0x0C, 0x1C,
  39732. 0x76, 0x1E, 0xD6, 0x15, 0x01, 0xAC, 0x9E, 0xF1,
  39733. 0x41, 0x02, 0x90, 0x38, 0xC8, 0x19, 0x95, 0x40,
  39734. 0x89, 0xB7, 0x38, 0x09, 0x87, 0x08, 0x17, 0x43,
  39735. 0x93, 0xFE, 0xAE, 0xA7, 0xB0, 0x2A, 0xE5, 0xCE,
  39736. 0xF6, 0x7B, 0x3C, 0x8C, 0xE6, 0xA9, 0x70, 0x67,
  39737. 0x5C, 0xA1, 0xB8, 0xC8, 0x56, 0xDC, 0xF5, 0x97,
  39738. 0x25, 0x08, 0xC7, 0xC6, 0xB2, 0x5E, 0xE4, 0xD1,
  39739. 0x2D, 0x82, 0x12, 0xB9, 0x89, 0x40, 0xB4, 0x88,
  39740. 0xEC, 0x40, 0x2A, 0xC7, 0xAE, 0x3C, 0x70, 0xDF,
  39741. 0x93, 0x8D, 0x12, 0x88, 0xCD, 0xA7, 0xA3, 0x19,
  39742. 0xE0, 0x85, 0xBC, 0x73, 0xA4, 0x69, 0xB2, 0xD2,
  39743. 0xA3, 0x30, 0x3B, 0x11, 0xA6, 0x83, 0x10, 0x0A,
  39744. 0xF6, 0xDB, 0x86, 0x93, 0x7B, 0xA1, 0x18, 0x29,
  39745. 0x03, 0x61, 0x6E, 0x3F, 0x03, 0x47, 0xBD, 0x68,
  39746. 0x59, 0x1B, 0x47, 0xBA, 0x65, 0x15, 0x6B, 0x93,
  39747. 0xF2, 0x60, 0xDE, 0x59, 0xB3, 0xAE, 0xB2, 0x89,
  39748. 0xE2, 0xA7, 0x3A, 0x3B, 0xFF, 0x38, 0xC2, 0xF3,
  39749. 0xAD, 0xED, 0xA2, 0x9C, 0x7E, 0x90, 0x28, 0x3A,
  39750. 0xC7, 0xB8, 0x6D, 0x03, 0x6B, 0x47, 0xD5, 0xBA,
  39751. 0x1A, 0x03, 0xEC, 0x78, 0x3D, 0x25, 0x0B, 0xAC,
  39752. 0xAE, 0x58, 0x47, 0xE4, 0x1F, 0x82, 0x9C, 0xB3,
  39753. 0x3D, 0xE0, 0x8D, 0xF8, 0xF7, 0xD6, 0x9C, 0x9A,
  39754. 0xA4, 0xED, 0xE8, 0xD7, 0xAB, 0x96, 0x84, 0x07,
  39755. 0xEE, 0xD3, 0x1A, 0x05, 0x6B, 0xA0, 0xEF, 0x88,
  39756. 0x16, 0xE1, 0x27, 0xAA, 0x90, 0x06, 0x5A, 0x67,
  39757. 0x9E, 0x1C, 0xA9, 0x55, 0x0D, 0xEE, 0xF2, 0x5A,
  39758. 0xC5, 0xB7, 0xA3, 0x4F, 0x70, 0xDC, 0xF2, 0xB1,
  39759. 0x16, 0xCF, 0x35, 0x1F, 0x3B, 0xAD, 0xA9, 0x9F,
  39760. 0x83, 0x6C, 0x73, 0x0D, 0xCC, 0x1A, 0xE0, 0x3F,
  39761. 0x49, 0x6C, 0xF3, 0xF0, 0x38, 0x7A, 0x0C, 0x2C,
  39762. 0x70, 0x2E, 0x2C, 0x13, 0xBD, 0xD9, 0xCF, 0x45,
  39763. 0xA1, 0xCD, 0x53, 0xAB, 0x58, 0x73, 0x11, 0x88,
  39764. 0xB1, 0x8E, 0xA8, 0xBE, 0x48, 0xD5, 0x10, 0xC5,
  39765. 0x81, 0x2E, 0x90, 0xBC, 0xEC, 0xBC, 0x6E, 0x19,
  39766. 0x8E, 0x70, 0x8B, 0x1C, 0x08, 0xC8, 0xF8, 0x64,
  39767. 0xB1, 0x24, 0xBB, 0x4C, 0xC0, 0xBD, 0xBB, 0xDF,
  39768. 0x2C, 0x2F, 0x4E, 0x38, 0x8F, 0xC1, 0x96, 0x60,
  39769. 0xD6, 0x9C, 0xC2, 0xC0, 0xEB, 0xF9, 0x10, 0x08,
  39770. 0xC8, 0x24, 0x3D, 0xB4, 0x2D, 0xDA, 0xF5, 0x7C,
  39771. 0x02, 0x42, 0x51, 0xC4, 0x23, 0x1D, 0xF5, 0x37,
  39772. 0x90, 0xCE, 0x57, 0x56, 0x13, 0xEE, 0x8E, 0x1C,
  39773. 0x7A, 0x33, 0xC1, 0x56, 0x1F, 0x35, 0x04, 0xDE,
  39774. 0xAA, 0xED, 0x1E, 0x84, 0x08, 0x50, 0x06, 0x23,
  39775. 0xEC, 0xA5, 0xAE, 0x5A, 0x28, 0x45, 0x41, 0x17,
  39776. 0x49, 0x93, 0x0D, 0x8E, 0x42, 0x07, 0x8C, 0x03,
  39777. 0x23, 0x49, 0x95, 0x7F, 0xC3, 0x9A, 0x1D, 0xA0,
  39778. 0xEA, 0xF9, 0xE8, 0x7C, 0x31, 0xFF, 0xBF, 0x6A,
  39779. 0xC0, 0xC1, 0x81, 0x1E, 0xB2, 0x8A, 0x41, 0xB1,
  39780. 0xD8, 0x6B, 0xD7, 0xD4, 0x9A, 0xD1, 0xC4, 0x68,
  39781. 0xA4, 0x95, 0x94, 0x95, 0x65, 0x25, 0xA2, 0x0A,
  39782. 0x31, 0x70, 0x0F, 0x12, 0x2F, 0x4C, 0x4B, 0xB2,
  39783. 0x25, 0x2A, 0x2F, 0x3D, 0x5C, 0x5D, 0x68, 0x73,
  39784. 0x83, 0x8C, 0x90, 0x95, 0x97, 0xBB, 0xCA, 0xD8,
  39785. 0xE1, 0x33, 0x3D, 0x5D, 0x61, 0x7C, 0x87, 0xC8,
  39786. 0xEE, 0x0F, 0x1B, 0x22, 0x38, 0x3B, 0x42, 0x4B,
  39787. 0x4C, 0x5C, 0x62, 0x72, 0x98, 0xA3, 0xBE, 0xCC,
  39788. 0x1B, 0x32, 0x47, 0x5C, 0x9D, 0xB6, 0xB9, 0xBD,
  39789. 0xC6, 0xD6, 0xDC, 0xF5, 0x00, 0x00, 0x00, 0x00,
  39790. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39791. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39792. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39793. 0x11, 0x19, 0x28, 0x34
  39794. };
  39795. #endif
  39796. #ifndef WOLFSSL_NO_ML_DSA_65
  39797. static const byte pk_65[] = {
  39798. 0x6C, 0x9E, 0x7A, 0x1E, 0xE3, 0x66, 0x25, 0x76,
  39799. 0x0E, 0x5D, 0x2F, 0x33, 0xDF, 0x29, 0x29, 0xDA,
  39800. 0x56, 0x20, 0x32, 0x34, 0x06, 0x91, 0x60, 0xE5,
  39801. 0xF2, 0xBF, 0x03, 0x9C, 0x11, 0x06, 0x22, 0x73,
  39802. 0x07, 0x3C, 0x23, 0x75, 0x66, 0xCE, 0x05, 0x5D,
  39803. 0x87, 0x1F, 0x38, 0xAC, 0xD1, 0xA9, 0x85, 0x9A,
  39804. 0x82, 0x44, 0x67, 0xF1, 0x9B, 0xE6, 0x8E, 0x4F,
  39805. 0x00, 0x64, 0x5D, 0x22, 0x5C, 0x42, 0xC8, 0x5A,
  39806. 0x55, 0x7D, 0x2C, 0x5E, 0xCB, 0x44, 0x2B, 0x0F,
  39807. 0x02, 0x8A, 0x65, 0x28, 0x89, 0x8E, 0xE2, 0xB6,
  39808. 0x73, 0xD8, 0x63, 0xF3, 0x2E, 0xB9, 0xEC, 0x81,
  39809. 0x64, 0x12, 0x75, 0x41, 0xF3, 0x25, 0x19, 0xBB,
  39810. 0x88, 0xE0, 0x34, 0xA0, 0x3F, 0x46, 0xF7, 0xD1,
  39811. 0x93, 0xCD, 0x3D, 0xFB, 0xAD, 0xF6, 0x35, 0x57,
  39812. 0x92, 0x6C, 0x5C, 0x8F, 0x5B, 0x76, 0x6A, 0x7F,
  39813. 0xC5, 0xEC, 0x8B, 0x3F, 0x94, 0x8B, 0xF7, 0xA8,
  39814. 0x21, 0xB5, 0x4C, 0x94, 0x41, 0xAB, 0x0B, 0xD8,
  39815. 0x33, 0xFD, 0x63, 0x54, 0xCE, 0xC7, 0x06, 0xFA,
  39816. 0xA5, 0x00, 0xAB, 0xB5, 0x28, 0x9B, 0x90, 0xB1,
  39817. 0xBF, 0x91, 0x76, 0x77, 0xA2, 0x9D, 0x11, 0x5F,
  39818. 0x00, 0x94, 0xBD, 0xB4, 0x8D, 0xC7, 0x2E, 0x26,
  39819. 0x1D, 0xBA, 0x12, 0x0B, 0xA6, 0xFF, 0x5E, 0x52,
  39820. 0xA0, 0x1B, 0x17, 0x89, 0x81, 0xDD, 0x82, 0x96,
  39821. 0x44, 0x46, 0x56, 0xD9, 0x44, 0x2D, 0xF9, 0xCB,
  39822. 0xB6, 0xBF, 0xDA, 0xE5, 0x6A, 0x23, 0x0F, 0x6F,
  39823. 0x29, 0xF9, 0x4C, 0xDC, 0xC2, 0x65, 0x57, 0x6A,
  39824. 0xA8, 0x75, 0x2A, 0xCE, 0xD0, 0x7E, 0x99, 0x89,
  39825. 0x5C, 0xAE, 0xF0, 0x16, 0x8B, 0xF8, 0x3D, 0x23,
  39826. 0xFD, 0xAD, 0xFB, 0xB9, 0x28, 0xCB, 0xCD, 0xAB,
  39827. 0xA2, 0x5F, 0xE2, 0xCD, 0x26, 0xAD, 0xDF, 0xB0,
  39828. 0xDA, 0xCD, 0x74, 0x94, 0x0F, 0x35, 0x14, 0x26,
  39829. 0x94, 0x2F, 0x17, 0x6F, 0xFB, 0xC5, 0xF3, 0x45,
  39830. 0x6D, 0xB7, 0xC9, 0x12, 0xAA, 0x16, 0xB8, 0x6D,
  39831. 0x07, 0x45, 0xF8, 0x7C, 0x9F, 0x45, 0x37, 0x0A,
  39832. 0x84, 0x56, 0xA1, 0xAD, 0xB5, 0x1D, 0xB4, 0x05,
  39833. 0x2B, 0x5C, 0x9E, 0xAF, 0x60, 0xAD, 0x7B, 0x80,
  39834. 0xA4, 0x2E, 0xA4, 0xBF, 0x92, 0xC8, 0x41, 0x27,
  39835. 0x3A, 0xD7, 0x61, 0xDE, 0xDB, 0x0D, 0x34, 0xBF,
  39836. 0x57, 0x96, 0x00, 0xB1, 0x49, 0xFC, 0xCD, 0x42,
  39837. 0xAB, 0x15, 0x49, 0xBA, 0x0A, 0xBE, 0xDA, 0x57,
  39838. 0xEF, 0x71, 0xD1, 0xFC, 0xA5, 0x70, 0x2A, 0xAD,
  39839. 0x08, 0x32, 0x99, 0xBB, 0x98, 0x30, 0x01, 0x89,
  39840. 0xC2, 0x5F, 0x3B, 0x27, 0x0A, 0x87, 0x65, 0x8D,
  39841. 0x0B, 0x2E, 0xA5, 0x65, 0x24, 0x14, 0x7F, 0x73,
  39842. 0x9E, 0xB6, 0xC6, 0x76, 0xD7, 0xBE, 0x73, 0xDD,
  39843. 0x3B, 0x95, 0xB1, 0x0C, 0x55, 0xAB, 0x46, 0xFD,
  39844. 0x01, 0x54, 0x9C, 0x51, 0x68, 0xBF, 0x7D, 0xA1,
  39845. 0x3A, 0x49, 0x97, 0x85, 0xF3, 0x5A, 0x1E, 0x3B,
  39846. 0x56, 0xF4, 0xC5, 0x67, 0xF5, 0x4E, 0xA9, 0xAA,
  39847. 0x28, 0x17, 0xA3, 0x36, 0x38, 0x36, 0x43, 0xFA,
  39848. 0x2E, 0xA3, 0x1F, 0xB1, 0xB7, 0x3E, 0x10, 0x24,
  39849. 0x8D, 0xFC, 0xA0, 0x5C, 0x04, 0x13, 0x12, 0x66,
  39850. 0x49, 0x8E, 0x1C, 0x94, 0x91, 0x13, 0x5A, 0x50,
  39851. 0xE6, 0x3D, 0x02, 0xFA, 0xDF, 0x41, 0x65, 0xFC,
  39852. 0x9E, 0x15, 0xE3, 0xE1, 0xB3, 0x2F, 0xAB, 0x83,
  39853. 0x37, 0x68, 0x4C, 0x49, 0x19, 0x3E, 0x1B, 0xC4,
  39854. 0xED, 0xEA, 0xE3, 0x73, 0xA2, 0x67, 0xA7, 0x14,
  39855. 0xAC, 0x1F, 0x90, 0x9C, 0xC6, 0x57, 0xCD, 0x80,
  39856. 0x66, 0x64, 0x63, 0x27, 0xE0, 0xEE, 0xA0, 0x41,
  39857. 0xAC, 0x9F, 0x2A, 0xEF, 0xFC, 0x80, 0x69, 0x1B,
  39858. 0xF6, 0x0D, 0x3C, 0x94, 0xC6, 0x42, 0x55, 0x7E,
  39859. 0x42, 0x99, 0xD3, 0x95, 0x92, 0x22, 0x16, 0xC6,
  39860. 0x5E, 0x75, 0xB7, 0xE1, 0xA5, 0x02, 0x89, 0x60,
  39861. 0x38, 0x4B, 0xF8, 0x16, 0xC9, 0xF7, 0x05, 0x48,
  39862. 0x29, 0xE7, 0x98, 0x5B, 0x58, 0x41, 0xA7, 0x33,
  39863. 0xF3, 0x3F, 0xCE, 0x24, 0x55, 0xEF, 0xC8, 0x9B,
  39864. 0xAE, 0x84, 0xB4, 0x79, 0x90, 0xE8, 0xD0, 0xAF,
  39865. 0xC6, 0x19, 0x3E, 0x4A, 0xF9, 0xBC, 0x68, 0x0A,
  39866. 0xE2, 0x4F, 0xE5, 0x91, 0xE8, 0x8B, 0xA6, 0xA2,
  39867. 0xAE, 0x12, 0xDA, 0x38, 0x58, 0xD2, 0x1F, 0x49,
  39868. 0x2D, 0x24, 0xAB, 0xC4, 0xFE, 0x4F, 0xD5, 0x2D,
  39869. 0x5A, 0xBF, 0x24, 0xBD, 0x25, 0x46, 0x87, 0xB9,
  39870. 0x18, 0x79, 0x2F, 0x0A, 0x00, 0x3A, 0x52, 0x22,
  39871. 0xDF, 0x45, 0x03, 0x86, 0x85, 0xC7, 0x25, 0xCE,
  39872. 0x75, 0x79, 0xE0, 0x2C, 0xB1, 0x68, 0xBB, 0xC6,
  39873. 0x66, 0xAB, 0xF6, 0x69, 0x85, 0x6E, 0x10, 0x53,
  39874. 0x7C, 0x92, 0x91, 0x69, 0x2C, 0x0C, 0xB0, 0xCF,
  39875. 0xA9, 0x06, 0x27, 0x0A, 0xC2, 0xC7, 0xB7, 0xDC,
  39876. 0x31, 0xD4, 0xF9, 0x28, 0x3C, 0xB2, 0xDB, 0x8A,
  39877. 0x46, 0x2A, 0xEC, 0x0B, 0x98, 0x07, 0xBB, 0xF4,
  39878. 0xAB, 0x45, 0x76, 0xFE, 0xC6, 0x22, 0x6B, 0x41,
  39879. 0x79, 0x32, 0x2B, 0x67, 0xAE, 0xA5, 0x3B, 0xDD,
  39880. 0xF9, 0xC9, 0xBE, 0x5E, 0x0D, 0xBC, 0x43, 0xF7,
  39881. 0x87, 0x43, 0x06, 0x8A, 0xB5, 0xBE, 0x49, 0xF0,
  39882. 0xE6, 0x2F, 0x8E, 0x2E, 0xB1, 0xB6, 0xC6, 0x73,
  39883. 0x6C, 0x05, 0xC9, 0x41, 0x3D, 0x06, 0x5C, 0xE0,
  39884. 0xCC, 0xB7, 0x90, 0x54, 0x80, 0x41, 0xD7, 0xE8,
  39885. 0x32, 0x88, 0x1A, 0x83, 0x9B, 0x57, 0x29, 0xAF,
  39886. 0x94, 0xAB, 0x79, 0xFD, 0x8A, 0x16, 0xDF, 0xFF,
  39887. 0x78, 0xCA, 0xAA, 0x14, 0x1D, 0x97, 0xCC, 0x06,
  39888. 0x50, 0xF8, 0x62, 0x62, 0xF2, 0x61, 0x59, 0xBE,
  39889. 0x8B, 0x36, 0x1A, 0x4A, 0x04, 0x1E, 0x9A, 0x0B,
  39890. 0x65, 0x11, 0xBB, 0xE3, 0x35, 0x5A, 0x4B, 0xF5,
  39891. 0x7A, 0xC0, 0x98, 0x48, 0x84, 0x7E, 0xE0, 0x24,
  39892. 0x3C, 0x3B, 0xA7, 0x74, 0x77, 0x6F, 0x7E, 0x9A,
  39893. 0x22, 0x72, 0x75, 0xD7, 0x4E, 0x6E, 0x31, 0x01,
  39894. 0xD3, 0x82, 0x81, 0x87, 0x63, 0xED, 0x1E, 0x13,
  39895. 0x53, 0xAB, 0x9E, 0xEC, 0xCD, 0x92, 0x0C, 0xD2,
  39896. 0x89, 0x22, 0xD5, 0x59, 0xA4, 0x04, 0x8F, 0x40,
  39897. 0xF0, 0x62, 0x16, 0x4C, 0xB6, 0x61, 0xC4, 0xF4,
  39898. 0xAF, 0xA8, 0x1A, 0x3D, 0x55, 0x93, 0x3C, 0x47,
  39899. 0x91, 0xED, 0xDA, 0xA3, 0x93, 0x9E, 0x5A, 0xC3,
  39900. 0x42, 0xB0, 0xAD, 0x1F, 0x43, 0x8A, 0x53, 0x2C,
  39901. 0x6C, 0xE7, 0x86, 0x68, 0x1A, 0x87, 0x0D, 0x94,
  39902. 0xEC, 0x88, 0xA3, 0x34, 0xCC, 0xEF, 0xC6, 0xAC,
  39903. 0xE7, 0xD9, 0x88, 0xA1, 0xA8, 0x2B, 0xC0, 0xAC,
  39904. 0xCE, 0x78, 0x5F, 0x12, 0x3B, 0xE2, 0x3A, 0x7C,
  39905. 0x92, 0xAF, 0x10, 0x8E, 0x5E, 0xD4, 0xF0, 0x86,
  39906. 0x9E, 0x22, 0xDA, 0xE2, 0x73, 0x55, 0x6D, 0x1D,
  39907. 0xE3, 0x86, 0x62, 0x3A, 0x6C, 0x3F, 0x11, 0x5B,
  39908. 0xBD, 0x11, 0x92, 0x71, 0xD3, 0xFB, 0xA7, 0x96,
  39909. 0xF6, 0x18, 0xB5, 0x39, 0x59, 0xFB, 0x98, 0x01,
  39910. 0x2E, 0x7D, 0x5B, 0x9A, 0xC6, 0x88, 0x94, 0x0B,
  39911. 0x87, 0xE2, 0xC9, 0xC0, 0x65, 0x52, 0x4A, 0x00,
  39912. 0xD3, 0xA4, 0xF4, 0xDB, 0xF5, 0x2F, 0x4B, 0x1A,
  39913. 0x63, 0xEF, 0x5C, 0x46, 0x19, 0x3B, 0xAD, 0xF7,
  39914. 0xAD, 0x7F, 0x98, 0x8D, 0x44, 0x64, 0x34, 0x5B,
  39915. 0x2C, 0x3E, 0x54, 0x96, 0x84, 0xF2, 0xF9, 0x05,
  39916. 0xF6, 0xF8, 0x9D, 0xD6, 0x41, 0x47, 0x3E, 0xC0,
  39917. 0x51, 0x08, 0xA5, 0x2D, 0x8D, 0xBB, 0x91, 0x76,
  39918. 0x8C, 0x54, 0x1D, 0xE5, 0x20, 0xB1, 0x76, 0x66,
  39919. 0x97, 0x0A, 0xAE, 0xB5, 0x06, 0xE7, 0x5D, 0x8E,
  39920. 0xE9, 0xF4, 0xB4, 0x45, 0x5B, 0x71, 0xE0, 0x08,
  39921. 0x8A, 0xB2, 0x56, 0x55, 0x21, 0x3B, 0x75, 0x85,
  39922. 0x9D, 0x25, 0xF5, 0x59, 0xD3, 0xC3, 0x24, 0xD2,
  39923. 0x83, 0xD3, 0x97, 0xAB, 0xE6, 0xF0, 0xAA, 0xA3,
  39924. 0x86, 0x81, 0x57, 0x68, 0xD0, 0x33, 0x57, 0xD7,
  39925. 0x75, 0x96, 0x49, 0x02, 0x41, 0x31, 0x53, 0xE3,
  39926. 0x56, 0x0C, 0xCE, 0xF1, 0xFD, 0x44, 0xB6, 0x5F,
  39927. 0xF1, 0xB2, 0x87, 0xA9, 0x2A, 0x96, 0x93, 0xF0,
  39928. 0x34, 0xB7, 0xEE, 0x66, 0x89, 0x34, 0x70, 0x2D,
  39929. 0x75, 0x01, 0xCA, 0xF6, 0xDA, 0x4E, 0xE9, 0x8A,
  39930. 0xF4, 0xE8, 0xE6, 0x4B, 0x03, 0x40, 0xE0, 0xBB,
  39931. 0x8B, 0xDC, 0x53, 0x3B, 0x0E, 0xFE, 0xE1, 0x91,
  39932. 0x5A, 0x4B, 0x68, 0xB9, 0x3C, 0x5E, 0x95, 0x32,
  39933. 0x1E, 0xED, 0xC2, 0x34, 0xAE, 0xFE, 0x71, 0xAE,
  39934. 0x2E, 0x5D, 0xAC, 0xEC, 0x2F, 0x52, 0xF8, 0x37,
  39935. 0x23, 0xA2, 0x39, 0x2A, 0x7F, 0x8E, 0x13, 0xBC,
  39936. 0x03, 0x01, 0xCD, 0x10, 0x4D, 0x85, 0x2E, 0x62,
  39937. 0xA7, 0xF8, 0x28, 0xAD, 0x32, 0x9B, 0x3D, 0x95,
  39938. 0x96, 0xC5, 0x8E, 0x13, 0xFC, 0xC0, 0xED, 0x96,
  39939. 0xC1, 0xC4, 0x8D, 0x82, 0xA2, 0xC0, 0xF4, 0xD9,
  39940. 0xD2, 0x4D, 0xD8, 0x42, 0x1F, 0xDC, 0xCE, 0xFD,
  39941. 0x49, 0x7A, 0x9B, 0x05, 0xFF, 0xC5, 0x09, 0x04,
  39942. 0x77, 0x04, 0x01, 0x37, 0x3F, 0xEE, 0x7D, 0xC7,
  39943. 0x37, 0x73, 0x41, 0x8A, 0xEB, 0x4A, 0x1F, 0x59,
  39944. 0x9A, 0x4B, 0xB3, 0x8E, 0xDE, 0x8D, 0x10, 0xA3,
  39945. 0xCC, 0x83, 0xA1, 0xC7, 0x2D, 0xE9, 0x21, 0x96,
  39946. 0x9E, 0x3C, 0xE3, 0xE8, 0xEF, 0x2F, 0x7D, 0xA8,
  39947. 0x9D, 0x34, 0x4C, 0x80, 0xD6, 0x1C, 0xF9, 0xC5,
  39948. 0xA4, 0x23, 0xB1, 0xA4, 0xF3, 0x56, 0x7D, 0x96,
  39949. 0xDB, 0x2D, 0xA3, 0xDB, 0x9B, 0x5B, 0x5F, 0xA6,
  39950. 0x81, 0x56, 0xBE, 0x74, 0x52, 0xC8, 0xA0, 0x18,
  39951. 0x1B, 0xB9, 0xF0, 0xDC, 0x75, 0xCD, 0x97, 0x50,
  39952. 0x88, 0x3D, 0x0D, 0xDA, 0xE5, 0x3F, 0xC1, 0x56,
  39953. 0xD6, 0x7A, 0x74, 0x20, 0x08, 0x69, 0x04, 0x6B,
  39954. 0x41, 0xDF, 0x4B, 0xC4, 0x39, 0x69, 0x93, 0xC0,
  39955. 0x8A, 0xA4, 0x89, 0x7A, 0x0B, 0xDD, 0xEF, 0xB5,
  39956. 0x5F, 0x69, 0xCC, 0x1C, 0x4D, 0x7B, 0x5F, 0xB1,
  39957. 0x50, 0x40, 0x84, 0x27, 0xB4, 0x16, 0xF7, 0x31,
  39958. 0x83, 0xF2, 0xB3, 0xCC, 0x16, 0xE3, 0xB7, 0xDA,
  39959. 0x63, 0xCE, 0xE1, 0x14, 0x3A, 0xDA, 0x1A, 0x05,
  39960. 0x66, 0x26, 0xA0, 0x77, 0xB6, 0xD2, 0x1C, 0x3D,
  39961. 0xD9, 0x74, 0xED, 0x90, 0x7C, 0x5A, 0x09, 0x40,
  39962. 0x19, 0x22, 0x57, 0x37, 0xEF, 0xB9, 0x33, 0x19,
  39963. 0xAD, 0x3B, 0x40, 0xA4, 0xF4, 0x34, 0xAE, 0x49,
  39964. 0xD2, 0x83, 0x91, 0xC1, 0x7A, 0x99, 0x9C, 0x74,
  39965. 0x4A, 0x68, 0xC5, 0x5A, 0x91, 0xB8, 0x62, 0x72,
  39966. 0x95, 0x83, 0xD3, 0xDA, 0x46, 0xEE, 0x70, 0xC5,
  39967. 0xCC, 0x46, 0x16, 0x94, 0x16, 0x7D, 0x32, 0xD2,
  39968. 0x1D, 0xE7, 0x53, 0x27, 0x73, 0x2C, 0x63, 0xBB,
  39969. 0xFB, 0xD7, 0xB3, 0x0D, 0xBF, 0x20, 0x57, 0xA0,
  39970. 0xD6, 0x81, 0x51, 0x9F, 0x6E, 0x4A, 0xF6, 0x08,
  39971. 0xD4, 0xBC, 0xD0, 0xB4, 0x75, 0x07, 0x26, 0x77,
  39972. 0x0E, 0x15, 0x6A, 0xED, 0xE8, 0x54, 0x17, 0xBD,
  39973. 0x75, 0x9D, 0x5F, 0xFE, 0x40, 0x1C, 0xB2, 0x99,
  39974. 0x6F, 0x34, 0x43, 0x4D, 0xB4, 0x28, 0xD9, 0xA4,
  39975. 0x17, 0x03, 0x72, 0x01, 0xFC, 0xD2, 0x60, 0xFA,
  39976. 0xA9, 0x80, 0x84, 0x50, 0x2E, 0xED, 0x5C, 0x27,
  39977. 0xA8, 0x91, 0x6E, 0x44, 0xF5, 0x92, 0x98, 0x19,
  39978. 0xD2, 0x1A, 0x69, 0xCE, 0x16, 0xBC, 0xDC, 0x3C,
  39979. 0xC8, 0x14, 0x1E, 0x28, 0x5E, 0xF8, 0x97, 0xB1,
  39980. 0x40, 0x2C, 0x15, 0xC9, 0x52, 0x59, 0x01, 0x19,
  39981. 0x05, 0x1E, 0x36, 0x9A, 0x1B, 0x7B, 0xE4, 0x43,
  39982. 0xFE, 0xAE, 0x6E, 0x32, 0xBC, 0x8F, 0x3D, 0x64,
  39983. 0x7F, 0xC5, 0x31, 0x5A, 0x52, 0x00, 0xCD, 0x52,
  39984. 0x38, 0xDC, 0x66, 0x77, 0x46, 0x6E, 0xA8, 0x6E,
  39985. 0xF8, 0xD1, 0x8E, 0x5A, 0x79, 0xF2, 0x62, 0x48,
  39986. 0x3E, 0x89, 0x6B, 0x82, 0x77, 0xC7, 0x41, 0xF5,
  39987. 0x16, 0xFC, 0x04, 0x0C, 0x10, 0x90, 0xF2, 0x49,
  39988. 0x5B, 0xF1, 0x65, 0x0B, 0x02, 0xAF, 0x30, 0x45,
  39989. 0x67, 0x33, 0xA0, 0x71, 0xAF, 0x47, 0xD7, 0xA1,
  39990. 0x5B, 0xD8, 0xE3, 0x2A, 0x49, 0x80, 0x64, 0x55,
  39991. 0xD3, 0xBE, 0xA7, 0x4A, 0xEF, 0x5D, 0x00, 0x90,
  39992. 0x6A, 0xD2, 0xF0, 0xC0, 0x45, 0x35, 0x4E, 0xFD,
  39993. 0xE7, 0xC9, 0xA2, 0x76, 0xE7, 0x3D, 0x9E, 0xDD,
  39994. 0x11, 0xD1, 0xCA, 0x5C, 0x29, 0x7B, 0x9A, 0x68,
  39995. 0x51, 0xE7, 0xF6, 0x7E, 0x21, 0xEB, 0x06, 0x1B,
  39996. 0xB5, 0x5D, 0x9E, 0x67, 0x3C, 0x4A, 0x75, 0xFE,
  39997. 0xB8, 0x4D, 0x52, 0x62, 0x9E, 0xEC, 0xC5, 0x3C,
  39998. 0x24, 0xBE, 0xA9, 0x51, 0x53, 0x05, 0x1A, 0xC2,
  39999. 0x06, 0xC8, 0x7D, 0xF5, 0x54, 0x10, 0xCA, 0x1F,
  40000. 0xE6, 0xCF, 0xC3, 0xF4, 0x03, 0xA6, 0xD9, 0xD4,
  40001. 0x3E, 0xA8, 0x4C, 0x60, 0xC9, 0x45, 0xE6, 0x42,
  40002. 0xB2, 0x83, 0x63, 0x38, 0xB5, 0xAF, 0x9F, 0x69,
  40003. 0xE5, 0x27, 0x08, 0xB2, 0xE2, 0x25, 0x93, 0x3D,
  40004. 0xB3, 0x20, 0xBB, 0x3F, 0x79, 0x0D, 0x39, 0x7F,
  40005. 0x22, 0xD7, 0xB6, 0xF8, 0xA4, 0x33, 0xCD, 0xAC,
  40006. 0xE9, 0x81, 0x0A, 0xA0, 0xE2, 0x7C, 0x69, 0x95,
  40007. 0x55, 0x53, 0x0C, 0x56, 0x2D, 0xBF, 0x75, 0x17,
  40008. 0xA4, 0x16, 0x26, 0x28, 0xBF, 0x10, 0xD1, 0xB6,
  40009. 0xDB, 0xAC, 0xEF, 0x5C, 0x9E, 0xD5, 0x1E, 0x55,
  40010. 0xD9, 0xA8, 0x9D, 0x60, 0xE0, 0xFC, 0x37, 0x8C,
  40011. 0x47, 0xA2, 0x1D, 0x5E, 0x0F, 0x2D, 0xC3, 0xBC,
  40012. 0xEF, 0x5E, 0x05, 0xC6, 0xE0, 0x26, 0x15, 0x30,
  40013. 0xFB, 0x02, 0x7E, 0x50, 0x32, 0x55, 0x8C, 0xA2,
  40014. 0xB4, 0x70, 0x05, 0xBD, 0xDE, 0x99, 0x90, 0x99,
  40015. 0x30, 0x39, 0x1E, 0xAD, 0x7F, 0x3F, 0x0A, 0x96,
  40016. 0xB3, 0xDE, 0xDA, 0x54, 0xA1, 0x11, 0x45, 0xF5,
  40017. 0x30, 0xE5, 0x1D, 0xEF, 0x89, 0x2E, 0x5A, 0xB0,
  40018. 0x20, 0x4D, 0x61, 0x4E, 0x6E, 0x38, 0xAF, 0xE7,
  40019. 0x9C, 0xA9, 0x2C, 0x28, 0x15, 0x8D, 0x57, 0x01,
  40020. 0x20, 0x35, 0x3B, 0x7A, 0x4D, 0xE0, 0x88, 0x98,
  40021. 0x46, 0xD8, 0x35, 0x29, 0x49, 0x39, 0x55, 0x7E,
  40022. 0xD0, 0xAE, 0xDA, 0x27, 0x0D, 0x4D, 0x73, 0xED,
  40023. 0x84, 0xD3, 0xD4, 0x9F, 0x9F, 0x03, 0x2D, 0x43,
  40024. 0x45, 0x7B, 0xF5, 0x9B, 0xB7, 0xD6, 0x63, 0x59,
  40025. 0xDC, 0x53, 0xF9, 0xB4, 0x69, 0x63, 0xB2, 0x17,
  40026. 0x84, 0xB0, 0x6C, 0xBC, 0xF0, 0x4B, 0xEC, 0x1E,
  40027. 0x33, 0xA3, 0x33, 0x71, 0x53, 0x27, 0x16, 0xC9,
  40028. 0xED, 0xB3, 0xFB, 0xED, 0xB8, 0x19, 0x99, 0xB4,
  40029. 0x37, 0x2D, 0x09, 0x45, 0xC1, 0x0A, 0xE8, 0x26,
  40030. 0xC6, 0x0F, 0xFE, 0x93, 0x17, 0x0B, 0x6D, 0x29,
  40031. 0x4B, 0x38, 0x91, 0xB0, 0xD2, 0xA7, 0xB3, 0x5B,
  40032. 0x28, 0xA8, 0x97, 0x18, 0x45, 0xDC, 0x2F, 0xEC,
  40033. 0xE2, 0x37, 0xB8, 0x0F, 0x20, 0xB3, 0x79, 0xCC,
  40034. 0x4D, 0x13, 0x6D, 0xAB, 0x3F, 0xBB, 0x37, 0x92,
  40035. 0xC6, 0x3E, 0xC6, 0x1F, 0x5C, 0x75, 0x5B, 0xC9,
  40036. 0xDB, 0x35, 0x08, 0x6F, 0xBF, 0x46, 0xD2, 0xB7,
  40037. 0x97, 0x0D, 0xCA, 0x2A, 0x85, 0x23, 0xFD, 0xB4,
  40038. 0xC7, 0xA0, 0xB8, 0xE4, 0x2F, 0x8A, 0xF9, 0xAC,
  40039. 0xAD, 0x2A, 0x0E, 0xFC, 0x11, 0x36, 0x02, 0xA4,
  40040. 0xEA, 0x62, 0xE4, 0xEB, 0xB7, 0xD2, 0x69, 0xC3,
  40041. 0xA4, 0x0B, 0xA2, 0xC4, 0x4E, 0xDD, 0x29, 0x56
  40042. };
  40043. static const byte msg_65[] = {
  40044. 0xC4, 0xF5, 0x9F, 0xA2, 0xDE, 0x30, 0xC8, 0x42,
  40045. 0x0A, 0x7E, 0x7F, 0x09, 0x6B, 0xAF, 0x6A, 0xD6,
  40046. 0x9B, 0x1C, 0x15, 0xA5, 0xC6, 0xE6, 0x1C, 0x9D,
  40047. 0x82, 0xAF, 0xCF, 0xDB, 0x6E, 0xB8, 0xF2, 0x75,
  40048. 0xBF, 0x57, 0x87, 0x18, 0x6A, 0xAE, 0x78, 0x1F,
  40049. 0x48, 0x7F, 0x9F, 0x88, 0x75, 0x8C, 0x9C, 0x61,
  40050. 0xF3, 0x5D, 0x50, 0x83, 0xEE, 0x70, 0x42, 0x4B,
  40051. 0x0D, 0x0A, 0x51, 0x57, 0x50, 0x10, 0xC2, 0xA9,
  40052. 0x07, 0xF4, 0x96, 0x08, 0x11, 0x5D, 0x33, 0xEB,
  40053. 0xA0, 0x03, 0x15, 0x09, 0x32, 0x2A, 0xA7, 0xD3,
  40054. 0x06, 0x1F, 0xEC, 0x31, 0x62, 0xF9, 0x6A, 0x56,
  40055. 0x5F, 0x98, 0x76, 0x9E, 0x9A, 0x19, 0x23, 0x5D,
  40056. 0x89, 0xD1, 0xB2, 0x1D, 0x60, 0xA3, 0x81, 0xDF,
  40057. 0x8E, 0xB3, 0x7D, 0x58, 0xC6, 0xA2, 0xE4, 0x83,
  40058. 0xA8, 0xEB, 0x70, 0x73, 0x6E, 0x4B, 0x7B, 0xB9,
  40059. 0x11, 0xF7, 0xAB, 0x92, 0x3D, 0xC2, 0x9F, 0x1E
  40060. };
  40061. static const byte sig_65[] = {
  40062. 0xE8, 0x95, 0xDB, 0x64, 0xC5, 0x7B, 0xC3, 0xC2,
  40063. 0xA9, 0x7F, 0x0E, 0xC9, 0x33, 0x41, 0x0E, 0x98,
  40064. 0xF6, 0x21, 0x61, 0x03, 0xE3, 0x42, 0x3C, 0xAF,
  40065. 0x06, 0xA6, 0x71, 0x96, 0x4C, 0x51, 0x4A, 0x69,
  40066. 0x4E, 0xB6, 0xF6, 0x5C, 0xBD, 0x11, 0x37, 0xCC,
  40067. 0xCF, 0x88, 0x81, 0xFA, 0x40, 0x3C, 0x5F, 0xA0,
  40068. 0xE0, 0xB2, 0xF3, 0x6B, 0x9F, 0x40, 0x09, 0xC3,
  40069. 0x78, 0x21, 0x0D, 0x29, 0xE5, 0x4A, 0x7A, 0x5A,
  40070. 0x9B, 0x79, 0x31, 0x97, 0xCD, 0x6D, 0x2F, 0x38,
  40071. 0xD7, 0xE1, 0xF3, 0xAC, 0xA6, 0x9D, 0x48, 0x88,
  40072. 0x13, 0x89, 0x38, 0x1C, 0x89, 0xFA, 0x67, 0x6D,
  40073. 0xE4, 0x26, 0xD6, 0x34, 0xF9, 0xA1, 0x57, 0x05,
  40074. 0x5F, 0x17, 0x28, 0x3E, 0xCE, 0x82, 0x48, 0xCA,
  40075. 0xF1, 0x4D, 0xCF, 0x11, 0xE2, 0xD5, 0x63, 0x55,
  40076. 0xB0, 0x47, 0xDF, 0x63, 0x2A, 0x18, 0x48, 0x2E,
  40077. 0x79, 0xCB, 0x2D, 0x5A, 0x74, 0x39, 0x66, 0xBA,
  40078. 0xA8, 0xA7, 0x61, 0x21, 0xBB, 0x69, 0xC2, 0xE6,
  40079. 0x81, 0x55, 0xAC, 0xCB, 0x0A, 0x31, 0xDA, 0x6E,
  40080. 0xDC, 0x73, 0xCB, 0x09, 0xA9, 0xE6, 0x60, 0xFE,
  40081. 0xB2, 0x0F, 0x66, 0xC7, 0xBD, 0x96, 0x7A, 0xDE,
  40082. 0x32, 0x14, 0x9C, 0x55, 0x52, 0xEA, 0xEB, 0x2E,
  40083. 0xA1, 0x75, 0xB5, 0x62, 0x33, 0xF3, 0xB3, 0x70,
  40084. 0xED, 0xD8, 0x67, 0x92, 0x69, 0xCE, 0x0D, 0x2B,
  40085. 0x43, 0xF6, 0xB2, 0xF6, 0x5F, 0xE9, 0x57, 0xE7,
  40086. 0xAB, 0x37, 0xB9, 0x82, 0x04, 0x37, 0x54, 0xEA,
  40087. 0xC8, 0xA3, 0x0B, 0x36, 0xC1, 0x00, 0x04, 0xEF,
  40088. 0x13, 0xC6, 0x92, 0xE2, 0x19, 0xAA, 0x7A, 0xF0,
  40089. 0xA4, 0xC5, 0x28, 0x69, 0x10, 0xC7, 0x10, 0x0D,
  40090. 0xA4, 0x1E, 0x17, 0xBB, 0xEF, 0x2D, 0xA2, 0xAB,
  40091. 0x03, 0xAD, 0xF3, 0x07, 0x4B, 0xA1, 0xDA, 0x15,
  40092. 0xBC, 0xC8, 0x48, 0x05, 0xB8, 0x9B, 0x9D, 0xA8,
  40093. 0x8E, 0x9B, 0x40, 0x0A, 0xFB, 0x7E, 0x3B, 0xC8,
  40094. 0x33, 0x8D, 0x35, 0x4D, 0xA9, 0x53, 0xAC, 0x0B,
  40095. 0xAD, 0x82, 0x27, 0x56, 0xCA, 0x92, 0xE5, 0xDD,
  40096. 0x95, 0x07, 0xF4, 0x2B, 0xFE, 0xFC, 0xCB, 0x32,
  40097. 0xB4, 0xB9, 0x1A, 0x2B, 0xE5, 0xEF, 0x34, 0xC2,
  40098. 0xCF, 0x11, 0x77, 0xEA, 0xAF, 0xB2, 0x50, 0xAC,
  40099. 0x9A, 0xDE, 0xC4, 0xBE, 0x71, 0x80, 0x75, 0x89,
  40100. 0xF1, 0x00, 0x32, 0x27, 0xF9, 0xB7, 0x6B, 0x74,
  40101. 0xE0, 0x7B, 0xA6, 0x7A, 0xC6, 0x08, 0x19, 0xB2,
  40102. 0xAF, 0x76, 0x6A, 0x47, 0xFF, 0xFC, 0x7B, 0x76,
  40103. 0xD3, 0xA7, 0xC0, 0x77, 0xF5, 0xEC, 0x69, 0xAE,
  40104. 0xEA, 0x3E, 0x96, 0x38, 0x59, 0xB8, 0x2C, 0x2A,
  40105. 0xDE, 0x58, 0xBE, 0xC2, 0x15, 0x2E, 0xC8, 0x20,
  40106. 0x51, 0x10, 0x97, 0x5D, 0x37, 0xC6, 0x50, 0x5E,
  40107. 0x0D, 0xC7, 0x76, 0xFD, 0xE0, 0x71, 0x09, 0x7E,
  40108. 0x93, 0x01, 0x3D, 0x10, 0x04, 0xF4, 0xE1, 0xA2,
  40109. 0xFD, 0x79, 0xB8, 0x77, 0xED, 0x50, 0x25, 0xF5,
  40110. 0x27, 0xF3, 0xBF, 0xF1, 0x37, 0xF0, 0x41, 0xBB,
  40111. 0x9B, 0xD0, 0x01, 0xE9, 0x49, 0xF0, 0x8B, 0x4C,
  40112. 0xF8, 0x8D, 0xFD, 0x32, 0xFC, 0x7C, 0xDB, 0xCE,
  40113. 0xCC, 0xFD, 0xB0, 0xFA, 0x2D, 0xE7, 0x82, 0x3E,
  40114. 0x11, 0x0B, 0xCF, 0xF5, 0x8A, 0x41, 0x2C, 0xEA,
  40115. 0x27, 0x95, 0x75, 0x3E, 0x9C, 0x89, 0x67, 0x8C,
  40116. 0x3A, 0xE2, 0x42, 0x68, 0xF7, 0x48, 0x9F, 0x72,
  40117. 0x97, 0x4B, 0x69, 0x55, 0xED, 0xD0, 0x4E, 0x19,
  40118. 0x0D, 0x99, 0xBB, 0x0D, 0x7A, 0x25, 0x2F, 0xAD,
  40119. 0x5B, 0xBA, 0x60, 0x6C, 0x1A, 0x1F, 0x3A, 0xCA,
  40120. 0x73, 0x3B, 0xFA, 0xE3, 0x30, 0x9E, 0xA0, 0xA6,
  40121. 0xEB, 0x7D, 0x07, 0xE3, 0x6D, 0x8C, 0xA3, 0x36,
  40122. 0xD2, 0x64, 0x4F, 0xCE, 0x1A, 0x41, 0x89, 0x5D,
  40123. 0x01, 0x4D, 0x1A, 0x60, 0xCB, 0x10, 0x6F, 0x3F,
  40124. 0x80, 0x75, 0xF9, 0x37, 0x84, 0x61, 0x73, 0x8D,
  40125. 0x63, 0xD1, 0x15, 0xD0, 0x0B, 0x02, 0x4C, 0x67,
  40126. 0x78, 0x01, 0x05, 0x0A, 0x1B, 0x0B, 0x50, 0xDE,
  40127. 0x05, 0x7F, 0x85, 0xDB, 0x6A, 0xEB, 0x2C, 0x9D,
  40128. 0x6B, 0xB7, 0x40, 0x2A, 0x66, 0xE3, 0xAB, 0x4D,
  40129. 0xB0, 0x5C, 0x58, 0xBB, 0xDA, 0x12, 0xF6, 0x95,
  40130. 0x95, 0x8B, 0x8A, 0xC7, 0xB4, 0xE4, 0x5E, 0xC6,
  40131. 0xC9, 0x52, 0xF6, 0x79, 0xC1, 0xEE, 0xBD, 0xF8,
  40132. 0x60, 0xE3, 0x48, 0x98, 0x27, 0x79, 0xAA, 0x69,
  40133. 0x88, 0xEF, 0xC2, 0xAD, 0x1D, 0xC1, 0xEA, 0xE2,
  40134. 0x2A, 0x27, 0xA5, 0xB2, 0xC6, 0x1C, 0x97, 0xB3,
  40135. 0xB2, 0x49, 0x3C, 0xB6, 0xC1, 0x3C, 0x5F, 0x6E,
  40136. 0x20, 0xA6, 0x7B, 0x88, 0xD3, 0xC3, 0xAC, 0xCF,
  40137. 0xAF, 0x0A, 0x42, 0x57, 0x42, 0xDF, 0x24, 0x06,
  40138. 0x34, 0xD1, 0xEE, 0x59, 0x38, 0x28, 0xFE, 0x62,
  40139. 0x97, 0x44, 0x6C, 0x07, 0x6F, 0x97, 0x90, 0x55,
  40140. 0x98, 0x8A, 0xB8, 0x34, 0xB2, 0xBD, 0x82, 0xE1,
  40141. 0x4D, 0xC0, 0x86, 0x40, 0x0E, 0x1C, 0x95, 0x6C,
  40142. 0xC0, 0xC3, 0x0C, 0xE7, 0xBF, 0xD9, 0x62, 0x22,
  40143. 0x3D, 0x23, 0xFE, 0x94, 0x94, 0x96, 0x4A, 0x81,
  40144. 0x1B, 0x93, 0xE8, 0xD7, 0xB8, 0xF3, 0x4C, 0x89,
  40145. 0xAA, 0xD4, 0x5D, 0xD4, 0x11, 0x3F, 0x2A, 0xE7,
  40146. 0xBD, 0x94, 0xB5, 0x3F, 0xC8, 0x6E, 0x8B, 0x2A,
  40147. 0xE8, 0x2E, 0x51, 0xEC, 0x6F, 0x3E, 0xA4, 0xC3,
  40148. 0x0D, 0x60, 0xB8, 0x60, 0x72, 0x74, 0x86, 0x12,
  40149. 0xD1, 0x60, 0x70, 0x56, 0xB5, 0xFF, 0x6A, 0x45,
  40150. 0x00, 0xEE, 0xE7, 0x8A, 0x5A, 0x63, 0x9C, 0x7B,
  40151. 0x74, 0x16, 0x97, 0x77, 0x62, 0x68, 0x64, 0xDD,
  40152. 0x9E, 0xAE, 0xF0, 0xE3, 0xAD, 0x84, 0x93, 0xD8,
  40153. 0x31, 0xF7, 0x1D, 0xEA, 0x95, 0xBB, 0xFC, 0xF8,
  40154. 0x14, 0x23, 0xA2, 0x66, 0xDE, 0x56, 0xF3, 0xA8,
  40155. 0xFE, 0x8E, 0x6C, 0x3C, 0x0D, 0x61, 0x2F, 0xB6,
  40156. 0x2B, 0xD6, 0x42, 0x18, 0x8C, 0xA7, 0x1C, 0xB8,
  40157. 0x98, 0x34, 0xF3, 0x0B, 0xCC, 0x28, 0xBD, 0x17,
  40158. 0x88, 0x45, 0xF1, 0xF6, 0xF4, 0x6C, 0x03, 0xD3,
  40159. 0x06, 0xF7, 0xED, 0x4E, 0x68, 0x75, 0x94, 0x27,
  40160. 0xAE, 0xC2, 0x70, 0x11, 0x98, 0xC3, 0xC0, 0x5D,
  40161. 0x38, 0x5D, 0xFA, 0xFD, 0x52, 0x8C, 0xCE, 0x84,
  40162. 0x25, 0xBC, 0x55, 0x14, 0x69, 0xA0, 0xED, 0x68,
  40163. 0x1B, 0xEE, 0x4D, 0x12, 0xA8, 0x43, 0xE3, 0x33,
  40164. 0xB5, 0xA8, 0xE0, 0x51, 0x7F, 0xC6, 0x19, 0x06,
  40165. 0xF9, 0xC4, 0xE7, 0x80, 0x9B, 0xAE, 0xD4, 0xD3,
  40166. 0xD1, 0x6E, 0xB2, 0x2F, 0x1F, 0xA9, 0xAB, 0x40,
  40167. 0x2D, 0x98, 0x8E, 0xD5, 0x9F, 0x9F, 0xED, 0x04,
  40168. 0x55, 0xE9, 0x26, 0x0F, 0xD6, 0x27, 0xA2, 0x4A,
  40169. 0x17, 0xFE, 0x7C, 0xB6, 0x3E, 0x53, 0x0B, 0x48,
  40170. 0xF5, 0xFB, 0x66, 0x87, 0xA2, 0xE8, 0xC4, 0x9D,
  40171. 0xA7, 0x9F, 0xBD, 0x69, 0xA3, 0x40, 0x00, 0x56,
  40172. 0x66, 0x5D, 0xD1, 0x1D, 0x19, 0xA2, 0xBC, 0x4D,
  40173. 0xB1, 0xD3, 0x74, 0xAB, 0x6A, 0x6E, 0x42, 0x47,
  40174. 0x2A, 0x27, 0xAC, 0x6B, 0x98, 0xF6, 0x76, 0xE8,
  40175. 0xED, 0xAA, 0xDD, 0x51, 0x4F, 0x6D, 0x44, 0xDE,
  40176. 0xEC, 0xDA, 0xB5, 0xA6, 0xDF, 0xA0, 0xF8, 0x4F,
  40177. 0x13, 0x9A, 0x80, 0x3A, 0x25, 0x24, 0xBF, 0x33,
  40178. 0x5D, 0xC5, 0x2E, 0xA5, 0x8F, 0xA5, 0x0D, 0x98,
  40179. 0xFB, 0x5C, 0xD5, 0x5D, 0x5D, 0x50, 0xA6, 0x63,
  40180. 0xCF, 0x64, 0x7E, 0xEE, 0x56, 0xFE, 0x8E, 0x66,
  40181. 0x4B, 0x3B, 0xCA, 0xF9, 0xE3, 0x33, 0x97, 0x8A,
  40182. 0x79, 0x46, 0x97, 0x3F, 0xD1, 0x13, 0xE4, 0xFD,
  40183. 0x39, 0x24, 0xE6, 0xC0, 0x9E, 0x60, 0x38, 0x64,
  40184. 0x44, 0x21, 0x4D, 0xFA, 0x7A, 0x4D, 0x67, 0x1F,
  40185. 0xC2, 0x38, 0x90, 0x63, 0x7E, 0xB8, 0x59, 0x13,
  40186. 0x4D, 0x79, 0xE2, 0x65, 0xC5, 0x9C, 0xA3, 0xEC,
  40187. 0xCD, 0xDF, 0xA0, 0x18, 0x22, 0x3C, 0x9B, 0xAE,
  40188. 0x1C, 0xCA, 0x10, 0x39, 0x62, 0x07, 0x8B, 0xC5,
  40189. 0xF0, 0xDD, 0x02, 0x24, 0x6F, 0xA2, 0x83, 0x24,
  40190. 0xF7, 0xCB, 0x2F, 0xCF, 0xAD, 0x07, 0xC2, 0x5B,
  40191. 0x4B, 0xC2, 0xD8, 0x88, 0x06, 0x9B, 0x0C, 0xF5,
  40192. 0xF2, 0x3C, 0x76, 0x1C, 0x0E, 0x47, 0x10, 0x98,
  40193. 0x81, 0xCD, 0x31, 0x45, 0x6A, 0x64, 0xB9, 0x40,
  40194. 0xB4, 0xBB, 0x9B, 0x4C, 0x2C, 0x3B, 0x8E, 0x6B,
  40195. 0xA8, 0x34, 0xAA, 0xAE, 0x69, 0xFD, 0xFC, 0x47,
  40196. 0xD4, 0x4B, 0x3C, 0x96, 0x88, 0x7A, 0xBE, 0xD3,
  40197. 0x60, 0x15, 0xE7, 0xB6, 0x4E, 0x85, 0x42, 0x92,
  40198. 0x8F, 0x27, 0x7C, 0xBD, 0x2D, 0x3C, 0x51, 0x2C,
  40199. 0x24, 0xDE, 0xEF, 0xE5, 0x90, 0xE8, 0x1C, 0x68,
  40200. 0x4E, 0x06, 0x3E, 0x7A, 0xAD, 0xCF, 0x11, 0x7B,
  40201. 0x48, 0x94, 0x3D, 0xB7, 0x71, 0xFC, 0x22, 0x07,
  40202. 0xF5, 0x7A, 0x74, 0x53, 0x57, 0x55, 0x5D, 0x41,
  40203. 0x9C, 0x9C, 0xDC, 0xA3, 0x5C, 0xC1, 0xA7, 0x10,
  40204. 0x0A, 0x69, 0x13, 0xA3, 0xB6, 0xAA, 0xCF, 0x79,
  40205. 0x6F, 0xE3, 0xF9, 0x4D, 0xD2, 0xF8, 0x18, 0x98,
  40206. 0x27, 0x16, 0xCE, 0x03, 0x16, 0x54, 0x2A, 0x1B,
  40207. 0x95, 0x7E, 0x12, 0xDA, 0x43, 0xE2, 0x31, 0x54,
  40208. 0x2C, 0xC1, 0x4F, 0xCC, 0x66, 0xD7, 0x28, 0xA6,
  40209. 0x83, 0x26, 0xB2, 0xBC, 0x31, 0x12, 0x48, 0x33,
  40210. 0x0F, 0x3E, 0x98, 0xF8, 0x1E, 0xA3, 0x8C, 0xA9,
  40211. 0x24, 0xA8, 0xE4, 0xDA, 0x97, 0xCF, 0x67, 0x38,
  40212. 0x42, 0xC7, 0x59, 0xF9, 0x35, 0xBE, 0x88, 0x16,
  40213. 0x3C, 0xE9, 0x7F, 0xE4, 0xD9, 0x45, 0x71, 0x76,
  40214. 0xF5, 0xB8, 0x90, 0x8A, 0xF9, 0x48, 0xF7, 0x4D,
  40215. 0x5D, 0x1D, 0xDB, 0xC5, 0x21, 0x82, 0x5D, 0x93,
  40216. 0x1C, 0x63, 0xCA, 0x8A, 0x8E, 0x12, 0x24, 0x26,
  40217. 0x26, 0x30, 0x5A, 0xB6, 0xA2, 0xE0, 0x62, 0x45,
  40218. 0x64, 0xEE, 0x04, 0x19, 0x83, 0xC1, 0x8C, 0x29,
  40219. 0x52, 0xEC, 0x3D, 0x9D, 0x15, 0x9B, 0xDE, 0x39,
  40220. 0x85, 0xCF, 0x77, 0x89, 0x7E, 0xE2, 0xDC, 0x88,
  40221. 0x81, 0x12, 0x72, 0x1D, 0x48, 0x54, 0xE9, 0x14,
  40222. 0xA5, 0x39, 0x7E, 0x08, 0xB5, 0x4F, 0x4A, 0x54,
  40223. 0x32, 0x3F, 0xF8, 0x20, 0x82, 0x1B, 0xE0, 0x26,
  40224. 0xEA, 0x09, 0x1E, 0xCA, 0x6B, 0x7D, 0x80, 0xD9,
  40225. 0x1E, 0x3D, 0xCA, 0x2E, 0xF7, 0x84, 0x8B, 0x86,
  40226. 0xFC, 0xA6, 0xBB, 0x40, 0xCE, 0x48, 0x27, 0x1E,
  40227. 0x10, 0x08, 0x36, 0x8E, 0x3E, 0xBB, 0x5E, 0x39,
  40228. 0x5E, 0x1C, 0xCD, 0x0D, 0x17, 0x8F, 0x1A, 0x62,
  40229. 0x57, 0xD2, 0x6B, 0x6B, 0xA4, 0xB7, 0xCE, 0x53,
  40230. 0x2C, 0xAA, 0x1E, 0x76, 0xCE, 0x28, 0xFA, 0x4C,
  40231. 0xF9, 0xE0, 0x29, 0xE2, 0x48, 0x2B, 0x94, 0xD3,
  40232. 0xAC, 0xF9, 0x7A, 0x32, 0x6D, 0x23, 0x5D, 0x1B,
  40233. 0xDC, 0x89, 0xF7, 0x00, 0x02, 0x19, 0x84, 0x51,
  40234. 0xD9, 0xF1, 0xF1, 0x2C, 0xCD, 0x5B, 0xCA, 0xEC,
  40235. 0xDD, 0xE9, 0xE1, 0x4A, 0xC8, 0x07, 0x42, 0xEB,
  40236. 0x31, 0xE6, 0x46, 0x4C, 0x83, 0x21, 0x0A, 0x39,
  40237. 0xF3, 0x50, 0x98, 0xBE, 0x03, 0x78, 0xD0, 0x74,
  40238. 0xCE, 0x1C, 0xCD, 0x1E, 0xBC, 0x1C, 0x77, 0x70,
  40239. 0xF7, 0x78, 0xD6, 0x05, 0xF2, 0xBE, 0x59, 0xDB,
  40240. 0x7E, 0xA0, 0x7D, 0x80, 0xCC, 0xDF, 0x55, 0xF1,
  40241. 0x6E, 0x98, 0x5B, 0x14, 0x2F, 0xB7, 0xBD, 0xA0,
  40242. 0x7A, 0xA7, 0xDC, 0xA5, 0xB2, 0x01, 0xE1, 0x95,
  40243. 0x0C, 0xF9, 0xA7, 0x28, 0xF2, 0x1E, 0x9A, 0x9D,
  40244. 0x8A, 0xC4, 0xD1, 0x32, 0x7E, 0x3B, 0xC0, 0xFF,
  40245. 0x33, 0x9A, 0x25, 0x05, 0x22, 0xF6, 0x31, 0xDF,
  40246. 0x2E, 0x75, 0x95, 0x51, 0x54, 0x89, 0x3E, 0x4A,
  40247. 0x1A, 0xAF, 0x98, 0x66, 0xFE, 0xE1, 0x63, 0x7E,
  40248. 0xE1, 0xAA, 0x51, 0x06, 0xD2, 0x44, 0xE9, 0x9E,
  40249. 0x6F, 0x31, 0xFC, 0x56, 0x01, 0xBB, 0x7B, 0x79,
  40250. 0xBA, 0xD8, 0x28, 0x60, 0xB1, 0xD6, 0x05, 0x9D,
  40251. 0x9B, 0x13, 0x2E, 0x02, 0x64, 0x18, 0x02, 0x0D,
  40252. 0xB0, 0x6E, 0xB8, 0x39, 0x1F, 0xA1, 0x5B, 0x7A,
  40253. 0x0F, 0x29, 0xE3, 0x6D, 0x96, 0x6A, 0xBD, 0x3D,
  40254. 0x2A, 0x2F, 0xF3, 0xF2, 0xAA, 0xC3, 0x4C, 0x8B,
  40255. 0x45, 0xC7, 0xD2, 0x35, 0x5E, 0xDB, 0xB8, 0x0B,
  40256. 0x22, 0x4B, 0xC1, 0x06, 0xEB, 0xC6, 0x75, 0x0E,
  40257. 0x55, 0x07, 0x0F, 0x85, 0xA7, 0xCB, 0x60, 0x03,
  40258. 0x39, 0x4E, 0x51, 0x61, 0xAE, 0x26, 0xF5, 0xAB,
  40259. 0xF8, 0x3F, 0x0D, 0xCC, 0xCF, 0x69, 0xB8, 0x61,
  40260. 0x39, 0xAF, 0x86, 0x94, 0xFE, 0x1D, 0xC0, 0x07,
  40261. 0x81, 0xEA, 0xE0, 0x9C, 0xDB, 0x42, 0x18, 0x14,
  40262. 0x87, 0x80, 0x43, 0xDC, 0x9B, 0x05, 0x30, 0xE5,
  40263. 0x54, 0x5A, 0x16, 0x5E, 0x39, 0xA9, 0xB7, 0xDE,
  40264. 0x88, 0xB4, 0xAD, 0x2A, 0xEB, 0x90, 0xD3, 0xC3,
  40265. 0x29, 0x41, 0x2E, 0xD2, 0xFE, 0x1D, 0x97, 0xB7,
  40266. 0x32, 0xC8, 0x43, 0x9D, 0xF4, 0xF8, 0x3D, 0x22,
  40267. 0x88, 0x35, 0xB5, 0x38, 0xDC, 0x27, 0x8F, 0xF0,
  40268. 0xA2, 0xDC, 0x42, 0xF4, 0x1B, 0x00, 0xCE, 0x3A,
  40269. 0xCA, 0x06, 0xB0, 0x5C, 0x48, 0x39, 0xB8, 0x96,
  40270. 0x93, 0x15, 0x15, 0xD7, 0x8E, 0xA3, 0x67, 0x3A,
  40271. 0x37, 0x82, 0x79, 0xF4, 0xE8, 0x9C, 0xE0, 0x8E,
  40272. 0x34, 0x53, 0xFF, 0x2F, 0xB4, 0x53, 0xBE, 0x03,
  40273. 0x1C, 0x63, 0x18, 0x62, 0x8A, 0x73, 0x1D, 0x02,
  40274. 0x9F, 0xC7, 0xBE, 0xA2, 0xBA, 0x5E, 0xAC, 0x49,
  40275. 0x16, 0x27, 0x8B, 0x93, 0x8A, 0x6A, 0x6A, 0xCE,
  40276. 0xF5, 0xBF, 0xE2, 0x15, 0x8F, 0x2A, 0xF4, 0x3D,
  40277. 0x8E, 0x56, 0xA0, 0x64, 0x9D, 0xF2, 0x8A, 0x25,
  40278. 0x0D, 0x2F, 0x25, 0x36, 0xAB, 0xDE, 0x1E, 0x00,
  40279. 0x8E, 0xB6, 0x31, 0xF4, 0xBD, 0x0E, 0xB5, 0x55,
  40280. 0x73, 0xA4, 0x05, 0x39, 0xA6, 0x00, 0x41, 0x81,
  40281. 0xA9, 0xD2, 0xBF, 0x7A, 0x1E, 0x53, 0x50, 0x4F,
  40282. 0x11, 0xE0, 0x14, 0x84, 0x07, 0x33, 0x84, 0x41,
  40283. 0x31, 0xAC, 0x66, 0x89, 0x46, 0xE5, 0xB8, 0x27,
  40284. 0x28, 0x9A, 0xB6, 0xB2, 0x13, 0x66, 0xC5, 0xD0,
  40285. 0xE2, 0x64, 0x92, 0x19, 0xB9, 0x2C, 0x47, 0x60,
  40286. 0xDF, 0xB7, 0x05, 0xF7, 0xF6, 0x1A, 0x96, 0x56,
  40287. 0x4C, 0x9E, 0x84, 0x0D, 0x14, 0xB0, 0xBB, 0x0D,
  40288. 0xA8, 0x2D, 0xA5, 0x0F, 0x8B, 0x8E, 0x75, 0x2B,
  40289. 0xBF, 0xEA, 0x3B, 0x0A, 0x33, 0x7B, 0xE1, 0x24,
  40290. 0xF7, 0x2D, 0x8F, 0x82, 0x49, 0x19, 0x5B, 0xC1,
  40291. 0x9C, 0x3E, 0x0B, 0x62, 0xEA, 0xE4, 0x96, 0xD3,
  40292. 0x8C, 0xF7, 0x50, 0x0B, 0x4F, 0x10, 0x66, 0x5F,
  40293. 0xC2, 0xD2, 0x8B, 0x9E, 0xA9, 0x35, 0xF7, 0xE3,
  40294. 0x16, 0x47, 0x2F, 0x4F, 0xF4, 0x01, 0x26, 0x75,
  40295. 0x41, 0xBD, 0xB6, 0x23, 0x01, 0x55, 0x4B, 0x20,
  40296. 0x09, 0x92, 0x8C, 0x64, 0x45, 0xBB, 0xD0, 0xEF,
  40297. 0x21, 0xD0, 0x99, 0x72, 0xF3, 0x50, 0x81, 0xAB,
  40298. 0xA9, 0x09, 0x1A, 0x6C, 0x23, 0xFE, 0xD2, 0x9F,
  40299. 0x5C, 0xF9, 0xE0, 0x77, 0x9F, 0x7E, 0xFB, 0xAD,
  40300. 0x88, 0xE6, 0x2A, 0x45, 0x44, 0x42, 0xB3, 0x00,
  40301. 0x79, 0xBE, 0x0A, 0xC9, 0xC6, 0x48, 0x26, 0xB9,
  40302. 0x8C, 0x1E, 0x10, 0x01, 0xCB, 0x0F, 0xB0, 0xF0,
  40303. 0xA9, 0x5F, 0x79, 0x65, 0xFE, 0x93, 0x12, 0xBF,
  40304. 0xDA, 0xEC, 0x33, 0xF9, 0x50, 0x65, 0xC8, 0xE5,
  40305. 0x9D, 0x39, 0x50, 0xF8, 0x0A, 0xDC, 0x7F, 0xB3,
  40306. 0x34, 0xF2, 0x02, 0xD3, 0xE5, 0xF8, 0xDA, 0x48,
  40307. 0x1C, 0x9B, 0x54, 0xA7, 0x59, 0x83, 0x93, 0x0F,
  40308. 0xD1, 0xE5, 0xAC, 0xD1, 0x62, 0x84, 0xF0, 0x71,
  40309. 0x93, 0xFB, 0xCB, 0x50, 0xD0, 0xDC, 0x00, 0xEF,
  40310. 0xF8, 0x20, 0x31, 0x44, 0xC1, 0x1E, 0xC6, 0x14,
  40311. 0x20, 0xFC, 0x32, 0xD7, 0x98, 0x2C, 0xE8, 0x96,
  40312. 0x40, 0x6B, 0xE7, 0x69, 0xA7, 0x5D, 0xD8, 0xD3,
  40313. 0xCA, 0xC7, 0x53, 0xAB, 0xE5, 0xA2, 0x78, 0x65,
  40314. 0x5B, 0xF5, 0x4B, 0xE3, 0x3A, 0x1B, 0x83, 0x74,
  40315. 0xEB, 0xEE, 0xFF, 0x21, 0x2C, 0x39, 0xCE, 0x51,
  40316. 0x46, 0x68, 0xF1, 0xC4, 0x56, 0xEA, 0xA2, 0x53,
  40317. 0x28, 0x28, 0xC8, 0x42, 0x93, 0xF1, 0xA5, 0xBC,
  40318. 0x9E, 0xB5, 0xDE, 0xDF, 0x55, 0x8A, 0x9B, 0x4C,
  40319. 0x12, 0x39, 0xF7, 0x72, 0x72, 0xC6, 0x7E, 0x1A,
  40320. 0xB2, 0x8E, 0x1E, 0xFE, 0xC5, 0x89, 0x3E, 0x09,
  40321. 0xC1, 0x06, 0x62, 0xB5, 0x3C, 0x8B, 0x82, 0x55,
  40322. 0xB1, 0xC8, 0xDC, 0x8F, 0x8E, 0x51, 0x20, 0xA2,
  40323. 0x5C, 0x75, 0xEE, 0xFE, 0x79, 0xC4, 0x3F, 0x7A,
  40324. 0x8B, 0x37, 0xDF, 0x9D, 0x1E, 0x4F, 0x32, 0x48,
  40325. 0x69, 0x33, 0xDA, 0x1C, 0xB0, 0x66, 0x4C, 0x5D,
  40326. 0xB3, 0x9E, 0x21, 0xBC, 0x22, 0x7B, 0x0C, 0xDF,
  40327. 0xE7, 0xA5, 0x50, 0x7F, 0x07, 0xF2, 0x18, 0xA7,
  40328. 0xA4, 0x7D, 0xEB, 0xCD, 0x9D, 0xAD, 0x72, 0x47,
  40329. 0xB4, 0xD0, 0x45, 0xA1, 0x3A, 0xD4, 0xF7, 0x5E,
  40330. 0xAD, 0x2D, 0x45, 0xC3, 0x39, 0xD0, 0xDF, 0x04,
  40331. 0x57, 0x7F, 0x2E, 0x0F, 0xDC, 0x78, 0x03, 0x92,
  40332. 0x55, 0x30, 0x33, 0xC7, 0x38, 0x85, 0x2B, 0x1B,
  40333. 0xE4, 0xE6, 0x3E, 0xA3, 0x89, 0x7D, 0x6C, 0x9C,
  40334. 0x4B, 0x11, 0xAD, 0x6B, 0x58, 0xD3, 0xE2, 0xD3,
  40335. 0x42, 0xD3, 0x28, 0x40, 0xF6, 0x49, 0xDD, 0x83,
  40336. 0xE7, 0x59, 0x86, 0x6B, 0x73, 0x81, 0xA8, 0x4C,
  40337. 0x8A, 0xDD, 0xDF, 0x41, 0x3F, 0xAE, 0x18, 0xE6,
  40338. 0x43, 0x1B, 0x1E, 0xEA, 0x73, 0xA5, 0x6C, 0xD8,
  40339. 0x89, 0xB7, 0x6B, 0xC9, 0x78, 0x6B, 0xED, 0xED,
  40340. 0xCA, 0x25, 0x41, 0xE4, 0xC9, 0xB2, 0x4E, 0x28,
  40341. 0xF5, 0x8A, 0xD3, 0x74, 0xC1, 0xD9, 0x3D, 0xF2,
  40342. 0xD3, 0xF2, 0xC3, 0x7E, 0xC5, 0x94, 0xA0, 0x49,
  40343. 0x8C, 0x57, 0x45, 0x79, 0xA7, 0x33, 0x2F, 0x72,
  40344. 0xC0, 0xF9, 0x75, 0x08, 0x77, 0xFA, 0xD5, 0xB9,
  40345. 0x0B, 0x96, 0x8D, 0x88, 0xF1, 0x16, 0x82, 0xC4,
  40346. 0x07, 0x1E, 0x4E, 0xA3, 0x8B, 0x81, 0x6A, 0xEA,
  40347. 0xD6, 0xBE, 0x54, 0xD2, 0xF3, 0x71, 0x32, 0x4F,
  40348. 0x24, 0x75, 0xB8, 0x62, 0xC7, 0x54, 0x24, 0xEC,
  40349. 0xF9, 0x85, 0x8A, 0xA4, 0xE2, 0x00, 0xCF, 0xBA,
  40350. 0x41, 0x2D, 0x7E, 0x3E, 0x6C, 0x30, 0x8D, 0x8D,
  40351. 0xE1, 0x1D, 0xD1, 0x85, 0x33, 0x1A, 0xF9, 0xD4,
  40352. 0x1A, 0xFE, 0x88, 0x79, 0x96, 0x5D, 0x67, 0x46,
  40353. 0xEF, 0x21, 0xFD, 0x98, 0xD3, 0xED, 0x38, 0x06,
  40354. 0xFB, 0x5C, 0x46, 0x19, 0xC9, 0x8E, 0x34, 0x7D,
  40355. 0x76, 0xB8, 0xB8, 0x98, 0x49, 0x39, 0x55, 0x61,
  40356. 0xEE, 0x28, 0x6D, 0xFD, 0xFC, 0x6A, 0x04, 0xE1,
  40357. 0xD4, 0x7E, 0x9F, 0x5B, 0x5B, 0x49, 0x25, 0x77,
  40358. 0x84, 0xC3, 0x93, 0x64, 0xDF, 0xA8, 0x8A, 0xD6,
  40359. 0x30, 0xDF, 0xA5, 0x9C, 0xCA, 0x32, 0x37, 0xF4,
  40360. 0xA2, 0xB1, 0x41, 0xA8, 0x13, 0xD2, 0x2C, 0x6F,
  40361. 0xFE, 0x73, 0xC2, 0xD9, 0x9A, 0xDC, 0x82, 0x4D,
  40362. 0x93, 0xE0, 0x6A, 0x54, 0xB6, 0xDE, 0x62, 0xC3,
  40363. 0x12, 0x5D, 0x94, 0xB4, 0x9E, 0x95, 0x0D, 0xEC,
  40364. 0x36, 0x1F, 0x96, 0x1F, 0x56, 0xD3, 0x67, 0x1C,
  40365. 0x99, 0x25, 0x37, 0x7F, 0x6E, 0x67, 0x06, 0x65,
  40366. 0x32, 0x2B, 0x84, 0x89, 0xE8, 0x33, 0xD3, 0x83,
  40367. 0x0E, 0xCC, 0xDD, 0x0F, 0x53, 0xF4, 0xA4, 0xF9,
  40368. 0xD6, 0x8F, 0x14, 0x45, 0xF3, 0xAE, 0xD5, 0xC9,
  40369. 0xD7, 0x66, 0x40, 0x9B, 0x59, 0xBA, 0xE7, 0xA7,
  40370. 0x29, 0x12, 0xE9, 0x8B, 0x3B, 0xB5, 0x73, 0x42,
  40371. 0xD2, 0x9B, 0x6A, 0xCF, 0xD1, 0x43, 0x36, 0xB7,
  40372. 0xB8, 0xB6, 0xB7, 0x54, 0x9A, 0xF8, 0xCC, 0x88,
  40373. 0x45, 0xE1, 0x0C, 0x28, 0x11, 0x28, 0x72, 0x81,
  40374. 0x98, 0x5D, 0x5D, 0x47, 0x68, 0x5F, 0xC5, 0x89,
  40375. 0xF2, 0x67, 0x8E, 0xD8, 0x93, 0xF5, 0x7B, 0x85,
  40376. 0xAC, 0xED, 0x75, 0x63, 0x2E, 0x50, 0xDE, 0x5E,
  40377. 0x07, 0x4E, 0x6C, 0xED, 0xCF, 0x1A, 0xD4, 0x99,
  40378. 0xBC, 0xE6, 0x7A, 0x7F, 0x49, 0x85, 0x64, 0xDE,
  40379. 0xEC, 0x67, 0x7C, 0x70, 0x83, 0x88, 0xDE, 0x8F,
  40380. 0xD7, 0xB0, 0x99, 0xCF, 0xC1, 0x16, 0x09, 0x6C,
  40381. 0x45, 0xFE, 0x28, 0x89, 0x0B, 0x5E, 0xAF, 0x06,
  40382. 0x16, 0x99, 0x39, 0xFD, 0xA3, 0x5E, 0x12, 0x15,
  40383. 0xF2, 0x38, 0xE8, 0xCD, 0xED, 0xFE, 0x67, 0x00,
  40384. 0x65, 0xF5, 0xDE, 0x32, 0x72, 0xA2, 0x32, 0xFD,
  40385. 0x53, 0xC2, 0x50, 0xF5, 0xD7, 0x79, 0xB3, 0x16,
  40386. 0x94, 0xFB, 0xA9, 0x1B, 0x55, 0x48, 0x03, 0x67,
  40387. 0x6E, 0x4D, 0xEA, 0x28, 0x84, 0x63, 0xFE, 0x10,
  40388. 0x63, 0x00, 0x9E, 0x9C, 0xB7, 0x6C, 0x31, 0x7D,
  40389. 0xB4, 0x00, 0xAC, 0xF4, 0xD2, 0xD2, 0xB6, 0xD1,
  40390. 0x6E, 0xDE, 0xBA, 0x41, 0x08, 0x91, 0x3F, 0x60,
  40391. 0xAE, 0xB2, 0x52, 0xCD, 0xE4, 0x13, 0x69, 0x0C,
  40392. 0xEE, 0xFD, 0xCF, 0xA6, 0x38, 0x96, 0x3D, 0xBD,
  40393. 0x04, 0xF4, 0xCF, 0x21, 0xAD, 0x74, 0xDD, 0xE6,
  40394. 0x5F, 0x0F, 0x1E, 0x7C, 0xE7, 0x0A, 0xF1, 0x01,
  40395. 0xA6, 0xDE, 0x9A, 0x59, 0xDB, 0x21, 0xD3, 0x80,
  40396. 0x27, 0xDB, 0xBF, 0x76, 0x16, 0x78, 0x27, 0x95,
  40397. 0x0B, 0x69, 0x41, 0x82, 0x66, 0xAF, 0xA4, 0x44,
  40398. 0xC7, 0x28, 0xDE, 0x36, 0x24, 0xA1, 0xC8, 0x1E,
  40399. 0x5B, 0x16, 0x41, 0xDB, 0xE8, 0x79, 0xCD, 0x82,
  40400. 0x2F, 0xB2, 0x30, 0x3C, 0xC3, 0xA9, 0xFC, 0xEE,
  40401. 0xFE, 0x3D, 0xDF, 0x7D, 0xBD, 0x0B, 0x70, 0x57,
  40402. 0x24, 0x8A, 0x28, 0xD6, 0x06, 0x2D, 0x76, 0xEB,
  40403. 0x13, 0xB9, 0x2C, 0x9C, 0x9D, 0x00, 0x3B, 0x69,
  40404. 0xE1, 0x84, 0x2A, 0x54, 0xC0, 0x9C, 0xF6, 0xB4,
  40405. 0x84, 0x52, 0x08, 0x15, 0xE2, 0xBB, 0x23, 0x72,
  40406. 0x88, 0xC6, 0x4F, 0xC6, 0x96, 0xFD, 0x3B, 0xC4,
  40407. 0x5D, 0xB3, 0x0C, 0xB8, 0x64, 0x65, 0xDF, 0x11,
  40408. 0x88, 0xBF, 0x47, 0x95, 0x6E, 0x5B, 0x91, 0x6A,
  40409. 0x80, 0x09, 0x71, 0x5C, 0xC9, 0xA9, 0xA6, 0xDC,
  40410. 0xE4, 0x4C, 0x54, 0xF9, 0x28, 0x81, 0x6B, 0x41,
  40411. 0xD0, 0x18, 0xC5, 0xFE, 0x65, 0x2F, 0xFE, 0x4E,
  40412. 0x33, 0xF3, 0x52, 0xD3, 0x83, 0xA9, 0xC1, 0x36,
  40413. 0x5F, 0x02, 0xAB, 0xFD, 0x64, 0x7B, 0xD6, 0xB4,
  40414. 0x2A, 0xD1, 0x63, 0x73, 0x0F, 0x8B, 0xFD, 0xA1,
  40415. 0xE2, 0xBE, 0x5F, 0x61, 0x4D, 0x79, 0x59, 0x78,
  40416. 0x25, 0xBA, 0x09, 0xF4, 0x57, 0xD3, 0xCB, 0xE7,
  40417. 0x56, 0x1E, 0x7E, 0x89, 0xEA, 0xF0, 0x59, 0xE9,
  40418. 0x77, 0xD1, 0xEE, 0x88, 0x84, 0x8B, 0x78, 0x1F,
  40419. 0x21, 0xF7, 0x23, 0x89, 0x0F, 0xF1, 0xF9, 0x87,
  40420. 0x39, 0x28, 0x41, 0x2C, 0x8F, 0x11, 0xEE, 0xDD,
  40421. 0x2C, 0x0C, 0x39, 0xC9, 0x51, 0x27, 0x90, 0x98,
  40422. 0x6A, 0x19, 0xE1, 0x7B, 0x2B, 0x70, 0xA4, 0xD7,
  40423. 0xCF, 0x49, 0xD9, 0xD1, 0x8C, 0xAA, 0x0C, 0x20,
  40424. 0x23, 0x13, 0x4C, 0xAC, 0xD1, 0x69, 0x20, 0x0D,
  40425. 0x88, 0x17, 0xFA, 0x32, 0x1F, 0x04, 0xAC, 0xC9,
  40426. 0x10, 0x61, 0x3D, 0xFF, 0x25, 0x0E, 0xB3, 0x25,
  40427. 0xDB, 0xEF, 0x29, 0xEB, 0x56, 0x11, 0xB2, 0xAD,
  40428. 0x2A, 0x23, 0xED, 0xD5, 0x38, 0x04, 0x9B, 0x3F,
  40429. 0x43, 0xEF, 0xEB, 0x4D, 0x60, 0x98, 0x37, 0x92,
  40430. 0xB4, 0xBF, 0x05, 0x56, 0x79, 0x44, 0xAA, 0xDB,
  40431. 0x7A, 0xC4, 0xD3, 0xA5, 0xD8, 0x0A, 0x1B, 0x9D,
  40432. 0x84, 0x48, 0xB4, 0xC0, 0xC1, 0x15, 0xC3, 0xB5,
  40433. 0xAD, 0x38, 0x85, 0x35, 0x3F, 0x47, 0xD5, 0xFC,
  40434. 0xB9, 0xB7, 0xD6, 0x44, 0x6F, 0x1A, 0x72, 0x10,
  40435. 0xBB, 0xC6, 0x67, 0xFC, 0x41, 0x14, 0x15, 0xF2,
  40436. 0x3C, 0xD4, 0x0A, 0x2A, 0x3D, 0x64, 0x06, 0x1D,
  40437. 0x71, 0xC6, 0x71, 0x91, 0x57, 0x1A, 0x97, 0xD0,
  40438. 0x10, 0x88, 0xA2, 0x4B, 0x67, 0x11, 0x56, 0x7F,
  40439. 0xC8, 0x91, 0x06, 0x73, 0x2D, 0x88, 0x92, 0xFF,
  40440. 0x98, 0x5B, 0x8E, 0x6C, 0xF7, 0x01, 0x63, 0x82,
  40441. 0x9C, 0xC0, 0x85, 0xBE, 0x4E, 0x40, 0x83, 0x15,
  40442. 0x36, 0x1B, 0xB1, 0xB2, 0x00, 0x3D, 0x64, 0x13,
  40443. 0x22, 0x0B, 0x13, 0x45, 0x06, 0xD3, 0xC3, 0x04,
  40444. 0xC0, 0xBB, 0xBA, 0x9C, 0x9C, 0x45, 0xD3, 0x65,
  40445. 0x1E, 0x05, 0x71, 0xB6, 0xB1, 0x15, 0x17, 0x72,
  40446. 0x13, 0xD8, 0x59, 0x5E, 0x14, 0x3D, 0xB9, 0x0B,
  40447. 0xD7, 0x2F, 0x7E, 0xB9, 0x74, 0xD8, 0xD0, 0xA0,
  40448. 0x31, 0x74, 0x09, 0xD6, 0x4D, 0x58, 0x37, 0xEA,
  40449. 0xEC, 0x9B, 0x8D, 0x44, 0xDD, 0x7E, 0xCF, 0xF6,
  40450. 0xCD, 0xA9, 0xF7, 0x29, 0x38, 0x2A, 0x43, 0xB3,
  40451. 0x79, 0xCB, 0xDD, 0x43, 0xFF, 0xB1, 0x8A, 0xEA,
  40452. 0x35, 0xC1, 0xA9, 0x96, 0xCE, 0xF1, 0x48, 0x8D,
  40453. 0x3B, 0x7A, 0x81, 0xEE, 0x7C, 0xFC, 0x0B, 0x96,
  40454. 0x23, 0x41, 0x8A, 0xB3, 0x91, 0x9A, 0x6E, 0xDD,
  40455. 0xB9, 0x9F, 0x22, 0x2F, 0x0D, 0xDD, 0xB2, 0xF3,
  40456. 0x2A, 0x20, 0xC8, 0xF8, 0x4F, 0xBF, 0x4C, 0x49,
  40457. 0xB4, 0xCB, 0x3E, 0xB5, 0x0D, 0x9C, 0x4C, 0xD2,
  40458. 0x5A, 0x6F, 0x71, 0x75, 0x46, 0x70, 0x66, 0xD2,
  40459. 0x5E, 0x64, 0x37, 0xB6, 0x7F, 0x2D, 0xBC, 0x70,
  40460. 0xC2, 0xE6, 0xEB, 0x0B, 0xDE, 0x23, 0x86, 0xD0,
  40461. 0x30, 0x14, 0xA7, 0x89, 0xFB, 0x6D, 0xC0, 0x8E,
  40462. 0xE3, 0x3C, 0x0C, 0x67, 0x95, 0x1D, 0xA9, 0xD7,
  40463. 0x4B, 0x9C, 0x94, 0x84, 0x5D, 0x2A, 0x99, 0x03,
  40464. 0x7E, 0x09, 0x5F, 0xEF, 0x79, 0x19, 0x92, 0x0F,
  40465. 0xE5, 0x26, 0xEB, 0x5D, 0xD0, 0xBA, 0x1F, 0x97,
  40466. 0xDF, 0xBD, 0x2D, 0xDC, 0x31, 0x60, 0x9C, 0x1B,
  40467. 0x7B, 0x45, 0xEC, 0x3A, 0xDB, 0x58, 0x6F, 0xE3,
  40468. 0x03, 0x0A, 0x0C, 0x7A, 0x9D, 0xD0, 0x34, 0xA3,
  40469. 0xC2, 0xE6, 0xF9, 0x84, 0x90, 0x93, 0xCE, 0xE1,
  40470. 0x0A, 0x18, 0x19, 0x53, 0x54, 0x7F, 0x8B, 0xE3,
  40471. 0x28, 0x72, 0x0A, 0x4A, 0x5A, 0x82, 0x90, 0xB5,
  40472. 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40473. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40474. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40475. 0x0B, 0x10, 0x18, 0x1A, 0x21
  40476. };
  40477. #endif
  40478. #ifndef WOLFSSL_NO_ML_DSA_87
  40479. static const byte pk_87[] = {
  40480. 0x59, 0xB2, 0x37, 0x1F, 0xE7, 0xBA, 0xCC, 0x20,
  40481. 0x7F, 0xE1, 0xFE, 0xE8, 0x8A, 0x8B, 0x38, 0x05,
  40482. 0xA7, 0x05, 0x28, 0x65, 0x69, 0x17, 0x89, 0xBB,
  40483. 0x90, 0x54, 0x2F, 0xA4, 0x7F, 0x7E, 0xF2, 0xB7,
  40484. 0x5F, 0xCA, 0x13, 0xDB, 0xA5, 0x88, 0x8B, 0xEC,
  40485. 0x32, 0x05, 0x14, 0xDC, 0xB0, 0x5F, 0xD2, 0x6E,
  40486. 0xB5, 0x54, 0x1F, 0x6E, 0x57, 0x2E, 0xCE, 0xA6,
  40487. 0xC4, 0xF1, 0xD3, 0x8A, 0xA7, 0x02, 0x59, 0x09,
  40488. 0x4A, 0xA9, 0x45, 0xF1, 0x9F, 0xED, 0x0D, 0x98,
  40489. 0x0E, 0x65, 0xDB, 0xF6, 0x5D, 0xB8, 0x0F, 0x56,
  40490. 0x4F, 0xE2, 0x9D, 0x83, 0x6C, 0x54, 0x79, 0x28,
  40491. 0x8B, 0x55, 0xCF, 0x07, 0xF4, 0xE0, 0x01, 0x59,
  40492. 0xB6, 0x95, 0x5D, 0xAB, 0xDE, 0xCC, 0x8C, 0x4D,
  40493. 0x66, 0xAE, 0x68, 0x87, 0x28, 0xBA, 0x6D, 0x5C,
  40494. 0x04, 0x42, 0xF3, 0xC1, 0x23, 0x2C, 0x78, 0x2C,
  40495. 0x46, 0x5B, 0x9B, 0x7C, 0x50, 0x14, 0xB1, 0x46,
  40496. 0x40, 0x65, 0xCC, 0xD8, 0xA5, 0x6D, 0x6B, 0x1C,
  40497. 0x16, 0x51, 0x08, 0x69, 0xE0, 0x14, 0xE6, 0x93,
  40498. 0x39, 0x98, 0xEF, 0x72, 0x55, 0x20, 0xB4, 0x00,
  40499. 0x91, 0x3D, 0x93, 0xB0, 0xEC, 0x75, 0xE2, 0xFB,
  40500. 0x72, 0x5D, 0xC1, 0xAE, 0xC0, 0xC0, 0xCC, 0x73,
  40501. 0x43, 0xB9, 0xE5, 0x44, 0xBA, 0xA4, 0xD6, 0x79,
  40502. 0x86, 0x0E, 0x34, 0x7B, 0x2E, 0x94, 0x7D, 0x8D,
  40503. 0x24, 0x36, 0xF0, 0x92, 0x98, 0xA7, 0xBB, 0x83,
  40504. 0x36, 0xB9, 0xDE, 0x9C, 0xFD, 0x5C, 0xDB, 0xCD,
  40505. 0x91, 0xC7, 0x24, 0x92, 0x68, 0xCA, 0x03, 0xEF,
  40506. 0xAC, 0x27, 0x3A, 0xF5, 0x29, 0x68, 0xD5, 0x01,
  40507. 0x40, 0x6C, 0xD9, 0xC9, 0x61, 0x59, 0xD7, 0xC1,
  40508. 0x5A, 0xA2, 0x90, 0x03, 0x30, 0xC1, 0x18, 0x9C,
  40509. 0xFC, 0x2C, 0xD8, 0xB9, 0x12, 0xC4, 0x80, 0xE4,
  40510. 0x58, 0x29, 0x7E, 0xF1, 0x4D, 0xB6, 0x94, 0xA3,
  40511. 0xF1, 0xE7, 0x2C, 0x1D, 0xFA, 0x3A, 0x3D, 0x2A,
  40512. 0x8A, 0x69, 0xE0, 0x11, 0x60, 0x2B, 0x93, 0x02,
  40513. 0x0B, 0xAC, 0xD1, 0xC2, 0xF3, 0xAD, 0x06, 0xC9,
  40514. 0x5A, 0x7F, 0x36, 0xEB, 0xF5, 0x26, 0x1F, 0x6E,
  40515. 0xC1, 0x06, 0x81, 0x6B, 0xB3, 0x30, 0x3C, 0xC0,
  40516. 0x0B, 0xF4, 0xE8, 0x68, 0x8D, 0x2E, 0x85, 0x48,
  40517. 0xF1, 0x04, 0x90, 0xD9, 0xEB, 0x23, 0xC5, 0x67,
  40518. 0x93, 0xB3, 0x4B, 0x84, 0x06, 0xCB, 0xE4, 0x43,
  40519. 0xD8, 0x35, 0x6B, 0xCD, 0x0F, 0x4F, 0x61, 0xD0,
  40520. 0xD0, 0x17, 0xD5, 0x48, 0x31, 0xB9, 0xBA, 0x32,
  40521. 0x9F, 0x89, 0x48, 0xF2, 0x5C, 0x31, 0x22, 0xF9,
  40522. 0xDE, 0xDE, 0x8C, 0xEC, 0xBA, 0x51, 0x56, 0x9E,
  40523. 0xDF, 0xFF, 0x89, 0x5F, 0xA0, 0x20, 0x86, 0x2C,
  40524. 0x5D, 0xF7, 0x9F, 0x86, 0x40, 0x78, 0x48, 0x6B,
  40525. 0x5F, 0xB2, 0x28, 0xFD, 0x78, 0x9C, 0x35, 0xFD,
  40526. 0xE1, 0xC5, 0x4B, 0xFF, 0xBF, 0x4A, 0x02, 0x5A,
  40527. 0x7F, 0xE7, 0xD8, 0xC3, 0x49, 0x0A, 0x5D, 0x4E,
  40528. 0x62, 0xD0, 0x4F, 0x79, 0xF4, 0x18, 0x3C, 0xA6,
  40529. 0x83, 0x79, 0xF4, 0x64, 0x8B, 0xD5, 0xB2, 0x41,
  40530. 0x6D, 0xBE, 0x5B, 0x84, 0x5C, 0x9F, 0x4B, 0x7A,
  40531. 0x7E, 0x23, 0x39, 0xC0, 0x50, 0x6D, 0x58, 0x53,
  40532. 0x9E, 0xAE, 0xA9, 0x45, 0x1C, 0x9B, 0x2F, 0xE2,
  40533. 0xA1, 0x8C, 0x84, 0x9D, 0xCA, 0x7E, 0xED, 0x9D,
  40534. 0xAC, 0xC0, 0x58, 0xD0, 0x05, 0xFB, 0x73, 0x75,
  40535. 0xC4, 0xEF, 0x45, 0xB0, 0x01, 0x54, 0x3F, 0xC6,
  40536. 0x8E, 0x47, 0xDD, 0xB6, 0xD1, 0x4F, 0xF9, 0x37,
  40537. 0xD1, 0xAA, 0x0D, 0x4D, 0x74, 0x89, 0xDF, 0xFA,
  40538. 0x62, 0x10, 0x67, 0x9C, 0xCC, 0xEC, 0xF9, 0xB8,
  40539. 0x55, 0x1D, 0xCF, 0x68, 0x2D, 0x2A, 0xF1, 0xE5,
  40540. 0xBD, 0x86, 0x9F, 0x3E, 0x8D, 0x40, 0x0D, 0x5C,
  40541. 0x86, 0x1A, 0xE5, 0x1F, 0xE7, 0xEB, 0xBB, 0x54,
  40542. 0x57, 0xF2, 0xEA, 0xAF, 0xD0, 0x93, 0xA9, 0x59,
  40543. 0x8E, 0xC7, 0x21, 0xC6, 0x93, 0x27, 0xC5, 0x19,
  40544. 0x30, 0xF4, 0xB9, 0xFF, 0xB2, 0xAA, 0x7F, 0x1A,
  40545. 0x28, 0x43, 0x6B, 0x6D, 0x80, 0x8D, 0x75, 0x39,
  40546. 0x2B, 0xC4, 0x3C, 0x1B, 0x5B, 0x85, 0x9C, 0x66,
  40547. 0xC5, 0x4F, 0xA5, 0x15, 0xC7, 0xA6, 0x15, 0xA6,
  40548. 0x9E, 0x60, 0x92, 0x14, 0x34, 0xAA, 0x9C, 0xF9,
  40549. 0xF9, 0xE0, 0x3C, 0x3C, 0xA3, 0x5B, 0x5E, 0xBC,
  40550. 0x6A, 0x40, 0x9E, 0x82, 0x2F, 0xE7, 0x6E, 0x09,
  40551. 0x24, 0xC6, 0xC0, 0x62, 0xF1, 0x72, 0x4C, 0x38,
  40552. 0x2F, 0xF3, 0xC8, 0xAC, 0xB5, 0xC1, 0x66, 0x6C,
  40553. 0x2E, 0xC2, 0x6B, 0x76, 0x28, 0xE3, 0xD7, 0xC1,
  40554. 0x3D, 0xA8, 0xD7, 0x58, 0x89, 0x0E, 0x6C, 0xC0,
  40555. 0x17, 0xB7, 0x89, 0x25, 0x82, 0xE9, 0x5E, 0xDD,
  40556. 0x04, 0xBA, 0x93, 0x45, 0xDF, 0x70, 0xFA, 0xD5,
  40557. 0x6E, 0xA6, 0x8B, 0xF8, 0x87, 0x5B, 0x93, 0x2C,
  40558. 0x28, 0xB3, 0x28, 0x07, 0xC8, 0x63, 0x71, 0xE1,
  40559. 0x7D, 0xCC, 0x04, 0x72, 0x5C, 0xB5, 0x97, 0xB5,
  40560. 0x24, 0x46, 0x79, 0x63, 0xE1, 0xD4, 0xA6, 0x1B,
  40561. 0x5F, 0xBF, 0x9E, 0xC5, 0x04, 0xD5, 0xDD, 0xB6,
  40562. 0x17, 0x93, 0xDD, 0x4E, 0x34, 0xAE, 0x08, 0x2A,
  40563. 0x59, 0x90, 0xEF, 0xCE, 0x80, 0x1E, 0x93, 0x8C,
  40564. 0xCA, 0xE7, 0x38, 0xE0, 0x2E, 0x90, 0x59, 0x9D,
  40565. 0x97, 0x1C, 0x2D, 0x7C, 0x64, 0xE5, 0xB6, 0xF8,
  40566. 0x63, 0x9F, 0x75, 0x8E, 0xD6, 0x21, 0xC1, 0xF2,
  40567. 0x10, 0x73, 0xC0, 0x3E, 0xDB, 0x78, 0x2C, 0x7A,
  40568. 0x0F, 0x5D, 0x7C, 0x66, 0xF5, 0xCE, 0x16, 0x1D,
  40569. 0xED, 0x55, 0xB3, 0xE9, 0x2D, 0xC2, 0x71, 0x83,
  40570. 0xAB, 0x08, 0x3D, 0xBC, 0x1F, 0x39, 0x30, 0xAE,
  40571. 0x56, 0xED, 0xB8, 0xC5, 0x3E, 0x9A, 0x7E, 0x02,
  40572. 0x0F, 0xFF, 0x0C, 0x40, 0x42, 0xF5, 0x18, 0xB2,
  40573. 0x6F, 0x39, 0x0C, 0x96, 0xC8, 0x18, 0x3B, 0x79,
  40574. 0xB5, 0x3C, 0x7C, 0x7B, 0xC5, 0x15, 0x18, 0x7B,
  40575. 0x3D, 0xE8, 0xCA, 0xB0, 0x87, 0x69, 0xC5, 0xDD,
  40576. 0x6F, 0xF5, 0x49, 0x21, 0x12, 0xE8, 0xB0, 0xF2,
  40577. 0x8D, 0x09, 0xF4, 0x06, 0x7A, 0xDB, 0x04, 0x19,
  40578. 0x4F, 0x60, 0x25, 0x0E, 0x75, 0xAD, 0xE3, 0x31,
  40579. 0xA5, 0xC2, 0x55, 0x93, 0xBC, 0xD9, 0x2A, 0x6D,
  40580. 0x13, 0x50, 0x43, 0x95, 0x85, 0x86, 0x0B, 0xB6,
  40581. 0xFE, 0xED, 0xBD, 0x2F, 0x83, 0x9F, 0x31, 0x7A,
  40582. 0x01, 0x35, 0x88, 0x76, 0xC8, 0x8E, 0x89, 0x8A,
  40583. 0xC0, 0xC8, 0x53, 0x78, 0xF5, 0x72, 0xF2, 0x3C,
  40584. 0xDE, 0x93, 0x1D, 0x47, 0xDE, 0x71, 0xD3, 0x35,
  40585. 0x3D, 0xAB, 0x1F, 0x81, 0x0A, 0x61, 0xB1, 0x8D,
  40586. 0x24, 0xCD, 0x83, 0xDD, 0xAB, 0x8D, 0x53, 0xBA,
  40587. 0x9C, 0x7B, 0x82, 0x74, 0xB0, 0xFE, 0x82, 0xAF,
  40588. 0xF3, 0x0C, 0x57, 0x07, 0x2F, 0x64, 0x37, 0x87,
  40589. 0xCA, 0x1D, 0xF0, 0x3B, 0x99, 0xEB, 0x57, 0xDB,
  40590. 0xDA, 0x8C, 0x8E, 0xE8, 0xEB, 0x20, 0x1F, 0x28,
  40591. 0x47, 0xCB, 0xC9, 0xD3, 0x4F, 0xD8, 0x0C, 0xE6,
  40592. 0xBC, 0x5E, 0x1E, 0x32, 0x8E, 0xB6, 0xEF, 0xC8,
  40593. 0x3C, 0x4B, 0xD9, 0xD5, 0x2F, 0x32, 0x4E, 0x30,
  40594. 0xEE, 0x4B, 0x5E, 0x86, 0x35, 0x1E, 0x5C, 0x8C,
  40595. 0x4C, 0x54, 0x56, 0x83, 0x6D, 0x5A, 0x45, 0x22,
  40596. 0x03, 0xB3, 0xC3, 0x72, 0xC7, 0x87, 0xAE, 0x33,
  40597. 0x32, 0xC8, 0xA5, 0xE9, 0xDC, 0x21, 0x97, 0xD9,
  40598. 0xC3, 0x41, 0xB9, 0x75, 0x6B, 0xB1, 0xE6, 0x3C,
  40599. 0x75, 0xBB, 0xD5, 0xCF, 0x3E, 0x5C, 0xD4, 0xBF,
  40600. 0x47, 0xBD, 0x1F, 0xEB, 0xC3, 0xE3, 0x71, 0x09,
  40601. 0x12, 0xD6, 0x30, 0x32, 0xF6, 0xB9, 0x7D, 0xC1,
  40602. 0x9C, 0x4D, 0xE1, 0x96, 0xAC, 0xD9, 0x15, 0x77,
  40603. 0x15, 0xE2, 0xC1, 0x4E, 0x05, 0x4A, 0x93, 0x17,
  40604. 0xBF, 0x96, 0xA6, 0x84, 0xBB, 0x96, 0xCE, 0xFB,
  40605. 0x7D, 0x8F, 0xDC, 0xA8, 0xAA, 0x47, 0x7A, 0x2A,
  40606. 0xF6, 0xF7, 0x26, 0xD2, 0xCA, 0xC1, 0xA6, 0x03,
  40607. 0xCF, 0x13, 0x60, 0xEC, 0x11, 0xCA, 0x89, 0x7E,
  40608. 0x5B, 0xC7, 0x35, 0xAB, 0x69, 0xB8, 0x64, 0x7F,
  40609. 0x30, 0xCE, 0xD4, 0x94, 0x7B, 0xA9, 0xF6, 0x35,
  40610. 0xD9, 0xCB, 0x2D, 0x82, 0xA6, 0x62, 0xFF, 0x17,
  40611. 0xA0, 0xE1, 0x2D, 0x4D, 0x06, 0xD6, 0x41, 0xEE,
  40612. 0x76, 0xEB, 0x8B, 0x45, 0xC7, 0x1E, 0xDE, 0x38,
  40613. 0xC9, 0x05, 0xC5, 0x2B, 0xE7, 0x6C, 0x61, 0x09,
  40614. 0xF2, 0x61, 0x2F, 0xEE, 0x6C, 0x31, 0x94, 0x46,
  40615. 0x5C, 0x19, 0xBA, 0x5D, 0x3E, 0xBC, 0xF1, 0xF0,
  40616. 0xB5, 0xE5, 0x34, 0xE0, 0xF0, 0xF1, 0xD3, 0x1C,
  40617. 0xB1, 0xE7, 0xA3, 0x6C, 0x43, 0x03, 0xF2, 0x83,
  40618. 0xDB, 0xA8, 0x59, 0x1C, 0xC6, 0x09, 0x31, 0x1A,
  40619. 0x80, 0x9E, 0x44, 0x4E, 0x33, 0xA8, 0x93, 0x88,
  40620. 0x0C, 0xDB, 0xAE, 0x29, 0x11, 0x91, 0x46, 0xA3,
  40621. 0x68, 0xE4, 0xD2, 0xED, 0xD9, 0x1F, 0xE4, 0x71,
  40622. 0x64, 0x7F, 0xFE, 0x82, 0x1A, 0xA6, 0xD3, 0x1C,
  40623. 0x9F, 0xA4, 0x96, 0x95, 0xEB, 0x99, 0x41, 0xB0,
  40624. 0x8F, 0x7B, 0xE3, 0xF0, 0x6C, 0xDD, 0xF2, 0x73,
  40625. 0x9B, 0x8C, 0xAD, 0x2A, 0xB0, 0xDA, 0x4F, 0x5A,
  40626. 0x3C, 0x0A, 0x26, 0xDF, 0x6A, 0x17, 0xB1, 0x37,
  40627. 0xCA, 0xAB, 0x3B, 0x91, 0x9A, 0xB6, 0x36, 0xD6,
  40628. 0xC8, 0x9B, 0xED, 0xA3, 0x05, 0x88, 0x98, 0x62,
  40629. 0x87, 0x21, 0xF2, 0x77, 0x03, 0x15, 0xFE, 0xEE,
  40630. 0x88, 0x15, 0x95, 0xE2, 0x4C, 0xF4, 0x8B, 0x44,
  40631. 0x16, 0x60, 0xD0, 0xB2, 0xE9, 0xD5, 0xB9, 0x09,
  40632. 0x28, 0xC3, 0x81, 0xF2, 0xB0, 0xFA, 0x26, 0x34,
  40633. 0x2E, 0x4C, 0x9B, 0x88, 0xC0, 0x88, 0x7A, 0x46,
  40634. 0x87, 0x12, 0x4C, 0x01, 0x2D, 0x96, 0x9E, 0x1A,
  40635. 0xFD, 0x85, 0x32, 0x75, 0x4B, 0xA1, 0x21, 0x25,
  40636. 0xE9, 0x43, 0x3D, 0xCF, 0x6D, 0x7B, 0xC1, 0xA3,
  40637. 0x6A, 0x83, 0xE6, 0xA1, 0x0B, 0xA1, 0xCB, 0x76,
  40638. 0x52, 0xA8, 0x13, 0x50, 0x89, 0x9C, 0x2D, 0xFC,
  40639. 0x6E, 0x4F, 0xED, 0x38, 0xD0, 0x09, 0xE6, 0xD0,
  40640. 0xF1, 0xD4, 0x4C, 0xCC, 0xB9, 0x5E, 0x55, 0x1B,
  40641. 0x3A, 0xD5, 0x4B, 0x3A, 0xC8, 0x1E, 0x8B, 0xA4,
  40642. 0x66, 0x5E, 0xA4, 0x28, 0xB3, 0xC8, 0x61, 0xE8,
  40643. 0x67, 0x78, 0x90, 0xCF, 0x5F, 0x62, 0x5C, 0x19,
  40644. 0xA7, 0xC5, 0x94, 0x3A, 0x94, 0x01, 0xCB, 0x78,
  40645. 0xE7, 0x02, 0x6B, 0xAE, 0x92, 0xB6, 0x0A, 0x8B,
  40646. 0x68, 0x07, 0xC1, 0x77, 0x45, 0x41, 0x5C, 0xD8,
  40647. 0xE0, 0x30, 0xC6, 0x4C, 0x56, 0xE8, 0x22, 0x13,
  40648. 0x9A, 0x35, 0xDA, 0x42, 0x3F, 0x26, 0x43, 0x36,
  40649. 0xE0, 0xAF, 0xDF, 0x16, 0x74, 0x30, 0xDD, 0x36,
  40650. 0xE0, 0x06, 0x4B, 0x2F, 0x6E, 0x8D, 0x8B, 0xB6,
  40651. 0xBE, 0x99, 0xC5, 0xA9, 0xFB, 0x55, 0x1C, 0xC6,
  40652. 0x3E, 0x50, 0x8D, 0xB6, 0x36, 0x66, 0x7D, 0xDA,
  40653. 0x53, 0xF6, 0x11, 0xF0, 0x2F, 0xCD, 0x1F, 0x99,
  40654. 0x41, 0x0F, 0x1A, 0x7A, 0x82, 0x88, 0x2F, 0x96,
  40655. 0x23, 0xAD, 0xDC, 0x50, 0xEB, 0x01, 0xE1, 0xF3,
  40656. 0x99, 0x78, 0xBF, 0x68, 0x50, 0x6C, 0x71, 0xDB,
  40657. 0xBE, 0xE4, 0x2E, 0x4A, 0x80, 0x06, 0x9B, 0x0E,
  40658. 0x4C, 0x7F, 0xC4, 0xCC, 0x14, 0x71, 0xF4, 0xF1,
  40659. 0x02, 0x8D, 0xB2, 0x5C, 0x46, 0x87, 0xB6, 0x0D,
  40660. 0xF4, 0x25, 0x5D, 0xEC, 0x91, 0x48, 0x19, 0x7A,
  40661. 0x74, 0x79, 0x6E, 0xC7, 0x60, 0xA6, 0x6A, 0xFC,
  40662. 0x78, 0x84, 0x03, 0x86, 0x51, 0x92, 0x09, 0x73,
  40663. 0xA6, 0x9C, 0x20, 0x35, 0x16, 0x22, 0x26, 0x32,
  40664. 0xEC, 0x58, 0x75, 0xEA, 0x6D, 0x83, 0x80, 0x96,
  40665. 0xE7, 0xFE, 0x9B, 0x5B, 0x4F, 0xB6, 0x9C, 0x5E,
  40666. 0x94, 0x07, 0xE7, 0x0D, 0x27, 0xFA, 0x34, 0xB0,
  40667. 0xCD, 0xBD, 0x6E, 0x11, 0x9D, 0x87, 0xCE, 0x38,
  40668. 0x58, 0x1D, 0xF1, 0xD3, 0xE0, 0xDF, 0x3A, 0xE0,
  40669. 0x29, 0x04, 0x2A, 0x3B, 0x20, 0xE9, 0x23, 0xEB,
  40670. 0xCE, 0x19, 0xA4, 0x95, 0x87, 0x55, 0xEE, 0x2F,
  40671. 0x98, 0xFD, 0x23, 0x4C, 0x44, 0x13, 0xE2, 0xDB,
  40672. 0xC9, 0x35, 0x59, 0xA4, 0x28, 0xDC, 0x37, 0xF2,
  40673. 0xD1, 0x23, 0x5B, 0xD4, 0x41, 0x9B, 0x09, 0x9E,
  40674. 0x0F, 0x0D, 0xE5, 0x42, 0xC4, 0x69, 0x35, 0x99,
  40675. 0x1B, 0xE0, 0x69, 0x2A, 0x6D, 0x80, 0xB8, 0xFD,
  40676. 0x98, 0x86, 0xE0, 0xFA, 0x17, 0x69, 0xB4, 0x9E,
  40677. 0x8A, 0xE6, 0x30, 0x7C, 0xB0, 0xBC, 0x1B, 0x49,
  40678. 0x73, 0x2D, 0x26, 0xE2, 0x5C, 0xA1, 0xCD, 0x9D,
  40679. 0x40, 0x7E, 0x0D, 0x88, 0x64, 0x04, 0x09, 0x41,
  40680. 0x61, 0x1F, 0x93, 0x33, 0xB6, 0x36, 0x7E, 0x83,
  40681. 0x00, 0xFD, 0x64, 0x6A, 0xC5, 0xA7, 0x1A, 0xD9,
  40682. 0x13, 0xEE, 0xFD, 0x80, 0x8D, 0x5C, 0xAF, 0xBF,
  40683. 0x15, 0x21, 0xA3, 0x06, 0x2E, 0xC1, 0x84, 0xE5,
  40684. 0x21, 0x65, 0x50, 0x1E, 0x00, 0x55, 0x56, 0xDE,
  40685. 0x4D, 0xEE, 0x46, 0xF9, 0xE5, 0x3D, 0x7D, 0xEF,
  40686. 0x99, 0x09, 0xF3, 0xD5, 0xD9, 0x8C, 0xA8, 0x0D,
  40687. 0x87, 0x70, 0x7F, 0x7B, 0xC0, 0xFF, 0x8D, 0x87,
  40688. 0x9D, 0x65, 0xD4, 0xD7, 0x83, 0xD1, 0x96, 0xF2,
  40689. 0x46, 0x06, 0x93, 0x81, 0x1C, 0xDF, 0x33, 0x35,
  40690. 0x8E, 0x08, 0x2D, 0x81, 0xF4, 0xDB, 0x8F, 0x6C,
  40691. 0x20, 0x48, 0x61, 0x83, 0xA3, 0x6D, 0x4F, 0xBC,
  40692. 0xC8, 0xA1, 0xC6, 0xDA, 0x21, 0xAA, 0x4D, 0xD1,
  40693. 0x36, 0xE1, 0x9F, 0xEF, 0x2E, 0xA9, 0x93, 0x97,
  40694. 0x2B, 0xB9, 0x98, 0x9A, 0xC1, 0xC3, 0x8A, 0x79,
  40695. 0xF3, 0x18, 0x52, 0x17, 0x80, 0x04, 0x12, 0x3C,
  40696. 0x46, 0x27, 0x7D, 0x38, 0xA8, 0x8F, 0xC1, 0x58,
  40697. 0x9F, 0x25, 0x73, 0x32, 0x28, 0x4C, 0xD8, 0xA8,
  40698. 0x73, 0xC2, 0x5A, 0x1A, 0x6D, 0x40, 0x26, 0x5B,
  40699. 0x28, 0x5D, 0xF0, 0x93, 0x70, 0xE8, 0x8F, 0x72,
  40700. 0xFF, 0x70, 0xE4, 0x34, 0xE8, 0xF6, 0x60, 0x84,
  40701. 0xCC, 0xFE, 0xBD, 0xBB, 0xC4, 0xB9, 0x9E, 0xDF,
  40702. 0xBC, 0x75, 0x0C, 0xC5, 0xDE, 0xA6, 0x36, 0x17,
  40703. 0xF6, 0x47, 0xF5, 0xF0, 0x21, 0xD5, 0x7D, 0x64,
  40704. 0xD5, 0xEF, 0xF0, 0x48, 0x63, 0x4D, 0xB2, 0x20,
  40705. 0x9D, 0x7C, 0x8B, 0x82, 0xFB, 0x63, 0xB8, 0x82,
  40706. 0x3E, 0x4C, 0xA0, 0x57, 0x16, 0x8B, 0xAE, 0x88,
  40707. 0xD9, 0x71, 0x52, 0x91, 0x24, 0x0B, 0x37, 0x58,
  40708. 0xD7, 0x68, 0x45, 0x01, 0xF8, 0x61, 0x86, 0x7B,
  40709. 0x7A, 0x24, 0x1C, 0x06, 0x3B, 0x05, 0xD5, 0xE8,
  40710. 0xCA, 0x6B, 0x4C, 0x79, 0xCB, 0x24, 0x35, 0xD7,
  40711. 0xF9, 0x94, 0xCB, 0x76, 0x91, 0x5B, 0x4A, 0x54,
  40712. 0x87, 0x08, 0xB1, 0x1B, 0x29, 0x44, 0x96, 0x85,
  40713. 0x94, 0x1D, 0x43, 0xE6, 0x0A, 0x89, 0x76, 0xF9,
  40714. 0xA9, 0x60, 0x72, 0xF9, 0x10, 0x41, 0xF4, 0xC3,
  40715. 0xDF, 0x7C, 0x73, 0x96, 0x90, 0x12, 0xAE, 0x1B,
  40716. 0x30, 0xE4, 0xB9, 0xC4, 0xE1, 0x33, 0x55, 0x8D,
  40717. 0xAB, 0xC4, 0x6C, 0x10, 0x3C, 0x0C, 0xB1, 0xDF,
  40718. 0xB9, 0x9B, 0x58, 0x53, 0x74, 0xA5, 0x4F, 0x9B,
  40719. 0xA5, 0x6B, 0x72, 0x48, 0xB8, 0xC3, 0xF6, 0x6F,
  40720. 0x1D, 0x55, 0x76, 0x0D, 0x6A, 0xBB, 0x43, 0x03,
  40721. 0x75, 0x77, 0x4D, 0xFB, 0xA2, 0x05, 0x9C, 0x5D,
  40722. 0xDD, 0xB6, 0x59, 0xFD, 0x2E, 0x1D, 0xA9, 0xC3,
  40723. 0xF0, 0xB8, 0x08, 0x68, 0xC9, 0x2B, 0xCA, 0xC1,
  40724. 0x04, 0x03, 0xDC, 0xD1, 0x40, 0xD6, 0xA3, 0xD3,
  40725. 0xF3, 0x5F, 0x8E, 0xF1, 0xA2, 0xDD, 0x98, 0xDE,
  40726. 0x1A, 0x43, 0x34, 0x23, 0x85, 0x99, 0xED, 0xAD,
  40727. 0x92, 0x0D, 0xC0, 0xAA, 0x69, 0x8E, 0x9F, 0xE6,
  40728. 0x10, 0x6A, 0x07, 0x80, 0xC9, 0xC2, 0x45, 0xF2,
  40729. 0xC6, 0x5A, 0x0C, 0x3E, 0x5C, 0xD5, 0x36, 0x61,
  40730. 0x10, 0xB1, 0x76, 0x0F, 0xCD, 0x41, 0x4D, 0x45,
  40731. 0x0D, 0xB9, 0xD7, 0x6A, 0x22, 0xA9, 0xEA, 0xEA,
  40732. 0x0C, 0x9F, 0xB7, 0x2E, 0xD5, 0x43, 0xCE, 0x9F,
  40733. 0xA3, 0x31, 0x4B, 0xAB, 0x17, 0x68, 0x7E, 0x9D,
  40734. 0xE5, 0xAD, 0xAD, 0x75, 0x61, 0xF1, 0xA5, 0xBE,
  40735. 0xC1, 0x63, 0x39, 0x26, 0x9A, 0x87, 0xE0, 0x9A,
  40736. 0xCB, 0x29, 0xE4, 0xC4, 0x39, 0x60, 0x5E, 0x95,
  40737. 0x72, 0xAA, 0x9B, 0x7D, 0x0E, 0x83, 0x71, 0xA3,
  40738. 0x0E, 0x41, 0xA0, 0xA7, 0xBD, 0xC0, 0x2D, 0xA3,
  40739. 0xA6, 0x12, 0x1B, 0xF2, 0x61, 0xEA, 0xA0, 0x16,
  40740. 0xA2, 0x07, 0x4E, 0x44, 0x32, 0xCF, 0x63, 0xAF,
  40741. 0x96, 0xBE, 0x81, 0xCE, 0xB6, 0xE0, 0xC2, 0x67,
  40742. 0x6A, 0x85, 0x45, 0xC6, 0x6D, 0x2F, 0x30, 0xC9,
  40743. 0x8B, 0x54, 0x24, 0xF0, 0xFE, 0xF0, 0x4B, 0x3C,
  40744. 0x6C, 0x70, 0x64, 0xE2, 0xD2, 0xE1, 0x1C, 0xBE,
  40745. 0x60, 0xF8, 0x57, 0x23, 0xFF, 0xC0, 0xB7, 0x70,
  40746. 0xD6, 0x86, 0x6F, 0xFA, 0x58, 0x9E, 0x3F, 0x9B,
  40747. 0x2A, 0xBF, 0x75, 0x10, 0x40, 0x19, 0xAA, 0x69,
  40748. 0xCB, 0x58, 0x89, 0x5B, 0x47, 0x4A, 0x0A, 0xDE,
  40749. 0x2B, 0x60, 0xA4, 0xAB, 0x07, 0x7C, 0x3A, 0x6D,
  40750. 0xF6, 0x15, 0x33, 0x4E, 0xBB, 0xE7, 0x32, 0xE9,
  40751. 0x52, 0x20, 0x21, 0x39, 0x94, 0xD3, 0xBD, 0xC4,
  40752. 0x43, 0xC8, 0xEF, 0x94, 0xAD, 0x51, 0x5F, 0x45,
  40753. 0x41, 0x83, 0x55, 0x18, 0x33, 0x14, 0x48, 0x58,
  40754. 0x57, 0xAC, 0x12, 0xBA, 0x1D, 0x62, 0xCF, 0x4F,
  40755. 0xD4, 0xF4, 0xDE, 0x2A, 0x7F, 0xFF, 0x1E, 0xCF,
  40756. 0x0D, 0x29, 0x0C, 0x4C, 0xDF, 0xFA, 0x88, 0xD8,
  40757. 0xF4, 0x8C, 0x5B, 0x83, 0x7D, 0x3A, 0x94, 0xCD,
  40758. 0x17, 0xB3, 0xD1, 0x69, 0x96, 0x6E, 0xB0, 0x38,
  40759. 0xFE, 0x5A, 0x6E, 0x85, 0xDF, 0xC6, 0x0A, 0x00,
  40760. 0x23, 0x3F, 0x10, 0x73, 0x19, 0x73, 0xDC, 0x47,
  40761. 0x5D, 0x53, 0xBC, 0x7B, 0x9E, 0x60, 0x32, 0x0B,
  40762. 0xA7, 0x90, 0x5D, 0x88, 0x51, 0x9F, 0xA3, 0x25,
  40763. 0xDF, 0x5A, 0xB0, 0x2B, 0x40, 0xF2, 0xAB, 0xBD,
  40764. 0xB3, 0x7D, 0x22, 0x61, 0xCB, 0x81, 0x48, 0x27,
  40765. 0x7B, 0x87, 0xAE, 0x32, 0x97, 0x97, 0x6C, 0x80,
  40766. 0xC3, 0x51, 0x34, 0xE5, 0xF7, 0x86, 0x90, 0x45,
  40767. 0x64, 0xC1, 0x46, 0x99, 0x47, 0xF6, 0x20, 0xFE,
  40768. 0x09, 0xFD, 0xF3, 0x86, 0x2C, 0x40, 0x57, 0xA3,
  40769. 0xBC, 0xEF, 0x70, 0x75, 0x0C, 0xB7, 0x27, 0xF0,
  40770. 0x31, 0x28, 0x3A, 0x18, 0x26, 0xF1, 0x38, 0x1B,
  40771. 0x33, 0x48, 0xE3, 0xEA, 0x46, 0x88, 0x60, 0x9E,
  40772. 0xCB, 0x19, 0x3A, 0xFA, 0xAE, 0xE1, 0xCD, 0x97,
  40773. 0xE4, 0xDD, 0xAA, 0x02, 0xC0, 0xC3, 0x0E, 0x49,
  40774. 0xF1, 0x37, 0xD0, 0x82, 0x85, 0x94, 0x15, 0x28,
  40775. 0x10, 0x17, 0x59, 0xA7, 0x42, 0x2A, 0xA4, 0x99,
  40776. 0xC9, 0x00, 0xA3, 0x79, 0xDD, 0x73, 0xB3, 0x07,
  40777. 0x28, 0x4C, 0xCD, 0xDA, 0xF1, 0xFA, 0x1B, 0x0C,
  40778. 0x4B, 0x28, 0x0E, 0x3F, 0x9F, 0x1D, 0xB6, 0xD3,
  40779. 0x8E, 0xCF, 0x8A, 0x84, 0x1F, 0x9D, 0x4E, 0x40,
  40780. 0xEC, 0xA8, 0x62, 0x47, 0xD6, 0xCD, 0x9B, 0x31,
  40781. 0xEA, 0xCD, 0x6A, 0x46, 0xF0, 0xE3, 0x33, 0xB9,
  40782. 0xE8, 0x3D, 0x69, 0x0D, 0x7E, 0x13, 0x46, 0x76,
  40783. 0x19, 0xB4, 0x6A, 0xF9, 0xAF, 0xCF, 0xDC, 0x4A,
  40784. 0xA9, 0xA0, 0x49, 0xB1, 0x80, 0x26, 0x0D, 0x70,
  40785. 0xD9, 0xEE, 0xDB, 0x8A, 0x53, 0x30, 0x51, 0xAB,
  40786. 0x83, 0x51, 0x7A, 0xAD, 0xC2, 0xCD, 0x90, 0x0B,
  40787. 0x3E, 0xA5, 0x12, 0x60, 0xF4, 0x64, 0xAF, 0xC5,
  40788. 0xD2, 0xDC, 0x41, 0x10, 0x29, 0x77, 0x9B, 0x21,
  40789. 0xCE, 0x2C, 0xBD, 0x16, 0x02, 0x18, 0xDF, 0x41,
  40790. 0xF6, 0x61, 0xDA, 0x1A, 0xD9, 0x5A, 0xD4, 0x0B,
  40791. 0x8C, 0x35, 0x3C, 0x7F, 0x10, 0xFC, 0x23, 0xF8,
  40792. 0x30, 0xD1, 0x17, 0xBC, 0xAE, 0xF8, 0xCE, 0xCE,
  40793. 0xBC, 0xBF, 0xA4, 0x9D, 0x79, 0xD8, 0xD9, 0x39,
  40794. 0x1E, 0x8D, 0x08, 0x28, 0x1F, 0x00, 0x0A, 0x55,
  40795. 0xE9, 0x2D, 0xB3, 0x31, 0xBD, 0xEC, 0xD7, 0x31,
  40796. 0x83, 0xE0, 0x58, 0xFF, 0x3F, 0xE5, 0x83, 0x9A,
  40797. 0xF5, 0x0D, 0x8C, 0x55, 0xF2, 0x2F, 0x6A, 0xFF,
  40798. 0x5A, 0x33, 0xDA, 0x77, 0x4B, 0xA1, 0xB3, 0xE6,
  40799. 0x43, 0xF5, 0x87, 0x7C, 0xF5, 0x49, 0xC4, 0xF9,
  40800. 0x08, 0xEA, 0x64, 0xA3, 0x7D, 0xF3, 0xBF, 0xA4,
  40801. 0xCD, 0x5F, 0x70, 0xF8, 0xCD, 0x15, 0x44, 0x76,
  40802. 0xD3, 0x4B, 0xC8, 0x53, 0xC9, 0xE8, 0xF7, 0x97,
  40803. 0x9E, 0x5F, 0x4E, 0xBB, 0x88, 0x8A, 0xF7, 0x61
  40804. };
  40805. static const byte msg_87[] = {
  40806. 0x4A, 0xC4, 0x67, 0x5C, 0x96, 0xD9, 0x11, 0x7D,
  40807. 0x1E, 0xDE, 0xB8, 0x0D, 0x7C, 0xD2, 0x84, 0xA3,
  40808. 0xE1, 0xE1, 0xFE, 0x03, 0x8E, 0x30, 0x12, 0x05,
  40809. 0xB4, 0xC4, 0x08, 0xEB, 0x96, 0x52, 0x35, 0xAD,
  40810. 0x1C, 0x85, 0xF8, 0xBE, 0x3F, 0x77, 0xCA, 0x48,
  40811. 0x6F, 0xD2, 0x07, 0xF7, 0xC7, 0x5F, 0x41, 0x21,
  40812. 0xCD, 0x3C, 0xA2, 0xB2, 0x3D, 0x6B, 0xCE, 0x43,
  40813. 0x82, 0xA6, 0xD3, 0x61, 0x21, 0x81, 0x50, 0x25,
  40814. 0xD5, 0x80, 0x6C, 0xBE, 0xF4, 0x52, 0xE0, 0x83,
  40815. 0x93, 0x3C, 0x6E, 0x5C, 0x73, 0x94, 0xAC, 0x88,
  40816. 0x26, 0x2A, 0x6D, 0xE7, 0x77, 0x0B, 0x2D, 0x88,
  40817. 0x43, 0xEC, 0x10, 0x1F, 0xFB, 0x5E, 0x84, 0xDE,
  40818. 0x2F, 0x7A, 0x8B, 0x74, 0xE7, 0x67, 0x4B, 0x3B,
  40819. 0x23, 0x19, 0xBD, 0x6B, 0xF4, 0x11, 0x2F, 0x92,
  40820. 0xC5, 0xCF, 0xC0, 0xA5, 0x5F, 0x7F, 0xA0, 0x61,
  40821. 0xF4, 0x53, 0x25, 0x40, 0x8D, 0x03, 0x9D, 0x51
  40822. };
  40823. static const byte sig_87[] = {
  40824. 0x4B, 0x3F, 0x52, 0xF0, 0x81, 0xB3, 0xD9, 0x14,
  40825. 0xBC, 0x7C, 0x6C, 0x07, 0x3B, 0x18, 0x2B, 0x26,
  40826. 0x8A, 0xDF, 0x51, 0x89, 0xE2, 0x98, 0xA8, 0x69,
  40827. 0xBF, 0xB9, 0x91, 0xB1, 0x99, 0x99, 0x3C, 0x10,
  40828. 0x42, 0xDE, 0xF5, 0xB5, 0x92, 0x70, 0xB6, 0xCD,
  40829. 0x3F, 0xF8, 0xF9, 0x07, 0xA1, 0xCB, 0x0D, 0x3B,
  40830. 0x6F, 0xED, 0xCA, 0x14, 0x38, 0x38, 0xF8, 0xF8,
  40831. 0x1E, 0x0C, 0x37, 0x0F, 0xFE, 0xEE, 0x6B, 0x25,
  40832. 0xCD, 0x07, 0x03, 0x56, 0x41, 0xA0, 0x51, 0x94,
  40833. 0x4E, 0xAB, 0x51, 0x6C, 0xFB, 0xB8, 0x01, 0x53,
  40834. 0x6B, 0x4F, 0x26, 0x2B, 0x16, 0x19, 0x8E, 0x7D,
  40835. 0xDB, 0x1D, 0x61, 0xC3, 0x5A, 0x64, 0xD9, 0x0D,
  40836. 0x39, 0x48, 0xCE, 0xAA, 0xC8, 0xEE, 0x58, 0x0D,
  40837. 0xCE, 0xF5, 0x40, 0xED, 0x99, 0xD9, 0x12, 0xBB,
  40838. 0xA2, 0xBC, 0x4F, 0x51, 0x45, 0xBB, 0x94, 0x9C,
  40839. 0x73, 0xCC, 0xBD, 0x58, 0x26, 0x13, 0xB1, 0x0E,
  40840. 0xAA, 0xE8, 0x63, 0xAC, 0xA3, 0x46, 0x83, 0xEB,
  40841. 0x92, 0x2B, 0x3D, 0xAD, 0xFC, 0x74, 0xF7, 0x6F,
  40842. 0x47, 0xE4, 0x97, 0x86, 0x02, 0x59, 0x24, 0x02,
  40843. 0xD9, 0x15, 0x43, 0x94, 0xEB, 0x09, 0xFB, 0xC2,
  40844. 0xEB, 0xCC, 0xC5, 0x94, 0x73, 0x2F, 0x2D, 0x8B,
  40845. 0xC3, 0x83, 0x50, 0xE5, 0x53, 0x5A, 0x44, 0x12,
  40846. 0xA7, 0x7A, 0xDD, 0x79, 0x16, 0x60, 0x45, 0x76,
  40847. 0xFD, 0x6A, 0x36, 0x31, 0xE5, 0x15, 0xBA, 0xF2,
  40848. 0x6A, 0x6F, 0x9C, 0xA4, 0x06, 0x1E, 0xBB, 0xDD,
  40849. 0x3B, 0xEC, 0x71, 0x79, 0xAD, 0x58, 0x55, 0x2A,
  40850. 0x5B, 0x50, 0x8F, 0x31, 0x34, 0x8A, 0x56, 0xAD,
  40851. 0x1A, 0xDA, 0x7A, 0x05, 0x35, 0x2C, 0x72, 0xC0,
  40852. 0x04, 0xB9, 0x4C, 0x47, 0xE7, 0x04, 0x9A, 0x10,
  40853. 0xB3, 0xA5, 0x9B, 0xF2, 0x38, 0xA8, 0xDF, 0xC6,
  40854. 0xC7, 0x01, 0x9A, 0x17, 0xF0, 0x5D, 0x5B, 0xFC,
  40855. 0xB9, 0xD9, 0x3D, 0x9D, 0x1C, 0xCB, 0xCB, 0x47,
  40856. 0xF8, 0xC4, 0x38, 0x09, 0x8F, 0xDB, 0xDF, 0xE2,
  40857. 0x3F, 0x9F, 0x78, 0xBC, 0x28, 0x06, 0x99, 0x08,
  40858. 0xC6, 0xB9, 0x89, 0x8B, 0x43, 0x4C, 0xBF, 0x37,
  40859. 0x78, 0x7E, 0x1A, 0xF6, 0xA6, 0xB8, 0x27, 0xE8,
  40860. 0x30, 0xE9, 0xF7, 0x62, 0x9C, 0xD8, 0xF5, 0x10,
  40861. 0x70, 0xC4, 0xC8, 0xA8, 0xDE, 0xB2, 0x60, 0xD0,
  40862. 0x7C, 0x3E, 0x41, 0xD8, 0x49, 0x04, 0x84, 0x87,
  40863. 0x74, 0x91, 0xB3, 0x9A, 0xA6, 0xD9, 0xE1, 0x0D,
  40864. 0x91, 0x74, 0x8B, 0x64, 0xE3, 0x31, 0x60, 0x62,
  40865. 0x9D, 0x8A, 0xE4, 0x3E, 0xFD, 0x5F, 0x85, 0x78,
  40866. 0x1E, 0x69, 0xF7, 0x6B, 0x68, 0x95, 0xC1, 0x41,
  40867. 0xEB, 0xCD, 0xDF, 0xEE, 0xB4, 0x85, 0xA0, 0x0B,
  40868. 0xDB, 0xA4, 0xF7, 0xC9, 0x91, 0xF5, 0x3F, 0x2F,
  40869. 0x84, 0x93, 0x39, 0x26, 0xAF, 0x39, 0xE6, 0x96,
  40870. 0x4A, 0xBF, 0x2D, 0xFE, 0xBB, 0xC1, 0x9A, 0x7E,
  40871. 0x31, 0xC5, 0x07, 0x97, 0xB8, 0xDA, 0x29, 0x31,
  40872. 0xE1, 0x0F, 0x3D, 0xAC, 0x49, 0x3F, 0x19, 0x8D,
  40873. 0xFD, 0x78, 0x5D, 0x21, 0xAD, 0xB2, 0xC0, 0x62,
  40874. 0xB0, 0x97, 0xE8, 0x89, 0xA2, 0x07, 0x37, 0xF1,
  40875. 0x86, 0x00, 0x8F, 0x29, 0x28, 0xF6, 0xB8, 0x4D,
  40876. 0x6E, 0x09, 0xE9, 0x75, 0xA8, 0xF2, 0xAA, 0xAD,
  40877. 0xC7, 0x85, 0x23, 0x42, 0x34, 0xFD, 0xA0, 0x37,
  40878. 0x03, 0xA7, 0xC2, 0x1F, 0x81, 0x2D, 0x65, 0x0B,
  40879. 0xD2, 0x51, 0x0B, 0x30, 0xF0, 0x55, 0x00, 0x81,
  40880. 0x04, 0x7A, 0x15, 0x5C, 0x84, 0x85, 0x86, 0xA9,
  40881. 0x6F, 0x10, 0x0D, 0x77, 0x4F, 0x3E, 0x39, 0xE0,
  40882. 0x29, 0xB0, 0x77, 0x7C, 0xD3, 0x3E, 0x68, 0x31,
  40883. 0x8A, 0x11, 0xC1, 0x98, 0x02, 0x93, 0xFA, 0xD3,
  40884. 0xE7, 0x87, 0xD2, 0x0D, 0xFE, 0x7E, 0xEE, 0x70,
  40885. 0x53, 0xC0, 0x5E, 0xEB, 0x6A, 0x15, 0x9B, 0xAA,
  40886. 0xD4, 0x02, 0x0B, 0x9E, 0xC3, 0xF5, 0x37, 0xDA,
  40887. 0x4D, 0xAD, 0xAF, 0xB3, 0xB1, 0xBB, 0x1D, 0xBE,
  40888. 0xB2, 0xD5, 0xB8, 0xF9, 0xD0, 0x5A, 0x01, 0x97,
  40889. 0x98, 0xEA, 0xE0, 0xED, 0x09, 0x9D, 0xB0, 0x66,
  40890. 0xD7, 0x3E, 0xE8, 0xE9, 0xA5, 0x6D, 0xE3, 0x68,
  40891. 0xE8, 0x78, 0xA7, 0xFF, 0x39, 0x14, 0x0D, 0x80,
  40892. 0x21, 0xD5, 0x00, 0x85, 0xE6, 0x25, 0x29, 0x41,
  40893. 0xAB, 0x31, 0x53, 0x09, 0xCB, 0x53, 0xAA, 0xA4,
  40894. 0x9E, 0x86, 0x34, 0x7F, 0xBA, 0xD5, 0x4A, 0x1F,
  40895. 0x87, 0x3E, 0x0C, 0xB4, 0xB8, 0x6A, 0x8D, 0x5B,
  40896. 0x1B, 0x2A, 0x95, 0xD4, 0x85, 0xF3, 0x7A, 0x9F,
  40897. 0xB6, 0x10, 0x5D, 0xF8, 0x44, 0x0F, 0xDB, 0x85,
  40898. 0x78, 0xF2, 0x62, 0x4C, 0x07, 0x93, 0x29, 0x56,
  40899. 0x9A, 0x75, 0xF3, 0x6F, 0x2C, 0x55, 0xD8, 0xD0,
  40900. 0x30, 0xFB, 0xFE, 0xAA, 0x88, 0x89, 0xAD, 0x74,
  40901. 0x6C, 0x32, 0x3B, 0x1A, 0xC4, 0xEC, 0x8C, 0x40,
  40902. 0x3E, 0x77, 0x5A, 0x6F, 0xBE, 0x59, 0x6E, 0x7E,
  40903. 0x6A, 0x5A, 0x28, 0x63, 0x57, 0x66, 0x25, 0x14,
  40904. 0x99, 0x40, 0x97, 0x6F, 0x7C, 0xC9, 0x36, 0x17,
  40905. 0xB4, 0x3F, 0xB1, 0x34, 0x89, 0x07, 0x4E, 0xCA,
  40906. 0xC5, 0xBE, 0xB1, 0xA4, 0xDF, 0xE5, 0x8B, 0x9A,
  40907. 0xD2, 0xE0, 0xC6, 0xA1, 0x5B, 0x76, 0xA7, 0xC2,
  40908. 0xD2, 0x08, 0x72, 0x5A, 0x31, 0x23, 0xCA, 0x4E,
  40909. 0x6F, 0x2C, 0x58, 0x47, 0xEE, 0x5F, 0xA8, 0x38,
  40910. 0x49, 0x19, 0xEF, 0x89, 0x01, 0x1D, 0x21, 0x9B,
  40911. 0x25, 0x7B, 0x3E, 0x4D, 0xC4, 0xF2, 0x09, 0x51,
  40912. 0x60, 0x84, 0x4C, 0xAE, 0xEA, 0xFC, 0xF8, 0x57,
  40913. 0x26, 0x0F, 0x1C, 0x63, 0xD3, 0xB0, 0x5A, 0x67,
  40914. 0xD3, 0xD0, 0xF2, 0xB0, 0xEC, 0x9D, 0xCC, 0x27,
  40915. 0x23, 0xF1, 0x37, 0x55, 0x75, 0x0B, 0xAE, 0x62,
  40916. 0xFC, 0xC3, 0x61, 0xCF, 0xB5, 0x84, 0xF7, 0x74,
  40917. 0xC0, 0x9A, 0xDF, 0x9A, 0x04, 0x31, 0xB2, 0x3E,
  40918. 0x48, 0x8C, 0x35, 0x9C, 0x0A, 0xEF, 0x5B, 0x1C,
  40919. 0x97, 0x87, 0xBD, 0x8F, 0x52, 0xB0, 0x83, 0xBC,
  40920. 0x9D, 0xBC, 0xC9, 0xB3, 0x03, 0x9F, 0x77, 0x7C,
  40921. 0x7E, 0x8E, 0xAB, 0xC8, 0x00, 0x78, 0x05, 0x0C,
  40922. 0xE6, 0xD4, 0x9C, 0x3B, 0xB7, 0x01, 0x68, 0xFA,
  40923. 0x21, 0x77, 0x29, 0x8F, 0xB0, 0xA8, 0xF7, 0x2C,
  40924. 0x1C, 0xD2, 0x8D, 0x66, 0x2A, 0x07, 0xDA, 0xE6,
  40925. 0xC7, 0xAC, 0xB7, 0xFB, 0x8E, 0x7F, 0xDD, 0x01,
  40926. 0xDF, 0xB2, 0x7C, 0x62, 0xEE, 0x68, 0x3F, 0x4E,
  40927. 0x5F, 0x88, 0xC7, 0xC1, 0xDD, 0xDD, 0x5E, 0xEC,
  40928. 0xC1, 0xC3, 0xAF, 0x85, 0x3F, 0x1F, 0xF6, 0xB1,
  40929. 0xD9, 0xDE, 0x67, 0x2F, 0x1B, 0xF6, 0x47, 0x3A,
  40930. 0xF0, 0x02, 0x1D, 0x8A, 0x3D, 0x4D, 0xD0, 0x4A,
  40931. 0x2F, 0xCA, 0x23, 0x25, 0xC7, 0x21, 0xCF, 0x1C,
  40932. 0x82, 0x16, 0x76, 0xD0, 0xA0, 0xD5, 0x74, 0x18,
  40933. 0x66, 0x25, 0xDE, 0x83, 0x1C, 0x84, 0x11, 0xF6,
  40934. 0x41, 0x79, 0xF9, 0x16, 0x7F, 0x78, 0xBC, 0xB2,
  40935. 0x2F, 0xB4, 0x1C, 0x2C, 0xDB, 0x63, 0xC4, 0xDB,
  40936. 0x5E, 0x13, 0x87, 0x66, 0xD3, 0x80, 0x35, 0x89,
  40937. 0x59, 0x8F, 0x11, 0x4F, 0x41, 0xBA, 0x42, 0xCD,
  40938. 0xB1, 0x34, 0x10, 0x20, 0x44, 0x9B, 0xA9, 0x96,
  40939. 0x56, 0x11, 0x39, 0x90, 0xB4, 0xE0, 0x22, 0xD8,
  40940. 0xDA, 0x20, 0xD7, 0x44, 0x49, 0x1C, 0x6E, 0xEA,
  40941. 0xB6, 0x7B, 0x91, 0x8E, 0x80, 0xFF, 0xF3, 0x43,
  40942. 0xCC, 0x5B, 0x4C, 0x8E, 0x58, 0xC3, 0x48, 0x4B,
  40943. 0x01, 0x25, 0xA6, 0x0C, 0x36, 0xAE, 0xF7, 0x63,
  40944. 0x89, 0x4D, 0x35, 0x14, 0x8B, 0x57, 0x8F, 0x41,
  40945. 0x7C, 0x3A, 0x98, 0xA1, 0x43, 0xED, 0xFE, 0x9F,
  40946. 0x8C, 0x95, 0xBC, 0xC3, 0x46, 0xC6, 0xF5, 0xEA,
  40947. 0xF9, 0x7A, 0xAD, 0x11, 0xDA, 0xE0, 0x1C, 0x47,
  40948. 0x7C, 0x22, 0x7A, 0x88, 0xD1, 0x0E, 0xCF, 0xDC,
  40949. 0xF4, 0x50, 0xB3, 0x7F, 0x88, 0x19, 0x68, 0x02,
  40950. 0x78, 0x49, 0xD9, 0xB4, 0x3E, 0x2B, 0xFF, 0x90,
  40951. 0xC6, 0xA3, 0x4A, 0xE4, 0x1B, 0x8B, 0xBD, 0x74,
  40952. 0x30, 0x83, 0xD3, 0xC5, 0x87, 0x86, 0xB0, 0x36,
  40953. 0x67, 0x1C, 0xD6, 0xEE, 0xD9, 0x4D, 0xAE, 0x51,
  40954. 0xF7, 0x61, 0x32, 0x47, 0xEF, 0x86, 0x07, 0xAC,
  40955. 0xF7, 0x4A, 0x3C, 0xCE, 0x93, 0x2F, 0x1C, 0x38,
  40956. 0x69, 0xBD, 0xB3, 0x5C, 0xA1, 0x7F, 0xC6, 0xBA,
  40957. 0x9F, 0x9C, 0x95, 0x6F, 0xF1, 0xD4, 0xD8, 0x80,
  40958. 0x94, 0x32, 0x5C, 0xAB, 0xCE, 0x41, 0x23, 0x3F,
  40959. 0xB1, 0xD8, 0x08, 0xEF, 0x41, 0x01, 0x03, 0x96,
  40960. 0xDE, 0xB0, 0xEC, 0xF5, 0x07, 0x34, 0xD8, 0x18,
  40961. 0xDD, 0xAB, 0x70, 0x01, 0x5A, 0x0A, 0xBD, 0xD1,
  40962. 0x92, 0x6D, 0xFA, 0x49, 0x1F, 0x71, 0x1A, 0xA8,
  40963. 0x5D, 0xA2, 0xA8, 0xEC, 0x60, 0xE3, 0x25, 0x5C,
  40964. 0xCF, 0x97, 0x5C, 0x23, 0xCC, 0x4E, 0x8D, 0xAF,
  40965. 0xDD, 0xED, 0x9F, 0xEC, 0x60, 0xA6, 0x46, 0x7C,
  40966. 0x45, 0xB0, 0x3C, 0xA4, 0x76, 0x49, 0x9A, 0xA3,
  40967. 0x31, 0xB0, 0xE3, 0x99, 0x95, 0x76, 0xCE, 0xC3,
  40968. 0x19, 0x1A, 0x9A, 0x62, 0xBC, 0x1B, 0xEA, 0xC1,
  40969. 0xEA, 0xF2, 0x0E, 0x18, 0xCF, 0xC3, 0x21, 0x61,
  40970. 0x27, 0xDE, 0x4A, 0xAE, 0x2E, 0x75, 0x20, 0x1F,
  40971. 0x9E, 0x42, 0x7E, 0x39, 0xBF, 0x92, 0x11, 0x50,
  40972. 0xEA, 0xB9, 0x49, 0x55, 0x9C, 0x02, 0x2D, 0x87,
  40973. 0x6F, 0xA2, 0x42, 0xC2, 0xA8, 0x45, 0xBC, 0xA7,
  40974. 0x23, 0x5F, 0x72, 0x1B, 0x00, 0x56, 0x78, 0x8A,
  40975. 0x44, 0xEC, 0xC3, 0xEB, 0x98, 0xF0, 0xF5, 0x02,
  40976. 0xB8, 0x9F, 0x8E, 0x74, 0x10, 0xEA, 0x56, 0x79,
  40977. 0xAE, 0x7C, 0x04, 0x34, 0xF1, 0x3A, 0xD8, 0x16,
  40978. 0x42, 0x1D, 0x2F, 0xEE, 0x30, 0xCB, 0xCB, 0x2D,
  40979. 0xAA, 0x6B, 0x85, 0x1C, 0xD1, 0xB6, 0xE9, 0x96,
  40980. 0xDA, 0x7A, 0x75, 0x7E, 0x4C, 0x4D, 0x85, 0x72,
  40981. 0xC8, 0xB6, 0x00, 0xDE, 0x85, 0xDD, 0xB6, 0x53,
  40982. 0x20, 0xD1, 0xCB, 0x71, 0xD9, 0x37, 0x83, 0x49,
  40983. 0xC0, 0xC4, 0x01, 0xAD, 0x4F, 0x9E, 0x91, 0x27,
  40984. 0x21, 0x39, 0x22, 0x8A, 0x8D, 0xA2, 0xF4, 0xFD,
  40985. 0x2F, 0x48, 0x89, 0x1A, 0x4D, 0xCB, 0x06, 0x6D,
  40986. 0x50, 0x1D, 0x44, 0x74, 0x83, 0xB6, 0x11, 0xBB,
  40987. 0x3C, 0x80, 0x55, 0x0A, 0x90, 0xEA, 0x0B, 0x73,
  40988. 0x2D, 0x63, 0x9D, 0x8B, 0x39, 0x26, 0xB6, 0xE7,
  40989. 0xC3, 0x54, 0x53, 0xED, 0x3C, 0xC1, 0x10, 0xBA,
  40990. 0xF5, 0x56, 0xCF, 0x46, 0xD8, 0xFC, 0x21, 0x77,
  40991. 0xE7, 0x6F, 0xB2, 0x66, 0x3B, 0x8B, 0xDD, 0x17,
  40992. 0x1E, 0x94, 0xC0, 0xAC, 0xAF, 0x25, 0xB9, 0x15,
  40993. 0x3B, 0x22, 0xBC, 0xA7, 0x49, 0x91, 0x67, 0x56,
  40994. 0xFB, 0x3E, 0xD3, 0x01, 0x8E, 0x09, 0x44, 0xB6,
  40995. 0xC3, 0xB9, 0xB6, 0xBF, 0xA1, 0x5B, 0x9B, 0xE8,
  40996. 0x03, 0xAC, 0x79, 0x33, 0x3C, 0xD2, 0xC3, 0xA2,
  40997. 0x7A, 0x26, 0xBC, 0x17, 0xCD, 0xA2, 0x57, 0x79,
  40998. 0x8A, 0xE1, 0x6B, 0x28, 0xB4, 0x63, 0xB6, 0xDF,
  40999. 0x3F, 0xA8, 0x7C, 0x2D, 0x74, 0x2D, 0x0F, 0x68,
  41000. 0x85, 0xBE, 0xE0, 0xBE, 0xC6, 0xE2, 0x0D, 0x01,
  41001. 0xE5, 0xDA, 0xDC, 0x86, 0x82, 0x3E, 0x92, 0xD6,
  41002. 0x0F, 0xEC, 0x79, 0xB0, 0xD2, 0x40, 0x24, 0x87,
  41003. 0x53, 0xE4, 0x20, 0x48, 0x38, 0x4C, 0x80, 0x42,
  41004. 0x89, 0x60, 0x48, 0x21, 0xA5, 0x7F, 0x4F, 0x9F,
  41005. 0x50, 0xAE, 0x0C, 0x38, 0x52, 0x7F, 0xE5, 0xA3,
  41006. 0x49, 0x38, 0xDD, 0xBC, 0xDC, 0xD9, 0xA1, 0xD0,
  41007. 0x20, 0x83, 0x9B, 0xEB, 0xB6, 0x2F, 0x9F, 0x41,
  41008. 0xFB, 0xA0, 0x80, 0x52, 0xAB, 0xB8, 0x2F, 0xAD,
  41009. 0xA8, 0x84, 0xCB, 0xE5, 0x63, 0x79, 0x11, 0x03,
  41010. 0xAA, 0x58, 0x55, 0x46, 0xEB, 0xFE, 0xB1, 0x12,
  41011. 0x72, 0xCC, 0x2E, 0x87, 0xA3, 0xB7, 0x5B, 0x3C,
  41012. 0x6B, 0xB1, 0x85, 0x3A, 0xE7, 0xF9, 0xCF, 0x55,
  41013. 0x85, 0xB2, 0x65, 0x3C, 0xF5, 0xEE, 0xA2, 0x44,
  41014. 0xD2, 0x04, 0xEB, 0x26, 0x9C, 0x56, 0xA2, 0x09,
  41015. 0x85, 0x16, 0x06, 0x59, 0xCB, 0x07, 0x25, 0xEE,
  41016. 0x13, 0xCE, 0x35, 0xD5, 0x5E, 0xB0, 0x95, 0xA5,
  41017. 0x34, 0x14, 0xF2, 0x32, 0xDF, 0x81, 0x08, 0xB1,
  41018. 0x80, 0x24, 0xEB, 0x0D, 0xBF, 0x34, 0x5E, 0xB5,
  41019. 0xCD, 0xAD, 0x0B, 0xCE, 0x72, 0x63, 0x50, 0x9A,
  41020. 0x34, 0x1D, 0x54, 0xA7, 0xD5, 0x34, 0xE5, 0x53,
  41021. 0xEA, 0xEF, 0xFE, 0x4E, 0x24, 0x2E, 0xA2, 0x3B,
  41022. 0xCF, 0xE5, 0x9A, 0x58, 0xA6, 0x04, 0x25, 0x88,
  41023. 0x2C, 0xB7, 0xE3, 0xB0, 0xC9, 0xE4, 0xAF, 0xE8,
  41024. 0x69, 0x8E, 0x3D, 0xF5, 0x6A, 0xFD, 0x6D, 0x61,
  41025. 0x1E, 0x91, 0x68, 0x74, 0x7D, 0x87, 0x35, 0xCF,
  41026. 0x92, 0x46, 0xD9, 0x4F, 0x21, 0x26, 0xBE, 0x72,
  41027. 0x7F, 0xB4, 0x2B, 0x22, 0x41, 0xA8, 0x3B, 0x34,
  41028. 0xF0, 0xB9, 0xEB, 0x47, 0x93, 0x8D, 0x72, 0x65,
  41029. 0x02, 0xC5, 0x4E, 0x45, 0x72, 0x76, 0x63, 0x31,
  41030. 0x62, 0x8F, 0xA5, 0xCD, 0xA8, 0x93, 0xC3, 0x53,
  41031. 0x76, 0xAB, 0x45, 0x38, 0xFF, 0x87, 0x17, 0xC2,
  41032. 0x79, 0x5B, 0x0F, 0x51, 0xF0, 0x8E, 0x11, 0x37,
  41033. 0x61, 0x2B, 0x89, 0xB0, 0xC1, 0xE2, 0xCD, 0x1F,
  41034. 0x09, 0x9E, 0x88, 0x55, 0x69, 0x23, 0xAE, 0x57,
  41035. 0xA1, 0xDA, 0xD2, 0xAF, 0xB1, 0x23, 0x0B, 0x50,
  41036. 0x94, 0xA1, 0xB2, 0x1B, 0xAD, 0x7D, 0xBB, 0xC3,
  41037. 0x33, 0xA9, 0x7F, 0x17, 0x93, 0x04, 0x71, 0x8F,
  41038. 0x32, 0x89, 0xB6, 0xDE, 0x31, 0x31, 0x5B, 0x74,
  41039. 0xC1, 0xA7, 0x3A, 0xC7, 0x75, 0x6F, 0xAA, 0x4D,
  41040. 0x7E, 0xB5, 0x68, 0xBB, 0xC6, 0xF7, 0xE7, 0x88,
  41041. 0xCD, 0x08, 0x9B, 0x39, 0x55, 0x64, 0xD2, 0x17,
  41042. 0x6B, 0x00, 0x56, 0xDF, 0xFE, 0x95, 0x2C, 0x77,
  41043. 0x48, 0xB0, 0x48, 0x30, 0x67, 0x20, 0xF6, 0x02,
  41044. 0xB6, 0x7E, 0x8F, 0x6A, 0xDC, 0xC9, 0x1F, 0x8E,
  41045. 0x3A, 0xA4, 0xB8, 0xC4, 0xD7, 0xFA, 0xC2, 0x33,
  41046. 0xAA, 0xF9, 0x36, 0x53, 0xAD, 0x22, 0x09, 0xE2,
  41047. 0xFF, 0x92, 0xDA, 0x30, 0xC2, 0xD5, 0x3F, 0xDE,
  41048. 0xF6, 0xF4, 0xC9, 0x0E, 0xAA, 0x0D, 0xE6, 0x0D,
  41049. 0x59, 0x4A, 0xDA, 0x39, 0x15, 0xDB, 0x24, 0x27,
  41050. 0x9D, 0x86, 0x74, 0x76, 0xEA, 0xD7, 0x57, 0xB4,
  41051. 0xC0, 0x26, 0x4A, 0x1D, 0xB8, 0xA1, 0xF5, 0x7A,
  41052. 0x1B, 0x5D, 0x71, 0x73, 0xBB, 0x1A, 0x96, 0x0C,
  41053. 0xE0, 0x2F, 0xDE, 0xFE, 0xF1, 0x60, 0xD5, 0x12,
  41054. 0x66, 0x7D, 0x65, 0x52, 0x68, 0xFC, 0xC3, 0xA1,
  41055. 0x53, 0xA4, 0x31, 0x47, 0x82, 0xA0, 0xEB, 0xFF,
  41056. 0x84, 0xF6, 0x5F, 0x14, 0xA0, 0xE3, 0xE1, 0x2A,
  41057. 0x13, 0x25, 0x0C, 0x07, 0xD0, 0x8C, 0x22, 0x5B,
  41058. 0x11, 0xA6, 0x83, 0x1B, 0xC2, 0x5C, 0x40, 0x46,
  41059. 0x7B, 0x76, 0x80, 0x04, 0xDD, 0xE0, 0xE8, 0x74,
  41060. 0xA5, 0x11, 0x44, 0xC1, 0x89, 0x20, 0xBD, 0xF2,
  41061. 0x86, 0x09, 0x0B, 0x59, 0xF5, 0x15, 0x64, 0xEA,
  41062. 0x40, 0x70, 0xFB, 0xBF, 0x61, 0xE3, 0x69, 0x64,
  41063. 0x35, 0xF2, 0x8F, 0x63, 0x33, 0x2B, 0x64, 0x49,
  41064. 0x6D, 0xF3, 0xEC, 0x8B, 0x65, 0xD5, 0x4E, 0x1C,
  41065. 0xF4, 0x78, 0x9D, 0xDA, 0xB1, 0x22, 0xDA, 0x6B,
  41066. 0x26, 0x4D, 0x31, 0x2A, 0x71, 0x1C, 0x12, 0x9E,
  41067. 0x3B, 0x07, 0xF4, 0xC6, 0xDA, 0x25, 0xA5, 0x61,
  41068. 0x73, 0xAF, 0x58, 0xB9, 0x0A, 0x71, 0xB7, 0xAC,
  41069. 0xFA, 0x31, 0x61, 0xA8, 0x1F, 0x59, 0xD1, 0x79,
  41070. 0x14, 0xC9, 0x9B, 0xBA, 0xC4, 0xF9, 0xA3, 0x14,
  41071. 0x97, 0x7A, 0x89, 0xCE, 0xF7, 0x69, 0x69, 0x43,
  41072. 0x60, 0x9B, 0xB4, 0x82, 0x79, 0x64, 0xFB, 0x29,
  41073. 0x76, 0x40, 0x3B, 0xD4, 0x99, 0x6F, 0x1E, 0x84,
  41074. 0x2B, 0xF5, 0xAA, 0xAE, 0x1E, 0xCC, 0xA1, 0x12,
  41075. 0x55, 0xB9, 0xE6, 0x00, 0x1C, 0x20, 0xF7, 0x2F,
  41076. 0x1F, 0xD5, 0xE3, 0x2C, 0xDA, 0x32, 0xD8, 0xA7,
  41077. 0xAC, 0x5F, 0x62, 0xB0, 0x9A, 0x0E, 0x61, 0x58,
  41078. 0x47, 0xCA, 0x74, 0x6F, 0x48, 0x95, 0x15, 0xCF,
  41079. 0x8F, 0x18, 0x31, 0x62, 0x85, 0x9F, 0x53, 0xB9,
  41080. 0x7E, 0x9E, 0x5C, 0xA8, 0x00, 0xEE, 0x62, 0x4F,
  41081. 0x72, 0x98, 0x43, 0xA0, 0x00, 0x91, 0x64, 0xA4,
  41082. 0xA9, 0xFF, 0x76, 0xEB, 0x34, 0xE4, 0x70, 0x41,
  41083. 0x84, 0x84, 0x8A, 0x13, 0x9A, 0xD9, 0x7D, 0x90,
  41084. 0x9F, 0x7A, 0x7E, 0xD1, 0x14, 0xF0, 0x87, 0xA4,
  41085. 0xB2, 0xE1, 0xB4, 0xA3, 0x03, 0x23, 0x91, 0x16,
  41086. 0x0B, 0x6F, 0x3A, 0x36, 0x49, 0xFF, 0x15, 0xAE,
  41087. 0xA2, 0xB7, 0x10, 0x7A, 0xF8, 0xA3, 0xB5, 0xFC,
  41088. 0xAD, 0x61, 0xD4, 0x3D, 0x60, 0x2E, 0x62, 0x86,
  41089. 0xA9, 0x00, 0x87, 0x0C, 0xC8, 0xCE, 0x24, 0xE3,
  41090. 0x9E, 0x78, 0xF0, 0x39, 0x7A, 0x0D, 0x7E, 0x27,
  41091. 0xE8, 0xE2, 0xD4, 0x77, 0x6A, 0x44, 0xCB, 0xA2,
  41092. 0x18, 0xEB, 0xCD, 0x88, 0xB3, 0xC2, 0x8C, 0x18,
  41093. 0x2A, 0x7C, 0x9F, 0x4D, 0xBB, 0x2D, 0xBB, 0x5E,
  41094. 0x98, 0x15, 0x63, 0xD6, 0x6C, 0xEE, 0xB7, 0x7E,
  41095. 0x7F, 0x90, 0x34, 0xBD, 0x42, 0x9D, 0x27, 0x63,
  41096. 0x7C, 0xF7, 0x97, 0xDE, 0x82, 0xE0, 0x1F, 0xEB,
  41097. 0xBC, 0xE2, 0x17, 0x1E, 0xFD, 0x01, 0x6E, 0x40,
  41098. 0x2A, 0x42, 0xD7, 0x8E, 0xA1, 0xAC, 0xE2, 0xCB,
  41099. 0x37, 0x0E, 0x75, 0xC9, 0x0A, 0xDF, 0xA1, 0xA7,
  41100. 0x93, 0xB2, 0x16, 0x9C, 0xC2, 0x65, 0x22, 0xDB,
  41101. 0x2F, 0x54, 0x6A, 0xC1, 0xDE, 0x34, 0xC9, 0x08,
  41102. 0x71, 0x20, 0xC4, 0x2A, 0x9F, 0x10, 0xC0, 0x0D,
  41103. 0x49, 0x3C, 0x25, 0x73, 0x01, 0x66, 0xF9, 0xD2,
  41104. 0x19, 0xFB, 0xDA, 0xD2, 0x22, 0xC8, 0xB2, 0x81,
  41105. 0x15, 0x54, 0x33, 0x13, 0x21, 0x08, 0x48, 0xFB,
  41106. 0x2F, 0x04, 0xBF, 0xDC, 0xE1, 0x5D, 0x32, 0x0C,
  41107. 0x36, 0x34, 0xA8, 0xE4, 0xD6, 0x37, 0x55, 0x51,
  41108. 0x59, 0x00, 0xC7, 0x5B, 0xFD, 0x09, 0x0A, 0xD7,
  41109. 0x8D, 0xD5, 0x88, 0x65, 0x9F, 0xBF, 0x97, 0xC9,
  41110. 0x6E, 0x0D, 0x0A, 0xCC, 0x8E, 0x81, 0x5E, 0x60,
  41111. 0x8F, 0x9E, 0x86, 0x1D, 0x79, 0xAF, 0x30, 0x51,
  41112. 0xB9, 0x42, 0xB5, 0x25, 0x70, 0xB6, 0x29, 0x2B,
  41113. 0xF4, 0x8C, 0x2B, 0xFA, 0xA9, 0x07, 0x7D, 0xC7,
  41114. 0x6F, 0xE9, 0x02, 0x68, 0x32, 0x17, 0xB8, 0xBF,
  41115. 0x80, 0x9E, 0xD7, 0xA0, 0x05, 0x0A, 0xDD, 0xBB,
  41116. 0x65, 0xFD, 0xDF, 0xBD, 0x24, 0x01, 0x9C, 0x91,
  41117. 0x81, 0xB5, 0xAC, 0x81, 0x56, 0x61, 0x13, 0xD6,
  41118. 0x69, 0x4E, 0xA6, 0x29, 0x1D, 0x7F, 0x4A, 0x7F,
  41119. 0x56, 0xA4, 0x1E, 0xB9, 0x1F, 0x76, 0x36, 0x8D,
  41120. 0xF8, 0x2B, 0x16, 0x4B, 0x48, 0x59, 0x25, 0x9D,
  41121. 0x71, 0x89, 0x24, 0x0F, 0x1D, 0x88, 0x03, 0xF8,
  41122. 0x10, 0x72, 0x96, 0xD3, 0x78, 0xBA, 0xB4, 0xD2,
  41123. 0x4F, 0xE6, 0xD1, 0x0E, 0xF7, 0x88, 0x36, 0x7B,
  41124. 0xCE, 0x16, 0xC5, 0xAB, 0x77, 0xFB, 0xC1, 0x68,
  41125. 0xB8, 0x57, 0xF7, 0xBA, 0x5C, 0xDC, 0xBE, 0x50,
  41126. 0x67, 0xC8, 0x64, 0xF8, 0x79, 0x80, 0x9F, 0xE5,
  41127. 0x21, 0x7D, 0xEF, 0x02, 0x94, 0xBF, 0xAF, 0xDF,
  41128. 0x80, 0x9A, 0xBC, 0xE9, 0x53, 0x2D, 0xD9, 0xDA,
  41129. 0xB3, 0x44, 0x8F, 0x4D, 0xA6, 0x8E, 0xCA, 0x51,
  41130. 0x60, 0x94, 0x76, 0x27, 0x8E, 0xB8, 0xC4, 0xF6,
  41131. 0x9E, 0xA2, 0x96, 0x73, 0xF6, 0x94, 0x18, 0x04,
  41132. 0x1D, 0x26, 0x85, 0x7E, 0xBC, 0x24, 0xA4, 0x87,
  41133. 0xBB, 0x4B, 0x0B, 0xA6, 0x3A, 0xF8, 0x48, 0x54,
  41134. 0x5E, 0xE9, 0xBE, 0x89, 0xF1, 0x39, 0xD5, 0x02,
  41135. 0x09, 0x9B, 0x9D, 0x35, 0xDB, 0x38, 0x07, 0xB9,
  41136. 0x25, 0xCB, 0xA5, 0x76, 0xE2, 0x71, 0x70, 0xEA,
  41137. 0xEC, 0x48, 0xCC, 0x2C, 0xC1, 0x5B, 0x04, 0x36,
  41138. 0x77, 0x82, 0x5D, 0x0E, 0xE8, 0x1E, 0xB2, 0xCE,
  41139. 0xE3, 0xA8, 0xED, 0x14, 0xA7, 0x98, 0xB8, 0x79,
  41140. 0x53, 0x02, 0x20, 0xE5, 0x0C, 0xE8, 0xC0, 0x03,
  41141. 0xA3, 0x05, 0x38, 0x2A, 0x24, 0xD2, 0x3C, 0x27,
  41142. 0x7B, 0x99, 0xD1, 0xF4, 0xC5, 0x4F, 0x9A, 0x8D,
  41143. 0x33, 0xFA, 0x3D, 0x1E, 0x33, 0x7E, 0x18, 0xD7,
  41144. 0xCB, 0xBA, 0x5E, 0x5A, 0x47, 0xF2, 0xD5, 0xE0,
  41145. 0x96, 0xCF, 0x45, 0x51, 0xB2, 0x3B, 0x1B, 0x86,
  41146. 0x43, 0x6E, 0x81, 0xB4, 0xA0, 0x9D, 0x1E, 0x3D,
  41147. 0x38, 0x49, 0x2E, 0xC8, 0xB2, 0xA0, 0x09, 0x67,
  41148. 0x01, 0x6A, 0xB7, 0x6B, 0x9A, 0x9B, 0x18, 0x64,
  41149. 0x67, 0x14, 0x21, 0xDA, 0x56, 0xF5, 0x7D, 0x00,
  41150. 0x8D, 0x5C, 0xE1, 0xB8, 0x92, 0xA7, 0xE9, 0xC1,
  41151. 0xF6, 0x9F, 0x6C, 0x72, 0x2C, 0xF1, 0x09, 0xDB,
  41152. 0x50, 0x0E, 0x53, 0xF6, 0xBC, 0x07, 0x83, 0x7A,
  41153. 0xD1, 0xCD, 0x4C, 0xF4, 0xA6, 0x4D, 0xA7, 0x63,
  41154. 0xB4, 0xA9, 0xC4, 0x92, 0x9B, 0x0D, 0xCD, 0xDF,
  41155. 0x7C, 0x7E, 0x11, 0x86, 0xBE, 0x3F, 0xF0, 0xC3,
  41156. 0x21, 0x15, 0x84, 0x37, 0x82, 0x0C, 0x81, 0xE7,
  41157. 0x4F, 0xF3, 0x16, 0xAE, 0x32, 0x54, 0xE9, 0x72,
  41158. 0xFC, 0x19, 0x7A, 0x7F, 0x0E, 0x62, 0x02, 0x42,
  41159. 0xAC, 0x05, 0xA4, 0xE4, 0x3E, 0x98, 0x7C, 0x2A,
  41160. 0x83, 0x55, 0xB0, 0x35, 0x77, 0x45, 0xCA, 0x79,
  41161. 0xE6, 0xAE, 0x48, 0xAB, 0x29, 0xED, 0x4F, 0xA6,
  41162. 0x3D, 0x3A, 0x1F, 0x19, 0xB9, 0x99, 0xDE, 0x25,
  41163. 0x1F, 0xDE, 0x06, 0x40, 0xDD, 0x87, 0x87, 0x6D,
  41164. 0x55, 0x76, 0x28, 0x78, 0xAD, 0x1D, 0xB1, 0x2D,
  41165. 0x65, 0xBA, 0xFD, 0x14, 0xB6, 0xA9, 0xA7, 0x08,
  41166. 0x1B, 0xF2, 0x3F, 0x9F, 0x06, 0xD9, 0x0C, 0xE2,
  41167. 0x73, 0xC5, 0xA2, 0x6E, 0x01, 0x2C, 0xA9, 0x4D,
  41168. 0xD4, 0x81, 0xD3, 0x2E, 0x10, 0x93, 0x8C, 0x16,
  41169. 0x51, 0x63, 0xE8, 0x9B, 0xE8, 0xA9, 0x3A, 0x63,
  41170. 0x03, 0x4D, 0x34, 0x5B, 0x74, 0xE2, 0xA9, 0x4E,
  41171. 0xF6, 0x43, 0xD0, 0x6A, 0xF9, 0xE1, 0xF5, 0xC9,
  41172. 0xF1, 0x04, 0x93, 0x0D, 0xA0, 0x0E, 0x61, 0xE0,
  41173. 0x61, 0xEE, 0x8C, 0x3B, 0xB1, 0x7C, 0x11, 0xE0,
  41174. 0x5D, 0x45, 0xC1, 0x68, 0x2E, 0x4D, 0x59, 0x3C,
  41175. 0x91, 0x98, 0x23, 0x8D, 0x2B, 0xA2, 0x89, 0x77,
  41176. 0x9E, 0x7D, 0x0F, 0x22, 0x7B, 0xCB, 0x0B, 0x09,
  41177. 0x97, 0x2B, 0x19, 0x77, 0x0F, 0xF0, 0x11, 0xBF,
  41178. 0x6C, 0x60, 0xD9, 0xD1, 0x93, 0xCF, 0xAB, 0x32,
  41179. 0x74, 0x7A, 0x00, 0x95, 0xE1, 0xA4, 0xAD, 0x32,
  41180. 0x51, 0x4C, 0x78, 0x2E, 0xF3, 0xDE, 0x7A, 0x26,
  41181. 0xEA, 0x77, 0x1F, 0x55, 0x30, 0xD9, 0xDE, 0x97,
  41182. 0x36, 0xD0, 0xF6, 0xAE, 0x1A, 0xFB, 0x78, 0xEC,
  41183. 0x7C, 0xE4, 0x88, 0x4A, 0x1B, 0xB4, 0x36, 0xCF,
  41184. 0xCE, 0x45, 0x9C, 0xD9, 0x93, 0x58, 0x26, 0x09,
  41185. 0x06, 0xAA, 0xC9, 0x97, 0x16, 0xA5, 0x36, 0xCC,
  41186. 0x76, 0x87, 0xA0, 0x37, 0x5F, 0xDA, 0x11, 0x00,
  41187. 0x76, 0x18, 0xE5, 0x53, 0x53, 0x4E, 0x54, 0xD5,
  41188. 0xB2, 0x14, 0xF7, 0xAA, 0x6F, 0xC7, 0xDB, 0xE3,
  41189. 0x7C, 0x2B, 0xD2, 0xB6, 0x48, 0x50, 0xAE, 0x46,
  41190. 0x9A, 0x98, 0x58, 0x98, 0x7F, 0x3F, 0xA4, 0xB1,
  41191. 0xFD, 0x26, 0xD9, 0x54, 0xBF, 0xEC, 0x36, 0x5D,
  41192. 0xBE, 0x06, 0xDD, 0xCD, 0x61, 0x5E, 0x1F, 0xED,
  41193. 0x58, 0xA8, 0x86, 0x76, 0x40, 0x2D, 0x1D, 0x6B,
  41194. 0x58, 0x14, 0x85, 0x49, 0x8B, 0x5A, 0xDF, 0xFF,
  41195. 0xC4, 0x2D, 0x47, 0xD6, 0x1D, 0xF9, 0x93, 0x84,
  41196. 0xE2, 0x2C, 0x51, 0x57, 0xF0, 0x17, 0x8A, 0x6F,
  41197. 0xDA, 0xF8, 0xF4, 0xA9, 0x49, 0x1D, 0xAF, 0x29,
  41198. 0x8B, 0x2C, 0x3E, 0xC8, 0x80, 0x85, 0x02, 0x2C,
  41199. 0x0A, 0x7C, 0xF2, 0x45, 0xED, 0x0F, 0xB5, 0xA3,
  41200. 0x8C, 0xD1, 0x6F, 0x30, 0xD3, 0x7D, 0xA5, 0xC4,
  41201. 0x95, 0x9A, 0x55, 0x50, 0x1D, 0xAD, 0x50, 0xF1,
  41202. 0xB4, 0x8B, 0xBB, 0xDD, 0x86, 0xAB, 0x8B, 0xB5,
  41203. 0x22, 0xA9, 0x36, 0xDD, 0xF0, 0x00, 0x3B, 0x81,
  41204. 0xBE, 0x16, 0x23, 0x1A, 0x04, 0xE7, 0xA5, 0x89,
  41205. 0xC5, 0x6F, 0xFF, 0xB5, 0x1B, 0x07, 0x92, 0x7B,
  41206. 0x4A, 0xFA, 0x1D, 0xB7, 0xD4, 0x8B, 0xC6, 0xFB,
  41207. 0xC3, 0xF3, 0x67, 0x56, 0x37, 0x18, 0x4B, 0x7A,
  41208. 0xDB, 0x9B, 0xAD, 0xF4, 0xDE, 0x7C, 0x08, 0x5B,
  41209. 0xCA, 0x1D, 0x42, 0x8D, 0xC9, 0xFC, 0x82, 0x77,
  41210. 0xCB, 0xD8, 0x58, 0x84, 0xA5, 0x92, 0x1B, 0x52,
  41211. 0xBB, 0x05, 0xB7, 0x10, 0x61, 0x55, 0x08, 0x26,
  41212. 0x1B, 0xB4, 0x54, 0x6B, 0xD6, 0xE1, 0xFC, 0x73,
  41213. 0x0D, 0x16, 0xB0, 0x49, 0xEA, 0x12, 0x79, 0x8C,
  41214. 0xE2, 0xE6, 0xDF, 0x43, 0xF5, 0xB8, 0xF3, 0xEF,
  41215. 0x9A, 0xC8, 0xFB, 0xAE, 0x31, 0xB0, 0x11, 0xE1,
  41216. 0x0C, 0x4F, 0xC6, 0x2F, 0xFD, 0x7F, 0x39, 0xD1,
  41217. 0x6E, 0xC3, 0x2C, 0xA8, 0x21, 0x0E, 0xD1, 0x6E,
  41218. 0x04, 0x1D, 0xA4, 0x3D, 0x92, 0x74, 0x22, 0x95,
  41219. 0x14, 0x05, 0x4A, 0x0F, 0x82, 0xD4, 0x62, 0xFE,
  41220. 0x08, 0x0C, 0x6F, 0xFD, 0x7B, 0xBD, 0xBF, 0xBF,
  41221. 0x0B, 0xFF, 0xC6, 0xD5, 0xEC, 0xC4, 0x32, 0xA3,
  41222. 0x25, 0x6C, 0x0B, 0xE0, 0xDD, 0xFD, 0x5D, 0x90,
  41223. 0x80, 0xC6, 0x76, 0xC7, 0x95, 0x5D, 0x66, 0xE4,
  41224. 0x4D, 0x1C, 0xE5, 0x1F, 0xCC, 0x23, 0x82, 0xF8,
  41225. 0x68, 0xD7, 0x32, 0xE8, 0x58, 0x51, 0x72, 0x1B,
  41226. 0x48, 0xA0, 0x1D, 0x08, 0xC6, 0x39, 0x62, 0x6E,
  41227. 0xE0, 0x50, 0x9C, 0xB5, 0x81, 0xEF, 0xF5, 0x62,
  41228. 0x8F, 0xA6, 0xCC, 0xD1, 0x08, 0x9A, 0xC0, 0xE1,
  41229. 0x2D, 0xEB, 0xE0, 0x85, 0x17, 0x82, 0xE6, 0x4C,
  41230. 0x50, 0x49, 0xCB, 0xD6, 0x50, 0x10, 0x13, 0x96,
  41231. 0x5C, 0xC0, 0xCA, 0x25, 0xAC, 0xAB, 0x17, 0x6E,
  41232. 0xF7, 0xCA, 0xB9, 0x29, 0x40, 0x98, 0x5D, 0xDB,
  41233. 0x49, 0x02, 0x1D, 0xF6, 0xC6, 0x0D, 0x6C, 0x4A,
  41234. 0x48, 0x91, 0x16, 0x31, 0x1E, 0x86, 0xBA, 0x19,
  41235. 0xED, 0xF0, 0x0D, 0x74, 0x79, 0x73, 0x58, 0x20,
  41236. 0x7C, 0xDE, 0x50, 0x50, 0x6D, 0x00, 0x7F, 0xE0,
  41237. 0x3C, 0x88, 0x04, 0xC6, 0x64, 0x51, 0xF0, 0x2A,
  41238. 0x01, 0x82, 0xD3, 0x87, 0xB7, 0x59, 0x89, 0x40,
  41239. 0x96, 0xF6, 0x52, 0x32, 0x95, 0x2D, 0x18, 0x3D,
  41240. 0xBA, 0xAA, 0xBB, 0x6B, 0xC0, 0xE1, 0x91, 0xDC,
  41241. 0x2C, 0x3F, 0x75, 0xFC, 0x72, 0xBD, 0x61, 0xBA,
  41242. 0xB2, 0xEF, 0x19, 0xB6, 0x53, 0x2B, 0x23, 0x1C,
  41243. 0x4A, 0xFB, 0x1A, 0x9C, 0x2C, 0xB2, 0xF3, 0xD6,
  41244. 0xC4, 0x51, 0xE8, 0x44, 0x0D, 0x6A, 0x92, 0x3C,
  41245. 0xF7, 0x2A, 0x63, 0xE2, 0xED, 0x85, 0x54, 0x77,
  41246. 0x38, 0x87, 0x91, 0x0C, 0xA5, 0xC6, 0x71, 0xAD,
  41247. 0x4F, 0xD5, 0x92, 0x3C, 0xB9, 0x5E, 0xC7, 0x3F,
  41248. 0xFD, 0xFB, 0xDA, 0x4B, 0x66, 0x55, 0xF5, 0x5D,
  41249. 0xBF, 0xD1, 0x31, 0x7D, 0x02, 0x44, 0x22, 0x30,
  41250. 0x1E, 0xD6, 0x6A, 0x6E, 0x4C, 0x67, 0x20, 0x85,
  41251. 0xCE, 0xD1, 0xF4, 0xC7, 0xB0, 0x50, 0x30, 0xA1,
  41252. 0x00, 0xC4, 0x78, 0x8F, 0xEF, 0x4C, 0xD3, 0xE4,
  41253. 0x94, 0xA8, 0x53, 0xBD, 0xE6, 0x3E, 0x9D, 0x44,
  41254. 0x9A, 0xE3, 0xBB, 0x6B, 0xA1, 0x08, 0x32, 0x38,
  41255. 0xDA, 0x3F, 0x40, 0x90, 0x51, 0x5D, 0x14, 0x3C,
  41256. 0x67, 0xDB, 0xE5, 0x3D, 0x8D, 0x50, 0x7A, 0x52,
  41257. 0x29, 0xFF, 0xEB, 0x20, 0x72, 0xD0, 0xBD, 0x09,
  41258. 0x2F, 0xC9, 0xAE, 0x52, 0xDE, 0xAA, 0xAC, 0xD1,
  41259. 0xF0, 0xF1, 0x4B, 0x5A, 0xC8, 0x47, 0x52, 0xBF,
  41260. 0xD0, 0x02, 0x5E, 0x5F, 0x55, 0xB8, 0x69, 0x35,
  41261. 0x0F, 0x4B, 0x27, 0x19, 0xC5, 0xC0, 0x5A, 0xC1,
  41262. 0x66, 0x9B, 0xB0, 0xFD, 0x3C, 0x61, 0x4A, 0xCE,
  41263. 0x02, 0xA2, 0x70, 0x61, 0x3F, 0xD3, 0x30, 0x97,
  41264. 0x06, 0xDD, 0xCD, 0x5B, 0x1A, 0x6A, 0xD2, 0x6F,
  41265. 0x35, 0x9A, 0xDA, 0x80, 0xB3, 0x0E, 0x50, 0xA7,
  41266. 0xE5, 0x0B, 0xBD, 0x3A, 0xA4, 0x5D, 0x06, 0x54,
  41267. 0xDD, 0x7D, 0x05, 0x8B, 0x0B, 0xBF, 0x4D, 0x0D,
  41268. 0x92, 0x13, 0x51, 0x42, 0x21, 0x4E, 0xE7, 0x05,
  41269. 0x11, 0xF3, 0x67, 0x6A, 0xE6, 0x43, 0xB5, 0xF2,
  41270. 0x45, 0x06, 0x3B, 0x94, 0x19, 0xCF, 0x6B, 0x49,
  41271. 0xFD, 0x64, 0x7F, 0x27, 0xD7, 0xC4, 0x1C, 0x86,
  41272. 0x6E, 0x6C, 0xAD, 0x9D, 0x5E, 0x2E, 0x3E, 0x33,
  41273. 0x1B, 0xF6, 0xB9, 0xF7, 0x2A, 0xCA, 0x32, 0x9B,
  41274. 0xB6, 0x42, 0x59, 0xC3, 0xE7, 0x97, 0x83, 0xA2,
  41275. 0x66, 0x74, 0xB7, 0xD3, 0x8E, 0xBD, 0xE8, 0x31,
  41276. 0x84, 0x11, 0xF4, 0x76, 0x4E, 0xBD, 0xC4, 0xC7,
  41277. 0xE4, 0x1A, 0xCF, 0xF8, 0x5B, 0xBB, 0x30, 0x31,
  41278. 0x8D, 0x59, 0xC4, 0x2C, 0x92, 0x03, 0xAB, 0xD6,
  41279. 0x63, 0x6B, 0xA3, 0xF7, 0x72, 0xB6, 0x72, 0x51,
  41280. 0x21, 0xC0, 0x52, 0xDE, 0x99, 0x91, 0x0D, 0x55,
  41281. 0x15, 0x8C, 0x6F, 0x3E, 0xF8, 0xBB, 0x7F, 0xED,
  41282. 0xE2, 0xF8, 0x1E, 0x58, 0xA7, 0xAE, 0xB2, 0x5E,
  41283. 0x2E, 0x46, 0xFD, 0x72, 0x32, 0x30, 0x2F, 0xAF,
  41284. 0xA8, 0xFC, 0x37, 0xFC, 0x8B, 0x55, 0xD5, 0x94,
  41285. 0xB7, 0x6E, 0xC4, 0xA5, 0x3E, 0xB1, 0x1E, 0xB3,
  41286. 0xFD, 0x63, 0x44, 0x28, 0xAA, 0xA5, 0xD8, 0x6F,
  41287. 0x83, 0x9D, 0x08, 0x9A, 0xBE, 0x2F, 0xEF, 0xE2,
  41288. 0xAE, 0x52, 0x62, 0xFE, 0xFC, 0x73, 0x48, 0xD8,
  41289. 0x36, 0x69, 0x2E, 0xDB, 0x21, 0x5D, 0x6F, 0x8F,
  41290. 0x54, 0x8B, 0x88, 0x52, 0x90, 0xC2, 0x40, 0x3C,
  41291. 0x51, 0xC3, 0xE2, 0x69, 0xD4, 0x93, 0xFB, 0xD3,
  41292. 0x39, 0xB5, 0xDF, 0xB0, 0xA3, 0x8E, 0xED, 0xA7,
  41293. 0x75, 0x4D, 0xAF, 0xFA, 0x16, 0xE5, 0xBC, 0xA5,
  41294. 0xA9, 0xBB, 0xDE, 0x04, 0xB0, 0x14, 0xB7, 0xAE,
  41295. 0xA8, 0x98, 0x8F, 0x37, 0x49, 0xD5, 0x2D, 0x2F,
  41296. 0xC1, 0xC9, 0xF7, 0xC7, 0xB2, 0xC2, 0xD6, 0x92,
  41297. 0xE7, 0x89, 0x6E, 0x4C, 0x34, 0xF5, 0x7C, 0x55,
  41298. 0x8C, 0xFE, 0x83, 0x17, 0xA8, 0x37, 0x44, 0x09,
  41299. 0xD5, 0x66, 0x87, 0x9A, 0x08, 0x62, 0x8F, 0x64,
  41300. 0x4F, 0xB4, 0x5B, 0x81, 0x84, 0x55, 0xBC, 0xA6,
  41301. 0x04, 0x2B, 0x4E, 0x61, 0x87, 0xC1, 0xDD, 0x17,
  41302. 0x7E, 0x9E, 0x51, 0x46, 0x31, 0x99, 0x04, 0xB1,
  41303. 0x50, 0x5F, 0x3E, 0xE0, 0x0C, 0xD7, 0xFE, 0xAF,
  41304. 0x0E, 0x83, 0xC3, 0x02, 0x49, 0x56, 0xF7, 0x76,
  41305. 0x59, 0xAC, 0xC5, 0x6D, 0x8D, 0x91, 0x7A, 0x37,
  41306. 0xE8, 0xFF, 0x7E, 0xB8, 0x87, 0x13, 0xCC, 0xA3,
  41307. 0x34, 0xEA, 0x04, 0xB8, 0xE2, 0x58, 0xC9, 0x34,
  41308. 0x5D, 0xA9, 0xDE, 0x26, 0xA0, 0xA3, 0x66, 0x51,
  41309. 0x94, 0x51, 0xE1, 0x01, 0x2D, 0xE6, 0xAA, 0xBF,
  41310. 0x46, 0x97, 0xC9, 0xDE, 0x82, 0x1D, 0x70, 0x02,
  41311. 0x1C, 0x32, 0x50, 0xA1, 0x06, 0xCF, 0x4C, 0x23,
  41312. 0xA1, 0xB1, 0x78, 0x5F, 0x54, 0x9D, 0x3C, 0x8C,
  41313. 0xD7, 0x1B, 0x05, 0xFE, 0xA7, 0x53, 0xE0, 0x04,
  41314. 0x6A, 0x3A, 0xE0, 0xA9, 0xB1, 0xF4, 0x02, 0x77,
  41315. 0xCF, 0x45, 0x3A, 0x2B, 0xA1, 0x4C, 0xBA, 0x92,
  41316. 0x3C, 0xC6, 0x26, 0x97, 0x06, 0xDF, 0xFF, 0xD5,
  41317. 0x17, 0xC1, 0xE5, 0x93, 0x00, 0x79, 0x91, 0x2E,
  41318. 0x05, 0xA5, 0x57, 0x18, 0x97, 0xA0, 0x68, 0x65,
  41319. 0x51, 0x6C, 0x86, 0x69, 0x9F, 0x70, 0x7E, 0x00,
  41320. 0xCB, 0x38, 0xCE, 0x19, 0x34, 0x90, 0xAE, 0xE3,
  41321. 0x0B, 0xA4, 0x7D, 0xDD, 0xF3, 0xA5, 0xB4, 0xFB,
  41322. 0xCE, 0xBA, 0x73, 0xDC, 0x13, 0xD0, 0xA1, 0x60,
  41323. 0xEA, 0x64, 0x2D, 0x30, 0xD6, 0x3A, 0x02, 0x96,
  41324. 0x4E, 0xDF, 0xDB, 0x2F, 0x29, 0xDC, 0xD3, 0x2C,
  41325. 0xA9, 0x97, 0x4F, 0x89, 0xC3, 0x2D, 0x1F, 0xA9,
  41326. 0xA8, 0x3C, 0x94, 0xA2, 0x77, 0x0F, 0xCF, 0xCF,
  41327. 0x86, 0xE6, 0x46, 0x46, 0x88, 0x2B, 0xD5, 0x50,
  41328. 0xDD, 0xD6, 0x5B, 0x4E, 0x2D, 0x28, 0x7A, 0xF6,
  41329. 0xC1, 0x96, 0xF4, 0x2D, 0xBD, 0x39, 0xB0, 0x20,
  41330. 0xD7, 0xCD, 0xFB, 0xB6, 0xE6, 0xE7, 0x5F, 0xFA,
  41331. 0xAB, 0x26, 0x09, 0x9E, 0xC1, 0xD2, 0x5E, 0x32,
  41332. 0x34, 0xF7, 0x0D, 0xD9, 0x72, 0x28, 0x6A, 0xEA,
  41333. 0x0C, 0x34, 0x36, 0x59, 0x5F, 0xE4, 0x9F, 0xCA,
  41334. 0x89, 0x8B, 0xFA, 0x42, 0x16, 0x04, 0xC8, 0x2D,
  41335. 0x3E, 0x94, 0x85, 0x6D, 0x18, 0x69, 0x05, 0x07,
  41336. 0x6D, 0x18, 0x6C, 0x68, 0x41, 0x74, 0xBF, 0x42,
  41337. 0x90, 0xDF, 0x31, 0x76, 0x9E, 0xDC, 0x97, 0xA1,
  41338. 0xDF, 0x2D, 0xFE, 0xD0, 0x3C, 0xF4, 0x5C, 0xE6,
  41339. 0x78, 0xC8, 0xA1, 0x42, 0x9E, 0xB9, 0x78, 0xD0,
  41340. 0x2A, 0x79, 0xD4, 0xF8, 0xCF, 0x01, 0x68, 0xDA,
  41341. 0xAB, 0x48, 0x2C, 0x6C, 0x61, 0x2F, 0x04, 0xB1,
  41342. 0xC9, 0x36, 0x37, 0xFE, 0x77, 0xB3, 0x02, 0xCE,
  41343. 0xFA, 0x78, 0x8C, 0x11, 0x35, 0x6C, 0x52, 0xC5,
  41344. 0x4F, 0x37, 0xA9, 0xDC, 0xFD, 0xA5, 0x59, 0x27,
  41345. 0xA8, 0xEF, 0x0A, 0x0C, 0xEA, 0x7C, 0xC4, 0xAD,
  41346. 0xCE, 0xE4, 0x59, 0xEB, 0x64, 0xDF, 0x08, 0xED,
  41347. 0x0F, 0xC2, 0x9F, 0xDC, 0x3C, 0x7B, 0x76, 0x2B,
  41348. 0x39, 0x93, 0x32, 0x06, 0x33, 0x40, 0xD4, 0x73,
  41349. 0x96, 0x62, 0x19, 0xBF, 0xC8, 0x7B, 0x4A, 0x3C,
  41350. 0x91, 0xC8, 0x0F, 0x0E, 0x4B, 0xA8, 0x6A, 0xA1,
  41351. 0x87, 0x9C, 0x76, 0x62, 0x5C, 0x86, 0x80, 0xA2,
  41352. 0x27, 0xAB, 0x22, 0x78, 0x06, 0x59, 0xD4, 0xB5,
  41353. 0xD3, 0x0E, 0x0E, 0x9A, 0x0D, 0xCE, 0x09, 0x4D,
  41354. 0xAF, 0x53, 0x76, 0x79, 0x27, 0x3A, 0x9B, 0x27,
  41355. 0x7E, 0xD2, 0xA2, 0xE2, 0x50, 0xEE, 0xA0, 0x93,
  41356. 0x82, 0x04, 0xC9, 0xE9, 0x63, 0xD3, 0x38, 0x52,
  41357. 0x2A, 0x3D, 0x1A, 0x44, 0x40, 0xE2, 0xA1, 0x23,
  41358. 0x97, 0xA5, 0xB9, 0x7D, 0x35, 0x65, 0x73, 0x07,
  41359. 0xBE, 0xC9, 0x4C, 0xC0, 0xC7, 0x2C, 0x5C, 0x6B,
  41360. 0x09, 0xDA, 0xF2, 0xBA, 0xF0, 0x02, 0x0B, 0x7D,
  41361. 0x8C, 0xA5, 0x60, 0xBF, 0x65, 0x96, 0x92, 0x9A,
  41362. 0xC8, 0xD4, 0xE5, 0x46, 0x0F, 0x78, 0x37, 0xB4,
  41363. 0x1B, 0x4A, 0xE6, 0xFF, 0x12, 0x33, 0x9D, 0xB8,
  41364. 0xEB, 0xD7, 0x02, 0x8A, 0xAC, 0xFE, 0x0B, 0x42,
  41365. 0xE0, 0x2C, 0xDE, 0x90, 0x67, 0x83, 0xAB, 0xFF,
  41366. 0x69, 0x4E, 0x7C, 0xBE, 0x08, 0x97, 0xED, 0x6E,
  41367. 0xD4, 0x38, 0xAC, 0xDB, 0x00, 0xA4, 0x70, 0x9C,
  41368. 0xFE, 0xF7, 0x15, 0x0E, 0xBE, 0xB0, 0x8C, 0x8F,
  41369. 0xF6, 0xC1, 0x54, 0x38, 0x15, 0xF4, 0xB8, 0x95,
  41370. 0x1C, 0x3C, 0xAC, 0xE4, 0x99, 0x58, 0x64, 0x58,
  41371. 0xA7, 0x3C, 0x85, 0x72, 0x38, 0x9A, 0xFC, 0x97,
  41372. 0x03, 0xA7, 0xFE, 0xAF, 0x67, 0x34, 0x45, 0xFB,
  41373. 0x4B, 0x0C, 0xCA, 0xA5, 0x11, 0xD4, 0xA2, 0xCF,
  41374. 0x46, 0x3F, 0x57, 0xE3, 0xA6, 0xD7, 0x2D, 0xA0,
  41375. 0x4B, 0x25, 0x66, 0x99, 0xA3, 0x02, 0x12, 0xE7,
  41376. 0xC5, 0x76, 0x8E, 0xFC, 0x15, 0x1B, 0x71, 0x74,
  41377. 0x41, 0x56, 0x57, 0x5A, 0x2E, 0x94, 0x43, 0x31,
  41378. 0x92, 0x32, 0xD1, 0x59, 0xC6, 0xCC, 0x00, 0x6F,
  41379. 0xDB, 0x57, 0xC5, 0x81, 0x73, 0xAD, 0x8D, 0x2C,
  41380. 0x86, 0x6C, 0x88, 0x87, 0x43, 0x7C, 0x22, 0x38,
  41381. 0x88, 0xE2, 0x1E, 0xF6, 0x7E, 0x1A, 0x33, 0x2C,
  41382. 0x1F, 0xDF, 0xCC, 0x15, 0xEF, 0x17, 0x47, 0x6F,
  41383. 0xE0, 0xFB, 0x57, 0xD4, 0x22, 0x98, 0x94, 0x72,
  41384. 0x5E, 0x14, 0x74, 0xC1, 0xBA, 0x12, 0x16, 0x56,
  41385. 0x28, 0x17, 0xF1, 0x6C, 0x53, 0xEC, 0xE0, 0x1C,
  41386. 0x7F, 0x9E, 0x36, 0x64, 0xEE, 0xDB, 0xBA, 0x94,
  41387. 0x95, 0x29, 0x87, 0x43, 0x1A, 0xA2, 0xA5, 0x7D,
  41388. 0x33, 0x0E, 0xB1, 0x1B, 0x28, 0xE6, 0xBF, 0x77,
  41389. 0x0E, 0x34, 0x9E, 0xCE, 0x35, 0x0C, 0x83, 0xE9,
  41390. 0x0D, 0xA6, 0xFE, 0x0D, 0x0A, 0x4A, 0xB9, 0x71,
  41391. 0x5D, 0xB2, 0x8B, 0xDD, 0x39, 0x7F, 0xAF, 0xA1,
  41392. 0x42, 0x83, 0x02, 0x15, 0x1E, 0x1F, 0x22, 0x2B,
  41393. 0x44, 0x69, 0x87, 0x9E, 0xB5, 0xD0, 0xF0, 0x18,
  41394. 0x60, 0x6A, 0x75, 0x94, 0xBF, 0xC8, 0x2C, 0x39,
  41395. 0x4E, 0x91, 0xB9, 0x26, 0x44, 0x95, 0xC9, 0x06,
  41396. 0x3D, 0x50, 0x52, 0x62, 0x79, 0x9B, 0x9F, 0xCB,
  41397. 0xE6, 0x31, 0x6B, 0xBC, 0xC8, 0xD8, 0x09, 0x30,
  41398. 0x53, 0x63, 0x6A, 0x74, 0xD4, 0xFA, 0x00, 0x00,
  41399. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41400. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41401. 0x00, 0x00, 0x00, 0x02, 0x0F, 0x16, 0x1B, 0x1F,
  41402. 0x29, 0x2E, 0x36
  41403. };
  41404. #endif
  41405. #else
  41406. #ifndef WOLFSSL_NO_ML_DSA_44
  41407. static const byte pk_44[] = {
  41408. 0x35, 0x07, 0x31, 0x3A, 0xE3, 0x7A, 0xF6, 0x96,
  41409. 0x6C, 0x11, 0xA9, 0xE4, 0x0B, 0xEB, 0xEC, 0xE9,
  41410. 0x2B, 0x67, 0x3F, 0xD2, 0x67, 0x3C, 0x1C, 0x4C,
  41411. 0x08, 0xF0, 0x45, 0xA9, 0xDD, 0x5A, 0xB8, 0x8C,
  41412. 0x0A, 0x51, 0xA9, 0xBA, 0x89, 0x0F, 0x4C, 0xCB,
  41413. 0x9D, 0x0A, 0x41, 0x3F, 0x9C, 0xF4, 0x13, 0x36,
  41414. 0x79, 0x49, 0x00, 0x90, 0xBB, 0x57, 0x3B, 0xBD,
  41415. 0x2E, 0x18, 0xB3, 0xD0, 0xA5, 0x0E, 0x6B, 0x67,
  41416. 0xFF, 0x98, 0x8C, 0xDD, 0x07, 0xE8, 0xA7, 0xA1,
  41417. 0x3F, 0xAE, 0xFB, 0xD6, 0xC0, 0xF8, 0xF3, 0x34,
  41418. 0xA5, 0x17, 0xC2, 0x34, 0x88, 0x92, 0x65, 0xA6,
  41419. 0xE8, 0x66, 0x57, 0xFE, 0x86, 0x08, 0xF7, 0xDF,
  41420. 0xA0, 0x5B, 0x70, 0x3E, 0x91, 0x6C, 0x63, 0xA0,
  41421. 0xA3, 0x75, 0x55, 0xF8, 0xB6, 0xAA, 0xD4, 0x1B,
  41422. 0x78, 0x5E, 0x42, 0x9F, 0x96, 0xE4, 0xA0, 0x50,
  41423. 0xB6, 0x94, 0x2D, 0xC3, 0xE3, 0x36, 0x2B, 0x9D,
  41424. 0x6B, 0x7A, 0xEF, 0xF5, 0x68, 0xF2, 0x11, 0xDF,
  41425. 0x87, 0xA0, 0x9A, 0xC4, 0x61, 0xFB, 0xA4, 0x1C,
  41426. 0x98, 0x3F, 0xC9, 0x52, 0x59, 0x3B, 0x47, 0x4D,
  41427. 0xF5, 0x24, 0xA3, 0xD8, 0x63, 0xE1, 0xED, 0xDC,
  41428. 0xFD, 0xEB, 0x96, 0xFB, 0xF3, 0xE7, 0x50, 0x9C,
  41429. 0x72, 0x61, 0xC7, 0x3C, 0xCE, 0xF2, 0xEB, 0x22,
  41430. 0x55, 0x6B, 0x9F, 0x25, 0xE4, 0x45, 0xE1, 0xFB,
  41431. 0x3E, 0x2E, 0x4E, 0x92, 0x4F, 0x8A, 0x85, 0xEB,
  41432. 0x63, 0x2C, 0x05, 0x0F, 0x9A, 0xEC, 0x0E, 0x9D,
  41433. 0x05, 0x81, 0x46, 0x82, 0xEA, 0x74, 0x91, 0xD5,
  41434. 0x2A, 0xBC, 0xCC, 0xBB, 0xD6, 0x7F, 0x5F, 0x9A,
  41435. 0xD3, 0xBD, 0xEB, 0x14, 0xBA, 0x84, 0x27, 0x13,
  41436. 0x32, 0xB5, 0xF3, 0x71, 0xAC, 0x47, 0x19, 0x6B,
  41437. 0x5E, 0x43, 0x50, 0xC2, 0xA8, 0x82, 0xF5, 0x97,
  41438. 0x9B, 0x27, 0x62, 0xFB, 0xB7, 0xFF, 0x6B, 0xC8,
  41439. 0x52, 0x1E, 0xFB, 0x97, 0x39, 0x1E, 0x7F, 0x01,
  41440. 0xF8, 0x34, 0x47, 0xAA, 0xB2, 0x64, 0xB5, 0x9E,
  41441. 0x28, 0x18, 0xCB, 0x4A, 0x94, 0xBE, 0x6A, 0x43,
  41442. 0x5B, 0xAE, 0x21, 0xA4, 0x63, 0x64, 0x46, 0x0C,
  41443. 0x6B, 0x36, 0x1C, 0x2A, 0x3B, 0x64, 0xFA, 0xA0,
  41444. 0xAB, 0xE3, 0x3B, 0x7D, 0xB0, 0x23, 0x99, 0x21,
  41445. 0x55, 0x59, 0xBF, 0xD6, 0xDB, 0xB8, 0xDB, 0x09,
  41446. 0x5E, 0xBC, 0x32, 0x3C, 0xAC, 0xAB, 0x1A, 0x63,
  41447. 0x32, 0x21, 0x10, 0xD5, 0x8D, 0x7A, 0x5F, 0xCE,
  41448. 0x72, 0x8D, 0x2A, 0xED, 0x1D, 0x30, 0x38, 0x5D,
  41449. 0x3E, 0x62, 0xC2, 0x8E, 0xC9, 0x9F, 0x8C, 0x50,
  41450. 0x3F, 0xC6, 0xCE, 0x86, 0x4D, 0x67, 0x3D, 0x09,
  41451. 0xB6, 0x27, 0x14, 0x57, 0x14, 0xED, 0xC9, 0x8F,
  41452. 0xAC, 0x9E, 0xAC, 0x6F, 0xB5, 0xB2, 0xE6, 0x8D,
  41453. 0x9D, 0x5E, 0xE6, 0x78, 0x77, 0x09, 0x94, 0x35,
  41454. 0x5E, 0x3B, 0x64, 0x04, 0x38, 0xD4, 0x5B, 0x04,
  41455. 0xB8, 0x6C, 0x33, 0x97, 0xE1, 0x58, 0x54, 0x32,
  41456. 0xB3, 0x0F, 0x37, 0x69, 0x39, 0xCE, 0x57, 0x31,
  41457. 0x5C, 0x75, 0xA8, 0x94, 0xD0, 0x39, 0x2D, 0xB4,
  41458. 0x73, 0xA7, 0xA4, 0x7C, 0xBE, 0x34, 0x03, 0x2D,
  41459. 0x99, 0x1D, 0xDF, 0x32, 0x26, 0xB7, 0x45, 0x1B,
  41460. 0x03, 0xCD, 0xEE, 0x9D, 0x58, 0xA8, 0xA7, 0x76,
  41461. 0x1B, 0x17, 0x42, 0xD9, 0x69, 0x0F, 0x26, 0x3A,
  41462. 0x9D, 0x70, 0x9B, 0x4E, 0x81, 0xEB, 0x96, 0x02,
  41463. 0xB5, 0xB3, 0x92, 0x31, 0xFE, 0xBC, 0x38, 0x11,
  41464. 0x5A, 0x47, 0xED, 0x0A, 0x2A, 0xE2, 0xB8, 0x47,
  41465. 0x13, 0x5E, 0x43, 0x97, 0xD5, 0xFA, 0x31, 0x02,
  41466. 0x58, 0xE9, 0x9E, 0xB5, 0x3F, 0x85, 0x92, 0x0E,
  41467. 0xB9, 0xDB, 0xE0, 0xEE, 0x56, 0x76, 0x64, 0x8F,
  41468. 0xF2, 0xE2, 0x47, 0x81, 0xD4, 0xA4, 0x82, 0x43,
  41469. 0x69, 0xAE, 0x8E, 0x48, 0x50, 0x84, 0x93, 0x3B,
  41470. 0x9C, 0x65, 0xD3, 0x6F, 0xCD, 0x90, 0xA0, 0xD8,
  41471. 0xA0, 0xE1, 0x79, 0xCC, 0xD5, 0x1F, 0x71, 0x73,
  41472. 0x93, 0xE7, 0xB2, 0xB0, 0x78, 0x17, 0xD7, 0x79,
  41473. 0xDE, 0xCC, 0x83, 0x7D, 0x5A, 0xF2, 0x0E, 0xA6,
  41474. 0xB1, 0x76, 0x61, 0x15, 0x88, 0x8E, 0xD7, 0xA6,
  41475. 0x51, 0xBF, 0x9C, 0xD1, 0x0A, 0xFC, 0xDA, 0x65,
  41476. 0xA5, 0x65, 0xFE, 0xB2, 0xED, 0x07, 0x74, 0x42,
  41477. 0x4C, 0xF5, 0x42, 0x3D, 0xAF, 0x5F, 0x4D, 0x72,
  41478. 0x51, 0xE6, 0x3F, 0x68, 0xCC, 0xC5, 0x2D, 0x89,
  41479. 0x01, 0xD8, 0x80, 0xB4, 0xFC, 0xEB, 0x3B, 0xBE,
  41480. 0x7C, 0xFA, 0x24, 0x27, 0xE1, 0x05, 0x94, 0x67,
  41481. 0xAD, 0xB3, 0x47, 0x7D, 0x28, 0x18, 0xC1, 0xC9,
  41482. 0xB8, 0xA1, 0x2A, 0x95, 0xBB, 0x5D, 0xC9, 0x42,
  41483. 0x4F, 0x64, 0x94, 0x07, 0x5F, 0x65, 0xD3, 0xA5,
  41484. 0x65, 0xEE, 0x67, 0x2C, 0x10, 0x65, 0x81, 0x4D,
  41485. 0x7F, 0xAF, 0x2E, 0x97, 0x9E, 0x11, 0xA3, 0xF5,
  41486. 0x3E, 0xDE, 0xB1, 0x1D, 0x44, 0x72, 0x90, 0x74,
  41487. 0xFD, 0x47, 0x82, 0xA6, 0x04, 0x3E, 0x28, 0x3C,
  41488. 0x15, 0xDF, 0xC4, 0x7A, 0x7C, 0xF5, 0x5A, 0xC6,
  41489. 0xFB, 0xE4, 0xC2, 0xE0, 0x6E, 0x4C, 0x09, 0x2E,
  41490. 0xE3, 0xE6, 0x3A, 0xEF, 0xF6, 0x54, 0xDC, 0x92,
  41491. 0xBE, 0x8F, 0x24, 0x8E, 0x70, 0x53, 0x90, 0x3D,
  41492. 0x06, 0xA5, 0x0A, 0x72, 0xA0, 0x7B, 0x22, 0x14,
  41493. 0x80, 0x43, 0xAD, 0xDC, 0x11, 0xFC, 0xFF, 0xCF,
  41494. 0x5E, 0xA4, 0x69, 0x1C, 0x09, 0x09, 0xC3, 0x3D,
  41495. 0xF5, 0xE7, 0x05, 0x6F, 0x16, 0x33, 0x75, 0xB4,
  41496. 0x9B, 0x7B, 0x26, 0xDB, 0xE7, 0x27, 0x56, 0xD3,
  41497. 0x91, 0x82, 0x9D, 0xEB, 0x96, 0x3E, 0xE8, 0x40,
  41498. 0xAB, 0x5D, 0x6C, 0xB7, 0xA6, 0x36, 0x07, 0xD4,
  41499. 0xE7, 0x7C, 0xD4, 0x5C, 0x36, 0xE4, 0xFC, 0x7C,
  41500. 0x8A, 0x36, 0x8D, 0x53, 0x43, 0xD4, 0xAC, 0x0B,
  41501. 0x1B, 0xBA, 0x32, 0x88, 0xFA, 0xCE, 0xC1, 0xB9,
  41502. 0x34, 0x3C, 0xAC, 0xA0, 0xF4, 0xF2, 0x83, 0xA8,
  41503. 0xBB, 0x6F, 0x12, 0xC6, 0xB5, 0x3C, 0xDE, 0xA8,
  41504. 0x49, 0x66, 0x97, 0xD7, 0x7E, 0x37, 0xF7, 0xCE,
  41505. 0x7C, 0xF8, 0xC8, 0xBB, 0x8C, 0xB5, 0x3B, 0x3F,
  41506. 0xB9, 0x51, 0x68, 0x00, 0xD7, 0x2E, 0x1C, 0x10,
  41507. 0xAF, 0x9F, 0x3C, 0xD2, 0xAC, 0xE5, 0xBE, 0x94,
  41508. 0xB9, 0x60, 0xF5, 0xB2, 0x70, 0x24, 0xE8, 0x8A,
  41509. 0x2C, 0xD8, 0x95, 0xAF, 0xAA, 0xA9, 0xA5, 0x2B,
  41510. 0xCA, 0xE0, 0x58, 0x44, 0x02, 0x3F, 0xF8, 0x21,
  41511. 0x0C, 0x29, 0xB7, 0xD5, 0x08, 0x9E, 0x69, 0x81,
  41512. 0xD4, 0x6C, 0xC5, 0x0B, 0xF6, 0xEF, 0xAB, 0x01,
  41513. 0xEA, 0xDF, 0x36, 0x2C, 0x5C, 0xFB, 0xEB, 0xC8,
  41514. 0x4F, 0x71, 0x80, 0xD7, 0x00, 0xC9, 0x32, 0x5D,
  41515. 0x02, 0x4F, 0x96, 0x94, 0x71, 0xCD, 0x98, 0xC4,
  41516. 0x25, 0x7A, 0x92, 0xF1, 0x9B, 0xA0, 0x34, 0x30,
  41517. 0x6C, 0x41, 0x59, 0xD5, 0x01, 0x5D, 0xD6, 0x56,
  41518. 0xEA, 0x05, 0xF2, 0xFC, 0xF8, 0x58, 0xFA, 0x12,
  41519. 0x9C, 0x5A, 0x5C, 0xD5, 0x3D, 0xC7, 0x5D, 0x1B,
  41520. 0x99, 0x2A, 0x6A, 0x4C, 0xF9, 0xEA, 0x9D, 0x70,
  41521. 0x53, 0xBC, 0xBE, 0xAD, 0x61, 0xC7, 0x2D, 0x77,
  41522. 0xEF, 0x61, 0xC7, 0xBE, 0x9C, 0x73, 0xC1, 0xD5,
  41523. 0xD4, 0x5C, 0x5F, 0x21, 0x6A, 0x5C, 0xEE, 0x78,
  41524. 0xAA, 0xC6, 0x6C, 0x56, 0xDB, 0x38, 0x5A, 0x94,
  41525. 0x12, 0xB8, 0x73, 0x7C, 0xDF, 0x9A, 0x27, 0xCD,
  41526. 0xC5, 0xD1, 0xD3, 0xCA, 0x0E, 0x37, 0x0A, 0xC1,
  41527. 0x6F, 0xAD, 0xE3, 0x32, 0x94, 0x6C, 0x20, 0xB5,
  41528. 0xED, 0xE6, 0x2D, 0x34, 0x39, 0x58, 0xD2, 0x1E,
  41529. 0x63, 0x8D, 0xFA, 0xFF, 0xB5, 0xE8, 0x40, 0xC8,
  41530. 0x42, 0x38, 0x7A, 0x01, 0x80, 0xFF, 0x52, 0x3F,
  41531. 0xE9, 0x89, 0x63, 0xAD, 0x91, 0x5F, 0xCE, 0x0A,
  41532. 0x47, 0x87, 0xF9, 0x6D, 0xD7, 0x79, 0xEF, 0xCE,
  41533. 0x10, 0x7B, 0x73, 0x43, 0xBE, 0x51, 0xA0, 0xDF,
  41534. 0xE5, 0xEC, 0xA9, 0x63, 0xF6, 0x5E, 0x72, 0x36,
  41535. 0x22, 0x86, 0xEE, 0x4E, 0x4A, 0x76, 0xFD, 0x86,
  41536. 0xBA, 0xE6, 0xD6, 0xC4, 0xD2, 0xE6, 0xFF, 0xB2,
  41537. 0x5B, 0x39, 0xF9, 0xC3, 0x29, 0xA8, 0x61, 0x3A,
  41538. 0x33, 0x34, 0x89, 0xC9, 0x83, 0xF9, 0xB2, 0x70,
  41539. 0x21, 0x54, 0x44, 0x94, 0x70, 0xAD, 0x70, 0x18,
  41540. 0x84, 0x38, 0x91, 0xFB, 0xDE, 0x5E, 0x3D, 0xE3,
  41541. 0xB2, 0xA7, 0x3C, 0x1D, 0x49, 0xA6, 0x66, 0x7C,
  41542. 0x4B, 0xEB, 0xB0, 0xA7, 0x7C, 0xC5, 0xAE, 0x45,
  41543. 0x1F, 0xBE, 0x0E, 0x2F, 0x11, 0xDC, 0x92, 0x08,
  41544. 0xAA, 0x18, 0x38, 0xFE, 0x61, 0xBE, 0x9D, 0xC3,
  41545. 0x3A, 0x1F, 0x2F, 0xB6, 0x6E, 0xB6, 0x54, 0x97,
  41546. 0x74, 0x06, 0xBC, 0x12, 0x2D, 0x64, 0x18, 0x14,
  41547. 0x25, 0x5A, 0xCB, 0x7B, 0xD7, 0x9D, 0xC3, 0x2C,
  41548. 0xC2, 0x0B, 0x19, 0x10, 0xD2, 0x57, 0xF0, 0xDF,
  41549. 0xA4, 0x95, 0xA4, 0x5A, 0xA0, 0x2D, 0x0F, 0xA0,
  41550. 0xBC, 0xF7, 0x60, 0x7F, 0x38, 0xE1, 0x17, 0x0D,
  41551. 0x36, 0x08, 0xF5, 0xF9, 0x75, 0x28, 0x75, 0xAC,
  41552. 0xA9, 0x2B, 0x75, 0xC4, 0x41, 0xE0, 0x0D, 0x5C,
  41553. 0xBC, 0x5F, 0x49, 0x16, 0x25, 0x38, 0x16, 0xE1,
  41554. 0x0C, 0x2C, 0x9C, 0x63, 0xA8, 0x5F, 0x70, 0xF4,
  41555. 0x64, 0xC7, 0x10, 0x19, 0x52, 0x19, 0x6E, 0x9B,
  41556. 0x5C, 0x09, 0x4F, 0xEE, 0xB6, 0x7C, 0x85, 0xC9,
  41557. 0x6E, 0xCB, 0x33, 0x32, 0x42, 0x9D, 0x57, 0x18,
  41558. 0xE6, 0x55, 0x94, 0x74, 0x02, 0xEE, 0xEB, 0xAA,
  41559. 0xF7, 0xD3, 0x45, 0x7A, 0x49, 0x6F, 0x83, 0x89,
  41560. 0x00, 0xE4, 0xAA, 0x20, 0x87, 0x10, 0xAD, 0xC0,
  41561. 0x0E, 0xF5, 0x93, 0x57, 0xE5, 0x45, 0x7A, 0xBD,
  41562. 0x82, 0x87, 0x50, 0x0F, 0xE1, 0x2C, 0x0C, 0x6D,
  41563. 0xEE, 0xC8, 0x94, 0xB8, 0x39, 0xF3, 0x3C, 0xFE,
  41564. 0x7E, 0xC1, 0x0F, 0xB4, 0x67, 0xA2, 0xDF, 0xC6,
  41565. 0x9D, 0xB5, 0x9D, 0xB8, 0x72, 0x50, 0xBD, 0xB3,
  41566. 0xDB, 0xF6, 0x87, 0x5E, 0x26, 0x93, 0xF0, 0xD4,
  41567. 0x0D, 0x68, 0xA4, 0x8B, 0xBD, 0x2C, 0x6E, 0xD8,
  41568. 0x4F, 0x81, 0x5D, 0x0D, 0xAC, 0x72, 0x65, 0xEC,
  41569. 0x4E, 0xF2, 0x4E, 0x5F, 0x67, 0x04, 0xF3, 0x08,
  41570. 0x29, 0x4D, 0xB2, 0xE2, 0xD5, 0x9F, 0xD4, 0xB9,
  41571. 0x13, 0xB4, 0x33, 0x80, 0x27, 0x84, 0x7E, 0xF4
  41572. };
  41573. static const byte msg_44[] = {
  41574. 0x5C, 0x70, 0x7F, 0xBF, 0xF4, 0xFF, 0xE5, 0x9B,
  41575. 0x09, 0xAA, 0xF8, 0xDB, 0x21, 0xAD, 0xBE, 0xBA,
  41576. 0xC6, 0xB2, 0x65, 0x37, 0x9A, 0x9A, 0x43, 0x3A,
  41577. 0xA8, 0x23, 0x2B, 0x13, 0x9B, 0xBD, 0x46, 0x37,
  41578. 0x30, 0x60, 0xA7, 0x5B, 0xC4, 0x48, 0x63, 0x5F,
  41579. 0x41, 0x35, 0x38, 0x69, 0xF9, 0x6F, 0xB5, 0x65,
  41580. 0x26, 0xDB, 0xAE, 0xB7, 0x5C, 0xFE, 0x2C, 0x03,
  41581. 0xCB, 0x43, 0x08, 0x58, 0x5E, 0x27, 0xD1, 0x42,
  41582. 0x14, 0xF2, 0x4B, 0xD7, 0x13, 0xE4, 0x96, 0x74,
  41583. 0x6A, 0xC1, 0x36, 0xC7, 0x9D, 0x0F, 0x7D, 0xB0,
  41584. 0x7B, 0x8A, 0x3A, 0x6D, 0x00, 0x5B, 0x29, 0x7B,
  41585. 0x37, 0xBA, 0x3F, 0x5B, 0xBD, 0xCE, 0x21, 0x77,
  41586. 0xFD, 0xD6, 0x78, 0x77, 0x20, 0x31, 0xF0, 0x60,
  41587. 0x49, 0xAE, 0x12, 0x86, 0x7A, 0x64, 0xBD, 0x0B,
  41588. 0x9E, 0xC6, 0x26, 0x80, 0x9E, 0xCE, 0x19, 0x8D,
  41589. 0x6A, 0x6B, 0x09, 0x03, 0x45, 0xDF, 0x22, 0x7D
  41590. };
  41591. static const byte sig_44[] = {
  41592. 0x08, 0xF0, 0x10, 0xFA, 0x63, 0x3F, 0x2B, 0xA1,
  41593. 0x46, 0x81, 0x34, 0xC4, 0xBC, 0xAB, 0x62, 0x17,
  41594. 0x0B, 0x64, 0xEA, 0x00, 0x2D, 0xD6, 0x8A, 0xE5,
  41595. 0xC2, 0x45, 0x29, 0xB9, 0xEC, 0x6F, 0x3B, 0xF2,
  41596. 0xDC, 0x2F, 0xC7, 0x34, 0x5A, 0x1E, 0xFE, 0x0C,
  41597. 0xCA, 0xB9, 0x6A, 0xD8, 0xDA, 0xBA, 0xAA, 0x80,
  41598. 0x90, 0xDC, 0x8C, 0x6C, 0x22, 0xFF, 0xC4, 0x90,
  41599. 0x9E, 0xE9, 0xA5, 0x45, 0xFC, 0xE8, 0x64, 0x53,
  41600. 0x9E, 0xC4, 0x17, 0xE1, 0xB2, 0x1A, 0x31, 0x40,
  41601. 0x26, 0x9D, 0x5E, 0x03, 0x6A, 0xC6, 0x09, 0x19,
  41602. 0xDD, 0xB3, 0x63, 0xE0, 0x35, 0xCD, 0xB4, 0x2E,
  41603. 0x25, 0x38, 0x6E, 0x6C, 0x76, 0xA9, 0x19, 0x75,
  41604. 0x68, 0x6E, 0xB7, 0xAB, 0xAD, 0x8F, 0x63, 0x64,
  41605. 0x97, 0x4E, 0x56, 0x82, 0x30, 0x45, 0x86, 0x22,
  41606. 0x64, 0xDA, 0xD2, 0xAE, 0x54, 0x70, 0x5C, 0xF1,
  41607. 0xEB, 0xD1, 0x84, 0x8D, 0xFF, 0x86, 0x15, 0xE6,
  41608. 0x20, 0xCE, 0x14, 0x89, 0xEF, 0xFA, 0x2E, 0xF8,
  41609. 0x60, 0xCA, 0x53, 0x52, 0xE4, 0xD5, 0xC8, 0x2E,
  41610. 0x50, 0xD5, 0x9D, 0x90, 0xA6, 0x12, 0xC7, 0xF1,
  41611. 0x70, 0x0D, 0xE2, 0x89, 0x5B, 0x31, 0x6A, 0x21,
  41612. 0x79, 0x9C, 0xBE, 0x77, 0x6E, 0xA6, 0xBF, 0x51,
  41613. 0x05, 0x2A, 0x83, 0x50, 0x7E, 0x86, 0x14, 0xD1,
  41614. 0x50, 0x53, 0x1F, 0x1C, 0x5E, 0x50, 0x24, 0x69,
  41615. 0x6C, 0x91, 0x55, 0x35, 0x19, 0x6F, 0xE0, 0xDC,
  41616. 0xB5, 0xD6, 0x48, 0x7E, 0x78, 0x61, 0x59, 0x2C,
  41617. 0xD0, 0x1B, 0x42, 0x58, 0xAF, 0x7A, 0x39, 0xCA,
  41618. 0x02, 0x1C, 0x50, 0xEF, 0xE9, 0xE1, 0xDE, 0x31,
  41619. 0x8D, 0x09, 0x51, 0xC9, 0xDB, 0x16, 0xF9, 0xB9,
  41620. 0x45, 0x54, 0x81, 0x16, 0xD7, 0x14, 0xD8, 0xBE,
  41621. 0x9C, 0xCA, 0x53, 0xFE, 0x8F, 0x24, 0x99, 0x0D,
  41622. 0xBA, 0x7F, 0x99, 0x42, 0x11, 0x9B, 0x32, 0xDD,
  41623. 0x93, 0x5C, 0xBA, 0x2D, 0xD3, 0xB3, 0xF2, 0x48,
  41624. 0x13, 0x9C, 0x80, 0xBB, 0x8D, 0xF4, 0xC7, 0xAA,
  41625. 0xEB, 0xC6, 0xFD, 0xB8, 0x35, 0x95, 0x87, 0x2B,
  41626. 0x9E, 0xCF, 0x48, 0xF3, 0x2D, 0xFF, 0x70, 0xF4,
  41627. 0xCE, 0x35, 0x68, 0x7E, 0x9D, 0xDF, 0xD5, 0x0C,
  41628. 0xCD, 0xE3, 0x51, 0xB0, 0x90, 0x86, 0xE5, 0xD1,
  41629. 0xF1, 0x3B, 0x72, 0x42, 0x73, 0x07, 0x03, 0xE2,
  41630. 0xFB, 0x40, 0x3F, 0xD4, 0xC8, 0x30, 0xB6, 0x86,
  41631. 0x49, 0x8A, 0x17, 0xDB, 0x8F, 0x46, 0x6C, 0x3A,
  41632. 0xC3, 0x49, 0xCD, 0x59, 0x68, 0x81, 0x66, 0x03,
  41633. 0xD7, 0x24, 0xAF, 0x1F, 0x77, 0xC7, 0xFB, 0xF7,
  41634. 0x83, 0xCD, 0xA2, 0x6D, 0x35, 0x0C, 0x8B, 0xBC,
  41635. 0x29, 0x3A, 0x7F, 0xAC, 0xB9, 0xF9, 0x78, 0x50,
  41636. 0x6A, 0x67, 0xFC, 0xDC, 0x6F, 0x01, 0x65, 0x06,
  41637. 0x82, 0x81, 0xB0, 0x7D, 0x25, 0x5D, 0x74, 0x0B,
  41638. 0x68, 0x5F, 0x51, 0x2C, 0x82, 0xF3, 0x1D, 0x92,
  41639. 0xF6, 0xA9, 0xA9, 0x6A, 0x77, 0x57, 0x58, 0xAA,
  41640. 0x7C, 0xBE, 0x35, 0xF4, 0x56, 0xDE, 0x42, 0x01,
  41641. 0x2D, 0xB8, 0x28, 0x83, 0x7B, 0xA0, 0xA9, 0x7D,
  41642. 0xC3, 0x30, 0x13, 0x52, 0xD0, 0xA1, 0xC8, 0xA1,
  41643. 0x2C, 0x51, 0x49, 0xAE, 0xA8, 0x04, 0xCB, 0xA8,
  41644. 0x66, 0x01, 0x26, 0xDF, 0x2D, 0x1C, 0x21, 0xA2,
  41645. 0x4E, 0xBD, 0xA5, 0x48, 0x2A, 0x2D, 0x56, 0x60,
  41646. 0x20, 0x98, 0x4D, 0x15, 0x7D, 0x02, 0xB6, 0x3A,
  41647. 0xE4, 0x11, 0xAE, 0xF7, 0x3E, 0x5D, 0x56, 0x4F,
  41648. 0x6A, 0xA3, 0x0A, 0xEA, 0xCC, 0x35, 0x8A, 0xB7,
  41649. 0xC4, 0x8F, 0x25, 0x3E, 0x42, 0x41, 0x2B, 0xA5,
  41650. 0x1F, 0xA7, 0x3B, 0x87, 0x22, 0x86, 0x79, 0xD5,
  41651. 0xE5, 0x2A, 0xA2, 0xCD, 0x68, 0xCE, 0xB8, 0x18,
  41652. 0x6D, 0xEF, 0x1C, 0x36, 0x7F, 0x75, 0x50, 0x36,
  41653. 0x1B, 0x58, 0xEB, 0x32, 0xA1, 0xC8, 0xAF, 0x47,
  41654. 0xE1, 0x26, 0x73, 0x1F, 0x5D, 0x73, 0x30, 0x13,
  41655. 0x2F, 0xC7, 0x8B, 0xA3, 0x03, 0xB4, 0xA8, 0x86,
  41656. 0x25, 0x29, 0xD1, 0x75, 0x10, 0xEE, 0x7F, 0x56,
  41657. 0xBC, 0x0D, 0x59, 0xB4, 0xAE, 0xC9, 0x44, 0x0A,
  41658. 0xF7, 0x0D, 0xBF, 0x17, 0x6A, 0x22, 0x9C, 0x75,
  41659. 0x2B, 0x3E, 0x22, 0xB8, 0x2F, 0x4B, 0x68, 0xF1,
  41660. 0x07, 0xE3, 0x47, 0x47, 0x21, 0x9C, 0xA3, 0x5B,
  41661. 0x31, 0x0A, 0x14, 0xD9, 0x7C, 0xA8, 0xC0, 0xC6,
  41662. 0x5C, 0xAD, 0x05, 0xD6, 0x15, 0xD3, 0xEC, 0xEC,
  41663. 0x32, 0xC2, 0xFF, 0xF4, 0x96, 0x9C, 0xC8, 0x65,
  41664. 0xA0, 0xB2, 0xD6, 0xF4, 0x98, 0xBB, 0xB1, 0x4E,
  41665. 0xA5, 0x11, 0x3B, 0x4E, 0xA8, 0xEB, 0x90, 0xAB,
  41666. 0xD8, 0x25, 0x10, 0xE3, 0x66, 0xB5, 0xA5, 0x11,
  41667. 0x60, 0xA0, 0xCB, 0xDF, 0x77, 0x8A, 0x80, 0x4C,
  41668. 0x07, 0x9B, 0x1B, 0x45, 0x95, 0x29, 0x1D, 0x88,
  41669. 0x85, 0xAC, 0x32, 0x94, 0x26, 0x87, 0x12, 0x0A,
  41670. 0x2F, 0x9E, 0xAE, 0x69, 0x79, 0x25, 0x5A, 0x50,
  41671. 0xF4, 0xDB, 0x15, 0x20, 0x9F, 0x7A, 0x7A, 0xF2,
  41672. 0xE5, 0x8A, 0x63, 0x6A, 0xDD, 0xBD, 0x06, 0xCB,
  41673. 0x42, 0xF0, 0x20, 0xA9, 0x3B, 0x52, 0xD8, 0x68,
  41674. 0x37, 0x71, 0x07, 0xB8, 0x5B, 0xFE, 0xA0, 0xEC,
  41675. 0xBD, 0x75, 0xFF, 0x9C, 0x89, 0xDF, 0x01, 0xE7,
  41676. 0x17, 0x7D, 0xA7, 0xE8, 0x27, 0x9E, 0xA2, 0x41,
  41677. 0x66, 0xE6, 0xDB, 0x8B, 0x5A, 0x3F, 0x6C, 0xC9,
  41678. 0xE3, 0x4F, 0x0D, 0xD0, 0x92, 0x1E, 0x27, 0x41,
  41679. 0xF2, 0xB3, 0x08, 0x32, 0x03, 0x6D, 0x2C, 0x4F,
  41680. 0x78, 0xEC, 0x99, 0xB3, 0x94, 0x6C, 0xC1, 0x89,
  41681. 0xD9, 0x34, 0x0F, 0xEF, 0x10, 0xF0, 0xDA, 0xCE,
  41682. 0x09, 0x69, 0x7A, 0x93, 0xC6, 0xFF, 0x19, 0x4F,
  41683. 0xBD, 0xDE, 0xA6, 0x54, 0x8A, 0xE5, 0x81, 0x3F,
  41684. 0x96, 0xD3, 0xA0, 0x77, 0x7C, 0xF2, 0x4B, 0xF1,
  41685. 0x68, 0xA2, 0x23, 0x3D, 0xD4, 0x16, 0xC1, 0x66,
  41686. 0xDA, 0x13, 0x53, 0xE1, 0x9F, 0x9A, 0x36, 0x09,
  41687. 0x4D, 0x72, 0x08, 0x09, 0xEB, 0x87, 0x74, 0x9A,
  41688. 0xB2, 0x8C, 0x60, 0x7F, 0xFB, 0x70, 0x17, 0x51,
  41689. 0xB1, 0xAC, 0x18, 0xDF, 0xCB, 0x43, 0x2A, 0xD3,
  41690. 0x89, 0xDA, 0x78, 0xAE, 0xDC, 0xEA, 0xB2, 0x22,
  41691. 0xCA, 0x2F, 0xF1, 0xE4, 0xA7, 0xCC, 0xAF, 0xB1,
  41692. 0x63, 0x1B, 0x5D, 0xDD, 0xD1, 0x49, 0xB8, 0x90,
  41693. 0x2E, 0xC9, 0xC0, 0x83, 0x0D, 0xAB, 0x88, 0x88,
  41694. 0x4C, 0x74, 0x72, 0x00, 0x7D, 0xFE, 0xF2, 0x46,
  41695. 0x73, 0xFD, 0x99, 0xEC, 0x89, 0x8B, 0x3B, 0x0F,
  41696. 0xCE, 0x35, 0x5A, 0xEA, 0x13, 0x4F, 0x67, 0x67,
  41697. 0xFD, 0x0D, 0x87, 0xFC, 0xB1, 0x36, 0x48, 0x07,
  41698. 0x33, 0x0B, 0xCA, 0xD4, 0xD7, 0xD0, 0xCC, 0xA1,
  41699. 0x8F, 0xF0, 0x3F, 0x01, 0x8B, 0x6B, 0x74, 0x44,
  41700. 0x2F, 0x1B, 0xE0, 0x65, 0x31, 0x1B, 0x4E, 0xDB,
  41701. 0x67, 0x65, 0xA9, 0x34, 0xE8, 0x4D, 0x0C, 0xF3,
  41702. 0x29, 0xED, 0x53, 0xAB, 0x8A, 0x98, 0x07, 0x2B,
  41703. 0xE0, 0xCD, 0xC0, 0x08, 0x82, 0x4A, 0x72, 0x28,
  41704. 0x72, 0xA2, 0xAC, 0xFE, 0xF7, 0xBF, 0x6E, 0x8E,
  41705. 0xF8, 0x3E, 0x04, 0x58, 0xA4, 0x36, 0x46, 0x33,
  41706. 0xAB, 0xDD, 0x0E, 0xBF, 0x01, 0xD2, 0xEF, 0x19,
  41707. 0x5B, 0x78, 0x2B, 0x30, 0x51, 0x25, 0x50, 0xD0,
  41708. 0xB5, 0x82, 0xC7, 0x20, 0x0D, 0xA1, 0x2C, 0x38,
  41709. 0xAF, 0x44, 0xFC, 0xBD, 0x49, 0xB8, 0x7F, 0x89,
  41710. 0xEF, 0xBE, 0x37, 0x5C, 0xCB, 0xA2, 0x11, 0x75,
  41711. 0x7D, 0xDA, 0xA8, 0x7B, 0x3A, 0x3C, 0x10, 0x11,
  41712. 0x4D, 0x9F, 0x99, 0xAB, 0x4B, 0xA2, 0x20, 0x7A,
  41713. 0x5F, 0x96, 0xEF, 0x1C, 0x00, 0xD7, 0x27, 0x17,
  41714. 0x77, 0x7C, 0x51, 0x58, 0x4B, 0x13, 0x97, 0x53,
  41715. 0x2A, 0xC6, 0x86, 0x4D, 0x3B, 0x8E, 0xBB, 0x4F,
  41716. 0xB8, 0xA0, 0x84, 0x87, 0xF6, 0xEF, 0x55, 0x12,
  41717. 0x2B, 0xCF, 0x9E, 0x5C, 0xD0, 0x0E, 0xBC, 0x1E,
  41718. 0x79, 0x53, 0xE7, 0x8C, 0x4D, 0x8B, 0xCB, 0x20,
  41719. 0xF6, 0xEA, 0x72, 0x0A, 0x63, 0x2F, 0x0C, 0xCF,
  41720. 0x57, 0x27, 0x26, 0xF4, 0x3A, 0x95, 0xCA, 0xBE,
  41721. 0xB5, 0x7C, 0x47, 0x60, 0x10, 0xCD, 0x28, 0x9E,
  41722. 0x02, 0x64, 0xC9, 0x8D, 0x82, 0x49, 0xD0, 0xD6,
  41723. 0x60, 0xF8, 0xDC, 0xC8, 0x4B, 0x7D, 0xB5, 0xEF,
  41724. 0x11, 0x17, 0xC7, 0x94, 0x5F, 0x0D, 0x99, 0xBE,
  41725. 0x75, 0x48, 0x49, 0xC6, 0x58, 0x43, 0x64, 0x99,
  41726. 0x1A, 0x5A, 0x41, 0xBA, 0xC2, 0x31, 0xB3, 0xE0,
  41727. 0x45, 0x1B, 0x81, 0xD2, 0x12, 0xBE, 0x90, 0xDB,
  41728. 0xFF, 0xBC, 0xCB, 0x99, 0xA3, 0xF0, 0x74, 0xE8,
  41729. 0x2C, 0x48, 0x58, 0xB3, 0x17, 0xA4, 0x9A, 0xD2,
  41730. 0x22, 0x46, 0xFB, 0xF5, 0x85, 0x8D, 0x07, 0xDF,
  41731. 0xDB, 0x78, 0x07, 0xF4, 0x99, 0xA8, 0x6C, 0xEE,
  41732. 0x6E, 0x96, 0x20, 0xB8, 0xC2, 0xA9, 0xFA, 0x8B,
  41733. 0x6E, 0xA6, 0x79, 0x6D, 0xF9, 0xC3, 0x0C, 0x77,
  41734. 0x74, 0xAE, 0xB0, 0x40, 0xA9, 0xE5, 0xA7, 0x0B,
  41735. 0x30, 0x40, 0x4B, 0x4F, 0xB1, 0x0A, 0x0B, 0x7B,
  41736. 0xEE, 0x1F, 0x69, 0xFA, 0xD0, 0xF0, 0x2D, 0x5D,
  41737. 0x00, 0xB5, 0x4D, 0xEB, 0x32, 0x84, 0xB2, 0xB7,
  41738. 0x60, 0xAA, 0x6C, 0xF9, 0x98, 0x18, 0xB3, 0xD9,
  41739. 0xC1, 0x54, 0x8D, 0xAC, 0x12, 0xB0, 0x3A, 0x26,
  41740. 0xB2, 0x23, 0x2D, 0x9B, 0xF8, 0x20, 0xEE, 0x90,
  41741. 0xE0, 0x6D, 0x31, 0xDE, 0xF5, 0xCA, 0xBA, 0x6A,
  41742. 0x53, 0x40, 0x29, 0x6C, 0x18, 0x62, 0xA5, 0x8A,
  41743. 0xB8, 0x17, 0xA0, 0xAB, 0xCB, 0xDC, 0xE1, 0x3B,
  41744. 0xD6, 0xC6, 0x29, 0xA3, 0x1C, 0x5F, 0x8D, 0x6E,
  41745. 0x73, 0xF6, 0x98, 0x10, 0x0F, 0x9F, 0x7E, 0xCA,
  41746. 0x4C, 0xD8, 0xEB, 0xE4, 0xB8, 0xDF, 0x72, 0x78,
  41747. 0x65, 0xAF, 0x4A, 0x20, 0xFE, 0x7C, 0xB4, 0xCA,
  41748. 0x07, 0x81, 0xFD, 0xC5, 0xC5, 0xFD, 0x33, 0x4D,
  41749. 0xB8, 0x37, 0x37, 0xC4, 0x21, 0x81, 0x66, 0x45,
  41750. 0xAE, 0x81, 0x34, 0x13, 0xA6, 0x40, 0x81, 0x39,
  41751. 0x55, 0x90, 0xE6, 0xF1, 0x42, 0x56, 0x74, 0xFF,
  41752. 0x06, 0x9B, 0x50, 0x1F, 0x0F, 0xDA, 0x6B, 0x31,
  41753. 0xC6, 0x4B, 0xC5, 0xC2, 0x14, 0xE7, 0x01, 0x5E,
  41754. 0xA9, 0xDA, 0x12, 0x2D, 0x6C, 0xE0, 0x8C, 0xEB,
  41755. 0x2D, 0xF6, 0x2C, 0x45, 0xBC, 0x01, 0x73, 0x34,
  41756. 0x6D, 0xAB, 0xBC, 0x15, 0x4C, 0x16, 0x03, 0x35,
  41757. 0x9D, 0xD4, 0xF0, 0xAC, 0x49, 0x84, 0x4A, 0xEE,
  41758. 0x46, 0x47, 0x64, 0x93, 0xF2, 0x49, 0x59, 0x86,
  41759. 0x26, 0xFB, 0x24, 0x6B, 0x99, 0xB3, 0x9A, 0xCB,
  41760. 0xB4, 0x2B, 0x28, 0x4E, 0x0C, 0x2D, 0x3F, 0x9E,
  41761. 0xCE, 0x32, 0x71, 0xC4, 0xD5, 0xE0, 0x6C, 0x48,
  41762. 0x25, 0xEA, 0x1A, 0x8F, 0x08, 0x57, 0x23, 0x85,
  41763. 0x89, 0xCD, 0xC5, 0x48, 0x37, 0x19, 0x8E, 0xD4,
  41764. 0x23, 0x4D, 0xD0, 0x31, 0x73, 0xA8, 0x8E, 0x43,
  41765. 0xEE, 0x95, 0x67, 0xF5, 0x7A, 0x93, 0x27, 0xD3,
  41766. 0x90, 0x36, 0x30, 0x4C, 0xA1, 0xCD, 0xB5, 0xF8,
  41767. 0x65, 0xC5, 0x89, 0x54, 0x57, 0x2C, 0xAE, 0xF8,
  41768. 0x75, 0xF1, 0x2E, 0x14, 0x14, 0x14, 0x0D, 0x97,
  41769. 0x5B, 0x24, 0x52, 0x46, 0x7A, 0x57, 0x6D, 0x9C,
  41770. 0x4C, 0x79, 0xDB, 0x0A, 0xE0, 0x23, 0x69, 0x52,
  41771. 0x9B, 0xF8, 0x1B, 0x54, 0x40, 0x18, 0xDF, 0xE0,
  41772. 0x1E, 0xF0, 0x61, 0xE4, 0x79, 0x81, 0xF9, 0x98,
  41773. 0x9A, 0x8C, 0x48, 0xFF, 0x86, 0x93, 0x0B, 0x68,
  41774. 0x96, 0x78, 0x2F, 0xF1, 0x2D, 0xDC, 0x60, 0x1F,
  41775. 0x8B, 0x1C, 0x04, 0x43, 0x4E, 0x60, 0x96, 0x5B,
  41776. 0x8A, 0xF6, 0x89, 0xCC, 0xC8, 0xB2, 0x9B, 0xBF,
  41777. 0x87, 0x16, 0x2E, 0xA8, 0x6F, 0x9B, 0x4B, 0xFD,
  41778. 0x74, 0x4E, 0x8F, 0x36, 0x33, 0x23, 0xDE, 0x94,
  41779. 0xD2, 0xA1, 0x72, 0x4F, 0xB2, 0xE6, 0x75, 0x3D,
  41780. 0x6E, 0x47, 0x9B, 0xDB, 0x58, 0xE5, 0x4A, 0x0C,
  41781. 0x09, 0x8F, 0x9C, 0x83, 0x63, 0x98, 0x8B, 0xA4,
  41782. 0xF7, 0x3D, 0x01, 0xA6, 0x8B, 0x93, 0x97, 0x48,
  41783. 0x84, 0x75, 0x32, 0xC7, 0xD7, 0x03, 0xDF, 0x7E,
  41784. 0x94, 0x8C, 0x8A, 0xA6, 0x78, 0x1A, 0xAE, 0xDE,
  41785. 0x36, 0x8A, 0xAD, 0x13, 0x7E, 0xF0, 0x16, 0xC2,
  41786. 0x3B, 0xAF, 0xF9, 0xD8, 0x66, 0x12, 0x30, 0x72,
  41787. 0x76, 0x6D, 0x21, 0x4C, 0xF3, 0xEF, 0x0D, 0x8C,
  41788. 0x11, 0xA4, 0x12, 0xBE, 0xF5, 0x7E, 0x8E, 0x6A,
  41789. 0x11, 0x13, 0x48, 0x8D, 0xC2, 0x62, 0xCF, 0x45,
  41790. 0x7C, 0xE3, 0x91, 0x88, 0x59, 0xFF, 0xB0, 0xF1,
  41791. 0xC3, 0xBC, 0x1D, 0x2A, 0x3E, 0x9B, 0x78, 0xF3,
  41792. 0xB1, 0x2E, 0xB0, 0x27, 0xD8, 0x16, 0xF8, 0x9B,
  41793. 0x2A, 0xAF, 0xF1, 0xAB, 0xB0, 0xF1, 0x8C, 0x7F,
  41794. 0x94, 0x31, 0x97, 0x85, 0xDA, 0xF0, 0xF4, 0x27,
  41795. 0x51, 0x3E, 0x5A, 0xE1, 0xDD, 0x6D, 0x9E, 0x98,
  41796. 0x39, 0xBB, 0xDF, 0xA2, 0xBA, 0x2C, 0x08, 0xAD,
  41797. 0x1D, 0x3F, 0x86, 0xF6, 0xC2, 0x1A, 0x8C, 0xAD,
  41798. 0xE0, 0xDC, 0xDD, 0x02, 0x47, 0x4C, 0x7E, 0x2D,
  41799. 0xDA, 0x1D, 0x70, 0x92, 0x39, 0xAA, 0x4E, 0xBA,
  41800. 0x14, 0xC7, 0xEC, 0x26, 0xBD, 0x9D, 0x1F, 0x6D,
  41801. 0x91, 0x58, 0x3C, 0xB5, 0xEF, 0x37, 0xB9, 0x66,
  41802. 0x4E, 0x04, 0x7C, 0x29, 0xCF, 0xD7, 0x8E, 0x47,
  41803. 0x84, 0xF3, 0xD2, 0x21, 0x84, 0xC5, 0xF8, 0xDC,
  41804. 0xC9, 0xF2, 0x52, 0xD5, 0x6A, 0xBF, 0xF1, 0xF1,
  41805. 0xDE, 0x9E, 0x7A, 0xF1, 0xD5, 0x5A, 0xF6, 0xEF,
  41806. 0x94, 0x66, 0xF9, 0x25, 0x44, 0x7F, 0x8D, 0x92,
  41807. 0xA2, 0x25, 0x1C, 0x72, 0x92, 0x30, 0x2A, 0xB7,
  41808. 0xEF, 0x18, 0xF3, 0x8C, 0xEF, 0x69, 0xA5, 0x5C,
  41809. 0x19, 0x3E, 0xC5, 0xBD, 0xEE, 0x2C, 0x2D, 0x71,
  41810. 0xDB, 0x89, 0xD4, 0x11, 0xA6, 0x27, 0x80, 0x8F,
  41811. 0x5A, 0x39, 0x9A, 0x04, 0x28, 0x4F, 0x9F, 0x00,
  41812. 0xBE, 0xF9, 0xF7, 0x9B, 0x46, 0x69, 0xD6, 0xAC,
  41813. 0x12, 0xE9, 0xA7, 0xC2, 0xD1, 0xC8, 0xAD, 0x5D,
  41814. 0xF7, 0xCB, 0x0C, 0x98, 0x78, 0x2D, 0x04, 0x4D,
  41815. 0x2D, 0x41, 0xAB, 0xC6, 0x3F, 0x81, 0x1D, 0xB9,
  41816. 0x2C, 0x1F, 0x3F, 0x59, 0x11, 0xF4, 0x80, 0x4F,
  41817. 0x0B, 0xCA, 0x9F, 0x81, 0x6E, 0x9C, 0xD1, 0xB4,
  41818. 0x74, 0x06, 0x48, 0x0A, 0x87, 0x2C, 0xFD, 0x4D,
  41819. 0x85, 0xD4, 0x21, 0x65, 0x7C, 0x96, 0x69, 0x53,
  41820. 0x51, 0xC0, 0xC4, 0xB0, 0xEB, 0x20, 0xDB, 0xE0,
  41821. 0x41, 0x09, 0xA7, 0x62, 0xB2, 0xF3, 0xC7, 0x6A,
  41822. 0x1D, 0x53, 0xA0, 0x39, 0xBA, 0xCF, 0x78, 0x9E,
  41823. 0xBF, 0x1D, 0xA5, 0x98, 0x09, 0x8E, 0xA7, 0x1A,
  41824. 0xE7, 0x95, 0xFF, 0x10, 0x38, 0xCC, 0x8F, 0x44,
  41825. 0xCB, 0xE7, 0xF6, 0xD6, 0x2C, 0xFF, 0xA8, 0x1C,
  41826. 0xFF, 0xA3, 0x65, 0xE8, 0x4E, 0xAE, 0xC7, 0xEF,
  41827. 0x61, 0xE1, 0x16, 0x4B, 0x8C, 0xA8, 0xC8, 0xFB,
  41828. 0xA5, 0x2C, 0xD1, 0x0A, 0x39, 0xAB, 0x4A, 0xF9,
  41829. 0xEE, 0x0B, 0x9B, 0xB4, 0x33, 0x5E, 0x25, 0x15,
  41830. 0xD0, 0xAA, 0x93, 0xC4, 0x53, 0x42, 0x91, 0xC5,
  41831. 0x98, 0x15, 0x34, 0x9A, 0x22, 0x1D, 0x9A, 0xE7,
  41832. 0x0E, 0x81, 0xF6, 0x99, 0x55, 0xB3, 0xD6, 0x49,
  41833. 0x1B, 0xB8, 0xA8, 0xBE, 0xDF, 0x54, 0xF0, 0x78,
  41834. 0xF7, 0x02, 0x97, 0x74, 0x84, 0x67, 0x6B, 0xAE,
  41835. 0x2F, 0xEC, 0x6E, 0x59, 0x20, 0x68, 0xD8, 0xE3,
  41836. 0x5A, 0x07, 0x48, 0xE1, 0x99, 0x90, 0xEE, 0xCD,
  41837. 0x17, 0x2B, 0xB6, 0xD6, 0xAA, 0x1A, 0xF8, 0x97,
  41838. 0x4E, 0xE0, 0x67, 0x9E, 0x4C, 0x35, 0xFE, 0x68,
  41839. 0x71, 0x54, 0x43, 0x5D, 0x43, 0x59, 0x19, 0xEB,
  41840. 0x58, 0x8E, 0x9A, 0xF6, 0xBD, 0x88, 0x71, 0xEE,
  41841. 0x89, 0xC6, 0xF2, 0x10, 0x04, 0x33, 0x13, 0x88,
  41842. 0xCD, 0x08, 0xB5, 0xE3, 0x5D, 0xA8, 0xBC, 0x43,
  41843. 0xB3, 0x84, 0x5F, 0x70, 0x94, 0xD9, 0xAC, 0xAE,
  41844. 0x74, 0x70, 0x13, 0x1E, 0x21, 0xFB, 0xD5, 0x7F,
  41845. 0xEC, 0x66, 0x2F, 0xA0, 0xB1, 0x1D, 0xE3, 0xF8,
  41846. 0xB9, 0x36, 0x48, 0x25, 0x3D, 0xBA, 0x7D, 0x44,
  41847. 0x08, 0xC5, 0x71, 0x74, 0xDA, 0xD3, 0x4F, 0x97,
  41848. 0x86, 0xF1, 0x16, 0x38, 0xD8, 0xC9, 0xE3, 0x3A,
  41849. 0xA7, 0x2E, 0x06, 0x4D, 0x9D, 0xE8, 0xFC, 0x38,
  41850. 0x58, 0x2A, 0x8D, 0x2D, 0x07, 0x99, 0xEA, 0xDF,
  41851. 0xF3, 0x00, 0x3B, 0xBC, 0x5F, 0x67, 0x1E, 0x4B,
  41852. 0x6C, 0xF1, 0x4A, 0x47, 0xB0, 0x71, 0x90, 0x5A,
  41853. 0x3B, 0x75, 0x93, 0x75, 0x56, 0x50, 0x4C, 0x70,
  41854. 0xF3, 0xC7, 0x95, 0xD5, 0xEA, 0xCB, 0x4C, 0x92,
  41855. 0x4F, 0x22, 0x4F, 0xD9, 0x34, 0x46, 0x76, 0xFB,
  41856. 0x79, 0xD6, 0xBD, 0x4E, 0x84, 0xEE, 0xE7, 0x78,
  41857. 0x7C, 0xB8, 0x92, 0x9F, 0xAD, 0xF2, 0x17, 0x5D,
  41858. 0x38, 0xB1, 0x88, 0x2E, 0xE9, 0x65, 0xAC, 0x4C,
  41859. 0x24, 0x27, 0x1D, 0x7B, 0xA3, 0x69, 0x96, 0x55,
  41860. 0x5C, 0x26, 0x40, 0xAF, 0x04, 0xB1, 0xCE, 0xA8,
  41861. 0x5D, 0x1E, 0x1F, 0xE5, 0x5A, 0xC3, 0xAE, 0xF9,
  41862. 0x14, 0x03, 0x58, 0x10, 0x1C, 0x8B, 0x1F, 0xDB,
  41863. 0x6C, 0x71, 0x68, 0x60, 0x13, 0x32, 0xF1, 0xA9,
  41864. 0x69, 0x45, 0x28, 0x69, 0x7C, 0xE3, 0xC9, 0x56,
  41865. 0xAF, 0xF3, 0xBD, 0x4B, 0x9E, 0x0A, 0x06, 0x6A,
  41866. 0x62, 0x20, 0x40, 0x65, 0xBD, 0xBC, 0xBF, 0xC7,
  41867. 0x0A, 0x2A, 0xCF, 0x56, 0x7C, 0x0E, 0x64, 0xBB,
  41868. 0x64, 0x71, 0x2D, 0x90, 0xBB, 0x32, 0x00, 0x0A,
  41869. 0x4A, 0x45, 0x44, 0x08, 0x75, 0x2C, 0x86, 0x13,
  41870. 0x86, 0x52, 0x8D, 0x3D, 0xFC, 0xF3, 0x5E, 0x5B,
  41871. 0x3F, 0x7A, 0xAA, 0x98, 0x84, 0xCF, 0x92, 0xF9,
  41872. 0x0B, 0x40, 0x8F, 0xC0, 0xA3, 0x71, 0x84, 0xAD,
  41873. 0xEE, 0xDF, 0xC4, 0x91, 0x7E, 0x87, 0x7D, 0x06,
  41874. 0xCA, 0x65, 0x8C, 0xE4, 0x8E, 0x03, 0xF0, 0x59,
  41875. 0x3E, 0xB4, 0x90, 0x4C, 0xEE, 0x88, 0x29, 0xE4,
  41876. 0x26, 0x7D, 0xA6, 0x54, 0x82, 0x49, 0xC1, 0x9D,
  41877. 0x80, 0xAB, 0x6B, 0xD7, 0xBE, 0x7D, 0x09, 0x80,
  41878. 0x5E, 0xB6, 0xD1, 0x1E, 0xD1, 0x1B, 0xE9, 0x8D,
  41879. 0xFC, 0x6E, 0x9C, 0x14, 0x0C, 0x15, 0x02, 0x87,
  41880. 0xF3, 0x9D, 0x21, 0xF8, 0xCB, 0xC8, 0xB9, 0xBD,
  41881. 0xE1, 0x70, 0xEA, 0xE4, 0x86, 0x4C, 0x97, 0xC1,
  41882. 0xEE, 0x4C, 0x18, 0x95, 0xEC, 0xD2, 0x4D, 0x35,
  41883. 0x9F, 0xC6, 0x56, 0x10, 0x3E, 0xC0, 0xB9, 0x7B,
  41884. 0x13, 0x1A, 0x37, 0x3D, 0x40, 0x4C, 0x88, 0x8B,
  41885. 0x9A, 0xA5, 0xB2, 0xB8, 0xB9, 0xC3, 0xEC, 0xF1,
  41886. 0x14, 0x33, 0x63, 0x67, 0x84, 0x98, 0xC8, 0xF4,
  41887. 0x06, 0x0C, 0x0E, 0x0F, 0x10, 0x12, 0x15, 0x16,
  41888. 0x45, 0x4E, 0x55, 0x5A, 0x5F, 0x8A, 0x94, 0x97,
  41889. 0xA8, 0xAF, 0xB2, 0xCC, 0xD4, 0xDC, 0xE7, 0xF1,
  41890. 0xFE, 0xFF, 0x11, 0x24, 0x53, 0x62, 0x94, 0xB7,
  41891. 0xB9, 0xD3, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00,
  41892. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41893. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41894. 0x10, 0x18, 0x32, 0x3B
  41895. };
  41896. #endif
  41897. #ifndef WOLFSSL_NO_ML_DSA_65
  41898. static const byte pk_65[] = {
  41899. 0x6C, 0x84, 0x14, 0x38, 0x08, 0x56, 0xCB, 0x52,
  41900. 0xD7, 0x9C, 0x4B, 0x29, 0x13, 0x9F, 0xB1, 0x83,
  41901. 0x9B, 0x86, 0x06, 0xF5, 0x94, 0x8B, 0x9D, 0x72,
  41902. 0xA9, 0x56, 0xDC, 0xF1, 0x01, 0x16, 0xDA, 0x9E,
  41903. 0x2D, 0x79, 0x77, 0x01, 0x86, 0xFC, 0x74, 0xD9,
  41904. 0x42, 0xC0, 0xF4, 0xA3, 0xB5, 0x95, 0xFF, 0x6C,
  41905. 0x19, 0x80, 0x4B, 0x49, 0x90, 0x1C, 0x6A, 0xD5,
  41906. 0xFA, 0xF7, 0x16, 0x01, 0xC2, 0xB6, 0x00, 0x31,
  41907. 0x5E, 0x1F, 0x40, 0xC2, 0x05, 0x47, 0x67, 0xB0,
  41908. 0x09, 0x25, 0xDF, 0x3A, 0xA4, 0x90, 0xE8, 0xC7,
  41909. 0x6F, 0x05, 0xFB, 0xFB, 0x74, 0x91, 0x10, 0x75,
  41910. 0xE6, 0x51, 0x8C, 0x5F, 0x1D, 0x91, 0xB8, 0xA0,
  41911. 0xE5, 0xB5, 0x98, 0x30, 0xD3, 0xDF, 0x39, 0x94,
  41912. 0x76, 0x04, 0x11, 0xEB, 0xB9, 0x11, 0xED, 0x4C,
  41913. 0xC2, 0xC1, 0x60, 0xE3, 0x84, 0x9A, 0x93, 0x76,
  41914. 0x2D, 0xFC, 0xA7, 0xB9, 0x81, 0x2B, 0xC7, 0xAE,
  41915. 0xB2, 0xDD, 0xB2, 0x76, 0x7B, 0xEF, 0x36, 0x50,
  41916. 0x56, 0x05, 0xAE, 0x06, 0x92, 0x60, 0xBC, 0xC8,
  41917. 0xDC, 0x47, 0x87, 0xC4, 0x28, 0xCB, 0x3C, 0x07,
  41918. 0x6E, 0xF2, 0xA6, 0xB9, 0x35, 0x61, 0xD8, 0x94,
  41919. 0x3F, 0x45, 0xCA, 0xBE, 0x8F, 0x05, 0x53, 0xFF,
  41920. 0x2E, 0xA1, 0xAC, 0x95, 0xC1, 0xCE, 0x21, 0x59,
  41921. 0x3A, 0x17, 0x54, 0x59, 0xD7, 0xDF, 0x12, 0xC4,
  41922. 0x07, 0x0A, 0xDB, 0x0E, 0xEE, 0x55, 0xB4, 0xAB,
  41923. 0xAE, 0x59, 0xBE, 0x69, 0xC3, 0xFF, 0x0D, 0xE5,
  41924. 0xA9, 0xB0, 0x27, 0xFC, 0x7D, 0x8E, 0x6E, 0x05,
  41925. 0x7B, 0x71, 0x52, 0xEE, 0x6A, 0xB4, 0x80, 0xD1,
  41926. 0x05, 0xD3, 0x0B, 0x0F, 0x50, 0x51, 0xB6, 0x0C,
  41927. 0x79, 0x01, 0xC5, 0x25, 0xC4, 0x63, 0x5F, 0xE6,
  41928. 0x68, 0xCC, 0x00, 0xE9, 0xD3, 0x09, 0x7D, 0xB9,
  41929. 0x9D, 0x66, 0x32, 0x37, 0x15, 0xCE, 0x4F, 0x0B,
  41930. 0x79, 0xB4, 0x26, 0xB4, 0x54, 0x5E, 0x09, 0xF4,
  41931. 0xDE, 0x39, 0x32, 0x3D, 0xD1, 0x4C, 0xCB, 0x0D,
  41932. 0x17, 0x10, 0x8C, 0xD4, 0x6D, 0xEC, 0x61, 0x38,
  41933. 0xCD, 0xFA, 0x28, 0x72, 0xC1, 0xC4, 0xC8, 0xAE,
  41934. 0xAD, 0x5C, 0x8C, 0xE0, 0x41, 0x57, 0xE5, 0x53,
  41935. 0xA3, 0x75, 0x58, 0xC2, 0x34, 0x6A, 0x06, 0x19,
  41936. 0x4C, 0xB5, 0x0B, 0x49, 0x81, 0xBF, 0x4D, 0x09,
  41937. 0x0C, 0xE4, 0xE8, 0x60, 0x12, 0x6A, 0x82, 0x54,
  41938. 0xA4, 0xD4, 0xC0, 0x84, 0xC3, 0xE2, 0x02, 0x0B,
  41939. 0xC0, 0x75, 0x35, 0x21, 0x04, 0x9B, 0x0F, 0xD8,
  41940. 0x89, 0x97, 0xE0, 0x27, 0xAC, 0x51, 0xE7, 0x5C,
  41941. 0xF1, 0x35, 0x0C, 0x3F, 0x30, 0x3A, 0x0E, 0xCE,
  41942. 0x42, 0x64, 0x87, 0x15, 0x3D, 0xAF, 0x1F, 0xAA,
  41943. 0xD6, 0x80, 0x8B, 0x9D, 0x99, 0x07, 0xDA, 0x9F,
  41944. 0x35, 0x18, 0x5B, 0xD3, 0xBE, 0x8D, 0x9C, 0xEB,
  41945. 0xE9, 0x16, 0xCE, 0xD1, 0xFA, 0x29, 0x28, 0xD8,
  41946. 0x85, 0xA9, 0xCB, 0xA8, 0x81, 0x49, 0x70, 0x3F,
  41947. 0x5E, 0x47, 0x72, 0xE4, 0x85, 0x23, 0x12, 0x5D,
  41948. 0xDD, 0x02, 0x6E, 0x71, 0x4C, 0x49, 0xF4, 0xFB,
  41949. 0x4E, 0x54, 0x4B, 0xBF, 0x61, 0x7A, 0x40, 0xB0,
  41950. 0x0B, 0x68, 0xDF, 0x8F, 0x15, 0x5F, 0x58, 0x80,
  41951. 0xD4, 0x11, 0x87, 0x7E, 0x25, 0xB4, 0x2B, 0x24,
  41952. 0x48, 0xB3, 0x6B, 0xEC, 0x2F, 0x1F, 0x8F, 0x9A,
  41953. 0x77, 0x0C, 0x54, 0x51, 0x50, 0xA0, 0x27, 0x8E,
  41954. 0x9B, 0x72, 0x45, 0x00, 0xAE, 0xAA, 0xEA, 0x47,
  41955. 0x1C, 0x11, 0xCF, 0xF0, 0x4E, 0x30, 0xEA, 0xB2,
  41956. 0xF4, 0x73, 0xBC, 0x04, 0x8E, 0x32, 0xCD, 0x31,
  41957. 0xAE, 0xF2, 0x15, 0x79, 0xB6, 0x99, 0x22, 0x5B,
  41958. 0xF9, 0xE1, 0xB6, 0x70, 0x0C, 0x57, 0xE5, 0x09,
  41959. 0xFC, 0xA1, 0xF2, 0x36, 0x29, 0x4A, 0x59, 0x74,
  41960. 0xDA, 0xA1, 0x5F, 0xBC, 0xAD, 0x62, 0xD4, 0xBD,
  41961. 0xDC, 0x45, 0x32, 0xB2, 0x61, 0x41, 0x44, 0xDB,
  41962. 0xE2, 0x88, 0x07, 0x36, 0x8C, 0x28, 0x1A, 0x77,
  41963. 0x0E, 0xA2, 0x2B, 0x1E, 0x5A, 0x3F, 0xA5, 0xBA,
  41964. 0x14, 0x92, 0x6D, 0xC5, 0x5A, 0x54, 0xF8, 0x4A,
  41965. 0x2A, 0x77, 0xC5, 0xA7, 0x08, 0x41, 0xF0, 0x7B,
  41966. 0xC1, 0xDE, 0xEF, 0x74, 0x03, 0xB2, 0x47, 0xAB,
  41967. 0x42, 0xB8, 0x4A, 0xDF, 0x14, 0x1E, 0x03, 0x0C,
  41968. 0x98, 0x46, 0x84, 0x24, 0xDA, 0xAE, 0xB9, 0x9D,
  41969. 0x25, 0x77, 0xF9, 0x50, 0xC2, 0x37, 0x3C, 0xCA,
  41970. 0x1E, 0x2D, 0xC2, 0x76, 0x1B, 0x8E, 0xDD, 0x6D,
  41971. 0x08, 0xFF, 0x79, 0xE5, 0x28, 0x88, 0x0F, 0xFB,
  41972. 0x51, 0xC3, 0x6E, 0xD4, 0x20, 0xAC, 0x5D, 0x50,
  41973. 0xF2, 0x58, 0x2A, 0xA6, 0x64, 0xE5, 0x4E, 0xA5,
  41974. 0xF4, 0x18, 0x9E, 0xA0, 0x17, 0x6D, 0xAA, 0x61,
  41975. 0x22, 0xF6, 0x23, 0x5A, 0x70, 0xB1, 0x5C, 0xEB,
  41976. 0x4D, 0xDD, 0x65, 0xD3, 0xBE, 0x6E, 0xBF, 0x3D,
  41977. 0xC4, 0x31, 0x89, 0xEE, 0x0A, 0x2E, 0x31, 0x05,
  41978. 0x63, 0x8F, 0x23, 0x87, 0x36, 0x95, 0x28, 0x0F,
  41979. 0x1B, 0x74, 0x27, 0x43, 0x52, 0xD6, 0x0A, 0x48,
  41980. 0xE5, 0xD3, 0xDD, 0x02, 0xFB, 0x7A, 0x5E, 0xD8,
  41981. 0x3F, 0xE2, 0x7A, 0x69, 0x82, 0x51, 0x42, 0x1C,
  41982. 0x8E, 0x9C, 0x98, 0x80, 0x61, 0x02, 0x39, 0x6E,
  41983. 0x53, 0x73, 0x90, 0xAC, 0xFD, 0x8C, 0x1D, 0x0B,
  41984. 0x4F, 0x99, 0xB7, 0x02, 0xA9, 0xEA, 0x65, 0x98,
  41985. 0x78, 0x58, 0x3D, 0x92, 0x75, 0x89, 0x41, 0xB3,
  41986. 0x0E, 0xCE, 0x50, 0x7C, 0x10, 0x4B, 0x2C, 0xE4,
  41987. 0x87, 0x67, 0x9E, 0xCF, 0x68, 0xB4, 0xD8, 0xB9,
  41988. 0x80, 0x69, 0x8A, 0xCF, 0x6A, 0xA6, 0xA5, 0x7E,
  41989. 0x8E, 0xD6, 0xAF, 0x3F, 0xF1, 0x8D, 0x26, 0x68,
  41990. 0x95, 0x04, 0x28, 0xB5, 0x7D, 0x18, 0x2F, 0x73,
  41991. 0xBB, 0x49, 0xB9, 0xB0, 0x38, 0xCC, 0xC8, 0x2D,
  41992. 0x56, 0x12, 0x78, 0xA3, 0x86, 0xD5, 0x66, 0x45,
  41993. 0xEC, 0x3F, 0xAF, 0xFB, 0x41, 0x25, 0xE0, 0xE7,
  41994. 0xF3, 0x6B, 0x48, 0xB1, 0x4B, 0x45, 0x25, 0x47,
  41995. 0xA0, 0xB4, 0x81, 0xAA, 0x6B, 0x33, 0x42, 0x29,
  41996. 0x24, 0x91, 0x53, 0xE4, 0x2E, 0xDF, 0x7E, 0x49,
  41997. 0xDD, 0x6E, 0x76, 0x36, 0xBF, 0xC6, 0x15, 0xA2,
  41998. 0x3A, 0x40, 0x1E, 0xFD, 0x40, 0x34, 0xC8, 0x1B,
  41999. 0x4D, 0xCE, 0xF0, 0x27, 0xD3, 0x44, 0xDD, 0xCC,
  42000. 0xE0, 0xA7, 0x16, 0x18, 0xEB, 0x59, 0x10, 0xCE,
  42001. 0xC6, 0x22, 0x28, 0x81, 0x93, 0x85, 0x03, 0x3E,
  42002. 0x8D, 0x0A, 0xBD, 0x49, 0x3D, 0x98, 0x3E, 0x4F,
  42003. 0xC0, 0x87, 0xD7, 0x2B, 0x45, 0x5E, 0x4D, 0xB6,
  42004. 0x3A, 0x2F, 0x82, 0xCE, 0xFF, 0x65, 0xC1, 0xE6,
  42005. 0x28, 0xEA, 0xE6, 0x30, 0x59, 0x6D, 0xEC, 0x27,
  42006. 0xFB, 0x98, 0xB8, 0x4D, 0xBF, 0xDC, 0xDF, 0xAB,
  42007. 0x40, 0xE4, 0x72, 0x24, 0x49, 0x14, 0xAF, 0xF1,
  42008. 0x79, 0x32, 0x6D, 0x54, 0x2D, 0x40, 0x1A, 0x3C,
  42009. 0xBB, 0x86, 0xE5, 0xFF, 0x83, 0x51, 0xEF, 0xE5,
  42010. 0x3A, 0x73, 0xC5, 0x1A, 0xBB, 0x63, 0xFF, 0x55,
  42011. 0x3E, 0x7D, 0x79, 0x57, 0xEF, 0x89, 0x13, 0x5E,
  42012. 0x0F, 0x5B, 0xB1, 0xBD, 0x0C, 0x24, 0xF9, 0xE4,
  42013. 0x5E, 0x32, 0x36, 0x41, 0x3C, 0x60, 0xE1, 0x39,
  42014. 0x6A, 0x47, 0x56, 0x7C, 0x94, 0x39, 0x51, 0x0F,
  42015. 0x00, 0xD4, 0xA4, 0x3C, 0x14, 0x9A, 0x5C, 0xCC,
  42016. 0x04, 0xF3, 0xD4, 0x7E, 0x67, 0xA8, 0xE2, 0x94,
  42017. 0xA4, 0x61, 0xA5, 0xF6, 0x93, 0xDB, 0x0C, 0xAE,
  42018. 0x22, 0xCF, 0xAC, 0x61, 0xE8, 0x53, 0x47, 0x7D,
  42019. 0x33, 0x9A, 0x4E, 0x45, 0xF7, 0xB1, 0x7C, 0x3C,
  42020. 0x11, 0x6D, 0x56, 0xF3, 0xA0, 0x68, 0xFC, 0x5A,
  42021. 0xDF, 0xEF, 0x38, 0xFF, 0x85, 0x33, 0x2B, 0xD5,
  42022. 0x15, 0x3C, 0x4D, 0x8F, 0xB8, 0xF1, 0x48, 0xF1,
  42023. 0x17, 0x65, 0x9C, 0x2E, 0xA9, 0x4D, 0xB4, 0x2A,
  42024. 0xA0, 0xB0, 0xBE, 0xBB, 0x47, 0x5A, 0x11, 0x04,
  42025. 0x12, 0xF3, 0xCD, 0x33, 0x49, 0xFC, 0x1A, 0xD0,
  42026. 0x41, 0xB7, 0xD5, 0x30, 0x4A, 0x85, 0x93, 0x14,
  42027. 0x4E, 0xFA, 0x3A, 0x36, 0x1D, 0x1B, 0x0C, 0x76,
  42028. 0x13, 0xB8, 0x2C, 0x08, 0x6E, 0xA7, 0x12, 0x6E,
  42029. 0x43, 0xC6, 0x16, 0xCE, 0xE8, 0xF1, 0x44, 0x4E,
  42030. 0x99, 0x56, 0xE8, 0x7F, 0x5C, 0xAB, 0x95, 0xC7,
  42031. 0xC7, 0xFB, 0x17, 0x58, 0xEC, 0x7D, 0x97, 0x01,
  42032. 0x9E, 0x5B, 0xA9, 0x35, 0x43, 0xEF, 0x3B, 0xAC,
  42033. 0x1A, 0x17, 0x42, 0x99, 0xCA, 0x48, 0xBF, 0x78,
  42034. 0x59, 0xDB, 0xFB, 0xDF, 0xF2, 0x43, 0xB1, 0x14,
  42035. 0xF6, 0xBF, 0x42, 0x3C, 0xE9, 0x8B, 0x4D, 0x4D,
  42036. 0x09, 0x1D, 0xA4, 0x4F, 0x32, 0x74, 0xD5, 0x73,
  42037. 0xFD, 0xC9, 0x04, 0xBD, 0x88, 0x5E, 0x35, 0xC9,
  42038. 0x15, 0x2A, 0x65, 0x35, 0x48, 0x88, 0xF1, 0x1E,
  42039. 0xD4, 0xF3, 0xD6, 0x3F, 0x26, 0xA7, 0xBE, 0x2F,
  42040. 0x57, 0x26, 0xEA, 0xDA, 0xF4, 0x85, 0x86, 0x59,
  42041. 0x2B, 0xBD, 0xF6, 0xCE, 0xE2, 0x46, 0x76, 0x9E,
  42042. 0x0E, 0xDA, 0x2A, 0x80, 0x77, 0x1F, 0xED, 0x34,
  42043. 0x7D, 0x67, 0xAF, 0xEE, 0xC6, 0x8B, 0x89, 0x46,
  42044. 0x3F, 0xA0, 0x49, 0x6D, 0xBC, 0x15, 0xC8, 0x9E,
  42045. 0x8D, 0x56, 0x99, 0x83, 0xD1, 0xD6, 0x74, 0x73,
  42046. 0x3F, 0x2B, 0xF9, 0xDF, 0x4A, 0x98, 0x0E, 0xA8,
  42047. 0xC5, 0xE3, 0xAF, 0x15, 0x56, 0x0A, 0x0E, 0x28,
  42048. 0xD6, 0x72, 0xB5, 0x80, 0xAB, 0x65, 0x52, 0xED,
  42049. 0x76, 0xAA, 0xCB, 0x5F, 0x80, 0x26, 0x0B, 0x97,
  42050. 0x03, 0x76, 0x9D, 0x33, 0xF4, 0x13, 0x8A, 0xBC,
  42051. 0x10, 0xBF, 0x5B, 0x05, 0x82, 0xDC, 0xC6, 0x2D,
  42052. 0xBE, 0x58, 0xC8, 0x90, 0xF5, 0x1B, 0x41, 0x00,
  42053. 0x12, 0x77, 0x34, 0xFB, 0x7D, 0xB7, 0x44, 0x7A,
  42054. 0x72, 0x0A, 0xAE, 0x00, 0x9D, 0x00, 0xBE, 0x8C,
  42055. 0x61, 0x07, 0x92, 0xC6, 0x4F, 0x13, 0x1F, 0x2D,
  42056. 0x72, 0x11, 0x5C, 0x7E, 0x05, 0x8E, 0x48, 0xB9,
  42057. 0xDE, 0x64, 0xF5, 0x5B, 0x4D, 0x61, 0x0C, 0x36,
  42058. 0xD1, 0x12, 0x71, 0x6A, 0x31, 0xA3, 0xDF, 0xE2,
  42059. 0x66, 0x99, 0xE9, 0xC2, 0xAB, 0xA0, 0x56, 0x58,
  42060. 0xCE, 0xF1, 0xB2, 0xB0, 0x86, 0x7C, 0xF8, 0xD5,
  42061. 0x23, 0x3D, 0xB7, 0x4F, 0xA8, 0xDC, 0x3A, 0xD1,
  42062. 0x45, 0xF5, 0xD2, 0x85, 0x74, 0x36, 0x0A, 0x85,
  42063. 0xE3, 0xB0, 0xB1, 0x0A, 0xC0, 0xA6, 0x46, 0x7A,
  42064. 0x7B, 0x05, 0x98, 0x46, 0x28, 0xEC, 0xA1, 0x04,
  42065. 0x63, 0xF3, 0x48, 0xA3, 0x11, 0x1E, 0x00, 0x57,
  42066. 0x8D, 0x3C, 0xE5, 0x48, 0x0F, 0x53, 0x75, 0xA1,
  42067. 0xEE, 0x23, 0xEE, 0x82, 0x08, 0x7B, 0xAC, 0x41,
  42068. 0x23, 0x3A, 0x14, 0xAA, 0xA7, 0x24, 0x73, 0x4B,
  42069. 0x18, 0x74, 0xA4, 0xAC, 0xE1, 0x13, 0x37, 0x06,
  42070. 0x25, 0x8F, 0x5F, 0xEA, 0x3A, 0x0C, 0x16, 0x09,
  42071. 0xE3, 0x0C, 0x7F, 0xD2, 0x10, 0xDA, 0x0C, 0x4F,
  42072. 0xDE, 0x91, 0x62, 0xDF, 0x66, 0xFB, 0xAF, 0x79,
  42073. 0x2F, 0xA2, 0xAE, 0xAA, 0x51, 0x2F, 0x0F, 0xF7,
  42074. 0x83, 0x7B, 0x9C, 0xC0, 0x2E, 0xE9, 0xBD, 0x95,
  42075. 0x53, 0x9F, 0x00, 0x1B, 0xBD, 0x60, 0xDD, 0x8B,
  42076. 0x42, 0xD6, 0x16, 0xB2, 0xCA, 0x95, 0xF3, 0x83,
  42077. 0x5F, 0x5E, 0x47, 0xD4, 0x3B, 0x14, 0x34, 0xC4,
  42078. 0x56, 0x3F, 0xD8, 0x1C, 0x15, 0xBE, 0xFA, 0x20,
  42079. 0x2C, 0xF3, 0xD9, 0x54, 0x08, 0x73, 0xF6, 0x84,
  42080. 0xAF, 0xE1, 0x9A, 0xB5, 0xC0, 0x1F, 0xA9, 0x2E,
  42081. 0x95, 0xA8, 0xCD, 0x6F, 0x36, 0x07, 0x30, 0x85,
  42082. 0x6E, 0x59, 0xC9, 0xC6, 0xAB, 0x77, 0x0D, 0x65,
  42083. 0x75, 0x96, 0x2A, 0xF7, 0x58, 0x78, 0x57, 0x2A,
  42084. 0x2A, 0x26, 0x41, 0x3D, 0x01, 0xAB, 0x31, 0x8C,
  42085. 0x10, 0x0D, 0xFC, 0x34, 0xDC, 0x1D, 0xEF, 0xA5,
  42086. 0x92, 0x7C, 0x4B, 0x45, 0x99, 0x25, 0xD7, 0x3E,
  42087. 0x1E, 0xB9, 0x14, 0x70, 0xE3, 0x7A, 0x58, 0x45,
  42088. 0x5C, 0x22, 0xA9, 0x61, 0xFD, 0x53, 0xF7, 0xD9,
  42089. 0x90, 0x26, 0xFF, 0x88, 0x4B, 0xF4, 0xA2, 0x57,
  42090. 0x9F, 0x70, 0x63, 0x35, 0xEF, 0xB6, 0xFB, 0x22,
  42091. 0x50, 0xD5, 0x2A, 0xE5, 0x61, 0x89, 0x8B, 0xA1,
  42092. 0x60, 0x6E, 0x51, 0xE9, 0x6D, 0x37, 0xC9, 0xED,
  42093. 0x3E, 0xC6, 0xCF, 0xCB, 0x33, 0xBF, 0xBE, 0x9C,
  42094. 0x31, 0x43, 0xFD, 0x3B, 0x6B, 0x33, 0x4D, 0x5F,
  42095. 0x61, 0x92, 0x2B, 0x36, 0x9A, 0xFB, 0xB3, 0x1C,
  42096. 0x3E, 0x6E, 0x9B, 0x5F, 0x3A, 0xEB, 0xF9, 0x5C,
  42097. 0xB7, 0x08, 0x34, 0x6F, 0xEC, 0xF7, 0x15, 0x9C,
  42098. 0xAD, 0x94, 0xA9, 0x3D, 0x8C, 0xD4, 0xB8, 0xC4,
  42099. 0x89, 0x41, 0x92, 0xDF, 0xE5, 0x3E, 0xA4, 0x36,
  42100. 0xFB, 0xF3, 0xAF, 0x4E, 0x86, 0x4E, 0x8C, 0x39,
  42101. 0x91, 0xEA, 0x02, 0x0A, 0x81, 0x1F, 0x0A, 0xF5,
  42102. 0x0B, 0x42, 0x57, 0x43, 0x6A, 0x3F, 0xF5, 0x22,
  42103. 0xBE, 0x73, 0x67, 0x39, 0x1D, 0x0F, 0x95, 0x0B,
  42104. 0xA6, 0x45, 0x2F, 0xBF, 0xD8, 0xFD, 0x87, 0x28,
  42105. 0xF4, 0x0B, 0xD2, 0xFC, 0xB8, 0x94, 0x52, 0x99,
  42106. 0x85, 0xB4, 0x32, 0xDF, 0xEF, 0x62, 0x30, 0xEB,
  42107. 0x4D, 0xEE, 0x73, 0x7A, 0x8D, 0x10, 0xA3, 0xBC,
  42108. 0xDF, 0xB7, 0x63, 0xE0, 0x86, 0x9B, 0x22, 0x5C,
  42109. 0x1A, 0x8D, 0x0E, 0x1F, 0xBF, 0x2D, 0x16, 0x1C,
  42110. 0x2C, 0x65, 0xD6, 0xDF, 0xB9, 0x58, 0xE9, 0x82,
  42111. 0xD1, 0x17, 0x77, 0xAC, 0xBE, 0xAD, 0x8D, 0xFB,
  42112. 0x6B, 0x1F, 0x5E, 0xB2, 0x1E, 0xA9, 0x42, 0xF7,
  42113. 0xC4, 0x0D, 0xC2, 0x0D, 0x2E, 0x4E, 0xB3, 0xE7,
  42114. 0x29, 0xB4, 0xE2, 0x9F, 0x75, 0x01, 0xDA, 0x34,
  42115. 0x23, 0x45, 0x61, 0xF6, 0x28, 0x88, 0x12, 0xD6,
  42116. 0x12, 0xD4, 0x1D, 0xFA, 0x83, 0xC5, 0xB8, 0xD9,
  42117. 0x0F, 0xF3, 0x8B, 0xA5, 0x48, 0x20, 0x1B, 0x57,
  42118. 0x5B, 0x52, 0x93, 0xAD, 0x78, 0x12, 0x0D, 0x91,
  42119. 0xCE, 0xC0, 0x59, 0xCA, 0xE2, 0xE7, 0x6A, 0x9A,
  42120. 0xB4, 0x3E, 0xF1, 0x28, 0x1E, 0x2B, 0xEF, 0x3E,
  42121. 0x34, 0x8D, 0x28, 0xF2, 0x19, 0x47, 0xC8, 0x88,
  42122. 0x48, 0x96, 0x04, 0x59, 0x48, 0x97, 0x75, 0x17,
  42123. 0x6F, 0x8E, 0x40, 0xEE, 0x06, 0x42, 0x79, 0x53,
  42124. 0x68, 0x7F, 0xB6, 0x3E, 0x47, 0x0F, 0x7D, 0x59,
  42125. 0xFB, 0x60, 0xDF, 0x56, 0x9F, 0x8A, 0x11, 0xE2,
  42126. 0x8E, 0x09, 0x37, 0x16, 0x2C, 0x46, 0xAF, 0xC7,
  42127. 0xD2, 0x21, 0x0A, 0x88, 0x5F, 0xFA, 0x21, 0xB3,
  42128. 0xDB, 0xF5, 0x35, 0x4B, 0x29, 0x41, 0xF4, 0xED,
  42129. 0x5D, 0x50, 0x79, 0x08, 0x90, 0x84, 0x0C, 0xC3,
  42130. 0xB9, 0x73, 0xD2, 0xC3, 0xD0, 0x26, 0x02, 0xB2,
  42131. 0x9B, 0xAC, 0xCB, 0x6C, 0xE1, 0x7C, 0xED, 0xB9,
  42132. 0x7B, 0x08, 0x5A, 0x2A, 0xB3, 0x10, 0x57, 0x2B,
  42133. 0xA7, 0x37, 0x1D, 0x1F, 0x81, 0x20, 0xFF, 0xE3,
  42134. 0x7D, 0x0B, 0x0F, 0xCA, 0x35, 0xAF, 0xC5, 0xB5,
  42135. 0x62, 0xAA, 0x84, 0x99, 0x71, 0x5A, 0x29, 0x9C,
  42136. 0xE0, 0x59, 0xCC, 0xE3, 0xB0, 0xD1, 0x1C, 0xEF,
  42137. 0x0D, 0x92, 0x38, 0x96, 0x1A, 0xD4, 0xBE, 0x11,
  42138. 0xE9, 0xA6, 0xD1, 0xA4, 0x69, 0x21, 0x77, 0xC8,
  42139. 0xB0, 0xC5, 0x3F, 0x11, 0xA8, 0xED, 0x26, 0x50,
  42140. 0x21, 0x2E, 0x7A, 0x2F, 0x80, 0xEB, 0xFF, 0x6D,
  42141. 0xCF, 0xE4, 0x67, 0x21, 0x03, 0x65, 0x84, 0x34,
  42142. 0xD0, 0x32, 0x7A, 0xDD, 0xCD, 0x66, 0xBC, 0xB6
  42143. };
  42144. static const byte msg_65[] = {
  42145. 0xDB, 0x84, 0x94, 0xBA, 0x19, 0xC4, 0x11, 0x8F,
  42146. 0xB1, 0x5D, 0x0A, 0xCF, 0x42, 0x54, 0xFD, 0x37,
  42147. 0x48, 0x3F, 0xCF, 0x47, 0x48, 0xFD, 0x18, 0x44,
  42148. 0xF7, 0x17, 0xCE, 0x6F, 0x69, 0x58, 0x9E, 0x61,
  42149. 0x77, 0x2C, 0xFE, 0xFA, 0x7F, 0x97, 0x58, 0x65,
  42150. 0x34, 0x09, 0xD4, 0xEE, 0x5A, 0x26, 0x4B, 0x83,
  42151. 0x4E, 0x60, 0xD6, 0xBB, 0x96, 0x49, 0x9E, 0xBE,
  42152. 0xB2, 0xB0, 0x6B, 0x0B, 0xA8, 0x74, 0xBF, 0x31,
  42153. 0xE6, 0x41, 0x39, 0x4C, 0xFA, 0xA6, 0xA2, 0xD3,
  42154. 0x0D, 0xDB, 0x8F, 0x04, 0x58, 0x76, 0x20, 0x8D,
  42155. 0x2F, 0x51, 0xDE, 0x15, 0xE2, 0x05, 0xE8, 0xC9,
  42156. 0x1B, 0x87, 0xEC, 0xEB, 0x05, 0xFF, 0x31, 0x83,
  42157. 0x27, 0x1B, 0x26, 0x49, 0x66, 0x5D, 0xD3, 0xCC,
  42158. 0x49, 0xBF, 0xDB, 0x99, 0x8D, 0x53, 0x9D, 0xA8,
  42159. 0x09, 0x30, 0x55, 0x16, 0xBB, 0xBE, 0x9C, 0x90,
  42160. 0x60, 0x21, 0x19, 0x1C, 0x52, 0x23, 0xE5, 0x25,
  42161. 0xA8, 0xFC, 0x36, 0x16, 0xA1, 0x76, 0x5E, 0xC3,
  42162. 0xF9, 0xC5, 0xDB, 0x53, 0xCC, 0x33, 0x7E, 0x03,
  42163. 0x9F, 0x18, 0x6A, 0xCF, 0xEA, 0x91, 0x14, 0x8E,
  42164. 0xE2, 0xA7, 0x9C, 0xCA, 0x36, 0x89, 0xED, 0xB6,
  42165. 0x2A, 0xAF, 0x28, 0xB5, 0xD7, 0x52, 0xFD, 0xE2,
  42166. 0x65, 0xEE, 0x52, 0x80, 0xB5, 0x19, 0x72, 0x6C,
  42167. 0x1C, 0xA9, 0x80, 0x32, 0x95, 0xC6, 0x74, 0xB7,
  42168. 0xEF, 0xAF, 0xA4, 0xD6, 0x1B, 0x30, 0x6A, 0x79,
  42169. 0xE3, 0xF6, 0xE7, 0xA8, 0x87, 0xC2, 0xFB, 0x53,
  42170. 0x5B, 0x3B, 0x0F, 0xB3, 0xD9, 0xEB, 0xC8, 0x76,
  42171. 0x03, 0xEA, 0xFE, 0xF1, 0x70, 0xC1, 0xF1, 0xD2,
  42172. 0x8E, 0x99, 0xBB
  42173. };
  42174. static const byte sig_65[] = {
  42175. 0xF7, 0x78, 0x9A, 0x45, 0xA3, 0x58, 0x73, 0x30,
  42176. 0xE7, 0xFC, 0xF7, 0x06, 0x95, 0xF7, 0xF6, 0x96,
  42177. 0x88, 0xA2, 0xB8, 0xD0, 0xCE, 0x54, 0xF0, 0x90,
  42178. 0x21, 0x4F, 0x10, 0x9F, 0x56, 0x48, 0x4F, 0x98,
  42179. 0xC3, 0xAD, 0x1A, 0x53, 0xA5, 0x44, 0x1C, 0x2C,
  42180. 0xA7, 0x2A, 0x3B, 0x31, 0x91, 0xBC, 0x04, 0x6F,
  42181. 0x46, 0x37, 0x30, 0x45, 0xB9, 0xE5, 0x40, 0xC7,
  42182. 0x3D, 0xFE, 0x91, 0xB6, 0x1F, 0x05, 0x88, 0xD6,
  42183. 0x13, 0x59, 0x3F, 0xCE, 0x1B, 0x00, 0xEE, 0xF1,
  42184. 0xB2, 0x27, 0x03, 0x4C, 0x6F, 0xD3, 0xB1, 0x8B,
  42185. 0x3F, 0x22, 0x11, 0x10, 0xFB, 0x34, 0x5A, 0xA7,
  42186. 0x86, 0x31, 0xB8, 0xB5, 0x9F, 0xBD, 0xFD, 0xCC,
  42187. 0xDA, 0xE6, 0xA2, 0x4D, 0x25, 0x9D, 0x34, 0xAA,
  42188. 0xBA, 0xD2, 0x18, 0xB3, 0xAE, 0x4E, 0x77, 0x18,
  42189. 0x66, 0x53, 0xB8, 0x56, 0x3A, 0xA6, 0x12, 0x0A,
  42190. 0x0A, 0x53, 0x1A, 0x4E, 0x91, 0x37, 0x30, 0xDC,
  42191. 0x91, 0x4F, 0xE5, 0xE0, 0x08, 0xBE, 0xCE, 0x68,
  42192. 0x69, 0xB0, 0x2B, 0x07, 0xFD, 0xC1, 0x62, 0x14,
  42193. 0x54, 0x0D, 0x31, 0x6C, 0x43, 0xFA, 0x0C, 0x21,
  42194. 0x1B, 0x41, 0xAC, 0x7E, 0x52, 0x65, 0x67, 0x29,
  42195. 0xC7, 0x73, 0xE4, 0xC4, 0xB8, 0x8E, 0xD3, 0x11,
  42196. 0x88, 0x6D, 0xD4, 0xD2, 0x75, 0x41, 0x7D, 0x70,
  42197. 0x19, 0x66, 0x44, 0xEE, 0xD1, 0x5F, 0xA3, 0x15,
  42198. 0x06, 0x60, 0x03, 0xE3, 0x09, 0xF8, 0x32, 0xAF,
  42199. 0x91, 0x26, 0x2C, 0x94, 0x90, 0x11, 0xFC, 0xB0,
  42200. 0xAD, 0x2C, 0xCE, 0x65, 0xDD, 0x9E, 0xFF, 0x56,
  42201. 0x7E, 0xE2, 0x9C, 0xC4, 0x0A, 0x6F, 0xE0, 0x66,
  42202. 0x4E, 0x7D, 0x9F, 0x23, 0x65, 0x68, 0xFC, 0x94,
  42203. 0x29, 0x5D, 0xBB, 0x34, 0x28, 0x82, 0x33, 0xE8,
  42204. 0xC5, 0x11, 0xD2, 0x88, 0x15, 0xEC, 0x72, 0x10,
  42205. 0x32, 0x29, 0x6E, 0x1E, 0xDE, 0xCA, 0x7F, 0x72,
  42206. 0x6A, 0x6E, 0xB0, 0xF7, 0x6C, 0xC5, 0x82, 0x80,
  42207. 0x11, 0xC0, 0xE4, 0x01, 0x3C, 0xC7, 0xEE, 0x43,
  42208. 0x29, 0xB8, 0x1E, 0xCC, 0x0D, 0x52, 0xED, 0x1E,
  42209. 0x49, 0x1D, 0xD6, 0xD5, 0x5C, 0x52, 0x65, 0x66,
  42210. 0x5E, 0xD8, 0xAD, 0x21, 0x9B, 0x89, 0x4F, 0x31,
  42211. 0xC6, 0x8C, 0x61, 0x9A, 0xFC, 0xDB, 0x73, 0x58,
  42212. 0xE5, 0x55, 0x4C, 0x49, 0x5B, 0x8B, 0x6E, 0x33,
  42213. 0x25, 0x68, 0x8F, 0xB8, 0xC1, 0xA2, 0x53, 0x31,
  42214. 0xD5, 0x7B, 0xD3, 0x48, 0xA2, 0x7D, 0x39, 0x09,
  42215. 0x29, 0xBC, 0x46, 0xA1, 0x49, 0x6A, 0xB3, 0x5B,
  42216. 0x46, 0xBA, 0x61, 0xB6, 0xB9, 0xD2, 0x3C, 0xD0,
  42217. 0x63, 0x15, 0xFB, 0x72, 0xC2, 0x47, 0x76, 0x01,
  42218. 0x61, 0x30, 0xAD, 0xB1, 0xCF, 0x2D, 0xC7, 0x29,
  42219. 0x59, 0xEA, 0x9C, 0xAD, 0x96, 0xAF, 0x5D, 0xA9,
  42220. 0x96, 0x12, 0x6C, 0xDD, 0x85, 0xB1, 0x34, 0xCC,
  42221. 0x92, 0x7A, 0x51, 0xFD, 0x23, 0xF8, 0x47, 0x91,
  42222. 0xA3, 0xFC, 0xDA, 0x07, 0x7E, 0x15, 0x99, 0x17,
  42223. 0x48, 0xA0, 0x39, 0x4F, 0x33, 0x4E, 0xB8, 0xBC,
  42224. 0x48, 0xA9, 0x9A, 0xB9, 0xDF, 0xBB, 0x0F, 0x2A,
  42225. 0xAD, 0x6F, 0xBE, 0x48, 0x49, 0x61, 0xD3, 0xA4,
  42226. 0xE8, 0xF8, 0xB2, 0x1A, 0x6A, 0xC0, 0x92, 0xB2,
  42227. 0x26, 0xD6, 0xE1, 0x19, 0xFA, 0xD4, 0x4D, 0x8E,
  42228. 0x57, 0x6F, 0xE9, 0x6C, 0x6C, 0xDB, 0x68, 0x40,
  42229. 0xEA, 0x61, 0x4B, 0xAF, 0xC7, 0x07, 0x86, 0xC5,
  42230. 0x19, 0xE1, 0xD5, 0xDC, 0x0F, 0x98, 0x44, 0x43,
  42231. 0xC8, 0xB1, 0xE5, 0x4F, 0x8E, 0xE1, 0x76, 0xD9,
  42232. 0x8B, 0x2C, 0x70, 0x27, 0xF5, 0x7D, 0x7E, 0x3D,
  42233. 0xE9, 0xB2, 0xA0, 0xA3, 0x69, 0x11, 0xB8, 0xE4,
  42234. 0x71, 0x21, 0xDE, 0x0C, 0x07, 0xEB, 0xBA, 0x5D,
  42235. 0x7B, 0x59, 0x4E, 0xF2, 0x44, 0xC6, 0x83, 0x27,
  42236. 0xEC, 0x6C, 0x6D, 0x1D, 0xD5, 0x01, 0xF4, 0x83,
  42237. 0xFE, 0x9B, 0x95, 0x70, 0x59, 0x7E, 0x70, 0xDF,
  42238. 0x41, 0x3E, 0x7A, 0xF0, 0x38, 0x47, 0xF4, 0x09,
  42239. 0xED, 0x61, 0xE2, 0x84, 0x6E, 0x6C, 0x64, 0x1E,
  42240. 0x6A, 0x7F, 0xFA, 0x79, 0xDE, 0x6B, 0xFA, 0x37,
  42241. 0x3A, 0x06, 0x44, 0xB0, 0x0B, 0xF4, 0x1A, 0x03,
  42242. 0x49, 0x92, 0xA7, 0x94, 0xDA, 0x17, 0xC8, 0x88,
  42243. 0x85, 0x23, 0x90, 0x32, 0xC8, 0x51, 0x76, 0x4E,
  42244. 0x3E, 0x4D, 0xBD, 0xE7, 0xF1, 0x2A, 0x16, 0xC5,
  42245. 0xA2, 0x63, 0xE9, 0x64, 0xC1, 0xE7, 0xFD, 0xD3,
  42246. 0xCC, 0xE5, 0x76, 0xDD, 0x6D, 0x56, 0xB1, 0x81,
  42247. 0x82, 0x84, 0x8B, 0x75, 0x63, 0x64, 0x5D, 0x4E,
  42248. 0x42, 0xFF, 0x22, 0x74, 0x2A, 0x99, 0x67, 0x85,
  42249. 0x16, 0x9D, 0x7F, 0x50, 0x3B, 0x48, 0xA7, 0x15,
  42250. 0x8B, 0x3C, 0xBD, 0x29, 0x93, 0x5E, 0xD3, 0x20,
  42251. 0x49, 0xBE, 0xA1, 0xAD, 0x95, 0x3E, 0xF7, 0x07,
  42252. 0x32, 0x7B, 0x77, 0x8B, 0xFD, 0xDD, 0xFC, 0x60,
  42253. 0x51, 0x1D, 0xA1, 0x13, 0xA3, 0x4F, 0x65, 0x57,
  42254. 0x12, 0xE4, 0xE5, 0x9D, 0x6C, 0xCE, 0x40, 0x4E,
  42255. 0x94, 0xAB, 0xA6, 0x1E, 0x81, 0x35, 0x38, 0x8F,
  42256. 0xC2, 0x1C, 0x8E, 0x41, 0x34, 0x4F, 0x32, 0x4B,
  42257. 0x01, 0xAC, 0x8C, 0x06, 0x9F, 0x92, 0x57, 0x5D,
  42258. 0x34, 0xF8, 0x8B, 0xCA, 0x22, 0xCB, 0x30, 0x7E,
  42259. 0x37, 0x07, 0x00, 0x63, 0x32, 0x02, 0x56, 0xB8,
  42260. 0xBA, 0xD6, 0xEB, 0x7A, 0x81, 0xAF, 0xE9, 0xA2,
  42261. 0x54, 0x01, 0x6E, 0x1C, 0x8A, 0x12, 0x50, 0x89,
  42262. 0xAA, 0xA3, 0xED, 0xE8, 0x4E, 0x5B, 0x6C, 0x2E,
  42263. 0xCF, 0xAE, 0xFA, 0xA5, 0x2B, 0x9F, 0x57, 0x09,
  42264. 0x60, 0x2C, 0x06, 0xAE, 0xA4, 0xA0, 0x38, 0x4E,
  42265. 0x9B, 0x09, 0xE5, 0xB8, 0x81, 0x64, 0xB2, 0x74,
  42266. 0xEA, 0x32, 0x65, 0xFB, 0x51, 0x52, 0x39, 0x7D,
  42267. 0xFF, 0x5A, 0x3A, 0x08, 0x61, 0xE2, 0xBC, 0x12,
  42268. 0xD2, 0x10, 0x92, 0x89, 0x72, 0x97, 0x47, 0xE8,
  42269. 0x3F, 0xDF, 0x24, 0x3A, 0x1D, 0x17, 0xB9, 0x83,
  42270. 0x48, 0x37, 0x98, 0x45, 0xA9, 0xE9, 0x55, 0xE2,
  42271. 0xD6, 0xF9, 0x38, 0xDA, 0xA5, 0x91, 0x8E, 0x2A,
  42272. 0x14, 0xF9, 0x7B, 0xA2, 0xBE, 0x50, 0x1C, 0xCC,
  42273. 0xAF, 0xD6, 0x81, 0x91, 0x0F, 0x4A, 0x4F, 0x06,
  42274. 0x71, 0x5C, 0xE8, 0x40, 0x96, 0xF3, 0x7A, 0x91,
  42275. 0xDC, 0xCA, 0x2A, 0x8A, 0x4B, 0xE8, 0xDA, 0x79,
  42276. 0x21, 0xDB, 0xF8, 0xD3, 0xF4, 0xEF, 0xB9, 0x8C,
  42277. 0x6B, 0x4F, 0x94, 0x0E, 0xCE, 0xF8, 0x32, 0xB5,
  42278. 0x49, 0xD0, 0x68, 0x94, 0x7C, 0x3D, 0xFB, 0x58,
  42279. 0x09, 0xCB, 0x7B, 0x06, 0x0A, 0x3A, 0x0E, 0xF3,
  42280. 0xB2, 0x1C, 0x01, 0x64, 0x50, 0x1D, 0xDE, 0xA7,
  42281. 0xC9, 0xE5, 0xE7, 0x89, 0x7C, 0x6B, 0x1C, 0x46,
  42282. 0x34, 0x8B, 0x2C, 0x3E, 0x80, 0x5F, 0x6F, 0x22,
  42283. 0x87, 0xBA, 0x15, 0x8C, 0xF9, 0x25, 0xA7, 0xBA,
  42284. 0x7F, 0x08, 0x25, 0x49, 0x89, 0xC8, 0x7D, 0x24,
  42285. 0x97, 0x9A, 0xD9, 0x86, 0xAA, 0x97, 0xC5, 0x1B,
  42286. 0x01, 0xF4, 0x5D, 0x4A, 0x1F, 0x24, 0x75, 0x29,
  42287. 0x91, 0xF0, 0x42, 0x05, 0xEB, 0x55, 0x1F, 0xD0,
  42288. 0x2D, 0x41, 0x5F, 0x2D, 0xD1, 0xEF, 0xF1, 0x42,
  42289. 0xB0, 0xD7, 0x04, 0x16, 0xC6, 0xD8, 0x15, 0xEB,
  42290. 0x91, 0x73, 0x2B, 0x26, 0x8F, 0xB2, 0x0D, 0x08,
  42291. 0x67, 0x44, 0x2D, 0x71, 0xDE, 0xC0, 0x57, 0xB2,
  42292. 0x86, 0xCD, 0x93, 0x81, 0x1F, 0xF3, 0xF6, 0x46,
  42293. 0xEB, 0xD5, 0x65, 0xD5, 0x1D, 0x09, 0xA4, 0x2D,
  42294. 0x3A, 0xBA, 0xAC, 0x0F, 0x34, 0xCC, 0x81, 0x7B,
  42295. 0x18, 0x93, 0x8E, 0xCC, 0xBB, 0x1F, 0xEF, 0x05,
  42296. 0xBD, 0x3C, 0x2B, 0x49, 0x4F, 0xA5, 0x29, 0xED,
  42297. 0x4C, 0x63, 0x4C, 0x93, 0x25, 0xA4, 0x81, 0x73,
  42298. 0xF2, 0x0F, 0xFA, 0xC3, 0x2D, 0xC1, 0x01, 0xE6,
  42299. 0xEE, 0x03, 0xB2, 0xFC, 0xBE, 0xC2, 0x46, 0x8D,
  42300. 0xBC, 0x8F, 0x76, 0x75, 0x8C, 0x32, 0x15, 0x47,
  42301. 0x4F, 0x7E, 0xF2, 0x40, 0x65, 0xF7, 0x90, 0x60,
  42302. 0xAC, 0xA3, 0xC8, 0xD5, 0xD7, 0x4A, 0xF7, 0x0F,
  42303. 0x48, 0x30, 0x1D, 0xDB, 0x30, 0xC0, 0x5D, 0xB3,
  42304. 0xEF, 0xA7, 0x26, 0xCF, 0x88, 0x55, 0x59, 0x01,
  42305. 0x84, 0x12, 0x82, 0xAA, 0x08, 0xF6, 0x66, 0xA6,
  42306. 0x53, 0x51, 0xA6, 0xA2, 0x4E, 0xED, 0x6B, 0xE2,
  42307. 0x11, 0x77, 0x31, 0x07, 0xE1, 0x85, 0xE1, 0xB4,
  42308. 0x88, 0xA2, 0xE4, 0x91, 0xB6, 0xC1, 0x41, 0x52,
  42309. 0x84, 0x62, 0xA8, 0x64, 0x94, 0xB5, 0x4F, 0xDC,
  42310. 0xCE, 0xCC, 0xB6, 0xAA, 0x21, 0x25, 0x36, 0x86,
  42311. 0x69, 0x3A, 0xE7, 0x98, 0xC9, 0xCE, 0x9E, 0x0B,
  42312. 0xDD, 0xC6, 0xAE, 0x53, 0xD9, 0xB7, 0x06, 0xDC,
  42313. 0x4F, 0x4D, 0x81, 0xB9, 0xC7, 0x3C, 0x46, 0x1E,
  42314. 0xCD, 0x70, 0x35, 0xC5, 0x17, 0x2E, 0xFA, 0xE5,
  42315. 0x60, 0x2C, 0xAF, 0x88, 0xC6, 0x4E, 0x79, 0xE5,
  42316. 0x32, 0x40, 0x30, 0x55, 0x5D, 0xE2, 0x11, 0xF8,
  42317. 0x9F, 0xD4, 0x24, 0xC3, 0x38, 0xC3, 0x88, 0x3C,
  42318. 0x83, 0xCA, 0x94, 0x05, 0xC2, 0xB5, 0xD1, 0x44,
  42319. 0x5F, 0x7C, 0x98, 0xC4, 0x3E, 0xD3, 0xD2, 0xBE,
  42320. 0xCB, 0xE2, 0x5F, 0x5F, 0x3F, 0x54, 0x4C, 0xCC,
  42321. 0x5B, 0x5A, 0xEA, 0xE4, 0x7D, 0xDF, 0x3F, 0xB5,
  42322. 0x64, 0x9F, 0xF5, 0xD6, 0x1E, 0xAA, 0x02, 0xED,
  42323. 0xEB, 0xC7, 0x5C, 0xE4, 0x78, 0xBA, 0x00, 0x42,
  42324. 0x6C, 0xAF, 0x47, 0x4F, 0xA7, 0x9E, 0x5B, 0x08,
  42325. 0x9E, 0xB1, 0xA8, 0x82, 0xF1, 0x53, 0x54, 0x59,
  42326. 0x26, 0x95, 0x95, 0x2B, 0xA0, 0xA8, 0xEE, 0x91,
  42327. 0xE6, 0x49, 0xE3, 0xF2, 0xC3, 0x82, 0x26, 0x4D,
  42328. 0xAA, 0x30, 0xF6, 0xA6, 0xD2, 0x17, 0xF6, 0x12,
  42329. 0x9C, 0x19, 0x39, 0xB6, 0xDC, 0xAC, 0xCD, 0xA5,
  42330. 0xB6, 0x37, 0x32, 0x6E, 0x8A, 0x83, 0x61, 0xC3,
  42331. 0xB5, 0x6F, 0xCF, 0xFC, 0x48, 0x50, 0x36, 0x86,
  42332. 0x58, 0x22, 0xB9, 0xBB, 0x87, 0xB4, 0x35, 0x10,
  42333. 0xBC, 0xDD, 0x55, 0xBC, 0x35, 0x0D, 0xE7, 0xB2,
  42334. 0xAE, 0x90, 0xA2, 0x1E, 0x9E, 0x19, 0x97, 0x8E,
  42335. 0xDA, 0x10, 0xDF, 0x66, 0x76, 0x14, 0xA4, 0x4F,
  42336. 0xE2, 0xA8, 0x4D, 0x16, 0xBE, 0x04, 0x3E, 0xA8,
  42337. 0x77, 0x36, 0x33, 0xEA, 0x6B, 0xAD, 0xF6, 0x57,
  42338. 0x10, 0x05, 0x2F, 0x34, 0x1F, 0x65, 0xCB, 0xE9,
  42339. 0x28, 0xD3, 0x96, 0x2A, 0x5A, 0x2F, 0xE6, 0x4E,
  42340. 0x46, 0xD6, 0xBF, 0xB8, 0xFD, 0x0D, 0x99, 0x78,
  42341. 0xF0, 0x42, 0x3C, 0xBD, 0x19, 0x5F, 0x72, 0xF3,
  42342. 0xCB, 0x19, 0xD7, 0xEF, 0xD9, 0xEB, 0xE3, 0x3C,
  42343. 0xD2, 0xF5, 0x70, 0x9A, 0x57, 0x80, 0x7D, 0xF9,
  42344. 0x44, 0xEC, 0xE5, 0x68, 0xAA, 0xCA, 0x43, 0x36,
  42345. 0x42, 0x20, 0x83, 0xB0, 0x69, 0x7B, 0x6A, 0xA0,
  42346. 0x05, 0x86, 0xE4, 0xBF, 0x7D, 0xD6, 0x73, 0xA3,
  42347. 0xD5, 0x96, 0xB8, 0x61, 0x8A, 0xC3, 0xB4, 0x06,
  42348. 0x17, 0x50, 0xC6, 0xBE, 0x97, 0xCB, 0x53, 0x75,
  42349. 0x3D, 0x02, 0x39, 0x55, 0x56, 0x07, 0x5A, 0x26,
  42350. 0xF1, 0x40, 0xB9, 0x3F, 0x57, 0x7D, 0xAD, 0x50,
  42351. 0x5E, 0x1C, 0xF2, 0xB5, 0x51, 0xA0, 0x4C, 0x98,
  42352. 0xC7, 0xF0, 0x90, 0x18, 0x31, 0xB3, 0xCA, 0x61,
  42353. 0xD7, 0x5D, 0xA7, 0x93, 0xAC, 0x72, 0xA4, 0x4C,
  42354. 0x7A, 0x07, 0xF7, 0xDB, 0xBA, 0xD6, 0x0A, 0x55,
  42355. 0xF4, 0x9C, 0xBD, 0x79, 0xDE, 0xE4, 0x73, 0x9F,
  42356. 0xFD, 0x36, 0x77, 0x8E, 0xBD, 0x08, 0xEB, 0xDB,
  42357. 0x79, 0xEC, 0x07, 0xA1, 0x62, 0x39, 0xC5, 0xB9,
  42358. 0x21, 0x59, 0x9F, 0xEB, 0xFE, 0xA4, 0x6D, 0xDF,
  42359. 0x96, 0x6A, 0xA4, 0xA0, 0x15, 0x12, 0xE6, 0x10,
  42360. 0x94, 0x3F, 0x5D, 0xC5, 0x4B, 0x4C, 0x76, 0xB7,
  42361. 0x64, 0xB3, 0x80, 0xBF, 0x2F, 0x84, 0xED, 0xE3,
  42362. 0x21, 0x24, 0x91, 0x2F, 0x54, 0xF7, 0xB6, 0xE2,
  42363. 0x07, 0xB7, 0x38, 0x1F, 0x67, 0x0F, 0x7A, 0xA0,
  42364. 0xF3, 0xC3, 0xED, 0x10, 0x15, 0x74, 0x03, 0x84,
  42365. 0xDD, 0x61, 0xA9, 0x76, 0x5E, 0xE4, 0x69, 0x6E,
  42366. 0xAC, 0xF8, 0x2E, 0xA4, 0x10, 0x69, 0x18, 0x05,
  42367. 0xCB, 0x68, 0x89, 0x03, 0x53, 0x5D, 0x70, 0x46,
  42368. 0x10, 0x0D, 0xCC, 0x2B, 0xA7, 0xD8, 0x30, 0x2A,
  42369. 0xCB, 0x04, 0x30, 0xD5, 0x06, 0xCC, 0xC1, 0xC0,
  42370. 0xDD, 0xEA, 0x71, 0x11, 0xA7, 0x6F, 0x45, 0xB4,
  42371. 0x54, 0xE2, 0x5C, 0xDD, 0xFB, 0x63, 0x9B, 0x3D,
  42372. 0x66, 0x4C, 0x36, 0xD8, 0x84, 0x35, 0x13, 0xA3,
  42373. 0xFC, 0xAF, 0x9E, 0x60, 0x57, 0xE9, 0xBC, 0x06,
  42374. 0x82, 0x37, 0xFE, 0x24, 0x19, 0xA2, 0xD2, 0xD9,
  42375. 0x0B, 0x4A, 0x1F, 0xC2, 0xA7, 0x1A, 0x14, 0x6D,
  42376. 0x2B, 0xD0, 0x43, 0x64, 0xC7, 0x9B, 0x8E, 0xBA,
  42377. 0x8E, 0x3E, 0x88, 0xCE, 0x11, 0xE9, 0x16, 0xE4,
  42378. 0xA7, 0x52, 0x84, 0x21, 0x32, 0x8C, 0xF5, 0x4F,
  42379. 0xAA, 0xB2, 0xB1, 0x9F, 0x44, 0x46, 0x87, 0x81,
  42380. 0xF8, 0xAB, 0x84, 0xB7, 0xDD, 0x97, 0x2F, 0xF5,
  42381. 0x61, 0x50, 0x71, 0x43, 0x0A, 0x43, 0x74, 0xDA,
  42382. 0xFC, 0xAE, 0x1E, 0x60, 0x44, 0xAA, 0x98, 0xE9,
  42383. 0x85, 0x94, 0x1B, 0xA6, 0xB9, 0xDB, 0x8C, 0x02,
  42384. 0xF5, 0x89, 0x60, 0x3E, 0xEB, 0x8B, 0xE9, 0x0A,
  42385. 0x70, 0xEF, 0xC0, 0x88, 0xD7, 0x95, 0xE6, 0xDA,
  42386. 0x1F, 0x1F, 0x2E, 0x6E, 0xCE, 0xDD, 0x03, 0x1D,
  42387. 0x81, 0x99, 0xE6, 0x59, 0x12, 0xD4, 0x34, 0xD0,
  42388. 0x9B, 0xFB, 0xE5, 0x94, 0x40, 0x6D, 0xC1, 0x15,
  42389. 0x0E, 0x99, 0x35, 0x8C, 0xEA, 0x7F, 0xAD, 0x2E,
  42390. 0x7C, 0x44, 0xC3, 0x8B, 0x6E, 0x0C, 0xEE, 0xAB,
  42391. 0x9B, 0xDE, 0x0D, 0xB9, 0x7B, 0xCF, 0x5A, 0xC9,
  42392. 0x94, 0x10, 0xC9, 0x47, 0x0E, 0x26, 0x6B, 0x8B,
  42393. 0xE4, 0x5F, 0x66, 0x90, 0x83, 0x1F, 0x41, 0x45,
  42394. 0xE2, 0x63, 0x79, 0xDB, 0x80, 0x7C, 0x26, 0xDD,
  42395. 0xF9, 0x1E, 0x30, 0x9D, 0x4F, 0x4A, 0x3E, 0x7E,
  42396. 0xCA, 0xB7, 0x36, 0x2F, 0x15, 0xD2, 0x0E, 0xA4,
  42397. 0x33, 0xB7, 0xE7, 0x0A, 0x7D, 0xDE, 0x74, 0x16,
  42398. 0xCE, 0xA8, 0x71, 0x49, 0x8B, 0x2C, 0xE3, 0xF5,
  42399. 0x8D, 0x29, 0xD8, 0x62, 0x8C, 0x53, 0x18, 0x40,
  42400. 0xF0, 0x22, 0xDD, 0x3B, 0xD2, 0xF3, 0x80, 0x9B,
  42401. 0x11, 0x68, 0xD3, 0x8E, 0x63, 0xC7, 0xF6, 0x93,
  42402. 0x08, 0xA3, 0x1A, 0x2D, 0x4D, 0x5E, 0xEB, 0x97,
  42403. 0x42, 0x39, 0xB3, 0x4A, 0x62, 0xBC, 0x85, 0xE4,
  42404. 0xEC, 0xF9, 0x0C, 0x33, 0x6A, 0x0C, 0x37, 0xBD,
  42405. 0x9E, 0x0E, 0xF4, 0x26, 0x6B, 0x83, 0x5A, 0xC8,
  42406. 0x90, 0x6A, 0x83, 0xCF, 0x0B, 0x35, 0x13, 0x8A,
  42407. 0x65, 0xE5, 0xD9, 0xA6, 0x1F, 0xCC, 0x9B, 0x2D,
  42408. 0x5A, 0x33, 0x7B, 0x8A, 0xBE, 0xF8, 0x8A, 0x7F,
  42409. 0xB3, 0xC0, 0x94, 0x5D, 0x7C, 0xAF, 0x35, 0x61,
  42410. 0x1A, 0xE0, 0xE4, 0x46, 0x93, 0xA5, 0xBC, 0xE0,
  42411. 0xA6, 0xE2, 0xFE, 0xCA, 0xE9, 0xBD, 0xF4, 0xE3,
  42412. 0x56, 0xD6, 0x53, 0x6B, 0x58, 0x1A, 0x18, 0xF0,
  42413. 0x3A, 0x59, 0x16, 0x4E, 0xD5, 0x44, 0x7C, 0x7E,
  42414. 0xC8, 0xBD, 0x99, 0x7B, 0xE9, 0x53, 0xDE, 0xD9,
  42415. 0x32, 0x53, 0x5B, 0x5F, 0x43, 0x8A, 0x04, 0x31,
  42416. 0x9F, 0x5E, 0x0D, 0x8B, 0x0F, 0xEB, 0xC8, 0xDE,
  42417. 0x81, 0x46, 0x65, 0x8E, 0x52, 0xB9, 0x75, 0x9C,
  42418. 0x73, 0x93, 0x5B, 0x12, 0x0D, 0xC9, 0xB8, 0x54,
  42419. 0xF3, 0xC8, 0xF9, 0x4E, 0xC9, 0x33, 0x90, 0x57,
  42420. 0xD7, 0xD7, 0xCD, 0x91, 0xF7, 0xE0, 0xB9, 0x8D,
  42421. 0x84, 0xEC, 0x7B, 0x2F, 0x92, 0x32, 0x8D, 0x73,
  42422. 0x60, 0x18, 0xB0, 0x31, 0x65, 0xA8, 0x74, 0x5F,
  42423. 0x8E, 0x77, 0xEB, 0x80, 0x29, 0xF9, 0x78, 0x26,
  42424. 0x70, 0xCB, 0xD8, 0x6B, 0x43, 0x16, 0xC7, 0xBE,
  42425. 0x4A, 0x88, 0x03, 0x38, 0xBA, 0xCF, 0xB0, 0x15,
  42426. 0x69, 0x9B, 0xF3, 0x0D, 0x3A, 0x4B, 0x05, 0x32,
  42427. 0x54, 0x35, 0xBA, 0x5F, 0xA3, 0xB9, 0xD2, 0xB2,
  42428. 0xFE, 0x0B, 0x51, 0x9C, 0x2C, 0xB2, 0x46, 0xE5,
  42429. 0x3D, 0x1A, 0x34, 0x3D, 0x66, 0x1A, 0x66, 0x14,
  42430. 0x3C, 0x6F, 0x46, 0x8C, 0x55, 0x38, 0x64, 0x5C,
  42431. 0xC2, 0x6D, 0x4E, 0x2A, 0x87, 0x03, 0xEC, 0x9B,
  42432. 0x10, 0xFC, 0x89, 0xBE, 0x6F, 0x85, 0x99, 0x97,
  42433. 0x70, 0x8F, 0x31, 0x19, 0x4F, 0x0D, 0xFE, 0xE9,
  42434. 0x29, 0x98, 0xB2, 0x5E, 0x93, 0xB9, 0x70, 0x70,
  42435. 0xDE, 0x14, 0x40, 0x9D, 0x5B, 0xA4, 0x3D, 0xF8,
  42436. 0x8D, 0x15, 0xC2, 0xFB, 0xA9, 0x7B, 0xDD, 0xE6,
  42437. 0x18, 0xCC, 0x3F, 0xC0, 0x42, 0xF7, 0x74, 0x81,
  42438. 0x84, 0xBA, 0x9E, 0xC9, 0xCB, 0xA1, 0xB2, 0x00,
  42439. 0x68, 0x81, 0xD0, 0x51, 0x42, 0x64, 0x19, 0x8F,
  42440. 0xB6, 0x91, 0xC5, 0xC0, 0x38, 0xE0, 0x49, 0x50,
  42441. 0xCF, 0x69, 0x09, 0x93, 0x77, 0xFE, 0x66, 0xBA,
  42442. 0x64, 0xE2, 0x19, 0x52, 0xA4, 0x45, 0x81, 0x71,
  42443. 0x96, 0x64, 0xF5, 0xD9, 0x23, 0x97, 0xD2, 0x2A,
  42444. 0xA7, 0x03, 0x2B, 0xF5, 0x89, 0xAF, 0x8A, 0xCA,
  42445. 0x48, 0xDF, 0x6D, 0x14, 0xEB, 0x43, 0xCE, 0xF0,
  42446. 0xA9, 0xC8, 0xA8, 0xF9, 0xAD, 0x32, 0x95, 0x25,
  42447. 0xEF, 0x0A, 0xAA, 0x4F, 0x9E, 0x09, 0xC3, 0x51,
  42448. 0x3C, 0xF0, 0x29, 0xF3, 0xDE, 0xFC, 0xBB, 0x41,
  42449. 0x14, 0xFA, 0x0F, 0x66, 0x8D, 0xB4, 0x72, 0x2F,
  42450. 0xCC, 0xD9, 0xC2, 0x07, 0xB6, 0x6F, 0x10, 0x9E,
  42451. 0xD9, 0x5B, 0x45, 0x4B, 0xB6, 0x19, 0x5D, 0x59,
  42452. 0xC4, 0xA6, 0x78, 0xBA, 0x6F, 0x5A, 0x9B, 0x23,
  42453. 0x41, 0x21, 0xAD, 0x05, 0x16, 0xA1, 0xD4, 0x12,
  42454. 0x3D, 0x38, 0x26, 0xD9, 0x2A, 0x61, 0xB3, 0x5D,
  42455. 0xEB, 0x29, 0x5B, 0xAA, 0x2F, 0xE1, 0xB5, 0xEE,
  42456. 0x25, 0x02, 0x1D, 0xAE, 0xF8, 0x57, 0xB5, 0xDF,
  42457. 0x19, 0x2E, 0x17, 0x5E, 0x3A, 0x2A, 0x0D, 0x3F,
  42458. 0x08, 0x2F, 0x21, 0x1C, 0xB5, 0xBD, 0xC2, 0x36,
  42459. 0x27, 0x4F, 0x86, 0xC5, 0xDC, 0x74, 0xC3, 0x9B,
  42460. 0xE9, 0x7C, 0xCF, 0x5F, 0x57, 0x94, 0xEB, 0x64,
  42461. 0xEC, 0x64, 0x55, 0x45, 0x21, 0x0F, 0xC6, 0x67,
  42462. 0xD1, 0xE0, 0x74, 0x0E, 0x66, 0xCB, 0xED, 0xC2,
  42463. 0x06, 0x48, 0xCA, 0x1F, 0xA7, 0x34, 0x14, 0x59,
  42464. 0x6B, 0xA0, 0x89, 0x17, 0xA1, 0x9A, 0x46, 0x3A,
  42465. 0xD3, 0x02, 0x7C, 0x81, 0x83, 0x6B, 0x8F, 0x4F,
  42466. 0x02, 0xB9, 0x9F, 0xC5, 0x08, 0x3F, 0x06, 0xF3,
  42467. 0x4B, 0xD2, 0x30, 0x9C, 0x23, 0x42, 0xAD, 0x88,
  42468. 0xA8, 0x4F, 0xA9, 0x6E, 0x20, 0x7C, 0x01, 0x08,
  42469. 0xF6, 0x82, 0x54, 0x14, 0x94, 0x4F, 0x26, 0x4E,
  42470. 0xD6, 0xC4, 0x66, 0x7C, 0x78, 0x8D, 0x61, 0xA6,
  42471. 0xBC, 0x2C, 0x45, 0x6A, 0xF6, 0x6C, 0x2F, 0x76,
  42472. 0x9E, 0x16, 0x90, 0x17, 0x06, 0x91, 0x2C, 0xC9,
  42473. 0x0D, 0x4B, 0x6C, 0x90, 0xDC, 0xA1, 0x6C, 0xAC,
  42474. 0x8F, 0xFE, 0xD8, 0x39, 0x70, 0x20, 0xE2, 0x97,
  42475. 0x5E, 0x24, 0xFF, 0x4C, 0x80, 0x7C, 0x8A, 0xB7,
  42476. 0x31, 0xC8, 0x1D, 0x36, 0xCA, 0x84, 0xC9, 0x12,
  42477. 0x1A, 0x85, 0x13, 0xE0, 0xC9, 0xD0, 0xF4, 0x1B,
  42478. 0xC6, 0x8F, 0x88, 0xEA, 0xCA, 0xA3, 0x55, 0x99,
  42479. 0xFA, 0xE3, 0xBB, 0xA6, 0xFC, 0xC6, 0x52, 0x8D,
  42480. 0x47, 0xE4, 0x0C, 0x07, 0x64, 0xCF, 0x9C, 0x83,
  42481. 0x83, 0xB3, 0xA4, 0x45, 0x15, 0xE6, 0x1D, 0x92,
  42482. 0xCD, 0xAE, 0xC9, 0xCB, 0x90, 0x82, 0xB5, 0xA0,
  42483. 0xC0, 0x37, 0x94, 0x60, 0xD9, 0x17, 0x9A, 0x7D,
  42484. 0x9D, 0xF2, 0x9E, 0x0B, 0x4B, 0x6A, 0x41, 0x18,
  42485. 0x28, 0x52, 0x15, 0xE8, 0x7B, 0x6F, 0x11, 0x8E,
  42486. 0x97, 0x31, 0xE4, 0x66, 0xFB, 0x3F, 0xEB, 0xD1,
  42487. 0x95, 0xE1, 0x44, 0xFD, 0x20, 0x37, 0xD1, 0x16,
  42488. 0x62, 0x75, 0x79, 0xAC, 0x55, 0xFE, 0xD5, 0xE3,
  42489. 0x25, 0x85, 0xEC, 0x66, 0x38, 0xA0, 0xDF, 0xBE,
  42490. 0x6E, 0xD6, 0xC5, 0x87, 0x6C, 0xF8, 0x11, 0x4C,
  42491. 0x90, 0x2A, 0xEF, 0xA3, 0x63, 0xF4, 0xC9, 0xB7,
  42492. 0x2E, 0x7D, 0x5C, 0x85, 0x2D, 0xCC, 0x1A, 0xF2,
  42493. 0xB8, 0x85, 0x2A, 0x9D, 0x0F, 0x99, 0x59, 0x38,
  42494. 0x86, 0x50, 0x84, 0xCE, 0x52, 0x13, 0xB3, 0x08,
  42495. 0xA9, 0xCB, 0x37, 0xF6, 0x81, 0x96, 0x0D, 0x84,
  42496. 0xEF, 0xE1, 0xDF, 0x51, 0x34, 0xA5, 0x91, 0x5A,
  42497. 0xE5, 0x87, 0x8B, 0x10, 0xDA, 0x0F, 0xD4, 0xD9,
  42498. 0xAC, 0x2A, 0xEF, 0x0C, 0x7E, 0x01, 0xC2, 0xE9,
  42499. 0xE7, 0xC0, 0x17, 0xE7, 0xBA, 0x74, 0x0C, 0xEE,
  42500. 0x1A, 0x89, 0x94, 0x59, 0xBB, 0x75, 0x03, 0x3E,
  42501. 0xEA, 0xF3, 0x19, 0x0D, 0x67, 0x79, 0xED, 0x9E,
  42502. 0xDD, 0x84, 0x6A, 0x74, 0xE3, 0x21, 0x52, 0x8C,
  42503. 0x03, 0x08, 0x4A, 0x5D, 0x30, 0x87, 0x48, 0x39,
  42504. 0x71, 0x8A, 0x53, 0x54, 0x9B, 0x2E, 0xC6, 0xB2,
  42505. 0xB7, 0x30, 0xAA, 0x93, 0x5C, 0xA6, 0xE1, 0xC4,
  42506. 0xFD, 0x8B, 0xE0, 0x35, 0x7D, 0x93, 0xF6, 0x21,
  42507. 0x74, 0xEE, 0xED, 0xF8, 0xDA, 0xB7, 0x75, 0x5B,
  42508. 0x46, 0x65, 0x7E, 0x59, 0xD7, 0xAA, 0x00, 0xB9,
  42509. 0xF2, 0xF8, 0x5E, 0x4C, 0x0F, 0x77, 0xFA, 0x11,
  42510. 0xA5, 0xD6, 0x9A, 0x23, 0xB1, 0xEF, 0x3A, 0x09,
  42511. 0xF2, 0x19, 0xD8, 0x3B, 0x1F, 0x39, 0x1F, 0x84,
  42512. 0x13, 0x18, 0xEE, 0xF3, 0x5A, 0x32, 0x63, 0x67,
  42513. 0xBF, 0xA2, 0xB1, 0x5F, 0xD7, 0x14, 0x03, 0x20,
  42514. 0x92, 0xB9, 0xD0, 0x2B, 0xF6, 0x13, 0xAF, 0xF7,
  42515. 0x69, 0x6F, 0xAD, 0xF1, 0xDE, 0x2C, 0x81, 0x70,
  42516. 0x77, 0xCB, 0x7C, 0x99, 0x67, 0x76, 0xD6, 0x9E,
  42517. 0xC2, 0x41, 0xA2, 0x42, 0x54, 0xDA, 0x2D, 0x13,
  42518. 0x98, 0x76, 0x91, 0xEA, 0xC7, 0xEB, 0xA8, 0xCD,
  42519. 0x8D, 0xCF, 0xB3, 0x94, 0x7B, 0x1D, 0x99, 0xED,
  42520. 0xF9, 0x62, 0xD2, 0x15, 0xB3, 0x18, 0xBB, 0x5F,
  42521. 0x9A, 0xA0, 0x4D, 0x1C, 0x82, 0x62, 0x6A, 0x41,
  42522. 0x73, 0xD0, 0x2D, 0x41, 0x0C, 0x58, 0x6B, 0xCA,
  42523. 0x4E, 0x51, 0xCA, 0x4F, 0x3E, 0x15, 0x1B, 0x54,
  42524. 0xF1, 0x7A, 0x6B, 0xC9, 0x67, 0x76, 0x09, 0xBB,
  42525. 0xAF, 0x6C, 0x30, 0x38, 0xA6, 0x7C, 0xAD, 0xA6,
  42526. 0x6B, 0x4F, 0xDF, 0xB5, 0x10, 0x29, 0xE0, 0x78,
  42527. 0x07, 0xD7, 0x05, 0x96, 0x9D, 0x96, 0xC9, 0xAB,
  42528. 0xFB, 0x71, 0x62, 0xE4, 0x58, 0x10, 0xA1, 0xDC,
  42529. 0x4B, 0x56, 0xDA, 0x14, 0x77, 0xED, 0x90, 0x0A,
  42530. 0x89, 0xCC, 0xAC, 0x29, 0x8E, 0x17, 0x88, 0x42,
  42531. 0x69, 0xC3, 0x9E, 0x8D, 0x7A, 0xB9, 0x66, 0xF3,
  42532. 0x3D, 0xDA, 0xDB, 0xE5, 0x6A, 0x38, 0x4C, 0xA2,
  42533. 0x0A, 0x7B, 0x18, 0x99, 0xEC, 0x18, 0xE2, 0xAE,
  42534. 0x54, 0x70, 0x00, 0xB9, 0x04, 0xE3, 0x4E, 0x46,
  42535. 0x80, 0x1D, 0x85, 0x74, 0xDB, 0x00, 0x84, 0x17,
  42536. 0xBC, 0xFD, 0xD1, 0xA7, 0x4D, 0xC0, 0x18, 0xE5,
  42537. 0x07, 0xB7, 0x6B, 0x0F, 0xA0, 0x86, 0x26, 0x23,
  42538. 0x5B, 0x1C, 0xE2, 0x4B, 0xCF, 0xC3, 0x20, 0xFA,
  42539. 0xE3, 0x55, 0x1C, 0x1C, 0x92, 0x9B, 0x94, 0xC7,
  42540. 0xC4, 0x96, 0x53, 0x41, 0x82, 0x9D, 0x8A, 0x13,
  42541. 0x47, 0xD6, 0xA7, 0x38, 0x58, 0x03, 0xB0, 0x8B,
  42542. 0xCD, 0xA8, 0x4A, 0x27, 0xEA, 0x5E, 0x49, 0xCA,
  42543. 0x1E, 0x60, 0x06, 0xEA, 0x23, 0x2A, 0x53, 0xEE,
  42544. 0x41, 0x7E, 0xC8, 0x81, 0xD3, 0x32, 0x8A, 0x15,
  42545. 0x63, 0x82, 0xA6, 0xB2, 0x93, 0x89, 0x4D, 0xDF,
  42546. 0x9B, 0x36, 0x9C, 0xDE, 0x6B, 0x2F, 0xF5, 0x9C,
  42547. 0xB6, 0xA5, 0x64, 0xE2, 0x1C, 0x92, 0x79, 0xEC,
  42548. 0xA0, 0x31, 0x1F, 0x5D, 0x80, 0xCE, 0x39, 0xB9,
  42549. 0x8B, 0xF9, 0x0D, 0xB3, 0x27, 0xF7, 0x4D, 0x3F,
  42550. 0x76, 0x2D, 0x11, 0x7D, 0xF5, 0xF9, 0x13, 0x20,
  42551. 0x84, 0xFF, 0xB5, 0x55, 0xA5, 0xD1, 0x47, 0x22,
  42552. 0x1A, 0xF8, 0x63, 0xAB, 0xF7, 0x87, 0x15, 0xB7,
  42553. 0x21, 0x94, 0x52, 0x9A, 0x0E, 0x33, 0x4D, 0x4A,
  42554. 0x19, 0x1D, 0x42, 0xA9, 0x9B, 0xEA, 0x52, 0xAD,
  42555. 0xA2, 0xC7, 0xCC, 0x4A, 0x97, 0x74, 0xD5, 0xCB,
  42556. 0x28, 0xD4, 0xED, 0x82, 0xB6, 0x1F, 0x94, 0xE8,
  42557. 0x9F, 0x60, 0xF0, 0xC8, 0xEA, 0x52, 0xDC, 0x07,
  42558. 0x9D, 0x46, 0x58, 0xBF, 0x8C, 0x85, 0x6D, 0x61,
  42559. 0x52, 0xD9, 0x22, 0x51, 0x94, 0x8B, 0x3B, 0xA0,
  42560. 0x14, 0xD8, 0xBA, 0xF3, 0xDC, 0xD3, 0x6B, 0xC7,
  42561. 0x1F, 0x8E, 0x5B, 0x2C, 0xE6, 0xF5, 0x35, 0xB7,
  42562. 0xB9, 0xAE, 0x13, 0xDA, 0x4A, 0x1E, 0xAF, 0xFC,
  42563. 0x25, 0x3B, 0xE4, 0x3A, 0x9F, 0x60, 0x8E, 0xAC,
  42564. 0xE7, 0x33, 0xCF, 0xCE, 0x52, 0xEA, 0x5C, 0xDA,
  42565. 0x83, 0x59, 0xDB, 0x53, 0xFF, 0x3A, 0xF2, 0xCE,
  42566. 0xFE, 0x87, 0x79, 0xBC, 0xC5, 0x3C, 0x24, 0xA4,
  42567. 0xB1, 0x8D, 0x5E, 0x0D, 0x78, 0x1B, 0xEC, 0xF7,
  42568. 0x5B, 0x54, 0x77, 0x47, 0x3A, 0x20, 0x24, 0xAD,
  42569. 0x56, 0xC5, 0x4A, 0x7F, 0x99, 0x0E, 0xF6, 0xB1,
  42570. 0xDF, 0xAC, 0x50, 0x10, 0x88, 0x50, 0x9D, 0x3A,
  42571. 0x37, 0xF1, 0xC8, 0xD5, 0xC2, 0x64, 0x87, 0xE4,
  42572. 0x20, 0xB7, 0xF4, 0x35, 0x8E, 0x92, 0x69, 0x76,
  42573. 0x1F, 0xF1, 0xFA, 0x3A, 0xFC, 0xBE, 0xCA, 0xEB,
  42574. 0x68, 0xF5, 0xDD, 0xDE, 0x3A, 0xA8, 0xFD, 0x07,
  42575. 0x8C, 0xC4, 0x22, 0x4C, 0xEA, 0x67, 0x13, 0x2D,
  42576. 0x7E, 0xBF, 0x5D, 0x23, 0x2E, 0x43, 0xBA, 0xDD,
  42577. 0x21, 0x8C, 0x0B, 0x4D, 0xBE, 0x1E, 0x16, 0x52,
  42578. 0x98, 0x66, 0xB9, 0xAB, 0x93, 0x58, 0x85, 0xAC,
  42579. 0xB4, 0x15, 0xFB, 0xB1, 0xEE, 0xE6, 0x94, 0x08,
  42580. 0xA5, 0x21, 0xB4, 0x62, 0xEC, 0x59, 0xCD, 0x0D,
  42581. 0x3C, 0x54, 0x96, 0xD9, 0x85, 0xAE, 0xB0, 0xCE,
  42582. 0x37, 0x4F, 0x67, 0x72, 0xA4, 0xE6, 0x39, 0x3A,
  42583. 0x4E, 0xF0, 0x07, 0x43, 0x80, 0x90, 0xA8, 0xA9,
  42584. 0xE5, 0x2D, 0x2F, 0x55, 0x66, 0x6D, 0x70, 0xF0,
  42585. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42586. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42587. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  42588. 0x08, 0x0E, 0x12, 0x19, 0x20
  42589. };
  42590. #endif
  42591. #ifndef WOLFSSL_NO_ML_DSA_87
  42592. static const byte pk_87[] = {
  42593. 0x2D, 0x1E, 0x6B, 0xED, 0x84, 0x52, 0xEB, 0xF1,
  42594. 0x26, 0xED, 0xE7, 0x0C, 0xA0, 0xA2, 0xB5, 0x0D,
  42595. 0x03, 0x34, 0x2D, 0x5B, 0x13, 0xB2, 0xAE, 0x21,
  42596. 0x0F, 0x45, 0x62, 0xA3, 0xBF, 0x67, 0x0C, 0xB1,
  42597. 0x5C, 0xE9, 0x25, 0xFD, 0x22, 0xF2, 0x62, 0x42,
  42598. 0xBA, 0xE3, 0x10, 0xB3, 0xAA, 0x41, 0x3B, 0x6E,
  42599. 0x78, 0xD4, 0x42, 0xD9, 0x35, 0xD1, 0x72, 0x8A,
  42600. 0x32, 0x48, 0xCC, 0x20, 0x5C, 0xCD, 0x8D, 0x3F,
  42601. 0xD8, 0x34, 0x95, 0x55, 0x20, 0xCD, 0xFB, 0x2C,
  42602. 0x73, 0xE9, 0x0E, 0x60, 0x8B, 0x2C, 0x3F, 0xA8,
  42603. 0xB7, 0xD1, 0x79, 0xFD, 0xDC, 0xC8, 0x81, 0x11,
  42604. 0xC9, 0xE8, 0x41, 0x71, 0xE9, 0x70, 0x9B, 0x53,
  42605. 0x59, 0x33, 0xE4, 0x92, 0xB6, 0x81, 0x9C, 0x6A,
  42606. 0x92, 0xED, 0xA2, 0x5A, 0xC4, 0x07, 0x77, 0x1A,
  42607. 0x8F, 0xED, 0xB4, 0xE7, 0x11, 0xFB, 0x89, 0xEB,
  42608. 0x7B, 0xDF, 0xCC, 0xEA, 0xC5, 0x3B, 0x4E, 0xF4,
  42609. 0x6B, 0x6F, 0xBE, 0xE1, 0x32, 0xA9, 0xD7, 0xAD,
  42610. 0xB4, 0x36, 0xE7, 0x4A, 0x6D, 0x67, 0x11, 0x83,
  42611. 0xAF, 0x31, 0x1A, 0x7A, 0x31, 0x42, 0x9B, 0x01,
  42612. 0x21, 0x17, 0x52, 0x75, 0x85, 0xF7, 0x92, 0x0F,
  42613. 0x34, 0x8A, 0x69, 0x11, 0x88, 0x5A, 0x02, 0x08,
  42614. 0xB6, 0x6D, 0xE3, 0x07, 0x93, 0xB1, 0x3F, 0xE1,
  42615. 0xD5, 0x7B, 0xD9, 0x51, 0xF7, 0xAA, 0xC0, 0x34,
  42616. 0x9A, 0x78, 0x5D, 0x26, 0xDB, 0xF1, 0xF0, 0xA9,
  42617. 0x1E, 0x5C, 0x9F, 0x4F, 0xA7, 0x43, 0x5C, 0x44,
  42618. 0xA9, 0x43, 0xF1, 0x38, 0x11, 0x45, 0xED, 0xEB,
  42619. 0x1C, 0x8A, 0x05, 0xEE, 0xFF, 0xAB, 0x20, 0x2C,
  42620. 0xF6, 0x2C, 0xEE, 0x77, 0x42, 0x36, 0x3E, 0xE6,
  42621. 0x9D, 0x8E, 0x45, 0x0F, 0xF6, 0x7C, 0x39, 0x62,
  42622. 0xD6, 0xFF, 0x97, 0xBC, 0x3D, 0x02, 0xD6, 0xDF,
  42623. 0x4A, 0x35, 0xDA, 0x3F, 0x89, 0xA4, 0x88, 0x33,
  42624. 0xCD, 0xF2, 0x90, 0xF0, 0xE9, 0x37, 0x2F, 0x65,
  42625. 0xA5, 0x88, 0x65, 0xFD, 0x40, 0x44, 0xAD, 0x09,
  42626. 0x09, 0x92, 0xAA, 0x15, 0x9E, 0xEE, 0xF7, 0x2B,
  42627. 0x0D, 0xA7, 0xCB, 0x3A, 0x5E, 0x0A, 0xED, 0xD6,
  42628. 0x7D, 0x82, 0x8B, 0xBA, 0xCF, 0xE5, 0x9E, 0xE4,
  42629. 0x62, 0xAB, 0x69, 0x6B, 0xBA, 0xD0, 0xE5, 0xA9,
  42630. 0xBB, 0x1F, 0x5A, 0x51, 0xE0, 0xFA, 0x5D, 0xD4,
  42631. 0x4D, 0x8E, 0xC0, 0xDC, 0x43, 0x06, 0xDF, 0x23,
  42632. 0x67, 0xB2, 0x4A, 0xA2, 0xFB, 0x75, 0x2F, 0x82,
  42633. 0xD8, 0x44, 0xE4, 0xC0, 0xCE, 0x15, 0x9E, 0x3F,
  42634. 0xD6, 0xB4, 0x70, 0x5F, 0x3B, 0xD0, 0x56, 0x3E,
  42635. 0x0A, 0x7A, 0x4B, 0x94, 0xBF, 0xBA, 0x01, 0x2B,
  42636. 0x9C, 0x8B, 0x91, 0x35, 0xF2, 0xDB, 0x4C, 0x8C,
  42637. 0x8D, 0xD6, 0xEE, 0xC8, 0x65, 0x8D, 0xF3, 0x05,
  42638. 0x59, 0xBE, 0x3A, 0x17, 0xA7, 0x72, 0x10, 0x56,
  42639. 0x14, 0xEF, 0xB8, 0xC1, 0xBE, 0x18, 0x11, 0x0B,
  42640. 0xE6, 0x70, 0xF8, 0x39, 0xA5, 0x72, 0x7D, 0xF9,
  42641. 0x47, 0xFB, 0xAC, 0xFD, 0x1F, 0xC3, 0x71, 0x33,
  42642. 0x58, 0x44, 0x15, 0xD3, 0x7C, 0x93, 0x2E, 0x70,
  42643. 0x92, 0xFA, 0xBB, 0xF2, 0xD0, 0x9D, 0x25, 0xC4,
  42644. 0xCF, 0x4A, 0xB8, 0xEC, 0xBE, 0x5D, 0x8B, 0x7F,
  42645. 0xA4, 0x7C, 0xAB, 0xAD, 0xE7, 0x1E, 0x93, 0x83,
  42646. 0x92, 0x86, 0x1E, 0x8D, 0x15, 0xA4, 0x1C, 0x5B,
  42647. 0x42, 0x25, 0xDA, 0x3D, 0x16, 0xD3, 0x93, 0xF2,
  42648. 0x85, 0x50, 0x86, 0x0A, 0x86, 0x35, 0x6B, 0x14,
  42649. 0xAB, 0x5F, 0x22, 0xD0, 0xCF, 0x03, 0x7C, 0xEB,
  42650. 0xB4, 0x0E, 0xAC, 0x87, 0xA2, 0x41, 0x42, 0xA0,
  42651. 0x21, 0x93, 0x00, 0xB6, 0x47, 0x6F, 0x96, 0xD0,
  42652. 0x41, 0xD1, 0xC3, 0x0E, 0x3C, 0x52, 0xD2, 0x45,
  42653. 0xAB, 0x6A, 0xE7, 0xA1, 0xE5, 0xFD, 0x73, 0xC5,
  42654. 0x82, 0x9D, 0x60, 0x62, 0x8B, 0x6D, 0x87, 0xFC,
  42655. 0x88, 0x9C, 0x3E, 0xEF, 0xAE, 0xAA, 0xB6, 0x1C,
  42656. 0x18, 0xEE, 0xD7, 0x51, 0x1A, 0x96, 0xC4, 0x93,
  42657. 0x25, 0x05, 0xD3, 0x83, 0x3D, 0xD8, 0x33, 0x16,
  42658. 0x14, 0x44, 0x88, 0xE2, 0xAF, 0xC4, 0xEC, 0x59,
  42659. 0x18, 0x12, 0xB9, 0x99, 0xC1, 0xC9, 0x5F, 0x31,
  42660. 0x79, 0x00, 0x03, 0xF6, 0xC9, 0x55, 0x14, 0xAA,
  42661. 0x29, 0x08, 0x78, 0x24, 0xAF, 0x1D, 0x99, 0x12,
  42662. 0x36, 0xD9, 0x4A, 0xD9, 0x50, 0xEF, 0x66, 0xFC,
  42663. 0x7F, 0xF4, 0xBC, 0x3B, 0xA0, 0xF6, 0xFD, 0xF2,
  42664. 0x62, 0xCA, 0xA5, 0x9D, 0x2B, 0x55, 0xB8, 0x33,
  42665. 0xBC, 0xA6, 0x7A, 0xA5, 0x1E, 0xE1, 0x14, 0x5F,
  42666. 0x94, 0xE2, 0xDC, 0xF0, 0x5B, 0xBD, 0x43, 0x07,
  42667. 0xD8, 0xB1, 0xE0, 0x81, 0x3F, 0x84, 0x54, 0x90,
  42668. 0xBF, 0x23, 0x59, 0x92, 0x3C, 0xA5, 0x98, 0xAB,
  42669. 0x7D, 0x99, 0xD2, 0xF0, 0xED, 0x8E, 0x0B, 0xC9,
  42670. 0x9F, 0xAF, 0xB0, 0x13, 0xED, 0xC7, 0xDD, 0xB8,
  42671. 0x61, 0x72, 0x07, 0x3D, 0xCC, 0x35, 0x73, 0xA0,
  42672. 0xCF, 0x0C, 0xD9, 0x7E, 0x93, 0xDC, 0x63, 0xB8,
  42673. 0x82, 0xEC, 0xF4, 0x30, 0xCE, 0x43, 0x92, 0xEA,
  42674. 0x5E, 0xD8, 0xC8, 0xA1, 0xEC, 0x79, 0xDC, 0xAE,
  42675. 0x64, 0xD4, 0x33, 0xEB, 0x53, 0x8C, 0xFC, 0x49,
  42676. 0x79, 0xBF, 0x7A, 0x28, 0x65, 0x1E, 0x8C, 0xD5,
  42677. 0x21, 0xB0, 0x8E, 0xCA, 0xAD, 0xF8, 0x96, 0x9A,
  42678. 0x98, 0x10, 0x00, 0x35, 0x6D, 0x58, 0x9A, 0xEF,
  42679. 0x84, 0x84, 0x86, 0x72, 0xBA, 0xCD, 0x38, 0x66,
  42680. 0x96, 0x9B, 0xC2, 0x83, 0xB0, 0x65, 0xC1, 0xAB,
  42681. 0xCF, 0x63, 0x8C, 0x2D, 0xC3, 0x42, 0xB2, 0x7D,
  42682. 0xF6, 0xB8, 0xF0, 0x3D, 0x26, 0x21, 0x8F, 0xAE,
  42683. 0x4E, 0x96, 0xF2, 0x55, 0x66, 0xBC, 0x6F, 0xED,
  42684. 0xE7, 0x19, 0xD3, 0x8D, 0xC0, 0xCD, 0x55, 0x20,
  42685. 0x5F, 0x10, 0xCA, 0xDA, 0x09, 0xED, 0x91, 0x4A,
  42686. 0x43, 0x33, 0xD3, 0x82, 0x11, 0x5C, 0x2F, 0x5D,
  42687. 0xEC, 0xCD, 0x54, 0xF9, 0x6C, 0xE4, 0xE5, 0xF2,
  42688. 0x68, 0xBC, 0xE9, 0x27, 0xB2, 0x1D, 0xCA, 0xB5,
  42689. 0xCD, 0x04, 0x01, 0x1E, 0x92, 0xF5, 0xF6, 0x01,
  42690. 0x86, 0x2B, 0x20, 0x20, 0x9B, 0xB0, 0xF9, 0x56,
  42691. 0xD9, 0x33, 0xD5, 0x0A, 0xEC, 0x1B, 0xF4, 0xCE,
  42692. 0xD2, 0xB2, 0xC2, 0xD4, 0x3F, 0x9A, 0x25, 0x76,
  42693. 0x8E, 0x29, 0x87, 0x52, 0x64, 0x86, 0x4A, 0xA5,
  42694. 0x7B, 0x5A, 0x91, 0x72, 0x6E, 0xBE, 0x6D, 0x73,
  42695. 0x0A, 0x8D, 0x89, 0x53, 0x82, 0x33, 0x70, 0x44,
  42696. 0x20, 0xBE, 0xE0, 0xB0, 0x1B, 0x76, 0x30, 0x43,
  42697. 0xA5, 0x5B, 0x8F, 0xAB, 0x7E, 0xB8, 0x61, 0x5F,
  42698. 0x43, 0x70, 0x1B, 0x1A, 0x71, 0x61, 0x56, 0xF9,
  42699. 0x13, 0x31, 0x2A, 0x64, 0x33, 0x14, 0x00, 0x98,
  42700. 0x72, 0xEC, 0x32, 0x88, 0x09, 0xFB, 0x64, 0x46,
  42701. 0x3D, 0x56, 0x02, 0xD9, 0x76, 0xD3, 0xAA, 0x90,
  42702. 0x0F, 0xBD, 0xF0, 0xF9, 0x96, 0x43, 0x7B, 0x62,
  42703. 0x19, 0x26, 0x22, 0x6A, 0x93, 0x91, 0xEC, 0x07,
  42704. 0x34, 0xF5, 0x22, 0x32, 0xB3, 0x65, 0x66, 0xE0,
  42705. 0x6B, 0x11, 0x7F, 0x97, 0x9F, 0x1A, 0x89, 0x46,
  42706. 0xCE, 0x8F, 0xBD, 0xFD, 0x2F, 0xCC, 0x3D, 0xBF,
  42707. 0xF2, 0x83, 0xA4, 0x30, 0xE1, 0x02, 0x72, 0xF8,
  42708. 0x74, 0xE6, 0x21, 0x96, 0x77, 0xE1, 0x57, 0x8A,
  42709. 0xF7, 0x9E, 0xB3, 0x31, 0xAF, 0xD8, 0xC5, 0xD7,
  42710. 0x20, 0xDC, 0xFD, 0xCF, 0x79, 0x06, 0x0F, 0x1F,
  42711. 0xE5, 0x84, 0x3D, 0x0B, 0x9C, 0xB3, 0xC7, 0xAB,
  42712. 0xB8, 0xF1, 0xC0, 0xD0, 0xB5, 0xC7, 0x01, 0xE2,
  42713. 0x0E, 0x3B, 0xAF, 0x7E, 0xAC, 0x44, 0x5A, 0x75,
  42714. 0x50, 0x0A, 0x76, 0x1C, 0x13, 0xDB, 0x25, 0xD4,
  42715. 0x0D, 0x19, 0x75, 0x4C, 0x02, 0xD9, 0xF3, 0xDF,
  42716. 0x6D, 0xBB, 0xCF, 0x47, 0xA6, 0xAE, 0xF6, 0xD1,
  42717. 0xFB, 0xF4, 0xB4, 0x55, 0xD3, 0xA5, 0x87, 0xA1,
  42718. 0x55, 0xFB, 0xBF, 0xCD, 0xF6, 0xA1, 0x64, 0x57,
  42719. 0x12, 0x75, 0x9A, 0x11, 0xA3, 0xCE, 0x42, 0x70,
  42720. 0x84, 0x54, 0x93, 0x12, 0xE1, 0x3A, 0x0F, 0xFA,
  42721. 0xCA, 0xF2, 0x25, 0x91, 0xF1, 0x4D, 0x8F, 0x84,
  42722. 0xB1, 0xB5, 0x35, 0xAC, 0xE9, 0x81, 0x77, 0x34,
  42723. 0x4D, 0x6F, 0x5D, 0x14, 0x9D, 0xB9, 0xE1, 0xF0,
  42724. 0x3F, 0x3C, 0xE7, 0xAD, 0x48, 0xE6, 0x8C, 0x51,
  42725. 0x86, 0xF4, 0x4A, 0xB4, 0xD0, 0x98, 0xEC, 0x3A,
  42726. 0x4E, 0xAB, 0x58, 0x2F, 0x08, 0x9E, 0x5A, 0x9D,
  42727. 0x45, 0x30, 0xB0, 0x85, 0xDF, 0x4A, 0xE7, 0x92,
  42728. 0xC6, 0xC8, 0x18, 0x93, 0x08, 0xCE, 0x9A, 0x8C,
  42729. 0xE2, 0x91, 0x8D, 0x91, 0x57, 0x7B, 0x37, 0xC8,
  42730. 0x80, 0xA2, 0x31, 0x10, 0x0D, 0x4E, 0xEF, 0x51,
  42731. 0x07, 0x94, 0x8E, 0xF8, 0x3C, 0x3C, 0x2E, 0xD5,
  42732. 0x03, 0x26, 0xB8, 0x72, 0x7F, 0xB9, 0xBC, 0xD7,
  42733. 0x95, 0xC4, 0x31, 0x08, 0xEC, 0x6F, 0xEE, 0x11,
  42734. 0xAF, 0xC0, 0xA2, 0xEC, 0xD7, 0xC8, 0x0B, 0xBE,
  42735. 0x15, 0xAE, 0xC9, 0x17, 0xBE, 0x37, 0xE2, 0x40,
  42736. 0x83, 0x65, 0xDE, 0xB3, 0x4E, 0xB4, 0x15, 0xB3,
  42737. 0x5C, 0x14, 0xF6, 0x5F, 0xA9, 0x1F, 0x70, 0xB5,
  42738. 0x23, 0x93, 0x78, 0xB9, 0x47, 0xF9, 0x1D, 0x2B,
  42739. 0x1E, 0x8D, 0xB1, 0x25, 0x7E, 0xE5, 0x85, 0x3C,
  42740. 0x16, 0x9F, 0xD0, 0xC2, 0x67, 0x8B, 0x0D, 0xD2,
  42741. 0x72, 0x4E, 0x74, 0x30, 0xE1, 0xAF, 0xB8, 0x66,
  42742. 0xCB, 0x53, 0xDF, 0xC4, 0xFB, 0xA5, 0x6D, 0x03,
  42743. 0xF2, 0xAE, 0xEE, 0x90, 0xFE, 0xD7, 0x30, 0xAF,
  42744. 0x33, 0x98, 0x09, 0xEB, 0x75, 0xC7, 0x3E, 0xC8,
  42745. 0x2F, 0xE7, 0x22, 0x5F, 0x2F, 0x0A, 0xBD, 0xA4,
  42746. 0x22, 0x88, 0x28, 0x19, 0x35, 0x83, 0x12, 0x86,
  42747. 0xEE, 0x72, 0xB4, 0x26, 0x89, 0x2F, 0xC7, 0x11,
  42748. 0x6E, 0xDD, 0x14, 0x98, 0x22, 0xE7, 0x73, 0x3E,
  42749. 0xFA, 0x46, 0x75, 0xF9, 0x40, 0xC1, 0x84, 0x22,
  42750. 0xBC, 0x75, 0x36, 0xC7, 0x82, 0xD3, 0xAE, 0x6E,
  42751. 0x0D, 0xBF, 0x6F, 0xC3, 0x4B, 0x67, 0x49, 0x19,
  42752. 0xF3, 0x4B, 0x12, 0xF2, 0x83, 0xFD, 0x39, 0x56,
  42753. 0x44, 0x05, 0x3A, 0x24, 0x6A, 0x35, 0x69, 0x12,
  42754. 0xCF, 0xE4, 0x93, 0xFE, 0x26, 0xCC, 0xD6, 0x01,
  42755. 0xA0, 0x4A, 0x84, 0xA8, 0x1D, 0x85, 0xE6, 0x83,
  42756. 0x0F, 0x3C, 0xE6, 0x6D, 0xD2, 0xCB, 0xB1, 0x14,
  42757. 0x8C, 0xEC, 0x10, 0xB3, 0x63, 0x4B, 0x9C, 0xF5,
  42758. 0x11, 0xE0, 0xF9, 0x86, 0x6F, 0xA7, 0xC0, 0x3B,
  42759. 0x9D, 0x25, 0xD7, 0x54, 0xCA, 0x40, 0x4D, 0x26,
  42760. 0xBA, 0x71, 0x8E, 0x25, 0xF5, 0xA7, 0xE3, 0x9B,
  42761. 0x25, 0x20, 0x7F, 0x29, 0x05, 0xB6, 0x27, 0x14,
  42762. 0x17, 0x67, 0x26, 0x10, 0xAD, 0xA3, 0x06, 0x03,
  42763. 0xFE, 0x82, 0x85, 0x5D, 0x01, 0x04, 0x4D, 0xE0,
  42764. 0x64, 0x38, 0x38, 0x5E, 0x83, 0x1E, 0x21, 0x9A,
  42765. 0x39, 0x02, 0xF8, 0xF9, 0x69, 0x85, 0x52, 0xE5,
  42766. 0xEC, 0x6A, 0xAC, 0x96, 0x86, 0xA7, 0x88, 0x69,
  42767. 0xB5, 0xB5, 0x7E, 0x03, 0x1D, 0xA9, 0x68, 0xCA,
  42768. 0x45, 0x0F, 0xF9, 0x14, 0xD6, 0x7B, 0xCF, 0x9C,
  42769. 0x03, 0x6F, 0xD1, 0xD9, 0x6F, 0x01, 0x3D, 0xF8,
  42770. 0xF3, 0x11, 0xF3, 0x29, 0x17, 0x90, 0xE8, 0x9B,
  42771. 0xED, 0x58, 0x9B, 0xF0, 0xBC, 0xC7, 0xBA, 0xF4,
  42772. 0x60, 0xC8, 0xAA, 0x30, 0xB4, 0x2F, 0x22, 0x8F,
  42773. 0xD3, 0xAC, 0x18, 0xC2, 0xB7, 0xC4, 0x7B, 0x31,
  42774. 0x9E, 0x0F, 0x7E, 0x9D, 0xBF, 0xD4, 0x63, 0xC2,
  42775. 0x8B, 0x1B, 0x58, 0x50, 0x33, 0x53, 0x6D, 0x79,
  42776. 0xBB, 0xF8, 0x0D, 0x91, 0x33, 0xD9, 0x07, 0xE7,
  42777. 0xB0, 0x81, 0xD4, 0xB4, 0x47, 0x61, 0x93, 0xF0,
  42778. 0xFB, 0x68, 0xBC, 0x1B, 0x41, 0xC2, 0xF5, 0x43,
  42779. 0x30, 0x7E, 0x76, 0xF9, 0xB1, 0xA3, 0xD6, 0xD4,
  42780. 0x26, 0xEA, 0x77, 0x75, 0x12, 0x7A, 0xC8, 0x30,
  42781. 0x9B, 0xCF, 0x45, 0xBE, 0x74, 0x7D, 0x8A, 0x8B,
  42782. 0xEC, 0xED, 0x11, 0xE6, 0xA1, 0xD1, 0xB8, 0xF1,
  42783. 0x90, 0xAD, 0x6D, 0x6A, 0xC6, 0x54, 0xE9, 0xDB,
  42784. 0xAD, 0x4C, 0x97, 0x39, 0xC8, 0xD8, 0x44, 0xA9,
  42785. 0x1A, 0x37, 0x16, 0x7E, 0x68, 0x45, 0x0C, 0xBB,
  42786. 0x10, 0xF4, 0xAE, 0x8E, 0x2B, 0x69, 0xFA, 0x95,
  42787. 0x3E, 0xA5, 0xC9, 0x91, 0xD3, 0xF1, 0xA3, 0x89,
  42788. 0x3F, 0x90, 0x86, 0x93, 0x1B, 0xF1, 0xA0, 0x89,
  42789. 0xC7, 0xF2, 0x23, 0x57, 0xD4, 0x8E, 0x2F, 0xD5,
  42790. 0x71, 0xCD, 0x36, 0xF1, 0x90, 0xB3, 0x98, 0x3E,
  42791. 0x19, 0xEA, 0xC8, 0x0F, 0x12, 0x9D, 0xBF, 0x58,
  42792. 0xED, 0xDC, 0x6B, 0x9A, 0x79, 0x84, 0xFC, 0xF0,
  42793. 0x4C, 0xC3, 0xB4, 0x0D, 0xB8, 0x7A, 0x8D, 0xAD,
  42794. 0x75, 0x40, 0xD5, 0xD5, 0xDE, 0xC8, 0xCA, 0x39,
  42795. 0x3E, 0x45, 0xE4, 0xBC, 0xF4, 0x33, 0xEA, 0x64,
  42796. 0xE1, 0x5E, 0x94, 0x42, 0x91, 0xAB, 0xBC, 0x42,
  42797. 0x2A, 0xB3, 0xD0, 0x60, 0x23, 0xCE, 0x57, 0x8E,
  42798. 0xFF, 0xAD, 0xA2, 0x2B, 0x64, 0xD9, 0x94, 0xA0,
  42799. 0x80, 0x0F, 0x8E, 0x50, 0x17, 0x08, 0x1D, 0x16,
  42800. 0xCF, 0x51, 0xD0, 0xB9, 0x28, 0xB6, 0x59, 0xEF,
  42801. 0x78, 0xCC, 0xC9, 0x96, 0xF9, 0xCA, 0x87, 0x7A,
  42802. 0xEE, 0xD9, 0x15, 0x5E, 0xDF, 0x5D, 0xBC, 0xC2,
  42803. 0x58, 0xE6, 0x04, 0xEE, 0x17, 0xDC, 0xB3, 0xF9,
  42804. 0x90, 0xF9, 0x88, 0x32, 0x9E, 0xA1, 0xDB, 0x1C,
  42805. 0x38, 0x56, 0x53, 0x90, 0x30, 0x69, 0x2E, 0x52,
  42806. 0x00, 0x2C, 0xF3, 0x0F, 0xD5, 0x80, 0x2E, 0x02,
  42807. 0x5B, 0x99, 0xBF, 0xCD, 0x11, 0x12, 0x64, 0x5B,
  42808. 0x56, 0xC6, 0x0A, 0xE6, 0x38, 0xE7, 0x4D, 0x21,
  42809. 0xE5, 0x98, 0x78, 0x9D, 0xE6, 0xCB, 0x60, 0xB4,
  42810. 0x2E, 0xE4, 0x98, 0x56, 0xCB, 0xAD, 0xE6, 0xDD,
  42811. 0x53, 0xF4, 0xC5, 0x67, 0xA2, 0x9F, 0xA0, 0x5C,
  42812. 0x7C, 0xFB, 0x24, 0x5A, 0xA7, 0x72, 0xD0, 0xE7,
  42813. 0x63, 0xF2, 0x5D, 0xBF, 0xD8, 0xE9, 0xF1, 0x6B,
  42814. 0xB4, 0x29, 0xA6, 0x28, 0xE6, 0x93, 0xD3, 0x87,
  42815. 0xB6, 0xD9, 0x3C, 0x39, 0x8D, 0xEA, 0x28, 0xC0,
  42816. 0x96, 0x3D, 0xF5, 0xC2, 0x3C, 0x29, 0xF2, 0x80,
  42817. 0x21, 0x8A, 0x03, 0x9D, 0x64, 0xF8, 0xBA, 0x81,
  42818. 0xC1, 0xDD, 0xA2, 0x88, 0x2A, 0x84, 0x2E, 0x3C,
  42819. 0xB5, 0x03, 0x95, 0xED, 0xAA, 0x6E, 0xE2, 0x6F,
  42820. 0x5E, 0x99, 0x3C, 0x63, 0xEE, 0xB8, 0x4F, 0x66,
  42821. 0x32, 0x77, 0x42, 0x23, 0x36, 0x29, 0x89, 0xB0,
  42822. 0xED, 0x5F, 0xF2, 0x5A, 0x65, 0x66, 0x3F, 0xD2,
  42823. 0x8B, 0x48, 0x68, 0x65, 0xDC, 0xE0, 0xB0, 0xC2,
  42824. 0x72, 0x73, 0xF1, 0xA4, 0xC6, 0x56, 0x2C, 0x5D,
  42825. 0xD8, 0xC6, 0x5C, 0x41, 0xCE, 0x30, 0x89, 0x59,
  42826. 0xA9, 0xD6, 0x45, 0x96, 0xD0, 0x8E, 0x7B, 0x25,
  42827. 0xE0, 0x13, 0xFB, 0xFE, 0x7C, 0xEA, 0xF3, 0x67,
  42828. 0x0D, 0xB2, 0x9A, 0x21, 0x3C, 0xCE, 0x99, 0x75,
  42829. 0xA9, 0x13, 0xCE, 0xF4, 0x23, 0x6E, 0x64, 0x00,
  42830. 0x30, 0x87, 0x70, 0x9C, 0xAD, 0x61, 0x81, 0x71,
  42831. 0x0E, 0x95, 0x19, 0x26, 0xCA, 0x55, 0x29, 0x71,
  42832. 0x99, 0xA6, 0x08, 0xAE, 0x54, 0x58, 0x75, 0xCD,
  42833. 0xC3, 0x8F, 0xE3, 0x83, 0xC1, 0x45, 0x62, 0xB4,
  42834. 0x8D, 0xCA, 0x66, 0x02, 0xEA, 0x34, 0x05, 0x5D,
  42835. 0x98, 0x3F, 0x38, 0xE6, 0x1C, 0xCE, 0x53, 0x1A,
  42836. 0xD9, 0x3F, 0x58, 0xEC, 0x16, 0x28, 0x45, 0xF5,
  42837. 0x38, 0xCE, 0x48, 0x43, 0x87, 0x1D, 0x3C, 0x4A,
  42838. 0xDF, 0x05, 0xF3, 0x5E, 0x29, 0x7E, 0xA6, 0x2E,
  42839. 0xFC, 0xDD, 0x5E, 0xF9, 0x40, 0x1B, 0xA0, 0x42,
  42840. 0xA2, 0x35, 0x15, 0x0A, 0x09, 0xD9, 0x47, 0x4A,
  42841. 0x3F, 0xB0, 0x3A, 0xAA, 0x19, 0xE7, 0xE3, 0x7A,
  42842. 0x22, 0x8D, 0x5F, 0x5B, 0x07, 0x41, 0x4C, 0x3D,
  42843. 0xA2, 0xAD, 0x2E, 0x5C, 0x75, 0xEC, 0xF0, 0x4C,
  42844. 0x11, 0x2B, 0x90, 0x76, 0x9E, 0x19, 0x96, 0x0E,
  42845. 0x97, 0x5E, 0x8D, 0x19, 0x17, 0xB3, 0xBF, 0xDA,
  42846. 0x84, 0xFD, 0xC6, 0xD2, 0x32, 0x6F, 0xB8, 0xA3,
  42847. 0xB0, 0x0F, 0x95, 0xD9, 0xC5, 0x26, 0x50, 0x11,
  42848. 0x15, 0x72, 0xBE, 0xC2, 0x1B, 0x12, 0x12, 0x7C,
  42849. 0xA5, 0x70, 0xD8, 0xA9, 0x8A, 0xB9, 0x77, 0xEB,
  42850. 0xD8, 0xD7, 0x9A, 0x59, 0x37, 0x5E, 0xE1, 0x4F,
  42851. 0x64, 0xB5, 0xB0, 0x4F, 0xD9, 0x69, 0xFE, 0xB0,
  42852. 0x3D, 0x0A, 0xF7, 0x34, 0x89, 0xE3, 0xBA, 0xEF,
  42853. 0xE7, 0xC7, 0xBC, 0x8D, 0xC7, 0xE8, 0x54, 0x83,
  42854. 0xEE, 0x62, 0xF0, 0x23, 0x98, 0x58, 0x0F, 0x83,
  42855. 0xB9, 0x6D, 0xD8, 0x44, 0x77, 0xB9, 0xC4, 0x8F,
  42856. 0x0B, 0xB3, 0x9F, 0x54, 0x06, 0xA3, 0x70, 0x36,
  42857. 0xD6, 0xF3, 0x6E, 0x2B, 0x1B, 0x6B, 0x53, 0xFE,
  42858. 0x6F, 0xF6, 0x1C, 0x32, 0x7B, 0x29, 0xD4, 0xE0,
  42859. 0x5D, 0xD2, 0xB8, 0x11, 0x74, 0xC6, 0x0B, 0x59,
  42860. 0xC7, 0x9C, 0xB1, 0x97, 0x6B, 0xC0, 0x6E, 0x7A,
  42861. 0xC3, 0x4D, 0xF3, 0xE3, 0x8F, 0x7D, 0x2C, 0x1C,
  42862. 0x0E, 0x31, 0x51, 0xB7, 0x14, 0x7A, 0xB8, 0x31,
  42863. 0x77, 0x47, 0x70, 0x14, 0x3B, 0x92, 0x7B, 0x5F,
  42864. 0xEC, 0x5D, 0xF7, 0x76, 0xC1, 0xD7, 0x2D, 0xB6,
  42865. 0xBC, 0x99, 0x81, 0xD6, 0x58, 0x67, 0x71, 0x3C,
  42866. 0xF2, 0x97, 0xC8, 0xB0, 0xF1, 0xE9, 0x8D, 0x0E,
  42867. 0x16, 0xF0, 0xCC, 0x22, 0x7A, 0x39, 0xE4, 0x7E,
  42868. 0x50, 0xBA, 0x01, 0x16, 0x15, 0x6D, 0x5B, 0x54,
  42869. 0x67, 0x53, 0x66, 0x04, 0xBE, 0x05, 0xCC, 0x2E,
  42870. 0xF4, 0x0A, 0xBC, 0xE8, 0x52, 0xF1, 0x5D, 0xFA,
  42871. 0x2C, 0xAC, 0xF8, 0x6A, 0x78, 0x9E, 0x5B, 0x7B,
  42872. 0x0E, 0x5B, 0xB4, 0xB7, 0x77, 0xCD, 0x7C, 0xC9,
  42873. 0xF6, 0x54, 0x77, 0x9B, 0x10, 0x2F, 0x78, 0xB5,
  42874. 0xAA, 0x4B, 0x94, 0xC3, 0xB4, 0xFD, 0xE5, 0x5F,
  42875. 0xA7, 0xF7, 0xBF, 0x54, 0xAC, 0x22, 0x5E, 0x1F,
  42876. 0x26, 0x16, 0x5B, 0x65, 0xF1, 0x6D, 0x03, 0x21,
  42877. 0x66, 0x9F, 0xD9, 0xF6, 0xE4, 0x7F, 0xCA, 0x1D,
  42878. 0xD3, 0x47, 0x09, 0x6D, 0xF5, 0xDD, 0xA8, 0x64,
  42879. 0x66, 0xA5, 0x7C, 0x5B, 0x06, 0x8D, 0x9C, 0x67,
  42880. 0xB7, 0x32, 0x03, 0x66, 0xEA, 0x19, 0xC8, 0x99,
  42881. 0x3F, 0xF9, 0x0B, 0xD8, 0xFB, 0x06, 0x93, 0xFB,
  42882. 0xA3, 0x70, 0xE6, 0x6D, 0x2B, 0x20, 0x3B, 0x99,
  42883. 0x70, 0x11, 0xB0, 0xD1, 0x5B, 0x94, 0xE2, 0x8B,
  42884. 0xAA, 0x2E, 0xBF, 0x01, 0x77, 0x4F, 0x7A, 0xE7,
  42885. 0x8F, 0x84, 0xED, 0xBD, 0xAD, 0x9F, 0x65, 0xA4,
  42886. 0x50, 0x42, 0x7A, 0x47, 0x74, 0xC6, 0x0C, 0xC8,
  42887. 0x9A, 0x02, 0x0B, 0x37, 0xDA, 0x21, 0xC7, 0x91,
  42888. 0xDA, 0xC8, 0xF7, 0xA7, 0x45, 0x7E, 0x30, 0xD0,
  42889. 0x8B, 0x01, 0x37, 0x51, 0x60, 0x03, 0x9C, 0x30,
  42890. 0x1B, 0x60, 0x51, 0xA9, 0x65, 0xE8, 0xA7, 0xCC,
  42891. 0xA2, 0xAE, 0xF9, 0x3B, 0xD5, 0x2F, 0x82, 0xC0,
  42892. 0x20, 0xBE, 0xCE, 0x90, 0xA1, 0x29, 0x02, 0x4E,
  42893. 0xFE, 0xA4, 0xB2, 0xFA, 0x21, 0x27, 0x0F, 0x8E,
  42894. 0xB5, 0xED, 0x6A, 0xAA, 0xE5, 0x59, 0x29, 0xAA,
  42895. 0xC5, 0x99, 0xA5, 0x77, 0x97, 0x29, 0x57, 0x66,
  42896. 0x0C, 0xC4, 0x7A, 0xC4, 0xE3, 0xCE, 0x77, 0x2B,
  42897. 0xBF, 0x10, 0x05, 0x2D, 0xE7, 0xED, 0xB1, 0xB8,
  42898. 0xA4, 0x49, 0x41, 0xF8, 0x84, 0xC9, 0xF8, 0xBE,
  42899. 0x13, 0x17, 0x46, 0x69, 0x94, 0x56, 0x29, 0xF4,
  42900. 0x6D, 0xE2, 0x46, 0x74, 0x44, 0xF3, 0x10, 0x6A,
  42901. 0x73, 0xFA, 0x27, 0x9C, 0xF0, 0x2A, 0x80, 0x0A,
  42902. 0x04, 0x7E, 0x20, 0xBD, 0x4D, 0x82, 0x0B, 0x38,
  42903. 0x9C, 0x3B, 0xB6, 0xA8, 0x68, 0xA5, 0x38, 0x4C,
  42904. 0xF5, 0x72, 0x4C, 0x20, 0x4C, 0xEF, 0xB1, 0xA6,
  42905. 0xA1, 0xBE, 0xB9, 0x72, 0x3E, 0x36, 0xDD, 0xDD,
  42906. 0xD9, 0xC7, 0x07, 0xC8, 0xF6, 0x3E, 0x8B, 0xC2,
  42907. 0x66, 0x83, 0xCC, 0x8B, 0x43, 0xC7, 0xDF, 0xDA,
  42908. 0xA4, 0x08, 0xAC, 0x4D, 0xD2, 0xBA, 0x9A, 0xEC,
  42909. 0xBC, 0x3B, 0x6D, 0xDA, 0xED, 0xCE, 0x09, 0x4A,
  42910. 0xAB, 0x58, 0xFF, 0x73, 0x2B, 0x19, 0x66, 0x38,
  42911. 0xD8, 0xB8, 0xEF, 0xC4, 0x28, 0xBB, 0xA9, 0x61,
  42912. 0x57, 0x93, 0xC4, 0xDD, 0x9F, 0x00, 0xF9, 0x0D,
  42913. 0x62, 0xC6, 0x76, 0xD1, 0x27, 0xA0, 0xE1, 0x8C,
  42914. 0x14, 0xC6, 0xEE, 0x9C, 0x99, 0x05, 0x10, 0xB0,
  42915. 0x54, 0xAD, 0xB4, 0xB4, 0x17, 0x0A, 0xC7, 0x12,
  42916. 0x7F, 0x93, 0x17, 0x5C, 0x1E, 0xB2, 0x25, 0x12
  42917. };
  42918. static const byte msg_87[] = {
  42919. 0x14, 0x42, 0x63, 0x34, 0x94, 0x09, 0x60, 0x77,
  42920. 0x3B, 0xFF, 0x65, 0xF0, 0x8D, 0x1D, 0xE4, 0x89,
  42921. 0xC4, 0xC3, 0xED, 0x36
  42922. };
  42923. static const byte sig_87[] = {
  42924. 0x13, 0xE8, 0x99, 0xEE, 0xDC, 0xCC, 0x0F, 0xBA,
  42925. 0x62, 0x91, 0x44, 0xE4, 0xAC, 0x06, 0x79, 0x06,
  42926. 0xB5, 0x32, 0x6B, 0x8F, 0x9A, 0x6C, 0xCB, 0xAB,
  42927. 0xE1, 0x44, 0x4A, 0xDD, 0x46, 0x45, 0x16, 0x0D,
  42928. 0x22, 0x57, 0x82, 0x87, 0x10, 0xD1, 0xEE, 0x10,
  42929. 0x60, 0x21, 0xB5, 0x64, 0x1E, 0x78, 0x81, 0x55,
  42930. 0x75, 0xD4, 0xF0, 0x95, 0xD0, 0x15, 0xD8, 0x46,
  42931. 0x5C, 0x92, 0xD2, 0xDD, 0xF4, 0xAB, 0xDF, 0xBE,
  42932. 0xB1, 0x1E, 0xE5, 0xE0, 0x70, 0xE6, 0xDA, 0x52,
  42933. 0xE5, 0x48, 0xDC, 0x04, 0xFD, 0xEF, 0x54, 0x72,
  42934. 0xE7, 0xE5, 0xF1, 0x82, 0x10, 0xAA, 0xCB, 0xA0,
  42935. 0x4F, 0x4F, 0x18, 0xAE, 0x66, 0x86, 0xB9, 0xAF,
  42936. 0x96, 0x57, 0xE3, 0x8E, 0x3B, 0x9B, 0xDD, 0xB4,
  42937. 0xAA, 0x84, 0xE6, 0x7B, 0x4D, 0x81, 0x92, 0xD0,
  42938. 0x03, 0x87, 0x3D, 0xD3, 0xEE, 0xE7, 0x47, 0x00,
  42939. 0xFB, 0xD8, 0x1E, 0x38, 0x1C, 0x21, 0x98, 0xB7,
  42940. 0xCC, 0xC1, 0x37, 0xC1, 0x71, 0xB2, 0x2F, 0x93,
  42941. 0x53, 0x41, 0x9C, 0x48, 0xC1, 0x4B, 0x8D, 0x63,
  42942. 0x0F, 0x99, 0x63, 0x40, 0x27, 0x5F, 0x6E, 0x60,
  42943. 0x4B, 0x95, 0xC4, 0x35, 0x20, 0x8A, 0xED, 0x2B,
  42944. 0xCA, 0x1B, 0x41, 0x9F, 0x83, 0x63, 0xF0, 0x95,
  42945. 0x0E, 0x24, 0x0D, 0x6F, 0x9E, 0xAB, 0x11, 0x8E,
  42946. 0x4B, 0xD3, 0xDA, 0x0E, 0xC3, 0xA2, 0xBE, 0x26,
  42947. 0xA8, 0xA0, 0x98, 0x57, 0x71, 0x3C, 0x36, 0xDD,
  42948. 0x69, 0xC3, 0x4E, 0xDD, 0x2C, 0x61, 0x9E, 0x88,
  42949. 0x26, 0x70, 0x71, 0xCF, 0x9E, 0xE5, 0xA6, 0x0C,
  42950. 0xA3, 0x14, 0x2D, 0xF1, 0x63, 0xF0, 0x1D, 0x8D,
  42951. 0x79, 0x6A, 0xC8, 0x50, 0xCF, 0xF3, 0x66, 0x60,
  42952. 0x78, 0xB3, 0x18, 0xFB, 0x5B, 0xD1, 0x73, 0x60,
  42953. 0xC8, 0x76, 0xC9, 0xC9, 0x0D, 0x8A, 0x7F, 0x41,
  42954. 0x2C, 0x8A, 0x31, 0x61, 0x6B, 0xE7, 0xA3, 0x74,
  42955. 0x58, 0x71, 0x54, 0x84, 0x86, 0x71, 0x5C, 0x94,
  42956. 0x26, 0x3A, 0x17, 0xB3, 0x6C, 0xA4, 0x99, 0x25,
  42957. 0x45, 0x0C, 0x57, 0x8A, 0xD9, 0xD4, 0xB1, 0xC2,
  42958. 0x00, 0x43, 0xF4, 0x5E, 0x84, 0x31, 0x99, 0x4F,
  42959. 0xA6, 0xD2, 0x6A, 0x14, 0x1B, 0xAD, 0x9E, 0x49,
  42960. 0x6E, 0x00, 0x9E, 0x91, 0x46, 0x16, 0xCA, 0x57,
  42961. 0x0C, 0x09, 0xF6, 0x38, 0xD0, 0x62, 0xBE, 0xC6,
  42962. 0x87, 0x33, 0x3A, 0xC7, 0x28, 0x38, 0x34, 0x53,
  42963. 0x7E, 0xFB, 0x60, 0x42, 0xF3, 0x7D, 0x83, 0xF7,
  42964. 0x29, 0x5D, 0xEA, 0x30, 0xD5, 0x00, 0x90, 0xB6,
  42965. 0x38, 0x4C, 0x17, 0x29, 0xEF, 0x17, 0xA0, 0xD5,
  42966. 0x87, 0x50, 0xC0, 0x03, 0x75, 0x14, 0xE5, 0xE1,
  42967. 0x22, 0x78, 0x53, 0xBC, 0x5A, 0xA3, 0x1E, 0x95,
  42968. 0xBE, 0xEC, 0x37, 0xB1, 0x51, 0x82, 0x69, 0x26,
  42969. 0x2E, 0xA3, 0x5A, 0xDA, 0x4F, 0xDA, 0x77, 0x62,
  42970. 0x7E, 0xED, 0xDA, 0xAF, 0x57, 0x97, 0x1B, 0xA3,
  42971. 0x6D, 0x46, 0x7B, 0x19, 0xA9, 0x0B, 0x99, 0x1C,
  42972. 0xD2, 0x55, 0xDB, 0x79, 0xB0, 0x15, 0x48, 0x86,
  42973. 0x52, 0x30, 0x31, 0xD6, 0xC5, 0xB1, 0xAE, 0x8F,
  42974. 0xCF, 0x9A, 0x43, 0x10, 0xBB, 0xC8, 0x19, 0x74,
  42975. 0x84, 0xB2, 0x92, 0x3B, 0xFE, 0x0B, 0x12, 0x15,
  42976. 0xA1, 0xC4, 0xD8, 0xC6, 0x83, 0x90, 0x89, 0x8A,
  42977. 0xD5, 0x3E, 0x33, 0x69, 0xB7, 0x05, 0x3F, 0xB1,
  42978. 0x8B, 0x0D, 0x87, 0x40, 0x70, 0x90, 0x2A, 0x5D,
  42979. 0x3B, 0x3D, 0x91, 0xD8, 0x1D, 0x4D, 0xF1, 0x08,
  42980. 0x7E, 0xF7, 0xDC, 0x05, 0x84, 0xEB, 0xDC, 0x63,
  42981. 0xD7, 0xBA, 0x3C, 0x0D, 0x31, 0xF8, 0x6D, 0xA6,
  42982. 0xC0, 0xFD, 0x08, 0x11, 0x5C, 0x53, 0xF6, 0xAE,
  42983. 0xFE, 0xC0, 0x82, 0x9A, 0x68, 0xD2, 0xA3, 0x44,
  42984. 0x2E, 0xEE, 0x47, 0x36, 0x70, 0x2D, 0x66, 0x81,
  42985. 0x0D, 0x62, 0x30, 0x8A, 0x8C, 0xC8, 0x2A, 0xA6,
  42986. 0x21, 0x82, 0xF5, 0x98, 0xF4, 0x4E, 0x25, 0x37,
  42987. 0x11, 0xB5, 0xD6, 0x07, 0x88, 0xBD, 0x0D, 0x69,
  42988. 0x0E, 0xF9, 0x8F, 0x9A, 0xD5, 0x93, 0xE0, 0x3C,
  42989. 0xEF, 0x38, 0xB9, 0xC9, 0x77, 0x98, 0x3F, 0x69,
  42990. 0x11, 0xBA, 0x1A, 0xB9, 0xF7, 0x35, 0xE9, 0x28,
  42991. 0xCD, 0xA3, 0x8C, 0x03, 0xE6, 0xAD, 0x83, 0x62,
  42992. 0xF4, 0x60, 0xAE, 0x4C, 0xD0, 0xF4, 0x6E, 0x00,
  42993. 0xEE, 0xEC, 0x74, 0xB6, 0x12, 0x34, 0x98, 0xAB,
  42994. 0x31, 0xE7, 0xA7, 0x9D, 0x33, 0x4D, 0x72, 0xA7,
  42995. 0xA7, 0xEE, 0xF3, 0xB5, 0x51, 0xE7, 0x8D, 0x31,
  42996. 0xBC, 0x2C, 0xAF, 0xFB, 0x13, 0x9C, 0xAC, 0xA4,
  42997. 0xD7, 0x9C, 0x8B, 0xBD, 0x52, 0xBD, 0x78, 0xF4,
  42998. 0x90, 0x65, 0x09, 0xBE, 0x42, 0xE7, 0x76, 0x3A,
  42999. 0xE6, 0xAC, 0xB8, 0x98, 0x28, 0x5E, 0xC9, 0x32,
  43000. 0x3E, 0x68, 0x67, 0x6A, 0x8C, 0xC7, 0x4A, 0x58,
  43001. 0xC8, 0xDA, 0x8B, 0xE9, 0x11, 0xED, 0x6F, 0x51,
  43002. 0x3B, 0x66, 0x08, 0x70, 0x73, 0x10, 0xFB, 0x45,
  43003. 0xCB, 0xD9, 0x7D, 0x5F, 0xF0, 0xD2, 0xAB, 0xA3,
  43004. 0x6F, 0xCE, 0xF7, 0x3D, 0x46, 0xCB, 0x7F, 0x01,
  43005. 0xC2, 0xCF, 0xE3, 0x8E, 0x68, 0xE8, 0x4F, 0x4A,
  43006. 0x30, 0x19, 0x16, 0xD2, 0xF5, 0x10, 0xD8, 0x2B,
  43007. 0x49, 0x69, 0xBE, 0x7A, 0x0E, 0x9C, 0xC6, 0x0E,
  43008. 0xFF, 0x5C, 0x0A, 0x87, 0x17, 0xB8, 0x22, 0x83,
  43009. 0x8C, 0x77, 0xAF, 0x42, 0x06, 0xB1, 0x25, 0x45,
  43010. 0x08, 0x9B, 0xB2, 0xDD, 0x6A, 0x3F, 0xF0, 0x12,
  43011. 0xC8, 0x64, 0x15, 0xBB, 0xA0, 0x4F, 0xD7, 0xD4,
  43012. 0xEC, 0x70, 0x7A, 0xF3, 0xB1, 0x7F, 0x25, 0x57,
  43013. 0x47, 0x66, 0xF1, 0xE9, 0x27, 0x38, 0xE0, 0x62,
  43014. 0x10, 0xF4, 0x8A, 0x5E, 0xF2, 0x55, 0x0E, 0xBD,
  43015. 0xF8, 0x5A, 0x5C, 0xA3, 0x44, 0x97, 0xCF, 0x1D,
  43016. 0x4D, 0x3A, 0x75, 0x86, 0x48, 0xEC, 0x41, 0x17,
  43017. 0x24, 0x43, 0x83, 0x5E, 0x50, 0x91, 0xBE, 0x8F,
  43018. 0x04, 0x78, 0x23, 0xD9, 0x62, 0x0C, 0x2A, 0xD5,
  43019. 0x1C, 0x96, 0x11, 0xAA, 0xEE, 0x39, 0xB2, 0x1E,
  43020. 0x6D, 0x6A, 0xEC, 0x87, 0x0C, 0x89, 0x15, 0xE2,
  43021. 0x66, 0x47, 0x6A, 0x50, 0xEE, 0xCA, 0x59, 0x96,
  43022. 0x22, 0xF7, 0x09, 0x1A, 0x34, 0xC2, 0x3F, 0x14,
  43023. 0xB4, 0x04, 0x29, 0xD9, 0x5E, 0x3E, 0xF9, 0x8F,
  43024. 0xED, 0x3E, 0x74, 0x94, 0x37, 0xF0, 0x4B, 0xB4,
  43025. 0xA3, 0x37, 0x52, 0x2E, 0x68, 0x09, 0xFC, 0x10,
  43026. 0x45, 0x03, 0xE2, 0x53, 0xB4, 0x1C, 0x4F, 0x03,
  43027. 0x01, 0xAF, 0x46, 0x7F, 0x74, 0xD3, 0x31, 0x25,
  43028. 0xFA, 0x83, 0xEF, 0x71, 0x24, 0x45, 0xA1, 0x71,
  43029. 0xFA, 0x40, 0xEB, 0xF4, 0xE6, 0x55, 0x3E, 0x45,
  43030. 0x4A, 0xFE, 0x25, 0x68, 0x02, 0x1D, 0x2B, 0x2A,
  43031. 0x19, 0x8D, 0xEC, 0x9B, 0xF7, 0x20, 0xF9, 0xD7,
  43032. 0x2F, 0x81, 0x52, 0x0B, 0xE8, 0x74, 0x66, 0xAF,
  43033. 0x70, 0xD0, 0x0E, 0x0E, 0x86, 0x0F, 0xF9, 0xAB,
  43034. 0xD0, 0x39, 0x78, 0xC3, 0xE4, 0x29, 0xB5, 0xAA,
  43035. 0x17, 0xB9, 0x7F, 0x9A, 0xE9, 0x34, 0x48, 0x85,
  43036. 0x3D, 0x6E, 0xFD, 0x16, 0x8A, 0x30, 0xC6, 0xCB,
  43037. 0xE8, 0xDE, 0x2D, 0x28, 0x8D, 0x9A, 0x24, 0xEA,
  43038. 0x5D, 0x2A, 0x58, 0x23, 0x33, 0x2B, 0x84, 0xFD,
  43039. 0x2C, 0xE7, 0x93, 0xA2, 0x2B, 0xEC, 0x43, 0x98,
  43040. 0x48, 0xD4, 0xE6, 0x0F, 0x3B, 0xB9, 0xC7, 0x5D,
  43041. 0x7E, 0xB0, 0x87, 0x1E, 0x80, 0x3D, 0x61, 0xB0,
  43042. 0x7E, 0x74, 0x9E, 0xD7, 0x60, 0x72, 0xB2, 0x7C,
  43043. 0x87, 0xB6, 0x9D, 0x6C, 0x01, 0x42, 0x61, 0xF6,
  43044. 0x47, 0xAF, 0xA8, 0x8C, 0x4F, 0x1E, 0xC5, 0x5A,
  43045. 0x75, 0xA5, 0x0F, 0xB4, 0xC7, 0x9D, 0x2C, 0x94,
  43046. 0xC0, 0x50, 0x3D, 0xB2, 0x0D, 0xFD, 0xF7, 0x1F,
  43047. 0x62, 0x88, 0x74, 0x18, 0x8C, 0xDD, 0x73, 0x85,
  43048. 0xC0, 0x33, 0x81, 0xDA, 0xBB, 0x85, 0x4D, 0x4A,
  43049. 0xA9, 0xF4, 0x7B, 0x66, 0x43, 0x8C, 0x43, 0xFF,
  43050. 0x53, 0xEF, 0x5E, 0x78, 0xAB, 0x45, 0x0B, 0x45,
  43051. 0x01, 0x91, 0x27, 0x8A, 0xF6, 0xE2, 0x6A, 0x7B,
  43052. 0x5E, 0x64, 0x61, 0xF5, 0x77, 0xF9, 0x85, 0x2F,
  43053. 0x81, 0xC9, 0x02, 0x03, 0xC7, 0x13, 0xF5, 0xB1,
  43054. 0xF6, 0xC3, 0xEF, 0x55, 0x8C, 0x90, 0x32, 0x51,
  43055. 0x6D, 0x8D, 0x62, 0xFD, 0x5E, 0x24, 0xE4, 0xF0,
  43056. 0xF5, 0x07, 0x18, 0xF5, 0x6B, 0x5A, 0x59, 0xA0,
  43057. 0x09, 0xD5, 0x93, 0x8D, 0xAD, 0x55, 0x91, 0xF6,
  43058. 0x1F, 0x4C, 0x65, 0x9A, 0x76, 0x05, 0x26, 0xEF,
  43059. 0x41, 0x20, 0x2F, 0xA7, 0xE5, 0xF6, 0xC7, 0xD5,
  43060. 0xE0, 0xB0, 0xC0, 0xC4, 0x3B, 0x52, 0x4B, 0x66,
  43061. 0x71, 0x2C, 0x5A, 0x7C, 0x53, 0xC8, 0x4C, 0x50,
  43062. 0xB8, 0x3E, 0xB9, 0xC9, 0x8D, 0x2F, 0xD0, 0x84,
  43063. 0xC9, 0xC5, 0xF2, 0x1F, 0xEE, 0x77, 0x42, 0xE6,
  43064. 0xEF, 0xC8, 0xCB, 0xBE, 0x57, 0x18, 0xB7, 0x0C,
  43065. 0x06, 0x2D, 0x82, 0xE2, 0xF9, 0x86, 0xF3, 0x8D,
  43066. 0xF1, 0xE7, 0x15, 0x89, 0xDC, 0x79, 0x87, 0x24,
  43067. 0x35, 0x62, 0xA2, 0x31, 0x9D, 0x7C, 0x00, 0xB2,
  43068. 0x6E, 0x53, 0x1E, 0x93, 0xC3, 0x84, 0x44, 0x61,
  43069. 0x8C, 0xE7, 0x58, 0x73, 0x4F, 0xDE, 0xCF, 0xD0,
  43070. 0xC6, 0x85, 0x37, 0x28, 0xC6, 0x10, 0x00, 0x78,
  43071. 0x4E, 0xDF, 0xFE, 0xD7, 0xB3, 0x30, 0x86, 0xE1,
  43072. 0x68, 0xD6, 0xCB, 0x63, 0xE3, 0xDA, 0xCA, 0xF3,
  43073. 0x55, 0x2F, 0x88, 0x5B, 0x47, 0x82, 0x62, 0xDE,
  43074. 0x5E, 0x1E, 0x63, 0xCE, 0x7A, 0x4C, 0x66, 0x95,
  43075. 0xD1, 0x19, 0x38, 0x35, 0xE4, 0x5A, 0x67, 0x91,
  43076. 0x8C, 0x42, 0xD3, 0x9B, 0xF8, 0x80, 0x38, 0x53,
  43077. 0x30, 0x31, 0x0F, 0x2C, 0x7B, 0xF9, 0x1E, 0x6C,
  43078. 0x3E, 0x29, 0xB7, 0x81, 0xD0, 0x98, 0x70, 0xC2,
  43079. 0x6D, 0x76, 0xBD, 0x8A, 0xE2, 0x09, 0xC4, 0x2B,
  43080. 0xC7, 0x43, 0x2D, 0xBB, 0x4C, 0x16, 0x52, 0x63,
  43081. 0x57, 0xA5, 0x63, 0x4E, 0xEC, 0xDE, 0x93, 0xC5,
  43082. 0x1D, 0xD4, 0xD6, 0xF0, 0x06, 0x5B, 0x2E, 0xC5,
  43083. 0x7A, 0xD3, 0xB5, 0x82, 0x66, 0x53, 0x95, 0x97,
  43084. 0xC8, 0xF4, 0x2B, 0x55, 0x27, 0x1D, 0x6F, 0x90,
  43085. 0xE9, 0x86, 0xF6, 0x82, 0x8D, 0x95, 0x9E, 0xE8,
  43086. 0x00, 0xDB, 0xEB, 0xCF, 0x48, 0x23, 0x6B, 0xA3,
  43087. 0xDE, 0x25, 0x27, 0xE0, 0xEC, 0xA4, 0xA3, 0xC2,
  43088. 0xA3, 0x4B, 0xBC, 0xDD, 0x6C, 0xBB, 0x3A, 0x9C,
  43089. 0x96, 0xDC, 0x3B, 0xE1, 0x10, 0xD3, 0x49, 0x94,
  43090. 0x66, 0xE2, 0x85, 0x7F, 0xBA, 0x98, 0x12, 0x3A,
  43091. 0x6D, 0xBA, 0x90, 0x14, 0x87, 0x7E, 0x24, 0xEA,
  43092. 0xDC, 0xCA, 0x40, 0xF8, 0xAE, 0x94, 0xB2, 0xFE,
  43093. 0xD2, 0x36, 0xCB, 0xE5, 0xBC, 0xA9, 0xDF, 0xE0,
  43094. 0xCB, 0xA9, 0xA0, 0xF8, 0x62, 0x41, 0x33, 0x18,
  43095. 0x59, 0xF9, 0xD6, 0xC0, 0x87, 0xB2, 0x76, 0xDE,
  43096. 0xC9, 0x35, 0x6F, 0x1F, 0xEF, 0x69, 0xB3, 0x59,
  43097. 0xF9, 0xFB, 0x38, 0x4A, 0x84, 0x02, 0x2D, 0xEC,
  43098. 0xB7, 0x01, 0x08, 0xDA, 0xC8, 0xE9, 0x3B, 0xB6,
  43099. 0xC3, 0x00, 0xC0, 0x34, 0x5F, 0xC6, 0x40, 0xC0,
  43100. 0x06, 0xEA, 0xEB, 0xC1, 0x51, 0x13, 0x81, 0x2F,
  43101. 0xB3, 0x7D, 0xD9, 0x6E, 0x2A, 0x06, 0xA4, 0x63,
  43102. 0xAF, 0xCE, 0x66, 0xC5, 0x9F, 0x8D, 0x71, 0x4A,
  43103. 0xA1, 0xFF, 0x49, 0x4F, 0x08, 0x6F, 0xB9, 0xEA,
  43104. 0xDA, 0x18, 0x45, 0x63, 0xCA, 0x9D, 0x88, 0x08,
  43105. 0xB1, 0x6C, 0x19, 0xA8, 0x24, 0xAD, 0x85, 0x7D,
  43106. 0xDE, 0x51, 0xE5, 0x08, 0xB7, 0x04, 0x12, 0x35,
  43107. 0xF3, 0x00, 0xED, 0x2C, 0x79, 0x9C, 0x18, 0x23,
  43108. 0x05, 0x38, 0x95, 0x76, 0xCF, 0x39, 0x3C, 0xAE,
  43109. 0xB0, 0xD3, 0xBA, 0x3E, 0x4E, 0xE4, 0xB5, 0x77,
  43110. 0xA3, 0xE3, 0x7B, 0x27, 0x5F, 0xD8, 0x05, 0x19,
  43111. 0x42, 0xAE, 0x91, 0x54, 0xE5, 0xBD, 0x7C, 0x35,
  43112. 0xE0, 0xF8, 0x95, 0x52, 0x3A, 0x29, 0xB0, 0xE6,
  43113. 0xB7, 0xAE, 0x20, 0xBE, 0x21, 0xDF, 0xF5, 0x67,
  43114. 0xEC, 0x82, 0x52, 0xFF, 0x5B, 0xD0, 0xAA, 0x14,
  43115. 0x50, 0x15, 0xE1, 0x1C, 0x6A, 0x1B, 0x94, 0x1B,
  43116. 0xCC, 0x76, 0x01, 0xBF, 0x03, 0x94, 0x42, 0xF2,
  43117. 0x00, 0x61, 0x96, 0x58, 0xD9, 0xD0, 0x40, 0x21,
  43118. 0xFA, 0xCE, 0x6B, 0xAB, 0x5D, 0x49, 0xD8, 0xD7,
  43119. 0xBC, 0x9A, 0x66, 0xC2, 0xBA, 0x3F, 0xDC, 0x49,
  43120. 0x0D, 0xA5, 0x5C, 0xB4, 0x67, 0x08, 0x38, 0xEB,
  43121. 0x2D, 0x07, 0x24, 0x5B, 0xB1, 0x22, 0x7B, 0x02,
  43122. 0x4A, 0x8A, 0x53, 0x38, 0xE9, 0x42, 0x8E, 0xA5,
  43123. 0x57, 0x41, 0xD6, 0x71, 0xA7, 0x9D, 0x6A, 0x14,
  43124. 0xD2, 0x7D, 0x13, 0xFB, 0x59, 0xD0, 0xDA, 0xE5,
  43125. 0x23, 0x9E, 0x1B, 0xC4, 0x21, 0x87, 0xBB, 0x78,
  43126. 0xE0, 0x38, 0x01, 0x1D, 0xA0, 0xD1, 0x36, 0x3F,
  43127. 0xD0, 0xA7, 0x8F, 0x86, 0x26, 0x1E, 0xB0, 0x26,
  43128. 0xDE, 0x7E, 0x17, 0x3A, 0x90, 0xFC, 0xC0, 0x17,
  43129. 0xDD, 0x78, 0xF5, 0xA3, 0x2D, 0x3E, 0x29, 0xCE,
  43130. 0x38, 0x45, 0x76, 0xA9, 0x55, 0x11, 0xB6, 0xB4,
  43131. 0xE5, 0x6E, 0xDD, 0x01, 0x4B, 0x16, 0x07, 0x99,
  43132. 0xBD, 0x19, 0x77, 0xF5, 0xD7, 0x9E, 0x39, 0x9E,
  43133. 0xAA, 0x8E, 0x2B, 0x75, 0xC5, 0xEB, 0x33, 0x56,
  43134. 0x6C, 0xD8, 0xB6, 0x3F, 0x3F, 0x4E, 0x81, 0x7E,
  43135. 0x29, 0x0A, 0x68, 0xED, 0x1E, 0x9F, 0xDC, 0x6B,
  43136. 0xFA, 0x18, 0xE3, 0xE5, 0x7D, 0x05, 0x7F, 0x22,
  43137. 0xFA, 0xA2, 0xF6, 0x0F, 0xB6, 0x34, 0x56, 0x72,
  43138. 0x55, 0x16, 0x5E, 0xF4, 0x18, 0xD1, 0x82, 0xFA,
  43139. 0xDD, 0xF7, 0xB8, 0x9F, 0x7D, 0x30, 0x10, 0x69,
  43140. 0xC4, 0x85, 0xD8, 0xE8, 0x34, 0x89, 0xD4, 0x93,
  43141. 0xBE, 0x56, 0xEE, 0xDC, 0x43, 0xD4, 0x82, 0x00,
  43142. 0xFD, 0x1E, 0x2B, 0x06, 0x69, 0x07, 0x1B, 0xBF,
  43143. 0x33, 0x61, 0x39, 0x28, 0xCA, 0x31, 0x91, 0x0B,
  43144. 0xF2, 0xEA, 0x32, 0x8E, 0xA8, 0x64, 0x13, 0x9A,
  43145. 0xEF, 0x79, 0x1A, 0x9A, 0xBE, 0x52, 0x13, 0x32,
  43146. 0x49, 0x93, 0x7D, 0xA8, 0x8C, 0x48, 0xD4, 0xC0,
  43147. 0x1D, 0x10, 0x8A, 0x46, 0x85, 0xAD, 0x29, 0xDF,
  43148. 0x2E, 0xCD, 0x41, 0x83, 0x82, 0x01, 0x28, 0x44,
  43149. 0x0E, 0xE5, 0x37, 0x8D, 0x6B, 0xCA, 0x61, 0x98,
  43150. 0xDE, 0x89, 0xA9, 0x7B, 0xBB, 0x44, 0x48, 0xA2,
  43151. 0x8D, 0x82, 0x3A, 0x57, 0x40, 0x60, 0x7C, 0x6E,
  43152. 0x69, 0x98, 0x98, 0x93, 0xFA, 0x7E, 0x29, 0x9A,
  43153. 0x74, 0x53, 0xD8, 0xDC, 0xB3, 0x4B, 0xDB, 0x7E,
  43154. 0xFE, 0x95, 0xB0, 0xC7, 0x23, 0x14, 0xEF, 0xCB,
  43155. 0x49, 0x3C, 0x09, 0xD7, 0x7B, 0xD0, 0x11, 0x9B,
  43156. 0xAC, 0xF2, 0xC2, 0x2E, 0x7C, 0xCB, 0xCD, 0x59,
  43157. 0x7F, 0x6A, 0x09, 0xFE, 0xFE, 0xDF, 0xA0, 0xA7,
  43158. 0xAC, 0x3C, 0x90, 0xBA, 0x75, 0x19, 0xF4, 0x01,
  43159. 0x60, 0x56, 0xD5, 0xFB, 0x41, 0x2B, 0xA0, 0x2D,
  43160. 0x0D, 0x45, 0xCF, 0xF3, 0xA6, 0x3D, 0x36, 0xEE,
  43161. 0xE1, 0xE4, 0x68, 0xE6, 0xEA, 0x2F, 0x67, 0x3A,
  43162. 0x7A, 0x02, 0x92, 0x6B, 0xB3, 0x18, 0xBA, 0x73,
  43163. 0xEE, 0x1B, 0x2C, 0x13, 0x7D, 0xEF, 0x4A, 0x39,
  43164. 0xE8, 0x03, 0xFF, 0x57, 0x35, 0x53, 0xE9, 0xA5,
  43165. 0xC6, 0xAA, 0x1A, 0x17, 0x21, 0xCA, 0x54, 0x38,
  43166. 0x7C, 0xB1, 0xDF, 0xB8, 0xFA, 0x7D, 0xA7, 0x26,
  43167. 0xB2, 0xAE, 0x7A, 0x05, 0x45, 0x3B, 0x40, 0x0A,
  43168. 0x19, 0xE5, 0x32, 0x52, 0x78, 0x9D, 0xC3, 0x20,
  43169. 0x63, 0x24, 0xB2, 0x58, 0x4B, 0x86, 0x1F, 0x00,
  43170. 0xA2, 0x50, 0xF9, 0x9F, 0xD9, 0xDC, 0x7D, 0x51,
  43171. 0x3D, 0xD7, 0xA6, 0x5A, 0x04, 0x03, 0x4E, 0xB3,
  43172. 0x3D, 0x2D, 0x56, 0xA4, 0x96, 0xB3, 0x6A, 0xBA,
  43173. 0x0A, 0x30, 0x08, 0xE3, 0x0F, 0xC1, 0x38, 0x24,
  43174. 0x88, 0x5D, 0x9E, 0x6F, 0x68, 0x1A, 0x7D, 0xB6,
  43175. 0x2D, 0xDD, 0xE3, 0x50, 0x1B, 0xD4, 0x07, 0x75,
  43176. 0xE2, 0xE2, 0xCC, 0x09, 0xCC, 0x8E, 0x4E, 0x67,
  43177. 0x02, 0x72, 0x02, 0xA8, 0x11, 0x70, 0xA5, 0x7F,
  43178. 0x4A, 0xC1, 0x98, 0xC1, 0x7F, 0xBF, 0x95, 0xBB,
  43179. 0xCE, 0xD3, 0x6D, 0x49, 0x30, 0xB9, 0x50, 0x8C,
  43180. 0xFA, 0x3E, 0x8B, 0xF6, 0xE5, 0x54, 0xE9, 0x1B,
  43181. 0xD7, 0xD6, 0xE5, 0x32, 0x33, 0xBB, 0x91, 0xAD,
  43182. 0xC8, 0x15, 0x76, 0x1A, 0x04, 0x35, 0xDE, 0xCC,
  43183. 0xE1, 0x67, 0x26, 0x4C, 0x2F, 0x4E, 0x34, 0x34,
  43184. 0x3D, 0x1E, 0x5A, 0xF7, 0xBC, 0xE6, 0x0C, 0x9B,
  43185. 0x7B, 0x7E, 0xE5, 0xDF, 0x72, 0x9A, 0x0D, 0xDD,
  43186. 0x4B, 0xE6, 0x6F, 0x82, 0xFB, 0x5E, 0x2C, 0xC0,
  43187. 0x7B, 0x03, 0x85, 0x76, 0x11, 0x0E, 0xFD, 0xC7,
  43188. 0xD5, 0x50, 0x26, 0xBE, 0x75, 0x5E, 0xC1, 0xF0,
  43189. 0x2E, 0x47, 0x62, 0xD6, 0xF1, 0xDA, 0xDF, 0xF4,
  43190. 0x1C, 0xEE, 0x63, 0x52, 0xC4, 0x45, 0x37, 0xE6,
  43191. 0x85, 0xA5, 0x0A, 0x07, 0x54, 0x63, 0x21, 0x7B,
  43192. 0x92, 0xF7, 0x33, 0x0C, 0xD9, 0x29, 0xCF, 0xE3,
  43193. 0xAB, 0xB5, 0xFC, 0xAA, 0x26, 0x20, 0x93, 0x55,
  43194. 0x8A, 0x07, 0x33, 0xB2, 0x7D, 0x95, 0x02, 0x7A,
  43195. 0x76, 0x9E, 0x7D, 0xBB, 0xC1, 0xF3, 0x6E, 0x84,
  43196. 0x10, 0x30, 0x4B, 0x5D, 0x59, 0x73, 0x68, 0xEC,
  43197. 0x2A, 0x63, 0x2D, 0x46, 0xE8, 0xC2, 0xF8, 0xEA,
  43198. 0x2B, 0xC4, 0x4F, 0xA7, 0x6E, 0xF4, 0x74, 0xEB,
  43199. 0x96, 0xA3, 0x64, 0x40, 0x9B, 0x23, 0x63, 0x42,
  43200. 0x4B, 0x8F, 0x85, 0x00, 0x43, 0x04, 0xAD, 0x61,
  43201. 0x76, 0x93, 0xBD, 0xC3, 0x88, 0xC3, 0xFC, 0x29,
  43202. 0x61, 0xBD, 0xB1, 0x5A, 0x1F, 0x5B, 0x20, 0xEF,
  43203. 0x95, 0xED, 0x99, 0x84, 0x96, 0xB2, 0x93, 0x81,
  43204. 0x82, 0xFF, 0xE3, 0xB9, 0x27, 0xEA, 0x9A, 0x23,
  43205. 0xF6, 0x42, 0x8D, 0xD3, 0x5C, 0x86, 0x11, 0xC8,
  43206. 0x39, 0xE3, 0x16, 0xE9, 0xA5, 0x32, 0x7C, 0xC9,
  43207. 0xEA, 0x82, 0x50, 0x9B, 0x21, 0x5C, 0xC9, 0x66,
  43208. 0xBE, 0x1C, 0x78, 0x48, 0xEF, 0x39, 0x2D, 0xA1,
  43209. 0xC6, 0xF3, 0x69, 0xA3, 0x36, 0x25, 0x3A, 0xA1,
  43210. 0x15, 0x2B, 0x6D, 0xCF, 0xDA, 0xA7, 0xCA, 0xDD,
  43211. 0x4D, 0x9A, 0x1D, 0x58, 0x9F, 0x73, 0xD3, 0xEF,
  43212. 0x0F, 0xBF, 0x03, 0x88, 0x2F, 0xDE, 0xB9, 0x44,
  43213. 0xB5, 0xB6, 0xCF, 0xE2, 0x6F, 0x6A, 0xB5, 0x12,
  43214. 0x38, 0x29, 0x55, 0x8C, 0x4C, 0x73, 0x6F, 0x0B,
  43215. 0x68, 0x7A, 0xC7, 0x06, 0x83, 0x80, 0xFE, 0x7F,
  43216. 0x61, 0xBE, 0x6B, 0x40, 0xE3, 0xF0, 0x4D, 0x7B,
  43217. 0x36, 0x82, 0x0F, 0xD8, 0x63, 0x29, 0xB3, 0x10,
  43218. 0x9D, 0x02, 0xEC, 0x63, 0x90, 0xEA, 0xFC, 0x8C,
  43219. 0xA7, 0x30, 0x56, 0x2B, 0x68, 0x08, 0x24, 0x24,
  43220. 0xFD, 0xA9, 0x8D, 0x0B, 0x64, 0xBC, 0x97, 0x34,
  43221. 0xB4, 0x0B, 0x63, 0xF7, 0xE3, 0x7A, 0xF6, 0x89,
  43222. 0x0A, 0xF7, 0xC2, 0xD9, 0x2F, 0x79, 0xEE, 0xA3,
  43223. 0xCC, 0xEA, 0xC6, 0x0A, 0x6F, 0x38, 0x06, 0x92,
  43224. 0xF8, 0x02, 0xB1, 0x55, 0x6A, 0x78, 0xFE, 0x55,
  43225. 0x83, 0xFF, 0x20, 0xA9, 0xC6, 0xA7, 0xBF, 0xCC,
  43226. 0x86, 0x3A, 0x9E, 0x7B, 0x62, 0x01, 0x4D, 0x16,
  43227. 0x05, 0xDE, 0x89, 0x4F, 0xB5, 0x85, 0xE2, 0xD4,
  43228. 0xF9, 0x41, 0x15, 0xE0, 0x29, 0xE5, 0x85, 0x7E,
  43229. 0x6A, 0x0A, 0x73, 0x89, 0x27, 0x5F, 0x53, 0x0D,
  43230. 0x3D, 0x80, 0xCF, 0xAB, 0x1F, 0x22, 0x5D, 0x38,
  43231. 0x33, 0x5D, 0x24, 0x67, 0x91, 0x97, 0xD4, 0x8A,
  43232. 0x01, 0x8A, 0x34, 0x18, 0x7D, 0xE3, 0xBC, 0xCE,
  43233. 0xDE, 0x94, 0xFF, 0x8E, 0xC5, 0x34, 0xC0, 0x2D,
  43234. 0xA7, 0x24, 0xD4, 0x59, 0x8D, 0x66, 0x9E, 0x85,
  43235. 0xA9, 0xC6, 0x0E, 0x45, 0x21, 0x4F, 0xAA, 0x65,
  43236. 0x44, 0xD6, 0xA4, 0x7D, 0x1C, 0x4E, 0xD7, 0x40,
  43237. 0x9D, 0x55, 0xB1, 0xA7, 0xF1, 0x15, 0xAE, 0x15,
  43238. 0x44, 0x3A, 0x1C, 0x31, 0x06, 0x40, 0xD1, 0x16,
  43239. 0x23, 0x84, 0x93, 0xEF, 0x3E, 0xE2, 0x87, 0x9B,
  43240. 0xB8, 0x46, 0x1F, 0x7D, 0x68, 0x73, 0x64, 0x70,
  43241. 0xD4, 0xB5, 0x73, 0xAE, 0x45, 0x49, 0x93, 0xF5,
  43242. 0x32, 0x30, 0x1E, 0x35, 0xCB, 0x9E, 0xEE, 0xDF,
  43243. 0xFE, 0xA8, 0x2F, 0xAC, 0x49, 0x77, 0x53, 0xF7,
  43244. 0x50, 0x19, 0xF2, 0xB3, 0xB0, 0x2C, 0x70, 0xB6,
  43245. 0x4A, 0x57, 0x95, 0x31, 0xC3, 0x26, 0x07, 0x2A,
  43246. 0xCF, 0x1B, 0xD0, 0xAA, 0xA0, 0x9F, 0x0A, 0x97,
  43247. 0x8B, 0x78, 0xAB, 0x22, 0xBD, 0x61, 0x19, 0xF8,
  43248. 0x8D, 0xD2, 0xD5, 0x72, 0xF8, 0x91, 0x9D, 0x47,
  43249. 0x4F, 0x59, 0x1D, 0xAE, 0x9F, 0xCE, 0x47, 0x53,
  43250. 0xC9, 0x85, 0xFB, 0x25, 0x04, 0x25, 0xF2, 0x65,
  43251. 0x61, 0xFF, 0xA9, 0x44, 0x3F, 0x23, 0x76, 0x68,
  43252. 0x9F, 0xEB, 0x48, 0xC4, 0xCE, 0x51, 0x46, 0x04,
  43253. 0x52, 0x6A, 0x10, 0x0A, 0xF3, 0x3F, 0x0D, 0x43,
  43254. 0x37, 0xD1, 0x60, 0x42, 0x22, 0xC4, 0xD9, 0xF9,
  43255. 0x3A, 0x8E, 0x69, 0xE4, 0xCC, 0xD3, 0x66, 0x69,
  43256. 0x09, 0x0C, 0x5D, 0xFB, 0x0E, 0x95, 0x49, 0x42,
  43257. 0x29, 0xFF, 0x9B, 0x20, 0xCC, 0xB1, 0xAC, 0x81,
  43258. 0xB8, 0x1A, 0x36, 0xD6, 0x3A, 0x85, 0x0D, 0xDB,
  43259. 0x33, 0x33, 0x4D, 0xAA, 0x51, 0x46, 0xBF, 0x36,
  43260. 0xFE, 0x18, 0x80, 0x1E, 0x3B, 0xEB, 0xD0, 0xE9,
  43261. 0x1B, 0x5E, 0x1C, 0xFE, 0x7A, 0x98, 0x26, 0x85,
  43262. 0x0A, 0xF4, 0x39, 0x7D, 0x1B, 0x07, 0xD3, 0xB7,
  43263. 0x19, 0xE5, 0x7B, 0xB8, 0x32, 0xAF, 0x42, 0x34,
  43264. 0xC0, 0xCD, 0x9F, 0xD4, 0x0B, 0x88, 0x2F, 0xCE,
  43265. 0xDA, 0x93, 0x7E, 0xF9, 0xA2, 0xDA, 0x24, 0x59,
  43266. 0x2B, 0xCB, 0x5D, 0x1B, 0xE8, 0x3E, 0xC5, 0xF0,
  43267. 0x3D, 0xBD, 0xFB, 0xCB, 0x33, 0x5D, 0x90, 0xD5,
  43268. 0xC8, 0xA0, 0x2E, 0xE5, 0x3D, 0x50, 0x8E, 0xB5,
  43269. 0xDE, 0x4A, 0x96, 0x1B, 0x95, 0x8F, 0x75, 0x1E,
  43270. 0x5F, 0x89, 0xA1, 0xD2, 0x88, 0x95, 0xA3, 0xDB,
  43271. 0x7B, 0x62, 0xEF, 0x4A, 0xE1, 0x6D, 0x28, 0xFB,
  43272. 0x78, 0x9B, 0x32, 0x03, 0xAD, 0x24, 0x63, 0xD6,
  43273. 0xEA, 0xB8, 0x3A, 0x6D, 0x20, 0xCE, 0xA1, 0x31,
  43274. 0x4A, 0xE0, 0x2A, 0x3F, 0xF6, 0xF6, 0x53, 0x15,
  43275. 0x4A, 0xE1, 0x44, 0x23, 0x81, 0x86, 0x21, 0x47,
  43276. 0x41, 0xC2, 0x36, 0x14, 0x81, 0x83, 0xBC, 0x39,
  43277. 0xAE, 0xDF, 0x44, 0xDA, 0x97, 0xF7, 0x31, 0xCE,
  43278. 0x3D, 0xCB, 0x61, 0xA4, 0xCF, 0xE1, 0x4F, 0x9E,
  43279. 0x84, 0xAA, 0x05, 0xAB, 0x1C, 0x1B, 0x95, 0x1D,
  43280. 0x20, 0x15, 0x52, 0x33, 0xFA, 0xFA, 0xF1, 0x6C,
  43281. 0xF1, 0xBD, 0x0B, 0xAF, 0xE1, 0x99, 0xE6, 0x5D,
  43282. 0x56, 0x34, 0x53, 0xBF, 0xE5, 0x5D, 0x5F, 0x47,
  43283. 0x4A, 0xB1, 0x05, 0x94, 0xD7, 0x38, 0xA8, 0xC1,
  43284. 0x06, 0x28, 0x8D, 0x69, 0xD0, 0x7A, 0x16, 0x88,
  43285. 0x60, 0x14, 0x63, 0xF3, 0xBD, 0x21, 0x46, 0x81,
  43286. 0x9C, 0x83, 0x72, 0x6D, 0x14, 0xC6, 0xA8, 0x08,
  43287. 0x39, 0xB8, 0x79, 0x0B, 0x57, 0x16, 0xE7, 0x72,
  43288. 0xF6, 0xC2, 0x4C, 0x2B, 0xEB, 0x7E, 0x2C, 0xF3,
  43289. 0x7B, 0x3F, 0x42, 0xAC, 0xDD, 0x47, 0x3E, 0x8C,
  43290. 0xCD, 0xBE, 0x48, 0x4D, 0x6E, 0x07, 0xB0, 0x73,
  43291. 0xDE, 0xCB, 0x17, 0x4A, 0xC3, 0xB8, 0xBB, 0x2E,
  43292. 0xF5, 0x4E, 0x6D, 0xF9, 0xE0, 0x20, 0x71, 0xFA,
  43293. 0x60, 0x0A, 0xE5, 0x59, 0x67, 0xEB, 0x6F, 0x70,
  43294. 0x2F, 0x71, 0x91, 0x59, 0xF0, 0xEB, 0x06, 0x5C,
  43295. 0xC4, 0x60, 0x48, 0xE8, 0x75, 0xE7, 0xCF, 0x42,
  43296. 0x71, 0xAD, 0x2E, 0xDA, 0xF9, 0x10, 0x82, 0x9A,
  43297. 0xF6, 0x13, 0xBA, 0x89, 0xFC, 0x61, 0x2A, 0x00,
  43298. 0xFD, 0xAE, 0x53, 0x7B, 0x09, 0x3A, 0xE8, 0xCB,
  43299. 0xE6, 0xB7, 0x0D, 0x03, 0x01, 0xFA, 0x2E, 0x13,
  43300. 0xA9, 0x16, 0x38, 0x1C, 0x92, 0xEC, 0xB4, 0x51,
  43301. 0xA3, 0x6E, 0x3F, 0xA8, 0xB7, 0x37, 0x36, 0x20,
  43302. 0xC0, 0x71, 0xA3, 0x05, 0x34, 0xED, 0xCB, 0x4A,
  43303. 0x3F, 0x11, 0x31, 0x17, 0xA5, 0x02, 0xD6, 0xA7,
  43304. 0x2D, 0xE6, 0xC7, 0x7B, 0xBB, 0xF6, 0xAE, 0x99,
  43305. 0x85, 0x9A, 0xAC, 0xE6, 0x4A, 0x92, 0x8C, 0x37,
  43306. 0x4B, 0xD2, 0xC4, 0x65, 0x2A, 0xC9, 0x7E, 0xB7,
  43307. 0x44, 0xD2, 0x9A, 0x70, 0xCE, 0xA9, 0xA1, 0x9D,
  43308. 0x70, 0x13, 0x49, 0x7B, 0xCA, 0xB6, 0x96, 0x31,
  43309. 0x43, 0x3F, 0x9E, 0xD1, 0xFE, 0x20, 0xF8, 0x0B,
  43310. 0x59, 0x83, 0xE1, 0x28, 0x8B, 0xB6, 0xA2, 0xBE,
  43311. 0x91, 0x54, 0x3E, 0xD4, 0x79, 0x28, 0xBB, 0x5E,
  43312. 0x46, 0x2D, 0x01, 0xE9, 0xC0, 0xB7, 0xFF, 0xFA,
  43313. 0xC0, 0x6C, 0x10, 0xF1, 0x52, 0xF4, 0x3C, 0x32,
  43314. 0x9E, 0x89, 0xDF, 0x8A, 0x79, 0x99, 0x6A, 0x09,
  43315. 0x79, 0x8A, 0x36, 0x76, 0x40, 0xBE, 0x9F, 0xB5,
  43316. 0x3D, 0xCE, 0x27, 0xBD, 0x0B, 0xAA, 0x9B, 0xF0,
  43317. 0x21, 0xBF, 0x10, 0xD2, 0xFC, 0xFE, 0x5B, 0x13,
  43318. 0xFD, 0x7D, 0x84, 0xD1, 0xC1, 0xEB, 0xC0, 0xBC,
  43319. 0xEC, 0x26, 0xD0, 0x87, 0x80, 0xD1, 0x3B, 0x99,
  43320. 0x47, 0x67, 0x26, 0x61, 0xE0, 0xFA, 0x5F, 0xAE,
  43321. 0x6F, 0x31, 0x5B, 0x6D, 0xE4, 0x01, 0x68, 0xC2,
  43322. 0x35, 0x1D, 0xE3, 0x1F, 0x41, 0xFF, 0x6C, 0x53,
  43323. 0x32, 0x26, 0xE1, 0xBC, 0xE3, 0xF8, 0xE2, 0x16,
  43324. 0xAF, 0x3B, 0xE6, 0x4C, 0x69, 0x33, 0x72, 0xA0,
  43325. 0x66, 0xB1, 0x75, 0xF7, 0x26, 0xCF, 0xCD, 0x64,
  43326. 0x2B, 0xAE, 0x98, 0x02, 0x92, 0xC1, 0xCB, 0x65,
  43327. 0xE0, 0x1F, 0x07, 0x29, 0x64, 0x0A, 0xB0, 0x09,
  43328. 0xCB, 0x98, 0x89, 0x2D, 0x6C, 0xFE, 0x40, 0x03,
  43329. 0x34, 0x55, 0xDE, 0xE7, 0x30, 0x33, 0xB6, 0xD5,
  43330. 0xE1, 0x9C, 0x59, 0x9F, 0x8A, 0x40, 0x0E, 0xB1,
  43331. 0x41, 0x52, 0x7D, 0xF2, 0xBB, 0xDD, 0xEF, 0x50,
  43332. 0xBB, 0xD5, 0xFB, 0x55, 0xAA, 0x5E, 0xFD, 0xB3,
  43333. 0x5D, 0x08, 0x56, 0x9B, 0x02, 0x97, 0xE2, 0x48,
  43334. 0x14, 0x69, 0xF1, 0x7B, 0x87, 0xB5, 0x08, 0x93,
  43335. 0x6A, 0x9C, 0x5C, 0x11, 0x08, 0x9A, 0xE9, 0xE4,
  43336. 0xB0, 0xCA, 0xC5, 0x74, 0x93, 0x93, 0xC8, 0x03,
  43337. 0xE4, 0x70, 0x39, 0xF5, 0x1B, 0x5C, 0xBD, 0x42,
  43338. 0xA6, 0xC9, 0xE1, 0x9E, 0xC3, 0xF6, 0x3C, 0x23,
  43339. 0x32, 0xE8, 0x77, 0x68, 0xA9, 0x60, 0xFA, 0x02,
  43340. 0x18, 0x6B, 0x7A, 0x2B, 0x02, 0x92, 0x65, 0x09,
  43341. 0x11, 0x46, 0x73, 0x04, 0x63, 0xDF, 0x8B, 0x37,
  43342. 0x5F, 0x24, 0xAA, 0x83, 0xBD, 0xD4, 0x1D, 0x13,
  43343. 0x04, 0xFC, 0x2F, 0xB5, 0x2D, 0xA1, 0x0F, 0x1F,
  43344. 0xED, 0x65, 0x29, 0x08, 0xCF, 0x8C, 0x52, 0x8F,
  43345. 0xB2, 0x62, 0x5F, 0x39, 0x3F, 0xC8, 0xC7, 0xB3,
  43346. 0x3F, 0xAD, 0x45, 0xBA, 0xD4, 0x7D, 0x38, 0x3D,
  43347. 0x2C, 0x04, 0xCF, 0x32, 0xE8, 0x07, 0x42, 0x5F,
  43348. 0x93, 0xD2, 0x35, 0x07, 0x21, 0xB7, 0xB2, 0xF5,
  43349. 0x96, 0x64, 0x8E, 0xB5, 0xE1, 0x38, 0x6B, 0x43,
  43350. 0xD1, 0x2E, 0xFD, 0xDB, 0x8F, 0xE2, 0x43, 0x6A,
  43351. 0xEC, 0x27, 0x8E, 0xE7, 0x68, 0x75, 0xB5, 0x23,
  43352. 0xC5, 0x43, 0x1D, 0x99, 0x48, 0x57, 0x73, 0xD9,
  43353. 0xAD, 0xBC, 0xD0, 0x14, 0xDD, 0x87, 0xBC, 0x68,
  43354. 0xFB, 0x82, 0xEE, 0x47, 0x4B, 0x22, 0xA5, 0x43,
  43355. 0x3A, 0xF9, 0xF9, 0x91, 0xFC, 0x34, 0xB2, 0x58,
  43356. 0x34, 0xDF, 0x13, 0x09, 0x9A, 0x46, 0xF5, 0x68,
  43357. 0xAF, 0xD1, 0x15, 0x5F, 0x32, 0x1B, 0x9D, 0xA9,
  43358. 0xE9, 0xC0, 0x63, 0x47, 0xAB, 0x3C, 0x1F, 0x59,
  43359. 0xF7, 0xEA, 0x0E, 0xD6, 0xCF, 0x47, 0xB3, 0xE9,
  43360. 0xAF, 0x65, 0x7A, 0xA7, 0xAE, 0x9B, 0xF8, 0x26,
  43361. 0x0B, 0x96, 0x9D, 0xE4, 0xAD, 0x24, 0xD3, 0xA8,
  43362. 0xCE, 0x95, 0xE5, 0x77, 0xD0, 0x44, 0x13, 0x05,
  43363. 0x06, 0x4E, 0x07, 0xB9, 0xA2, 0xC7, 0x5C, 0x3C,
  43364. 0x43, 0x80, 0x1F, 0xCE, 0xB7, 0x36, 0xFE, 0x3D,
  43365. 0x27, 0x1B, 0xE1, 0xF3, 0x6B, 0xFF, 0xC8, 0xE4,
  43366. 0x3D, 0xB1, 0x4A, 0x16, 0x24, 0x76, 0xBA, 0xEA,
  43367. 0x9D, 0x34, 0x6B, 0x52, 0x11, 0xAB, 0xD0, 0x06,
  43368. 0x08, 0xB1, 0x5A, 0xF3, 0xB5, 0xE6, 0x3A, 0x00,
  43369. 0xFF, 0x92, 0x8D, 0x1E, 0xA1, 0xA1, 0x8D, 0x75,
  43370. 0xFA, 0x7C, 0x6C, 0x1B, 0x0F, 0xB6, 0x27, 0x2E,
  43371. 0x55, 0xC3, 0xFE, 0x7E, 0x4D, 0x42, 0x05, 0xE5,
  43372. 0xCF, 0x0A, 0x1F, 0x87, 0x18, 0x30, 0x4E, 0x14,
  43373. 0xF2, 0xB4, 0xCC, 0x54, 0x3D, 0x04, 0x37, 0x34,
  43374. 0x1A, 0x4A, 0x31, 0x16, 0x01, 0xA9, 0x2E, 0x92,
  43375. 0x56, 0x6B, 0x7D, 0xFB, 0x42, 0x64, 0xE8, 0x70,
  43376. 0xE1, 0xB3, 0xA8, 0x75, 0xED, 0xBC, 0x00, 0x3A,
  43377. 0x56, 0x19, 0x70, 0xCF, 0x8A, 0x66, 0x9F, 0x3D,
  43378. 0x1B, 0x69, 0x28, 0x8C, 0xC6, 0xE3, 0x59, 0xCE,
  43379. 0x28, 0xCA, 0x65, 0xF9, 0xDA, 0xE8, 0xCE, 0xCA,
  43380. 0x74, 0x3C, 0x1C, 0x8D, 0x9F, 0xFB, 0x55, 0x08,
  43381. 0x82, 0x4A, 0x83, 0x61, 0xE3, 0x3B, 0x43, 0x1A,
  43382. 0x2E, 0x9E, 0x9A, 0x99, 0x78, 0x47, 0xD2, 0xE6,
  43383. 0xE4, 0x3C, 0x83, 0xF0, 0x22, 0x62, 0xE2, 0x94,
  43384. 0x6D, 0xF7, 0x72, 0x6D, 0x54, 0xE3, 0xE6, 0xC9,
  43385. 0xCC, 0xDB, 0x6D, 0x3F, 0x13, 0x63, 0x46, 0xC1,
  43386. 0x1E, 0x59, 0x42, 0xE7, 0xA1, 0xBF, 0x85, 0x0C,
  43387. 0x2E, 0x99, 0xB4, 0xFA, 0xCE, 0x75, 0xFD, 0x40,
  43388. 0x88, 0x69, 0x33, 0x90, 0x7C, 0xCD, 0xFC, 0x0D,
  43389. 0xE1, 0x17, 0x70, 0x20, 0x31, 0x94, 0x1D, 0x00,
  43390. 0x1E, 0x2A, 0x68, 0x3C, 0x55, 0x78, 0xFD, 0x33,
  43391. 0x54, 0x21, 0x2C, 0xEA, 0xD9, 0x69, 0xBF, 0x1C,
  43392. 0x81, 0x23, 0x9E, 0xEC, 0xC7, 0x74, 0xFD, 0x0B,
  43393. 0x88, 0x3D, 0x0E, 0xEE, 0x82, 0x4B, 0x10, 0xB8,
  43394. 0x79, 0xCF, 0x70, 0x7C, 0xB2, 0x68, 0x47, 0x45,
  43395. 0x22, 0x06, 0x1E, 0x92, 0x7B, 0x12, 0x43, 0x24,
  43396. 0x41, 0x15, 0xC6, 0x69, 0xE9, 0xEB, 0x27, 0x2B,
  43397. 0x60, 0xA6, 0x44, 0xF5, 0x19, 0xEF, 0xEC, 0x06,
  43398. 0x34, 0x08, 0xB6, 0x58, 0x47, 0x2E, 0x91, 0x61,
  43399. 0xA1, 0xF7, 0x44, 0xFD, 0x66, 0x16, 0x9F, 0x0C,
  43400. 0xAE, 0x36, 0xB4, 0x2E, 0x23, 0x79, 0xCB, 0xE8,
  43401. 0x1E, 0x6E, 0x51, 0xA0, 0xF5, 0x34, 0x15, 0x18,
  43402. 0x4E, 0xA0, 0x06, 0xB2, 0x27, 0x0B, 0x33, 0xE2,
  43403. 0xCA, 0x36, 0x4C, 0xDB, 0x33, 0xAA, 0xAE, 0x77,
  43404. 0xFF, 0xD9, 0x53, 0xDB, 0x39, 0x70, 0x4D, 0x49,
  43405. 0x0C, 0xE9, 0xAC, 0x6F, 0x2D, 0xD1, 0xC7, 0xA1,
  43406. 0x8E, 0x61, 0x74, 0x19, 0xA9, 0xAA, 0xFB, 0x37,
  43407. 0xE7, 0x23, 0x9B, 0x23, 0x6A, 0x4B, 0x74, 0xCE,
  43408. 0x63, 0xE4, 0xA0, 0xAD, 0xFF, 0x85, 0x5D, 0xCD,
  43409. 0x78, 0xF6, 0x45, 0x8E, 0x76, 0x0B, 0xFD, 0x1D,
  43410. 0x2A, 0xB9, 0x5E, 0x83, 0xC0, 0x3B, 0x6F, 0xAE,
  43411. 0x0C, 0xD3, 0xC5, 0xCE, 0xEE, 0xEE, 0x1C, 0x69,
  43412. 0x51, 0x59, 0x65, 0xA3, 0x35, 0xFC, 0xF7, 0x8E,
  43413. 0x80, 0xAA, 0x73, 0x93, 0x39, 0x54, 0x21, 0x27,
  43414. 0x17, 0x0B, 0x2C, 0x3E, 0xE1, 0x0B, 0x0E, 0xAA,
  43415. 0x09, 0x9A, 0xC7, 0xAD, 0x4C, 0xD7, 0x6E, 0x7F,
  43416. 0xE4, 0xC1, 0x16, 0x4E, 0x62, 0xF4, 0xE5, 0x80,
  43417. 0x7D, 0xC0, 0x06, 0x1F, 0x77, 0xE4, 0xA8, 0xA5,
  43418. 0x28, 0xD7, 0x10, 0x37, 0x59, 0x30, 0xCB, 0x75,
  43419. 0x5B, 0x28, 0xBF, 0xFD, 0x92, 0x8C, 0xB0, 0x7B,
  43420. 0xB4, 0xA1, 0x07, 0xCD, 0xCA, 0xBB, 0x30, 0x8A,
  43421. 0x48, 0x65, 0x0D, 0xA4, 0xE5, 0x74, 0xD9, 0xBF,
  43422. 0x56, 0x07, 0xF5, 0x83, 0xDA, 0xC3, 0x40, 0xD7,
  43423. 0x20, 0x93, 0xEF, 0xB1, 0x2B, 0xBF, 0x93, 0x41,
  43424. 0x0F, 0x1E, 0xF5, 0xC9, 0x51, 0x6C, 0x74, 0x4D,
  43425. 0x23, 0x15, 0xEC, 0x9E, 0x00, 0x0A, 0x8D, 0xC5,
  43426. 0xD1, 0x7A, 0x7B, 0x6F, 0x0D, 0x07, 0x9D, 0x78,
  43427. 0x4B, 0x6D, 0x90, 0x19, 0x3F, 0x6E, 0x3E, 0xE7,
  43428. 0xEA, 0x0E, 0xAB, 0xFC, 0x6F, 0x68, 0xC5, 0x2B,
  43429. 0x37, 0xCB, 0xCE, 0x82, 0x18, 0xAF, 0xA3, 0x67,
  43430. 0x0A, 0x80, 0xBC, 0x17, 0xB9, 0x5D, 0x7B, 0x40,
  43431. 0x53, 0x62, 0x26, 0x35, 0x8F, 0x04, 0xAC, 0xD9,
  43432. 0x2A, 0x1B, 0xE1, 0x5B, 0x26, 0xA4, 0xE5, 0x81,
  43433. 0x7E, 0x62, 0x8B, 0xA6, 0x79, 0xB3, 0x52, 0x72,
  43434. 0x03, 0xCD, 0x36, 0x32, 0x62, 0x8E, 0xC8, 0x3A,
  43435. 0xA4, 0xF2, 0x18, 0x6D, 0x2F, 0x00, 0x5D, 0x5D,
  43436. 0xFE, 0x6F, 0x7F, 0xDB, 0x4F, 0xED, 0xAC, 0x9E,
  43437. 0x89, 0xD6, 0x66, 0xE3, 0x03, 0xBB, 0x56, 0x83,
  43438. 0x06, 0x15, 0x6C, 0x56, 0xF0, 0x95, 0x34, 0xE2,
  43439. 0x5C, 0x61, 0x9A, 0xB3, 0xB9, 0x50, 0x18, 0xF4,
  43440. 0x89, 0x6B, 0xAC, 0xAA, 0x48, 0x34, 0xF6, 0xD2,
  43441. 0xD8, 0xFE, 0x14, 0xA9, 0x38, 0xAA, 0x10, 0xE5,
  43442. 0x30, 0x54, 0xF0, 0x00, 0x84, 0x44, 0xAC, 0x2E,
  43443. 0xEA, 0x25, 0x38, 0xC1, 0x23, 0x0E, 0x6A, 0x18,
  43444. 0xC9, 0x2B, 0x01, 0xD9, 0x14, 0x7F, 0xDC, 0xEF,
  43445. 0xC9, 0xC8, 0xDA, 0xC1, 0xD4, 0xEC, 0xC8, 0xCF,
  43446. 0x1F, 0x96, 0x2E, 0xFA, 0x1B, 0x8C, 0xD3, 0xC9,
  43447. 0x69, 0x00, 0x0B, 0x7E, 0xBA, 0xC5, 0x98, 0xDC,
  43448. 0xA4, 0x5E, 0xB4, 0x0B, 0xCF, 0xB1, 0x98, 0x51,
  43449. 0x48, 0x38, 0x51, 0xCF, 0x34, 0x0F, 0x3E, 0x8C,
  43450. 0x23, 0x7A, 0x9E, 0xFF, 0x1C, 0x9F, 0x21, 0xE4,
  43451. 0x97, 0x55, 0x41, 0xC6, 0x1A, 0x8F, 0xEF, 0x2A,
  43452. 0xC6, 0x05, 0x7F, 0x59, 0xDC, 0xB2, 0x3A, 0x80,
  43453. 0xE8, 0x06, 0x10, 0xCD, 0x85, 0xDB, 0x20, 0x3C,
  43454. 0x35, 0xD2, 0x4B, 0xC8, 0x2B, 0x9C, 0xD7, 0x82,
  43455. 0x46, 0xF5, 0x9F, 0xEB, 0xB2, 0x48, 0x32, 0xD7,
  43456. 0xCD, 0x66, 0x4C, 0x99, 0x51, 0x88, 0xE0, 0x28,
  43457. 0x1C, 0xD7, 0x86, 0x79, 0x00, 0xDC, 0x0D, 0xF4,
  43458. 0x4D, 0x40, 0x90, 0x80, 0x26, 0x8B, 0x79, 0xE9,
  43459. 0x56, 0x82, 0x88, 0x5F, 0x22, 0x87, 0x70, 0x73,
  43460. 0x4F, 0xA5, 0x35, 0x18, 0xEC, 0x80, 0xCE, 0x23,
  43461. 0x06, 0xCE, 0x14, 0x48, 0x52, 0x4E, 0xF0, 0x18,
  43462. 0x43, 0x03, 0xD4, 0x50, 0xC7, 0x6E, 0xA6, 0x3B,
  43463. 0x73, 0x3E, 0xB0, 0xC8, 0xDC, 0x48, 0xBF, 0x12,
  43464. 0x42, 0x3A, 0xD2, 0x38, 0x89, 0xCF, 0xCD, 0xD8,
  43465. 0x91, 0xE5, 0x95, 0x00, 0x47, 0x24, 0x0D, 0xC0,
  43466. 0xC3, 0x8A, 0xB2, 0xDB, 0xC1, 0x65, 0xB8, 0x1E,
  43467. 0x63, 0x10, 0x02, 0xEA, 0x6F, 0x74, 0x11, 0x9E,
  43468. 0x27, 0xF9, 0xF8, 0x60, 0x73, 0xBF, 0x2D, 0xF7,
  43469. 0x10, 0x81, 0x86, 0x76, 0x98, 0x0C, 0x4C, 0xB6,
  43470. 0xBD, 0x53, 0xF9, 0xA5, 0x72, 0x17, 0x78, 0xB8,
  43471. 0x9F, 0x59, 0xC6, 0x8C, 0x89, 0x35, 0xF5, 0x03,
  43472. 0x1C, 0x8A, 0x93, 0x36, 0x7D, 0x71, 0x70, 0x57,
  43473. 0xFD, 0x4D, 0x5E, 0xFA, 0xBE, 0xDE, 0x70, 0x2C,
  43474. 0xC6, 0x45, 0xEF, 0xB6, 0xD7, 0xF4, 0x4C, 0x86,
  43475. 0x0F, 0xFF, 0x76, 0x37, 0xAA, 0xD9, 0x72, 0x24,
  43476. 0x8C, 0x84, 0x4D, 0x15, 0x13, 0x39, 0x20, 0x07,
  43477. 0x38, 0x91, 0xC3, 0x13, 0x5D, 0x29, 0x78, 0x68,
  43478. 0xB7, 0xDA, 0x86, 0xF0, 0x97, 0xD8, 0xFB, 0x39,
  43479. 0xC1, 0x3B, 0xA1, 0x4C, 0x4F, 0x24, 0x75, 0x16,
  43480. 0xAB, 0xA4, 0xC5, 0xF8, 0xCE, 0x38, 0x18, 0x48,
  43481. 0x2C, 0x8F, 0xF6, 0x0C, 0xCA, 0x51, 0xFD, 0xB2,
  43482. 0xCE, 0xE9, 0x6B, 0xC1, 0x13, 0x8D, 0xC0, 0x4A,
  43483. 0x86, 0xF8, 0x57, 0x72, 0x75, 0x91, 0xAA, 0xE6,
  43484. 0xF8, 0x7C, 0x30, 0x05, 0x9B, 0x3E, 0x81, 0xB6,
  43485. 0x80, 0x55, 0xB2, 0x4E, 0xA2, 0xFA, 0x98, 0x36,
  43486. 0x86, 0x49, 0x8B, 0xFC, 0x9D, 0x9E, 0x7D, 0x59,
  43487. 0x50, 0x79, 0xEB, 0x64, 0x6E, 0x85, 0xB2, 0x12,
  43488. 0xCE, 0xDD, 0x21, 0xD0, 0x08, 0x7E, 0x0F, 0x2A,
  43489. 0xF6, 0x63, 0xEB, 0x77, 0x2A, 0x98, 0x47, 0xB1,
  43490. 0xDF, 0x21, 0x97, 0xAF, 0x13, 0x62, 0x6B, 0x89,
  43491. 0x7C, 0x24, 0x63, 0x7A, 0xF5, 0xBF, 0xE8, 0x18,
  43492. 0x16, 0xA8, 0xC9, 0x0D, 0x30, 0x48, 0x37, 0x5B,
  43493. 0x69, 0x94, 0x97, 0x14, 0x3E, 0x57, 0x71, 0x85,
  43494. 0xA7, 0x0E, 0x11, 0x50, 0x58, 0xA3, 0xA9, 0x11,
  43495. 0x2B, 0x2C, 0x43, 0x51, 0xB6, 0xCA, 0xD0, 0x09,
  43496. 0x28, 0x2B, 0x4F, 0x7C, 0xB8, 0xBD, 0xFC, 0x28,
  43497. 0x57, 0x77, 0xD7, 0xDF, 0xE8, 0xF5, 0x00, 0x00,
  43498. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43499. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43500. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43501. 0x00, 0x00, 0x00, 0x03, 0x06, 0x0B, 0x11, 0x17,
  43502. 0x1F, 0x27, 0x2E
  43503. };
  43504. #endif
  43505. #endif
  43506. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43507. ExpectNotNull(key);
  43508. if (key != NULL) {
  43509. XMEMSET(key, 0, sizeof(*key));
  43510. }
  43511. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  43512. #ifndef WOLFSSL_NO_ML_DSA_44
  43513. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  43514. ExpectIntEQ(wc_dilithium_import_public(pk_44, (word32)sizeof(pk_44), key),
  43515. 0);
  43516. ExpectIntEQ(wc_dilithium_verify_msg(sig_44, (word32)sizeof(sig_44), msg_44,
  43517. (word32)sizeof(msg_44), &res, key), 0);
  43518. ExpectIntEQ(res, 1);
  43519. #endif
  43520. #ifndef WOLFSSL_NO_ML_DSA_65
  43521. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  43522. ExpectIntEQ(wc_dilithium_import_public(pk_65, (word32)sizeof(pk_65), key),
  43523. 0);
  43524. ExpectIntEQ(wc_dilithium_verify_msg(sig_65, (word32)sizeof(sig_65), msg_65,
  43525. (word32)sizeof(msg_65), &res, key), 0);
  43526. ExpectIntEQ(res, 1);
  43527. #endif
  43528. #ifndef WOLFSSL_NO_ML_DSA_87
  43529. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  43530. ExpectIntEQ(wc_dilithium_import_public(pk_87, (word32)sizeof(pk_87), key),
  43531. 0);
  43532. ExpectIntEQ(wc_dilithium_verify_msg(sig_87, (word32)sizeof(sig_87), msg_87,
  43533. (word32)sizeof(msg_87), &res, key), 0);
  43534. ExpectIntEQ(res, 1);
  43535. #endif
  43536. wc_dilithium_free(key);
  43537. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43538. #endif
  43539. return EXPECT_RESULT();
  43540. }
  43541. /*
  43542. * Testing wc_SetSubjectBuffer
  43543. */
  43544. static int test_wc_SetSubjectBuffer(void)
  43545. {
  43546. EXPECT_DECLS;
  43547. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  43548. Cert cert;
  43549. XFILE file = XBADFILE;
  43550. byte* der = NULL;
  43551. word32 derSz;
  43552. derSz = FOURK_BUF;
  43553. ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  43554. DYNAMIC_TYPE_TMP_BUFFER));
  43555. ExpectTrue((file = XFOPEN("./certs/ca-cert.der", "rb")) != XBADFILE);
  43556. ExpectTrue((derSz = (word32)XFREAD(der, 1, FOURK_BUF, file)) > 0);
  43557. if (file != XBADFILE)
  43558. XFCLOSE(file);
  43559. ExpectIntEQ(wc_InitCert(&cert), 0);
  43560. ExpectIntEQ(wc_SetSubjectBuffer(&cert, der, (int)derSz), 0);
  43561. ExpectIntEQ(wc_SetSubjectBuffer(NULL, der, (int)derSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43562. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43563. #endif
  43564. return EXPECT_RESULT();
  43565. } /* End test_wc_SetSubjectBuffer*/
  43566. /*
  43567. * Testing wc_SetSubjectKeyIdFromPublicKey_ex
  43568. */
  43569. static int test_wc_SetSubjectKeyIdFromPublicKey_ex(void)
  43570. {
  43571. EXPECT_DECLS;
  43572. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  43573. WC_RNG rng;
  43574. Cert cert;
  43575. #if !defined(NO_RSA) && defined(HAVE_RSA)
  43576. RsaKey rsaKey;
  43577. int bits = 2048;
  43578. #endif
  43579. #if defined(HAVE_ECC)
  43580. ecc_key eccKey;
  43581. int ret;
  43582. #endif
  43583. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43584. ed25519_key ed25519Key;
  43585. #endif
  43586. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43587. ed448_key ed448Key;
  43588. #endif
  43589. #ifndef HAVE_FIPS
  43590. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  43591. #else
  43592. ExpectIntEQ(wc_InitRng(&rng), 0);
  43593. #endif
  43594. ExpectIntEQ(wc_InitCert(&cert), 0);
  43595. #if !defined(NO_RSA) && defined(HAVE_RSA) && defined(WOLFSSL_KEY_GEN)
  43596. /* RSA */
  43597. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  43598. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  43599. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  43600. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey),
  43601. 0);
  43602. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  43603. #endif
  43604. #if defined(HAVE_ECC)
  43605. /* ECC */
  43606. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  43607. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  43608. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  43609. #if defined(WOLFSSL_ASYNC_CRYPT)
  43610. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  43611. #endif
  43612. ExpectIntEQ(ret, 0);
  43613. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey),
  43614. 0);
  43615. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  43616. #endif
  43617. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43618. /* ED25519 */
  43619. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  43620. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  43621. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  43622. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  43623. &ed25519Key), 0);
  43624. wc_ed25519_free(&ed25519Key);
  43625. #endif
  43626. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43627. /* ED448 */
  43628. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  43629. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  43630. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  43631. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE,
  43632. &ed448Key), 0);
  43633. wc_ed448_free(&ed448Key);
  43634. #endif
  43635. wc_FreeRng(&rng);
  43636. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  43637. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  43638. return EXPECT_RESULT();
  43639. } /* End test_wc_SetSubjectKeyIdFromPublicKey_ex*/
  43640. /*
  43641. * Testing wc_SetAuthKeyIdFromPublicKey_ex
  43642. */
  43643. static int test_wc_SetAuthKeyIdFromPublicKey_ex(void)
  43644. {
  43645. EXPECT_DECLS;
  43646. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  43647. WC_RNG rng;
  43648. Cert cert;
  43649. #if !defined(NO_RSA) && defined(HAVE_RSA)
  43650. RsaKey rsaKey;
  43651. int bits = 2048;
  43652. #endif
  43653. #if defined(HAVE_ECC)
  43654. ecc_key eccKey;
  43655. int ret;
  43656. #endif
  43657. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43658. ed25519_key ed25519Key;
  43659. #endif
  43660. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43661. ed448_key ed448Key;
  43662. #endif
  43663. #ifndef HAVE_FIPS
  43664. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  43665. #else
  43666. ExpectIntEQ(wc_InitRng(&rng), 0);
  43667. #endif
  43668. ExpectIntEQ(wc_InitCert(&cert), 0);
  43669. #if !defined(NO_RSA) && defined(HAVE_RSA) && defined(WOLFSSL_KEY_GEN)
  43670. /* RSA */
  43671. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  43672. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  43673. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  43674. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey), 0);
  43675. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  43676. #endif
  43677. #if defined(HAVE_ECC)
  43678. /* ECC */
  43679. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  43680. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  43681. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  43682. #if defined(WOLFSSL_ASYNC_CRYPT)
  43683. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  43684. #endif
  43685. ExpectIntEQ(ret, 0);
  43686. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey), 0);
  43687. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  43688. #endif
  43689. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43690. /* ED25519 */
  43691. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  43692. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  43693. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  43694. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  43695. &ed25519Key), 0);
  43696. wc_ed25519_free(&ed25519Key);
  43697. #endif
  43698. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43699. /* ED448 */
  43700. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  43701. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  43702. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  43703. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, &ed448Key),
  43704. 0);
  43705. wc_ed448_free(&ed448Key);
  43706. #endif
  43707. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  43708. #endif /* defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)*/
  43709. return EXPECT_RESULT();
  43710. } /* End test_wc_SetAuthKeyIdFromPublicKey_ex*/
  43711. /*
  43712. * Testing wc_PKCS7_New()
  43713. */
  43714. static int test_wc_PKCS7_New(void)
  43715. {
  43716. EXPECT_DECLS;
  43717. #if defined(HAVE_PKCS7)
  43718. PKCS7* pkcs7 = NULL;
  43719. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, testDevId));
  43720. wc_PKCS7_Free(pkcs7);
  43721. #endif
  43722. return EXPECT_RESULT();
  43723. } /* END test-wc_PKCS7_New */
  43724. /*
  43725. * Testing wc_PKCS7_Init()
  43726. */
  43727. static int test_wc_PKCS7_Init(void)
  43728. {
  43729. EXPECT_DECLS;
  43730. #if defined(HAVE_PKCS7)
  43731. PKCS7* pkcs7 = NULL;
  43732. void* heap = NULL;
  43733. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  43734. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  43735. /* Pass in bad args. */
  43736. ExpectIntEQ(wc_PKCS7_Init(NULL, heap, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43737. wc_PKCS7_Free(pkcs7);
  43738. #endif
  43739. return EXPECT_RESULT();
  43740. } /* END test-wc_PKCS7_Init */
  43741. /*
  43742. * Testing wc_PKCS7_InitWithCert()
  43743. */
  43744. static int test_wc_PKCS7_InitWithCert(void)
  43745. {
  43746. EXPECT_DECLS;
  43747. #if defined(HAVE_PKCS7)
  43748. PKCS7* pkcs7 = NULL;
  43749. #ifndef NO_RSA
  43750. #if defined(USE_CERT_BUFFERS_2048)
  43751. unsigned char cert[sizeof(client_cert_der_2048)];
  43752. int certSz = (int)sizeof(cert);
  43753. XMEMSET(cert, 0, certSz);
  43754. XMEMCPY(cert, client_cert_der_2048, sizeof(client_cert_der_2048));
  43755. #elif defined(USE_CERT_BUFFERS_1024)
  43756. unsigned char cert[sizeof(client_cert_der_1024)];
  43757. int certSz = (int)sizeof(cert);
  43758. XMEMSET(cert, 0, certSz);
  43759. XMEMCPY(cert, client_cert_der_1024, sizeof_client_cert_der_1024);
  43760. #else
  43761. unsigned char cert[ONEK_BUF];
  43762. XFILE fp = XBADFILE;
  43763. int certSz;
  43764. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  43765. XBADFILE);
  43766. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  43767. fp), 0);
  43768. if (fp != XBADFILE)
  43769. XFCLOSE(fp);
  43770. #endif
  43771. #elif defined(HAVE_ECC)
  43772. #if defined(USE_CERT_BUFFERS_256)
  43773. unsigned char cert[sizeof(cliecc_cert_der_256)];
  43774. int certSz = (int)sizeof(cert);
  43775. XMEMSET(cert, 0, certSz);
  43776. XMEMCPY(cert, cliecc_cert_der_256, sizeof(cliecc_cert_der_256));
  43777. #else
  43778. unsigned char cert[ONEK_BUF];
  43779. XFILE fp = XBADFILE;
  43780. int certSz;
  43781. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  43782. XBADFILE);
  43783. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof(cliecc_cert_der_256),
  43784. fp), 0);
  43785. if (fp != XBADFILE)
  43786. XFCLOSE(fp);
  43787. #endif
  43788. #else
  43789. #error PKCS7 requires ECC or RSA
  43790. #endif
  43791. #ifdef HAVE_ECC
  43792. {
  43793. /* bad test case from ZD 11011, malformed cert gives bad ECC key */
  43794. static unsigned char certWithInvalidEccKey[] = {
  43795. 0x30, 0x82, 0x03, 0x5F, 0x30, 0x82, 0x03, 0x04, 0xA0, 0x03, 0x02, 0x01,
  43796. 0x02, 0x02, 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79,
  43797. 0x42, 0x83, 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x31, 0xAA, 0x2C, 0x30,
  43798. 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30,
  43799. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  43800. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08,
  43801. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  43802. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  43803. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  43804. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  43805. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  43806. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  43807. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  43808. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  43809. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  43810. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30,
  43811. 0x1E, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x36, 0x31, 0x39, 0x31, 0x33, 0x32,
  43812. 0x33, 0x34, 0x31, 0x5A, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x33, 0x31, 0x36,
  43813. 0x31, 0x33, 0x32, 0x33, 0x34, 0x31, 0x5A, 0x30, 0x81, 0x8D, 0x31, 0x0B,
  43814. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
  43815. 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x06, 0x4F, 0x72,
  43816. 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04,
  43817. 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D, 0x31, 0x13, 0x30, 0x11,
  43818. 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43, 0x6C, 0x69, 0x65, 0x6E,
  43819. 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55,
  43820. 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74, 0x31, 0x18, 0x30, 0x26,
  43821. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  43822. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F,
  43823. 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  43824. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66,
  43825. 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x59, 0x30, 0x13, 0x06,
  43826. 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86,
  43827. 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x02, 0x00, 0x04, 0x55, 0xBF,
  43828. 0xF4, 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5, 0x4D,
  43829. 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80, 0xEC, 0x5A, 0x4C,
  43830. 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA, 0xEF, 0xA2, 0x35, 0x12, 0x43,
  43831. 0x84, 0x76, 0x16, 0xC6, 0x56, 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6,
  43832. 0x75, 0x1A, 0x42, 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D,
  43833. 0x7F, 0xB4, 0xA3, 0x82, 0x01, 0x3E, 0x30, 0x82, 0x01, 0x3A, 0x30, 0x1D,
  43834. 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xEB, 0xD4, 0x4B,
  43835. 0x59, 0x6B, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  43836. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0x30, 0x81, 0xCD, 0x06, 0x03, 0x55, 0x1D,
  43837. 0x23, 0x04, 0x81, 0xC5, 0x30, 0x81, 0xC2, 0x80, 0x14, 0xEB, 0xD4, 0x4B,
  43838. 0x59, 0x72, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  43839. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0xA1, 0x81, 0x93, 0xA4, 0x81, 0x90, 0x30,
  43840. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  43841. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x08, 0x08,
  43842. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  43843. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  43844. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  43845. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  43846. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  43847. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  43848. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  43849. 0x6F, 0x6D, 0x30, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  43850. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  43851. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
  43852. 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79, 0x42, 0x83,
  43853. 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x32, 0xAA, 0x2C, 0x30, 0x0C, 0x06,
  43854. 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30,
  43855. 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30, 0x13, 0x82, 0x0B,
  43856. 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x87,
  43857. 0x04, 0x23, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25,
  43858. 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07,
  43859. 0x03, 0x01, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
  43860. 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02,
  43861. 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xE4, 0xA0, 0x23, 0x26,
  43862. 0x2B, 0x0B, 0x42, 0x0F, 0x97, 0x37, 0x6D, 0xCB, 0x14, 0x23, 0xC3, 0xC3,
  43863. 0xE6, 0x44, 0xCF, 0x5F, 0x4C, 0x26, 0xA3, 0x72, 0x64, 0x7A, 0x9C, 0xCB,
  43864. 0x64, 0xAB, 0xA6, 0xBE, 0x02, 0x21, 0x00, 0xAA, 0xC5, 0xA3, 0x50, 0xF6,
  43865. 0xF1, 0xA5, 0xDB, 0x05, 0xE0, 0x75, 0xD2, 0xF7, 0xBA, 0x49, 0x5F, 0x8F,
  43866. 0x7D, 0x1C, 0x44, 0xB1, 0x6E, 0xDF, 0xC8, 0xDA, 0x10, 0x48, 0x2D, 0x53,
  43867. 0x08, 0xA8, 0xB4
  43868. };
  43869. #endif
  43870. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  43871. /* If initialization is not successful, it's free'd in init func. */
  43872. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz),
  43873. 0);
  43874. wc_PKCS7_Free(pkcs7);
  43875. pkcs7 = NULL;
  43876. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  43877. /* Valid initialization usage. */
  43878. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  43879. /* Pass in bad args. No need free for null checks, free at end.*/
  43880. ExpectIntEQ(wc_PKCS7_InitWithCert(NULL, (byte*)cert, (word32)certSz),
  43881. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43882. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, (word32)certSz),
  43883. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43884. #ifdef HAVE_ECC
  43885. ExpectIntLT(wc_PKCS7_InitWithCert(pkcs7, certWithInvalidEccKey,
  43886. sizeof(certWithInvalidEccKey)), 0);
  43887. }
  43888. #endif
  43889. wc_PKCS7_Free(pkcs7);
  43890. #endif
  43891. return EXPECT_RESULT();
  43892. } /* END test_wc_PKCS7_InitWithCert */
  43893. /*
  43894. * Testing wc_PKCS7_EncodeData()
  43895. */
  43896. static int test_wc_PKCS7_EncodeData(void)
  43897. {
  43898. EXPECT_DECLS;
  43899. #if defined(HAVE_PKCS7)
  43900. PKCS7* pkcs7 = NULL;
  43901. byte output[FOURK_BUF];
  43902. byte data[] = "My encoded DER cert.";
  43903. #ifndef NO_RSA
  43904. #if defined(USE_CERT_BUFFERS_2048)
  43905. unsigned char cert[sizeof(client_cert_der_2048)];
  43906. unsigned char key[sizeof(client_key_der_2048)];
  43907. int certSz = (int)sizeof(cert);
  43908. int keySz = (int)sizeof(key);
  43909. XMEMSET(cert, 0, certSz);
  43910. XMEMSET(key, 0, keySz);
  43911. XMEMCPY(cert, client_cert_der_2048, certSz);
  43912. XMEMCPY(key, client_key_der_2048, keySz);
  43913. #elif defined(USE_CERT_BUFFERS_1024)
  43914. unsigned char cert[sizeof(sizeof_client_cert_der_1024)];
  43915. unsigned char key[sizeof_client_key_der_1024];
  43916. int certSz = (int)sizeof(cert);
  43917. int keySz = (int)sizeof(key);
  43918. XMEMSET(cert, 0, certSz);
  43919. XMEMSET(key, 0, keySz);
  43920. XMEMCPY(cert, client_cert_der_1024, certSz);
  43921. XMEMCPY(key, client_key_der_1024, keySz);
  43922. #else
  43923. unsigned char cert[ONEK_BUF];
  43924. unsigned char key[ONEK_BUF];
  43925. XFILE fp = XBADFILE;
  43926. int certSz;
  43927. int keySz;
  43928. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  43929. XBADFILE);
  43930. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  43931. fp), 0);
  43932. if (fp != XBADFILE) {
  43933. XFCLOSE(fp);
  43934. fp = XBADFILE;
  43935. }
  43936. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  43937. XBADFILE);
  43938. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  43939. 0);
  43940. if (fp != XBADFILE)
  43941. XFCLOSE(fp);
  43942. #endif
  43943. #elif defined(HAVE_ECC)
  43944. #if defined(USE_CERT_BUFFERS_256)
  43945. unsigned char cert[sizeof(cliecc_cert_der_256)];
  43946. unsigned char key[sizeof(ecc_clikey_der_256)];
  43947. int certSz = (int)sizeof(cert);
  43948. int keySz = (int)sizeof(key);
  43949. XMEMSET(cert, 0, certSz);
  43950. XMEMSET(key, 0, keySz);
  43951. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  43952. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  43953. #else
  43954. unsigned char cert[ONEK_BUF];
  43955. unsigned char key[ONEK_BUF];
  43956. XFILE fp = XBADFILE;
  43957. int certSz, keySz;
  43958. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  43959. XBADFILE);
  43960. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  43961. fp), 0);
  43962. if (fp != XBADFILE) {
  43963. XFCLOSE(fp);
  43964. fp = XBADFILE;
  43965. }
  43966. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  43967. XBADFILE);
  43968. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  43969. 0);
  43970. if (fp != XBADFILE)
  43971. XFCLOSE(fp);
  43972. #endif
  43973. #endif
  43974. XMEMSET(output, 0, sizeof(output));
  43975. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  43976. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  43977. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  43978. if (pkcs7 != NULL) {
  43979. pkcs7->content = data;
  43980. pkcs7->contentSz = sizeof(data);
  43981. pkcs7->privateKey = key;
  43982. pkcs7->privateKeySz = (word32)keySz;
  43983. }
  43984. ExpectIntGT(wc_PKCS7_EncodeData(pkcs7, output, (word32)sizeof(output)), 0);
  43985. /* Test bad args. */
  43986. ExpectIntEQ(wc_PKCS7_EncodeData(NULL, output, (word32)sizeof(output)),
  43987. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43988. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, NULL, (word32)sizeof(output)),
  43989. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43990. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, output, 5), WC_NO_ERR_TRACE(BUFFER_E));
  43991. wc_PKCS7_Free(pkcs7);
  43992. #endif
  43993. return EXPECT_RESULT();
  43994. } /* END test_wc_PKCS7_EncodeData */
  43995. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  43996. !defined(NO_RSA) && !defined(NO_SHA256)
  43997. /* RSA sign raw digest callback */
  43998. static int rsaSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz,
  43999. byte* out, word32 outSz, byte* privateKey,
  44000. word32 privateKeySz, int devid, int hashOID)
  44001. {
  44002. /* specific DigestInfo ASN.1 encoding prefix for a SHA2565 digest */
  44003. byte digInfoEncoding[] = {
  44004. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  44005. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  44006. 0x00, 0x04, 0x20
  44007. };
  44008. int ret;
  44009. byte digestInfo[ONEK_BUF];
  44010. byte sig[FOURK_BUF];
  44011. word32 digestInfoSz = 0;
  44012. word32 idx = 0;
  44013. RsaKey rsa;
  44014. /* SHA-256 required only for this example callback due to above
  44015. * digInfoEncoding[] */
  44016. if (pkcs7 == NULL || digest == NULL || out == NULL ||
  44017. (sizeof(digestInfo) < sizeof(digInfoEncoding) + digestSz) ||
  44018. (hashOID != SHA256h)) {
  44019. return -1;
  44020. }
  44021. /* build DigestInfo */
  44022. XMEMCPY(digestInfo, digInfoEncoding, sizeof(digInfoEncoding));
  44023. digestInfoSz += sizeof(digInfoEncoding);
  44024. XMEMCPY(digestInfo + digestInfoSz, digest, digestSz);
  44025. digestInfoSz += digestSz;
  44026. /* set up RSA key */
  44027. ret = wc_InitRsaKey_ex(&rsa, pkcs7->heap, devid);
  44028. if (ret != 0) {
  44029. return ret;
  44030. }
  44031. ret = wc_RsaPrivateKeyDecode(privateKey, &idx, &rsa, privateKeySz);
  44032. /* sign DigestInfo */
  44033. if (ret == 0) {
  44034. ret = wc_RsaSSL_Sign(digestInfo, digestInfoSz, sig, sizeof(sig),
  44035. &rsa, pkcs7->rng);
  44036. if (ret > 0) {
  44037. if (ret > (int)outSz) {
  44038. /* output buffer too small */
  44039. ret = -1;
  44040. }
  44041. else {
  44042. /* success, ret holds sig size */
  44043. XMEMCPY(out, sig, ret);
  44044. }
  44045. }
  44046. }
  44047. wc_FreeRsaKey(&rsa);
  44048. return ret;
  44049. }
  44050. #endif
  44051. #if defined(HAVE_PKCS7) && defined(ASN_BER_TO_DER)
  44052. typedef struct encodeSignedDataStream {
  44053. byte out[FOURK_BUF*3];
  44054. int idx;
  44055. word32 outIdx;
  44056. } encodeSignedDataStream;
  44057. /* content is 8k of partially created bundle */
  44058. static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
  44059. {
  44060. int ret = 0;
  44061. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44062. if (strm->outIdx < pkcs7->contentSz) {
  44063. ret = (pkcs7->contentSz > strm->outIdx + FOURK_BUF)?
  44064. FOURK_BUF : pkcs7->contentSz - strm->outIdx;
  44065. *content = strm->out + strm->outIdx;
  44066. strm->outIdx += ret;
  44067. }
  44068. (void)pkcs7;
  44069. return ret;
  44070. }
  44071. static int StreamOutputCB(PKCS7* pkcs7, const byte* output, word32 outputSz,
  44072. void* ctx)
  44073. {
  44074. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44075. XMEMCPY(strm->out + strm->idx, output, outputSz);
  44076. strm->idx += outputSz;
  44077. (void)pkcs7;
  44078. return 0;
  44079. }
  44080. #endif
  44081. /*
  44082. * Testing wc_PKCS7_EncodeSignedData()
  44083. */
  44084. static int test_wc_PKCS7_EncodeSignedData(void)
  44085. {
  44086. EXPECT_DECLS;
  44087. #if defined(HAVE_PKCS7)
  44088. PKCS7* pkcs7 = NULL;
  44089. WC_RNG rng;
  44090. byte output[FOURK_BUF];
  44091. byte badOut[1];
  44092. word32 outputSz = (word32)sizeof(output);
  44093. word32 badOutSz = 0;
  44094. byte data[] = "Test data to encode.";
  44095. #ifndef NO_RSA
  44096. #if defined(USE_CERT_BUFFERS_2048)
  44097. byte key[sizeof(client_key_der_2048)];
  44098. byte cert[sizeof(client_cert_der_2048)];
  44099. word32 keySz = (word32)sizeof(key);
  44100. word32 certSz = (word32)sizeof(cert);
  44101. XMEMSET(key, 0, keySz);
  44102. XMEMSET(cert, 0, certSz);
  44103. XMEMCPY(key, client_key_der_2048, keySz);
  44104. XMEMCPY(cert, client_cert_der_2048, certSz);
  44105. #elif defined(USE_CERT_BUFFERS_1024)
  44106. byte key[sizeof_client_key_der_1024];
  44107. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44108. word32 keySz = (word32)sizeof(key);
  44109. word32 certSz = (word32)sizeof(cert);
  44110. XMEMSET(key, 0, keySz);
  44111. XMEMSET(cert, 0, certSz);
  44112. XMEMCPY(key, client_key_der_1024, keySz);
  44113. XMEMCPY(cert, client_cert_der_1024, certSz);
  44114. #else
  44115. unsigned char cert[ONEK_BUF];
  44116. unsigned char key[ONEK_BUF];
  44117. XFILE fp = XBADFILE;
  44118. int certSz;
  44119. int keySz;
  44120. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44121. XBADFILE);
  44122. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44123. fp), 0);
  44124. if (fp != XBADFILE) {
  44125. XFCLOSE(fp);
  44126. fp = XBADFILE;
  44127. }
  44128. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44129. XBADFILE);
  44130. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44131. 0);
  44132. if (fp != XBADFILE)
  44133. XFCLOSE(fp);
  44134. #endif
  44135. #elif defined(HAVE_ECC)
  44136. #if defined(USE_CERT_BUFFERS_256)
  44137. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44138. unsigned char key[sizeof(ecc_clikey_der_256)];
  44139. int certSz = (int)sizeof(cert);
  44140. int keySz = (int)sizeof(key);
  44141. XMEMSET(cert, 0, certSz);
  44142. XMEMSET(key, 0, keySz);
  44143. XMEMCPY(cert, cliecc_cert_der_256, certSz);
  44144. XMEMCPY(key, ecc_clikey_der_256, keySz);
  44145. #else
  44146. unsigned char cert[ONEK_BUF];
  44147. unsigned char key[ONEK_BUF];
  44148. XFILE fp = XBADFILE;
  44149. int certSz;
  44150. int keySz;
  44151. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44152. XBADFILE);
  44153. ExpectIntGT(certSz = (int)XFREAD(cert, 1, ONEK_BUF, fp), 0);
  44154. if (fp != XBADFILE) {
  44155. XFCLOSE(fp);
  44156. fp = XBADFILE;
  44157. }
  44158. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44159. XBADFILE);
  44160. ExpectIntGT(keySz = (int)XFREAD(key, 1, ONEK_BUF, fp), 0);
  44161. if (fp != XBADFILE)
  44162. XFCLOSE(fp);
  44163. #endif
  44164. #endif
  44165. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44166. XMEMSET(output, 0, outputSz);
  44167. ExpectIntEQ(wc_InitRng(&rng), 0);
  44168. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44169. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44170. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44171. if (pkcs7 != NULL) {
  44172. pkcs7->content = data;
  44173. pkcs7->contentSz = (word32)sizeof(data);
  44174. pkcs7->privateKey = key;
  44175. pkcs7->privateKeySz = (word32)sizeof(key);
  44176. pkcs7->encryptOID = RSAk;
  44177. #ifdef NO_SHA
  44178. pkcs7->hashOID = SHA256h;
  44179. #else
  44180. pkcs7->hashOID = SHAh;
  44181. #endif
  44182. pkcs7->rng = &rng;
  44183. }
  44184. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44185. wc_PKCS7_Free(pkcs7);
  44186. pkcs7 = NULL;
  44187. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44188. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44189. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44190. #ifdef ASN_BER_TO_DER
  44191. wc_PKCS7_Free(pkcs7);
  44192. /* reinitialize and test setting stream mode */
  44193. {
  44194. int signedSz = 0;
  44195. encodeSignedDataStream strm;
  44196. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44197. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44198. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44199. if (pkcs7 != NULL) {
  44200. pkcs7->content = data;
  44201. pkcs7->contentSz = (word32)sizeof(data);
  44202. pkcs7->privateKey = key;
  44203. pkcs7->privateKeySz = (word32)sizeof(key);
  44204. pkcs7->encryptOID = RSAk;
  44205. #ifdef NO_SHA
  44206. pkcs7->hashOID = SHA256h;
  44207. #else
  44208. pkcs7->hashOID = SHAh;
  44209. #endif
  44210. pkcs7->rng = &rng;
  44211. }
  44212. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  44213. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  44214. ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1, NULL, NULL, NULL),
  44215. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44216. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
  44217. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
  44218. outputSz), 0);
  44219. wc_PKCS7_Free(pkcs7);
  44220. pkcs7 = NULL;
  44221. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44222. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44223. /* use exact signed buffer size since BER encoded */
  44224. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)signedSz), 0);
  44225. wc_PKCS7_Free(pkcs7);
  44226. /* now try with using callbacks for IO */
  44227. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44228. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44229. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44230. if (pkcs7 != NULL) {
  44231. pkcs7->contentSz = FOURK_BUF*2;
  44232. pkcs7->privateKey = key;
  44233. pkcs7->privateKeySz = (word32)sizeof(key);
  44234. pkcs7->encryptOID = RSAk;
  44235. #ifdef NO_SHA
  44236. pkcs7->hashOID = SHA256h;
  44237. #else
  44238. pkcs7->hashOID = SHAh;
  44239. #endif
  44240. pkcs7->rng = &rng;
  44241. }
  44242. XMEMSET(&strm, 0, sizeof(strm));
  44243. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  44244. StreamOutputCB, (void*)&strm), 0);
  44245. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, NULL, 0), 0);
  44246. wc_PKCS7_Free(pkcs7);
  44247. pkcs7 = NULL;
  44248. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44249. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44250. /* use exact signed buffer size since BER encoded */
  44251. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, strm.out, (word32)signedSz), 0);
  44252. }
  44253. #endif
  44254. #ifndef NO_PKCS7_STREAM
  44255. wc_PKCS7_Free(pkcs7);
  44256. pkcs7 = NULL;
  44257. {
  44258. word32 z;
  44259. int ret;
  44260. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44261. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44262. /* test for streaming mode */
  44263. ret = -1;
  44264. for (z = 0; z < outputSz && ret != 0; z++) {
  44265. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44266. if (ret < 0){
  44267. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44268. }
  44269. }
  44270. ExpectIntEQ(ret, 0);
  44271. ExpectIntNE(pkcs7->contentSz, 0);
  44272. ExpectNotNull(pkcs7->contentDynamic);
  44273. }
  44274. #endif /* !NO_PKCS7_STREAM */
  44275. /* Pass in bad args. */
  44276. ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
  44277. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44278. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, NULL, outputSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44279. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, badOut,
  44280. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44281. if (pkcs7 != NULL) {
  44282. pkcs7->hashOID = 0; /* bad hashOID */
  44283. }
  44284. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz),
  44285. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44286. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  44287. !defined(NO_RSA) && !defined(NO_SHA256)
  44288. /* test RSA sign raw digest callback, if using RSA and compiled in.
  44289. * Example callback assumes SHA-256, so only run test if compiled in. */
  44290. wc_PKCS7_Free(pkcs7);
  44291. pkcs7 = NULL;
  44292. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44293. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44294. if (pkcs7 != NULL) {
  44295. pkcs7->content = data;
  44296. pkcs7->contentSz = (word32)sizeof(data);
  44297. pkcs7->privateKey = key;
  44298. pkcs7->privateKeySz = (word32)sizeof(key);
  44299. pkcs7->encryptOID = RSAk;
  44300. pkcs7->hashOID = SHA256h;
  44301. pkcs7->rng = &rng;
  44302. }
  44303. ExpectIntEQ(wc_PKCS7_SetRsaSignRawDigestCb(pkcs7, rsaSignRawDigestCb), 0);
  44304. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44305. #endif
  44306. wc_PKCS7_Free(pkcs7);
  44307. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44308. #endif
  44309. return EXPECT_RESULT();
  44310. } /* END test_wc_PKCS7_EncodeSignedData */
  44311. /*
  44312. * Testing wc_PKCS7_EncodeSignedData_ex() and wc_PKCS7_VerifySignedData_ex()
  44313. */
  44314. static int test_wc_PKCS7_EncodeSignedData_ex(void)
  44315. {
  44316. EXPECT_DECLS;
  44317. #if defined(HAVE_PKCS7)
  44318. int i;
  44319. PKCS7* pkcs7 = NULL;
  44320. WC_RNG rng;
  44321. byte outputHead[FOURK_BUF/2];
  44322. byte outputFoot[FOURK_BUF/2];
  44323. word32 outputHeadSz = (word32)sizeof(outputHead);
  44324. word32 outputFootSz = (word32)sizeof(outputFoot);
  44325. byte data[FOURK_BUF];
  44326. wc_HashAlg hash;
  44327. #ifdef NO_SHA
  44328. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  44329. #else
  44330. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  44331. #endif
  44332. byte hashBuf[WC_MAX_DIGEST_SIZE];
  44333. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  44334. #ifndef NO_RSA
  44335. #if defined(USE_CERT_BUFFERS_2048)
  44336. byte key[sizeof(client_key_der_2048)];
  44337. byte cert[sizeof(client_cert_der_2048)];
  44338. word32 keySz = (word32)sizeof(key);
  44339. word32 certSz = (word32)sizeof(cert);
  44340. XMEMSET(key, 0, keySz);
  44341. XMEMSET(cert, 0, certSz);
  44342. XMEMCPY(key, client_key_der_2048, keySz);
  44343. XMEMCPY(cert, client_cert_der_2048, certSz);
  44344. #elif defined(USE_CERT_BUFFERS_1024)
  44345. byte key[sizeof_client_key_der_1024];
  44346. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44347. word32 keySz = (word32)sizeof(key);
  44348. word32 certSz = (word32)sizeof(cert);
  44349. XMEMSET(key, 0, keySz);
  44350. XMEMSET(cert, 0, certSz);
  44351. XMEMCPY(key, client_key_der_1024, keySz);
  44352. XMEMCPY(cert, client_cert_der_1024, certSz);
  44353. #else
  44354. unsigned char cert[ONEK_BUF];
  44355. unsigned char key[ONEK_BUF];
  44356. XFILE fp = XBADFILE;
  44357. int certSz;
  44358. int keySz;
  44359. ExpectTure((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44360. XBADFILE);
  44361. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44362. fp), 0);
  44363. if (fp != XBADFILE) {
  44364. XFCLOSE(fp);
  44365. fp = XBADFILE;
  44366. }
  44367. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44368. XBADFILE);
  44369. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44370. 0);
  44371. if (fp != XBADFILE)
  44372. XFCLOSE(fp);
  44373. #endif
  44374. #elif defined(HAVE_ECC)
  44375. #if defined(USE_CERT_BUFFERS_256)
  44376. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44377. unsigned char key[sizeof(ecc_clikey_der_256)];
  44378. int certSz = (int)sizeof(cert);
  44379. int keySz = (int)sizeof(key);
  44380. XMEMSET(cert, 0, certSz);
  44381. XMEMSET(key, 0, keySz);
  44382. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  44383. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  44384. #else
  44385. unsigned char cert[ONEK_BUF];
  44386. unsigned char key[ONEK_BUF];
  44387. XFILE fp = XBADFILE;
  44388. int certSz;
  44389. int keySz;
  44390. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44391. XBADFILE);
  44392. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  44393. fp), 0);
  44394. if (fp != XBADFILE) {
  44395. XFCLOSE(fp);
  44396. fp = XBADFILE;
  44397. }
  44398. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44399. XBADFILE);
  44400. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  44401. 0);
  44402. if (fp != XBADFILE)
  44403. XFCLOSE(fp);
  44404. #endif
  44405. #endif
  44406. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44407. /* initialize large data with sequence */
  44408. for (i=0; i<(int)sizeof(data); i++)
  44409. data[i] = i & 0xff;
  44410. XMEMSET(outputHead, 0, outputHeadSz);
  44411. XMEMSET(outputFoot, 0, outputFootSz);
  44412. ExpectIntEQ(wc_InitRng(&rng), 0);
  44413. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44414. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44415. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44416. if (pkcs7 != NULL) {
  44417. pkcs7->content = NULL; /* not used for ex */
  44418. pkcs7->contentSz = (word32)sizeof(data);
  44419. pkcs7->privateKey = key;
  44420. pkcs7->privateKeySz = (word32)sizeof(key);
  44421. pkcs7->encryptOID = RSAk;
  44422. #ifdef NO_SHA
  44423. pkcs7->hashOID = SHA256h;
  44424. #else
  44425. pkcs7->hashOID = SHAh;
  44426. #endif
  44427. pkcs7->rng = &rng;
  44428. }
  44429. /* calculate hash for content */
  44430. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  44431. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  44432. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  44433. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  44434. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  44435. /* Perform PKCS7 sign using hash directly */
  44436. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44437. outputHead, &outputHeadSz, outputFoot, &outputFootSz), 0);
  44438. ExpectIntGT(outputHeadSz, 0);
  44439. ExpectIntGT(outputFootSz, 0);
  44440. wc_PKCS7_Free(pkcs7);
  44441. pkcs7 = NULL;
  44442. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44443. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44444. /* required parameter even on verify when using _ex, if using outputHead
  44445. * and outputFoot */
  44446. if (pkcs7 != NULL) {
  44447. pkcs7->contentSz = (word32)sizeof(data);
  44448. }
  44449. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44450. outputHead, outputHeadSz, outputFoot, outputFootSz), 0);
  44451. wc_PKCS7_Free(pkcs7);
  44452. pkcs7 = NULL;
  44453. /* assembly complete PKCS7 sign and use normal verify */
  44454. {
  44455. byte* output = NULL;
  44456. word32 outputSz = 0;
  44457. #ifndef NO_PKCS7_STREAM
  44458. word32 z;
  44459. int ret;
  44460. #endif /* !NO_PKCS7_STREAM */
  44461. ExpectNotNull(output = (byte*)XMALLOC(
  44462. outputHeadSz + sizeof(data) + outputFootSz, HEAP_HINT,
  44463. DYNAMIC_TYPE_TMP_BUFFER));
  44464. if (output != NULL) {
  44465. XMEMCPY(&output[outputSz], outputHead, outputHeadSz);
  44466. outputSz += outputHeadSz;
  44467. XMEMCPY(&output[outputSz], data, sizeof(data));
  44468. outputSz += sizeof(data);
  44469. XMEMCPY(&output[outputSz], outputFoot, outputFootSz);
  44470. outputSz += outputFootSz;
  44471. }
  44472. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44473. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44474. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44475. #ifndef NO_PKCS7_STREAM
  44476. wc_PKCS7_Free(pkcs7);
  44477. pkcs7 = NULL;
  44478. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44479. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44480. /* test for streaming mode */
  44481. ret = -1;
  44482. for (z = 0; z < outputSz && ret != 0; z++) {
  44483. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44484. if (ret < 0){
  44485. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44486. }
  44487. }
  44488. ExpectIntEQ(ret, 0);
  44489. ExpectIntNE(pkcs7->contentSz, 0);
  44490. ExpectNotNull(pkcs7->contentDynamic);
  44491. wc_PKCS7_Free(pkcs7);
  44492. pkcs7 = NULL;
  44493. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44494. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44495. #endif /* !NO_PKCS7_STREAM */
  44496. XFREE(output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44497. }
  44498. /* Pass in bad args. */
  44499. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44500. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44501. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44502. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44503. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44504. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44505. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44506. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44507. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44508. outputHead, NULL, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44509. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44510. outputHead, &outputHeadSz, NULL, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44511. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44512. outputHead, &outputHeadSz, outputFoot, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44513. if (pkcs7 != NULL) {
  44514. pkcs7->hashOID = 0; /* bad hashOID */
  44515. }
  44516. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44517. outputHead, &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44518. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44519. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44520. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44521. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44522. #ifndef NO_PKCS7_STREAM
  44523. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44524. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44525. #else
  44526. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44527. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BUFFER_E));
  44528. #endif
  44529. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44530. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44531. #ifndef NO_PKCS7_STREAM
  44532. /* can pass in 0 buffer length with streaming API */
  44533. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44534. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44535. #else
  44536. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44537. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44538. #endif
  44539. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44540. outputHead, outputHeadSz, NULL, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44541. #ifndef NO_PKCS7_STREAM
  44542. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44543. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44544. #else
  44545. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44546. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(BUFFER_E));
  44547. #endif
  44548. wc_PKCS7_Free(pkcs7);
  44549. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44550. #endif
  44551. return EXPECT_RESULT();
  44552. } /* END test_wc_PKCS7_EncodeSignedData_ex */
  44553. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  44554. /**
  44555. * Loads certs/keys from files or buffers into the argument buffers,
  44556. * helper function called by CreatePKCS7SignedData().
  44557. *
  44558. * Returns 0 on success, negative on error.
  44559. */
  44560. static int LoadPKCS7SignedDataCerts(
  44561. int useIntermediateCertChain, int pkAlgoType,
  44562. byte* intCARoot, word32* intCARootSz,
  44563. byte* intCA1, word32* intCA1Sz,
  44564. byte* intCA2, word32* intCA2Sz,
  44565. byte* cert, word32* certSz,
  44566. byte* key, word32* keySz)
  44567. {
  44568. EXPECT_DECLS;
  44569. int ret = 0;
  44570. XFILE fp = XBADFILE;
  44571. #ifndef NO_RSA
  44572. const char* intCARootRSA = "./certs/ca-cert.der";
  44573. const char* intCA1RSA = "./certs/intermediate/ca-int-cert.der";
  44574. const char* intCA2RSA = "./certs/intermediate/ca-int2-cert.der";
  44575. const char* intServCertRSA = "./certs/intermediate/server-int-cert.der";
  44576. const char* intServKeyRSA = "./certs/server-key.der";
  44577. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)
  44578. const char* cli1024Cert = "./certs/1024/client-cert.der";
  44579. const char* cli1024Key = "./certs/1024/client-key.der";
  44580. #endif
  44581. #endif
  44582. #ifdef HAVE_ECC
  44583. const char* intCARootECC = "./certs/ca-ecc-cert.der";
  44584. const char* intCA1ECC = "./certs/intermediate/ca-int-ecc-cert.der";
  44585. const char* intCA2ECC = "./certs/intermediate/ca-int2-ecc-cert.der";
  44586. const char* intServCertECC = "./certs/intermediate/server-int-ecc-cert.der";
  44587. const char* intServKeyECC = "./certs/ecc-key.der";
  44588. #ifndef USE_CERT_BUFFERS_256
  44589. const char* cliEccCert = "./certs/client-ecc-cert.der";
  44590. const char* cliEccKey = "./certs/client-ecc-key.der";
  44591. #endif
  44592. #endif
  44593. if (cert == NULL || certSz == NULL || key == NULL || keySz == NULL ||
  44594. ((useIntermediateCertChain == 1) &&
  44595. (intCARoot == NULL || intCARootSz == NULL || intCA1 == NULL ||
  44596. intCA1Sz == NULL || intCA2 == NULL || intCA2Sz == NULL))) {
  44597. return BAD_FUNC_ARG;
  44598. }
  44599. /* Read/load certs and keys to use for signing based on PK type and chain */
  44600. switch (pkAlgoType) {
  44601. #ifndef NO_RSA
  44602. case RSA_TYPE:
  44603. if (useIntermediateCertChain == 1) {
  44604. ExpectTrue((fp = XFOPEN(intCARootRSA, "rb")) != XBADFILE);
  44605. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
  44606. if (fp != XBADFILE) {
  44607. XFCLOSE(fp);
  44608. fp = XBADFILE;
  44609. }
  44610. ExpectIntGT(*intCARootSz, 0);
  44611. ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
  44612. if (fp != XBADFILE) {
  44613. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  44614. XFCLOSE(fp);
  44615. fp = XBADFILE;
  44616. }
  44617. ExpectIntGT(*intCA1Sz, 0);
  44618. ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
  44619. if (fp != XBADFILE) {
  44620. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  44621. XFCLOSE(fp);
  44622. fp = XBADFILE;
  44623. }
  44624. ExpectIntGT(*intCA2Sz, 0);
  44625. ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
  44626. if (fp != XBADFILE) {
  44627. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44628. XFCLOSE(fp);
  44629. fp = XBADFILE;
  44630. }
  44631. ExpectIntGT(*certSz, 0);
  44632. ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
  44633. if (fp != XBADFILE) {
  44634. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44635. XFCLOSE(fp);
  44636. fp = XBADFILE;
  44637. }
  44638. ExpectIntGT(*keySz, 0);
  44639. }
  44640. else {
  44641. #if defined(USE_CERT_BUFFERS_2048)
  44642. *keySz = sizeof_client_key_der_2048;
  44643. *certSz = sizeof_client_cert_der_2048;
  44644. XMEMCPY(key, client_key_der_2048, *keySz);
  44645. XMEMCPY(cert, client_cert_der_2048, *certSz);
  44646. #elif defined(USE_CERT_BUFFERS_1024)
  44647. *keySz = sizeof_client_key_der_1024;
  44648. *certSz = sizeof_client_cert_der_1024;
  44649. XMEMCPY(key, client_key_der_1024, *keySz);
  44650. XMEMCPY(cert, client_cert_der_1024, *certSz);
  44651. #else
  44652. ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
  44653. if (fp != XBADFILE) {
  44654. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44655. XFCLOSE(fp);
  44656. fp = XBADFILE;
  44657. }
  44658. ExpectIntGT(*keySz, 0);
  44659. ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
  44660. if (fp != XBADFILE) {
  44661. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44662. XFCLOSE(fp);
  44663. fp = XBADFILE;
  44664. }
  44665. ExpectIntGT(*certSz, 0);
  44666. #endif /* USE_CERT_BUFFERS_2048 */
  44667. }
  44668. break;
  44669. #endif /* !NO_RSA */
  44670. #ifdef HAVE_ECC
  44671. case ECC_TYPE:
  44672. if (useIntermediateCertChain == 1) {
  44673. ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
  44674. if (fp != XBADFILE) {
  44675. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
  44676. fp);
  44677. XFCLOSE(fp);
  44678. fp = XBADFILE;
  44679. }
  44680. ExpectIntGT(*intCARootSz, 0);
  44681. ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
  44682. if (fp != XBADFILE) {
  44683. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  44684. XFCLOSE(fp);
  44685. fp = XBADFILE;
  44686. }
  44687. ExpectIntGT(*intCA1Sz, 0);
  44688. ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
  44689. if (fp != XBADFILE) {
  44690. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  44691. XFCLOSE(fp);
  44692. fp = XBADFILE;
  44693. }
  44694. ExpectIntGT(*intCA2Sz, 0);
  44695. ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
  44696. if (fp != XBADFILE) {
  44697. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44698. XFCLOSE(fp);
  44699. fp = XBADFILE;
  44700. }
  44701. ExpectIntGT(*certSz, 0);
  44702. ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
  44703. if (fp != XBADFILE) {
  44704. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44705. XFCLOSE(fp);
  44706. fp = XBADFILE;
  44707. }
  44708. ExpectIntGT(*keySz, 0);
  44709. }
  44710. else {
  44711. #if defined(USE_CERT_BUFFERS_256)
  44712. *keySz = sizeof_ecc_clikey_der_256;
  44713. *certSz = sizeof_cliecc_cert_der_256;
  44714. XMEMCPY(key, ecc_clikey_der_256, *keySz);
  44715. XMEMCPY(cert, cliecc_cert_der_256, *certSz);
  44716. #else
  44717. ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
  44718. if (fp != XBADFILE) {
  44719. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44720. XFCLOSE(fp);
  44721. fp = XBADFILE;
  44722. }
  44723. ExpectIntGT(*keySz, 0);
  44724. ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
  44725. if (fp != XBADFILE) {
  44726. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44727. XFCLOSE(fp);
  44728. fp = XBADFILE;
  44729. }
  44730. ExpectIntGT(*certSz, 0);
  44731. #endif /* USE_CERT_BUFFERS_256 */
  44732. }
  44733. break;
  44734. #endif /* HAVE_ECC */
  44735. default:
  44736. WOLFSSL_MSG("Unsupported SignedData PK type");
  44737. ret = BAD_FUNC_ARG;
  44738. break;
  44739. }
  44740. if (EXPECT_FAIL() && (ret == 0)) {
  44741. ret = BAD_FUNC_ARG;
  44742. }
  44743. return ret;
  44744. }
  44745. /**
  44746. * Creates a PKCS7/CMS SignedData bundle to use for testing.
  44747. *
  44748. * output output buffer to place SignedData
  44749. * outputSz size of output buffer
  44750. * data data buffer to be signed
  44751. * dataSz size of data buffer
  44752. * withAttribs [1/0] include attributes in SignedData message
  44753. * detachedSig [1/0] create detached signature, no content
  44754. * useIntCertChain [1/0] use certificate chain and include intermediate and
  44755. * root CAs in bundle
  44756. * pkAlgoType RSA_TYPE or ECC_TYPE, choose what key/cert type to use
  44757. *
  44758. * Return size of bundle created on success, negative on error */
  44759. static int CreatePKCS7SignedData(unsigned char* output, int outputSz,
  44760. byte* data, word32 dataSz,
  44761. int withAttribs, int detachedSig,
  44762. int useIntermediateCertChain,
  44763. int pkAlgoType)
  44764. {
  44765. EXPECT_DECLS;
  44766. int ret = 0;
  44767. WC_RNG rng;
  44768. PKCS7* pkcs7 = NULL;
  44769. static byte messageTypeOid[] =
  44770. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  44771. 0x09, 0x02 };
  44772. static byte messageType[] = { 0x13, 2, '1', '9' };
  44773. PKCS7Attrib attribs[] =
  44774. {
  44775. { messageTypeOid, sizeof(messageTypeOid), messageType,
  44776. sizeof(messageType) }
  44777. };
  44778. byte intCARoot[TWOK_BUF];
  44779. byte intCA1[TWOK_BUF];
  44780. byte intCA2[TWOK_BUF];
  44781. byte cert[TWOK_BUF];
  44782. byte key[TWOK_BUF];
  44783. word32 intCARootSz = sizeof(intCARoot);
  44784. word32 intCA1Sz = sizeof(intCA1);
  44785. word32 intCA2Sz = sizeof(intCA2);
  44786. word32 certSz = sizeof(cert);
  44787. word32 keySz = sizeof(key);
  44788. XMEMSET(intCARoot, 0, intCARootSz);
  44789. XMEMSET(intCA1, 0, intCA1Sz);
  44790. XMEMSET(intCA2, 0, intCA2Sz);
  44791. XMEMSET(cert, 0, certSz);
  44792. XMEMSET(key, 0, keySz);
  44793. ret = LoadPKCS7SignedDataCerts(useIntermediateCertChain, pkAlgoType,
  44794. intCARoot, &intCARootSz, intCA1, &intCA1Sz, intCA2, &intCA2Sz,
  44795. cert, &certSz, key, &keySz);
  44796. ExpectIntEQ(ret, 0);
  44797. XMEMSET(output, 0, outputSz);
  44798. ExpectIntEQ(wc_InitRng(&rng), 0);
  44799. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44800. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44801. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44802. if (useIntermediateCertChain == 1) {
  44803. /* Add intermediate and root CA certs into SignedData Certs SET */
  44804. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA2, intCA2Sz), 0);
  44805. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA1, intCA1Sz), 0);
  44806. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCARoot, intCARootSz), 0);
  44807. }
  44808. if (pkcs7 != NULL) {
  44809. pkcs7->content = data;
  44810. pkcs7->contentSz = dataSz;
  44811. pkcs7->privateKey = key;
  44812. pkcs7->privateKeySz = (word32)sizeof(key);
  44813. if (pkAlgoType == RSA_TYPE) {
  44814. pkcs7->encryptOID = RSAk;
  44815. }
  44816. else {
  44817. pkcs7->encryptOID = ECDSAk;
  44818. }
  44819. #ifdef NO_SHA
  44820. pkcs7->hashOID = SHA256h;
  44821. #else
  44822. pkcs7->hashOID = SHAh;
  44823. #endif
  44824. pkcs7->rng = &rng;
  44825. if (withAttribs) {
  44826. /* include a signed attribute */
  44827. pkcs7->signedAttribs = attribs;
  44828. pkcs7->signedAttribsSz = (sizeof(attribs)/sizeof(PKCS7Attrib));
  44829. }
  44830. }
  44831. if (detachedSig) {
  44832. ExpectIntEQ(wc_PKCS7_SetDetached(pkcs7, 1), 0);
  44833. }
  44834. outputSz = wc_PKCS7_EncodeSignedData(pkcs7, output, (word32)outputSz);
  44835. ExpectIntGT(outputSz, 0);
  44836. wc_PKCS7_Free(pkcs7);
  44837. pkcs7 = NULL;
  44838. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44839. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44840. if (detachedSig && (pkcs7 != NULL)) {
  44841. pkcs7->content = data;
  44842. pkcs7->contentSz = dataSz;
  44843. }
  44844. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)outputSz), 0);
  44845. wc_PKCS7_Free(pkcs7);
  44846. wc_FreeRng(&rng);
  44847. if (EXPECT_FAIL()) {
  44848. outputSz = 0;
  44849. }
  44850. return outputSz;
  44851. }
  44852. #endif
  44853. /*
  44854. * Testing wc_PKCS_VerifySignedData()
  44855. */
  44856. static int test_wc_PKCS7_VerifySignedData_RSA(void)
  44857. {
  44858. EXPECT_DECLS;
  44859. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  44860. PKCS7* pkcs7 = NULL;
  44861. byte output[6000]; /* Large size needed for bundles with int CA certs */
  44862. word32 outputSz = sizeof(output);
  44863. byte data[] = "Test data to encode.";
  44864. byte badOut[1];
  44865. word32 badOutSz = 0;
  44866. byte badContent[] = "This is different content than was signed";
  44867. wc_HashAlg hash;
  44868. #ifdef NO_SHA
  44869. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  44870. #else
  44871. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  44872. #endif
  44873. byte hashBuf[WC_MAX_DIGEST_SIZE];
  44874. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  44875. #ifndef NO_RSA
  44876. PKCS7DecodedAttrib* decodedAttrib = NULL;
  44877. /* contentType OID (1.2.840.113549.1.9.3) */
  44878. static const byte contentTypeOid[] =
  44879. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01, 0x09, 0x03 };
  44880. /* PKCS#7 DATA content type (contentType defaults to DATA) */
  44881. static const byte dataType[] =
  44882. { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01 };
  44883. /* messageDigest OID (1.2.840.113549.1.9.4) */
  44884. static const byte messageDigestOid[] =
  44885. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04 };
  44886. #ifndef NO_ASN_TIME
  44887. /* signingTime OID () */
  44888. static const byte signingTimeOid[] =
  44889. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05};
  44890. #endif
  44891. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  44892. int dateLength = 0;
  44893. byte dateFormat;
  44894. const byte* datePart = NULL;
  44895. struct tm timearg;
  44896. time_t now;
  44897. struct tm* nowTm = NULL;
  44898. #ifdef NEED_TMP_TIME
  44899. struct tm tmpTimeStorage;
  44900. struct tm* tmpTime = &tmpTimeStorage;
  44901. #endif
  44902. #endif /* !NO_ASN && !NO_ASN_TIME */
  44903. #ifndef NO_PKCS7_STREAM
  44904. word32 z;
  44905. int ret;
  44906. #endif /* !NO_PKCS7_STREAM */
  44907. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  44908. /* Success test with RSA certs/key */
  44909. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  44910. (word32)sizeof(data), 0, 0, 0, RSA_TYPE)), 0);
  44911. /* calculate hash for content, used later */
  44912. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  44913. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  44914. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  44915. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  44916. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44917. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44918. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44919. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44920. #ifndef NO_PKCS7_STREAM
  44921. wc_PKCS7_Free(pkcs7);
  44922. pkcs7 = NULL;
  44923. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44924. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44925. /* test for streaming */
  44926. ret = -1;
  44927. for (z = 0; z < outputSz && ret != 0; z++) {
  44928. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44929. if (ret < 0){
  44930. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44931. }
  44932. }
  44933. ExpectIntEQ(ret, 0);
  44934. ExpectIntNE(pkcs7->contentSz, 0);
  44935. ExpectNotNull(pkcs7->contentDynamic);
  44936. #endif /* !NO_PKCS7_STREAM */
  44937. /* Check that decoded signed attributes are correct */
  44938. /* messageDigest should be first */
  44939. if (pkcs7 != NULL) {
  44940. decodedAttrib = pkcs7->decodedAttrib;
  44941. }
  44942. ExpectNotNull(decodedAttrib);
  44943. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(messageDigestOid));
  44944. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, messageDigestOid,
  44945. decodedAttrib->oidSz), 0);
  44946. /* + 2 for OCTET STRING and length bytes */
  44947. ExpectIntEQ(decodedAttrib->valueSz, hashSz + 2);
  44948. ExpectNotNull(decodedAttrib->value);
  44949. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, hashBuf, hashSz), 0);
  44950. #ifndef NO_ASN_TIME
  44951. /* signingTime should be second */
  44952. if (decodedAttrib != NULL) {
  44953. decodedAttrib = decodedAttrib->next;
  44954. }
  44955. ExpectNotNull(decodedAttrib);
  44956. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(signingTimeOid));
  44957. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, signingTimeOid,
  44958. decodedAttrib->oidSz), 0);
  44959. ExpectIntGT(decodedAttrib->valueSz, 0);
  44960. ExpectNotNull(decodedAttrib->value);
  44961. #endif
  44962. /* Verify signingTime if ASN and time are available */
  44963. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  44964. ExpectIntEQ(wc_GetDateInfo(decodedAttrib->value, decodedAttrib->valueSz,
  44965. &datePart, &dateFormat, &dateLength), 0);
  44966. ExpectNotNull(datePart);
  44967. ExpectIntGT(dateLength, 0);
  44968. XMEMSET(&timearg, 0, sizeof(timearg));
  44969. ExpectIntEQ(wc_GetDateAsCalendarTime(datePart, dateLength, dateFormat,
  44970. &timearg), 0);
  44971. /* Get current time and compare year/month/day against attribute value */
  44972. ExpectIntEQ(wc_GetTime(&now, sizeof(now)), 0);
  44973. nowTm = (struct tm*)XGMTIME((time_t*)&now, tmpTime);
  44974. ExpectNotNull(nowTm);
  44975. ExpectIntEQ(timearg.tm_year, nowTm->tm_year);
  44976. ExpectIntEQ(timearg.tm_mon, nowTm->tm_mon);
  44977. ExpectIntEQ(timearg.tm_mday, nowTm->tm_mday);
  44978. #endif /* !NO_ASN && !NO_ASN_TIME */
  44979. /* contentType should be third */
  44980. if (decodedAttrib != NULL) {
  44981. decodedAttrib = decodedAttrib->next;
  44982. }
  44983. ExpectNotNull(decodedAttrib);
  44984. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(contentTypeOid));
  44985. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, contentTypeOid,
  44986. decodedAttrib->oidSz), 0);
  44987. ExpectIntEQ(decodedAttrib->valueSz, (int)sizeof(dataType) + 2);
  44988. ExpectNotNull(decodedAttrib->value);
  44989. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, dataType, sizeof(dataType)),
  44990. 0);
  44991. #endif /* !NO_RSA */
  44992. /* Test bad args. */
  44993. ExpectIntEQ(wc_PKCS7_VerifySignedData(NULL, output, outputSz),
  44994. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44995. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, NULL, outputSz),
  44996. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44997. #ifndef NO_PKCS7_STREAM
  44998. /* can pass in 0 buffer length with streaming API */
  44999. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45000. badOutSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45001. #else
  45002. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45003. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45004. #endif
  45005. wc_PKCS7_Free(pkcs7);
  45006. pkcs7 = NULL;
  45007. #ifndef NO_RSA
  45008. /* Try RSA certs/key/sig first */
  45009. outputSz = sizeof(output);
  45010. XMEMSET(output, 0, outputSz);
  45011. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45012. (word32)sizeof(data),
  45013. 1, 1, 0, RSA_TYPE)), 0);
  45014. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45015. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45016. if (pkcs7 != NULL) {
  45017. pkcs7->content = badContent;
  45018. pkcs7->contentSz = sizeof(badContent);
  45019. }
  45020. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45021. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45022. wc_PKCS7_Free(pkcs7);
  45023. pkcs7 = NULL;
  45024. #ifndef NO_PKCS7_STREAM
  45025. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45026. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45027. if (pkcs7 != NULL) {
  45028. pkcs7->content = badContent;
  45029. pkcs7->contentSz = sizeof(badContent);
  45030. }
  45031. /* test for streaming */
  45032. ret = -1;
  45033. for (z = 0; z < outputSz && ret != 0; z++) {
  45034. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45035. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45036. continue;
  45037. }
  45038. else if (ret < 0) {
  45039. break;
  45040. }
  45041. }
  45042. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45043. ExpectIntNE(pkcs7->contentSz, 0);
  45044. ExpectNotNull(pkcs7->contentDynamic);
  45045. wc_PKCS7_Free(pkcs7);
  45046. pkcs7 = NULL;
  45047. #endif /* !NO_PKCS7_STREAM */
  45048. /* Test success case with detached signature and valid content */
  45049. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45050. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45051. if (pkcs7 != NULL) {
  45052. pkcs7->content = data;
  45053. pkcs7->contentSz = sizeof(data);
  45054. }
  45055. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45056. wc_PKCS7_Free(pkcs7);
  45057. pkcs7 = NULL;
  45058. #ifndef NO_PKCS7_STREAM
  45059. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45060. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45061. if (pkcs7 != NULL) {
  45062. pkcs7->content = data;
  45063. pkcs7->contentSz = sizeof(data);
  45064. }
  45065. /* test for streaming */
  45066. ret = -1;
  45067. for (z = 0; z < outputSz && ret != 0; z++) {
  45068. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45069. if (ret < 0){
  45070. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45071. }
  45072. }
  45073. ExpectIntEQ(ret, 0);
  45074. ExpectIntNE(pkcs7->contentSz, 0);
  45075. ExpectNotNull(pkcs7->contentDynamic);
  45076. wc_PKCS7_Free(pkcs7);
  45077. pkcs7 = NULL;
  45078. #endif /* !NO_PKCS7_STREAM */
  45079. /* verify using pre-computed content digest only (no content) */
  45080. {
  45081. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45082. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45083. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45084. output, outputSz, NULL, 0), 0);
  45085. wc_PKCS7_Free(pkcs7);
  45086. pkcs7 = NULL;
  45087. }
  45088. #endif /* !NO_RSA */
  45089. /* Test verify on signedData containing intermediate/root CA certs */
  45090. #ifndef NO_RSA
  45091. outputSz = sizeof(output);
  45092. XMEMSET(output, 0, outputSz);
  45093. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45094. (word32)sizeof(data),
  45095. 0, 0, 1, RSA_TYPE)), 0);
  45096. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45097. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45098. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45099. wc_PKCS7_Free(pkcs7);
  45100. pkcs7 = NULL;
  45101. #ifndef NO_PKCS7_STREAM
  45102. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45103. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45104. /* test for streaming */
  45105. ret = -1;
  45106. for (z = 0; z < outputSz && ret != 0; z++) {
  45107. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45108. if (ret < 0){
  45109. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45110. }
  45111. }
  45112. ExpectIntEQ(ret, 0);
  45113. ExpectIntNE(pkcs7->contentSz, 0);
  45114. ExpectNotNull(pkcs7->contentDynamic);
  45115. wc_PKCS7_Free(pkcs7);
  45116. pkcs7 = NULL;
  45117. #endif /* !NO_PKCS7_STREAM */
  45118. #endif /* !NO_RSA */
  45119. #if defined(ASN_BER_TO_DER) && !defined(NO_PKCS7_STREAM) && \
  45120. !defined(NO_FILESYSTEM)
  45121. {
  45122. XFILE signedBundle = XBADFILE;
  45123. int signedBundleSz = 0;
  45124. int chunkSz = 1;
  45125. int i, rc = 0;
  45126. byte* buf = NULL;
  45127. ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",
  45128. "rb")) != XBADFILE);
  45129. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_END) == 0);
  45130. ExpectIntGT(signedBundleSz = (int)XFTELL(signedBundle), 0);
  45131. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_SET) == 0);
  45132. ExpectNotNull(buf = (byte*)XMALLOC(signedBundleSz, HEAP_HINT,
  45133. DYNAMIC_TYPE_FILE));
  45134. if (buf != NULL) {
  45135. ExpectIntEQ(XFREAD(buf, 1, (size_t)signedBundleSz, signedBundle),
  45136. signedBundleSz);
  45137. }
  45138. if (signedBundle != XBADFILE) {
  45139. XFCLOSE(signedBundle);
  45140. signedBundle = XBADFILE;
  45141. }
  45142. if (buf != NULL) {
  45143. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45144. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45145. for (i = 0; i < signedBundleSz;) {
  45146. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45147. chunkSz;
  45148. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45149. if (rc < 0 ) {
  45150. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45151. i += sz;
  45152. continue;
  45153. }
  45154. break;
  45155. }
  45156. else {
  45157. break;
  45158. }
  45159. }
  45160. ExpectIntEQ(rc, WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  45161. wc_PKCS7_Free(pkcs7);
  45162. pkcs7 = NULL;
  45163. }
  45164. /* now try with malformed bundle */
  45165. if (buf != NULL) {
  45166. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45167. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45168. buf[signedBundleSz - 2] = buf[signedBundleSz - 2] + 1;
  45169. for (i = 0; i < signedBundleSz;) {
  45170. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45171. chunkSz;
  45172. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45173. if (rc < 0 ) {
  45174. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45175. i += sz;
  45176. continue;
  45177. }
  45178. break;
  45179. }
  45180. else {
  45181. break;
  45182. }
  45183. }
  45184. ExpectIntEQ(rc, WC_NO_ERR_TRACE(ASN_PARSE_E));
  45185. wc_PKCS7_Free(pkcs7);
  45186. pkcs7 = NULL;
  45187. }
  45188. if (buf != NULL)
  45189. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  45190. }
  45191. #endif /* BER and stream */
  45192. #endif
  45193. return EXPECT_RESULT();
  45194. } /* END test_wc_PKCS7_VerifySignedData()_RSA */
  45195. /*
  45196. * Testing wc_PKCS_VerifySignedData()
  45197. */
  45198. static int test_wc_PKCS7_VerifySignedData_ECC(void)
  45199. {
  45200. EXPECT_DECLS;
  45201. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  45202. PKCS7* pkcs7 = NULL;
  45203. byte output[6000]; /* Large size needed for bundles with int CA certs */
  45204. word32 outputSz = sizeof(output);
  45205. byte data[] = "Test data to encode.";
  45206. byte badContent[] = "This is different content than was signed";
  45207. wc_HashAlg hash;
  45208. #ifndef NO_PKCS7_STREAM
  45209. word32 z;
  45210. int ret;
  45211. #endif /* !NO_PKCS7_STREAM */
  45212. #ifdef NO_SHA
  45213. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45214. #else
  45215. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45216. #endif
  45217. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45218. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45219. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45220. /* Success test with ECC certs/key */
  45221. outputSz = sizeof(output);
  45222. XMEMSET(output, 0, outputSz);
  45223. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45224. (word32)sizeof(data), 0, 0, 0, ECC_TYPE)), 0);
  45225. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45226. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45227. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45228. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45229. wc_PKCS7_Free(pkcs7);
  45230. pkcs7 = NULL;
  45231. #ifndef NO_PKCS7_STREAM
  45232. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45233. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45234. /* test for streaming */
  45235. ret = -1;
  45236. for (z = 0; z < outputSz && ret != 0; z++) {
  45237. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45238. if (ret < 0){
  45239. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45240. }
  45241. }
  45242. ExpectIntEQ(ret, 0);
  45243. ExpectIntNE(pkcs7->contentSz, 0);
  45244. ExpectNotNull(pkcs7->contentDynamic);
  45245. wc_PKCS7_Free(pkcs7);
  45246. pkcs7 = NULL;
  45247. #endif /* !NO_PKCS7_STREAM */
  45248. /* Invalid content should error, use detached signature so we can
  45249. * easily change content */
  45250. outputSz = sizeof(output);
  45251. XMEMSET(output, 0, outputSz);
  45252. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45253. (word32)sizeof(data), 1, 1, 0, ECC_TYPE)), 0);
  45254. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45255. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45256. if (pkcs7 != NULL) {
  45257. pkcs7->content = badContent;
  45258. pkcs7->contentSz = sizeof(badContent);
  45259. }
  45260. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45261. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45262. wc_PKCS7_Free(pkcs7);
  45263. pkcs7 = NULL;
  45264. #ifndef NO_PKCS7_STREAM
  45265. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45266. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45267. if (pkcs7 != NULL) {
  45268. pkcs7->content = badContent;
  45269. pkcs7->contentSz = sizeof(badContent);
  45270. }
  45271. /* test for streaming */
  45272. ret = -1;
  45273. for (z = 0; z < outputSz && ret != 0; z++) {
  45274. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45275. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45276. continue;
  45277. }
  45278. else if (ret < 0) {
  45279. break;
  45280. }
  45281. }
  45282. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45283. ExpectIntNE(pkcs7->contentSz, 0);
  45284. ExpectNotNull(pkcs7->contentDynamic);
  45285. wc_PKCS7_Free(pkcs7);
  45286. pkcs7 = NULL;
  45287. #endif /* !NO_PKCS7_STREAM */
  45288. /* Test success case with detached signature and valid content */
  45289. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45290. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45291. if (pkcs7 != NULL) {
  45292. pkcs7->content = data;
  45293. pkcs7->contentSz = sizeof(data);
  45294. }
  45295. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45296. wc_PKCS7_Free(pkcs7);
  45297. pkcs7 = NULL;
  45298. #ifndef NO_PKCS7_STREAM
  45299. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45300. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45301. if (pkcs7 != NULL) {
  45302. pkcs7->content = data;
  45303. pkcs7->contentSz = sizeof(data);
  45304. }
  45305. /* test for streaming */
  45306. ret = -1;
  45307. for (z = 0; z < outputSz && ret != 0; z++) {
  45308. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45309. if (ret < 0){
  45310. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45311. }
  45312. }
  45313. ExpectIntEQ(ret, 0);
  45314. ExpectIntNE(pkcs7->contentSz, 0);
  45315. ExpectNotNull(pkcs7->contentDynamic);
  45316. wc_PKCS7_Free(pkcs7);
  45317. pkcs7 = NULL;
  45318. #endif /* !NO_PKCS7_STREAM */
  45319. /* verify using pre-computed content digest only (no content) */
  45320. {
  45321. /* calculate hash for content */
  45322. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45323. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45324. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45325. ExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45326. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45327. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45328. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45329. output, outputSz, NULL, 0), 0);
  45330. wc_PKCS7_Free(pkcs7);
  45331. pkcs7 = NULL;
  45332. }
  45333. /* Test verify on signedData containing intermediate/root CA certs */
  45334. outputSz = sizeof(output);
  45335. XMEMSET(output, 0, outputSz);
  45336. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45337. (word32)sizeof(data), 0, 0, 1, ECC_TYPE)), 0);
  45338. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45339. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45340. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45341. wc_PKCS7_Free(pkcs7);
  45342. pkcs7 = NULL;
  45343. #ifndef NO_PKCS7_STREAM
  45344. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45345. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45346. /* test for streaming */
  45347. ret = -1;
  45348. for (z = 0; z < outputSz && ret != 0; z++) {
  45349. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45350. if (ret < 0){
  45351. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45352. }
  45353. }
  45354. ExpectIntEQ(ret, 0);
  45355. ExpectIntNE(pkcs7->contentSz, 0);
  45356. ExpectNotNull(pkcs7->contentDynamic);
  45357. wc_PKCS7_Free(pkcs7);
  45358. pkcs7 = NULL;
  45359. #endif /* !NO_PKCS7_STREAM */
  45360. #endif
  45361. return EXPECT_RESULT();
  45362. } /* END test_wc_PKCS7_VerifySignedData_ECC() */
  45363. #if defined(HAVE_PKCS7) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  45364. !defined(NO_AES_256)
  45365. static const byte defKey[] = {
  45366. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45367. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45368. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45369. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45370. };
  45371. static byte aesHandle[32]; /* simulated hardware key handle */
  45372. /* return 0 on success */
  45373. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45374. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45375. byte* in, int inSz, byte* out, void* usrCtx)
  45376. {
  45377. int ret;
  45378. Aes aes;
  45379. if (usrCtx == NULL) {
  45380. /* no simulated handle passed in */
  45381. return -1;
  45382. }
  45383. switch (encryptOID) {
  45384. case AES256CBCb:
  45385. if (ivSz != AES_BLOCK_SIZE)
  45386. return BAD_FUNC_ARG;
  45387. break;
  45388. default:
  45389. WOLFSSL_MSG("Unsupported content cipher type for test");
  45390. return ALGO_ID_E;
  45391. };
  45392. /* simulate using handle to get key */
  45393. ret = wc_AesInit(&aes, HEAP_HINT, INVALID_DEVID);
  45394. if (ret == 0) {
  45395. ret = wc_AesSetKey(&aes, (byte*)usrCtx, 32, iv, AES_DECRYPTION);
  45396. if (ret == 0)
  45397. ret = wc_AesCbcDecrypt(&aes, out, in, (word32)inSz);
  45398. wc_AesFree(&aes);
  45399. }
  45400. (void)aad;
  45401. (void)aadSz;
  45402. (void)authTag;
  45403. (void)authTagSz;
  45404. (void)pkcs7;
  45405. return ret;
  45406. }
  45407. /* returns key size on success */
  45408. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  45409. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  45410. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  45411. {
  45412. int ret = -1;
  45413. (void)cekSz;
  45414. (void)cek;
  45415. (void)outSz;
  45416. (void)keyIdSz;
  45417. (void)direction;
  45418. (void)orginKey; /* used with KAKRI */
  45419. (void)orginKeySz;
  45420. if (out == NULL)
  45421. return BAD_FUNC_ARG;
  45422. if (keyId[0] != 0x00) {
  45423. return -1;
  45424. }
  45425. if (type != (int)PKCS7_KEKRI) {
  45426. return -1;
  45427. }
  45428. switch (keyWrapAlgo) {
  45429. case AES256_WRAP:
  45430. /* simulate setting a handle for later decryption but use key
  45431. * as handle in the test case here */
  45432. ret = wc_AesKeyUnWrap(defKey, sizeof(defKey), cek, cekSz,
  45433. aesHandle, sizeof(aesHandle), NULL);
  45434. if (ret < 0)
  45435. return ret;
  45436. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)aesHandle);
  45437. if (ret < 0)
  45438. return ret;
  45439. /* return key size on success */
  45440. return sizeof(defKey);
  45441. default:
  45442. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  45443. return BAD_KEYWRAP_ALG_E;
  45444. };
  45445. }
  45446. #endif /* HAVE_PKCS7 && !NO_AES && HAVE_AES_CBC && !NO_AES_256 */
  45447. /*
  45448. * Testing wc_PKCS7_EncodeEnvelopedData()
  45449. */
  45450. static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
  45451. {
  45452. EXPECT_DECLS;
  45453. #if defined(HAVE_PKCS7)
  45454. PKCS7* pkcs7 = NULL;
  45455. #ifdef ASN_BER_TO_DER
  45456. int encodedSz = 0;
  45457. #endif
  45458. #ifdef ECC_TIMING_RESISTANT
  45459. WC_RNG rng;
  45460. #endif
  45461. word32 tempWrd32 = 0;
  45462. byte* tmpBytePtr = NULL;
  45463. const char input[] = "Test data to encode.";
  45464. int i;
  45465. int testSz = 0;
  45466. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) || \
  45467. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45468. byte* rsaCert = NULL;
  45469. byte* rsaPrivKey = NULL;
  45470. word32 rsaCertSz;
  45471. word32 rsaPrivKeySz;
  45472. #if !defined(NO_FILESYSTEM) && (!defined(USE_CERT_BUFFERS_1024) && \
  45473. !defined(USE_CERT_BUFFERS_2048) )
  45474. static const char* rsaClientCert = "./certs/client-cert.der";
  45475. static const char* rsaClientKey = "./certs/client-key.der";
  45476. rsaCertSz = (word32)sizeof(rsaClientCert);
  45477. rsaPrivKeySz = (word32)sizeof(rsaClientKey);
  45478. #endif
  45479. #endif
  45480. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45481. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45482. byte* eccCert = NULL;
  45483. byte* eccPrivKey = NULL;
  45484. word32 eccCertSz;
  45485. word32 eccPrivKeySz;
  45486. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_256)
  45487. static const char* eccClientCert = "./certs/client-ecc-cert.der";
  45488. static const char* eccClientKey = "./certs/ecc-client-key.der";
  45489. #endif
  45490. #endif
  45491. /* Generic buffer size. */
  45492. byte output[ONEK_BUF];
  45493. byte decoded[sizeof(input)/sizeof(char)];
  45494. int decodedSz = 0;
  45495. #ifndef NO_FILESYSTEM
  45496. XFILE certFile = XBADFILE;
  45497. XFILE keyFile = XBADFILE;
  45498. #endif
  45499. #ifdef ECC_TIMING_RESISTANT
  45500. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45501. #endif
  45502. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45503. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45504. /* RSA certs and keys. */
  45505. #if defined(USE_CERT_BUFFERS_1024)
  45506. rsaCertSz = (word32)sizeof_client_cert_der_1024;
  45507. /* Allocate buffer space. */
  45508. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45509. DYNAMIC_TYPE_TMP_BUFFER));
  45510. /* Init buffer. */
  45511. if (rsaCert != NULL) {
  45512. XMEMCPY(rsaCert, client_cert_der_1024, rsaCertSz);
  45513. }
  45514. rsaPrivKeySz = (word32)sizeof_client_key_der_1024;
  45515. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45516. DYNAMIC_TYPE_TMP_BUFFER));
  45517. if (rsaPrivKey != NULL) {
  45518. XMEMCPY(rsaPrivKey, client_key_der_1024, rsaPrivKeySz);
  45519. }
  45520. #elif defined(USE_CERT_BUFFERS_2048)
  45521. rsaCertSz = (word32)sizeof_client_cert_der_2048;
  45522. /* Allocate buffer */
  45523. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45524. DYNAMIC_TYPE_TMP_BUFFER));
  45525. /* Init buffer. */
  45526. if (rsaCert != NULL) {
  45527. XMEMCPY(rsaCert, client_cert_der_2048, rsaCertSz);
  45528. }
  45529. rsaPrivKeySz = (word32)sizeof_client_key_der_2048;
  45530. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45531. DYNAMIC_TYPE_TMP_BUFFER));
  45532. if (rsaPrivKey != NULL) {
  45533. XMEMCPY(rsaPrivKey, client_key_der_2048, rsaPrivKeySz);
  45534. }
  45535. #else
  45536. /* File system. */
  45537. ExpectTrue((certFile = XFOPEN(rsaClientCert, "rb")) != XBADFILE);
  45538. rsaCertSz = (word32)FOURK_BUF;
  45539. ExpectNotNull(rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45540. DYNAMIC_TYPE_TMP_BUFFER));
  45541. ExpectTrue((rsaCertSz = (word32)XFREAD(rsaCert, 1, rsaCertSz,
  45542. certFile)) > 0);
  45543. if (certFile != XBADFILE)
  45544. XFCLOSE(certFile);
  45545. ExpectTrue((keyFile = XFOPEN(rsaClientKey, "rb")) != XBADFILE);
  45546. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45547. DYNAMIC_TYPE_TMP_BUFFER));
  45548. rsaPrivKeySz = (word32)FOURK_BUF;
  45549. ExpectTrue((rsaPrivKeySz = (word32)XFREAD(rsaPrivKey, 1, rsaPrivKeySz,
  45550. keyFile)) > 0);
  45551. if (keyFile != XBADFILE)
  45552. XFCLOSE(keyFile);
  45553. #endif /* USE_CERT_BUFFERS */
  45554. #endif /* NO_RSA */
  45555. /* ECC */
  45556. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45557. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45558. #ifdef USE_CERT_BUFFERS_256
  45559. ExpectNotNull(eccCert = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  45560. DYNAMIC_TYPE_TMP_BUFFER));
  45561. /* Init buffer. */
  45562. eccCertSz = (word32)sizeof_cliecc_cert_der_256;
  45563. if (eccCert != NULL) {
  45564. XMEMCPY(eccCert, cliecc_cert_der_256, eccCertSz);
  45565. }
  45566. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  45567. DYNAMIC_TYPE_TMP_BUFFER));
  45568. eccPrivKeySz = (word32)sizeof_ecc_clikey_der_256;
  45569. if (eccPrivKey != NULL) {
  45570. XMEMCPY(eccPrivKey, ecc_clikey_der_256, eccPrivKeySz);
  45571. }
  45572. #else /* File system. */
  45573. ExpectTrue((certFile = XFOPEN(eccClientCert, "rb")) != XBADFILE);
  45574. eccCertSz = (word32)FOURK_BUF;
  45575. ExpectNotNull(eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45576. DYNAMIC_TYPE_TMP_BUFFER));
  45577. ExpectTrue((eccCertSz = (word32)XFREAD(eccCert, 1, eccCertSz,
  45578. certFile)) > 0);
  45579. if (certFile != XBADFILE) {
  45580. XFCLOSE(certFile);
  45581. }
  45582. ExpectTrue((keyFile = XFOPEN(eccClientKey, "rb")) != XBADFILE);
  45583. eccPrivKeySz = (word32)FOURK_BUF;
  45584. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45585. DYNAMIC_TYPE_TMP_BUFFER));
  45586. ExpectTrue((eccPrivKeySz = (word32)XFREAD(eccPrivKey, 1, eccPrivKeySz,
  45587. keyFile)) > 0);
  45588. if (keyFile != XBADFILE) {
  45589. XFCLOSE(keyFile);
  45590. }
  45591. #endif /* USE_CERT_BUFFERS_256 */
  45592. #endif /* END HAVE_ECC */
  45593. #ifndef NO_FILESYSTEM
  45594. /* Silence. */
  45595. (void)keyFile;
  45596. (void)certFile;
  45597. #endif
  45598. {
  45599. const pkcs7EnvelopedVector testVectors[] = {
  45600. /* DATA is a global variable defined in the makefile. */
  45601. #if !defined(NO_RSA)
  45602. #ifndef NO_DES3
  45603. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, DES3b, 0, 0,
  45604. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45605. #endif /* NO_DES3 */
  45606. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45607. #ifndef NO_AES_128
  45608. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES128CBCb,
  45609. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45610. #endif
  45611. #ifndef NO_AES_192
  45612. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES192CBCb,
  45613. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45614. #endif
  45615. #ifndef NO_AES_256
  45616. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES256CBCb,
  45617. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45618. #endif
  45619. #endif /* NO_AES && HAVE_AES_CBC */
  45620. #endif /* NO_RSA */
  45621. #if defined(HAVE_ECC)
  45622. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45623. #if !defined(NO_SHA) && !defined(NO_AES_128)
  45624. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  45625. AES128CBCb, AES128_WRAP, dhSinglePass_stdDH_sha1kdf_scheme,
  45626. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  45627. #endif
  45628. #if !defined(NO_SHA256) && !defined(NO_AES_256)
  45629. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  45630. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha256kdf_scheme,
  45631. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  45632. #endif
  45633. #if defined(WOLFSSL_SHA512) && !defined(NO_AES_256)
  45634. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  45635. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha512kdf_scheme,
  45636. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  45637. #endif
  45638. #endif /* NO_AES && HAVE_AES_CBC*/
  45639. #endif /* END HAVE_ECC */
  45640. }; /* END pkcs7EnvelopedVector */
  45641. #ifdef ECC_TIMING_RESISTANT
  45642. ExpectIntEQ(wc_InitRng(&rng), 0);
  45643. #endif
  45644. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45645. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  45646. testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
  45647. for (i = 0; i < testSz; i++) {
  45648. #ifdef ASN_BER_TO_DER
  45649. encodeSignedDataStream strm;
  45650. /* test setting stream mode, the first one using IO callbacks */
  45651. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  45652. (word32)(testVectors + i)->certSz), 0);
  45653. if (pkcs7 != NULL) {
  45654. #ifdef ECC_TIMING_RESISTANT
  45655. pkcs7->rng = &rng;
  45656. #endif
  45657. if (i != 0)
  45658. pkcs7->content = (byte*)(testVectors + i)->content;
  45659. pkcs7->contentSz = (testVectors + i)->contentSz;
  45660. pkcs7->contentOID = (testVectors + i)->contentOID;
  45661. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  45662. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  45663. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  45664. pkcs7->privateKey = (testVectors + i)->privateKey;
  45665. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  45666. }
  45667. if (i == 0) {
  45668. XMEMSET(&strm, 0, sizeof(strm));
  45669. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  45670. StreamOutputCB, (void*)&strm), 0);
  45671. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL, 0);
  45672. }
  45673. else {
  45674. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  45675. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  45676. (word32)sizeof(output));
  45677. }
  45678. switch ((testVectors + i)->encryptOID) {
  45679. #ifndef NO_DES3
  45680. case DES3b:
  45681. case DESb:
  45682. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45683. break;
  45684. #endif
  45685. #ifdef HAVE_AESCCM
  45686. #ifdef WOLFSSL_AES_128
  45687. case AES128CCMb:
  45688. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45689. break;
  45690. #endif
  45691. #ifdef WOLFSSL_AES_192
  45692. case AES192CCMb:
  45693. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45694. break;
  45695. #endif
  45696. #ifdef WOLFSSL_AES_256
  45697. case AES256CCMb:
  45698. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45699. break;
  45700. #endif
  45701. #endif
  45702. default:
  45703. ExpectIntGE(encodedSz, 0);
  45704. }
  45705. if (encodedSz > 0) {
  45706. if (i == 0) {
  45707. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7,
  45708. strm.out, (word32)encodedSz, decoded,
  45709. (word32)sizeof(decoded));
  45710. }
  45711. else {
  45712. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45713. (word32)encodedSz, decoded, (word32)sizeof(decoded));
  45714. }
  45715. ExpectIntGE(decodedSz, 0);
  45716. /* Verify the size of each buffer. */
  45717. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  45718. }
  45719. wc_PKCS7_Free(pkcs7);
  45720. pkcs7 = NULL;
  45721. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45722. #endif
  45723. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  45724. (word32)(testVectors + i)->certSz), 0);
  45725. if (pkcs7 != NULL) {
  45726. #ifdef ECC_TIMING_RESISTANT
  45727. pkcs7->rng = &rng;
  45728. #endif
  45729. pkcs7->content = (byte*)(testVectors + i)->content;
  45730. pkcs7->contentSz = (testVectors + i)->contentSz;
  45731. pkcs7->contentOID = (testVectors + i)->contentOID;
  45732. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  45733. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  45734. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  45735. pkcs7->privateKey = (testVectors + i)->privateKey;
  45736. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  45737. }
  45738. #ifdef ASN_BER_TO_DER
  45739. /* test without setting stream mode */
  45740. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  45741. #endif
  45742. ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  45743. (word32)sizeof(output)), 0);
  45744. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45745. (word32)sizeof(output), decoded, (word32)sizeof(decoded));
  45746. ExpectIntGE(decodedSz, 0);
  45747. /* Verify the size of each buffer. */
  45748. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  45749. /* Don't free the last time through the loop. */
  45750. if (i < testSz - 1) {
  45751. wc_PKCS7_Free(pkcs7);
  45752. pkcs7 = NULL;
  45753. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45754. }
  45755. } /* END test loop. */
  45756. }
  45757. /* Test bad args. */
  45758. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(NULL, output,
  45759. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45760. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL,
  45761. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45762. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45763. /* Decode. */
  45764. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(NULL, output,
  45765. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45766. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45767. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45768. (word32)sizeof(output), NULL, (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45769. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45770. (word32)sizeof(output), decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45771. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, NULL,
  45772. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45773. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45774. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output, 0, decoded,
  45775. (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45776. /* Should get a return of BAD_FUNC_ARG with structure data. Order matters.*/
  45777. #if defined(HAVE_ECC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  45778. /* only a failure for KARI test cases */
  45779. if (pkcs7 != NULL) {
  45780. tempWrd32 = pkcs7->singleCertSz;
  45781. pkcs7->singleCertSz = 0;
  45782. }
  45783. #if defined(WOLFSSL_ASN_TEMPLATE)
  45784. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45785. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45786. WC_NO_ERR_TRACE(BUFFER_E));
  45787. #else
  45788. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45789. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45790. WC_NO_ERR_TRACE(ASN_PARSE_E));
  45791. #endif
  45792. if (pkcs7 != NULL) {
  45793. pkcs7->singleCertSz = tempWrd32;
  45794. tmpBytePtr = pkcs7->singleCert;
  45795. pkcs7->singleCert = NULL;
  45796. }
  45797. #ifndef NO_RSA
  45798. #if defined(NO_PKCS7_STREAM)
  45799. /* when none streaming mode is used and PKCS7 is in bad state buffer error
  45800. * is returned from kari parse which gets set to bad func arg */
  45801. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45802. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45803. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45804. #else
  45805. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45806. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45807. WC_NO_ERR_TRACE(ASN_PARSE_E));
  45808. #endif
  45809. #endif /* !NO_RSA */
  45810. if (pkcs7 != NULL) {
  45811. pkcs7->singleCert = tmpBytePtr;
  45812. }
  45813. #endif
  45814. if (pkcs7 != NULL) {
  45815. tempWrd32 = pkcs7->privateKeySz;
  45816. pkcs7->privateKeySz = 0;
  45817. }
  45818. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45819. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45820. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45821. if (pkcs7 != NULL) {
  45822. pkcs7->privateKeySz = tempWrd32;
  45823. tmpBytePtr = pkcs7->privateKey;
  45824. pkcs7->privateKey = NULL;
  45825. }
  45826. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45827. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45828. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45829. if (pkcs7 != NULL) {
  45830. pkcs7->privateKey = tmpBytePtr;
  45831. }
  45832. wc_PKCS7_Free(pkcs7);
  45833. pkcs7 = NULL;
  45834. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
  45835. /* test of decrypt callback with KEKRI enveloped data */
  45836. {
  45837. int envelopedSz = 0;
  45838. const byte keyId[] = { 0x00 };
  45839. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45840. if (pkcs7 != NULL) {
  45841. pkcs7->content = (byte*)input;
  45842. pkcs7->contentSz = (word32)(sizeof(input)/sizeof(char));
  45843. pkcs7->contentOID = DATA;
  45844. pkcs7->encryptOID = AES256CBCb;
  45845. }
  45846. ExpectIntGT(wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP,
  45847. (byte*)defKey, sizeof(defKey), (byte*)keyId,
  45848. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0), 0);
  45849. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  45850. ExpectIntGT((envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  45851. (word32)sizeof(output))), 0);
  45852. wc_PKCS7_Free(pkcs7);
  45853. pkcs7 = NULL;
  45854. /* decode envelopedData */
  45855. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45856. ExpectIntEQ(wc_PKCS7_SetWrapCEKCb(pkcs7, myCEKwrapFunc), 0);
  45857. ExpectIntEQ(wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc), 0);
  45858. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45859. (word32)envelopedSz, decoded, sizeof(decoded))), 0);
  45860. wc_PKCS7_Free(pkcs7);
  45861. pkcs7 = NULL;
  45862. }
  45863. #endif /* !NO_AES && !NO_AES_256 */
  45864. #ifndef NO_RSA
  45865. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45866. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45867. #endif /* NO_RSA */
  45868. #ifdef HAVE_ECC
  45869. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45870. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45871. #endif /* HAVE_ECC */
  45872. #ifdef ECC_TIMING_RESISTANT
  45873. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45874. #endif
  45875. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DES3) && \
  45876. !defined(NO_RSA) && !defined(NO_SHA)
  45877. {
  45878. byte out[7];
  45879. byte *cms = NULL;
  45880. word32 cmsSz;
  45881. XFILE cmsFile = XBADFILE;
  45882. XMEMSET(out, 0, sizeof(out));
  45883. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45884. ExpectTrue((cmsFile = XFOPEN("./certs/test/ktri-keyid-cms.msg", "rb"))
  45885. != XBADFILE);
  45886. cmsSz = (word32)FOURK_BUF;
  45887. ExpectNotNull(cms = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45888. DYNAMIC_TYPE_TMP_BUFFER));
  45889. ExpectTrue((cmsSz = (word32)XFREAD(cms, 1, cmsSz, cmsFile)) > 0);
  45890. if (cmsFile != XBADFILE)
  45891. XFCLOSE(cmsFile);
  45892. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)client_cert_der_2048,
  45893. sizeof_client_cert_der_2048), 0);
  45894. if (pkcs7 != NULL) {
  45895. pkcs7->privateKey = (byte*)client_key_der_2048;
  45896. pkcs7->privateKeySz = sizeof_client_key_der_2048;
  45897. }
  45898. ExpectIntLT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  45899. 2), 0);
  45900. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  45901. sizeof(out)), 0);
  45902. XFREE(cms, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45903. ExpectIntEQ(XMEMCMP(out, "test", 4), 0);
  45904. wc_PKCS7_Free(pkcs7);
  45905. pkcs7 = NULL;
  45906. }
  45907. #endif /* USE_CERT_BUFFERS_2048 && !NO_DES3 && !NO_RSA && !NO_SHA */
  45908. #endif /* HAVE_PKCS7 */
  45909. return EXPECT_RESULT();
  45910. } /* END test_wc_PKCS7_EncodeDecodeEnvelopedData() */
  45911. /*
  45912. * Testing wc_PKCS7_EncodeEncryptedData()
  45913. */
  45914. static int test_wc_PKCS7_EncodeEncryptedData(void)
  45915. {
  45916. EXPECT_DECLS;
  45917. #if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
  45918. PKCS7* pkcs7 = NULL;
  45919. byte* tmpBytePtr = NULL;
  45920. byte encrypted[TWOK_BUF];
  45921. byte decoded[TWOK_BUF];
  45922. word32 tmpWrd32 = 0;
  45923. int tmpInt = 0;
  45924. int decodedSz = 0;
  45925. int encryptedSz = 0;
  45926. int testSz = 0;
  45927. int i = 0;
  45928. const byte data[] = { /* Hello World */
  45929. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  45930. 0x72,0x6c,0x64
  45931. };
  45932. #ifndef NO_DES3
  45933. byte desKey[] = {
  45934. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  45935. };
  45936. byte des3Key[] = {
  45937. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  45938. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  45939. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  45940. };
  45941. #endif
  45942. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45943. #ifndef NO_AES_128
  45944. byte aes128Key[] = {
  45945. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45946. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45947. };
  45948. #endif
  45949. #ifndef NO_AES_192
  45950. byte aes192Key[] = {
  45951. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45952. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45953. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45954. };
  45955. #endif
  45956. #ifndef NO_AES_256
  45957. byte aes256Key[] = {
  45958. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45959. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45960. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45961. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45962. };
  45963. #endif
  45964. #endif /* !NO_AES && HAVE_AES_CBC */
  45965. const pkcs7EncryptedVector testVectors[] =
  45966. {
  45967. #ifndef NO_DES3
  45968. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key)},
  45969. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey)},
  45970. #endif /* !NO_DES3 */
  45971. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45972. #ifndef NO_AES_128
  45973. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  45974. sizeof(aes128Key)},
  45975. #endif
  45976. #ifndef NO_AES_192
  45977. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  45978. sizeof(aes192Key)},
  45979. #endif
  45980. #ifndef NO_AES_256
  45981. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  45982. sizeof(aes256Key)},
  45983. #endif
  45984. #endif /* !NO_AES && HAVE_AES_CBC */
  45985. };
  45986. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  45987. for (i = 0; i < testSz; i++) {
  45988. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45989. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  45990. if (pkcs7 != NULL) {
  45991. pkcs7->content = (byte*)testVectors[i].content;
  45992. pkcs7->contentSz = testVectors[i].contentSz;
  45993. pkcs7->contentOID = testVectors[i].contentOID;
  45994. pkcs7->encryptOID = testVectors[i].encryptOID;
  45995. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  45996. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  45997. pkcs7->heap = HEAP_HINT;
  45998. }
  45999. /* encode encryptedData */
  46000. ExpectIntGT(encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46001. sizeof(encrypted)), 0);
  46002. /* Decode encryptedData */
  46003. ExpectIntGT(decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted,
  46004. (word32)encryptedSz, decoded, sizeof(decoded)), 0);
  46005. ExpectIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
  46006. /* Keep values for last itr. */
  46007. if (i < testSz - 1) {
  46008. wc_PKCS7_Free(pkcs7);
  46009. pkcs7 = NULL;
  46010. }
  46011. }
  46012. if (pkcs7 == NULL || testSz == 0) {
  46013. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46014. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46015. }
  46016. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
  46017. sizeof(encrypted)),WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46018. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, NULL,
  46019. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46020. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46021. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46022. /* Testing the struct. */
  46023. if (pkcs7 != NULL) {
  46024. tmpBytePtr = pkcs7->content;
  46025. pkcs7->content = NULL;
  46026. }
  46027. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46028. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46029. if (pkcs7 != NULL) {
  46030. pkcs7->content = tmpBytePtr;
  46031. tmpWrd32 = pkcs7->contentSz;
  46032. pkcs7->contentSz = 0;
  46033. }
  46034. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46035. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46036. if (pkcs7 != NULL) {
  46037. pkcs7->contentSz = tmpWrd32;
  46038. tmpInt = pkcs7->encryptOID;
  46039. pkcs7->encryptOID = 0;
  46040. }
  46041. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46042. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46043. if (pkcs7 != NULL) {
  46044. pkcs7->encryptOID = tmpInt;
  46045. tmpBytePtr = pkcs7->encryptionKey;
  46046. pkcs7->encryptionKey = NULL;
  46047. }
  46048. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46049. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46050. if (pkcs7 != NULL) {
  46051. pkcs7->encryptionKey = tmpBytePtr;
  46052. tmpWrd32 = pkcs7->encryptionKeySz;
  46053. pkcs7->encryptionKeySz = 0;
  46054. }
  46055. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46056. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46057. if (pkcs7 != NULL) {
  46058. pkcs7->encryptionKeySz = tmpWrd32;
  46059. }
  46060. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, (word32)encryptedSz,
  46061. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46062. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, NULL, (word32)encryptedSz,
  46063. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46064. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, 0,
  46065. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46066. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46067. NULL, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46068. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46069. decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46070. /* Test struct fields */
  46071. if (pkcs7 != NULL) {
  46072. tmpBytePtr = pkcs7->encryptionKey;
  46073. pkcs7->encryptionKey = NULL;
  46074. }
  46075. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46076. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46077. if (pkcs7 != NULL) {
  46078. pkcs7->encryptionKey = tmpBytePtr;
  46079. pkcs7->encryptionKeySz = 0;
  46080. }
  46081. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46082. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46083. wc_PKCS7_Free(pkcs7);
  46084. #endif
  46085. return EXPECT_RESULT();
  46086. } /* END test_wc_PKCS7_EncodeEncryptedData() */
  46087. /*
  46088. * Testing wc_PKCS7_Degenerate()
  46089. */
  46090. static int test_wc_PKCS7_Degenerate(void)
  46091. {
  46092. EXPECT_DECLS;
  46093. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  46094. PKCS7* pkcs7 = NULL;
  46095. char fName[] = "./certs/test-degenerate.p7b";
  46096. XFILE f = XBADFILE;
  46097. byte der[4096];
  46098. word32 derSz = 0;
  46099. #ifndef NO_PKCS7_STREAM
  46100. word32 z;
  46101. int ret;
  46102. #endif /* !NO_PKCS7_STREAM */
  46103. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46104. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46105. if (f != XBADFILE)
  46106. XFCLOSE(f);
  46107. /* test degenerate success */
  46108. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46109. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46110. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46111. #ifndef NO_RSA
  46112. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46113. #ifndef NO_PKCS7_STREAM
  46114. wc_PKCS7_Free(pkcs7);
  46115. pkcs7 = NULL;
  46116. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46117. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46118. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46119. /* test for streaming */
  46120. ret = -1;
  46121. for (z = 0; z < derSz && ret != 0; z++) {
  46122. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46123. if (ret < 0){
  46124. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46125. }
  46126. }
  46127. ExpectIntEQ(ret, 0);
  46128. #endif /* !NO_PKCS7_STREAM */
  46129. #else
  46130. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46131. #endif /* NO_RSA */
  46132. wc_PKCS7_Free(pkcs7);
  46133. pkcs7 = NULL;
  46134. /* test with turning off degenerate cases */
  46135. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46136. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46137. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46138. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46139. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz),
  46140. WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46141. #ifndef NO_PKCS7_STREAM
  46142. wc_PKCS7_Free(pkcs7);
  46143. pkcs7 = NULL;
  46144. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46145. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46146. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46147. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46148. /* test for streaming */
  46149. ret = -1;
  46150. for (z = 0; z < derSz && ret != 0; z++) {
  46151. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46152. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46153. continue;
  46154. }
  46155. else
  46156. break;
  46157. }
  46158. ExpectIntEQ(ret, WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46159. #endif /* !NO_PKCS7_STREAM */
  46160. wc_PKCS7_Free(pkcs7);
  46161. #endif
  46162. return EXPECT_RESULT();
  46163. } /* END test_wc_PKCS7_Degenerate() */
  46164. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46165. defined(ASN_BER_TO_DER) && !defined(NO_DES3) && !defined(NO_SHA)
  46166. static byte berContent[] = {
  46167. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46168. 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x80, 0x30,
  46169. 0x80, 0x02, 0x01, 0x00, 0x31, 0x82, 0x01, 0x48,
  46170. 0x30, 0x82, 0x01, 0x44, 0x02, 0x01, 0x00, 0x30,
  46171. 0x81, 0xAC, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30,
  46172. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  46173. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  46174. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E,
  46175. 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E,
  46176. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  46177. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15,
  46178. 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C,
  46179. 0x0C, 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C,
  46180. 0x5F, 0x31, 0x30, 0x32, 0x34, 0x31, 0x19, 0x30,
  46181. 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10,
  46182. 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D,
  46183. 0x69, 0x6E, 0x67, 0x2D, 0x31, 0x30, 0x32, 0x34,
  46184. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04,
  46185. 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  46186. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  46187. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09,
  46188. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  46189. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  46190. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E,
  46191. 0x63, 0x6F, 0x6D, 0x02, 0x09, 0x00, 0xBB, 0xD3,
  46192. 0x10, 0x03, 0xE6, 0x9D, 0x28, 0x03, 0x30, 0x0D,
  46193. 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46194. 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80,
  46195. 0x2F, 0xF9, 0x77, 0x4F, 0x04, 0x5C, 0x16, 0x62,
  46196. 0xF0, 0x77, 0x8D, 0x95, 0x4C, 0xB1, 0x44, 0x9A,
  46197. 0x8C, 0x3C, 0x8C, 0xE4, 0xD1, 0xC1, 0x14, 0x72,
  46198. 0xD0, 0x4A, 0x1A, 0x94, 0x27, 0x0F, 0xAA, 0xE8,
  46199. 0xD0, 0xA2, 0xE7, 0xED, 0x4C, 0x7F, 0x0F, 0xC7,
  46200. 0x1B, 0xFB, 0x81, 0x0E, 0x76, 0x8F, 0xDD, 0x32,
  46201. 0x11, 0x68, 0xA0, 0x13, 0xD2, 0x8D, 0x95, 0xEF,
  46202. 0x80, 0x53, 0x81, 0x0E, 0x1F, 0xC8, 0xD6, 0x76,
  46203. 0x5C, 0x31, 0xD3, 0x77, 0x33, 0x29, 0xA6, 0x1A,
  46204. 0xD3, 0xC6, 0x14, 0x36, 0xCA, 0x8E, 0x7D, 0x72,
  46205. 0xA0, 0x29, 0x4C, 0xC7, 0x3A, 0xAF, 0xFE, 0xF7,
  46206. 0xFC, 0xD7, 0xE2, 0x8F, 0x6A, 0x20, 0x46, 0x09,
  46207. 0x40, 0x22, 0x2D, 0x79, 0x38, 0x11, 0xB1, 0x4A,
  46208. 0xE3, 0x48, 0xE8, 0x10, 0x37, 0xA0, 0x22, 0xF7,
  46209. 0xB4, 0x79, 0xD1, 0xA9, 0x3D, 0xC2, 0xAB, 0x37,
  46210. 0xAE, 0x82, 0x68, 0x1A, 0x16, 0xEF, 0x33, 0x0C,
  46211. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46212. 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06,
  46213. 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03,
  46214. 0x07, 0x04, 0x08, 0xAD, 0xD0, 0x38, 0x9B, 0x16,
  46215. 0x4B, 0x7F, 0x99, 0xA0, 0x80, 0x04, 0x82, 0x03,
  46216. 0xE8, 0x6D, 0x48, 0xFB, 0x8A, 0xBD, 0xED, 0x6C,
  46217. 0xCD, 0xC6, 0x48, 0xFD, 0xB7, 0xB0, 0x7C, 0x86,
  46218. 0x2C, 0x8D, 0xF0, 0x23, 0x12, 0xD8, 0xA3, 0x2A,
  46219. 0x21, 0x6F, 0x8B, 0x75, 0xBB, 0x47, 0x7F, 0xC9,
  46220. 0xBA, 0xBA, 0xFF, 0x91, 0x09, 0x01, 0x7A, 0x5C,
  46221. 0x96, 0x02, 0xB8, 0x8E, 0xF8, 0x67, 0x7E, 0x8F,
  46222. 0xF9, 0x51, 0x0E, 0xFF, 0x8E, 0xE2, 0x61, 0xC0,
  46223. 0xDF, 0xFA, 0xE2, 0x4C, 0x50, 0x90, 0xAE, 0xA1,
  46224. 0x15, 0x38, 0x3D, 0xBE, 0x88, 0xD7, 0x57, 0xC0,
  46225. 0x11, 0x44, 0xA2, 0x61, 0x05, 0x49, 0x6A, 0x94,
  46226. 0x04, 0x10, 0xD9, 0xC2, 0x2D, 0x15, 0x20, 0x0D,
  46227. 0xBD, 0xA2, 0xEF, 0xE4, 0x68, 0xFA, 0x39, 0x75,
  46228. 0x7E, 0xD8, 0x64, 0x44, 0xCB, 0xE0, 0x00, 0x6D,
  46229. 0x57, 0x4E, 0x8A, 0x17, 0xA9, 0x83, 0x6C, 0x7F,
  46230. 0xFE, 0x01, 0xEE, 0xDE, 0x99, 0x3A, 0xB2, 0xFF,
  46231. 0xD3, 0x72, 0x78, 0xBA, 0xF1, 0x23, 0x54, 0x48,
  46232. 0x02, 0xD8, 0x38, 0xA9, 0x54, 0xE5, 0x4A, 0x81,
  46233. 0xB9, 0xC0, 0x67, 0xB2, 0x7D, 0x3C, 0x6F, 0xCE,
  46234. 0xA4, 0xDD, 0x34, 0x5F, 0x60, 0xB1, 0xA3, 0x7A,
  46235. 0xE4, 0x43, 0xF2, 0x89, 0x64, 0x35, 0x09, 0x32,
  46236. 0x51, 0xFB, 0x5C, 0x67, 0x0C, 0x3B, 0xFC, 0x36,
  46237. 0x6B, 0x37, 0x43, 0x6C, 0x03, 0xCD, 0x44, 0xC7,
  46238. 0x2B, 0x62, 0xD6, 0xD1, 0xF4, 0x07, 0x7B, 0x19,
  46239. 0x91, 0xF0, 0xD7, 0xF5, 0x54, 0xBC, 0x0F, 0x42,
  46240. 0x6B, 0x69, 0xF7, 0xA3, 0xC8, 0xEE, 0xB9, 0x7A,
  46241. 0x9E, 0x3D, 0xDF, 0x53, 0x47, 0xF7, 0x50, 0x67,
  46242. 0x00, 0xCF, 0x2B, 0x3B, 0xE9, 0x85, 0xEE, 0xBD,
  46243. 0x4C, 0x64, 0x66, 0x0B, 0x77, 0x80, 0x9D, 0xEF,
  46244. 0x11, 0x32, 0x77, 0xA8, 0xA4, 0x5F, 0xEE, 0x2D,
  46245. 0xE0, 0x43, 0x87, 0x76, 0x87, 0x53, 0x4E, 0xD7,
  46246. 0x1A, 0x04, 0x7B, 0xE1, 0xD1, 0xE1, 0xF5, 0x87,
  46247. 0x51, 0x13, 0xE0, 0xC2, 0xAA, 0xA3, 0x4B, 0xAA,
  46248. 0x9E, 0xB4, 0xA6, 0x1D, 0x4E, 0x28, 0x57, 0x0B,
  46249. 0x80, 0x90, 0x81, 0x4E, 0x04, 0xF5, 0x30, 0x8D,
  46250. 0x51, 0xCE, 0x57, 0x2F, 0x88, 0xC5, 0x70, 0xC4,
  46251. 0x06, 0x8F, 0xDD, 0x37, 0xC1, 0x34, 0x1E, 0x0E,
  46252. 0x15, 0x32, 0x23, 0x92, 0xAB, 0x40, 0xEA, 0xF7,
  46253. 0x43, 0xE2, 0x1D, 0xE2, 0x4B, 0xC9, 0x91, 0xF4,
  46254. 0x63, 0x21, 0x34, 0xDB, 0xE9, 0x86, 0x83, 0x1A,
  46255. 0xD2, 0x52, 0xEF, 0x7A, 0xA2, 0xEE, 0xA4, 0x11,
  46256. 0x56, 0xD3, 0x6C, 0xF5, 0x6D, 0xE4, 0xA5, 0x2D,
  46257. 0x99, 0x02, 0x10, 0xDF, 0x29, 0xC5, 0xE3, 0x0B,
  46258. 0xC4, 0xA1, 0xEE, 0x5F, 0x4A, 0x10, 0xEE, 0x85,
  46259. 0x73, 0x2A, 0x92, 0x15, 0x2C, 0xC8, 0xF4, 0x8C,
  46260. 0xD7, 0x3D, 0xBC, 0xAD, 0x18, 0xE0, 0x59, 0xD3,
  46261. 0xEE, 0x75, 0x90, 0x1C, 0xCC, 0x76, 0xC6, 0x64,
  46262. 0x17, 0xD2, 0xD0, 0x91, 0xA6, 0xD0, 0xC1, 0x4A,
  46263. 0xAA, 0x58, 0x22, 0xEC, 0x45, 0x98, 0xF2, 0xCC,
  46264. 0x4C, 0xE4, 0xBF, 0xED, 0xF6, 0x44, 0x72, 0x36,
  46265. 0x65, 0x3F, 0xE3, 0xB5, 0x8B, 0x3E, 0x54, 0x9C,
  46266. 0x82, 0x86, 0x5E, 0xB0, 0xF2, 0x12, 0xE5, 0x69,
  46267. 0xFA, 0x46, 0xA2, 0x54, 0xFC, 0xF5, 0x4B, 0xE0,
  46268. 0x24, 0x3B, 0x99, 0x04, 0x1A, 0x7A, 0xF7, 0xD1,
  46269. 0xFF, 0x68, 0x97, 0xB2, 0x85, 0x82, 0x95, 0x27,
  46270. 0x2B, 0xF4, 0xE7, 0x1A, 0x74, 0x19, 0xEC, 0x8C,
  46271. 0x4E, 0xA7, 0x0F, 0xAD, 0x4F, 0x5A, 0x02, 0x80,
  46272. 0xC1, 0x6A, 0x9E, 0x54, 0xE4, 0x8E, 0xA3, 0x41,
  46273. 0x3F, 0x6F, 0x9C, 0x82, 0x9F, 0x83, 0xB0, 0x44,
  46274. 0x01, 0x5F, 0x10, 0x9D, 0xD3, 0xB6, 0x33, 0x5B,
  46275. 0xAF, 0xAC, 0x6B, 0x57, 0x2A, 0x01, 0xED, 0x0E,
  46276. 0x17, 0xB9, 0x80, 0x76, 0x12, 0x1C, 0x51, 0x56,
  46277. 0xDD, 0x6D, 0x94, 0xAB, 0xD2, 0xE5, 0x15, 0x2D,
  46278. 0x3C, 0xC5, 0xE8, 0x62, 0x05, 0x8B, 0x40, 0xB1,
  46279. 0xC2, 0x83, 0xCA, 0xAC, 0x4B, 0x8B, 0x39, 0xF7,
  46280. 0xA0, 0x08, 0x43, 0x5C, 0xF7, 0xE8, 0xED, 0x40,
  46281. 0x72, 0x73, 0xE3, 0x6B, 0x18, 0x67, 0xA0, 0xB6,
  46282. 0x0F, 0xED, 0x8F, 0x9A, 0xE4, 0x27, 0x62, 0x23,
  46283. 0xAA, 0x6D, 0x6C, 0x31, 0xC9, 0x9D, 0x6B, 0xE0,
  46284. 0xBF, 0x9D, 0x7D, 0x2E, 0x76, 0x71, 0x06, 0x39,
  46285. 0xAC, 0x96, 0x1C, 0xAF, 0x30, 0xF2, 0x62, 0x9C,
  46286. 0x84, 0x3F, 0x43, 0x5E, 0x19, 0xA8, 0xE5, 0x3C,
  46287. 0x9D, 0x43, 0x3C, 0x43, 0x41, 0xE8, 0x82, 0xE7,
  46288. 0x5B, 0xF3, 0xE2, 0x15, 0xE3, 0x52, 0x20, 0xFD,
  46289. 0x0D, 0xB2, 0x4D, 0x48, 0xAD, 0x53, 0x7E, 0x0C,
  46290. 0xF0, 0xB9, 0xBE, 0xC9, 0x58, 0x4B, 0xC8, 0xA8,
  46291. 0xA3, 0x36, 0xF1, 0x2C, 0xD2, 0xE1, 0xC8, 0xC4,
  46292. 0x3C, 0x48, 0x70, 0xC2, 0x6D, 0x6C, 0x3D, 0x99,
  46293. 0xAC, 0x43, 0x19, 0x69, 0xCA, 0x67, 0x1A, 0xC9,
  46294. 0xE1, 0x47, 0xFA, 0x0A, 0xE6, 0x5B, 0x6F, 0x61,
  46295. 0xD0, 0x03, 0xE4, 0x03, 0x4B, 0xFD, 0xE2, 0xA5,
  46296. 0x8D, 0x83, 0x01, 0x7E, 0xC0, 0x7B, 0x2E, 0x0B,
  46297. 0x29, 0xDD, 0xD6, 0xDC, 0x71, 0x46, 0xBD, 0x9A,
  46298. 0x40, 0x46, 0x1E, 0x0A, 0xB1, 0x00, 0xE7, 0x71,
  46299. 0x29, 0x77, 0xFC, 0x9A, 0x76, 0x8A, 0x5F, 0x66,
  46300. 0x9B, 0x63, 0x91, 0x12, 0x78, 0xBF, 0x67, 0xAD,
  46301. 0xA1, 0x72, 0x9E, 0xC5, 0x3E, 0xE5, 0xCB, 0xAF,
  46302. 0xD6, 0x5A, 0x0D, 0xB6, 0x9B, 0xA3, 0x78, 0xE8,
  46303. 0xB0, 0x8F, 0x69, 0xED, 0xC1, 0x73, 0xD5, 0xE5,
  46304. 0x1C, 0x18, 0xA0, 0x58, 0x4C, 0x49, 0xBD, 0x91,
  46305. 0xCE, 0x15, 0x0D, 0xAA, 0x5A, 0x07, 0xEA, 0x1C,
  46306. 0xA7, 0x4B, 0x11, 0x31, 0x80, 0xAF, 0xA1, 0x0A,
  46307. 0xED, 0x6C, 0x70, 0xE4, 0xDB, 0x75, 0x86, 0xAE,
  46308. 0xBF, 0x4A, 0x05, 0x72, 0xDE, 0x84, 0x8C, 0x7B,
  46309. 0x59, 0x81, 0x58, 0xE0, 0xC0, 0x15, 0xB5, 0xF3,
  46310. 0xD5, 0x73, 0x78, 0x83, 0x53, 0xDA, 0x92, 0xC1,
  46311. 0xE6, 0x71, 0x74, 0xC7, 0x7E, 0xAA, 0x36, 0x06,
  46312. 0xF0, 0xDF, 0xBA, 0xFB, 0xEF, 0x54, 0xE8, 0x11,
  46313. 0xB2, 0x33, 0xA3, 0x0B, 0x9E, 0x0C, 0x59, 0x75,
  46314. 0x13, 0xFA, 0x7F, 0x88, 0xB9, 0x86, 0xBD, 0x1A,
  46315. 0xDB, 0x52, 0x12, 0xFB, 0x6D, 0x1A, 0xCB, 0x49,
  46316. 0x94, 0x94, 0xC4, 0xA9, 0x99, 0xC0, 0xA4, 0xB6,
  46317. 0x60, 0x36, 0x09, 0x94, 0x2A, 0xD5, 0xC4, 0x26,
  46318. 0xF4, 0xA3, 0x6A, 0x0E, 0x57, 0x8B, 0x7C, 0xA4,
  46319. 0x1D, 0x75, 0xE8, 0x2A, 0xF3, 0xC4, 0x3C, 0x7D,
  46320. 0x45, 0x6D, 0xD8, 0x24, 0xD1, 0x3B, 0xF7, 0xCF,
  46321. 0xE4, 0x45, 0x2A, 0x55, 0xE5, 0xA9, 0x1F, 0x1C,
  46322. 0x8F, 0x55, 0x8D, 0xC1, 0xF7, 0x74, 0xCC, 0x26,
  46323. 0xC7, 0xBA, 0x2E, 0x5C, 0xC1, 0x71, 0x0A, 0xAA,
  46324. 0xD9, 0x6D, 0x76, 0xA7, 0xF9, 0xD1, 0x18, 0xCB,
  46325. 0x5A, 0x52, 0x98, 0xA8, 0x0D, 0x3F, 0x06, 0xFC,
  46326. 0x49, 0x11, 0x21, 0x5F, 0x86, 0x19, 0x33, 0x81,
  46327. 0xB5, 0x7A, 0xDA, 0xA1, 0x47, 0xBF, 0x7C, 0xD7,
  46328. 0x05, 0x96, 0xC7, 0xF5, 0xC1, 0x61, 0xE5, 0x18,
  46329. 0xA5, 0x38, 0x68, 0xED, 0xB4, 0x17, 0x62, 0x0D,
  46330. 0x01, 0x5E, 0xC3, 0x04, 0xA6, 0xBA, 0xB1, 0x01,
  46331. 0x60, 0x5C, 0xC1, 0x3A, 0x34, 0x97, 0xD6, 0xDB,
  46332. 0x67, 0x73, 0x4D, 0x33, 0x96, 0x01, 0x67, 0x44,
  46333. 0xEA, 0x47, 0x5E, 0x44, 0xB5, 0xE5, 0xD1, 0x6C,
  46334. 0x20, 0xA9, 0x6D, 0x4D, 0xBC, 0x02, 0xF0, 0x70,
  46335. 0xE4, 0xDD, 0xE9, 0xD5, 0x5C, 0x28, 0x29, 0x0B,
  46336. 0xB4, 0x60, 0x2A, 0xF1, 0xF7, 0x1A, 0xF0, 0x36,
  46337. 0xAE, 0x51, 0x3A, 0xAE, 0x6E, 0x48, 0x7D, 0xC7,
  46338. 0x5C, 0xF3, 0xDC, 0xF6, 0xED, 0x27, 0x4E, 0x8E,
  46339. 0x48, 0x18, 0x3E, 0x08, 0xF1, 0xD8, 0x3D, 0x0D,
  46340. 0xE7, 0x2F, 0x65, 0x8A, 0x6F, 0xE2, 0x1E, 0x06,
  46341. 0xC1, 0x04, 0x58, 0x7B, 0x4A, 0x75, 0x60, 0x92,
  46342. 0x13, 0xC6, 0x40, 0x2D, 0x3A, 0x8A, 0xD1, 0x03,
  46343. 0x05, 0x1F, 0x28, 0x66, 0xC2, 0x57, 0x2A, 0x4C,
  46344. 0xE1, 0xA3, 0xCB, 0xA1, 0x95, 0x30, 0x10, 0xED,
  46345. 0xDF, 0xAE, 0x70, 0x49, 0x4E, 0xF6, 0xB4, 0x5A,
  46346. 0xB6, 0x22, 0x56, 0x37, 0x05, 0xE7, 0x3E, 0xB2,
  46347. 0xE3, 0x96, 0x62, 0xEC, 0x09, 0x53, 0xC0, 0x50,
  46348. 0x3D, 0xA7, 0xBC, 0x9B, 0x39, 0x02, 0x26, 0x16,
  46349. 0xB5, 0x34, 0x17, 0xD4, 0xCA, 0xFE, 0x1D, 0xE4,
  46350. 0x5A, 0xDA, 0x4C, 0xC2, 0xCA, 0x8E, 0x79, 0xBF,
  46351. 0xD8, 0x4C, 0xBB, 0xFA, 0x30, 0x7B, 0xA9, 0x3E,
  46352. 0x52, 0x19, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00,
  46353. 0x00, 0x00, 0x00, 0x00, 0x00
  46354. };
  46355. #endif /* HAVE_PKCS7 && !NO_FILESYSTEM && ASN_BER_TO_DER &&
  46356. * !NO_DES3 && !NO_SHA
  46357. */
  46358. /*
  46359. * Testing wc_PKCS7_BER()
  46360. */
  46361. static int test_wc_PKCS7_BER(void)
  46362. {
  46363. EXPECT_DECLS;
  46364. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46365. !defined(NO_SHA) && defined(ASN_BER_TO_DER)
  46366. PKCS7* pkcs7 = NULL;
  46367. char fName[] = "./certs/test-ber-exp02-05-2022.p7b";
  46368. XFILE f = XBADFILE;
  46369. byte der[4096];
  46370. #ifndef NO_DES3
  46371. byte decoded[2048];
  46372. #endif
  46373. word32 derSz = 0;
  46374. #ifndef NO_PKCS7_STREAM
  46375. word32 z;
  46376. int ret;
  46377. #endif /* !NO_PKCS7_STREAM */
  46378. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46379. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46380. if (f != XBADFILE) {
  46381. XFCLOSE(f);
  46382. f = XBADFILE;
  46383. }
  46384. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46385. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46386. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46387. #ifndef NO_RSA
  46388. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46389. #ifndef NO_PKCS7_STREAM
  46390. wc_PKCS7_Free(pkcs7);
  46391. pkcs7 = NULL;
  46392. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46393. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46394. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46395. /* test for streaming */
  46396. ret = -1;
  46397. for (z = 0; z < derSz && ret != 0; z++) {
  46398. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46399. if (ret < 0){
  46400. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46401. }
  46402. }
  46403. ExpectIntEQ(ret, 0);
  46404. #endif /* !NO_PKCS7_STREAM */
  46405. #else
  46406. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46407. #endif
  46408. wc_PKCS7_Free(pkcs7);
  46409. pkcs7 = NULL;
  46410. #ifndef NO_DES3
  46411. /* decode BER content */
  46412. ExpectTrue((f = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  46413. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46414. if (f != XBADFILE) {
  46415. XFCLOSE(f);
  46416. f = XBADFILE;
  46417. }
  46418. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46419. #ifndef NO_RSA
  46420. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46421. #else
  46422. ExpectIntNE(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46423. #endif
  46424. ExpectTrue((f = XFOPEN("./certs/1024/client-key.der", "rb")) != XBADFILE);
  46425. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46426. if (f != XBADFILE) {
  46427. XFCLOSE(f);
  46428. f = XBADFILE;
  46429. }
  46430. if (pkcs7 != NULL) {
  46431. pkcs7->privateKey = der;
  46432. pkcs7->privateKeySz = derSz;
  46433. }
  46434. #ifndef NO_RSA
  46435. #ifdef WOLFSSL_SP_MATH
  46436. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46437. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  46438. #else
  46439. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46440. sizeof(berContent), decoded, sizeof(decoded)), 0);
  46441. #endif
  46442. #else
  46443. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46444. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  46445. #endif
  46446. wc_PKCS7_Free(pkcs7);
  46447. #endif /* !NO_DES3 */
  46448. #endif
  46449. return EXPECT_RESULT();
  46450. } /* END test_wc_PKCS7_BER() */
  46451. static int test_wc_PKCS7_signed_enveloped(void)
  46452. {
  46453. EXPECT_DECLS;
  46454. #if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_AES) && \
  46455. !defined(NO_FILESYSTEM)
  46456. XFILE f = XBADFILE;
  46457. PKCS7* pkcs7 = NULL;
  46458. #ifdef HAVE_AES_CBC
  46459. PKCS7* inner = NULL;
  46460. #endif
  46461. WC_RNG rng;
  46462. unsigned char key[FOURK_BUF/2];
  46463. unsigned char cert[FOURK_BUF/2];
  46464. unsigned char env[FOURK_BUF];
  46465. int envSz = FOURK_BUF;
  46466. int keySz = 0;
  46467. int certSz = 0;
  46468. unsigned char sig[FOURK_BUF * 2];
  46469. int sigSz = FOURK_BUF * 2;
  46470. #ifdef HAVE_AES_CBC
  46471. unsigned char decoded[FOURK_BUF];
  46472. int decodedSz = FOURK_BUF;
  46473. #endif
  46474. #ifndef NO_PKCS7_STREAM
  46475. int z;
  46476. int ret;
  46477. #endif /* !NO_PKCS7_STREAM */
  46478. XMEMSET(&rng, 0, sizeof(WC_RNG));
  46479. /* load cert */
  46480. ExpectTrue((f = XFOPEN(cliCertDerFile, "rb")) != XBADFILE);
  46481. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), f)), 0);
  46482. if (f != XBADFILE) {
  46483. XFCLOSE(f);
  46484. f = XBADFILE;
  46485. }
  46486. /* load key */
  46487. ExpectTrue((f = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  46488. ExpectIntGT((keySz = (int)XFREAD(key, 1, sizeof(key), f)), 0);
  46489. if (f != XBADFILE) {
  46490. XFCLOSE(f);
  46491. f = XBADFILE;
  46492. }
  46493. ExpectIntGT(keySz = wolfSSL_KeyPemToDer(key, keySz, key, keySz, NULL), 0);
  46494. /* sign cert for envelope */
  46495. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46496. ExpectIntEQ(wc_InitRng(&rng), 0);
  46497. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46498. if (pkcs7 != NULL) {
  46499. pkcs7->content = cert;
  46500. pkcs7->contentSz = (word32)certSz;
  46501. pkcs7->contentOID = DATA;
  46502. pkcs7->privateKey = key;
  46503. pkcs7->privateKeySz = (word32)keySz;
  46504. pkcs7->encryptOID = RSAk;
  46505. pkcs7->hashOID = SHA256h;
  46506. pkcs7->rng = &rng;
  46507. }
  46508. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46509. wc_PKCS7_Free(pkcs7);
  46510. pkcs7 = NULL;
  46511. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  46512. #ifdef HAVE_AES_CBC
  46513. /* create envelope */
  46514. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46515. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46516. if (pkcs7 != NULL) {
  46517. pkcs7->content = sig;
  46518. pkcs7->contentSz = (word32)sigSz;
  46519. pkcs7->contentOID = DATA;
  46520. pkcs7->encryptOID = AES256CBCb;
  46521. pkcs7->privateKey = key;
  46522. pkcs7->privateKeySz = (word32)keySz;
  46523. }
  46524. ExpectIntGT((envSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, env, (word32)envSz)), 0);
  46525. ExpectIntLT(wc_PKCS7_EncodeEnvelopedData(pkcs7, env, 2), 0);
  46526. wc_PKCS7_Free(pkcs7);
  46527. pkcs7 = NULL;
  46528. #endif
  46529. /* create bad signed enveloped data */
  46530. sigSz = FOURK_BUF * 2;
  46531. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46532. ExpectIntEQ(wc_InitRng(&rng), 0);
  46533. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46534. if (pkcs7 != NULL) {
  46535. pkcs7->content = env;
  46536. pkcs7->contentSz = (word32)envSz;
  46537. pkcs7->contentOID = DATA;
  46538. pkcs7->privateKey = key;
  46539. pkcs7->privateKeySz = (word32)keySz;
  46540. pkcs7->encryptOID = RSAk;
  46541. pkcs7->hashOID = SHA256h;
  46542. pkcs7->rng = &rng;
  46543. }
  46544. /* Set no certs in bundle for this test. */
  46545. if (pkcs7 != NULL) {
  46546. ExpectIntEQ(wc_PKCS7_SetNoCerts(pkcs7, 1), 0);
  46547. ExpectIntEQ(wc_PKCS7_SetNoCerts(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46548. ExpectIntEQ(wc_PKCS7_GetNoCerts(pkcs7), 1);
  46549. }
  46550. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46551. wc_PKCS7_Free(pkcs7);
  46552. pkcs7 = NULL;
  46553. /* check verify fails */
  46554. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46555. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46556. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz),
  46557. WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  46558. /* try verifying the signature manually */
  46559. {
  46560. RsaKey rKey;
  46561. word32 idx = 0;
  46562. byte digest[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ +
  46563. WC_MAX_DIGEST_SIZE];
  46564. int digestSz = 0;
  46565. ExpectIntEQ(wc_InitRsaKey(&rKey, HEAP_HINT), 0);
  46566. ExpectIntEQ(wc_RsaPrivateKeyDecode(key, &idx, &rKey, (word32)keySz), 0);
  46567. ExpectIntGT(digestSz = wc_RsaSSL_Verify(pkcs7->signature,
  46568. pkcs7->signatureSz, digest, sizeof(digest), &rKey), 0);
  46569. ExpectIntEQ(digestSz, pkcs7->pkcs7DigestSz);
  46570. ExpectIntEQ(XMEMCMP(digest, pkcs7->pkcs7Digest, digestSz), 0);
  46571. ExpectIntEQ(wc_FreeRsaKey(&rKey), 0);
  46572. /* verify was success */
  46573. }
  46574. wc_PKCS7_Free(pkcs7);
  46575. pkcs7 = NULL;
  46576. /* initializing the PKCS7 struct with the signing certificate should pass */
  46577. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46578. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46579. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  46580. #ifndef NO_PKCS7_STREAM
  46581. wc_PKCS7_Free(pkcs7);
  46582. pkcs7 = NULL;
  46583. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46584. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46585. /* test for streaming */
  46586. ret = -1;
  46587. for (z = 0; z < sigSz && ret != 0; z++) {
  46588. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  46589. if (ret < 0){
  46590. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46591. }
  46592. }
  46593. ExpectIntEQ(ret, 0);
  46594. #endif /* !NO_PKCS7_STREAM */
  46595. wc_PKCS7_Free(pkcs7);
  46596. pkcs7 = NULL;
  46597. /* create valid degenerate bundle */
  46598. sigSz = FOURK_BUF * 2;
  46599. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46600. if (pkcs7 != NULL) {
  46601. pkcs7->content = env;
  46602. pkcs7->contentSz = (word32)envSz;
  46603. pkcs7->contentOID = DATA;
  46604. pkcs7->privateKey = key;
  46605. pkcs7->privateKeySz = (word32)keySz;
  46606. pkcs7->encryptOID = RSAk;
  46607. pkcs7->hashOID = SHA256h;
  46608. pkcs7->rng = &rng;
  46609. }
  46610. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  46611. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46612. wc_PKCS7_Free(pkcs7);
  46613. pkcs7 = NULL;
  46614. wc_FreeRng(&rng);
  46615. /* check verify */
  46616. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46617. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46618. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  46619. ExpectNotNull(pkcs7->content);
  46620. #ifndef NO_PKCS7_STREAM
  46621. wc_PKCS7_Free(pkcs7);
  46622. pkcs7 = NULL;
  46623. /* create valid degenerate bundle */
  46624. sigSz = FOURK_BUF * 2;
  46625. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46626. if (pkcs7 != NULL) {
  46627. pkcs7->content = env;
  46628. pkcs7->contentSz = (word32)envSz;
  46629. pkcs7->contentOID = DATA;
  46630. pkcs7->privateKey = key;
  46631. pkcs7->privateKeySz = (word32)keySz;
  46632. pkcs7->encryptOID = RSAk;
  46633. pkcs7->hashOID = SHA256h;
  46634. pkcs7->rng = &rng;
  46635. }
  46636. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  46637. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46638. wc_PKCS7_Free(pkcs7);
  46639. pkcs7 = NULL;
  46640. wc_FreeRng(&rng);
  46641. /* check verify */
  46642. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46643. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46644. /* test for streaming */
  46645. ret = -1;
  46646. for (z = 0; z < sigSz && ret != 0; z++) {
  46647. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  46648. if (ret < 0){
  46649. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46650. }
  46651. }
  46652. ExpectIntEQ(ret, 0);
  46653. #endif /* !NO_PKCS7_STREAM */
  46654. #ifdef HAVE_AES_CBC
  46655. /* check decode */
  46656. ExpectNotNull(inner = wc_PKCS7_New(NULL, 0));
  46657. ExpectIntEQ(wc_PKCS7_InitWithCert(inner, cert, (word32)certSz), 0);
  46658. if (inner != NULL) {
  46659. inner->privateKey = key;
  46660. inner->privateKeySz = (word32)keySz;
  46661. }
  46662. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(inner, pkcs7->content,
  46663. pkcs7->contentSz, decoded, (word32)decodedSz)), 0);
  46664. wc_PKCS7_Free(inner);
  46665. inner = NULL;
  46666. #endif
  46667. wc_PKCS7_Free(pkcs7);
  46668. pkcs7 = NULL;
  46669. #ifdef HAVE_AES_CBC
  46670. /* check cert set */
  46671. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46672. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46673. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, decoded, (word32)decodedSz), 0);
  46674. ExpectNotNull(pkcs7->singleCert);
  46675. ExpectIntNE(pkcs7->singleCertSz, 0);
  46676. wc_PKCS7_Free(pkcs7);
  46677. pkcs7 = NULL;
  46678. #ifndef NO_PKCS7_STREAM
  46679. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46680. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46681. /* test for streaming */
  46682. ret = -1;
  46683. for (z = 0; z < decodedSz && ret != 0; z++) {
  46684. ret = wc_PKCS7_VerifySignedData(pkcs7, decoded + z, 1);
  46685. if (ret < 0){
  46686. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46687. }
  46688. }
  46689. ExpectIntEQ(ret, 0);
  46690. ExpectNotNull(pkcs7->singleCert);
  46691. ExpectIntNE(pkcs7->singleCertSz, 0);
  46692. wc_PKCS7_Free(pkcs7);
  46693. pkcs7 = NULL;
  46694. #endif /* !NO_PKCS7_STREAM */
  46695. #endif
  46696. #endif /* HAVE_PKCS7 && !NO_RSA && !NO_AES */
  46697. return EXPECT_RESULT();
  46698. }
  46699. static int test_wc_PKCS7_NoDefaultSignedAttribs(void)
  46700. {
  46701. EXPECT_DECLS;
  46702. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46703. && !defined(NO_AES)
  46704. PKCS7* pkcs7 = NULL;
  46705. void* heap = NULL;
  46706. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  46707. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  46708. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46709. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(pkcs7), 0);
  46710. wc_PKCS7_Free(pkcs7);
  46711. #endif
  46712. return EXPECT_RESULT();
  46713. }
  46714. static int test_wc_PKCS7_SetOriEncryptCtx(void)
  46715. {
  46716. EXPECT_DECLS;
  46717. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46718. && !defined(NO_AES)
  46719. PKCS7* pkcs7 = NULL;
  46720. void* heap = NULL;
  46721. WOLFSSL_CTX* ctx = NULL;
  46722. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  46723. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  46724. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46725. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx), 0);
  46726. wc_PKCS7_Free(pkcs7);
  46727. #endif
  46728. return EXPECT_RESULT();
  46729. }
  46730. static int test_wc_PKCS7_SetOriDecryptCtx(void)
  46731. {
  46732. EXPECT_DECLS;
  46733. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46734. && !defined(NO_AES)
  46735. PKCS7* pkcs7 = NULL;
  46736. void* heap = NULL;
  46737. WOLFSSL_CTX* ctx = NULL;
  46738. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  46739. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  46740. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46741. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx), 0);
  46742. wc_PKCS7_Free(pkcs7);
  46743. #endif
  46744. return EXPECT_RESULT();
  46745. }
  46746. static int test_wc_PKCS7_DecodeCompressedData(void)
  46747. {
  46748. EXPECT_DECLS;
  46749. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46750. && !defined(NO_AES) && defined(HAVE_LIBZ)
  46751. PKCS7* pkcs7 = NULL;
  46752. void* heap = NULL;
  46753. byte out[4096];
  46754. byte* decompressed = NULL;
  46755. int outSz;
  46756. int decompressedSz;
  46757. const char* cert = "./certs/client-cert.pem";
  46758. byte* cert_buf = NULL;
  46759. size_t cert_sz = 0;
  46760. ExpectIntEQ(load_file(cert, &cert_buf, &cert_sz), 0);
  46761. ExpectNotNull((decompressed = (byte*)XMALLOC(cert_sz, heap,
  46762. DYNAMIC_TYPE_TMP_BUFFER)));
  46763. decompressedSz = (int)cert_sz;
  46764. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  46765. if (pkcs7 != NULL) {
  46766. pkcs7->content = (byte*)cert_buf;
  46767. pkcs7->contentSz = (word32)cert_sz;
  46768. pkcs7->contentOID = DATA;
  46769. }
  46770. ExpectIntGT((outSz = wc_PKCS7_EncodeCompressedData(pkcs7, out,
  46771. sizeof(out))), 0);
  46772. wc_PKCS7_Free(pkcs7);
  46773. pkcs7 = NULL;
  46774. /* compressed key should be smaller than when started */
  46775. ExpectIntLT(outSz, cert_sz);
  46776. /* test decompression */
  46777. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  46778. ExpectIntEQ(pkcs7->contentOID, 0);
  46779. /* fail case with out buffer too small */
  46780. ExpectIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  46781. decompressed, outSz), 0);
  46782. /* success case */
  46783. ExpectIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  46784. decompressed, decompressedSz), cert_sz);
  46785. ExpectIntEQ(pkcs7->contentOID, DATA);
  46786. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  46787. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  46788. decompressed = NULL;
  46789. /* test decompression function with different 'max' inputs */
  46790. outSz = sizeof(out);
  46791. ExpectIntGT((outSz = wc_Compress(out, outSz, cert_buf, (word32)cert_sz, 0)),
  46792. 0);
  46793. ExpectIntLT(wc_DeCompressDynamic(&decompressed, 1, DYNAMIC_TYPE_TMP_BUFFER,
  46794. out, outSz, 0, heap), 0);
  46795. ExpectNull(decompressed);
  46796. ExpectIntGT(wc_DeCompressDynamic(&decompressed, -1, DYNAMIC_TYPE_TMP_BUFFER,
  46797. out, outSz, 0, heap), 0);
  46798. ExpectNotNull(decompressed);
  46799. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  46800. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  46801. decompressed = NULL;
  46802. ExpectIntGT(wc_DeCompressDynamic(&decompressed, DYNAMIC_TYPE_TMP_BUFFER, 5,
  46803. out, outSz, 0, heap), 0);
  46804. ExpectNotNull(decompressed);
  46805. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  46806. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  46807. if (cert_buf != NULL)
  46808. free(cert_buf);
  46809. wc_PKCS7_Free(pkcs7);
  46810. #endif
  46811. return EXPECT_RESULT();
  46812. }
  46813. static int test_wc_i2d_PKCS12(void)
  46814. {
  46815. EXPECT_DECLS;
  46816. #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
  46817. && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46818. && !defined(NO_AES) && !defined(NO_SHA)
  46819. WC_PKCS12* pkcs12 = NULL;
  46820. unsigned char der[FOURK_BUF * 2];
  46821. unsigned char* pt;
  46822. int derSz = 0;
  46823. unsigned char out[FOURK_BUF * 2];
  46824. int outSz = FOURK_BUF * 2;
  46825. const char p12_f[] = "./certs/test-servercert.p12";
  46826. XFILE f = XBADFILE;
  46827. ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
  46828. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  46829. if (f != XBADFILE)
  46830. XFCLOSE(f);
  46831. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  46832. ExpectIntEQ(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
  46833. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  46834. ExpectIntEQ(outSz, derSz);
  46835. outSz = derSz - 1;
  46836. pt = out;
  46837. ExpectIntLE(wc_i2d_PKCS12(pkcs12, &pt, &outSz), 0);
  46838. outSz = derSz;
  46839. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, &outSz), derSz);
  46840. ExpectIntEQ((pt == out), 0);
  46841. pt = NULL;
  46842. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, NULL), derSz);
  46843. XFREE(pt, NULL, DYNAMIC_TYPE_PKCS);
  46844. wc_PKCS12_free(pkcs12);
  46845. pkcs12 = NULL;
  46846. /* Run the same test but use wc_d2i_PKCS12_fp. */
  46847. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  46848. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  46849. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  46850. ExpectIntEQ(outSz, derSz);
  46851. wc_PKCS12_free(pkcs12);
  46852. pkcs12 = NULL;
  46853. /* wc_d2i_PKCS12_fp can also allocate the PKCS12 object for the caller. */
  46854. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  46855. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  46856. ExpectIntEQ(outSz, derSz);
  46857. wc_PKCS12_free(pkcs12);
  46858. pkcs12 = NULL;
  46859. #endif
  46860. return EXPECT_RESULT();
  46861. }
  46862. /* Testing wc_SignatureGetSize() for signature type ECC */
  46863. static int test_wc_SignatureGetSize_ecc(void)
  46864. {
  46865. EXPECT_DECLS;
  46866. #if !defined(NO_SIG_WRAPPER) && defined(HAVE_ECC) && !defined(NO_ECC256)
  46867. enum wc_SignatureType sig_type;
  46868. word32 key_len;
  46869. ecc_key ecc;
  46870. const char* qx =
  46871. "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  46872. const char* qy =
  46873. "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  46874. const char* d =
  46875. "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  46876. XMEMSET(&ecc, 0, sizeof(ecc_key));
  46877. ExpectIntEQ(wc_ecc_init(&ecc), 0);
  46878. ExpectIntEQ(wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"), 0);
  46879. /* Input for signature type ECC */
  46880. sig_type = WC_SIGNATURE_TYPE_ECC;
  46881. key_len = sizeof(ecc_key);
  46882. ExpectIntGT(wc_SignatureGetSize(sig_type, &ecc, key_len), 0);
  46883. /* Test bad args */
  46884. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  46885. sig_type = (enum wc_SignatureType) 100;
  46886. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  46887. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46888. sig_type = WC_SIGNATURE_TYPE_ECC;
  46889. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), 0);
  46890. key_len = (word32)0;
  46891. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46892. DoExpectIntEQ(wc_ecc_free(&ecc), 0);
  46893. #endif /* !NO_SIG_WRAPPER && HAVE_ECC && !NO_ECC256 */
  46894. return EXPECT_RESULT();
  46895. } /* END test_wc_SignatureGetSize_ecc() */
  46896. /* Testing wc_SignatureGetSize() for signature type rsa */
  46897. static int test_wc_SignatureGetSize_rsa(void)
  46898. {
  46899. EXPECT_DECLS;
  46900. #if !defined(NO_SIG_WRAPPER) && !defined(NO_RSA)
  46901. enum wc_SignatureType sig_type;
  46902. word32 key_len;
  46903. word32 idx = 0;
  46904. RsaKey rsa_key;
  46905. byte* tmp = NULL;
  46906. size_t bytes;
  46907. XMEMSET(&rsa_key, 0, sizeof(RsaKey));
  46908. #ifdef USE_CERT_BUFFERS_1024
  46909. bytes = (size_t)sizeof_client_key_der_1024;
  46910. if (bytes < (size_t)sizeof_client_key_der_1024)
  46911. bytes = (size_t)sizeof_client_cert_der_1024;
  46912. #elif defined(USE_CERT_BUFFERS_2048)
  46913. bytes = (size_t)sizeof_client_key_der_2048;
  46914. if (bytes < (size_t)sizeof_client_cert_der_2048)
  46915. bytes = (size_t)sizeof_client_cert_der_2048;
  46916. #else
  46917. bytes = FOURK_BUF;
  46918. #endif
  46919. ExpectNotNull(tmp = (byte*)XMALLOC(bytes, HEAP_HINT,
  46920. DYNAMIC_TYPE_TMP_BUFFER));
  46921. if (tmp != NULL) {
  46922. #ifdef USE_CERT_BUFFERS_1024
  46923. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  46924. #elif defined(USE_CERT_BUFFERS_2048)
  46925. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  46926. #elif !defined(NO_FILESYSTEM)
  46927. XFILE file = XBADFILE;
  46928. ExpectTrue((file = XFOPEN(clientKey, "rb")) != XBADFILE);
  46929. ExpectIntGT(bytes = (size_t)XFREAD(tmp, 1, FOURK_BUF, file), 0);
  46930. if (file != XBADFILE)
  46931. XFCLOSE(file);
  46932. }
  46933. #else
  46934. ExpectFail();
  46935. #endif
  46936. }
  46937. ExpectIntEQ(wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, testDevId), 0);
  46938. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, (word32)bytes), 0);
  46939. /* Input for signature type RSA */
  46940. sig_type = WC_SIGNATURE_TYPE_RSA;
  46941. key_len = sizeof(RsaKey);
  46942. ExpectIntGT(wc_SignatureGetSize(sig_type, &rsa_key, key_len), 0);
  46943. /* Test bad args */
  46944. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  46945. sig_type = (enum wc_SignatureType)100;
  46946. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  46947. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46948. sig_type = WC_SIGNATURE_TYPE_RSA;
  46949. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46950. key_len = (word32)0;
  46951. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46952. DoExpectIntEQ(wc_FreeRsaKey(&rsa_key), 0);
  46953. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46954. #endif /* !NO_SIG_WRAPPER && !NO_RSA */
  46955. return EXPECT_RESULT();
  46956. } /* END test_wc_SignatureGetSize_rsa(void) */
  46957. /*----------------------------------------------------------------------------*
  46958. | hash.h Tests
  46959. *----------------------------------------------------------------------------*/
  46960. static int test_wc_HashInit(void)
  46961. {
  46962. EXPECT_DECLS;
  46963. int i; /* 0 indicates tests passed, 1 indicates failure */
  46964. wc_HashAlg hash;
  46965. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  46966. enum wc_HashType enumArray[] = {
  46967. #ifndef NO_MD5
  46968. WC_HASH_TYPE_MD5,
  46969. #endif
  46970. #ifndef NO_SHA
  46971. WC_HASH_TYPE_SHA,
  46972. #endif
  46973. #ifdef WOLFSSL_SHA224
  46974. WC_HASH_TYPE_SHA224,
  46975. #endif
  46976. #ifndef NO_SHA256
  46977. WC_HASH_TYPE_SHA256,
  46978. #endif
  46979. #ifdef WOLFSSL_SHA384
  46980. WC_HASH_TYPE_SHA384,
  46981. #endif
  46982. #ifdef WOLFSSL_SHA512
  46983. WC_HASH_TYPE_SHA512,
  46984. #endif
  46985. };
  46986. /* dynamically finds the length */
  46987. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  46988. /* For loop to test various arguments... */
  46989. for (i = 0; i < enumlen; i++) {
  46990. /* check for bad args */
  46991. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  46992. wc_HashFree(&hash, enumArray[i]);
  46993. /* check for null ptr */
  46994. ExpectIntEQ(wc_HashInit(NULL, enumArray[i]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46995. } /* end of for loop */
  46996. return EXPECT_RESULT();
  46997. } /* end of test_wc_HashInit */
  46998. /*
  46999. * Unit test function for wc_HashSetFlags()
  47000. */
  47001. static int test_wc_HashSetFlags(void)
  47002. {
  47003. EXPECT_DECLS;
  47004. #ifdef WOLFSSL_HASH_FLAGS
  47005. wc_HashAlg hash;
  47006. word32 flags = 0;
  47007. int i, j;
  47008. int notSupportedLen;
  47009. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47010. enum wc_HashType enumArray[] = {
  47011. #ifndef NO_MD5
  47012. WC_HASH_TYPE_MD5,
  47013. #endif
  47014. #ifndef NO_SHA
  47015. WC_HASH_TYPE_SHA,
  47016. #endif
  47017. #ifdef WOLFSSL_SHA224
  47018. WC_HASH_TYPE_SHA224,
  47019. #endif
  47020. #ifndef NO_SHA256
  47021. WC_HASH_TYPE_SHA256,
  47022. #endif
  47023. #ifdef WOLFSSL_SHA384
  47024. WC_HASH_TYPE_SHA384,
  47025. #endif
  47026. #ifdef WOLFSSL_SHA512
  47027. WC_HASH_TYPE_SHA512,
  47028. #endif
  47029. #ifdef WOLFSSL_SHA3
  47030. WC_HASH_TYPE_SHA3_224,
  47031. #endif
  47032. };
  47033. enum wc_HashType notSupported[] = {
  47034. WC_HASH_TYPE_MD5_SHA,
  47035. WC_HASH_TYPE_MD2,
  47036. WC_HASH_TYPE_MD4,
  47037. WC_HASH_TYPE_BLAKE2B,
  47038. WC_HASH_TYPE_BLAKE2S,
  47039. WC_HASH_TYPE_NONE,
  47040. };
  47041. /* dynamically finds the length */
  47042. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47043. /* For loop to test various arguments... */
  47044. for (i = 0; i < enumlen; i++) {
  47045. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47046. ExpectIntEQ(wc_HashSetFlags(&hash, enumArray[i], flags), 0);
  47047. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47048. ExpectIntEQ(wc_HashSetFlags(NULL, enumArray[i], flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47049. wc_HashFree(&hash, enumArray[i]);
  47050. }
  47051. /* For loop to test not supported cases */
  47052. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47053. for (j = 0; j < notSupportedLen; j++) {
  47054. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47055. ExpectIntEQ(wc_HashSetFlags(&hash, notSupported[j], flags),
  47056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47057. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47058. }
  47059. #endif
  47060. return EXPECT_RESULT();
  47061. } /* END test_wc_HashSetFlags */
  47062. /*
  47063. * Unit test function for wc_HashGetFlags()
  47064. */
  47065. static int test_wc_HashGetFlags(void)
  47066. {
  47067. EXPECT_DECLS;
  47068. #ifdef WOLFSSL_HASH_FLAGS
  47069. wc_HashAlg hash;
  47070. word32 flags = 0;
  47071. int i, j;
  47072. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47073. enum wc_HashType enumArray[] = {
  47074. #ifndef NO_MD5
  47075. WC_HASH_TYPE_MD5,
  47076. #endif
  47077. #ifndef NO_SHA
  47078. WC_HASH_TYPE_SHA,
  47079. #endif
  47080. #ifdef WOLFSSL_SHA224
  47081. WC_HASH_TYPE_SHA224,
  47082. #endif
  47083. #ifndef NO_SHA256
  47084. WC_HASH_TYPE_SHA256,
  47085. #endif
  47086. #ifdef WOLFSSL_SHA384
  47087. WC_HASH_TYPE_SHA384,
  47088. #endif
  47089. #ifdef WOLFSSL_SHA512
  47090. WC_HASH_TYPE_SHA512,
  47091. #endif
  47092. #ifdef WOLFSSL_SHA3
  47093. WC_HASH_TYPE_SHA3_224,
  47094. #endif
  47095. };
  47096. enum wc_HashType notSupported[] = {
  47097. WC_HASH_TYPE_MD5_SHA,
  47098. WC_HASH_TYPE_MD2,
  47099. WC_HASH_TYPE_MD4,
  47100. WC_HASH_TYPE_BLAKE2B,
  47101. WC_HASH_TYPE_BLAKE2S,
  47102. WC_HASH_TYPE_NONE,
  47103. };
  47104. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47105. int notSupportedLen;
  47106. /* For loop to test various arguments... */
  47107. for (i = 0; i < enumlen; i++) {
  47108. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47109. ExpectIntEQ(wc_HashGetFlags(&hash, enumArray[i], &flags), 0);
  47110. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47111. ExpectIntEQ(wc_HashGetFlags(NULL, enumArray[i], &flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47112. wc_HashFree(&hash, enumArray[i]);
  47113. }
  47114. /* For loop to test not supported cases */
  47115. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47116. for (j = 0; j < notSupportedLen; j++) {
  47117. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47118. ExpectIntEQ(wc_HashGetFlags(&hash, notSupported[j], &flags),
  47119. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47120. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47121. }
  47122. #endif
  47123. return EXPECT_RESULT();
  47124. } /* END test_wc_HashGetFlags */
  47125. /*----------------------------------------------------------------------------*
  47126. | Compatibility Tests
  47127. *----------------------------------------------------------------------------*/
  47128. /*----------------------------------------------------------------------------*
  47129. | ASN.1 Tests
  47130. *----------------------------------------------------------------------------*/
  47131. static int test_wolfSSL_ASN1_BIT_STRING(void)
  47132. {
  47133. EXPECT_DECLS;
  47134. #if !defined(NO_CERTS) && defined(OPENSSL_ALL)
  47135. ASN1_BIT_STRING* str = NULL;
  47136. ASN1_BIT_STRING* str2 = NULL;
  47137. unsigned char* der = NULL;
  47138. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47139. /* Empty data testing. */
  47140. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 1), 0);
  47141. ASN1_BIT_STRING_free(str);
  47142. str = NULL;
  47143. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47144. /* Invalid parameter testing. */
  47145. ExpectIntEQ(ASN1_BIT_STRING_set_bit(NULL, 42, 1), 0);
  47146. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, -1, 1), 0);
  47147. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 2), 0);
  47148. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, -1), 0);
  47149. /* No bit string - bit is always 0. */
  47150. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, 42), 0);
  47151. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, -1), 0);
  47152. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47153. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 0), 0);
  47154. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 1), 1);
  47155. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 1);
  47156. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 41), 0);
  47157. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47158. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 84, 1), 1);
  47159. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 84), 1);
  47160. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 83), 0);
  47161. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 91, 0), 1);
  47162. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 91), 0);
  47163. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 89, 0), 1);
  47164. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 89), 0);
  47165. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 0), 1);
  47166. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 0);
  47167. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, NULL), 14);
  47168. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, &der), 14);
  47169. #ifdef WOLFSSL_ASN_TEMPLATE
  47170. {
  47171. const unsigned char* tmp = der;
  47172. ExpectNotNull(d2i_ASN1_BIT_STRING(&str2, &tmp, 14));
  47173. }
  47174. #endif
  47175. ASN1_BIT_STRING_free(str);
  47176. ASN1_BIT_STRING_free(str2);
  47177. ASN1_BIT_STRING_free(NULL);
  47178. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  47179. #endif
  47180. return EXPECT_RESULT();
  47181. }
  47182. static int test_wolfSSL_ASN1_INTEGER(void)
  47183. {
  47184. EXPECT_DECLS;
  47185. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47186. ASN1_INTEGER* a = NULL;
  47187. ASN1_INTEGER* dup = NULL;
  47188. const unsigned char invalidLenDer[] = {
  47189. 0x02, 0x20, 0x00
  47190. };
  47191. const unsigned char longDer[] = {
  47192. 0x02, 0x20,
  47193. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47194. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47195. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47196. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
  47197. };
  47198. const unsigned char* p;
  47199. /* Invalid parameter testing. */
  47200. ASN1_INTEGER_free(NULL);
  47201. ExpectNull(wolfSSL_ASN1_INTEGER_dup(NULL));
  47202. ExpectNotNull(a = ASN1_INTEGER_new());
  47203. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47204. ASN1_INTEGER_free(dup);
  47205. dup = NULL;
  47206. ASN1_INTEGER_free(a);
  47207. a = NULL;
  47208. p = longDer;
  47209. ExpectNull(d2i_ASN1_INTEGER(NULL, &p, sizeof(invalidLenDer)));
  47210. p = longDer;
  47211. ExpectNotNull(a = d2i_ASN1_INTEGER(NULL, &p, sizeof(longDer)));
  47212. ExpectPtrNE(p, longDer);
  47213. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47214. ASN1_INTEGER_free(dup);
  47215. ASN1_INTEGER_free(a);
  47216. #endif
  47217. return EXPECT_RESULT();
  47218. }
  47219. static int test_wolfSSL_ASN1_INTEGER_cmp(void)
  47220. {
  47221. EXPECT_DECLS;
  47222. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47223. ASN1_INTEGER* a = NULL;
  47224. ASN1_INTEGER* b = NULL;
  47225. ExpectNotNull(a = ASN1_INTEGER_new());
  47226. ExpectNotNull(b = ASN1_INTEGER_new());
  47227. ExpectIntEQ(ASN1_INTEGER_set(a, 1), 1);
  47228. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47229. /* Invalid parameter testing. */
  47230. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, NULL), -1);
  47231. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, NULL), -1);
  47232. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, b), -1);
  47233. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47234. ExpectIntEQ(ASN1_INTEGER_set(b, -1), 1);
  47235. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47236. ExpectIntEQ(ASN1_INTEGER_set(a, -2), 1);
  47237. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47238. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47239. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47240. ExpectIntEQ(ASN1_INTEGER_set(a, 0x01), 1);
  47241. ExpectIntEQ(ASN1_INTEGER_set(b, 0x1000), 1);
  47242. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47243. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(b, a), 0);
  47244. ASN1_INTEGER_free(b);
  47245. ASN1_INTEGER_free(a);
  47246. #endif
  47247. return EXPECT_RESULT();
  47248. }
  47249. static int test_wolfSSL_ASN1_INTEGER_BN(void)
  47250. {
  47251. EXPECT_DECLS;
  47252. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47253. ASN1_INTEGER* ai = NULL;
  47254. ASN1_INTEGER* ai2 = NULL;
  47255. BIGNUM* bn = NULL;
  47256. BIGNUM* bn2 = NULL;
  47257. ExpectNotNull(ai = ASN1_INTEGER_new());
  47258. ExpectNotNull(bn2 = BN_new());
  47259. /* Invalid parameter testing. */
  47260. ExpectNull(bn = ASN1_INTEGER_to_BN(NULL, NULL));
  47261. ExpectNull(ai2 = BN_to_ASN1_INTEGER(NULL, NULL));
  47262. /* at the moment hard setting since no set function */
  47263. if (ai != NULL) {
  47264. ai->data[0] = 0xff; /* No DER encoding. */
  47265. ai->length = 1;
  47266. }
  47267. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47268. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47269. BN_free(bn);
  47270. bn = NULL;
  47271. #else
  47272. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47273. #endif
  47274. if (ai != NULL) {
  47275. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47276. ai->data[1] = 0x04; /* bad length of integer */
  47277. ai->data[2] = 0x03;
  47278. ai->length = 3;
  47279. }
  47280. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47281. /* Interpreted as a number 0x020403. */
  47282. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47283. BN_free(bn);
  47284. bn = NULL;
  47285. #else
  47286. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47287. #endif
  47288. if (ai != NULL) {
  47289. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47290. ai->data[1] = 0x01; /* length of integer */
  47291. ai->data[2] = 0x03;
  47292. ai->length = 3;
  47293. }
  47294. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47295. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, NULL));
  47296. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47297. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47298. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47299. if (ai != NULL) {
  47300. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47301. ai->data[1] = 0x02; /* length of integer */
  47302. ai->data[2] = 0x00; /* padding byte to ensure positive */
  47303. ai->data[3] = 0xff;
  47304. ai->length = 4;
  47305. }
  47306. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47307. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47308. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47309. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47310. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47311. if (ai != NULL) {
  47312. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47313. ai->data[1] = 0x01; /* length of integer */
  47314. ai->data[2] = 0x00;
  47315. ai->length = 3;
  47316. }
  47317. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47318. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47319. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47320. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47321. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47322. if (ai != NULL) {
  47323. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47324. ai->data[1] = 0x01; /* length of integer */
  47325. ai->data[2] = 0x01;
  47326. ai->length = 3;
  47327. ai->negative = 1;
  47328. }
  47329. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47330. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47331. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47332. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47333. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47334. BN_free(bn2);
  47335. BN_free(bn);
  47336. ASN1_INTEGER_free(ai2);
  47337. ASN1_INTEGER_free(ai);
  47338. #endif
  47339. return EXPECT_RESULT();
  47340. }
  47341. static int test_wolfSSL_ASN1_INTEGER_get_set(void)
  47342. {
  47343. EXPECT_DECLS;
  47344. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47345. ASN1_INTEGER *a = NULL;
  47346. long val;
  47347. ExpectNotNull(a = ASN1_INTEGER_new());
  47348. /* Invalid parameter testing. */
  47349. ExpectIntEQ(ASN1_INTEGER_get(NULL), 0);
  47350. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47351. ExpectIntEQ(ASN1_INTEGER_get(a), 0);
  47352. #else
  47353. ExpectIntEQ(ASN1_INTEGER_get(a), -1);
  47354. #endif
  47355. ASN1_INTEGER_free(a);
  47356. a = NULL;
  47357. ExpectNotNull(a = ASN1_INTEGER_new());
  47358. val = 0;
  47359. ExpectIntEQ(ASN1_INTEGER_set(NULL, val), 0);
  47360. ASN1_INTEGER_free(a);
  47361. a = NULL;
  47362. /* 0 */
  47363. ExpectNotNull(a = ASN1_INTEGER_new());
  47364. val = 0;
  47365. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47366. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47367. ASN1_INTEGER_free(a);
  47368. a = NULL;
  47369. /* 40 */
  47370. ExpectNotNull(a = ASN1_INTEGER_new());
  47371. val = 40;
  47372. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47373. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47374. ASN1_INTEGER_free(a);
  47375. a = NULL;
  47376. /* -40 */
  47377. ExpectNotNull(a = ASN1_INTEGER_new());
  47378. val = -40;
  47379. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47380. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47381. ASN1_INTEGER_free(a);
  47382. a = NULL;
  47383. /* 128 */
  47384. ExpectNotNull(a = ASN1_INTEGER_new());
  47385. val = 128;
  47386. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47387. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47388. ASN1_INTEGER_free(a);
  47389. a = NULL;
  47390. /* -128 */
  47391. ExpectNotNull(a = ASN1_INTEGER_new());
  47392. val = -128;
  47393. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47394. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47395. ASN1_INTEGER_free(a);
  47396. a = NULL;
  47397. /* 200 */
  47398. ExpectNotNull(a = ASN1_INTEGER_new());
  47399. val = 200;
  47400. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47401. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47402. ASN1_INTEGER_free(a);
  47403. a = NULL;
  47404. /* int max (2147483647) */
  47405. ExpectNotNull(a = ASN1_INTEGER_new());
  47406. val = 2147483647;
  47407. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47408. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47409. ASN1_INTEGER_free(a);
  47410. a = NULL;
  47411. /* int min (-2147483648) */
  47412. ExpectNotNull(a = ASN1_INTEGER_new());
  47413. val = -2147483647 - 1;
  47414. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47415. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47416. ASN1_INTEGER_free(a);
  47417. a = NULL;
  47418. /* long max positive */
  47419. ExpectNotNull(a = ASN1_INTEGER_new());
  47420. val = (long)(((unsigned long)-1) >> 1);
  47421. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47422. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47423. ASN1_INTEGER_free(a);
  47424. #endif
  47425. return EXPECT_RESULT();
  47426. }
  47427. #if defined(OPENSSL_EXTRA)
  47428. typedef struct ASN1IntTestVector {
  47429. const byte* der;
  47430. const size_t derSz;
  47431. const long value;
  47432. } ASN1IntTestVector;
  47433. #endif
  47434. static int test_wolfSSL_d2i_ASN1_INTEGER(void)
  47435. {
  47436. EXPECT_DECLS;
  47437. #if defined(OPENSSL_EXTRA)
  47438. size_t i;
  47439. WOLFSSL_ASN1_INTEGER* a = NULL;
  47440. WOLFSSL_ASN1_INTEGER* b = NULL;
  47441. WOLFSSL_ASN1_INTEGER* c = NULL;
  47442. const byte* p = NULL;
  47443. byte* p2 = NULL;
  47444. byte* reEncoded = NULL;
  47445. int reEncodedSz = 0;
  47446. static const byte zeroDer[] = {
  47447. 0x02, 0x01, 0x00
  47448. };
  47449. static const byte oneDer[] = {
  47450. 0x02, 0x01, 0x01
  47451. };
  47452. static const byte negativeDer[] = {
  47453. 0x02, 0x03, 0xC1, 0x16, 0x0D
  47454. };
  47455. static const byte positiveDer[] = {
  47456. 0x02, 0x03, 0x01, 0x00, 0x01
  47457. };
  47458. static const byte primeDer[] = {
  47459. 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0x95, 0x08, 0xe1, 0x57, 0x41,
  47460. 0xf2, 0x71, 0x6d, 0xb7, 0xd2, 0x45, 0x41, 0x27, 0x01, 0x65, 0xc6,
  47461. 0x45, 0xae, 0xf2, 0xbc, 0x24, 0x30, 0xb8, 0x95, 0xce, 0x2f, 0x4e,
  47462. 0xd6, 0xf6, 0x1c, 0x88, 0xbc, 0x7c, 0x9f, 0xfb, 0xa8, 0x67, 0x7f,
  47463. 0xfe, 0x5c, 0x9c, 0x51, 0x75, 0xf7, 0x8a, 0xca, 0x07, 0xe7, 0x35,
  47464. 0x2f, 0x8f, 0xe1, 0xbd, 0x7b, 0xc0, 0x2f, 0x7c, 0xab, 0x64, 0xa8,
  47465. 0x17, 0xfc, 0xca, 0x5d, 0x7b, 0xba, 0xe0, 0x21, 0xe5, 0x72, 0x2e,
  47466. 0x6f, 0x2e, 0x86, 0xd8, 0x95, 0x73, 0xda, 0xac, 0x1b, 0x53, 0xb9,
  47467. 0x5f, 0x3f, 0xd7, 0x19, 0x0d, 0x25, 0x4f, 0xe1, 0x63, 0x63, 0x51,
  47468. 0x8b, 0x0b, 0x64, 0x3f, 0xad, 0x43, 0xb8, 0xa5, 0x1c, 0x5c, 0x34,
  47469. 0xb3, 0xae, 0x00, 0xa0, 0x63, 0xc5, 0xf6, 0x7f, 0x0b, 0x59, 0x68,
  47470. 0x78, 0x73, 0xa6, 0x8c, 0x18, 0xa9, 0x02, 0x6d, 0xaf, 0xc3, 0x19,
  47471. 0x01, 0x2e, 0xb8, 0x10, 0xe3, 0xc6, 0xcc, 0x40, 0xb4, 0x69, 0xa3,
  47472. 0x46, 0x33, 0x69, 0x87, 0x6e, 0xc4, 0xbb, 0x17, 0xa6, 0xf3, 0xe8,
  47473. 0xdd, 0xad, 0x73, 0xbc, 0x7b, 0x2f, 0x21, 0xb5, 0xfd, 0x66, 0x51,
  47474. 0x0c, 0xbd, 0x54, 0xb3, 0xe1, 0x6d, 0x5f, 0x1c, 0xbc, 0x23, 0x73,
  47475. 0xd1, 0x09, 0x03, 0x89, 0x14, 0xd2, 0x10, 0xb9, 0x64, 0xc3, 0x2a,
  47476. 0xd0, 0xa1, 0x96, 0x4a, 0xbc, 0xe1, 0xd4, 0x1a, 0x5b, 0xc7, 0xa0,
  47477. 0xc0, 0xc1, 0x63, 0x78, 0x0f, 0x44, 0x37, 0x30, 0x32, 0x96, 0x80,
  47478. 0x32, 0x23, 0x95, 0xa1, 0x77, 0xba, 0x13, 0xd2, 0x97, 0x73, 0xe2,
  47479. 0x5d, 0x25, 0xc9, 0x6a, 0x0d, 0xc3, 0x39, 0x60, 0xa4, 0xb4, 0xb0,
  47480. 0x69, 0x42, 0x42, 0x09, 0xe9, 0xd8, 0x08, 0xbc, 0x33, 0x20, 0xb3,
  47481. 0x58, 0x22, 0xa7, 0xaa, 0xeb, 0xc4, 0xe1, 0xe6, 0x61, 0x83, 0xc5,
  47482. 0xd2, 0x96, 0xdf, 0xd9, 0xd0, 0x4f, 0xad, 0xd7
  47483. };
  47484. static const byte garbageDer[] = {0xDE, 0xAD, 0xBE, 0xEF};
  47485. static const ASN1IntTestVector testVectors[] = {
  47486. {zeroDer, sizeof(zeroDer), 0},
  47487. {oneDer, sizeof(oneDer), 1},
  47488. {negativeDer, sizeof(negativeDer), -4123123},
  47489. {positiveDer, sizeof(positiveDer), 65537},
  47490. {primeDer, sizeof(primeDer), 0}
  47491. };
  47492. static const size_t NUM_TEST_VECTORS =
  47493. sizeof(testVectors)/sizeof(testVectors[0]);
  47494. /* Check d2i error conditions */
  47495. /* NULL pointer to input. */
  47496. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, NULL, 1)));
  47497. ExpectNull(b);
  47498. /* NULL input. */
  47499. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 1)));
  47500. ExpectNull(b);
  47501. /* 0 length. */
  47502. p = testVectors[0].der;
  47503. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 0)));
  47504. ExpectNull(b);
  47505. /* Negative length. */
  47506. p = testVectors[0].der;
  47507. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, -1)));
  47508. ExpectNull(b);
  47509. /* Garbage DER input. */
  47510. p = garbageDer;
  47511. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, sizeof(garbageDer))));
  47512. ExpectNull(b);
  47513. /* Check i2d error conditions */
  47514. /* NULL input. */
  47515. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(NULL, &p2), 0);
  47516. /* 0 length input data buffer (a->length == 0). */
  47517. ExpectNotNull((a = wolfSSL_ASN1_INTEGER_new()));
  47518. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  47519. if (a != NULL)
  47520. a->data = NULL;
  47521. /* NULL input data buffer. */
  47522. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  47523. if (a != NULL) {
  47524. /* Reset a->data. */
  47525. a->data = a->intData;
  47526. }
  47527. /* Set a to valid value. */
  47528. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(a, 1), WOLFSSL_SUCCESS);
  47529. /* NULL output buffer. */
  47530. ExpectIntEQ(wolfSSL_i2d_ASN1_INTEGER(a, NULL), 3);
  47531. wolfSSL_ASN1_INTEGER_free(a);
  47532. a = NULL;
  47533. for (i = 0; i < NUM_TEST_VECTORS; ++i) {
  47534. p = testVectors[i].der;
  47535. ExpectNotNull(a = wolfSSL_d2i_ASN1_INTEGER(&b, &p,
  47536. testVectors[i].derSz));
  47537. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47538. if (testVectors[i].derSz <= sizeof(long)) {
  47539. ExpectNotNull(c = wolfSSL_ASN1_INTEGER_new());
  47540. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(c, testVectors[i].value), 1);
  47541. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, c), 0);
  47542. wolfSSL_ASN1_INTEGER_free(c);
  47543. c = NULL;
  47544. }
  47545. /* Convert to DER without a pre-allocated output buffer. */
  47546. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &reEncoded)), 0);
  47547. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  47548. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  47549. /* Convert to DER with a pre-allocated output buffer. In this case, the
  47550. * output buffer pointer should be incremented just past the end of the
  47551. * encoded data. */
  47552. p2 = reEncoded;
  47553. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &p2)), 0);
  47554. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  47555. ExpectPtrEq(reEncoded, p2 - reEncodedSz);
  47556. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  47557. XFREE(reEncoded, NULL, DYNAMIC_TYPE_ASN1);
  47558. reEncoded = NULL;
  47559. wolfSSL_ASN1_INTEGER_free(a);
  47560. a = NULL;
  47561. }
  47562. #endif /* OPENSSL_EXTRA */
  47563. return EXPECT_RESULT();
  47564. }
  47565. static int test_wolfSSL_a2i_ASN1_INTEGER(void)
  47566. {
  47567. EXPECT_DECLS;
  47568. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  47569. BIO* bio = NULL;
  47570. BIO* out = NULL;
  47571. BIO* fixed = NULL;
  47572. ASN1_INTEGER* ai = NULL;
  47573. char buf[] = "123456\n12345\n1123456789123456\\\n78901234567890 \r\n\n";
  47574. char tmp[1024];
  47575. int tmpSz;
  47576. const char expected1[] = "123456";
  47577. const char expected2[] = "112345678912345678901234567890";
  47578. char longStr[] = "123456781234567812345678123456781234567812345678\n"
  47579. "123456781234567812345678123456781234567812345678\\\n12345678\n";
  47580. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  47581. ExpectNotNull(ai = ASN1_INTEGER_new());
  47582. ExpectNotNull(bio = BIO_new_mem_buf(buf, -1));
  47583. /* Invalid parameter testing. */
  47584. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, -1), 0);
  47585. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, NULL, -1), 0);
  47586. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, NULL, -1), 0);
  47587. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, tmp, -1), 0);
  47588. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, 1024), 0);
  47589. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, 1024), 0);
  47590. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, 1024), 0);
  47591. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, 1024), 0);
  47592. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, -1), 0);
  47593. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, NULL), 0);
  47594. ExpectIntEQ(i2a_ASN1_INTEGER(bio, NULL), 0);
  47595. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, ai), 0);
  47596. /* No data to read from BIO. */
  47597. ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, 1024), 0);
  47598. /* read first line */
  47599. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47600. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 6);
  47601. XMEMSET(tmp, 0, 1024);
  47602. tmpSz = BIO_read(out, tmp, 1024);
  47603. ExpectIntEQ(tmpSz, 6);
  47604. ExpectIntEQ(XMEMCMP(tmp, expected1, tmpSz), 0);
  47605. /* fail on second line (not % 2) */
  47606. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  47607. /* read 3rd long line */
  47608. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47609. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 30);
  47610. XMEMSET(tmp, 0, 1024);
  47611. tmpSz = BIO_read(out, tmp, 1024);
  47612. ExpectIntEQ(tmpSz, 30);
  47613. ExpectIntEQ(XMEMCMP(tmp, expected2, tmpSz), 0);
  47614. /* fail on empty line */
  47615. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  47616. BIO_free(bio);
  47617. bio = NULL;
  47618. /* Make long integer, requiring dynamic memory, even longer. */
  47619. ExpectNotNull(bio = BIO_new_mem_buf(longStr, -1));
  47620. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47621. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 48);
  47622. XMEMSET(tmp, 0, 1024);
  47623. tmpSz = BIO_read(out, tmp, 1024);
  47624. ExpectIntEQ(tmpSz, 48);
  47625. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47626. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 56);
  47627. XMEMSET(tmp, 0, 1024);
  47628. tmpSz = BIO_read(out, tmp, 1024);
  47629. ExpectIntEQ(tmpSz, 56);
  47630. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(ai, 1), 1);
  47631. BIO_free(bio);
  47632. BIO_free(out);
  47633. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  47634. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  47635. /* Ensure there is 0 bytes available to write into. */
  47636. ExpectIntEQ(BIO_write(fixed, tmp, 1), 1);
  47637. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  47638. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  47639. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  47640. BIO_free(fixed);
  47641. ASN1_INTEGER_free(ai);
  47642. #endif
  47643. return EXPECT_RESULT();
  47644. }
  47645. static int test_wolfSSL_i2c_ASN1_INTEGER(void)
  47646. {
  47647. EXPECT_DECLS;
  47648. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47649. ASN1_INTEGER *a = NULL;
  47650. unsigned char *pp = NULL,*tpp = NULL;
  47651. int ret = 0;
  47652. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  47653. /* Invalid parameter testing. */
  47654. /* Set pp to an invalid value. */
  47655. pp = NULL;
  47656. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, &pp), 0);
  47657. ExpectIntEQ(i2c_ASN1_INTEGER(a, &pp), 0);
  47658. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, NULL), 0);
  47659. /* 40 */
  47660. if (a != NULL) {
  47661. a->intData[0] = ASN_INTEGER;
  47662. a->intData[1] = 1;
  47663. a->intData[2] = 40;
  47664. }
  47665. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47666. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47667. DYNAMIC_TYPE_TMP_BUFFER));
  47668. tpp = pp;
  47669. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47670. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47671. tpp--;
  47672. ExpectIntEQ(*tpp, 40);
  47673. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47674. pp = NULL;
  47675. /* 128 */
  47676. if (a != NULL) {
  47677. a->intData[0] = ASN_INTEGER;
  47678. a->intData[1] = 1;
  47679. a->intData[2] = 128;
  47680. }
  47681. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  47682. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47683. DYNAMIC_TYPE_TMP_BUFFER));
  47684. tpp = pp;
  47685. if (tpp != NULL) {
  47686. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47687. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  47688. tpp--;
  47689. ExpectIntEQ(*(tpp--), 128);
  47690. ExpectIntEQ(*tpp, 0);
  47691. }
  47692. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47693. pp = NULL;
  47694. /* -40 */
  47695. if (a != NULL) {
  47696. a->intData[0] = ASN_INTEGER;
  47697. a->intData[1] = 1;
  47698. a->intData[2] = 40;
  47699. a->negative = 1;
  47700. }
  47701. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47702. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47703. DYNAMIC_TYPE_TMP_BUFFER));
  47704. tpp = pp;
  47705. if (tpp != NULL) {
  47706. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47707. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47708. tpp--;
  47709. ExpectIntEQ(*tpp, 216);
  47710. }
  47711. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47712. pp = NULL;
  47713. /* -128 */
  47714. if (a != NULL) {
  47715. a->intData[0] = ASN_INTEGER;
  47716. a->intData[1] = 1;
  47717. a->intData[2] = 128;
  47718. a->negative = 1;
  47719. }
  47720. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47721. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47722. DYNAMIC_TYPE_TMP_BUFFER));
  47723. tpp = pp;
  47724. if (tpp != NULL) {
  47725. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47726. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47727. tpp--;
  47728. ExpectIntEQ(*tpp, 128);
  47729. }
  47730. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47731. pp = NULL;
  47732. /* -200 */
  47733. if (a != NULL) {
  47734. a->intData[0] = ASN_INTEGER;
  47735. a->intData[1] = 1;
  47736. a->intData[2] = 200;
  47737. a->negative = 1;
  47738. }
  47739. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  47740. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47741. DYNAMIC_TYPE_TMP_BUFFER));
  47742. tpp = pp;
  47743. if (tpp != NULL) {
  47744. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47745. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  47746. tpp--;
  47747. ExpectIntEQ(*(tpp--), 56);
  47748. ExpectIntEQ(*tpp, 255);
  47749. }
  47750. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47751. pp = NULL;
  47752. /* Empty */
  47753. if (a != NULL) {
  47754. a->intData[0] = ASN_INTEGER;
  47755. a->intData[1] = 0;
  47756. a->negative = 0;
  47757. }
  47758. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47759. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47760. DYNAMIC_TYPE_TMP_BUFFER));
  47761. tpp = pp;
  47762. if (tpp != NULL) {
  47763. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47764. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47765. tpp--;
  47766. ExpectIntEQ(*tpp, 0);
  47767. }
  47768. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47769. pp = NULL;
  47770. /* 0 */
  47771. if (a != NULL) {
  47772. a->intData[0] = ASN_INTEGER;
  47773. a->intData[1] = 1;
  47774. a->intData[2] = 0;
  47775. a->negative = 1;
  47776. }
  47777. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47778. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47779. DYNAMIC_TYPE_TMP_BUFFER));
  47780. if (tpp != NULL) {
  47781. tpp = pp;
  47782. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47783. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47784. tpp--;
  47785. ExpectIntEQ(*tpp, 0);
  47786. }
  47787. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47788. pp = NULL;
  47789. /* 0x100 */
  47790. if (a != NULL) {
  47791. a->intData[0] = ASN_INTEGER;
  47792. a->intData[1] = 2;
  47793. a->intData[2] = 0x01;
  47794. a->intData[3] = 0x00;
  47795. a->negative = 0;
  47796. }
  47797. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  47798. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47799. DYNAMIC_TYPE_TMP_BUFFER));
  47800. if (tpp != NULL) {
  47801. tpp = pp;
  47802. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47803. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  47804. tpp -= 2;
  47805. ExpectIntEQ(tpp[0], 0x01);
  47806. ExpectIntEQ(tpp[1], 0x00);
  47807. }
  47808. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47809. pp = NULL;
  47810. /* -0x8000 => 0x8000 */
  47811. if (a != NULL) {
  47812. a->intData[0] = ASN_INTEGER;
  47813. a->intData[1] = 2;
  47814. a->intData[2] = 0x80;
  47815. a->intData[3] = 0x00;
  47816. a->negative = 1;
  47817. }
  47818. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  47819. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47820. DYNAMIC_TYPE_TMP_BUFFER));
  47821. tpp = pp;
  47822. if (tpp != NULL) {
  47823. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47824. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  47825. tpp -= 2;
  47826. ExpectIntEQ(tpp[0], 0x80);
  47827. ExpectIntEQ(tpp[1], 0x00);
  47828. }
  47829. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47830. pp = NULL;
  47831. /* -0x8001 => 0xFF7FFF */
  47832. if (a != NULL) {
  47833. a->intData[0] = ASN_INTEGER;
  47834. a->intData[1] = 2;
  47835. a->intData[2] = 0x80;
  47836. a->intData[3] = 0x01;
  47837. a->negative = 1;
  47838. }
  47839. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 3);
  47840. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47841. DYNAMIC_TYPE_TMP_BUFFER));
  47842. tpp = pp;
  47843. if (tpp != NULL) {
  47844. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47845. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 3);
  47846. tpp -= 3;
  47847. ExpectIntEQ(tpp[0], 0xFF);
  47848. ExpectIntEQ(tpp[1], 0x7F);
  47849. ExpectIntEQ(tpp[2], 0xFF);
  47850. }
  47851. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47852. wolfSSL_ASN1_INTEGER_free(a);
  47853. #endif /* OPENSSL_EXTRA && !NO_ASN */
  47854. return EXPECT_RESULT();
  47855. }
  47856. static int test_wolfSSL_ASN1_OBJECT(void)
  47857. {
  47858. EXPECT_DECLS;
  47859. #if defined(OPENSSL_EXTRA)
  47860. ASN1_OBJECT* a = NULL;
  47861. ASN1_OBJECT s;
  47862. const unsigned char der[] = { 0x06, 0x01, 0x00 };
  47863. /* Invalid parameter testing. */
  47864. ASN1_OBJECT_free(NULL);
  47865. ExpectNull(wolfSSL_ASN1_OBJECT_dup(NULL));
  47866. /* Test that a static ASN1_OBJECT can be freed. */
  47867. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  47868. ASN1_OBJECT_free(&s);
  47869. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  47870. ASN1_OBJECT_free(a);
  47871. a = NULL;
  47872. s.obj = der;
  47873. s.objSz = sizeof(der);
  47874. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  47875. ASN1_OBJECT_free(a);
  47876. ASN1_OBJECT_free(&s);
  47877. #endif /* OPENSSL_EXTRA */
  47878. return EXPECT_RESULT();
  47879. }
  47880. static int test_wolfSSL_ASN1_get_object(void)
  47881. {
  47882. EXPECT_DECLS;
  47883. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  47884. const unsigned char* derBuf = cliecc_cert_der_256;
  47885. const unsigned char* nullPtr = NULL;
  47886. const unsigned char objDerInvalidLen[] = { 0x30, 0x81 };
  47887. const unsigned char objDerBadLen[] = { 0x30, 0x04 };
  47888. const unsigned char objDerNotObj[] = { 0x02, 0x01, 0x00 };
  47889. const unsigned char objDerNoData[] = { 0x06, 0x00 };
  47890. const unsigned char* p;
  47891. unsigned char objDer[10];
  47892. unsigned char* der;
  47893. unsigned char* derPtr;
  47894. int len = sizeof_cliecc_cert_der_256;
  47895. long asnLen = 0;
  47896. int tag = 0;
  47897. int cls = 0;
  47898. ASN1_OBJECT* a = NULL;
  47899. ASN1_OBJECT s;
  47900. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  47901. /* Invalid encoding at length. */
  47902. p = objDerInvalidLen;
  47903. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  47904. 0x80);
  47905. p = objDerBadLen;
  47906. /* Error = 0x80, Constructed = 0x20 */
  47907. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  47908. 0x80 | 0x20);
  47909. /* Read a couple TLV triplets and make sure they match the expected values
  47910. */
  47911. /* SEQUENCE */
  47912. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, len) & 0x80, 0);
  47913. ExpectIntEQ(asnLen, 861);
  47914. ExpectIntEQ(tag, 0x10);
  47915. ExpectIntEQ(cls, 0);
  47916. /* SEQUENCE */
  47917. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  47918. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  47919. ExpectIntEQ(asnLen, 772);
  47920. ExpectIntEQ(tag, 0x10);
  47921. ExpectIntEQ(cls, 0);
  47922. /* [0] */
  47923. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  47924. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  47925. ExpectIntEQ(asnLen, 3);
  47926. ExpectIntEQ(tag, 0);
  47927. ExpectIntEQ(cls, 0x80);
  47928. /* INTEGER */
  47929. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  47930. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  47931. ExpectIntEQ(asnLen, 1);
  47932. ExpectIntEQ(tag, 0x2);
  47933. ExpectIntEQ(cls, 0);
  47934. derBuf += asnLen;
  47935. /* INTEGER */
  47936. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  47937. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  47938. ExpectIntEQ(asnLen, 20);
  47939. ExpectIntEQ(tag, 0x2);
  47940. ExpectIntEQ(cls, 0);
  47941. derBuf += asnLen;
  47942. /* SEQUENCE */
  47943. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  47944. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  47945. ExpectIntEQ(asnLen, 10);
  47946. ExpectIntEQ(tag, 0x10);
  47947. ExpectIntEQ(cls, 0);
  47948. /* Found OBJECT_ID. */
  47949. /* Invalid parameter testing. */
  47950. ExpectIntEQ(ASN1_get_object(NULL, NULL, NULL, NULL, 0), 0x80);
  47951. ExpectIntEQ(ASN1_get_object(&nullPtr, NULL, NULL, NULL, 0), 0x80);
  47952. ExpectIntEQ(ASN1_get_object(NULL, &asnLen, &tag, &cls, len), 0x80);
  47953. ExpectIntEQ(ASN1_get_object(&nullPtr, &asnLen, &tag, &cls, len), 0x80);
  47954. ExpectIntEQ(ASN1_get_object(&derBuf, NULL, &tag, &cls, len), 0x80);
  47955. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, NULL, &cls, len), 0x80);
  47956. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, NULL, len), 0x80);
  47957. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, 0), 0x80);
  47958. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, -1), 0x80);
  47959. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, -1));
  47960. ExpectNull(d2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  47961. ExpectNull(d2i_ASN1_OBJECT(NULL, &derBuf, -1));
  47962. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, 0));
  47963. ExpectNull(d2i_ASN1_OBJECT(&a, NULL, len));
  47964. ExpectNull(d2i_ASN1_OBJECT(&a, &nullPtr, len));
  47965. ExpectNull(d2i_ASN1_OBJECT(&a, &derBuf, -1));
  47966. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, -1));
  47967. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  47968. ExpectNull(c2i_ASN1_OBJECT(NULL, &derBuf, -1));
  47969. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, 1));
  47970. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, 1));
  47971. /* Invalid encoding at length. */
  47972. p = objDerInvalidLen;
  47973. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerInvalidLen)));
  47974. p = objDerBadLen;
  47975. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerBadLen)));
  47976. p = objDerNotObj;
  47977. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNotObj)));
  47978. p = objDerNoData;
  47979. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNoData)));
  47980. /* Create an ASN OBJECT from content */
  47981. p = derBuf + 2;
  47982. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 8));
  47983. ASN1_OBJECT_free(a);
  47984. a = NULL;
  47985. /* Create an ASN OBJECT from DER */
  47986. ExpectNotNull(d2i_ASN1_OBJECT(&a, &derBuf, len));
  47987. /* Invalid parameter testing. */
  47988. ExpectIntEQ(i2d_ASN1_OBJECT(NULL, NULL), 0);
  47989. ExpectIntEQ(i2d_ASN1_OBJECT(&s, NULL), 0);
  47990. ExpectIntEQ(i2d_ASN1_OBJECT(a, NULL), 10);
  47991. der = NULL;
  47992. ExpectIntEQ(i2d_ASN1_OBJECT(a, &der), 10);
  47993. derPtr = objDer;
  47994. ExpectIntEQ(i2d_ASN1_OBJECT(a, &derPtr), 10);
  47995. ExpectPtrNE(derPtr, objDer);
  47996. ExpectIntEQ(XMEMCMP(der, objDer, 10), 0);
  47997. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  47998. ASN1_OBJECT_free(a);
  47999. #endif /* OPENSSL_EXTRA && HAVE_ECC && USE_CERT_BUFFERS_256 */
  48000. return EXPECT_RESULT();
  48001. }
  48002. static int test_wolfSSL_i2a_ASN1_OBJECT(void)
  48003. {
  48004. EXPECT_DECLS;
  48005. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48006. ASN1_OBJECT* obj = NULL;
  48007. ASN1_OBJECT* a = NULL;
  48008. BIO *bio = NULL;
  48009. const unsigned char notObjDer[] = { 0x04, 0x01, 0xff };
  48010. const unsigned char* p;
  48011. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  48012. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  48013. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, obj), 0);
  48014. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, NULL), 0);
  48015. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(NULL, obj), 0);
  48016. /* No DER encoding in ASN1_OBJECT. */
  48017. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_new());
  48018. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 0);
  48019. ASN1_OBJECT_free(a);
  48020. a = NULL;
  48021. /* DER encoding */
  48022. p = notObjDer;
  48023. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 3));
  48024. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 5);
  48025. ASN1_OBJECT_free(a);
  48026. BIO_free(bio);
  48027. ASN1_OBJECT_free(obj);
  48028. #endif
  48029. return EXPECT_RESULT();
  48030. }
  48031. static int test_wolfSSL_i2t_ASN1_OBJECT(void)
  48032. {
  48033. EXPECT_DECLS;
  48034. #if defined(OPENSSL_EXTRA) && \
  48035. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  48036. char buf[50] = {0};
  48037. ASN1_OBJECT* obj;
  48038. const char* oid = "2.5.29.19";
  48039. const char* ln = "X509v3 Basic Constraints";
  48040. obj = NULL;
  48041. ExpectIntEQ(i2t_ASN1_OBJECT(NULL, sizeof(buf), obj), 0);
  48042. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), NULL), 0);
  48043. ExpectIntEQ(i2t_ASN1_OBJECT(buf, 0, NULL), 0);
  48044. ExpectNotNull(obj = OBJ_txt2obj(oid, 0));
  48045. XMEMSET(buf, 0, sizeof(buf));
  48046. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), obj), XSTRLEN(ln));
  48047. ExpectIntEQ(XSTRNCMP(buf, ln, XSTRLEN(ln)), 0);
  48048. ASN1_OBJECT_free(obj);
  48049. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  48050. return EXPECT_RESULT();
  48051. }
  48052. static int test_wolfSSL_sk_ASN1_OBJECT(void)
  48053. {
  48054. EXPECT_DECLS;
  48055. #if !defined(NO_ASN) && (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL))
  48056. WOLFSSL_STACK* sk = NULL;
  48057. WOLFSSL_ASN1_OBJECT* obj;
  48058. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48059. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48060. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48061. sk = NULL;
  48062. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48063. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, NULL), -1);
  48064. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, NULL), 0);
  48065. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, obj), -1);
  48066. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48067. wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
  48068. sk = NULL;
  48069. /* obj freed in pop_free call. */
  48070. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48071. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48072. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48073. ExpectPtrEq(obj, wolfSSL_sk_ASN1_OBJECT_pop(sk));
  48074. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48075. wolfSSL_ASN1_OBJECT_free(obj);
  48076. #endif /* !NO_ASN && (OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL) */
  48077. return EXPECT_RESULT();
  48078. }
  48079. static int test_wolfSSL_ASN1_STRING(void)
  48080. {
  48081. EXPECT_DECLS;
  48082. #if defined(OPENSSL_EXTRA)
  48083. ASN1_STRING* str = NULL;
  48084. ASN1_STRING* c = NULL;
  48085. const char data[] = "hello wolfSSL";
  48086. const char data2[] = "Same len data";
  48087. const char longData[] =
  48088. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48089. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48090. ASN1_STRING_free(str);
  48091. str = NULL;
  48092. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48093. ExpectIntEQ(ASN1_STRING_type(str), V_ASN1_OCTET_STRING);
  48094. ExpectIntEQ(ASN1_STRING_type(NULL), 0);
  48095. /* Check setting to NULL works. */
  48096. ExpectIntEQ(ASN1_STRING_set(str, NULL, 0), 1);
  48097. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, sizeof(data)), 1);
  48098. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48099. ExpectIntEQ(ASN1_STRING_set(str, NULL, -1), 0);
  48100. ExpectIntEQ(ASN1_STRING_set(NULL, NULL, 0), 0);
  48101. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, NULL), 0);
  48102. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(str, NULL), 0);
  48103. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, str), 0);
  48104. ExpectNull(wolfSSL_ASN1_STRING_dup(NULL));
  48105. ExpectNotNull(c = wolfSSL_ASN1_STRING_dup(str));
  48106. ExpectIntEQ(ASN1_STRING_cmp(NULL, NULL), -1);
  48107. ExpectIntEQ(ASN1_STRING_cmp(str, NULL), -1);
  48108. ExpectIntEQ(ASN1_STRING_cmp(NULL, c), -1);
  48109. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48110. ExpectIntEQ(ASN1_STRING_set(c, (const void*)data2, -1), 1);
  48111. ExpectIntGT(ASN1_STRING_cmp(str, c), 0);
  48112. ExpectIntEQ(ASN1_STRING_set(str, (const void*)longData, -1), 1);
  48113. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(c, str), 1);
  48114. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48115. /* Check setting back to smaller size frees dynamic data. */
  48116. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48117. ExpectIntLT(ASN1_STRING_cmp(str, c), 0);
  48118. ExpectIntGT(ASN1_STRING_cmp(c, str), 0);
  48119. ExpectNull(ASN1_STRING_get0_data(NULL));
  48120. ExpectNotNull(ASN1_STRING_get0_data(str));
  48121. ExpectNull(ASN1_STRING_data(NULL));
  48122. ExpectNotNull(ASN1_STRING_data(str));
  48123. ExpectIntEQ(ASN1_STRING_length(NULL), 0);
  48124. ExpectIntGT(ASN1_STRING_length(str), 0);
  48125. ASN1_STRING_free(c);
  48126. ASN1_STRING_free(str);
  48127. ASN1_STRING_free(NULL);
  48128. #ifndef NO_WOLFSSL_STUB
  48129. ExpectNull(d2i_DISPLAYTEXT(NULL, NULL, 0));
  48130. #endif
  48131. #endif
  48132. return EXPECT_RESULT();
  48133. }
  48134. static int test_wolfSSL_ASN1_STRING_to_UTF8(void)
  48135. {
  48136. EXPECT_DECLS;
  48137. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_RSA) && \
  48138. !defined(NO_FILESYSTEM)
  48139. WOLFSSL_X509* x509 = NULL;
  48140. WOLFSSL_X509_NAME* subject = NULL;
  48141. WOLFSSL_X509_NAME_ENTRY* e = NULL;
  48142. WOLFSSL_ASN1_STRING* a = NULL;
  48143. FILE* file = XBADFILE;
  48144. int idx = 0;
  48145. char targetOutput[16] = "www.wolfssl.com";
  48146. unsigned char* actual_output = NULL;
  48147. int len = 0;
  48148. ExpectNotNull(file = fopen("./certs/server-cert.pem", "rb"));
  48149. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  48150. if (file != XBADFILE)
  48151. fclose(file);
  48152. /* wolfSSL_ASN1_STRING_to_UTF8(): NID_commonName */
  48153. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(x509));
  48154. ExpectIntEQ((idx = wolfSSL_X509_NAME_get_index_by_NID(subject,
  48155. NID_commonName, -1)), 5);
  48156. ExpectNotNull(e = wolfSSL_X509_NAME_get_entry(subject, idx));
  48157. ExpectNotNull(a = wolfSSL_X509_NAME_ENTRY_get_data(e));
  48158. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a)), 15);
  48159. ExpectIntEQ(strncmp((const char*)actual_output, targetOutput, (size_t)len), 0);
  48160. a = NULL;
  48161. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, valid) */
  48162. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, a)), -1);
  48163. /* wolfSSL_ASN1_STRING_to_UTF8(valid, NULL) */
  48164. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, NULL)), -1);
  48165. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL) */
  48166. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL)), -1);
  48167. wolfSSL_X509_free(x509);
  48168. XFREE(actual_output, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48169. ExpectNotNull(a = ASN1_STRING_new());
  48170. ExpectIntEQ(wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a), -1);
  48171. ASN1_STRING_free(a);
  48172. #endif
  48173. return EXPECT_RESULT();
  48174. }
  48175. static int test_wolfSSL_i2s_ASN1_STRING(void)
  48176. {
  48177. EXPECT_DECLS;
  48178. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48179. WOLFSSL_ASN1_STRING* str = NULL;
  48180. const char* data = "test_wolfSSL_i2s_ASN1_STRING";
  48181. char* ret = NULL;
  48182. ExpectNotNull(str = ASN1_STRING_new());
  48183. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, NULL));
  48184. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48185. ret = NULL;
  48186. /* No data. */
  48187. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48188. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48189. ret = NULL;
  48190. ExpectIntEQ(ASN1_STRING_set(str, data, 0), 1);
  48191. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48192. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48193. ret = NULL;
  48194. ExpectIntEQ(ASN1_STRING_set(str, data, -1), 1);
  48195. /* No type. */
  48196. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48197. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48198. ASN1_STRING_free(str);
  48199. #endif
  48200. return EXPECT_RESULT();
  48201. }
  48202. static int test_wolfSSL_ASN1_STRING_canon(void)
  48203. {
  48204. EXPECT_DECLS;
  48205. #if defined(WOLFSSL_TEST_STATIC_BUILD)
  48206. #if !defined(NO_CERTS) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  48207. defined(OPENSSL_EXTRA_X509_SMALL))
  48208. WOLFSSL_ASN1_STRING* orig = NULL;
  48209. WOLFSSL_ASN1_STRING* canon = NULL;
  48210. const char* data = "test_wolfSSL_ASN1_STRING_canon";
  48211. const char* whitespaceOnly = "\t\r\n";
  48212. const char* modData = " \x01\f\t\x02\r\n\v\xff\nTt \n";
  48213. const char* canonData = "\x01 \x02 \xff tt";
  48214. const char longData[] =
  48215. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48216. ExpectNotNull(orig = ASN1_STRING_new());
  48217. ExpectNotNull(canon = ASN1_STRING_new());
  48218. /* Invalid parameter testing. */
  48219. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48220. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48221. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, orig), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48222. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48223. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48224. ExpectIntEQ(ASN1_STRING_set(orig, longData, (int)XSTRLEN(data)), 1);
  48225. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48226. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48227. ExpectIntEQ(ASN1_STRING_set(orig, data, (int)XSTRLEN(data)), 1);
  48228. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48229. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48230. ASN1_STRING_free(orig);
  48231. orig = NULL;
  48232. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48233. ExpectIntEQ(ASN1_STRING_set(orig, modData, 15), 1);
  48234. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48235. ExpectIntEQ(ASN1_STRING_set(orig, canonData, 8), 1);
  48236. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48237. ASN1_STRING_free(orig);
  48238. orig = NULL;
  48239. ExpectNotNull(orig = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48240. ExpectIntEQ(ASN1_STRING_set(orig, whitespaceOnly, 3), 1);
  48241. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48242. ASN1_STRING_free(orig);
  48243. orig = NULL;
  48244. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48245. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48246. ASN1_STRING_free(orig);
  48247. ASN1_STRING_free(canon);
  48248. #endif
  48249. #endif
  48250. return EXPECT_RESULT();
  48251. }
  48252. static int test_wolfSSL_ASN1_STRING_print(void)
  48253. {
  48254. EXPECT_DECLS;
  48255. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_CERTS) && \
  48256. !defined(NO_BIO)
  48257. ASN1_STRING* asnStr = NULL;
  48258. const char HELLO_DATA[]= \
  48259. {'H','e','l','l','o',' ','w','o','l','f','S','S','L','!'};
  48260. #define MAX_UNPRINTABLE_CHAR 32
  48261. #define MAX_BUF 255
  48262. unsigned char unprintableData[MAX_UNPRINTABLE_CHAR + sizeof(HELLO_DATA)];
  48263. unsigned char expected[sizeof(unprintableData)+1];
  48264. unsigned char rbuf[MAX_BUF];
  48265. BIO *bio = NULL;
  48266. int p_len;
  48267. int i;
  48268. /* setup */
  48269. for (i = 0; i < (int)sizeof(HELLO_DATA); i++) {
  48270. unprintableData[i] = (unsigned char)HELLO_DATA[i];
  48271. expected[i] = (unsigned char)HELLO_DATA[i];
  48272. }
  48273. for (i = 0; i < (int)MAX_UNPRINTABLE_CHAR; i++) {
  48274. unprintableData[sizeof(HELLO_DATA)+i] = i;
  48275. if (i == (int)'\n' || i == (int)'\r')
  48276. expected[sizeof(HELLO_DATA)+i] = i;
  48277. else
  48278. expected[sizeof(HELLO_DATA)+i] = '.';
  48279. }
  48280. unprintableData[sizeof(unprintableData)-1] = '\0';
  48281. expected[sizeof(expected)-1] = '\0';
  48282. XMEMSET(rbuf, 0, MAX_BUF);
  48283. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48284. ExpectIntEQ(BIO_set_write_buf_size(bio, MAX_BUF), 0);
  48285. ExpectNotNull(asnStr = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48286. ExpectIntEQ(ASN1_STRING_set(asnStr,(const void*)unprintableData,
  48287. (int)sizeof(unprintableData)), 1);
  48288. /* test */
  48289. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, NULL), 0);
  48290. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, NULL), 0);
  48291. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, asnStr), 0);
  48292. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print(bio, asnStr), 46);
  48293. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 46), 46);
  48294. ExpectStrEQ((char*)rbuf, (const char*)expected);
  48295. BIO_free(bio);
  48296. bio = NULL;
  48297. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48298. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48299. /* Ensure there is 0 bytes available to write into. */
  48300. ExpectIntEQ(BIO_write(bio, rbuf, 1), 1);
  48301. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48302. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48303. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48304. ExpectIntEQ(BIO_set_write_buf_size(bio, 45), 1);
  48305. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48306. BIO_free(bio);
  48307. ASN1_STRING_free(asnStr);
  48308. #endif /* OPENSSL_EXTRA && !NO_ASN && !NO_CERTS && !NO_BIO */
  48309. return EXPECT_RESULT();
  48310. }
  48311. static int test_wolfSSL_ASN1_STRING_print_ex(void)
  48312. {
  48313. EXPECT_DECLS;
  48314. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48315. ASN1_STRING* asn_str = NULL;
  48316. const char data[] = "Hello wolfSSL!";
  48317. ASN1_STRING* esc_str = NULL;
  48318. const char esc_data[] = "a+;<>";
  48319. ASN1_STRING* neg_int = NULL;
  48320. const char neg_int_data[] = "\xff";
  48321. ASN1_STRING* neg_enum = NULL;
  48322. const char neg_enum_data[] = "\xff";
  48323. BIO *bio = NULL;
  48324. BIO *fixed = NULL;
  48325. unsigned long flags;
  48326. int p_len;
  48327. unsigned char rbuf[255];
  48328. /* setup */
  48329. XMEMSET(rbuf, 0, 255);
  48330. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48331. ExpectIntEQ(BIO_set_write_buf_size(bio, 255), 0);
  48332. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48333. ExpectNotNull(asn_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48334. ExpectIntEQ(ASN1_STRING_set(asn_str, (const void*)data, sizeof(data)), 1);
  48335. ExpectNotNull(esc_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48336. ExpectIntEQ(ASN1_STRING_set(esc_str, (const void*)esc_data,
  48337. sizeof(esc_data)), 1);
  48338. ExpectNotNull(neg_int = ASN1_STRING_type_new(V_ASN1_NEG_INTEGER));
  48339. ExpectIntEQ(ASN1_STRING_set(neg_int, (const void*)neg_int_data,
  48340. sizeof(neg_int_data) - 1), 1);
  48341. ExpectNotNull(neg_enum = ASN1_STRING_type_new(V_ASN1_NEG_ENUMERATED));
  48342. ExpectIntEQ(ASN1_STRING_set(neg_enum, (const void*)neg_enum_data,
  48343. sizeof(neg_enum_data) - 1), 1);
  48344. /* Invalid parameter testing. */
  48345. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, NULL, 0), 0);
  48346. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(bio, NULL, 0), 0);
  48347. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, asn_str, 0), 0);
  48348. /* no flags */
  48349. XMEMSET(rbuf, 0, 255);
  48350. flags = 0;
  48351. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 15);
  48352. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 15), 15);
  48353. ExpectStrEQ((char*)rbuf, "Hello wolfSSL!");
  48354. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48355. /* Ensure there is 0 bytes available to write into. */
  48356. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48357. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48358. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48359. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48360. ExpectIntEQ(BIO_set_write_buf_size(fixed, 14), 1);
  48361. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48362. /* RFC2253 Escape */
  48363. XMEMSET(rbuf, 0, 255);
  48364. flags = ASN1_STRFLGS_ESC_2253;
  48365. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, esc_str, flags), 9);
  48366. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 9), 9);
  48367. ExpectStrEQ((char*)rbuf, "a\\+\\;\\<\\>");
  48368. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48369. /* Ensure there is 0 bytes available to write into. */
  48370. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48371. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48372. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48373. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48374. ExpectIntEQ(BIO_set_write_buf_size(fixed, 8), 1);
  48375. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48376. /* Show type */
  48377. XMEMSET(rbuf, 0, 255);
  48378. flags = ASN1_STRFLGS_SHOW_TYPE;
  48379. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 28);
  48380. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 28), 28);
  48381. ExpectStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!");
  48382. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48383. /* Ensure there is 0 bytes available to write into. */
  48384. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48385. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48386. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48387. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48388. ExpectIntEQ(BIO_set_write_buf_size(fixed, 12), 1);
  48389. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48390. ExpectIntEQ(BIO_set_write_buf_size(fixed, 27), 1);
  48391. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48392. /* Dump All */
  48393. XMEMSET(rbuf, 0, 255);
  48394. flags = ASN1_STRFLGS_DUMP_ALL;
  48395. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 31);
  48396. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 31), 31);
  48397. ExpectStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100");
  48398. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48399. /* Ensure there is 0 bytes available to write into. */
  48400. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48401. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48402. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48403. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48404. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48405. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48406. /* Dump Der */
  48407. XMEMSET(rbuf, 0, 255);
  48408. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_DUMP_DER;
  48409. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 35);
  48410. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 35), 35);
  48411. ExpectStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100");
  48412. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48413. /* Ensure there is 0 bytes available to write into. */
  48414. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48415. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48416. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48417. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48418. ExpectIntEQ(BIO_set_write_buf_size(fixed, 2), 1);
  48419. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48420. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48421. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48422. /* Dump All + Show type */
  48423. XMEMSET(rbuf, 0, 255);
  48424. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48425. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 44);
  48426. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 44), 44);
  48427. ExpectStrEQ((char*)rbuf, "OCTET STRING:#48656C6C6F20776F6C6653534C2100");
  48428. /* Dump All + Show type - Negative Integer. */
  48429. XMEMSET(rbuf, 0, 255);
  48430. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48431. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_int, flags), 11);
  48432. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 11), 11);
  48433. ExpectStrEQ((char*)rbuf, "INTEGER:#FF");
  48434. /* Dump All + Show type - Negative Enumerated. */
  48435. XMEMSET(rbuf, 0, 255);
  48436. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48437. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_enum, flags), 14);
  48438. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 14), 14);
  48439. ExpectStrEQ((char*)rbuf, "ENUMERATED:#FF");
  48440. BIO_free(fixed);
  48441. BIO_free(bio);
  48442. ASN1_STRING_free(asn_str);
  48443. ASN1_STRING_free(esc_str);
  48444. ASN1_STRING_free(neg_int);
  48445. ASN1_STRING_free(neg_enum);
  48446. ExpectStrEQ(wolfSSL_ASN1_tag2str(-1), "(unknown)");
  48447. ExpectStrEQ(wolfSSL_ASN1_tag2str(31), "(unknown)");
  48448. #endif
  48449. return EXPECT_RESULT();
  48450. }
  48451. static int test_wolfSSL_ASN1_UNIVERSALSTRING_to_string(void)
  48452. {
  48453. EXPECT_DECLS;
  48454. #if defined(OPENSSL_ALL) && !defined(NO_ASN)
  48455. ASN1_STRING* asn1str_test = NULL;
  48456. ASN1_STRING* asn1str_answer = NULL;
  48457. /* Each character is encoded using 4 bytes */
  48458. char input[] = {
  48459. 0, 0, 0, 'T',
  48460. 0, 0, 0, 'e',
  48461. 0, 0, 0, 's',
  48462. 0, 0, 0, 't',
  48463. };
  48464. char output[] = "Test";
  48465. char badInput[] = {
  48466. 1, 0, 0, 'T',
  48467. 0, 1, 0, 'e',
  48468. 0, 0, 1, 's',
  48469. };
  48470. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(NULL), 0);
  48471. /* Test wrong type. */
  48472. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48473. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48474. ASN1_STRING_free(asn1str_test);
  48475. asn1str_test = NULL;
  48476. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING));
  48477. /* Test bad length. */
  48478. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input) - 1), 1);
  48479. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48480. /* Test bad input. */
  48481. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 0, 4), 1);
  48482. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48483. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 4, 4), 1);
  48484. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48485. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 8, 4), 1);
  48486. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48487. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input)), 1);
  48488. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 1);
  48489. ExpectNotNull(
  48490. asn1str_answer = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48491. ExpectIntEQ(ASN1_STRING_set(asn1str_answer, output, sizeof(output)-1), 1);
  48492. ExpectIntEQ(ASN1_STRING_cmp(asn1str_test, asn1str_answer), 0);
  48493. ASN1_STRING_free(asn1str_test);
  48494. ASN1_STRING_free(asn1str_answer);
  48495. #endif /* OPENSSL_ALL && !NO_ASN */
  48496. return EXPECT_RESULT();
  48497. }
  48498. static int test_wolfSSL_ASN1_GENERALIZEDTIME_free(void)
  48499. {
  48500. EXPECT_DECLS;
  48501. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48502. WOLFSSL_ASN1_GENERALIZEDTIME* asn1_gtime = NULL;
  48503. ExpectNotNull(asn1_gtime = ASN1_GENERALIZEDTIME_new());
  48504. if (asn1_gtime != NULL)
  48505. XMEMCPY(asn1_gtime->data, "20180504123500Z", ASN_GENERALIZED_TIME_SIZE);
  48506. ASN1_GENERALIZEDTIME_free(asn1_gtime);
  48507. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME */
  48508. return EXPECT_RESULT();
  48509. }
  48510. static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void)
  48511. {
  48512. EXPECT_DECLS;
  48513. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  48514. WOLFSSL_ASN1_GENERALIZEDTIME* gtime = NULL;
  48515. BIO* bio = NULL;
  48516. unsigned char buf[24];
  48517. int i;
  48518. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48519. BIO_set_write_buf_size(bio, 24);
  48520. ExpectNotNull(gtime = ASN1_GENERALIZEDTIME_new());
  48521. /* Type not set. */
  48522. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  48523. ExpectIntEQ(wolfSSL_ASN1_TIME_set_string(gtime, "20180504123500Z"), 1);
  48524. /* Invalid parameters testing. */
  48525. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48526. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48527. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, gtime), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48528. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 1);
  48529. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 20);
  48530. ExpectIntEQ(XMEMCMP(buf, "May 04 12:35:00 2018", 20), 0);
  48531. BIO_free(bio);
  48532. bio = NULL;
  48533. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48534. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48535. /* Ensure there is 0 bytes available to write into. */
  48536. ExpectIntEQ(BIO_write(bio, buf, 1), 1);
  48537. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  48538. for (i = 1; i < 20; i++) {
  48539. ExpectIntEQ(BIO_set_write_buf_size(bio, i), 1);
  48540. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  48541. }
  48542. BIO_free(bio);
  48543. wolfSSL_ASN1_GENERALIZEDTIME_free(gtime);
  48544. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  48545. return EXPECT_RESULT();
  48546. }
  48547. static int test_wolfSSL_ASN1_TIME(void)
  48548. {
  48549. EXPECT_DECLS;
  48550. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48551. WOLFSSL_ASN1_TIME* asn_time = NULL;
  48552. unsigned char *data;
  48553. ExpectNotNull(asn_time = ASN1_TIME_new());
  48554. #ifndef NO_WOLFSSL_STUB
  48555. ExpectNotNull(ASN1_TIME_set(asn_time, 1));
  48556. #endif
  48557. ExpectIntEQ(ASN1_TIME_set_string(NULL, NULL), 0);
  48558. ExpectIntEQ(ASN1_TIME_set_string(asn_time, NULL), 0);
  48559. ExpectIntEQ(ASN1_TIME_set_string(NULL,
  48560. "String longer than CTC_DATA_SIZE that is 32 bytes"), 0);
  48561. ExpectIntEQ(ASN1_TIME_set_string(NULL, "101219181011Z"), 1);
  48562. ExpectIntEQ(ASN1_TIME_set_string(asn_time, "101219181011Z"), 1);
  48563. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(NULL), 0);
  48564. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(asn_time), ASN_UTC_TIME_SIZE - 1);
  48565. ExpectNull(wolfSSL_ASN1_TIME_get_data(NULL));
  48566. ExpectNotNull(data = wolfSSL_ASN1_TIME_get_data(asn_time));
  48567. ExpectIntEQ(XMEMCMP(data, "101219181011Z", 14), 0);
  48568. ExpectIntEQ(ASN1_TIME_check(NULL), 0);
  48569. ExpectIntEQ(ASN1_TIME_check(asn_time), 1);
  48570. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Z"), 1);
  48571. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Za"), 0);
  48572. ASN1_TIME_free(asn_time);
  48573. ASN1_TIME_free(NULL);
  48574. #endif
  48575. return EXPECT_RESULT();
  48576. }
  48577. static int test_wolfSSL_ASN1_TIME_to_string(void)
  48578. {
  48579. EXPECT_DECLS;
  48580. #ifndef NO_ASN_TIME
  48581. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  48582. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  48583. WOLFSSL_ASN1_TIME* t = NULL;
  48584. char buf[ASN_GENERALIZED_TIME_SIZE];
  48585. ExpectNotNull((t = ASN1_TIME_new()));
  48586. ExpectIntEQ(ASN1_TIME_set_string(t, "030222211515Z"), 1);
  48587. /* Invalid parameter testing. */
  48588. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 4));
  48589. ExpectNull(ASN1_TIME_to_string(t, NULL, 4));
  48590. ExpectNull(ASN1_TIME_to_string(NULL, buf, 4));
  48591. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 5));
  48592. ExpectNull(ASN1_TIME_to_string(NULL, buf, 5));
  48593. ExpectNull(ASN1_TIME_to_string(t, NULL, 5));
  48594. ExpectNull(ASN1_TIME_to_string(t, buf, 4));
  48595. /* Buffer needs to be longer than minimum of 5 characters. */
  48596. ExpectNull(ASN1_TIME_to_string(t, buf, 5));
  48597. ASN1_TIME_free(t);
  48598. #endif
  48599. #endif /* NO_ASN_TIME */
  48600. return EXPECT_RESULT();
  48601. }
  48602. static int test_wolfSSL_ASN1_TIME_diff_compare(void)
  48603. {
  48604. EXPECT_DECLS;
  48605. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48606. ASN1_TIME* fromTime = NULL;
  48607. ASN1_TIME* closeToTime = NULL;
  48608. ASN1_TIME* toTime = NULL;
  48609. ASN1_TIME* invalidTime = NULL;
  48610. int daysDiff = 0;
  48611. int secsDiff = 0;
  48612. ExpectNotNull((fromTime = ASN1_TIME_new()));
  48613. /* Feb 22, 2003, 21:15:15 */
  48614. ExpectIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), 1);
  48615. ExpectNotNull((closeToTime = ASN1_TIME_new()));
  48616. /* Feb 22, 2003, 21:16:15 */
  48617. ExpectIntEQ(ASN1_TIME_set_string(closeToTime, "030222211615Z"), 1);
  48618. ExpectNotNull((toTime = ASN1_TIME_new()));
  48619. /* Dec 19, 2010, 18:10:11 */
  48620. ExpectIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1);
  48621. ExpectNotNull((invalidTime = ASN1_TIME_new()));
  48622. /* Dec 19, 2010, 18:10:11 but 'U' instead of 'Z' which is invalid. */
  48623. ExpectIntEQ(ASN1_TIME_set_string(invalidTime, "102519181011U"), 1);
  48624. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, invalidTime), 0);
  48625. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, invalidTime, toTime), 0);
  48626. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48627. /* Error conditions. */
  48628. ExpectIntEQ(ASN1_TIME_diff(NULL, &secsDiff, fromTime, toTime), 0);
  48629. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, NULL, fromTime, toTime), 0);
  48630. /* If both times are NULL, difference is 0. */
  48631. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, NULL), 1);
  48632. ExpectIntEQ(daysDiff, 0);
  48633. ExpectIntEQ(secsDiff, 0);
  48634. /* If one time is NULL, it defaults to the current time. */
  48635. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, toTime), 1);
  48636. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, NULL), 1);
  48637. /* Normal operation. Both times non-NULL. */
  48638. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48639. ExpectIntEQ(daysDiff, 2856);
  48640. ExpectIntEQ(secsDiff, 75296);
  48641. /* Swapping the times should return negative values. */
  48642. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, toTime, fromTime), 1);
  48643. ExpectIntEQ(daysDiff, -2856);
  48644. ExpectIntEQ(secsDiff, -75296);
  48645. /* Compare with invalid time string. */
  48646. ExpectIntEQ(ASN1_TIME_compare(fromTime, invalidTime), -2);
  48647. ExpectIntEQ(ASN1_TIME_compare(invalidTime, toTime), -2);
  48648. /* Compare with days difference of 0. */
  48649. ExpectIntEQ(ASN1_TIME_compare(fromTime, closeToTime), -1);
  48650. ExpectIntEQ(ASN1_TIME_compare(closeToTime, fromTime), 1);
  48651. /* Days and seconds differences not 0. */
  48652. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  48653. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  48654. /* Same time. */
  48655. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  48656. /* Compare regression test: No seconds difference, just difference in days.
  48657. */
  48658. ASN1_TIME_set_string(fromTime, "19700101000000Z");
  48659. ASN1_TIME_set_string(toTime, "19800101000000Z");
  48660. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  48661. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  48662. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  48663. /* Edge case with Unix epoch. */
  48664. ExpectNotNull(ASN1_TIME_set_string(fromTime, "19700101000000Z"));
  48665. ExpectNotNull(ASN1_TIME_set_string(toTime, "19800101000000Z"));
  48666. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48667. ExpectIntEQ(daysDiff, 3652);
  48668. ExpectIntEQ(secsDiff, 0);
  48669. /* Edge case with year > 2038 (year 2038 problem). */
  48670. ExpectNotNull(ASN1_TIME_set_string(toTime, "99991231235959Z"));
  48671. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48672. ExpectIntEQ(daysDiff, 2932896);
  48673. ExpectIntEQ(secsDiff, 86399);
  48674. ASN1_TIME_free(fromTime);
  48675. ASN1_TIME_free(closeToTime);
  48676. ASN1_TIME_free(toTime);
  48677. ASN1_TIME_free(invalidTime);
  48678. #endif
  48679. return EXPECT_RESULT();
  48680. }
  48681. static int test_wolfSSL_ASN1_TIME_adj(void)
  48682. {
  48683. EXPECT_DECLS;
  48684. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  48685. !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  48686. const int year = 365*24*60*60;
  48687. const int day = 24*60*60;
  48688. const int hour = 60*60;
  48689. const int mini = 60;
  48690. const byte asn_utc_time = ASN_UTC_TIME;
  48691. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  48692. const byte asn_gen_time = ASN_GENERALIZED_TIME;
  48693. #endif
  48694. WOLFSSL_ASN1_TIME* asn_time = NULL;
  48695. WOLFSSL_ASN1_TIME* s = NULL;
  48696. int offset_day;
  48697. long offset_sec;
  48698. char date_str[CTC_DATE_SIZE + 1];
  48699. time_t t;
  48700. ExpectNotNull(s = wolfSSL_ASN1_TIME_new());
  48701. /* UTC notation test */
  48702. /* 2000/2/15 20:30:00 */
  48703. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  48704. offset_day = 7;
  48705. offset_sec = 45 * mini;
  48706. /* offset_sec = -45 * min;*/
  48707. ExpectNotNull(asn_time =
  48708. wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
  48709. ExpectTrue(asn_time->type == asn_utc_time);
  48710. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48711. CTC_DATE_SIZE));
  48712. date_str[CTC_DATE_SIZE] = '\0';
  48713. ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
  48714. /* negative offset */
  48715. offset_sec = -45 * mini;
  48716. asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
  48717. ExpectNotNull(asn_time);
  48718. ExpectTrue(asn_time->type == asn_utc_time);
  48719. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48720. CTC_DATE_SIZE));
  48721. date_str[CTC_DATE_SIZE] = '\0';
  48722. ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
  48723. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  48724. s = NULL;
  48725. XMEMSET(date_str, 0, sizeof(date_str));
  48726. /* Generalized time will overflow time_t if not long */
  48727. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  48728. s = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL,
  48729. DYNAMIC_TYPE_OPENSSL);
  48730. /* GeneralizedTime notation test */
  48731. /* 2055/03/01 09:00:00 */
  48732. t = (time_t)85 * year + 59 * day + 9 * hour + 21 * day;
  48733. offset_day = 12;
  48734. offset_sec = 10 * mini;
  48735. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  48736. offset_sec));
  48737. ExpectTrue(asn_time->type == asn_gen_time);
  48738. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48739. CTC_DATE_SIZE));
  48740. date_str[CTC_DATE_SIZE] = '\0';
  48741. ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
  48742. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  48743. s = NULL;
  48744. XMEMSET(date_str, 0, sizeof(date_str));
  48745. #endif /* !TIME_T_NOT_64BIT && !NO_64BIT */
  48746. /* if WOLFSSL_ASN1_TIME struct is not allocated */
  48747. s = NULL;
  48748. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 15 + 7 * day;
  48749. offset_day = 7;
  48750. offset_sec = 45 * mini;
  48751. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  48752. offset_sec));
  48753. ExpectTrue(asn_time->type == asn_utc_time);
  48754. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48755. CTC_DATE_SIZE));
  48756. date_str[CTC_DATE_SIZE] = '\0';
  48757. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  48758. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  48759. asn_time = NULL;
  48760. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
  48761. offset_sec));
  48762. ExpectTrue(asn_time->type == asn_utc_time);
  48763. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48764. CTC_DATE_SIZE));
  48765. date_str[CTC_DATE_SIZE] = '\0';
  48766. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  48767. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  48768. #endif
  48769. return EXPECT_RESULT();
  48770. }
  48771. static int test_wolfSSL_ASN1_TIME_to_tm(void)
  48772. {
  48773. EXPECT_DECLS;
  48774. #if (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  48775. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  48776. defined(OPENSSL_ALL)) && !defined(NO_ASN_TIME)
  48777. ASN1_TIME asnTime;
  48778. struct tm tm;
  48779. time_t testTime = 1683926567; /* Fri May 12 09:22:47 PM UTC 2023 */
  48780. XMEMSET(&tm, 0, sizeof(struct tm));
  48781. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  48782. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515Z"), 1);
  48783. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, NULL), 1);
  48784. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  48785. ExpectIntEQ(tm.tm_sec, 15);
  48786. ExpectIntEQ(tm.tm_min, 15);
  48787. ExpectIntEQ(tm.tm_hour, 21);
  48788. ExpectIntEQ(tm.tm_mday, 22);
  48789. ExpectIntEQ(tm.tm_mon, 1);
  48790. ExpectIntEQ(tm.tm_year, 100);
  48791. ExpectIntEQ(tm.tm_isdst, 0);
  48792. #ifdef XMKTIME
  48793. ExpectIntEQ(tm.tm_wday, 2);
  48794. ExpectIntEQ(tm.tm_yday, 52);
  48795. #endif
  48796. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "500222211515Z"), 1);
  48797. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  48798. ExpectIntEQ(tm.tm_year, 50);
  48799. /* Get current time. */
  48800. ExpectIntEQ(ASN1_TIME_to_tm(NULL, NULL), 0);
  48801. ExpectIntEQ(ASN1_TIME_to_tm(NULL, &tm), 1);
  48802. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  48803. /* 0 length. */
  48804. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  48805. /* No type. */
  48806. asnTime.length = 1;
  48807. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  48808. /* Not UTCTIME length. */
  48809. asnTime.type = V_ASN1_UTCTIME;
  48810. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  48811. /* Not GENERALIZEDTIME length. */
  48812. asnTime.type = V_ASN1_GENERALIZEDTIME;
  48813. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  48814. /* Not Zulu timezone. */
  48815. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515U"), 1);
  48816. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  48817. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "20000222211515U"), 1);
  48818. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  48819. #ifdef XMKTIME
  48820. ExpectNotNull(ASN1_TIME_adj(&asnTime, testTime, 0, 0));
  48821. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  48822. ExpectIntEQ(tm.tm_sec, 47);
  48823. ExpectIntEQ(tm.tm_min, 22);
  48824. ExpectIntEQ(tm.tm_hour, 21);
  48825. ExpectIntEQ(tm.tm_mday, 12);
  48826. ExpectIntEQ(tm.tm_mon, 4);
  48827. ExpectIntEQ(tm.tm_year, 123);
  48828. ExpectIntEQ(tm.tm_wday, 5);
  48829. ExpectIntEQ(tm.tm_yday, 131);
  48830. /* Confirm that when used with a tm struct from ASN1_TIME_adj, all other
  48831. fields are zeroed out as expected. */
  48832. ExpectIntEQ(tm.tm_isdst, 0);
  48833. #endif
  48834. #endif
  48835. return EXPECT_RESULT();
  48836. }
  48837. static int test_wolfSSL_ASN1_TIME_to_generalizedtime(void)
  48838. {
  48839. EXPECT_DECLS;
  48840. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48841. WOLFSSL_ASN1_TIME *t = NULL;
  48842. WOLFSSL_ASN1_TIME *out = NULL;
  48843. WOLFSSL_ASN1_TIME *gtime = NULL;
  48844. int tlen = 0;
  48845. unsigned char *data = NULL;
  48846. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  48847. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(NULL, &out));
  48848. /* type not set. */
  48849. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  48850. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48851. t = NULL;
  48852. /* UTC Time test */
  48853. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  48854. if (t != NULL) {
  48855. XMEMSET(t->data, 0, ASN_GENERALIZED_TIME_SIZE);
  48856. t->type = ASN_UTC_TIME;
  48857. t->length = ASN_UTC_TIME_SIZE;
  48858. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  48859. }
  48860. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t), ASN_UTC_TIME_SIZE);
  48861. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)), "050727123456Z");
  48862. out = NULL;
  48863. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  48864. wolfSSL_ASN1_TIME_free(gtime);
  48865. gtime = NULL;
  48866. ExpectNotNull(out = wolfSSL_ASN1_TIME_new());
  48867. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  48868. ExpectPtrEq(gtime, out);
  48869. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  48870. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  48871. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  48872. /* Generalized Time test */
  48873. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  48874. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  48875. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  48876. if (t != NULL) {
  48877. t->type = ASN_GENERALIZED_TIME;
  48878. t->length = ASN_GENERALIZED_TIME_SIZE;
  48879. XMEMCPY(t->data, "20050727123456Z", ASN_GENERALIZED_TIME_SIZE);
  48880. }
  48881. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t),
  48882. ASN_GENERALIZED_TIME_SIZE);
  48883. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)),
  48884. "20050727123456Z");
  48885. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  48886. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  48887. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  48888. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  48889. /* UTC Time to Generalized Time 1900's test */
  48890. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  48891. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  48892. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  48893. if (t != NULL) {
  48894. t->type = ASN_UTC_TIME;
  48895. t->length = ASN_UTC_TIME_SIZE;
  48896. XMEMCPY(t->data, "500727123456Z", ASN_UTC_TIME_SIZE);
  48897. }
  48898. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  48899. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  48900. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  48901. ExpectStrEQ((char*)gtime->data, "19500727123456Z");
  48902. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48903. /* Null parameter test */
  48904. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  48905. gtime = NULL;
  48906. out = NULL;
  48907. if (t != NULL) {
  48908. t->type = ASN_UTC_TIME;
  48909. t->length = ASN_UTC_TIME_SIZE;
  48910. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  48911. }
  48912. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, NULL));
  48913. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  48914. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  48915. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  48916. XFREE(gtime, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48917. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48918. #endif
  48919. return EXPECT_RESULT();
  48920. }
  48921. static int test_wolfSSL_ASN1_TIME_print(void)
  48922. {
  48923. EXPECT_DECLS;
  48924. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_BIO) && \
  48925. (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  48926. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  48927. defined(OPENSSL_ALL)) && defined(USE_CERT_BUFFERS_2048) && \
  48928. !defined(NO_ASN_TIME)
  48929. BIO* bio = NULL;
  48930. BIO* fixed = NULL;
  48931. X509* x509 = NULL;
  48932. const unsigned char* der = client_cert_der_2048;
  48933. ASN1_TIME* notAfter = NULL;
  48934. ASN1_TIME* notBefore = NULL;
  48935. unsigned char buf[25];
  48936. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48937. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48938. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(der,
  48939. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  48940. ExpectNotNull(notBefore = X509_get_notBefore(x509));
  48941. ExpectIntEQ(ASN1_TIME_print(NULL, NULL), 0);
  48942. ExpectIntEQ(ASN1_TIME_print(bio, NULL), 0);
  48943. ExpectIntEQ(ASN1_TIME_print(NULL, notBefore), 0);
  48944. ExpectIntEQ(ASN1_TIME_print(bio, notBefore), 1);
  48945. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  48946. ExpectIntEQ(XMEMCMP(buf, "Dec 13 22:19:28 2023 GMT", sizeof(buf) - 1), 0);
  48947. /* Test BIO_write fails. */
  48948. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48949. /* Ensure there is 0 bytes available to write into. */
  48950. ExpectIntEQ(BIO_write(fixed, buf, 1), 1);
  48951. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  48952. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48953. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  48954. ExpectIntEQ(BIO_set_write_buf_size(fixed, 23), 1);
  48955. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  48956. /* create a bad time and test results */
  48957. ExpectNotNull(notAfter = X509_get_notAfter(x509));
  48958. ExpectIntEQ(ASN1_TIME_check(notAfter), 1);
  48959. if (EXPECT_SUCCESS()) {
  48960. notAfter->data[8] = 0;
  48961. notAfter->data[3] = 0;
  48962. }
  48963. ExpectIntNE(ASN1_TIME_print(bio, notAfter), 1);
  48964. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  48965. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  48966. ExpectIntEQ(ASN1_TIME_check(notAfter), 0);
  48967. BIO_free(bio);
  48968. BIO_free(fixed);
  48969. X509_free(x509);
  48970. #endif
  48971. return EXPECT_RESULT();
  48972. }
  48973. static int test_wolfSSL_ASN1_UTCTIME_print(void)
  48974. {
  48975. EXPECT_DECLS;
  48976. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  48977. BIO* bio = NULL;
  48978. ASN1_UTCTIME* utc = NULL;
  48979. unsigned char buf[25];
  48980. const char* validDate = "190424111501Z"; /* UTC = YYMMDDHHMMSSZ */
  48981. const char* invalidDate = "190424111501X"; /* UTC = YYMMDDHHMMSSZ */
  48982. const char* genDate = "20190424111501Z"; /* GEN = YYYYMMDDHHMMSSZ */
  48983. /* Valid date */
  48984. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48985. ExpectNotNull(utc = (ASN1_UTCTIME*)XMALLOC(sizeof(ASN1_UTCTIME), NULL,
  48986. DYNAMIC_TYPE_ASN1));
  48987. if (utc != NULL) {
  48988. utc->type = ASN_UTC_TIME;
  48989. utc->length = ASN_UTC_TIME_SIZE;
  48990. XMEMCPY(utc->data, (byte*)validDate, ASN_UTC_TIME_SIZE);
  48991. }
  48992. ExpectIntEQ(ASN1_UTCTIME_print(NULL, NULL), 0);
  48993. ExpectIntEQ(ASN1_UTCTIME_print(bio, NULL), 0);
  48994. ExpectIntEQ(ASN1_UTCTIME_print(NULL, utc), 0);
  48995. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 1);
  48996. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  48997. ExpectIntEQ(XMEMCMP(buf, "Apr 24 11:15:01 2019 GMT", sizeof(buf)-1), 0);
  48998. XMEMSET(buf, 0, sizeof(buf));
  48999. BIO_free(bio);
  49000. bio = NULL;
  49001. /* Invalid format */
  49002. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49003. if (utc != NULL) {
  49004. utc->type = ASN_UTC_TIME;
  49005. utc->length = ASN_UTC_TIME_SIZE;
  49006. XMEMCPY(utc->data, (byte*)invalidDate, ASN_UTC_TIME_SIZE);
  49007. }
  49008. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49009. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  49010. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  49011. /* Invalid type */
  49012. if (utc != NULL) {
  49013. utc->type = ASN_GENERALIZED_TIME;
  49014. utc->length = ASN_GENERALIZED_TIME_SIZE;
  49015. XMEMCPY(utc->data, (byte*)genDate, ASN_GENERALIZED_TIME_SIZE);
  49016. }
  49017. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49018. XFREE(utc, NULL, DYNAMIC_TYPE_ASN1);
  49019. BIO_free(bio);
  49020. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49021. return EXPECT_RESULT();
  49022. }
  49023. static int test_wolfSSL_ASN1_TYPE(void)
  49024. {
  49025. EXPECT_DECLS;
  49026. #if defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD) || \
  49027. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  49028. WOLFSSL_ASN1_TYPE* t = NULL;
  49029. WOLFSSL_ASN1_OBJECT* obj = NULL;
  49030. #ifndef NO_ASN_TIME
  49031. WOLFSSL_ASN1_TIME* time = NULL;
  49032. #endif
  49033. WOLFSSL_ASN1_STRING* str = NULL;
  49034. unsigned char data[] = { 0x00 };
  49035. ASN1_TYPE_set(NULL, V_ASN1_NULL, NULL);
  49036. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49037. ASN1_TYPE_set(t, V_ASN1_EOC, NULL);
  49038. wolfSSL_ASN1_TYPE_free(t);
  49039. t = NULL;
  49040. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49041. ASN1_TYPE_set(t, V_ASN1_NULL, NULL);
  49042. ASN1_TYPE_set(t, V_ASN1_NULL, data);
  49043. wolfSSL_ASN1_TYPE_free(t);
  49044. t = NULL;
  49045. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49046. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49047. ASN1_TYPE_set(t, V_ASN1_OBJECT, obj);
  49048. wolfSSL_ASN1_TYPE_free(t);
  49049. t = NULL;
  49050. #ifndef NO_ASN_TIME
  49051. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49052. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49053. ASN1_TYPE_set(t, V_ASN1_UTCTIME, time);
  49054. wolfSSL_ASN1_TYPE_free(t);
  49055. t = NULL;
  49056. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49057. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49058. ASN1_TYPE_set(t, V_ASN1_GENERALIZEDTIME, time);
  49059. wolfSSL_ASN1_TYPE_free(t);
  49060. t = NULL;
  49061. #endif
  49062. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49063. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49064. ASN1_TYPE_set(t, V_ASN1_UTF8STRING, str);
  49065. wolfSSL_ASN1_TYPE_free(t);
  49066. t = NULL;
  49067. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49068. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49069. ASN1_TYPE_set(t, V_ASN1_PRINTABLESTRING, str);
  49070. wolfSSL_ASN1_TYPE_free(t);
  49071. t = NULL;
  49072. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49073. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49074. ASN1_TYPE_set(t, V_ASN1_T61STRING, str);
  49075. wolfSSL_ASN1_TYPE_free(t);
  49076. t = NULL;
  49077. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49078. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49079. ASN1_TYPE_set(t, V_ASN1_IA5STRING, str);
  49080. wolfSSL_ASN1_TYPE_free(t);
  49081. t = NULL;
  49082. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49083. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49084. ASN1_TYPE_set(t, V_ASN1_UNIVERSALSTRING, str);
  49085. wolfSSL_ASN1_TYPE_free(t);
  49086. t = NULL;
  49087. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49088. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49089. ASN1_TYPE_set(t, V_ASN1_SEQUENCE, str);
  49090. wolfSSL_ASN1_TYPE_free(t);
  49091. t = NULL;
  49092. #endif
  49093. return EXPECT_RESULT();
  49094. }
  49095. /* Testing code used in old dpp.c in hostap */
  49096. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49097. typedef struct {
  49098. /* AlgorithmIdentifier ecPublicKey with optional parameters present
  49099. * as an OID identifying the curve */
  49100. X509_ALGOR *alg;
  49101. /* Compressed format public key per ANSI X9.63 */
  49102. ASN1_BIT_STRING *pub_key;
  49103. } DPP_BOOTSTRAPPING_KEY;
  49104. ASN1_SEQUENCE(DPP_BOOTSTRAPPING_KEY) = {
  49105. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, alg, X509_ALGOR),
  49106. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, pub_key, ASN1_BIT_STRING)
  49107. } ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY)
  49108. IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY)
  49109. typedef struct {
  49110. int type;
  49111. union {
  49112. ASN1_BIT_STRING *str1;
  49113. ASN1_BIT_STRING *str2;
  49114. ASN1_BIT_STRING *str3;
  49115. } d;
  49116. } ASN1_CHOICE_TEST;
  49117. ASN1_CHOICE(ASN1_CHOICE_TEST) = {
  49118. ASN1_IMP(ASN1_CHOICE_TEST, d.str1, ASN1_BIT_STRING, 1),
  49119. ASN1_IMP(ASN1_CHOICE_TEST, d.str2, ASN1_BIT_STRING, 2),
  49120. ASN1_IMP(ASN1_CHOICE_TEST, d.str3, ASN1_BIT_STRING, 3)
  49121. } ASN1_CHOICE_END(ASN1_CHOICE_TEST)
  49122. IMPLEMENT_ASN1_FUNCTIONS(ASN1_CHOICE_TEST)
  49123. /* Test nested objects */
  49124. typedef struct {
  49125. DPP_BOOTSTRAPPING_KEY* key;
  49126. ASN1_INTEGER* asnNum;
  49127. ASN1_INTEGER* expNum;
  49128. STACK_OF(ASN1_GENERALSTRING) *strList;
  49129. ASN1_CHOICE_TEST* str;
  49130. } TEST_ASN1_NEST1;
  49131. ASN1_SEQUENCE(TEST_ASN1_NEST1) = {
  49132. ASN1_SIMPLE(TEST_ASN1_NEST1, key, DPP_BOOTSTRAPPING_KEY),
  49133. ASN1_SIMPLE(TEST_ASN1_NEST1, asnNum, ASN1_INTEGER),
  49134. ASN1_EXP(TEST_ASN1_NEST1, expNum, ASN1_INTEGER, 0),
  49135. ASN1_EXP_SEQUENCE_OF(TEST_ASN1_NEST1, strList, ASN1_GENERALSTRING, 1),
  49136. ASN1_SIMPLE(TEST_ASN1_NEST1, str, ASN1_CHOICE_TEST)
  49137. } ASN1_SEQUENCE_END(TEST_ASN1_NEST1)
  49138. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST1)
  49139. typedef struct {
  49140. ASN1_INTEGER* num;
  49141. DPP_BOOTSTRAPPING_KEY* key;
  49142. TEST_ASN1_NEST1* asn1_obj;
  49143. } TEST_ASN1_NEST2;
  49144. ASN1_SEQUENCE(TEST_ASN1_NEST2) = {
  49145. ASN1_SIMPLE(TEST_ASN1_NEST2, num, ASN1_INTEGER),
  49146. ASN1_SIMPLE(TEST_ASN1_NEST2, key, DPP_BOOTSTRAPPING_KEY),
  49147. ASN1_SIMPLE(TEST_ASN1_NEST2, asn1_obj, TEST_ASN1_NEST1)
  49148. } ASN1_SEQUENCE_END(TEST_ASN1_NEST2)
  49149. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST2)
  49150. /* End nested objects */
  49151. typedef struct {
  49152. ASN1_INTEGER *integer;
  49153. } TEST_ASN1;
  49154. ASN1_SEQUENCE(TEST_ASN1) = {
  49155. ASN1_SIMPLE(TEST_ASN1, integer, ASN1_INTEGER),
  49156. } ASN1_SEQUENCE_END(TEST_ASN1)
  49157. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1)
  49158. typedef STACK_OF(ASN1_INTEGER) TEST_ASN1_ITEM;
  49159. ASN1_ITEM_TEMPLATE(TEST_ASN1_ITEM) =
  49160. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, MemName, ASN1_INTEGER)
  49161. ASN1_ITEM_TEMPLATE_END(TEST_ASN1_ITEM)
  49162. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_ITEM)
  49163. #endif
  49164. static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
  49165. {
  49166. EXPECT_DECLS;
  49167. /* Testing code used in dpp.c in hostap */
  49168. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49169. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  49170. EC_KEY *eckey = NULL;
  49171. EVP_PKEY *key = NULL;
  49172. size_t len = 0;
  49173. unsigned char *der = NULL;
  49174. unsigned char *der2 = NULL;
  49175. const unsigned char *tmp = NULL;
  49176. DPP_BOOTSTRAPPING_KEY *bootstrap = NULL, *bootstrap2 = NULL;
  49177. const unsigned char *in = ecc_clikey_der_256;
  49178. WOLFSSL_ASN1_OBJECT* ec_obj = NULL;
  49179. WOLFSSL_ASN1_OBJECT* group_obj = NULL;
  49180. const EC_GROUP *group = NULL;
  49181. const EC_POINT *point = NULL;
  49182. int nid;
  49183. TEST_ASN1 *test_asn1 = NULL;
  49184. TEST_ASN1 *test_asn1_2 = NULL;
  49185. const unsigned char badObjDer[] = { 0x06, 0x00 };
  49186. const unsigned char goodObjDer[] = {
  49187. 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01
  49188. };
  49189. WOLFSSL_ASN1_ITEM emptyTemplate;
  49190. XMEMSET(&emptyTemplate, 0, sizeof(WOLFSSL_ASN1_ITEM));
  49191. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49192. der = NULL;
  49193. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(NULL, &der), -1);
  49194. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, NULL), -1);
  49195. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49196. ExpectNotNull(key = d2i_PrivateKey(EVP_PKEY_EC, NULL, &in,
  49197. (long)sizeof_ecc_clikey_der_256));
  49198. ExpectNotNull(eckey = EVP_PKEY_get1_EC_KEY(key));
  49199. ExpectNotNull(group = EC_KEY_get0_group(eckey));
  49200. ExpectNotNull(point = EC_KEY_get0_public_key(eckey));
  49201. nid = EC_GROUP_get_curve_name(group);
  49202. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49203. group_obj = OBJ_nid2obj(nid);
  49204. if ((ec_obj != NULL) && (group_obj != NULL)) {
  49205. ExpectIntEQ(X509_ALGOR_set0(bootstrap->alg, ec_obj, V_ASN1_OBJECT,
  49206. group_obj), 1);
  49207. if (EXPECT_SUCCESS()) {
  49208. ec_obj = NULL;
  49209. group_obj = NULL;
  49210. }
  49211. }
  49212. wolfSSL_ASN1_OBJECT_free(group_obj);
  49213. wolfSSL_ASN1_OBJECT_free(ec_obj);
  49214. ExpectIntEQ(EC_POINT_point2oct(group, point, 0, NULL, 0, NULL), 0);
  49215. #ifdef HAVE_COMP_KEY
  49216. ExpectIntGT((len = EC_POINT_point2oct(
  49217. group, point, POINT_CONVERSION_COMPRESSED,
  49218. NULL, 0, NULL)), 0);
  49219. #else
  49220. ExpectIntGT((len = EC_POINT_point2oct(
  49221. group, point, POINT_CONVERSION_UNCOMPRESSED,
  49222. NULL, 0, NULL)), 0);
  49223. #endif
  49224. ExpectNotNull(der = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1));
  49225. #ifdef HAVE_COMP_KEY
  49226. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49227. der, len-1, NULL), 0);
  49228. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49229. der, len, NULL), len);
  49230. #else
  49231. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49232. der, len-1, NULL), 0);
  49233. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49234. der, len, NULL), len);
  49235. #endif
  49236. if (EXPECT_SUCCESS()) {
  49237. bootstrap->pub_key->data = der;
  49238. bootstrap->pub_key->length = (int)len;
  49239. /* Not actually used */
  49240. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49241. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49242. }
  49243. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, NULL), 16+len);
  49244. der = NULL;
  49245. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16+len);
  49246. der2 = NULL;
  49247. #ifdef WOLFSSL_ASN_TEMPLATE
  49248. tmp = der;
  49249. ExpectNotNull(d2i_DPP_BOOTSTRAPPING_KEY(&bootstrap2, &tmp, 16+len));
  49250. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap2, &der2), 16+len);
  49251. ExpectBufEQ(der, der2, 49);
  49252. #endif
  49253. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49254. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49255. EVP_PKEY_free(key);
  49256. EC_KEY_free(eckey);
  49257. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49258. DPP_BOOTSTRAPPING_KEY_free(bootstrap2);
  49259. bootstrap = NULL;
  49260. DPP_BOOTSTRAPPING_KEY_free(NULL);
  49261. /* Create bootstrap key with bad OBJECT_ID DER data, parameter that is
  49262. * a NULL and an empty BIT_STRING. */
  49263. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49264. ExpectNotNull(bootstrap->alg->algorithm = wolfSSL_ASN1_OBJECT_new());
  49265. if (EXPECT_SUCCESS()) {
  49266. bootstrap->alg->algorithm->obj = badObjDer;
  49267. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(badObjDer);
  49268. }
  49269. ExpectNotNull(bootstrap->alg->parameter = wolfSSL_ASN1_TYPE_new());
  49270. if (EXPECT_SUCCESS()) {
  49271. bootstrap->alg->parameter->type = V_ASN1_NULL;
  49272. bootstrap->alg->parameter->value.ptr = NULL;
  49273. bootstrap->pub_key->data = NULL;
  49274. bootstrap->pub_key->length = 0;
  49275. /* Not actually used */
  49276. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49277. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49278. }
  49279. /* Encode with bad OBJECT_ID. */
  49280. der = NULL;
  49281. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49282. /* Fix OBJECT_ID and encode with empty BIT_STRING. */
  49283. if (EXPECT_SUCCESS()) {
  49284. bootstrap->alg->algorithm->obj = goodObjDer;
  49285. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(goodObjDer);
  49286. bootstrap->alg->algorithm->grp = 2;
  49287. }
  49288. der = NULL;
  49289. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16);
  49290. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, &emptyTemplate), -1);
  49291. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49292. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49293. /* Test integer */
  49294. ExpectNotNull(test_asn1 = TEST_ASN1_new());
  49295. der = NULL;
  49296. ExpectIntEQ(ASN1_INTEGER_set(test_asn1->integer, 100), 1);
  49297. ExpectIntEQ(i2d_TEST_ASN1(test_asn1, &der), 5);
  49298. tmp = der;
  49299. ExpectNotNull(d2i_TEST_ASN1(&test_asn1_2, &tmp, 5));
  49300. der2 = NULL;
  49301. ExpectIntEQ(i2d_TEST_ASN1(test_asn1_2, &der2), 5);
  49302. ExpectBufEQ(der, der2, 5);
  49303. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49304. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49305. TEST_ASN1_free(test_asn1);
  49306. TEST_ASN1_free(test_asn1_2);
  49307. /* Test integer cases. */
  49308. ExpectNull(wolfSSL_ASN1_item_new(NULL));
  49309. TEST_ASN1_free(NULL);
  49310. /* Test nested asn1 objects */
  49311. {
  49312. TEST_ASN1_NEST2 *nested_asn1 = NULL;
  49313. TEST_ASN1_NEST2 *nested_asn1_2 = NULL;
  49314. int i;
  49315. ExpectNotNull(nested_asn1 = TEST_ASN1_NEST2_new());
  49316. /* Populate nested_asn1 with some random data */
  49317. /* nested_asn1->num */
  49318. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->num, 30003), 1);
  49319. /* nested_asn1->key */
  49320. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49321. group_obj = OBJ_nid2obj(NID_secp256k1);
  49322. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->key->alg, ec_obj,
  49323. V_ASN1_OBJECT, group_obj), 1);
  49324. ec_obj = NULL;
  49325. group_obj = NULL;
  49326. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->key->pub_key, 50, 1),
  49327. 1);
  49328. /* nested_asn1->asn1_obj->key */
  49329. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49330. group_obj = OBJ_nid2obj(NID_secp256k1);
  49331. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->asn1_obj->key->alg, ec_obj,
  49332. V_ASN1_OBJECT, group_obj), 1);
  49333. ec_obj = NULL;
  49334. group_obj = NULL;
  49335. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->key->pub_key,
  49336. 500, 1), 1);
  49337. /* nested_asn1->asn1_obj->asnNum */
  49338. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->asnNum, 666666), 1);
  49339. /* nested_asn1->asn1_obj->expNum */
  49340. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->expNum, 22222), 1);
  49341. /* nested_asn1->asn1_obj->strList */
  49342. for (i = 10; i >= 0; i--) {
  49343. ASN1_GENERALSTRING* genStr;
  49344. char fmtStr[20];
  49345. ExpectIntGT(snprintf(fmtStr, sizeof(fmtStr), "Bonjour #%d", i), 0);
  49346. ExpectNotNull(genStr = ASN1_GENERALSTRING_new());
  49347. ExpectIntEQ(ASN1_GENERALSTRING_set(genStr, fmtStr, -1), 1);
  49348. ExpectIntGT(
  49349. sk_ASN1_GENERALSTRING_push(nested_asn1->asn1_obj->strList,
  49350. genStr), 0);
  49351. }
  49352. /* nested_asn1->asn1_obj->str */
  49353. ExpectNotNull(nested_asn1->asn1_obj->str->d.str2
  49354. = ASN1_BIT_STRING_new());
  49355. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->str->d.str2,
  49356. 150, 1), 1);
  49357. nested_asn1->asn1_obj->str->type = 2;
  49358. der = NULL;
  49359. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1, &der), 285);
  49360. #ifdef WOLFSSL_ASN_TEMPLATE
  49361. tmp = der;
  49362. ExpectNotNull(d2i_TEST_ASN1_NEST2(&nested_asn1_2, &tmp, 285));
  49363. der2 = NULL;
  49364. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1_2, &der2), 285);
  49365. ExpectBufEQ(der, der2, 285);
  49366. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49367. #endif
  49368. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49369. TEST_ASN1_NEST2_free(nested_asn1);
  49370. TEST_ASN1_NEST2_free(nested_asn1_2);
  49371. }
  49372. /* Test ASN1_ITEM_TEMPLATE */
  49373. {
  49374. TEST_ASN1_ITEM* asn1_item = NULL;
  49375. TEST_ASN1_ITEM* asn1_item2 = NULL;
  49376. int i;
  49377. ExpectNotNull(asn1_item = TEST_ASN1_ITEM_new());
  49378. for (i = 0; i < 11; i++) {
  49379. ASN1_INTEGER* asn1_num;
  49380. ExpectNotNull(asn1_num = ASN1_INTEGER_new());
  49381. ExpectIntEQ(ASN1_INTEGER_set(asn1_num, i), 1);
  49382. ExpectIntGT(wolfSSL_sk_insert(asn1_item, asn1_num, -1), 0);
  49383. }
  49384. der = NULL;
  49385. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item, &der), 35);
  49386. tmp = der;
  49387. ExpectNotNull(d2i_TEST_ASN1_ITEM(&asn1_item2, &tmp, 35));
  49388. der2 = NULL;
  49389. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item2, &der2), 35);
  49390. ExpectBufEQ(der, der2, 35);
  49391. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49392. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49393. TEST_ASN1_ITEM_free(asn1_item);
  49394. TEST_ASN1_ITEM_free(asn1_item2);
  49395. }
  49396. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  49397. #endif /* OPENSSL_ALL && HAVE_ECC && USE_CERT_BUFFERS_256 */
  49398. return EXPECT_RESULT();
  49399. }
  49400. static int test_wolfSSL_i2d_ASN1_TYPE(void)
  49401. {
  49402. EXPECT_DECLS;
  49403. #if defined(OPENSSL_EXTRA)
  49404. /* Taken from one of sssd's certs othernames */
  49405. unsigned char str_bin[] = {
  49406. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49407. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49408. };
  49409. ASN1_TYPE* asn1type = NULL;
  49410. unsigned char* der = NULL;
  49411. /* Create ASN1_TYPE manually as we don't have a d2i version yet */
  49412. {
  49413. ASN1_STRING* str = NULL;
  49414. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49415. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49416. ExpectNotNull(asn1type = ASN1_TYPE_new());
  49417. ASN1_TYPE_set(asn1type, V_ASN1_SEQUENCE, str);
  49418. }
  49419. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, NULL), sizeof(str_bin));
  49420. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, &der), sizeof(str_bin));
  49421. ExpectBufEQ(der, str_bin, sizeof(str_bin));
  49422. ASN1_TYPE_free(asn1type);
  49423. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49424. #endif
  49425. return EXPECT_RESULT();
  49426. }
  49427. static int test_wolfSSL_i2d_ASN1_SEQUENCE(void)
  49428. {
  49429. EXPECT_DECLS;
  49430. #if defined(OPENSSL_EXTRA)
  49431. /* Taken from one of sssd's certs othernames */
  49432. unsigned char str_bin[] = {
  49433. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49434. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49435. };
  49436. ASN1_STRING* str = NULL;
  49437. unsigned char* der = NULL;
  49438. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49439. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49440. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, NULL), sizeof(str_bin));
  49441. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, &der), sizeof(str_bin));
  49442. ASN1_STRING_free(str);
  49443. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49444. #endif
  49445. return EXPECT_RESULT();
  49446. }
  49447. static int test_ASN1_strings(void)
  49448. {
  49449. EXPECT_DECLS;
  49450. #if defined(OPENSSL_EXTRA)
  49451. char text[] = "\0\0test string";
  49452. unsigned char* der = NULL;
  49453. ASN1_STRING* str = NULL;
  49454. /* Set the length byte */
  49455. text[1] = XSTRLEN(text + 2);
  49456. /* GENERALSTRING */
  49457. {
  49458. const unsigned char* p = (const unsigned char*)text;
  49459. text[0] = ASN_GENERALSTRING;
  49460. ExpectNotNull(d2i_ASN1_GENERALSTRING(&str, &p, sizeof(text)));
  49461. ExpectIntEQ(i2d_ASN1_GENERALSTRING(str, &der), 13);
  49462. ASN1_STRING_free(str);
  49463. str = NULL;
  49464. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49465. der = NULL;
  49466. }
  49467. /* OCTET_STRING */
  49468. {
  49469. const unsigned char* p = (const unsigned char*)text;
  49470. text[0] = ASN_OCTET_STRING;
  49471. ExpectNotNull(d2i_ASN1_OCTET_STRING(&str, &p, sizeof(text)));
  49472. ExpectIntEQ(i2d_ASN1_OCTET_STRING(str, &der), 13);
  49473. ASN1_STRING_free(str);
  49474. str = NULL;
  49475. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49476. der = NULL;
  49477. }
  49478. /* UTF8STRING */
  49479. {
  49480. const unsigned char* p = (const unsigned char*)text;
  49481. text[0] = ASN_UTF8STRING;
  49482. ExpectNotNull(d2i_ASN1_UTF8STRING(&str, &p, sizeof(text)));
  49483. ExpectIntEQ(i2d_ASN1_UTF8STRING(str, &der), 13);
  49484. ASN1_STRING_free(str);
  49485. str = NULL;
  49486. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49487. der = NULL;
  49488. }
  49489. #endif
  49490. return EXPECT_RESULT();
  49491. }
  49492. static int test_wolfSSL_lhash(void)
  49493. {
  49494. EXPECT_DECLS;
  49495. #ifdef OPENSSL_ALL
  49496. const char testStr[] = "Like a true nature's child\n"
  49497. "We were born\n"
  49498. "Born to be wild";
  49499. #ifdef NO_SHA
  49500. ExpectIntEQ(lh_strhash(testStr), 0xf9dc8a43);
  49501. #else
  49502. ExpectIntEQ(lh_strhash(testStr), 0x5b7541dc);
  49503. #endif
  49504. #endif
  49505. return EXPECT_RESULT();
  49506. }
  49507. static int test_wolfSSL_X509_NAME(void)
  49508. {
  49509. EXPECT_DECLS;
  49510. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  49511. !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  49512. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN) && \
  49513. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT) || \
  49514. defined(OPENSSL_EXTRA))
  49515. X509* x509 = NULL;
  49516. const unsigned char* c = NULL;
  49517. unsigned char buf[4096];
  49518. int bytes = 0;
  49519. XFILE f = XBADFILE;
  49520. const X509_NAME* a = NULL;
  49521. const X509_NAME* b = NULL;
  49522. X509_NAME* d2i_name = NULL;
  49523. int sz = 0;
  49524. unsigned char* tmp = NULL;
  49525. char file[] = "./certs/ca-cert.der";
  49526. #ifndef OPENSSL_EXTRA_X509_SMALL
  49527. byte empty[] = { /* CN=empty emailAddress= */
  49528. 0x30, 0x21, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03,
  49529. 0x55, 0x04, 0x03, 0x0C, 0x05, 0x65, 0x6D, 0x70,
  49530. 0x74, 0x79, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x09,
  49531. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  49532. 0x01, 0x16, 0x00
  49533. };
  49534. #endif
  49535. #ifndef OPENSSL_EXTRA_X509_SMALL
  49536. /* test compile of deprecated function, returns 0 */
  49537. ExpectIntEQ(CRYPTO_thread_id(), 0);
  49538. #endif
  49539. ExpectNotNull(a = X509_NAME_new());
  49540. X509_NAME_free((X509_NAME*)a);
  49541. a = NULL;
  49542. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  49543. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  49544. if (f != XBADFILE)
  49545. XFCLOSE(f);
  49546. c = buf;
  49547. ExpectNotNull(x509 = wolfSSL_X509_d2i_ex(NULL, c, bytes, HEAP_HINT));
  49548. /* test cmp function */
  49549. ExpectNotNull(a = X509_get_issuer_name(x509));
  49550. ExpectNotNull(b = X509_get_subject_name(x509));
  49551. #ifndef OPENSSL_EXTRA_X509_SMALL
  49552. ExpectIntEQ(X509_NAME_cmp(a, b), 0); /* self signed should be 0 */
  49553. #endif
  49554. tmp = buf;
  49555. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)a, &tmp)), 0);
  49556. if (sz > 0 && tmp == buf) {
  49557. fprintf(stderr, "\nERROR - %s line %d failed with:", __FILE__,
  49558. __LINE__);
  49559. fprintf(stderr, " Expected pointer to be incremented\n");
  49560. abort();
  49561. }
  49562. #ifndef OPENSSL_EXTRA_X509_SMALL
  49563. tmp = buf;
  49564. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  49565. #endif
  49566. /* if output parameter is NULL, should still return required size. */
  49567. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, NULL)), 0);
  49568. /* retry but with the function creating a buffer */
  49569. tmp = NULL;
  49570. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  49571. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  49572. tmp = NULL;
  49573. #ifdef WOLFSSL_CERT_NAME_ALL
  49574. /* test for givenName and name */
  49575. {
  49576. WOLFSSL_X509_NAME_ENTRY* entry = NULL;
  49577. const byte gName[] = "test-given-name";
  49578. const byte name[] = "test-name";
  49579. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  49580. NID_givenName, ASN_UTF8STRING, gName, sizeof(gName)));
  49581. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  49582. 1);
  49583. wolfSSL_X509_NAME_ENTRY_free(entry);
  49584. entry = NULL;
  49585. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  49586. NID_name, ASN_UTF8STRING, name, sizeof(name)));
  49587. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  49588. 1);
  49589. wolfSSL_X509_NAME_ENTRY_free(entry);
  49590. tmp = NULL;
  49591. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  49592. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  49593. }
  49594. #endif
  49595. b = NULL;
  49596. ExpectNotNull(b = X509_NAME_dup((X509_NAME*)a));
  49597. #ifndef OPENSSL_EXTRA_X509_SMALL
  49598. ExpectIntEQ(X509_NAME_cmp(a, b), 0);
  49599. #endif
  49600. X509_NAME_free((X509_NAME*)b);
  49601. X509_NAME_free(d2i_name);
  49602. d2i_name = NULL;
  49603. X509_free(x509);
  49604. #ifndef OPENSSL_EXTRA_X509_SMALL
  49605. /* test with an empty domain component */
  49606. tmp = empty;
  49607. sz = sizeof(empty);
  49608. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  49609. ExpectIntEQ(X509_NAME_entry_count(d2i_name), 2);
  49610. /* size of empty emailAddress will be 0 */
  49611. tmp = buf;
  49612. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_emailAddress,
  49613. (char*)tmp, sizeof(buf)), 0);
  49614. /* should contain no organization name */
  49615. tmp = buf;
  49616. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_organizationName,
  49617. (char*)tmp, sizeof(buf)), -1);
  49618. X509_NAME_free(d2i_name);
  49619. #endif
  49620. #endif
  49621. return EXPECT_RESULT();
  49622. }
  49623. static int test_wolfSSL_X509_NAME_hash(void)
  49624. {
  49625. EXPECT_DECLS;
  49626. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  49627. !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_BIO)
  49628. BIO* bio = NULL;
  49629. X509* x509 = NULL;
  49630. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  49631. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  49632. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  49633. ExpectIntEQ(X509_NAME_hash(X509_get_subject_name(x509)), 0x137DC03F);
  49634. ExpectIntEQ(X509_NAME_hash(X509_get_issuer_name(x509)), 0xFDB2DA4);
  49635. X509_free(x509);
  49636. BIO_free(bio);
  49637. #endif
  49638. return EXPECT_RESULT();
  49639. }
  49640. static int test_wolfSSL_X509_NAME_print_ex(void)
  49641. {
  49642. EXPECT_DECLS;
  49643. #if (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  49644. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  49645. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  49646. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))) && \
  49647. !defined(NO_BIO) && !defined(NO_RSA)
  49648. int memSz = 0;
  49649. byte* mem = NULL;
  49650. BIO* bio = NULL;
  49651. BIO* membio = NULL;
  49652. X509* x509 = NULL;
  49653. X509_NAME* name = NULL;
  49654. const char* expNormal = "C=US, CN=wolfssl.com";
  49655. const char* expEqSpace = "C = US, CN = wolfssl.com";
  49656. const char* expReverse = "CN=wolfssl.com, C=US";
  49657. const char* expNotEscaped = "C= US,+\"\\ , CN=#wolfssl.com<>;";
  49658. const char* expNotEscapedRev = "CN=#wolfssl.com<>;, C= US,+\"\\ ";
  49659. const char* expRFC5523 =
  49660. "CN=\\#wolfssl.com\\<\\>\\;, C=\\ US\\,\\+\\\"\\\\\\ ";
  49661. /* Test with real cert (svrCertFile) first */
  49662. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  49663. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  49664. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  49665. ExpectNotNull(name = X509_get_subject_name(x509));
  49666. /* Test without flags */
  49667. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49668. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  49669. BIO_free(membio);
  49670. membio = NULL;
  49671. /* Test flag: XN_FLAG_RFC2253 */
  49672. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49673. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49674. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  49675. BIO_free(membio);
  49676. membio = NULL;
  49677. /* Test flag: XN_FLAG_RFC2253 | XN_FLAG_DN_REV */
  49678. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49679. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49680. XN_FLAG_RFC2253 | XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  49681. BIO_free(membio);
  49682. membio = NULL;
  49683. X509_free(x509);
  49684. BIO_free(bio);
  49685. name = NULL;
  49686. /* Test normal case without escaped characters */
  49687. {
  49688. /* Create name: "/C=US/CN=wolfssl.com" */
  49689. ExpectNotNull(name = X509_NAME_new());
  49690. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  49691. MBSTRING_UTF8, (byte*)"US", 2, -1, 0),
  49692. WOLFSSL_SUCCESS);
  49693. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  49694. MBSTRING_UTF8, (byte*)"wolfssl.com", 11, -1, 0),
  49695. WOLFSSL_SUCCESS);
  49696. /* Test without flags */
  49697. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49698. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  49699. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49700. ExpectIntEQ(memSz, XSTRLEN(expNormal));
  49701. ExpectIntEQ(XSTRNCMP((char*)mem, expNormal, XSTRLEN(expNormal)), 0);
  49702. BIO_free(membio);
  49703. membio = NULL;
  49704. /* Test with XN_FLAG_ONELINE which should enable XN_FLAG_SPC_EQ for
  49705. spaces aroun '=' */
  49706. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49707. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, XN_FLAG_ONELINE),
  49708. WOLFSSL_SUCCESS);
  49709. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49710. ExpectIntEQ(memSz, XSTRLEN(expEqSpace));
  49711. ExpectIntEQ(XSTRNCMP((char*)mem, expEqSpace, XSTRLEN(expEqSpace)), 0);
  49712. BIO_free(membio);
  49713. membio = NULL;
  49714. /* Test flags: XN_FLAG_RFC2253 - should be reversed */
  49715. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49716. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49717. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  49718. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49719. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  49720. BIO_free(membio);
  49721. membio = NULL;
  49722. /* Test flags: XN_FLAG_DN_REV - reversed */
  49723. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49724. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49725. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  49726. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49727. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  49728. ExpectIntEQ(XSTRNCMP((char*)mem, expReverse, XSTRLEN(expReverse)), 0);
  49729. BIO_free(membio);
  49730. membio = NULL;
  49731. X509_NAME_free(name);
  49732. name = NULL;
  49733. }
  49734. /* Test RFC2253 characters are escaped with backslashes */
  49735. {
  49736. ExpectNotNull(name = X509_NAME_new());
  49737. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  49738. /* space at beginning and end, and: ,+"\ */
  49739. MBSTRING_UTF8, (byte*)" US,+\"\\ ", 8, -1, 0),
  49740. WOLFSSL_SUCCESS);
  49741. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  49742. /* # at beginning, and: <>;*/
  49743. MBSTRING_UTF8, (byte*)"#wolfssl.com<>;", 15, -1, 0),
  49744. WOLFSSL_SUCCESS);
  49745. /* Test without flags */
  49746. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49747. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  49748. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49749. ExpectIntEQ(memSz, XSTRLEN(expNotEscaped));
  49750. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscaped,
  49751. XSTRLEN(expNotEscaped)), 0);
  49752. BIO_free(membio);
  49753. membio = NULL;
  49754. /* Test flags: XN_FLAG_RFC5523 - should be reversed and escaped */
  49755. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49756. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49757. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  49758. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49759. ExpectIntEQ(memSz, XSTRLEN(expRFC5523));
  49760. ExpectIntEQ(XSTRNCMP((char*)mem, expRFC5523, XSTRLEN(expRFC5523)), 0);
  49761. BIO_free(membio);
  49762. membio = NULL;
  49763. /* Test flags: XN_FLAG_DN_REV - reversed but not escaped */
  49764. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49765. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49766. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  49767. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49768. ExpectIntEQ(memSz, XSTRLEN(expNotEscapedRev));
  49769. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscapedRev,
  49770. XSTRLEN(expNotEscapedRev)), 0);
  49771. BIO_free(membio);
  49772. X509_NAME_free(name);
  49773. }
  49774. #endif
  49775. return EXPECT_RESULT();
  49776. }
  49777. #ifndef NO_BIO
  49778. static int test_wolfSSL_X509_INFO_multiple_info(void)
  49779. {
  49780. EXPECT_DECLS;
  49781. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  49782. STACK_OF(X509_INFO) *info_stack = NULL;
  49783. X509_INFO *info = NULL;
  49784. int len;
  49785. int i;
  49786. const char* files[] = {
  49787. cliCertFile,
  49788. cliKeyFile,
  49789. /* This needs to be the order as svrCertFile contains the
  49790. * intermediate cert as well. */
  49791. svrKeyFile,
  49792. svrCertFile,
  49793. NULL,
  49794. };
  49795. const char** curFile;
  49796. BIO *fileBIO = NULL;
  49797. BIO *concatBIO = NULL;
  49798. byte tmp[FOURK_BUF];
  49799. /* concatenate the cert and the key file to force PEM_X509_INFO_read_bio
  49800. * to group objects together. */
  49801. ExpectNotNull(concatBIO = BIO_new(BIO_s_mem()));
  49802. for (curFile = files; EXPECT_SUCCESS() && *curFile != NULL; curFile++) {
  49803. int fileLen = 0;
  49804. ExpectNotNull(fileBIO = BIO_new_file(*curFile, "rb"));
  49805. ExpectIntGT(fileLen = wolfSSL_BIO_get_len(fileBIO), 0);
  49806. if (EXPECT_SUCCESS()) {
  49807. while ((len = BIO_read(fileBIO, tmp, sizeof(tmp))) > 0) {
  49808. ExpectIntEQ(BIO_write(concatBIO, tmp, len), len);
  49809. fileLen -= len;
  49810. if (EXPECT_FAIL())
  49811. break;
  49812. }
  49813. /* Make sure we read the entire file */
  49814. ExpectIntEQ(fileLen, 0);
  49815. }
  49816. BIO_free(fileBIO);
  49817. fileBIO = NULL;
  49818. }
  49819. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(concatBIO, NULL, NULL,
  49820. NULL));
  49821. ExpectIntEQ(sk_X509_INFO_num(info_stack), 3);
  49822. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  49823. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  49824. ExpectNotNull(info->x509);
  49825. ExpectNull(info->crl);
  49826. if (i != 0) {
  49827. ExpectNotNull(info->x_pkey);
  49828. ExpectIntEQ(X509_check_private_key(info->x509,
  49829. info->x_pkey->dec_pkey), 1);
  49830. }
  49831. else {
  49832. ExpectNull(info->x_pkey);
  49833. }
  49834. }
  49835. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  49836. BIO_free(concatBIO);
  49837. #endif
  49838. return EXPECT_RESULT();
  49839. }
  49840. #endif
  49841. #ifndef NO_BIO
  49842. static int test_wolfSSL_X509_INFO(void)
  49843. {
  49844. EXPECT_DECLS;
  49845. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  49846. STACK_OF(X509_INFO) *info_stack = NULL;
  49847. X509_INFO *info = NULL;
  49848. BIO *cert = NULL;
  49849. int i;
  49850. /* PEM in hex format to avoid null terminator */
  49851. byte data[] = {
  49852. 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47,
  49853. 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x63, 0x2d, 0x2d, 0x2d, 0x2d,
  49854. 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44, 0x4d, 0x54, 0x42, 0x75, 0x51, 0x3d,
  49855. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x2d, 0x2d,
  49856. 0x2d, 0x2d, 0x2d
  49857. };
  49858. /* PEM in hex format to avoid null terminator */
  49859. byte data2[] = {
  49860. 0x41, 0x53, 0x4e, 0x31, 0x20, 0x4f, 0x49, 0x44, 0x3a, 0x20, 0x70, 0x72,
  49861. 0x69, 0x6d, 0x65, 0x32, 0x35, 0x36, 0x76, 0x31, 0x0a, 0x2d, 0x2d, 0x2d,
  49862. 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x45, 0x43, 0x20, 0x50,
  49863. 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2d, 0x2d, 0x2d,
  49864. 0x2d, 0x43, 0x65, 0x72, 0x74, 0x69, 0x2d, 0x0a, 0x42, 0x67, 0x67, 0x71,
  49865. 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x4d, 0x42, 0x42, 0x77, 0x3d, 0x3d,
  49866. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d
  49867. };
  49868. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  49869. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  49870. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  49871. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  49872. ExpectNotNull(info->x509);
  49873. ExpectNull(info->crl);
  49874. ExpectNull(info->x_pkey);
  49875. }
  49876. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  49877. info_stack = NULL;
  49878. BIO_free(cert);
  49879. cert = NULL;
  49880. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  49881. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  49882. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  49883. info_stack = NULL;
  49884. BIO_free(cert);
  49885. cert = NULL;
  49886. /* This case should fail due to invalid input. */
  49887. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  49888. ExpectIntEQ(BIO_write(cert, data, sizeof(data)), sizeof(data));
  49889. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  49890. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  49891. info_stack = NULL;
  49892. BIO_free(cert);
  49893. cert = NULL;
  49894. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  49895. ExpectIntEQ(BIO_write(cert, data2, sizeof(data2)), sizeof(data2));
  49896. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  49897. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  49898. BIO_free(cert);
  49899. #endif
  49900. return EXPECT_RESULT();
  49901. }
  49902. #endif
  49903. static int test_wolfSSL_X509_subject_name_hash(void)
  49904. {
  49905. EXPECT_DECLS;
  49906. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  49907. !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  49908. X509* x509 = NULL;
  49909. X509_NAME* subjectName = NULL;
  49910. unsigned long ret1 = 0;
  49911. unsigned long ret2 = 0;
  49912. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  49913. SSL_FILETYPE_PEM));
  49914. ExpectNotNull(subjectName = wolfSSL_X509_get_subject_name(x509));
  49915. /* These two
  49916. * - X509_subject_name_hash(x509)
  49917. * - X509_NAME_hash(X509_get_subject_name(x509))
  49918. * should give the same hash, if !defined(NO_SHA) is true. */
  49919. ret1 = X509_subject_name_hash(x509);
  49920. ExpectIntNE(ret1, 0);
  49921. #if !defined(NO_SHA)
  49922. ret2 = X509_NAME_hash(X509_get_subject_name(x509));
  49923. ExpectIntNE(ret2, 0);
  49924. ExpectIntEQ(ret1, ret2);
  49925. #else
  49926. (void) ret2;
  49927. #endif
  49928. X509_free(x509);
  49929. #endif
  49930. return EXPECT_RESULT();
  49931. }
  49932. static int test_wolfSSL_X509_issuer_name_hash(void)
  49933. {
  49934. EXPECT_DECLS;
  49935. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  49936. && !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  49937. X509* x509 = NULL;
  49938. X509_NAME* issuertName = NULL;
  49939. unsigned long ret1 = 0;
  49940. unsigned long ret2 = 0;
  49941. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  49942. SSL_FILETYPE_PEM));
  49943. ExpectNotNull(issuertName = wolfSSL_X509_get_issuer_name(x509));
  49944. /* These two
  49945. * - X509_issuer_name_hash(x509)
  49946. * - X509_NAME_hash(X509_get_issuer_name(x509))
  49947. * should give the same hash, if !defined(NO_SHA) is true. */
  49948. ret1 = X509_issuer_name_hash(x509);
  49949. ExpectIntNE(ret1, 0);
  49950. #if !defined(NO_SHA)
  49951. ret2 = X509_NAME_hash(X509_get_issuer_name(x509));
  49952. ExpectIntNE(ret2, 0);
  49953. ExpectIntEQ(ret1, ret2);
  49954. #else
  49955. (void) ret2;
  49956. #endif
  49957. X509_free(x509);
  49958. #endif
  49959. return EXPECT_RESULT();
  49960. }
  49961. static int test_wolfSSL_X509_check_host(void)
  49962. {
  49963. EXPECT_DECLS;
  49964. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  49965. && !defined(NO_SHA) && !defined(NO_RSA)
  49966. X509* x509 = NULL;
  49967. const char altName[] = "example.com";
  49968. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  49969. SSL_FILETYPE_PEM));
  49970. ExpectIntEQ(X509_check_host(x509, altName, XSTRLEN(altName), 0, NULL),
  49971. WOLFSSL_SUCCESS);
  49972. ExpectIntEQ(X509_check_host(x509, NULL, 0, 0, NULL),
  49973. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  49974. X509_free(x509);
  49975. ExpectIntEQ(X509_check_host(NULL, altName, XSTRLEN(altName), 0, NULL),
  49976. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  49977. #endif
  49978. return EXPECT_RESULT();
  49979. }
  49980. static int test_wolfSSL_X509_check_email(void)
  49981. {
  49982. EXPECT_DECLS;
  49983. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  49984. X509* x509 = NULL;
  49985. const char goodEmail[] = "info@wolfssl.com";
  49986. const char badEmail[] = "disinfo@wolfssl.com";
  49987. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  49988. SSL_FILETYPE_PEM));
  49989. /* Should fail on non-matching email address */
  49990. ExpectIntEQ(wolfSSL_X509_check_email(x509, badEmail, XSTRLEN(badEmail), 0),
  49991. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  49992. /* Should succeed on matching email address */
  49993. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, XSTRLEN(goodEmail), 0),
  49994. WOLFSSL_SUCCESS);
  49995. /* Should compute length internally when not provided */
  49996. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, 0, 0),
  49997. WOLFSSL_SUCCESS);
  49998. /* Should fail when email address is NULL */
  49999. ExpectIntEQ(wolfSSL_X509_check_email(x509, NULL, 0, 0),
  50000. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50001. X509_free(x509);
  50002. /* Should fail when x509 is NULL */
  50003. ExpectIntEQ(wolfSSL_X509_check_email(NULL, goodEmail, 0, 0),
  50004. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50005. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_GEN */
  50006. return EXPECT_RESULT();
  50007. }
  50008. static int test_wc_PemToDer(void)
  50009. {
  50010. EXPECT_DECLS;
  50011. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50012. int ret;
  50013. DerBuffer* pDer = NULL;
  50014. const char* ca_cert = "./certs/server-cert.pem";
  50015. byte* cert_buf = NULL;
  50016. size_t cert_sz = 0;
  50017. int eccKey = 0;
  50018. EncryptedInfo info;
  50019. XMEMSET(&info, 0, sizeof(info));
  50020. ExpectIntEQ(ret = load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50021. ExpectIntEQ(ret = wc_PemToDer(cert_buf, (long int)cert_sz, CERT_TYPE, &pDer, NULL,
  50022. &info, &eccKey), 0);
  50023. wc_FreeDer(&pDer);
  50024. pDer = NULL;
  50025. if (cert_buf != NULL) {
  50026. free(cert_buf);
  50027. cert_buf = NULL;
  50028. }
  50029. #ifdef HAVE_ECC
  50030. {
  50031. const char* ecc_private_key = "./certs/ecc-privOnlyKey.pem";
  50032. byte key_buf[256] = {0};
  50033. /* Test fail of loading a key with cert type */
  50034. ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0);
  50035. key_buf[0] = '\n';
  50036. ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz));
  50037. ExpectIntNE((ret = wc_PemToDer(key_buf, cert_sz + 1, CERT_TYPE,
  50038. &pDer, NULL, &info, &eccKey)), 0);
  50039. #ifdef OPENSSL_EXTRA
  50040. ExpectIntEQ((ret = wc_PemToDer(key_buf, cert_sz + 1, PRIVATEKEY_TYPE,
  50041. &pDer, NULL, &info, &eccKey)), 0);
  50042. #endif
  50043. wc_FreeDer(&pDer);
  50044. if (cert_buf != NULL)
  50045. free(cert_buf);
  50046. }
  50047. #endif
  50048. #endif
  50049. return EXPECT_RESULT();
  50050. }
  50051. static int test_wc_AllocDer(void)
  50052. {
  50053. EXPECT_DECLS;
  50054. #if !defined(NO_CERTS)
  50055. DerBuffer* pDer = NULL;
  50056. word32 testSize = 1024;
  50057. ExpectIntEQ(wc_AllocDer(NULL, testSize, CERT_TYPE, HEAP_HINT),
  50058. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50059. ExpectIntEQ(wc_AllocDer(&pDer, testSize, CERT_TYPE, HEAP_HINT), 0);
  50060. ExpectNotNull(pDer);
  50061. wc_FreeDer(&pDer);
  50062. #endif
  50063. return EXPECT_RESULT();
  50064. }
  50065. static int test_wc_CertPemToDer(void)
  50066. {
  50067. EXPECT_DECLS;
  50068. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50069. const char* ca_cert = "./certs/ca-cert.pem";
  50070. byte* cert_buf = NULL;
  50071. size_t cert_sz = 0;
  50072. size_t cert_dersz = 0;
  50073. byte* cert_der = NULL;
  50074. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50075. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50076. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50077. ExpectIntGE(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50078. (int)cert_dersz, CERT_TYPE), 0);
  50079. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, -1, CERT_TYPE),
  50080. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50081. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL, -1, CERT_TYPE),
  50082. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50083. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der, -1, CERT_TYPE),
  50084. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50085. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, (int)cert_dersz,
  50086. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50087. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der,
  50088. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50089. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL,
  50090. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50091. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der, -1,
  50092. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50093. if (cert_der != NULL)
  50094. free(cert_der);
  50095. if (cert_buf != NULL)
  50096. free(cert_buf);
  50097. #endif
  50098. return EXPECT_RESULT();
  50099. }
  50100. static int test_wc_KeyPemToDer(void)
  50101. {
  50102. EXPECT_DECLS;
  50103. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  50104. int ret = 0;
  50105. const byte cert_buf[] = \
  50106. "-----BEGIN PRIVATE KEY-----\n"
  50107. "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMG5KgWxP002pA\n"
  50108. "QJIdA4H5N0oM1Wf0LrHcos5RYUlrHDkC2b5p2BUpVRPmgDAFD2+8leim98x0BvcB\n"
  50109. "k48TNzrVynuwyVEY664+iQyzEBO5v27HPRydOddprbLCvRO036XINGIjauy1jHFi\n"
  50110. "HaDVx3bexSwgp9aefUGAszFXi4q1J4GacV7Cr2b/wBqUHqWv4ZXPu6R9/UYngTkD\n"
  50111. "UDJL5gLlLfcLzNyyodKPHPCIAKdWn6mSVdcHk8XVpK4y9lgz4E7YDWA6ohKZgWgG\n"
  50112. "2RDha8CMilFMDgYa0G0SiS9g3PQx0qh3AMXJJsKSVhScFCZufAE0kV6KvjP7jAqP\n"
  50113. "XBiSkRGPAgMBAAECggEAW7hmRyY2jRX2UMJThrM9VIs6fRLnYI0dQ0tsEJj536ay\n"
  50114. "nevQjArc05KWW0Yujg+WRDZPcry3RUqd9Djlmhp/F3Si6dpF1b+PMS3wJYVrf9Sd\n"
  50115. "SO5W7faArU4vnyBNe0HnY1Ta5xSVI65lg1RSIs88RTZwsooJwXYDGf0shq0/21CE\n"
  50116. "V8HOb27DDYNcEnm35lzaONjFnMqQQT2Vs9anRrPiSEXNleEvTgLVXZtGTyCGTz6v\n"
  50117. "x86Y8eSWL9YNHvPE1I+mDPuocfSR7eRNgRu7SK3mn94W5mqd7Ns072YKX/2XN1mO\n"
  50118. "66+ZFHO6v4dK1u7cSjuwrU1EhLHpUsgDz6Bna5InyQKBgQDv5l8RPy8UneKSADaf\n"
  50119. "M5L/5675I/5t4nqVjvbnQje00YveLTAEjlJBNR93Biln3sYgnvNamYDCxyEuUZ/I\n"
  50120. "S/vmBL9PoxfGZow4FcsIBOEbIn3E0SYJgCBNWthquUvGpKsYDnThJuhO+1cVmxAJ\n"
  50121. "BUOjLFnJYHM0a+Vmk9GexT2OBwKBgQDZzkUBOK7Im3eiYytFocUJyhqMH30d49X9\n"
  50122. "ujC7kGw4UWAqVe7YCSvlBa8nzWpRWK2kRpu3M0272RU0V4geyWqT+nr/SvRRPtNP\n"
  50123. "F5dY8l3yR7hjtSejqqjOfBcZT6ETJxI4tiG0+Nl5BlfM5M+0nxnkWpRcHuOR3j79\n"
  50124. "YUFERyN+OQKBgQCjlOKeUAc6d65W/+4/AFvsQ378Q57qLtSHxsR1TKHPmlNVXFqx\n"
  50125. "wJo1/JNIBduWCEHxXHF0BdfW+RGXE/FwEt/hKLuLAhrkHmjelX2sKieU6R/5ZOQa\n"
  50126. "9lMQbDHGFDOncAF6leD85hriQGBRSzrT69MDIOrYdfwYcroqCAGX0cb3YQKBgQC8\n"
  50127. "iIFQylj5SyHmjcMSNjKSA8CxFDzAV8yPIdE3Oo+CvGXqn5HsrRuy1hXE9VmXapR8\n"
  50128. "A6ackSszdHiXY0FvrNe1mfdH7wDHJwPQjdIzazCJHS3uGQxj7sDKY7226ie6pXJv\n"
  50129. "ZrCMr2/IBAaSVGm6ppHKCeIsT4ybYm7R85KEYLPHeQKBgBeJOMBinXQfWN/1jT9b\n"
  50130. "6Ywrutvp2zP8hVxQGSZJ0WG4iewZyFLsPUlbWRXOSYNPElHmdD0ZomdLVm+lSpAA\n"
  50131. "XSH5FJ/IFCwqq7Eft6Gf8NFRV+NjPMUny+PnjHe4oFP8YK/Ek22K3ttNG8Hw69Aw\n"
  50132. "AQue5o6oVfhgLiJzMdo/77gw\n"
  50133. "-----END PRIVATE KEY-----\n";
  50134. const int cert_sz = sizeof(cert_buf);
  50135. const char cert_pw[] = "password";
  50136. int cert_dersz = 0;
  50137. byte* cert_der = NULL;
  50138. /* Bad arg: Cert buffer is NULL */
  50139. ExpectIntEQ(wc_KeyPemToDer(NULL, cert_sz, cert_der, cert_dersz, ""),
  50140. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50141. /* Bad arg: Cert DER buffer non-NULL but size zero (or less) */
  50142. ExpectIntEQ(wc_KeyPemToDer(cert_buf, cert_sz, (byte*)&cert_der, 0, ""),
  50143. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50144. /* Test normal operation */
  50145. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50146. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50147. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50148. cert_pw), 0);
  50149. ExpectIntLE(ret, cert_sz);
  50150. if (cert_der != NULL) {
  50151. free(cert_der);
  50152. cert_der = NULL;
  50153. }
  50154. /* Test NULL for DER buffer to return needed DER buffer size */
  50155. ExpectIntGT(ret = wc_KeyPemToDer(cert_buf, cert_sz, NULL, 0, ""), 0);
  50156. ExpectIntLE(ret, cert_sz);
  50157. if (EXPECT_SUCCESS())
  50158. cert_dersz = ret;
  50159. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50160. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50161. cert_pw), 0);
  50162. ExpectIntLE(ret, cert_sz);
  50163. if (cert_der != NULL)
  50164. free(cert_der);
  50165. #endif
  50166. return EXPECT_RESULT();
  50167. }
  50168. static int test_wc_PubKeyPemToDer(void)
  50169. {
  50170. EXPECT_DECLS;
  50171. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && \
  50172. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50173. int ret = 0;
  50174. const char* key = "./certs/ecc-client-keyPub.pem";
  50175. byte* cert_buf = NULL;
  50176. size_t cert_sz = 0, cert_dersz = 0;
  50177. byte* cert_der = NULL;
  50178. ExpectIntEQ(wc_PubKeyPemToDer(cert_buf, (int)cert_sz,
  50179. cert_der, (int)cert_dersz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50180. ExpectIntEQ(load_file(key, &cert_buf, &cert_sz), 0);
  50181. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50182. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50183. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50184. (int)cert_dersz), 0);
  50185. if (cert_der != NULL) {
  50186. free(cert_der);
  50187. cert_der = NULL;
  50188. }
  50189. /* Test NULL for DER buffer to return needed DER buffer size */
  50190. ExpectIntGT(ret = wc_PubKeyPemToDer(cert_buf, (int)cert_sz, NULL, 0), 0);
  50191. ExpectIntLE(ret, cert_sz);
  50192. cert_dersz = (size_t)ret;
  50193. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50194. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50195. (int)cert_dersz), 0);
  50196. if (cert_der != NULL) {
  50197. free(cert_der);
  50198. }
  50199. if (cert_buf != NULL) {
  50200. free(cert_buf);
  50201. }
  50202. #endif
  50203. return EXPECT_RESULT();
  50204. }
  50205. static int test_wc_PemPubKeyToDer(void)
  50206. {
  50207. EXPECT_DECLS;
  50208. #if !defined(NO_FILESYSTEM) && \
  50209. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50210. const char* key = "./certs/ecc-client-keyPub.pem";
  50211. size_t cert_dersz = 1024;
  50212. byte* cert_der = NULL;
  50213. ExpectIntGE(wc_PemPubKeyToDer(NULL, cert_der, (int)cert_dersz),
  50214. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50215. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50216. ExpectIntGE(wc_PemPubKeyToDer(key, cert_der, (int)cert_dersz), 0);
  50217. if (cert_der != NULL) {
  50218. free(cert_der);
  50219. }
  50220. #endif
  50221. return EXPECT_RESULT();
  50222. }
  50223. static int test_wc_GetPubKeyDerFromCert(void)
  50224. {
  50225. EXPECT_DECLS;
  50226. #if !defined(NO_RSA) || defined(HAVE_ECC)
  50227. int ret;
  50228. word32 idx = 0;
  50229. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50230. word32 keyDerSz = (word32)sizeof(keyDer);
  50231. DecodedCert decoded;
  50232. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50233. byte certBuf[6000]; /* for PEM and CSR, client-cert.pem is 5-6kB */
  50234. word32 certBufSz = sizeof(certBuf);
  50235. #endif
  50236. #if ((!defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)) || \
  50237. defined(WOLFSSL_CERT_REQ)) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  50238. XFILE fp = XBADFILE;
  50239. #endif
  50240. #ifndef NO_RSA
  50241. RsaKey rsaKey;
  50242. #if defined(USE_CERT_BUFFERS_2048)
  50243. byte* rsaCertDer = (byte*)client_cert_der_2048;
  50244. word32 rsaCertDerSz = sizeof_client_cert_der_2048;
  50245. #elif defined(USE_CERT_BUFFERS_1024)
  50246. byte* rsaCertDer = (byte*)client_cert_der_1024;
  50247. word32 rsaCertDerSz = sizeof_client_cert_der_1024;
  50248. #else
  50249. unsigned char rsaCertDer[TWOK_BUF];
  50250. word32 rsaCertDerSz;
  50251. #endif
  50252. #endif
  50253. #ifdef HAVE_ECC
  50254. ecc_key eccKey;
  50255. #if defined(USE_CERT_BUFFERS_256)
  50256. byte* eccCert = (byte*)cliecc_cert_der_256;
  50257. word32 eccCertSz = sizeof_cliecc_cert_der_256;
  50258. #else
  50259. unsigned char eccCert[ONEK_BUF];
  50260. word32 eccCertSz;
  50261. XFILE fp2 = XBADFILE;
  50262. #endif
  50263. #endif
  50264. #ifndef NO_RSA
  50265. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  50266. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  50267. ExpectIntGT(rsaCertDerSz = (word32)XFREAD(rsaCertDer, 1, sizeof(rsaCertDer),
  50268. fp), 0);
  50269. if (fp != XBADFILE) {
  50270. XFCLOSE(fp);
  50271. fp = XBADFILE;
  50272. }
  50273. #endif
  50274. /* good test case - RSA DER cert */
  50275. wc_InitDecodedCert(&decoded, rsaCertDer, rsaCertDerSz, NULL);
  50276. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50277. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50278. ExpectIntGT(keyDerSz, 0);
  50279. /* sanity check, verify we can import DER public key */
  50280. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50281. ExpectIntEQ(ret, 0);
  50282. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50283. if (ret == 0) {
  50284. wc_FreeRsaKey(&rsaKey);
  50285. }
  50286. /* test LENGTH_ONLY_E case */
  50287. keyDerSz = 0;
  50288. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50289. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50290. ExpectIntGT(keyDerSz, 0);
  50291. /* bad args: DecodedCert NULL */
  50292. ExpectIntEQ(wc_GetPubKeyDerFromCert(NULL, keyDer, &keyDerSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50293. /* bad args: output key buff size */
  50294. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50295. /* bad args: zero size output key buffer */
  50296. keyDerSz = 0;
  50297. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50298. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50299. wc_FreeDecodedCert(&decoded);
  50300. /* Certificate Request Tests */
  50301. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50302. {
  50303. XMEMSET(certBuf, 0, sizeof(certBuf));
  50304. ExpectTrue((fp = XFOPEN("./certs/csr.signed.der", "rb")) != XBADFILE);
  50305. ExpectIntGT(certBufSz = (word32)XFREAD(certBuf, 1, certBufSz, fp), 0);
  50306. if (fp != XBADFILE) {
  50307. XFCLOSE(fp);
  50308. }
  50309. wc_InitDecodedCert(&decoded, certBuf, certBufSz, NULL);
  50310. ExpectIntEQ(wc_ParseCert(&decoded, CERTREQ_TYPE, VERIFY, NULL), 0);
  50311. /* good test case - RSA DER certificate request */
  50312. keyDerSz = sizeof(keyDer);
  50313. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50314. 0);
  50315. ExpectIntGT(keyDerSz, 0);
  50316. /* sanity check, verify we can import DER public key */
  50317. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50318. ExpectIntEQ(ret, 0);
  50319. idx = 0;
  50320. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50321. if (ret == 0) {
  50322. wc_FreeRsaKey(&rsaKey);
  50323. }
  50324. wc_FreeDecodedCert(&decoded);
  50325. }
  50326. #endif /* WOLFSSL_CERT_REQ */
  50327. #endif /* NO_RSA */
  50328. #ifdef HAVE_ECC
  50329. #ifndef USE_CERT_BUFFERS_256
  50330. ExpectTrue((fp2 = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  50331. XBADFILE);
  50332. ExpectIntGT(eccCertSz = (word32)XFREAD(eccCert, 1, ONEK_BUF, fp2), 0);
  50333. if (fp2 != XBADFILE) {
  50334. XFCLOSE(fp2);
  50335. }
  50336. #endif
  50337. wc_InitDecodedCert(&decoded, eccCert, eccCertSz, NULL);
  50338. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50339. /* good test case - ECC */
  50340. XMEMSET(keyDer, 0, sizeof(keyDer));
  50341. keyDerSz = sizeof(keyDer);
  50342. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50343. ExpectIntGT(keyDerSz, 0);
  50344. /* sanity check, verify we can import DER public key */
  50345. ret = wc_ecc_init(&eccKey);
  50346. ExpectIntEQ(ret, 0);
  50347. idx = 0; /* reset idx to 0, used above in RSA case */
  50348. ExpectIntEQ(wc_EccPublicKeyDecode(keyDer, &idx, &eccKey, keyDerSz), 0);
  50349. if (ret == 0) {
  50350. wc_ecc_free(&eccKey);
  50351. }
  50352. /* test LENGTH_ONLY_E case */
  50353. keyDerSz = 0;
  50354. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50355. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50356. ExpectIntGT(keyDerSz, 0);
  50357. wc_FreeDecodedCert(&decoded);
  50358. #endif
  50359. #endif /* !NO_RSA || HAVE_ECC */
  50360. return EXPECT_RESULT();
  50361. }
  50362. static int test_wc_CheckCertSigPubKey(void)
  50363. {
  50364. EXPECT_DECLS;
  50365. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50366. !defined(NO_RSA) && defined(WOLFSSL_PEM_TO_DER) && defined(HAVE_ECC)
  50367. int ret = 0;
  50368. const char* ca_cert = "./certs/ca-cert.pem";
  50369. byte* cert_buf = NULL;
  50370. size_t cert_sz = 0;
  50371. byte* cert_der = NULL;
  50372. word32 cert_dersz = 0;
  50373. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50374. word32 keyDerSz = (word32)sizeof(keyDer);
  50375. DecodedCert decoded;
  50376. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50377. cert_dersz = (word32)cert_sz; /* DER will be smaller than PEM */
  50378. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50379. ExpectIntGE(ret = wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50380. (int)cert_dersz, CERT_TYPE), 0);
  50381. wc_InitDecodedCert(&decoded, cert_der, cert_dersz, NULL);
  50382. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50383. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50384. ExpectIntGT(keyDerSz, 0);
  50385. /* Good test case. */
  50386. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50387. keyDerSz, RSAk), 0);
  50388. /* No certificate. */
  50389. ExpectIntEQ(wc_CheckCertSigPubKey(NULL, cert_dersz, NULL, keyDer, keyDerSz,
  50390. ECDSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50391. /* Bad cert size. */
  50392. ExpectIntNE(ret = wc_CheckCertSigPubKey(cert_der, 0, NULL, keyDer, keyDerSz,
  50393. RSAk), 0);
  50394. ExpectTrue(ret == WC_NO_ERR_TRACE(ASN_PARSE_E) || ret == WC_NO_ERR_TRACE(BUFFER_E));
  50395. /* No public key. */
  50396. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, NULL,
  50397. keyDerSz, RSAk), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  50398. /* Bad public key size. */
  50399. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer, 0,
  50400. RSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50401. /* Wrong aglo. */
  50402. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50403. keyDerSz, ECDSAk), WC_NO_ERR_TRACE(ASN_PARSE_E));
  50404. wc_FreeDecodedCert(&decoded);
  50405. if (cert_der != NULL)
  50406. free(cert_der);
  50407. if (cert_buf != NULL)
  50408. free(cert_buf);
  50409. #endif
  50410. return EXPECT_RESULT();
  50411. }
  50412. static int test_wolfSSL_certs(void)
  50413. {
  50414. EXPECT_DECLS;
  50415. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50416. !defined(NO_RSA)
  50417. X509* x509ext = NULL;
  50418. X509* x509 = NULL;
  50419. #ifdef OPENSSL_ALL
  50420. WOLFSSL_X509_EXTENSION* ext = NULL;
  50421. ASN1_OBJECT* obj = NULL;
  50422. #endif
  50423. WOLFSSL* ssl = NULL;
  50424. WOLFSSL_CTX* ctx = NULL;
  50425. STACK_OF(ASN1_OBJECT)* sk = NULL;
  50426. ASN1_STRING* asn1_str = NULL;
  50427. AUTHORITY_KEYID* akey = NULL;
  50428. BASIC_CONSTRAINTS* bc = NULL;
  50429. int crit = 0;
  50430. #ifndef NO_WOLFSSL_SERVER
  50431. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  50432. #else
  50433. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  50434. #endif
  50435. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  50436. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50437. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  50438. #if !defined(NO_CHECK_PRIVATE_KEY)
  50439. ExpectIntEQ(SSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50440. #endif
  50441. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50442. #if !defined(NO_CHECK_PRIVATE_KEY)
  50443. ExpectIntEQ(SSL_CTX_check_private_key(ctx), SSL_SUCCESS);
  50444. #endif
  50445. ExpectNotNull(ssl = SSL_new(ctx));
  50446. /* Invalid parameters. */
  50447. ExpectIntEQ(SSL_use_certificate_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  50448. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50449. ExpectIntEQ(SSL_use_certificate_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  50450. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50451. ExpectIntEQ(SSL_use_certificate_file(NULL, "./certs/server-cert.pem",
  50452. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50453. #if !defined(NO_CHECK_PRIVATE_KEY)
  50454. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50455. #endif
  50456. #ifdef HAVE_PK_CALLBACKS
  50457. ExpectIntEQ((int)SSL_set_tlsext_debug_arg(ssl, NULL), WOLFSSL_SUCCESS);
  50458. #endif /* HAVE_PK_CALLBACKS */
  50459. /* Invalid parameters. */
  50460. ExpectNotNull(x509 = wolfSSL_X509_new());
  50461. ExpectIntEQ(SSL_use_certificate(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50462. ExpectIntEQ(SSL_use_certificate(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50463. ExpectIntEQ(SSL_use_certificate(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50464. /* No data in certificate. */
  50465. ExpectIntEQ(SSL_use_certificate(ssl, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50466. wolfSSL_X509_free(x509);
  50467. x509 = NULL;
  50468. /* create and use x509 */
  50469. #ifdef OPENSSL_ALL
  50470. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50471. WOLFSSL_FILETYPE_PEM));
  50472. #endif
  50473. ExpectNotNull(x509ext = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  50474. WOLFSSL_FILETYPE_PEM));
  50475. ExpectIntEQ(SSL_use_certificate(ssl, x509ext), WOLFSSL_SUCCESS);
  50476. #if !defined(NO_CHECK_PRIVATE_KEY)
  50477. /* with loading in a new cert the check on private key should now fail */
  50478. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50479. #endif
  50480. #if defined(USE_CERT_BUFFERS_2048)
  50481. /* Invalid parameters. */
  50482. ExpectIntEQ(SSL_use_certificate_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50483. ExpectIntEQ(SSL_use_certificate_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50484. ExpectIntEQ(SSL_use_certificate_ASN1(NULL,
  50485. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50486. /* No data. */
  50487. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50488. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50489. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50490. (unsigned char*)server_cert_der_2048,
  50491. sizeof_server_cert_der_2048), WOLFSSL_SUCCESS);
  50492. #endif
  50493. #if !defined(NO_SHA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  50494. /************* Get Digest of Certificate ******************/
  50495. {
  50496. byte digest[64]; /* max digest size */
  50497. word32 digestSz;
  50498. XMEMSET(digest, 0, sizeof(digest));
  50499. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha1(), digest, &digestSz),
  50500. WOLFSSL_SUCCESS);
  50501. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha256(), digest, &digestSz),
  50502. WOLFSSL_SUCCESS);
  50503. ExpectIntEQ(X509_digest(NULL, wolfSSL_EVP_sha1(), digest, &digestSz),
  50504. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50505. }
  50506. #endif /* !NO_SHA && !NO_SHA256 && !NO_PWDBASED */
  50507. /* test and checkout X509 extensions */
  50508. ExpectNotNull(bc = (BASIC_CONSTRAINTS*)X509_get_ext_d2i(x509ext,
  50509. NID_basic_constraints, &crit, NULL));
  50510. ExpectIntEQ(crit, 0);
  50511. #ifdef OPENSSL_ALL
  50512. ExpectNotNull(ext = X509V3_EXT_i2d(NID_basic_constraints, crit, bc));
  50513. X509_EXTENSION_free(ext);
  50514. ext = NULL;
  50515. ExpectNotNull(ext = X509_EXTENSION_new());
  50516. X509_EXTENSION_set_critical(ext, 1);
  50517. ExpectNotNull(obj = OBJ_nid2obj(NID_basic_constraints));
  50518. ExpectIntEQ(X509_EXTENSION_set_object(ext, obj), SSL_SUCCESS);
  50519. ASN1_OBJECT_free(obj);
  50520. obj = NULL;
  50521. X509_EXTENSION_free(ext);
  50522. ext = NULL;
  50523. ExpectNotNull(ext = X509_EXTENSION_new());
  50524. X509_EXTENSION_set_critical(ext, 0);
  50525. ExpectIntEQ(X509_EXTENSION_set_data(ext, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50526. asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext, NID_key_usage, &crit,
  50527. NULL);
  50528. ExpectIntEQ(X509_EXTENSION_set_data(ext, asn1_str), SSL_SUCCESS);
  50529. ASN1_STRING_free(asn1_str); /* X509_EXTENSION_set_data has made a copy
  50530. * and X509_get_ext_d2i has created new */
  50531. asn1_str = NULL;
  50532. X509_EXTENSION_free(ext);
  50533. ext = NULL;
  50534. #endif
  50535. BASIC_CONSTRAINTS_free(bc);
  50536. bc = NULL;
  50537. ExpectNotNull(asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext,
  50538. NID_key_usage, &crit, NULL));
  50539. ExpectIntEQ(crit, 1);
  50540. ExpectIntEQ(asn1_str->type, NID_key_usage);
  50541. #ifdef OPENSSL_ALL
  50542. ExpectNotNull(ext = X509V3_EXT_i2d(NID_key_usage, crit, asn1_str));
  50543. X509_EXTENSION_free(ext);
  50544. ext = NULL;
  50545. #endif
  50546. ASN1_STRING_free(asn1_str);
  50547. asn1_str = NULL;
  50548. #ifdef OPENSSL_ALL
  50549. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  50550. NID_ext_key_usage, &crit, NULL));
  50551. ExpectNotNull(ext = X509V3_EXT_i2d(NID_ext_key_usage, crit, sk));
  50552. X509_EXTENSION_free(ext);
  50553. ext = NULL;
  50554. EXTENDED_KEY_USAGE_free(sk);
  50555. sk = NULL;
  50556. #else
  50557. sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, NID_ext_key_usage,
  50558. &crit, NULL);
  50559. ExpectNull(sk);
  50560. #endif
  50561. ExpectNotNull(akey = (AUTHORITY_KEYID*)X509_get_ext_d2i(x509ext,
  50562. NID_authority_key_identifier, &crit, NULL));
  50563. #ifdef OPENSSL_ALL
  50564. ExpectNotNull(ext = X509V3_EXT_i2d(NID_authority_key_identifier, crit,
  50565. akey));
  50566. X509_EXTENSION_free(ext);
  50567. ext = NULL;
  50568. #endif
  50569. wolfSSL_AUTHORITY_KEYID_free(akey);
  50570. akey = NULL;
  50571. /* NID not yet supported */
  50572. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50573. NID_private_key_usage_period, &crit, NULL));
  50574. ExpectIntEQ(crit, -1);
  50575. sk_ASN1_OBJECT_free(sk);
  50576. sk = NULL;
  50577. ExpectNotNull(sk = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(x509ext,
  50578. NID_subject_alt_name, &crit, NULL));
  50579. {
  50580. int i;
  50581. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  50582. GENERAL_NAME* gen = sk_GENERAL_NAME_value(sk, i);
  50583. ExpectIntEQ(gen->type, GEN_DNS);
  50584. ExpectIntEQ(gen->d.dNSName->type, V_ASN1_IA5STRING);
  50585. }
  50586. }
  50587. sk_GENERAL_NAME_free(sk);
  50588. sk = NULL;
  50589. /* NID not yet supported */
  50590. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50591. NID_issuer_alt_name, &crit, NULL));
  50592. ExpectIntEQ(crit, -1);
  50593. sk_ASN1_OBJECT_free(sk);
  50594. sk = NULL;
  50595. /* NID not yet supported */
  50596. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50597. NID_info_access, &crit, NULL));
  50598. sk_ASN1_OBJECT_free(sk);
  50599. sk = NULL;
  50600. /* NID not yet supported */
  50601. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50602. NID_sinfo_access, &crit, NULL));
  50603. ExpectIntEQ(crit, -1);
  50604. sk_ASN1_OBJECT_free(sk);
  50605. sk = NULL;
  50606. /* NID not yet supported */
  50607. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50608. NID_name_constraints, &crit, NULL));
  50609. ExpectIntEQ(crit, -1);
  50610. sk_ASN1_OBJECT_free(sk);
  50611. sk = NULL;
  50612. /* no cert policy set */
  50613. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50614. NID_certificate_policies, &crit, NULL));
  50615. sk_ASN1_OBJECT_free(sk);
  50616. sk = NULL;
  50617. /* NID not yet supported */
  50618. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50619. NID_policy_mappings, &crit, NULL));
  50620. ExpectIntEQ(crit, -1);
  50621. sk_ASN1_OBJECT_free(sk);
  50622. sk = NULL;
  50623. /* NID not yet supported */
  50624. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50625. NID_policy_constraints, &crit, NULL));
  50626. ExpectIntEQ(crit, -1);
  50627. sk_ASN1_OBJECT_free(sk);
  50628. sk = NULL;
  50629. /* NID not yet supported */
  50630. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50631. NID_inhibit_any_policy, &crit, NULL));
  50632. ExpectIntEQ(crit, -1);
  50633. sk_ASN1_OBJECT_free(sk);
  50634. sk = NULL;
  50635. /* NID not yet supported */
  50636. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50637. NID_tlsfeature, &crit, NULL));
  50638. ExpectIntEQ(crit, -1);
  50639. sk_ASN1_OBJECT_free(sk);
  50640. sk = NULL;
  50641. /* test invalid cases */
  50642. crit = 0;
  50643. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, -1, &crit,
  50644. NULL));
  50645. ExpectIntEQ(crit, -1);
  50646. /* NULL passed for criticality. */
  50647. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(NULL,
  50648. NID_tlsfeature, NULL, NULL));
  50649. ExpectIntEQ(SSL_get_hit(ssl), 0);
  50650. #ifdef OPENSSL_ALL
  50651. X509_free(x509);
  50652. #endif
  50653. X509_free(x509ext);
  50654. SSL_free(ssl);
  50655. SSL_CTX_free(ctx);
  50656. #endif /* OPENSSL_EXTRA && !NO_CERTS */
  50657. return EXPECT_RESULT();
  50658. }
  50659. static int test_wolfSSL_X509_check_private_key(void)
  50660. {
  50661. EXPECT_DECLS;
  50662. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  50663. defined(USE_CERT_BUFFERS_2048) && !defined(NO_CHECK_PRIVATE_KEY)
  50664. X509* x509 = NULL;
  50665. EVP_PKEY* pkey = NULL;
  50666. const byte* key;
  50667. /* Check with correct key */
  50668. ExpectNotNull((x509 = X509_load_certificate_file(cliCertFile,
  50669. SSL_FILETYPE_PEM)));
  50670. key = client_key_der_2048;
  50671. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  50672. (long)sizeof_client_key_der_2048));
  50673. ExpectIntEQ(X509_check_private_key(x509, pkey), 1);
  50674. EVP_PKEY_free(pkey);
  50675. pkey = NULL;
  50676. /* Check with wrong key */
  50677. key = server_key_der_2048;
  50678. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  50679. (long)sizeof_server_key_der_2048));
  50680. ExpectIntEQ(X509_check_private_key(x509, pkey), 0);
  50681. /* test for incorrect parameter */
  50682. ExpectIntEQ(X509_check_private_key(NULL, pkey), 0);
  50683. ExpectIntEQ(X509_check_private_key(x509, NULL), 0);
  50684. ExpectIntEQ(X509_check_private_key(NULL, NULL), 0);
  50685. EVP_PKEY_free(pkey);
  50686. X509_free(x509);
  50687. #endif
  50688. return EXPECT_RESULT();
  50689. }
  50690. static int test_wolfSSL_private_keys(void)
  50691. {
  50692. EXPECT_DECLS;
  50693. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  50694. !defined(NO_FILESYSTEM)
  50695. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  50696. WOLFSSL* ssl = NULL;
  50697. WOLFSSL_CTX* ctx = NULL;
  50698. EVP_PKEY* pkey = NULL;
  50699. OpenSSL_add_all_digests();
  50700. OpenSSL_add_all_algorithms();
  50701. #ifndef NO_RSA
  50702. #ifndef NO_WOLFSSL_SERVER
  50703. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  50704. #else
  50705. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  50706. #endif
  50707. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  50708. WOLFSSL_FILETYPE_PEM));
  50709. /* Have to load a cert before you can check the private key against that
  50710. * certificates public key! */
  50711. #if !defined(NO_CHECK_PRIVATE_KEY)
  50712. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50713. #endif
  50714. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  50715. WOLFSSL_FILETYPE_PEM));
  50716. #if !defined(NO_CHECK_PRIVATE_KEY)
  50717. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  50718. #endif
  50719. ExpectNotNull(ssl = SSL_new(ctx));
  50720. #if !defined(NO_CHECK_PRIVATE_KEY)
  50721. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50722. #endif
  50723. /* Invalid parameters. */
  50724. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  50725. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50726. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, svrKeyFile, WOLFSSL_FILETYPE_PEM),
  50727. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50728. ExpectIntEQ(SSL_use_PrivateKey_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  50729. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50730. #ifdef USE_CERT_BUFFERS_2048
  50731. {
  50732. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  50733. unsigned char buf[FOURK_BUF];
  50734. word32 bufSz;
  50735. /* Invalid parameters. */
  50736. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50737. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50738. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL,
  50739. (unsigned char*)client_key_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50740. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50741. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50742. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key, 0),
  50743. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50744. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50745. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50746. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key,
  50747. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50748. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl,
  50749. (unsigned char*)client_key_der_2048,
  50750. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  50751. #if !defined(NO_CHECK_PRIVATE_KEY)
  50752. /* Should mismatch now that a different private key loaded */
  50753. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50754. #endif
  50755. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl,
  50756. (unsigned char*)server_key,
  50757. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  50758. #if !defined(NO_CHECK_PRIVATE_KEY)
  50759. /* After loading back in DER format of original key, should match */
  50760. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50761. #endif
  50762. /* test loading private key to the WOLFSSL_CTX */
  50763. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  50764. (unsigned char*)client_key_der_2048,
  50765. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  50766. #if !defined(NO_CHECK_PRIVATE_KEY)
  50767. /* Should mismatch now that a different private key loaded */
  50768. ExpectIntNE(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  50769. #endif
  50770. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  50771. (unsigned char*)server_key,
  50772. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  50773. #if !defined(NO_CHECK_PRIVATE_KEY)
  50774. /* After loading back in DER format of original key, should match */
  50775. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  50776. #endif
  50777. /* Invalid parameters. */
  50778. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  50779. ExpectIntEQ(SSL_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50780. ExpectIntEQ(SSL_use_PrivateKey(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50781. ExpectIntEQ(SSL_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50782. /* pkey is empty - no key data to use. */
  50783. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WC_NO_ERR_TRACE(ASN_PARSE_E));
  50784. wolfSSL_EVP_PKEY_free(pkey);
  50785. pkey = NULL;
  50786. /* set PKEY and test again */
  50787. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  50788. &server_key, (long)sizeof_server_key_der_2048));
  50789. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  50790. /* reuse PKEY structure and test
  50791. * this should be checked with a memory management sanity checker */
  50792. ExpectFalse(server_key == (const unsigned char*)server_key_der_2048);
  50793. server_key = (const unsigned char*)server_key_der_2048;
  50794. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  50795. &server_key, (long)sizeof_server_key_der_2048));
  50796. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  50797. /* check striping PKCS8 header with wolfSSL_d2i_PrivateKey */
  50798. bufSz = FOURK_BUF;
  50799. ExpectIntGT((bufSz = (word32)wc_CreatePKCS8Key(buf, &bufSz,
  50800. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  50801. RSAk, NULL, 0)), 0);
  50802. server_key = (const unsigned char*)buf;
  50803. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  50804. (long)bufSz));
  50805. }
  50806. #endif
  50807. EVP_PKEY_free(pkey);
  50808. pkey = NULL;
  50809. SSL_free(ssl); /* frees x509 also since loaded into ssl */
  50810. ssl = NULL;
  50811. SSL_CTX_free(ctx);
  50812. ctx = NULL;
  50813. #endif /* end of RSA private key match tests */
  50814. #ifdef HAVE_ECC
  50815. #ifndef NO_WOLFSSL_SERVER
  50816. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  50817. #else
  50818. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  50819. #endif
  50820. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  50821. WOLFSSL_FILETYPE_PEM));
  50822. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  50823. WOLFSSL_FILETYPE_PEM));
  50824. ExpectNotNull(ssl = SSL_new(ctx));
  50825. #if !defined(NO_CHECK_PRIVATE_KEY)
  50826. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50827. #endif
  50828. SSL_free(ssl);
  50829. ssl = NULL;
  50830. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEccKeyFile,
  50831. WOLFSSL_FILETYPE_PEM));
  50832. ExpectNotNull(ssl = SSL_new(ctx));
  50833. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  50834. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50835. #endif
  50836. SSL_free(ssl);
  50837. ssl = NULL;
  50838. SSL_CTX_free(ctx);
  50839. ctx = NULL;
  50840. #endif /* end of ECC private key match tests */
  50841. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  50842. #ifndef NO_WOLFSSL_SERVER
  50843. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  50844. #else
  50845. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  50846. #endif
  50847. ExpectTrue(SSL_CTX_use_certificate_file(ctx, edCertFile,
  50848. WOLFSSL_FILETYPE_PEM));
  50849. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  50850. WOLFSSL_FILETYPE_PEM));
  50851. ExpectNotNull(ssl = SSL_new(ctx));
  50852. #if !defined(NO_CHECK_PRIVATE_KEY)
  50853. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50854. #endif
  50855. SSL_free(ssl);
  50856. ssl = NULL;
  50857. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEdKeyFile,
  50858. WOLFSSL_FILETYPE_PEM));
  50859. ExpectNotNull(ssl = SSL_new(ctx));
  50860. #if !defined(NO_CHECK_PRIVATE_KEY)
  50861. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50862. #endif
  50863. SSL_free(ssl);
  50864. ssl = NULL;
  50865. SSL_CTX_free(ctx);
  50866. ctx = NULL;
  50867. #endif /* end of Ed25519 private key match tests */
  50868. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  50869. #ifndef NO_WOLFSSL_SERVER
  50870. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  50871. #else
  50872. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  50873. #endif
  50874. ExpectTrue(SSL_CTX_use_certificate_file(ctx, ed448CertFile,
  50875. WOLFSSL_FILETYPE_PEM));
  50876. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  50877. WOLFSSL_FILETYPE_PEM));
  50878. ExpectNotNull(ssl = SSL_new(ctx));
  50879. #if !defined(NO_CHECK_PRIVATE_KEY)
  50880. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50881. #endif
  50882. SSL_free(ssl);
  50883. ssl = NULL;
  50884. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEd448KeyFile,
  50885. WOLFSSL_FILETYPE_PEM));
  50886. ExpectNotNull(ssl = SSL_new(ctx));
  50887. #if !defined(NO_CHECK_PRIVATE_KEY)
  50888. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50889. #endif
  50890. SSL_free(ssl);
  50891. ssl = NULL;
  50892. SSL_CTX_free(ctx);
  50893. ctx = NULL;
  50894. #endif /* end of Ed448 private key match tests */
  50895. EVP_cleanup();
  50896. /* test existence of no-op macros in wolfssl/openssl/ssl.h */
  50897. CONF_modules_free();
  50898. ENGINE_cleanup();
  50899. CONF_modules_unload();
  50900. (void)ssl;
  50901. (void)ctx;
  50902. (void)pkey;
  50903. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  50904. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  50905. return EXPECT_RESULT();
  50906. }
  50907. static int test_wolfSSL_PEM_def_callback(void)
  50908. {
  50909. EXPECT_DECLS;
  50910. #ifdef OPENSSL_EXTRA
  50911. char buf[10];
  50912. const char* defpwd = "DEF PWD";
  50913. int defpwdLen = (int)XSTRLEN(defpwd);
  50914. int smallLen = 1;
  50915. /* Bad parameters. */
  50916. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, NULL), 0);
  50917. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, (void*)defpwd),
  50918. 0);
  50919. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, NULL), 0);
  50920. XMEMSET(buf, 0, sizeof(buf));
  50921. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, (void*)defpwd),
  50922. defpwdLen);
  50923. ExpectIntEQ(XMEMCMP(buf, defpwd, defpwdLen), 0);
  50924. ExpectIntEQ(buf[defpwdLen], 0);
  50925. /* Size of buffer is smaller than default password. */
  50926. XMEMSET(buf, 0, sizeof(buf));
  50927. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, smallLen, 0, (void*)defpwd),
  50928. smallLen);
  50929. ExpectIntEQ(XMEMCMP(buf, defpwd, smallLen), 0);
  50930. ExpectIntEQ(buf[smallLen], 0);
  50931. #endif /* OPENSSL_EXTRA */
  50932. return EXPECT_RESULT();
  50933. }
  50934. static int test_wolfSSL_PEM_read_PrivateKey(void)
  50935. {
  50936. EXPECT_DECLS;
  50937. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || \
  50938. !defined(NO_DSA) || defined(HAVE_ECC) || !defined(NO_DH))
  50939. XFILE file = XBADFILE;
  50940. #if !defined(NO_RSA)
  50941. const char* fname_rsa = "./certs/server-key.pem";
  50942. RSA* rsa = NULL;
  50943. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  50944. unsigned char* sig = NULL;
  50945. size_t sigLen = 0;
  50946. const unsigned char tbs[] = {0, 1, 2, 3, 4, 5, 6, 7};
  50947. size_t tbsLen = sizeof(tbs);
  50948. #endif
  50949. #if !defined(NO_DSA)
  50950. const char* fname_dsa = "./certs/dsa2048.pem";
  50951. #endif
  50952. #if defined(HAVE_ECC)
  50953. const char* fname_ec = "./certs/ecc-key.pem";
  50954. #endif
  50955. #if !defined(NO_DH)
  50956. const char* fname_dh = "./certs/dh-priv-2048.pem";
  50957. #endif
  50958. EVP_PKEY* pkey = NULL;
  50959. /* Check error case. */
  50960. ExpectNull(pkey = PEM_read_PrivateKey(NULL, NULL, NULL, NULL));
  50961. /* not a PEM key. */
  50962. ExpectTrue((file = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  50963. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  50964. if (file != XBADFILE)
  50965. XFCLOSE(file);
  50966. file = XBADFILE;
  50967. #ifndef NO_RSA
  50968. /* Read in an RSA key. */
  50969. ExpectTrue((file = XFOPEN(fname_rsa, "rb")) != XBADFILE);
  50970. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  50971. if (file != XBADFILE)
  50972. XFCLOSE(file);
  50973. file = XBADFILE;
  50974. /* Make sure the key is usable by signing some data with it. */
  50975. ExpectNotNull(rsa = EVP_PKEY_get0_RSA(pkey));
  50976. ExpectIntGT((sigLen = RSA_size(rsa)), 0);
  50977. ExpectNotNull(sig = (unsigned char*)XMALLOC(sigLen, HEAP_HINT,
  50978. DYNAMIC_TYPE_TMP_BUFFER));
  50979. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  50980. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  50981. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &sigLen, tbs, tbsLen),
  50982. WOLFSSL_SUCCESS);
  50983. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50984. EVP_PKEY_CTX_free(ctx);
  50985. EVP_PKEY_free(pkey);
  50986. pkey = NULL;
  50987. #endif
  50988. #ifndef NO_DSA
  50989. /* Read in a DSA key. */
  50990. ExpectTrue((file = XFOPEN(fname_dsa, "rb")) != XBADFILE);
  50991. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  50992. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  50993. EVP_PKEY_free(pkey);
  50994. pkey = NULL;
  50995. #else
  50996. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  50997. #endif
  50998. if (file != XBADFILE)
  50999. XFCLOSE(file);
  51000. file = XBADFILE;
  51001. #endif
  51002. #ifdef HAVE_ECC
  51003. /* Read in an EC key. */
  51004. ExpectTrue((file = XFOPEN(fname_ec, "rb")) != XBADFILE);
  51005. ExpectNotNull(pkey = EVP_PKEY_new());
  51006. ExpectPtrEq(PEM_read_PrivateKey(file, &pkey, NULL, NULL), pkey);
  51007. if (file != XBADFILE)
  51008. XFCLOSE(file);
  51009. file = XBADFILE;
  51010. EVP_PKEY_free(pkey);
  51011. pkey = NULL;
  51012. #endif
  51013. #ifndef NO_DH
  51014. /* Read in a DH key. */
  51015. ExpectTrue((file = XFOPEN(fname_dh, "rb")) != XBADFILE);
  51016. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51017. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51018. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51019. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51020. EVP_PKEY_free(pkey);
  51021. pkey = NULL;
  51022. #else
  51023. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51024. #endif
  51025. if (file != XBADFILE)
  51026. XFCLOSE(file);
  51027. file = XBADFILE;
  51028. #endif
  51029. #endif
  51030. return EXPECT_RESULT();
  51031. }
  51032. static int test_wolfSSL_PEM_read_PUBKEY(void)
  51033. {
  51034. EXPECT_DECLS;
  51035. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) \
  51036. && !defined(NO_FILESYSTEM)
  51037. XFILE file = XBADFILE;
  51038. const char* fname = "./certs/client-keyPub.pem";
  51039. EVP_PKEY* pkey = NULL;
  51040. /* Check error case. */
  51041. ExpectNull(pkey = PEM_read_PUBKEY(NULL, NULL, NULL, NULL));
  51042. /* Read in an RSA key. */
  51043. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51044. ExpectNotNull(pkey = PEM_read_PUBKEY(file, NULL, NULL, NULL));
  51045. EVP_PKEY_free(pkey);
  51046. pkey = NULL;
  51047. if (file != XBADFILE)
  51048. XFCLOSE(file);
  51049. file = XBADFILE;
  51050. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51051. ExpectNotNull(pkey = EVP_PKEY_new());
  51052. ExpectPtrEq(PEM_read_PUBKEY(file, &pkey, NULL, NULL), pkey);
  51053. EVP_PKEY_free(pkey);
  51054. if (file != XBADFILE)
  51055. XFCLOSE(file);
  51056. #endif
  51057. return EXPECT_RESULT();
  51058. }
  51059. /* test loading RSA key using BIO */
  51060. static int test_wolfSSL_PEM_PrivateKey_rsa(void)
  51061. {
  51062. EXPECT_DECLS;
  51063. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  51064. defined(USE_CERT_BUFFERS_2048) && !defined(NO_FILESYSTEM) && \
  51065. !defined(NO_BIO)
  51066. BIO* bio = NULL;
  51067. XFILE file = XBADFILE;
  51068. const char* fname = "./certs/server-key.pem";
  51069. const char* fname_rsa_p8 = "./certs/server-keyPkcs8.pem";
  51070. EVP_PKEY* pkey = NULL;
  51071. size_t sz = 0;
  51072. byte* buf = NULL;
  51073. EVP_PKEY* pkey2 = NULL;
  51074. EVP_PKEY* pkey3 = NULL;
  51075. RSA* rsa_key = NULL;
  51076. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51077. unsigned char extra[10];
  51078. int i;
  51079. BIO* pub_bio = NULL;
  51080. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51081. #endif
  51082. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51083. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51084. ExpectIntGT(sz = XFTELL(file), 0);
  51085. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51086. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51087. if (buf != NULL) {
  51088. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51089. }
  51090. if (file != XBADFILE) {
  51091. XFCLOSE(file);
  51092. file = XBADFILE;
  51093. }
  51094. /* Test using BIO new mem and loading PEM private key */
  51095. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51096. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51097. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51098. buf = NULL;
  51099. BIO_free(bio);
  51100. bio = NULL;
  51101. /* New empty EVP_PKEY */
  51102. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51103. if (pkey2 != NULL) {
  51104. pkey2->type = EVP_PKEY_RSA;
  51105. }
  51106. /* Test parameter copy */
  51107. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 0);
  51108. EVP_PKEY_free(pkey2);
  51109. EVP_PKEY_free(pkey);
  51110. pkey = NULL;
  51111. /* Qt unit test case : rsa pkcs8 key */
  51112. ExpectTrue((file = XFOPEN(fname_rsa_p8, "rb")) != XBADFILE);
  51113. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51114. ExpectIntGT(sz = XFTELL(file), 0);
  51115. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51116. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51117. if (buf) {
  51118. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51119. }
  51120. if (file != XBADFILE) {
  51121. XFCLOSE(file);
  51122. file = XBADFILE;
  51123. }
  51124. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51125. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51126. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51127. buf = NULL;
  51128. BIO_free(bio);
  51129. bio = NULL;
  51130. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51131. ExpectNotNull(rsa_key = EVP_PKEY_get1_RSA(pkey));
  51132. ExpectIntEQ(EVP_PKEY_set1_RSA(pkey3, rsa_key), WOLFSSL_SUCCESS);
  51133. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51134. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51135. #else
  51136. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51137. #endif
  51138. RSA_free(rsa_key);
  51139. EVP_PKEY_free(pkey3);
  51140. EVP_PKEY_free(pkey);
  51141. pkey = NULL;
  51142. pkey2 = NULL;
  51143. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51144. #define BIO_PEM_TEST_CHAR 'a'
  51145. XMEMSET(extra, BIO_PEM_TEST_CHAR, sizeof(extra));
  51146. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51147. ExpectIntEQ(BIO_set_write_buf_size(bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51148. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51149. ExpectIntEQ(BIO_set_write_buf_size(pub_bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51150. ExpectNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key,
  51151. (long)sizeof_server_key_der_2048));
  51152. ExpectNull(pkey);
  51153. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  51154. (long)sizeof_server_key_der_2048));
  51155. ExpectIntEQ(PEM_write_bio_PrivateKey(NULL, pkey, NULL, NULL, 0, NULL, NULL),
  51156. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51157. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, NULL, NULL, NULL, 0, NULL, NULL),
  51158. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51159. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51160. WOLFSSL_SUCCESS);
  51161. ExpectIntGT(BIO_pending(bio), 0);
  51162. ExpectIntEQ(BIO_pending(bio), 1679);
  51163. /* Check if the pubkey API writes only the public key */
  51164. #ifdef WOLFSSL_KEY_GEN
  51165. ExpectIntEQ(PEM_write_bio_PUBKEY(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51166. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51167. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51168. ExpectIntGT(BIO_pending(pub_bio), 0);
  51169. /* Previously both the private key and the pubkey calls would write
  51170. * out the private key and the PEM header was the only difference.
  51171. * The public PEM should be significantly shorter than the
  51172. * private key versison. */
  51173. ExpectIntEQ(BIO_pending(pub_bio), 451);
  51174. #else
  51175. /* Not supported. */
  51176. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), 0);
  51177. #endif
  51178. /* test creating new EVP_PKEY with good args */
  51179. ExpectNotNull((pkey2 = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51180. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51181. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51182. pkey->pkey_sz), 0);
  51183. }
  51184. /* test of reuse of EVP_PKEY */
  51185. ExpectNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51186. ExpectIntEQ(BIO_pending(bio), 0);
  51187. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51188. SSL_SUCCESS);
  51189. /* add 10 extra bytes after PEM */
  51190. ExpectIntEQ(BIO_write(bio, extra, 10), 10);
  51191. ExpectNotNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51192. ExpectNotNull(pkey);
  51193. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51194. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51195. pkey->pkey_sz), 0);
  51196. }
  51197. /* check 10 extra bytes still there */
  51198. ExpectIntEQ(BIO_pending(bio), 10);
  51199. ExpectIntEQ(BIO_read(bio, extra, 10), 10);
  51200. for (i = 0; i < 10; i++) {
  51201. ExpectIntEQ(extra[i], BIO_PEM_TEST_CHAR);
  51202. }
  51203. BIO_free(pub_bio);
  51204. BIO_free(bio);
  51205. bio = NULL;
  51206. EVP_PKEY_free(pkey);
  51207. pkey = NULL;
  51208. EVP_PKEY_free(pkey2);
  51209. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  51210. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 &&
  51211. * !NO_FILESYSTEM && !NO_BIO */
  51212. return EXPECT_RESULT();
  51213. }
  51214. /* test loading ECC key using BIO */
  51215. static int test_wolfSSL_PEM_PrivateKey_ecc(void)
  51216. {
  51217. EXPECT_DECLS;
  51218. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_ECC) && \
  51219. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51220. BIO* bio = NULL;
  51221. EVP_PKEY* pkey = NULL;
  51222. XFILE file = XBADFILE;
  51223. const char* fname = "./certs/ecc-key.pem";
  51224. const char* fname_ecc_p8 = "./certs/ecc-keyPkcs8.pem";
  51225. size_t sz = 0;
  51226. byte* buf = NULL;
  51227. EVP_PKEY* pkey2 = NULL;
  51228. EVP_PKEY* pkey3 = NULL;
  51229. EC_KEY* ec_key = NULL;
  51230. int nid = 0;
  51231. BIO* pub_bio = NULL;
  51232. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51233. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51234. ExpectIntGT(sz = XFTELL(file), 0);
  51235. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51236. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51237. if (buf) {
  51238. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51239. }
  51240. if (file != XBADFILE) {
  51241. XFCLOSE(file);
  51242. file = XBADFILE;
  51243. }
  51244. /* Test using BIO new mem and loading PEM private key */
  51245. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51246. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51247. BIO_free(bio);
  51248. bio = NULL;
  51249. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51250. buf = NULL;
  51251. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51252. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51253. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51254. WOLFSSL_SUCCESS);
  51255. ExpectIntGT(BIO_pending(bio), 0);
  51256. /* No parameters. */
  51257. ExpectIntEQ(BIO_pending(bio), 227);
  51258. /* Check if the pubkey API writes only the public key */
  51259. #ifdef WOLFSSL_KEY_GEN
  51260. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51261. ExpectIntGT(BIO_pending(pub_bio), 0);
  51262. /* Previously both the private key and the pubkey calls would write
  51263. * out the private key and the PEM header was the only difference.
  51264. * The public PEM should be significantly shorter than the
  51265. * private key versison. */
  51266. ExpectIntEQ(BIO_pending(pub_bio), 178);
  51267. #endif
  51268. BIO_free(pub_bio);
  51269. BIO_free(bio);
  51270. bio = NULL;
  51271. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51272. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51273. if (pkey2 != NULL) {
  51274. pkey2->type = EVP_PKEY_EC;
  51275. }
  51276. /* Test parameter copy */
  51277. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 1);
  51278. /* Qt unit test case 1*/
  51279. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51280. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51281. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51282. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51283. #else
  51284. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51285. #endif
  51286. /* Test default digest */
  51287. ExpectIntEQ(EVP_PKEY_get_default_digest_nid(pkey, &nid), 1);
  51288. ExpectIntEQ(nid, NID_sha256);
  51289. EC_KEY_free(ec_key);
  51290. ec_key = NULL;
  51291. EVP_PKEY_free(pkey3);
  51292. pkey3 = NULL;
  51293. EVP_PKEY_free(pkey2);
  51294. pkey2 = NULL;
  51295. EVP_PKEY_free(pkey);
  51296. pkey = NULL;
  51297. /* Qt unit test case ec pkcs8 key */
  51298. ExpectTrue((file = XFOPEN(fname_ecc_p8, "rb")) != XBADFILE);
  51299. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51300. ExpectIntGT(sz = XFTELL(file), 0);
  51301. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51302. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51303. if (buf) {
  51304. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51305. }
  51306. if (file != XBADFILE) {
  51307. XFCLOSE(file);
  51308. file = XBADFILE;
  51309. }
  51310. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51311. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51312. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51313. buf = NULL;
  51314. BIO_free(bio);
  51315. bio = NULL;
  51316. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51317. /* Qt unit test case */
  51318. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51319. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51320. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51321. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51322. #else
  51323. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51324. #endif
  51325. EC_KEY_free(ec_key);
  51326. EVP_PKEY_free(pkey3);
  51327. EVP_PKEY_free(pkey);
  51328. pkey = NULL;
  51329. #endif
  51330. return EXPECT_RESULT();
  51331. }
  51332. /* test loading DSA key using BIO */
  51333. static int test_wolfSSL_PEM_PrivateKey_dsa(void)
  51334. {
  51335. EXPECT_DECLS;
  51336. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DSA) && \
  51337. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51338. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  51339. BIO* bio = NULL;
  51340. EVP_PKEY* pkey = NULL;
  51341. ExpectNotNull(bio = BIO_new_file("./certs/dsa2048.pem", "rb"));
  51342. /* Private DSA EVP_PKEY */
  51343. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51344. NULL));
  51345. BIO_free(bio);
  51346. bio = NULL;
  51347. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51348. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51349. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51350. NULL), 0);
  51351. #endif
  51352. #ifdef WOLFSSL_KEY_GEN
  51353. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 1);
  51354. ExpectIntEQ(BIO_pending(bio), 1178);
  51355. BIO_reset(bio);
  51356. #endif
  51357. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51358. 1);
  51359. ExpectIntEQ(BIO_pending(bio), 1196);
  51360. BIO_free(bio);
  51361. bio = NULL;
  51362. EVP_PKEY_free(pkey);
  51363. pkey = NULL;
  51364. #endif
  51365. #endif
  51366. return EXPECT_RESULT();
  51367. }
  51368. /* test loading DH key using BIO */
  51369. static int test_wolfSSL_PEM_PrivateKey_dh(void)
  51370. {
  51371. EXPECT_DECLS;
  51372. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DH) && \
  51373. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51374. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51375. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51376. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51377. BIO* bio = NULL;
  51378. EVP_PKEY* pkey = NULL;
  51379. ExpectNotNull(bio = BIO_new_file("./certs/dh-priv-2048.pem", "rb"));
  51380. /* Private DH EVP_PKEY */
  51381. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51382. NULL));
  51383. BIO_free(bio);
  51384. bio = NULL;
  51385. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51386. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51387. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51388. NULL), 0);
  51389. #endif
  51390. #ifdef WOLFSSL_KEY_GEN
  51391. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 0);
  51392. #endif
  51393. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51394. 1);
  51395. ExpectIntEQ(BIO_pending(bio), 806);
  51396. BIO_free(bio);
  51397. bio = NULL;
  51398. EVP_PKEY_free(pkey);
  51399. pkey = NULL;
  51400. #endif
  51401. #endif
  51402. return EXPECT_RESULT();
  51403. }
  51404. static int test_wolfSSL_PEM_PrivateKey(void)
  51405. {
  51406. EXPECT_DECLS;
  51407. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51408. (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(USE_CERT_BUFFERS_2048)
  51409. #ifndef NO_BIO
  51410. BIO* bio = NULL;
  51411. #endif
  51412. EVP_PKEY* pkey = NULL;
  51413. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51414. #ifndef NO_BIO
  51415. /* test creating new EVP_PKEY with bad arg */
  51416. ExpectNull((pkey = PEM_read_bio_PrivateKey(NULL, NULL, NULL, NULL)));
  51417. /* Test bad EVP_PKEY type. */
  51418. /* New HMAC EVP_PKEY */
  51419. ExpectNotNull(bio = BIO_new_mem_buf("", 1));
  51420. ExpectNotNull(pkey = EVP_PKEY_new());
  51421. if (pkey != NULL) {
  51422. pkey->type = EVP_PKEY_HMAC;
  51423. }
  51424. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51425. 0);
  51426. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51427. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51428. NULL), 0);
  51429. #endif
  51430. #ifdef WOLFSSL_KEY_GEN
  51431. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51432. #endif
  51433. EVP_PKEY_free(pkey);
  51434. pkey = NULL;
  51435. BIO_free(bio);
  51436. bio = NULL;
  51437. /* key is DES encrypted */
  51438. #if !defined(NO_DES3) && defined(WOLFSSL_ENCRYPTED_KEYS) && \
  51439. !defined(NO_RSA) && !defined(NO_BIO) && !defined(NO_FILESYSTEM) && \
  51440. !defined(NO_MD5) && defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  51441. {
  51442. XFILE f = XBADFILE;
  51443. wc_pem_password_cb* passwd_cb = NULL;
  51444. void* passwd_cb_userdata;
  51445. SSL_CTX* ctx = NULL;
  51446. char passwd[] = "bad password";
  51447. #ifndef WOLFSSL_NO_TLS12
  51448. #ifndef NO_WOLFSSL_SERVER
  51449. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51450. #else
  51451. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51452. #endif
  51453. #else
  51454. #ifndef NO_WOLFSSL_SERVER
  51455. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51456. #else
  51457. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51458. #endif
  51459. #endif
  51460. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51461. SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  51462. ExpectNotNull(passwd_cb = SSL_CTX_get_default_passwd_cb(ctx));
  51463. ExpectNull(passwd_cb_userdata =
  51464. SSL_CTX_get_default_passwd_cb_userdata(ctx));
  51465. /* fail case with password call back */
  51466. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51467. (void*)passwd));
  51468. BIO_free(bio);
  51469. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51470. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51471. (void*)passwd));
  51472. BIO_free(bio);
  51473. ExpectTrue((f = XFOPEN("./certs/server-keyEnc.pem", "rb")) != XBADFILE);
  51474. ExpectNotNull(bio = BIO_new_fp(f, BIO_CLOSE));
  51475. if ((bio == NULL) && (f != XBADFILE)) {
  51476. XFCLOSE(f);
  51477. }
  51478. /* use callback that works */
  51479. ExpectNotNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51480. (void*)"yassl123"));
  51481. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51482. EVP_PKEY_free(pkey);
  51483. pkey = NULL;
  51484. BIO_free(bio);
  51485. bio = NULL;
  51486. SSL_CTX_free(ctx);
  51487. }
  51488. #endif /* !defined(NO_DES3) */
  51489. #endif /* !NO_BIO */
  51490. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  51491. {
  51492. unsigned char buf[2048];
  51493. size_t bytes = 0;
  51494. XFILE f = XBADFILE;
  51495. SSL_CTX* ctx = NULL;
  51496. #ifndef WOLFSSL_NO_TLS12
  51497. #ifndef NO_WOLFSSL_SERVER
  51498. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51499. #else
  51500. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51501. #endif
  51502. #else
  51503. #ifndef NO_WOLFSSL_SERVER
  51504. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51505. #else
  51506. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51507. #endif
  51508. #endif
  51509. ExpectTrue((f = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  51510. ExpectIntGT(bytes = (size_t)XFREAD(buf, 1, sizeof(buf), f), 0);
  51511. if (f != XBADFILE)
  51512. XFCLOSE(f);
  51513. server_key = buf;
  51514. pkey = NULL;
  51515. ExpectNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key, (long int)bytes));
  51516. ExpectNull(pkey);
  51517. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key, (long int)bytes));
  51518. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51519. EVP_PKEY_free(pkey);
  51520. pkey = NULL;
  51521. SSL_CTX_free(ctx);
  51522. server_key = NULL;
  51523. }
  51524. #endif
  51525. #ifndef NO_BIO
  51526. (void)bio;
  51527. #endif
  51528. (void)pkey;
  51529. (void)server_key;
  51530. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 */
  51531. return EXPECT_RESULT();
  51532. }
  51533. static int test_wolfSSL_PEM_file_RSAKey(void)
  51534. {
  51535. EXPECT_DECLS;
  51536. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51537. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  51538. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  51539. RSA* rsa = NULL;
  51540. XFILE fp = XBADFILE;
  51541. ExpectTrue((fp = XFOPEN("./certs/rsa-pub-2048.pem", "rb")) != XBADFILE);
  51542. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL)));
  51543. if (fp != XBADFILE)
  51544. XFCLOSE(fp);
  51545. ExpectIntEQ(RSA_size(rsa), 256);
  51546. ExpectIntEQ(PEM_write_RSAPublicKey(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51547. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51548. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, rsa), WOLFSSL_SUCCESS);
  51549. ExpectIntEQ(PEM_write_RSA_PUBKEY(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51550. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51551. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, rsa), WOLFSSL_SUCCESS);
  51552. RSA_free(rsa);
  51553. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51554. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  51555. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  51556. return EXPECT_RESULT();
  51557. }
  51558. static int test_wolfSSL_PEM_file_RSAPrivateKey(void)
  51559. {
  51560. EXPECT_DECLS;
  51561. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  51562. !defined(NO_FILESYSTEM) && \
  51563. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  51564. RSA* rsa = NULL;
  51565. XFILE f = NULL;
  51566. ExpectTrue((f = XFOPEN(svrKeyFile, "r")) != XBADFILE);
  51567. ExpectNotNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  51568. ExpectIntEQ(RSA_size(rsa), 256);
  51569. if (f != XBADFILE) {
  51570. XFCLOSE(f);
  51571. f = XBADFILE;
  51572. }
  51573. ExpectIntEQ(PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0, NULL,
  51574. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51575. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  51576. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51577. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0, NULL, NULL),
  51578. WOLFSSL_SUCCESS);
  51579. RSA_free(rsa);
  51580. #ifdef HAVE_ECC
  51581. ExpectTrue((f = XFOPEN(eccKeyFile, "r")) != XBADFILE);
  51582. ExpectNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  51583. if (f != XBADFILE)
  51584. XFCLOSE(f);
  51585. #endif /* HAVE_ECC */
  51586. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51587. return EXPECT_RESULT();
  51588. }
  51589. static int test_wolfSSL_PEM_read_RSA_PUBKEY(void)
  51590. {
  51591. EXPECT_DECLS;
  51592. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51593. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  51594. XFILE file = XBADFILE;
  51595. const char* fname = "./certs/client-keyPub.pem";
  51596. RSA *rsa = NULL;
  51597. ExpectNull(wolfSSL_PEM_read_RSA_PUBKEY(XBADFILE, NULL, NULL, NULL));
  51598. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51599. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL)));
  51600. ExpectIntEQ(RSA_size(rsa), 256);
  51601. RSA_free(rsa);
  51602. if (file != XBADFILE)
  51603. XFCLOSE(file);
  51604. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51605. return EXPECT_RESULT();
  51606. }
  51607. #ifndef NO_BIO
  51608. static int test_wolfSSL_PEM_bio_RSAKey(void)
  51609. {
  51610. EXPECT_DECLS;
  51611. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51612. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  51613. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  51614. RSA* rsa = NULL;
  51615. BIO* bio = NULL;
  51616. /* PrivateKey */
  51617. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  51618. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(NULL, NULL, NULL, NULL)));
  51619. ExpectNotNull(PEM_read_bio_RSAPrivateKey(bio, &rsa, NULL, NULL));
  51620. ExpectNotNull(rsa);
  51621. ExpectIntEQ(RSA_size(rsa), 256);
  51622. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL, \
  51623. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51624. BIO_free(bio);
  51625. bio = NULL;
  51626. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51627. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, \
  51628. NULL), WOLFSSL_SUCCESS);
  51629. BIO_free(bio);
  51630. bio = NULL;
  51631. RSA_free(rsa);
  51632. rsa = NULL;
  51633. /* PUBKEY */
  51634. ExpectNotNull(bio = BIO_new_file("./certs/rsa-pub-2048.pem", "rb"));
  51635. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(NULL, NULL, NULL, NULL)));
  51636. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  51637. ExpectIntEQ(RSA_size(rsa), 256);
  51638. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51639. BIO_free(bio);
  51640. bio = NULL;
  51641. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51642. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(bio, rsa), WOLFSSL_SUCCESS);
  51643. BIO_free(bio);
  51644. bio = NULL;
  51645. RSA_free(rsa);
  51646. rsa = NULL;
  51647. /* Ensure that keys beginning with BEGIN RSA PUBLIC KEY can be read, too. */
  51648. ExpectNotNull(bio = BIO_new_file("./certs/server-keyPub.pem", "rb"));
  51649. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  51650. BIO_free(bio);
  51651. bio = NULL;
  51652. RSA_free(rsa);
  51653. rsa = NULL;
  51654. #ifdef HAVE_ECC
  51655. /* ensure that non-rsa keys do not work */
  51656. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  51657. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  51658. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  51659. BIO_free(bio);
  51660. bio = NULL;
  51661. RSA_free(rsa);
  51662. rsa = NULL;
  51663. #endif /* HAVE_ECC */
  51664. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51665. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  51666. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  51667. return EXPECT_RESULT();
  51668. }
  51669. static int test_wolfSSL_PEM_bio_RSAPrivateKey(void)
  51670. {
  51671. EXPECT_DECLS;
  51672. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51673. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  51674. RSA* rsa = NULL;
  51675. RSA* rsa_dup = NULL;
  51676. BIO* bio = NULL;
  51677. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  51678. ExpectNotNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  51679. ExpectIntEQ(RSA_size(rsa), 256);
  51680. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  51681. ExpectNull(rsa_dup = RSAPublicKey_dup(NULL));
  51682. /* Test duplicating empty key. */
  51683. ExpectNotNull(rsa_dup = RSA_new());
  51684. ExpectNull(RSAPublicKey_dup(rsa_dup));
  51685. RSA_free(rsa_dup);
  51686. rsa_dup = NULL;
  51687. ExpectNotNull(rsa_dup = RSAPublicKey_dup(rsa));
  51688. ExpectPtrNE(rsa_dup, rsa);
  51689. #endif
  51690. /* test if valgrind complains about unreleased memory */
  51691. RSA_up_ref(rsa);
  51692. RSA_free(rsa);
  51693. BIO_free(bio);
  51694. bio = NULL;
  51695. RSA_free(rsa);
  51696. rsa = NULL;
  51697. RSA_free(rsa_dup);
  51698. rsa_dup = NULL;
  51699. #ifdef HAVE_ECC
  51700. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
  51701. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  51702. BIO_free(bio);
  51703. #endif /* HAVE_ECC */
  51704. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51705. return EXPECT_RESULT();
  51706. }
  51707. static int test_wolfSSL_PEM_bio_DSAKey(void)
  51708. {
  51709. EXPECT_DECLS;
  51710. #ifndef HAVE_SELFTEST
  51711. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && !defined(NO_CERTS) && \
  51712. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && !defined(NO_DSA)
  51713. DSA* dsa = NULL;
  51714. BIO* bio = NULL;
  51715. /* PrivateKey */
  51716. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa1024.pem", "rb"));
  51717. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(NULL, NULL, NULL, NULL)));
  51718. ExpectNotNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  51719. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  51720. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  51721. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51722. BIO_free(bio);
  51723. bio = NULL;
  51724. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51725. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(bio, dsa, NULL, NULL, 0, NULL,
  51726. NULL), WOLFSSL_SUCCESS);
  51727. BIO_free(bio);
  51728. bio = NULL;
  51729. DSA_free(dsa);
  51730. dsa = NULL;
  51731. /* PUBKEY */
  51732. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa-pub-1024.pem", "rb"));
  51733. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(NULL, NULL, NULL, NULL)));
  51734. ExpectNotNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  51735. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  51736. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51737. BIO_free(bio);
  51738. bio = NULL;
  51739. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51740. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(bio, dsa), WOLFSSL_SUCCESS);
  51741. BIO_free(bio);
  51742. bio = NULL;
  51743. DSA_free(dsa);
  51744. dsa = NULL;
  51745. #ifdef HAVE_ECC
  51746. /* ensure that non-dsa keys do not work */
  51747. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  51748. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  51749. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  51750. BIO_free(bio);
  51751. bio = NULL;
  51752. DSA_free(dsa);
  51753. dsa = NULL;
  51754. #endif /* HAVE_ECC */
  51755. #endif /* defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && \
  51756. !defined(NO_CERTS) && defined(WOLFSSL_KEY_GEN) && \
  51757. !defined(NO_FILESYSTEM) && !defined(NO_DSA) */
  51758. #endif /* HAVE_SELFTEST */
  51759. return EXPECT_RESULT();
  51760. }
  51761. static int test_wolfSSL_PEM_bio_ECKey(void)
  51762. {
  51763. EXPECT_DECLS;
  51764. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51765. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  51766. EC_KEY* ec = NULL;
  51767. EC_KEY* ec2;
  51768. BIO* bio = NULL;
  51769. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  51770. unsigned char* pem = NULL;
  51771. int pLen;
  51772. #endif
  51773. static char ec_key_bad_1[] = "-----BEGIN PUBLIC KEY-----\n"
  51774. "MAA=\n"
  51775. "-----END PUBLIC KEY-----";
  51776. static char ec_priv_key_bad_1[] = "-----BEGIN EC PRIVATE KEY-----\n"
  51777. "MAA=\n"
  51778. "-----END EC PRIVATE KEY-----";
  51779. /* PrivateKey */
  51780. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  51781. ExpectNull((ec = PEM_read_bio_ECPrivateKey(NULL, NULL, NULL, NULL)));
  51782. ec2 = NULL;
  51783. ExpectNotNull((ec = PEM_read_bio_ECPrivateKey(bio, &ec2, NULL, NULL)));
  51784. ExpectIntEQ(ec == ec2, 1);
  51785. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  51786. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  51787. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51788. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  51789. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51790. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, ec, NULL, NULL, 0, NULL, NULL),
  51791. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51792. BIO_free(bio);
  51793. bio = NULL;
  51794. /* Public key data - fail. */
  51795. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  51796. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  51797. BIO_free(bio);
  51798. bio = NULL;
  51799. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51800. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, ec, NULL, NULL, 0, NULL, \
  51801. NULL), WOLFSSL_SUCCESS);
  51802. BIO_free(bio);
  51803. bio = NULL;
  51804. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, NULL, NULL, NULL, 0, NULL,
  51805. NULL),WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51806. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, NULL, NULL, NULL, 0, NULL, NULL),
  51807. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51808. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, ec, NULL, NULL, 0, NULL, NULL),
  51809. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51810. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, ec, NULL, NULL, 0, NULL, NULL),
  51811. WOLFSSL_SUCCESS);
  51812. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  51813. NULL), 0);
  51814. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  51815. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  51816. NULL), 0);
  51817. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  51818. NULL), 0);
  51819. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  51820. &pLen), 0);
  51821. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  51822. &pLen), 0);
  51823. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  51824. &pLen), 0);
  51825. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  51826. NULL), 0);
  51827. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  51828. &pLen), 1);
  51829. ExpectIntGT(pLen, 0);
  51830. XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  51831. #endif
  51832. EC_KEY_free(ec);
  51833. ec = NULL;
  51834. /* PUBKEY */
  51835. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  51836. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(NULL, NULL, NULL, NULL)));
  51837. ec2 = NULL;
  51838. ExpectNotNull((ec = PEM_read_bio_EC_PUBKEY(bio, &ec2, NULL, NULL)));
  51839. ExpectIntEQ(ec == ec2, 1);
  51840. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  51841. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51842. BIO_free(bio);
  51843. bio = NULL;
  51844. /* Test 0x30, 0x00 fails. */
  51845. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_key_bad_1,
  51846. sizeof(ec_key_bad_1)));
  51847. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  51848. BIO_free(bio);
  51849. bio = NULL;
  51850. /* Private key data - fail. */
  51851. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  51852. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  51853. BIO_free(bio);
  51854. bio = NULL;
  51855. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51856. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(bio, ec), WOLFSSL_SUCCESS);
  51857. BIO_free(bio);
  51858. bio = NULL;
  51859. /* Same test as above, but with a file pointer rather than a BIO. */
  51860. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51861. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, ec), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51862. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51863. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, ec), WOLFSSL_SUCCESS);
  51864. EC_KEY_free(ec);
  51865. ec = NULL;
  51866. #ifndef NO_RSA
  51867. /* ensure that non-ec keys do not work */
  51868. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb")); /* rsa key */
  51869. ExpectNull((ec = PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL)));
  51870. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL)));
  51871. BIO_free(bio);
  51872. bio = NULL;
  51873. EC_KEY_free(ec);
  51874. ec = NULL;
  51875. #endif /* !NO_RSA */
  51876. /* Test 0x30, 0x00 fails. */
  51877. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_priv_key_bad_1,
  51878. sizeof(ec_priv_key_bad_1)));
  51879. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  51880. BIO_free(bio);
  51881. bio = NULL;
  51882. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51883. return EXPECT_RESULT();
  51884. }
  51885. static int test_wolfSSL_PEM_PUBKEY(void)
  51886. {
  51887. EXPECT_DECLS;
  51888. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  51889. BIO* bio = NULL;
  51890. EVP_PKEY* pkey = NULL;
  51891. /* test creating new EVP_PKEY with bad arg */
  51892. ExpectNull((pkey = PEM_read_bio_PUBKEY(NULL, NULL, NULL, NULL)));
  51893. /* test loading ECC key using BIO */
  51894. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  51895. {
  51896. XFILE file = XBADFILE;
  51897. const char* fname = "./certs/ecc-client-keyPub.pem";
  51898. size_t sz = 0;
  51899. byte* buf = NULL;
  51900. EVP_PKEY* pkey2 = NULL;
  51901. EC_KEY* ec_key = NULL;
  51902. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51903. ExpectIntEQ(XFSEEK(file, 0, XSEEK_END), 0);
  51904. ExpectIntGT(sz = XFTELL(file), 0);
  51905. ExpectIntEQ(XFSEEK(file, 0, XSEEK_SET), 0);
  51906. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51907. if (buf != NULL) {
  51908. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51909. }
  51910. if (file != XBADFILE) {
  51911. XFCLOSE(file);
  51912. }
  51913. /* Test using BIO new mem and loading PEM private key */
  51914. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51915. ExpectNotNull((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)));
  51916. BIO_free(bio);
  51917. bio = NULL;
  51918. EVP_PKEY_free(pkey);
  51919. pkey = NULL;
  51920. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51921. ExpectNotNull(pkey = EVP_PKEY_new());
  51922. ExpectPtrEq(PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL), pkey);
  51923. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51924. BIO_free(bio);
  51925. bio = NULL;
  51926. /* Qt unit test case*/
  51927. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51928. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51929. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey2, ec_key), WOLFSSL_SUCCESS);
  51930. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51931. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 1/* match */);
  51932. #else
  51933. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 0);
  51934. #endif
  51935. EC_KEY_free(ec_key);
  51936. EVP_PKEY_free(pkey2);
  51937. EVP_PKEY_free(pkey);
  51938. pkey = NULL;
  51939. }
  51940. #endif
  51941. (void)bio;
  51942. (void)pkey;
  51943. #endif
  51944. return EXPECT_RESULT();
  51945. }
  51946. #endif /* !NO_BIO */
  51947. static int test_DSA_do_sign_verify(void)
  51948. {
  51949. EXPECT_DECLS;
  51950. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  51951. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  51952. !defined(NO_DSA)
  51953. unsigned char digest[WC_SHA_DIGEST_SIZE];
  51954. DSA_SIG* sig = NULL;
  51955. DSA* dsa = NULL;
  51956. word32 bytes;
  51957. byte sigBin[DSA_SIG_SIZE];
  51958. int dsacheck;
  51959. #ifdef USE_CERT_BUFFERS_1024
  51960. byte tmp[ONEK_BUF];
  51961. XMEMSET(tmp, 0, sizeof(tmp));
  51962. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  51963. bytes = sizeof_dsa_key_der_1024;
  51964. #elif defined(USE_CERT_BUFFERS_2048)
  51965. byte tmp[TWOK_BUF];
  51966. XMEMSET(tmp, 0, sizeof(tmp));
  51967. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  51968. bytes = sizeof_dsa_key_der_2048;
  51969. #else
  51970. byte tmp[TWOK_BUF];
  51971. XFILE fp = XBADFILE;
  51972. XMEMSET(tmp, 0, sizeof(tmp));
  51973. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb") != XBADFILE);
  51974. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  51975. if (fp != XBADFILE)
  51976. XFCLOSE(fp);
  51977. #endif /* END USE_CERT_BUFFERS_1024 */
  51978. XMEMSET(digest, 202, sizeof(digest));
  51979. ExpectNotNull(dsa = DSA_new());
  51980. ExpectIntEQ(DSA_LoadDer(dsa, tmp, (int)bytes), 1);
  51981. ExpectIntEQ(wolfSSL_DSA_do_sign(digest, sigBin, dsa), 1);
  51982. ExpectIntEQ(wolfSSL_DSA_do_verify(digest, sigBin, dsa, &dsacheck), 1);
  51983. ExpectNotNull(sig = DSA_do_sign(digest, WC_SHA_DIGEST_SIZE, dsa));
  51984. ExpectIntEQ(DSA_do_verify(digest, WC_SHA_DIGEST_SIZE, sig, dsa), 1);
  51985. DSA_SIG_free(sig);
  51986. DSA_free(dsa);
  51987. #endif
  51988. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  51989. return EXPECT_RESULT();
  51990. }
  51991. static int test_wolfSSL_tmp_dh(void)
  51992. {
  51993. EXPECT_DECLS;
  51994. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  51995. !defined(NO_RSA) && !defined(NO_DH) && !defined(NO_BIO)
  51996. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  51997. byte buff[6000];
  51998. static const unsigned char p[] = {
  51999. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52000. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52001. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52002. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52003. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52004. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52005. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52006. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52007. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52008. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52009. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52010. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52011. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52012. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52013. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52014. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52015. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52016. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52017. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52018. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52019. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52020. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52021. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52022. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52023. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52024. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52025. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52026. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52027. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52028. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52029. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52030. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x93
  52031. };
  52032. int pSz = (int)sizeof(p);
  52033. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52034. !defined(HAVE_SELFTEST)
  52035. static const unsigned char bad_p[] = {
  52036. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52037. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52038. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52039. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52040. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52041. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52042. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52043. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52044. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52045. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52046. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52047. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52048. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52049. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52050. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52051. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52052. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52053. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52054. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52055. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52056. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52057. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52058. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52059. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52060. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52061. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52062. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52063. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52064. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52065. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52066. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52067. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x91
  52068. };
  52069. #endif
  52070. static const unsigned char g[] = { 0x02 };
  52071. int gSz = (int)sizeof(g);
  52072. #if !defined(NO_DSA)
  52073. char file[] = "./certs/dsaparams.pem";
  52074. DSA* dsa = NULL;
  52075. #else
  52076. char file[] = "./certs/dh2048.pem";
  52077. #endif
  52078. XFILE f = XBADFILE;
  52079. int bytes = 0;
  52080. DH* dh = NULL;
  52081. DH* dh2 = NULL;
  52082. BIO* bio = NULL;
  52083. SSL* ssl = NULL;
  52084. SSL_CTX* ctx = NULL;
  52085. #ifndef NO_WOLFSSL_CLIENT
  52086. SSL* ssl_c = NULL;
  52087. SSL_CTX* ctx_c = NULL;
  52088. #endif
  52089. #ifndef NO_WOLFSSL_SERVER
  52090. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52091. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  52092. WOLFSSL_FILETYPE_PEM));
  52093. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  52094. WOLFSSL_FILETYPE_PEM));
  52095. ExpectNotNull(ssl = SSL_new(ctx));
  52096. #endif
  52097. #ifndef NO_WOLFSSL_CLIENT
  52098. ExpectNotNull(ctx_c = SSL_CTX_new(wolfSSLv23_client_method()));
  52099. ExpectTrue(SSL_CTX_use_certificate_file(ctx_c, svrCertFile,
  52100. WOLFSSL_FILETYPE_PEM));
  52101. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx_c, svrKeyFile,
  52102. WOLFSSL_FILETYPE_PEM));
  52103. ExpectNotNull(ssl_c = SSL_new(ctx_c));
  52104. #ifdef NO_WOLFSSL_SERVER
  52105. ctx = ctx_c;
  52106. ssl = ssl_c;
  52107. #endif
  52108. #endif
  52109. XMEMSET(buff, 0, sizeof(buff));
  52110. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  52111. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  52112. if (f != XBADFILE)
  52113. XFCLOSE(f);
  52114. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52115. #if !defined(NO_DSA)
  52116. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  52117. ExpectNotNull(dsa);
  52118. dh = wolfSSL_DSA_dup_DH(dsa);
  52119. #else
  52120. dh = wolfSSL_PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
  52121. #endif
  52122. ExpectNotNull(dh);
  52123. #if defined(WOLFSSL_DH_EXTRA) && \
  52124. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH))
  52125. ExpectNotNull(dh2 = wolfSSL_DH_dup(dh));
  52126. DH_free(dh2);
  52127. dh2 = NULL;
  52128. #endif
  52129. /* Failure cases */
  52130. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52131. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52132. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, NULL, 0),
  52133. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52134. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, NULL, 0),
  52135. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52136. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, g , 0),
  52137. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52138. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 0, NULL, 0),
  52139. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52140. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, g , 0),
  52141. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52142. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, g , 0),
  52143. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52144. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 1, g , 1),
  52145. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52146. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , buff, 6000, g , 1),
  52147. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52148. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52149. !defined(HAVE_SELFTEST)
  52150. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, bad_p, pSz, g, gSz),
  52151. WC_NO_ERR_TRACE(DH_CHECK_PUB_E));
  52152. #endif
  52153. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52154. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52155. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, NULL, 0),
  52156. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52157. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, NULL, 0),
  52158. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52159. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, g , 0),
  52160. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52161. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 0, NULL, 0),
  52162. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52163. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, g , 0),
  52164. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52165. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, g , 0),
  52166. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52167. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 1, g , 1),
  52168. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52169. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , buff, 6000, g , 1),
  52170. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52171. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52172. !defined(HAVE_SELFTEST)
  52173. #ifndef NO_WOLFSSL_SERVER
  52174. /* Parameters will be tested later so it passes now. */
  52175. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl, bad_p, pSz, g, gSz),
  52176. WOLFSSL_SUCCESS);
  52177. #endif
  52178. #endif
  52179. #ifndef NO_WOLFSSL_CLIENT
  52180. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl_c, p, pSz, g, gSz),
  52181. WC_NO_ERR_TRACE(SIDE_ERROR));
  52182. #endif
  52183. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52184. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52185. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52186. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52187. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52188. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52189. /* No p/g to use. */
  52190. dh2 = wolfSSL_DH_new();
  52191. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52192. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52193. DH_free(dh2);
  52194. dh2 = NULL;
  52195. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz),
  52196. WOLFSSL_SUCCESS);
  52197. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_SUCCESS);
  52198. #ifndef NO_WOLFSSL_SERVER
  52199. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WOLFSSL_SUCCESS);
  52200. #else
  52201. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WC_NO_ERR_TRACE(SIDE_ERROR));
  52202. #endif
  52203. BIO_free(bio);
  52204. #if !defined(NO_DSA)
  52205. DSA_free(dsa);
  52206. #endif
  52207. DH_free(dh);
  52208. dh = NULL;
  52209. #ifndef NO_WOLFSSL_CLIENT
  52210. if (ssl != ssl_c) {
  52211. SSL_free(ssl_c);
  52212. }
  52213. #endif
  52214. SSL_free(ssl);
  52215. #ifndef NO_WOLFSSL_CLIENT
  52216. if (ctx != ctx_c) {
  52217. SSL_CTX_free(ctx_c);
  52218. }
  52219. #endif
  52220. SSL_CTX_free(ctx);
  52221. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  52222. #endif
  52223. return EXPECT_RESULT();
  52224. }
  52225. static int test_wolfSSL_ctrl(void)
  52226. {
  52227. EXPECT_DECLS;
  52228. #if defined (OPENSSL_EXTRA) && !defined(NO_BIO)
  52229. byte buff[6000];
  52230. BIO* bio = NULL;
  52231. int bytes;
  52232. BUF_MEM* ptr = NULL;
  52233. XMEMSET(buff, 0, sizeof(buff));
  52234. bytes = sizeof(buff);
  52235. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52236. ExpectNotNull(BIO_s_socket());
  52237. ExpectIntEQ((int)wolfSSL_BIO_get_mem_ptr(bio, &ptr), WOLFSSL_SUCCESS);
  52238. /* needs tested after stubs filled out @TODO
  52239. SSL_ctrl
  52240. SSL_CTX_ctrl
  52241. */
  52242. BIO_free(bio);
  52243. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_BIO) */
  52244. return EXPECT_RESULT();
  52245. }
  52246. static int test_wolfSSL_EVP_PKEY_new_mac_key(void)
  52247. {
  52248. EXPECT_DECLS;
  52249. #ifdef OPENSSL_EXTRA
  52250. static const unsigned char pw[] = "password";
  52251. static const int pwSz = sizeof(pw) - 1;
  52252. size_t checkPwSz = 0;
  52253. const unsigned char* checkPw = NULL;
  52254. WOLFSSL_EVP_PKEY* key = NULL;
  52255. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, pw, pwSz));
  52256. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, NULL, pwSz));
  52257. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52258. pwSz));
  52259. if (key != NULL) {
  52260. ExpectIntEQ(key->type, EVP_PKEY_HMAC);
  52261. ExpectIntEQ(key->save_type, EVP_PKEY_HMAC);
  52262. ExpectIntEQ(key->pkey_sz, pwSz);
  52263. ExpectIntEQ(XMEMCMP(key->pkey.ptr, pw, pwSz), 0);
  52264. }
  52265. ExpectNotNull(checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz));
  52266. ExpectIntEQ((int)checkPwSz, pwSz);
  52267. ExpectIntEQ(XMEMCMP(checkPw, pw, pwSz), 0);
  52268. wolfSSL_EVP_PKEY_free(key);
  52269. key = NULL;
  52270. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52271. 0));
  52272. ExpectIntEQ(key->pkey_sz, 0);
  52273. if (EXPECT_SUCCESS()) {
  52274. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52275. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52276. }
  52277. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52278. ExpectIntEQ((int)checkPwSz, 0);
  52279. wolfSSL_EVP_PKEY_free(key);
  52280. key = NULL;
  52281. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, NULL,
  52282. 0));
  52283. ExpectIntEQ(key->pkey_sz, 0);
  52284. if (EXPECT_SUCCESS()) {
  52285. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52286. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52287. }
  52288. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52289. ExpectIntEQ((int)checkPwSz, 0);
  52290. wolfSSL_EVP_PKEY_free(key);
  52291. key = NULL;
  52292. #endif /* OPENSSL_EXTRA */
  52293. return EXPECT_RESULT();
  52294. }
  52295. static int test_wolfSSL_EVP_PKEY_new_CMAC_key(void)
  52296. {
  52297. EXPECT_DECLS;
  52298. #ifdef OPENSSL_EXTRA
  52299. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
  52300. const char *priv = "ABCDEFGHIJKLMNOP";
  52301. const WOLFSSL_EVP_CIPHER* cipher = EVP_aes_128_cbc();
  52302. WOLFSSL_EVP_PKEY* key = NULL;
  52303. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52304. NULL, NULL, AES_128_KEY_SIZE, cipher));
  52305. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52306. NULL, (const unsigned char *)priv, 0, cipher));
  52307. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52308. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, NULL));
  52309. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52310. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, cipher));
  52311. wolfSSL_EVP_PKEY_free(key);
  52312. #endif /* WOLFSSL_CMAC && !NO_AES && WOLFSSL_AES_DIRECT */
  52313. #endif /* OPENSSL_EXTRA */
  52314. return EXPECT_RESULT();
  52315. }
  52316. static int test_wolfSSL_EVP_Digest(void)
  52317. {
  52318. EXPECT_DECLS;
  52319. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  52320. const char* in = "abc";
  52321. int inLen = (int)XSTRLEN(in);
  52322. byte out[WC_SHA256_DIGEST_SIZE];
  52323. unsigned int outLen;
  52324. const char* expOut =
  52325. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  52326. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  52327. "\x15\xAD";
  52328. ExpectIntEQ(wolfSSL_EVP_Digest((unsigned char*)in, inLen, out, &outLen,
  52329. "SHA256", NULL), 1);
  52330. ExpectIntEQ(outLen, WC_SHA256_DIGEST_SIZE);
  52331. ExpectIntEQ(XMEMCMP(out, expOut, WC_SHA256_DIGEST_SIZE), 0);
  52332. #endif /* OPEN_EXTRA && ! NO_SHA256 */
  52333. return EXPECT_RESULT();
  52334. }
  52335. static int test_wolfSSL_EVP_Digest_all(void)
  52336. {
  52337. EXPECT_DECLS;
  52338. #ifdef OPENSSL_EXTRA
  52339. const char* digests[] = {
  52340. #ifndef NO_MD5
  52341. "MD5",
  52342. #endif
  52343. #ifndef NO_SHA
  52344. "SHA",
  52345. #endif
  52346. #ifdef WOLFSSL_SHA224
  52347. "SHA224",
  52348. #endif
  52349. #ifndef NO_SHA256
  52350. "SHA256",
  52351. #endif
  52352. #ifdef WOLFSSL_SHA384
  52353. "SHA384",
  52354. #endif
  52355. #ifdef WOLFSSL_SHA512
  52356. "SHA512",
  52357. #endif
  52358. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  52359. "SHA512_224",
  52360. #endif
  52361. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  52362. "SHA512_256",
  52363. #endif
  52364. #ifdef WOLFSSL_SHA3
  52365. #ifndef WOLFSSL_NOSHA3_224
  52366. "SHA3_224",
  52367. #endif
  52368. #ifndef WOLFSSL_NOSHA3_256
  52369. "SHA3_256",
  52370. #endif
  52371. "SHA3_384",
  52372. #ifndef WOLFSSL_NOSHA3_512
  52373. "SHA3_512",
  52374. #endif
  52375. #endif /* WOLFSSL_SHA3 */
  52376. NULL
  52377. };
  52378. const char** d;
  52379. const unsigned char in[] = "abc";
  52380. int inLen = XSTR_SIZEOF(in);
  52381. byte out[WC_MAX_DIGEST_SIZE];
  52382. unsigned int outLen;
  52383. for (d = digests; *d != NULL; d++) {
  52384. ExpectIntEQ(EVP_Digest(in, inLen, out, &outLen, *d, NULL), 1);
  52385. ExpectIntGT(outLen, 0);
  52386. ExpectIntEQ(EVP_MD_size(*d), outLen);
  52387. }
  52388. #endif
  52389. return EXPECT_RESULT();
  52390. }
  52391. static int test_wolfSSL_EVP_MD_size(void)
  52392. {
  52393. EXPECT_DECLS;
  52394. #ifdef OPENSSL_EXTRA
  52395. WOLFSSL_EVP_MD_CTX mdCtx;
  52396. #ifdef WOLFSSL_SHA3
  52397. #ifndef WOLFSSL_NOSHA3_224
  52398. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52399. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_224"), 1);
  52400. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_224_DIGEST_SIZE);
  52401. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_224_BLOCK_SIZE);
  52402. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52403. #endif
  52404. #ifndef WOLFSSL_NOSHA3_256
  52405. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52406. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_256"), 1);
  52407. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_256_DIGEST_SIZE);
  52408. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_256_BLOCK_SIZE);
  52409. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52410. #endif
  52411. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52412. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_384"), 1);
  52413. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_384_DIGEST_SIZE);
  52414. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_384_BLOCK_SIZE);
  52415. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52416. #ifndef WOLFSSL_NOSHA3_512
  52417. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52418. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_512"), 1);
  52419. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_512_DIGEST_SIZE);
  52420. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_512_BLOCK_SIZE);
  52421. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52422. #endif
  52423. #endif /* WOLFSSL_SHA3 */
  52424. #ifndef NO_SHA256
  52425. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52426. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA256"), 1);
  52427. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52428. WC_SHA256_DIGEST_SIZE);
  52429. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52430. WC_SHA256_BLOCK_SIZE);
  52431. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA256_DIGEST_SIZE);
  52432. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA256_BLOCK_SIZE);
  52433. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52434. #endif
  52435. #ifndef NO_MD5
  52436. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52437. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), 1);
  52438. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52439. WC_MD5_DIGEST_SIZE);
  52440. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52441. WC_MD5_BLOCK_SIZE);
  52442. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_MD5_DIGEST_SIZE);
  52443. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_MD5_BLOCK_SIZE);
  52444. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52445. #endif
  52446. #ifdef WOLFSSL_SHA224
  52447. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52448. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA224"), 1);
  52449. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52450. WC_SHA224_DIGEST_SIZE);
  52451. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52452. WC_SHA224_BLOCK_SIZE);
  52453. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA224_DIGEST_SIZE);
  52454. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA224_BLOCK_SIZE);
  52455. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52456. #endif
  52457. #ifdef WOLFSSL_SHA384
  52458. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52459. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA384"), 1);
  52460. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52461. WC_SHA384_DIGEST_SIZE);
  52462. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52463. WC_SHA384_BLOCK_SIZE);
  52464. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA384_DIGEST_SIZE);
  52465. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA384_BLOCK_SIZE);
  52466. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52467. #endif
  52468. #ifdef WOLFSSL_SHA512
  52469. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52470. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA512"), 1);
  52471. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52472. WC_SHA512_DIGEST_SIZE);
  52473. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52474. WC_SHA512_BLOCK_SIZE);
  52475. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA512_DIGEST_SIZE);
  52476. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA512_BLOCK_SIZE);
  52477. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52478. #endif
  52479. #ifndef NO_SHA
  52480. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52481. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA"), 1);
  52482. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52483. WC_SHA_DIGEST_SIZE);
  52484. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52485. WC_SHA_BLOCK_SIZE);
  52486. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52487. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52488. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52489. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52490. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA1"), 1);
  52491. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52492. WC_SHA_DIGEST_SIZE);
  52493. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52494. WC_SHA_BLOCK_SIZE);
  52495. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52496. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52497. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52498. #endif
  52499. /* error case */
  52500. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52501. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, ""), 0);
  52502. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)), 0);
  52503. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), 0);
  52504. /* Cleanup is valid on uninit'ed struct */
  52505. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52506. #endif /* OPENSSL_EXTRA */
  52507. return EXPECT_RESULT();
  52508. }
  52509. static int test_wolfSSL_EVP_MD_pkey_type(void)
  52510. {
  52511. EXPECT_DECLS;
  52512. #ifdef OPENSSL_EXTRA
  52513. const WOLFSSL_EVP_MD* md;
  52514. #ifndef NO_MD5
  52515. ExpectNotNull(md = EVP_md5());
  52516. ExpectIntEQ(EVP_MD_pkey_type(md), NID_md5WithRSAEncryption);
  52517. #endif
  52518. #ifndef NO_SHA
  52519. ExpectNotNull(md = EVP_sha1());
  52520. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha1WithRSAEncryption);
  52521. #endif
  52522. #ifdef WOLFSSL_SHA224
  52523. ExpectNotNull(md = EVP_sha224());
  52524. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha224WithRSAEncryption);
  52525. #endif
  52526. ExpectNotNull(md = EVP_sha256());
  52527. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha256WithRSAEncryption);
  52528. #ifdef WOLFSSL_SHA384
  52529. ExpectNotNull(md = EVP_sha384());
  52530. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha384WithRSAEncryption);
  52531. #endif
  52532. #ifdef WOLFSSL_SHA512
  52533. ExpectNotNull(md = EVP_sha512());
  52534. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha512WithRSAEncryption);
  52535. #endif
  52536. #endif
  52537. return EXPECT_RESULT();
  52538. }
  52539. #ifdef OPENSSL_EXTRA
  52540. static int test_hmac_signing(const WOLFSSL_EVP_MD *type, const byte* testKey,
  52541. size_t testKeySz, const char* testData, size_t testDataSz,
  52542. const byte* testResult, size_t testResultSz)
  52543. {
  52544. EXPECT_DECLS;
  52545. unsigned char check[WC_MAX_DIGEST_SIZE];
  52546. size_t checkSz = -1;
  52547. WOLFSSL_EVP_PKEY* key = NULL;
  52548. WOLFSSL_EVP_MD_CTX mdCtx;
  52549. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  52550. testKey, (int)testKeySz));
  52551. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52552. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  52553. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  52554. (unsigned int)testDataSz), 1);
  52555. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52556. ExpectIntEQ((int)checkSz, (int)testResultSz);
  52557. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52558. ExpectIntEQ((int)checkSz,(int)testResultSz);
  52559. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  52560. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52561. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  52562. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  52563. (unsigned int)testDataSz), 1);
  52564. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  52565. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52566. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52567. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  52568. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  52569. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52570. ExpectIntEQ((int)checkSz, (int)testResultSz);
  52571. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52572. ExpectIntEQ((int)checkSz,(int)testResultSz);
  52573. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  52574. (unsigned int)testDataSz - 4), 1);
  52575. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52576. ExpectIntEQ((int)checkSz,(int)testResultSz);
  52577. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  52578. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52579. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  52580. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  52581. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  52582. (unsigned int)testDataSz - 4), 1);
  52583. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  52584. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52585. wolfSSL_EVP_PKEY_free(key);
  52586. return EXPECT_RESULT();
  52587. }
  52588. #endif
  52589. static int test_wolfSSL_EVP_MD_hmac_signing(void)
  52590. {
  52591. EXPECT_DECLS;
  52592. #ifdef OPENSSL_EXTRA
  52593. static const unsigned char testKey[] =
  52594. {
  52595. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  52596. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  52597. 0x0b, 0x0b, 0x0b, 0x0b
  52598. };
  52599. static const char testData[] = "Hi There";
  52600. #ifdef WOLFSSL_SHA224
  52601. static const unsigned char testResultSha224[] =
  52602. {
  52603. 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
  52604. 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
  52605. 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
  52606. 0x53, 0x68, 0x4b, 0x22
  52607. };
  52608. #endif
  52609. #ifndef NO_SHA256
  52610. static const unsigned char testResultSha256[] =
  52611. {
  52612. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  52613. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  52614. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  52615. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  52616. };
  52617. #endif
  52618. #ifdef WOLFSSL_SHA384
  52619. static const unsigned char testResultSha384[] =
  52620. {
  52621. 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
  52622. 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
  52623. 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
  52624. 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
  52625. 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
  52626. 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
  52627. };
  52628. #endif
  52629. #ifdef WOLFSSL_SHA512
  52630. static const unsigned char testResultSha512[] =
  52631. {
  52632. 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
  52633. 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
  52634. 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
  52635. 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
  52636. 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
  52637. 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
  52638. 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
  52639. 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54
  52640. };
  52641. #endif
  52642. #ifdef WOLFSSL_SHA3
  52643. #ifndef WOLFSSL_NOSHA3_224
  52644. static const unsigned char testResultSha3_224[] =
  52645. {
  52646. 0x3b, 0x16, 0x54, 0x6b, 0xbc, 0x7b, 0xe2, 0x70,
  52647. 0x6a, 0x03, 0x1d, 0xca, 0xfd, 0x56, 0x37, 0x3d,
  52648. 0x98, 0x84, 0x36, 0x76, 0x41, 0xd8, 0xc5, 0x9a,
  52649. 0xf3, 0xc8, 0x60, 0xf7
  52650. };
  52651. #endif
  52652. #ifndef WOLFSSL_NOSHA3_256
  52653. static const unsigned char testResultSha3_256[] =
  52654. {
  52655. 0xba, 0x85, 0x19, 0x23, 0x10, 0xdf, 0xfa, 0x96,
  52656. 0xe2, 0xa3, 0xa4, 0x0e, 0x69, 0x77, 0x43, 0x51,
  52657. 0x14, 0x0b, 0xb7, 0x18, 0x5e, 0x12, 0x02, 0xcd,
  52658. 0xcc, 0x91, 0x75, 0x89, 0xf9, 0x5e, 0x16, 0xbb
  52659. };
  52660. #endif
  52661. #ifndef WOLFSSL_NOSHA3_384
  52662. static const unsigned char testResultSha3_384[] =
  52663. {
  52664. 0x68, 0xd2, 0xdc, 0xf7, 0xfd, 0x4d, 0xdd, 0x0a,
  52665. 0x22, 0x40, 0xc8, 0xa4, 0x37, 0x30, 0x5f, 0x61,
  52666. 0xfb, 0x73, 0x34, 0xcf, 0xb5, 0xd0, 0x22, 0x6e,
  52667. 0x1b, 0xc2, 0x7d, 0xc1, 0x0a, 0x2e, 0x72, 0x3a,
  52668. 0x20, 0xd3, 0x70, 0xb4, 0x77, 0x43, 0x13, 0x0e,
  52669. 0x26, 0xac, 0x7e, 0x3d, 0x53, 0x28, 0x86, 0xbd
  52670. };
  52671. #endif
  52672. #ifndef WOLFSSL_NOSHA3_512
  52673. static const unsigned char testResultSha3_512[] =
  52674. {
  52675. 0xeb, 0x3f, 0xbd, 0x4b, 0x2e, 0xaa, 0xb8, 0xf5,
  52676. 0xc5, 0x04, 0xbd, 0x3a, 0x41, 0x46, 0x5a, 0xac,
  52677. 0xec, 0x15, 0x77, 0x0a, 0x7c, 0xab, 0xac, 0x53,
  52678. 0x1e, 0x48, 0x2f, 0x86, 0x0b, 0x5e, 0xc7, 0xba,
  52679. 0x47, 0xcc, 0xb2, 0xc6, 0xf2, 0xaf, 0xce, 0x8f,
  52680. 0x88, 0xd2, 0x2b, 0x6d, 0xc6, 0x13, 0x80, 0xf2,
  52681. 0x3a, 0x66, 0x8f, 0xd3, 0x88, 0x8b, 0xb8, 0x05,
  52682. 0x37, 0xc0, 0xa0, 0xb8, 0x64, 0x07, 0x68, 0x9e
  52683. };
  52684. #endif
  52685. #endif
  52686. #ifndef NO_SHA256
  52687. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha256(), testKey,
  52688. sizeof(testKey), testData, XSTRLEN(testData), testResultSha256,
  52689. sizeof(testResultSha256)), TEST_SUCCESS);
  52690. #endif
  52691. #ifdef WOLFSSL_SHA224
  52692. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha224(), testKey,
  52693. sizeof(testKey), testData, XSTRLEN(testData), testResultSha224,
  52694. sizeof(testResultSha224)), TEST_SUCCESS);
  52695. #endif
  52696. #ifdef WOLFSSL_SHA384
  52697. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha384(), testKey,
  52698. sizeof(testKey), testData, XSTRLEN(testData), testResultSha384,
  52699. sizeof(testResultSha384)), TEST_SUCCESS);
  52700. #endif
  52701. #ifdef WOLFSSL_SHA512
  52702. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha512(), testKey,
  52703. sizeof(testKey), testData, XSTRLEN(testData), testResultSha512,
  52704. sizeof(testResultSha512)), TEST_SUCCESS);
  52705. #endif
  52706. #ifdef WOLFSSL_SHA3
  52707. #ifndef WOLFSSL_NOSHA3_224
  52708. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_224(), testKey,
  52709. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_224,
  52710. sizeof(testResultSha3_224)), TEST_SUCCESS);
  52711. #endif
  52712. #ifndef WOLFSSL_NOSHA3_256
  52713. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_256(), testKey,
  52714. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_256,
  52715. sizeof(testResultSha3_256)), TEST_SUCCESS);
  52716. #endif
  52717. #ifndef WOLFSSL_NOSHA3_384
  52718. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_384(), testKey,
  52719. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_384,
  52720. sizeof(testResultSha3_384)), TEST_SUCCESS);
  52721. #endif
  52722. #ifndef WOLFSSL_NOSHA3_512
  52723. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_512(), testKey,
  52724. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_512,
  52725. sizeof(testResultSha3_512)), TEST_SUCCESS);
  52726. #endif
  52727. #endif
  52728. #endif /* OPENSSL_EXTRA */
  52729. return EXPECT_RESULT();
  52730. }
  52731. static int test_wolfSSL_EVP_MD_rsa_signing(void)
  52732. {
  52733. EXPECT_DECLS;
  52734. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  52735. WOLFSSL_EVP_PKEY* privKey = NULL;
  52736. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52737. WOLFSSL_EVP_PKEY_CTX* keyCtx = NULL;
  52738. const char testData[] = "Hi There";
  52739. WOLFSSL_EVP_MD_CTX mdCtx;
  52740. WOLFSSL_EVP_MD_CTX mdCtxCopy;
  52741. int ret;
  52742. size_t checkSz = -1;
  52743. int sz = 2048 / 8;
  52744. const unsigned char* cp;
  52745. const unsigned char* p;
  52746. unsigned char check[2048/8];
  52747. size_t i;
  52748. int paddings[] = {
  52749. RSA_PKCS1_PADDING,
  52750. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && defined(WC_RSA_PSS)
  52751. RSA_PKCS1_PSS_PADDING,
  52752. #endif
  52753. };
  52754. cp = client_key_der_2048;
  52755. ExpectNotNull((privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &cp,
  52756. sizeof_client_key_der_2048)));
  52757. p = client_keypub_der_2048;
  52758. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  52759. sizeof_client_keypub_der_2048)));
  52760. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52761. wolfSSL_EVP_MD_CTX_init(&mdCtxCopy);
  52762. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52763. NULL, privKey), 1);
  52764. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  52765. (unsigned int)XSTRLEN(testData)), 1);
  52766. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52767. ExpectIntEQ((int)checkSz, sz);
  52768. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52769. ExpectIntEQ((int)checkSz,sz);
  52770. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  52771. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  52772. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtxCopy);
  52773. ExpectIntEQ(ret, 1);
  52774. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52775. ExpectIntEQ(ret, 1);
  52776. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52777. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52778. NULL, pubKey), 1);
  52779. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  52780. (unsigned int)XSTRLEN(testData)),
  52781. 1);
  52782. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  52783. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52784. ExpectIntEQ(ret, 1);
  52785. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52786. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52787. NULL, privKey), 1);
  52788. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  52789. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52790. ExpectIntEQ((int)checkSz, sz);
  52791. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52792. ExpectIntEQ((int)checkSz, sz);
  52793. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  52794. (unsigned int)XSTRLEN(testData) - 4), 1);
  52795. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52796. ExpectIntEQ((int)checkSz, sz);
  52797. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52798. ExpectIntEQ(ret, 1);
  52799. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52800. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52801. NULL, pubKey), 1);
  52802. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  52803. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  52804. (unsigned int)XSTRLEN(testData) - 4),
  52805. 1);
  52806. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  52807. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52808. ExpectIntEQ(ret, 1);
  52809. /* Check all signing padding types */
  52810. for (i = 0; i < sizeof(paddings)/sizeof(int); i++) {
  52811. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52812. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, &keyCtx,
  52813. wolfSSL_EVP_sha256(), NULL, privKey), 1);
  52814. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  52815. paddings[i]), 1);
  52816. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  52817. (unsigned int)XSTRLEN(testData)), 1);
  52818. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52819. ExpectIntEQ((int)checkSz, sz);
  52820. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52821. ExpectIntEQ((int)checkSz,sz);
  52822. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52823. ExpectIntEQ(ret, 1);
  52824. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52825. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, &keyCtx,
  52826. wolfSSL_EVP_sha256(), NULL, pubKey), 1);
  52827. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  52828. paddings[i]), 1);
  52829. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  52830. (unsigned int)XSTRLEN(testData)), 1);
  52831. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  52832. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52833. ExpectIntEQ(ret, 1);
  52834. }
  52835. wolfSSL_EVP_PKEY_free(pubKey);
  52836. wolfSSL_EVP_PKEY_free(privKey);
  52837. #endif
  52838. return EXPECT_RESULT();
  52839. }
  52840. static int test_wolfSSL_EVP_MD_ecc_signing(void)
  52841. {
  52842. EXPECT_DECLS;
  52843. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  52844. WOLFSSL_EVP_PKEY* privKey = NULL;
  52845. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52846. const char testData[] = "Hi There";
  52847. WOLFSSL_EVP_MD_CTX mdCtx;
  52848. int ret;
  52849. size_t checkSz = -1;
  52850. const unsigned char* cp;
  52851. const unsigned char* p;
  52852. unsigned char check[2048/8];
  52853. cp = ecc_clikey_der_256;
  52854. ExpectNotNull(privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  52855. sizeof_ecc_clikey_der_256));
  52856. p = ecc_clikeypub_der_256;
  52857. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  52858. sizeof_ecc_clikeypub_der_256)));
  52859. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52860. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52861. NULL, privKey), 1);
  52862. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  52863. (unsigned int)XSTRLEN(testData)), 1);
  52864. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52865. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52866. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52867. ExpectIntEQ(ret, 1);
  52868. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52869. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52870. NULL, pubKey), 1);
  52871. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  52872. (unsigned int)XSTRLEN(testData)),
  52873. 1);
  52874. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  52875. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52876. ExpectIntEQ(ret, 1);
  52877. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52878. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52879. NULL, privKey), 1);
  52880. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  52881. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52882. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52883. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  52884. (unsigned int)XSTRLEN(testData) - 4), 1);
  52885. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52886. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52887. ExpectIntEQ(ret, 1);
  52888. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52889. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52890. NULL, pubKey), 1);
  52891. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  52892. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  52893. (unsigned int)XSTRLEN(testData) - 4),
  52894. 1);
  52895. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  52896. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52897. ExpectIntEQ(ret, 1);
  52898. wolfSSL_EVP_PKEY_free(pubKey);
  52899. wolfSSL_EVP_PKEY_free(privKey);
  52900. #endif
  52901. return EXPECT_RESULT();
  52902. }
  52903. static int test_wolfSSL_CTX_add_extra_chain_cert(void)
  52904. {
  52905. EXPECT_DECLS;
  52906. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52907. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO)
  52908. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  52909. char caFile[] = "./certs/client-ca.pem";
  52910. char clientFile[] = "./certs/client-cert.pem";
  52911. SSL_CTX* ctx = NULL;
  52912. X509* x509 = NULL;
  52913. BIO *bio = NULL;
  52914. X509 *cert = NULL;
  52915. X509 *ca = NULL;
  52916. STACK_OF(X509) *chain = NULL;
  52917. STACK_OF(X509) *chain2 = NULL;
  52918. #ifndef NO_WOLFSSL_SERVER
  52919. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52920. #else
  52921. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52922. #endif
  52923. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  52924. WOLFSSL_FILETYPE_PEM));
  52925. /* Negative tests. */
  52926. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52927. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52928. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52929. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  52930. ExpectNotNull(x509 = wolfSSL_X509_new());
  52931. /* Empty certificate. */
  52932. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52933. wolfSSL_X509_free(x509);
  52934. x509 = NULL;
  52935. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  52936. WOLFSSL_FILETYPE_PEM));
  52937. /* additional test of getting EVP_PKEY key size from X509
  52938. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  52939. * allowed with user RSA */
  52940. {
  52941. EVP_PKEY* pkey = NULL;
  52942. #if defined(HAVE_ECC)
  52943. X509* ecX509 = NULL;
  52944. #endif /* HAVE_ECC */
  52945. ExpectNotNull(pkey = X509_get_pubkey(x509));
  52946. /* current RSA key is 2048 bit (256 bytes) */
  52947. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  52948. EVP_PKEY_free(pkey);
  52949. pkey = NULL;
  52950. #if defined(HAVE_ECC)
  52951. #if defined(USE_CERT_BUFFERS_256)
  52952. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  52953. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  52954. SSL_FILETYPE_ASN1));
  52955. #else
  52956. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  52957. cliEccCertFile, SSL_FILETYPE_PEM));
  52958. #endif
  52959. pkey = X509_get_pubkey(ecX509);
  52960. ExpectNotNull(pkey);
  52961. /* current ECC key is 256 bit (32 bytes) */
  52962. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  52963. X509_free(ecX509);
  52964. ecX509 = NULL;
  52965. EVP_PKEY_free(pkey);
  52966. pkey = NULL;
  52967. #endif /* HAVE_ECC */
  52968. }
  52969. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), SSL_SUCCESS);
  52970. if (EXPECT_SUCCESS()) {
  52971. x509 = NULL;
  52972. }
  52973. #ifdef WOLFSSL_ENCRYPTED_KEYS
  52974. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  52975. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  52976. #endif
  52977. SSL_CTX_free(ctx);
  52978. ctx = NULL;
  52979. #ifndef NO_WOLFSSL_SERVER
  52980. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52981. #else
  52982. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52983. #endif
  52984. /* Test haproxy use case */
  52985. ExpectNotNull(bio = BIO_new_file(svrCertFile, "r"));
  52986. /* Read Certificate */
  52987. ExpectNotNull(cert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  52988. ExpectNotNull(ca = PEM_read_bio_X509(bio, NULL, NULL, NULL));
  52989. ExpectNotNull(chain = sk_X509_new_null());
  52990. ExpectIntEQ(sk_X509_push(chain, ca), 1);
  52991. if (EXPECT_SUCCESS()) {
  52992. ca = NULL;
  52993. }
  52994. ExpectNotNull(chain2 = X509_chain_up_ref(chain));
  52995. ExpectNotNull(ca = sk_X509_shift(chain2));
  52996. ExpectIntEQ(SSL_CTX_use_certificate(ctx, cert), 1);
  52997. ExpectIntEQ(SSL_CTX_add_extra_chain_cert(ctx, ca), 1);
  52998. if (EXPECT_SUCCESS()) {
  52999. ca = NULL;
  53000. }
  53001. BIO_free(bio);
  53002. X509_free(cert);
  53003. X509_free(ca);
  53004. X509_free(x509);
  53005. sk_X509_pop_free(chain, X509_free);
  53006. sk_X509_pop_free(chain2, X509_free);
  53007. SSL_CTX_free(ctx);
  53008. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53009. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53010. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined (NO_BIO) */
  53011. return EXPECT_RESULT();
  53012. }
  53013. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  53014. static int test_wolfSSL_ERR_peek_last_error_line(void)
  53015. {
  53016. EXPECT_DECLS;
  53017. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53018. !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL) && \
  53019. !defined(NO_OLD_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  53020. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_ERROR_QUEUE)
  53021. callback_functions client_cb;
  53022. callback_functions server_cb;
  53023. int line = 0;
  53024. int flag = ERR_TXT_STRING;
  53025. const char* file = NULL;
  53026. const char* data = NULL;
  53027. /* create a failed connection and inspect the error */
  53028. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53029. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53030. client_cb.method = wolfTLSv1_1_client_method;
  53031. server_cb.method = wolfTLSv1_2_server_method;
  53032. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53033. ExpectIntGT(ERR_get_error_line_data(NULL, NULL, &data, &flag), 0);
  53034. ExpectNotNull(data);
  53035. /* check clearing error state */
  53036. ERR_remove_state(0);
  53037. ExpectIntEQ((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53038. ERR_peek_last_error_line(NULL, &line);
  53039. ExpectIntEQ(line, 0);
  53040. ERR_peek_last_error_line(&file, NULL);
  53041. ExpectNull(file);
  53042. /* retry connection to fill error queue */
  53043. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53044. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53045. client_cb.method = wolfTLSv1_1_client_method;
  53046. server_cb.method = wolfTLSv1_2_server_method;
  53047. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53048. /* check that error code was stored */
  53049. ExpectIntNE((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53050. ERR_peek_last_error_line(NULL, &line);
  53051. ExpectIntNE(line, 0);
  53052. ERR_peek_last_error_line(&file, NULL);
  53053. ExpectNotNull(file);
  53054. fprintf(stderr, "\nTesting error print out\n");
  53055. ERR_print_errors_fp(stderr);
  53056. fprintf(stderr, "Done testing print out\n\n");
  53057. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  53058. * !defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
  53059. return EXPECT_RESULT();
  53060. }
  53061. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  53062. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53063. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53064. static int verify_cb(int ok, X509_STORE_CTX *ctx)
  53065. {
  53066. (void) ok;
  53067. (void) ctx;
  53068. fprintf(stderr, "ENTER verify_cb\n");
  53069. return SSL_SUCCESS;
  53070. }
  53071. #endif
  53072. static int test_wolfSSL_X509_Name_canon(void)
  53073. {
  53074. EXPECT_DECLS;
  53075. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53076. !defined(NO_FILESYSTEM) && !defined(NO_SHA) && \
  53077. defined(WOLFSSL_CERT_GEN) && \
  53078. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && !defined(NO_RSA)
  53079. const long ex_hash1 = 0x0fdb2da4;
  53080. const long ex_hash2 = 0x9f3e8c9e;
  53081. X509_NAME *name = NULL;
  53082. X509 *x509 = NULL;
  53083. XFILE file = XBADFILE;
  53084. unsigned long hash = 0;
  53085. byte digest[WC_MAX_DIGEST_SIZE] = {0};
  53086. byte *pbuf = NULL;
  53087. word32 len = 0;
  53088. (void) ex_hash2;
  53089. ExpectTrue((file = XFOPEN(caCertFile, "rb")) != XBADFILE);
  53090. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53091. ExpectNotNull(name = X509_get_issuer_name(x509));
  53092. /* When output buffer is NULL, should return necessary output buffer
  53093. * length.*/
  53094. ExpectIntGT(wolfSSL_i2d_X509_NAME_canon(name, NULL), 0);
  53095. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53096. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53097. hash = (((unsigned long)digest[3] << 24) |
  53098. ((unsigned long)digest[2] << 16) |
  53099. ((unsigned long)digest[1] << 8) |
  53100. ((unsigned long)digest[0]));
  53101. ExpectIntEQ(hash, ex_hash1);
  53102. if (file != XBADFILE) {
  53103. XFCLOSE(file);
  53104. file = XBADFILE;
  53105. }
  53106. X509_free(x509);
  53107. x509 = NULL;
  53108. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53109. pbuf = NULL;
  53110. ExpectTrue((file = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  53111. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53112. ExpectNotNull(name = X509_get_issuer_name(x509));
  53113. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53114. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53115. hash = (((unsigned long)digest[3] << 24) |
  53116. ((unsigned long)digest[2] << 16) |
  53117. ((unsigned long)digest[1] << 8) |
  53118. ((unsigned long)digest[0]));
  53119. ExpectIntEQ(hash, ex_hash2);
  53120. if (file != XBADFILE)
  53121. XFCLOSE(file);
  53122. X509_free(x509);
  53123. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53124. #endif
  53125. return EXPECT_RESULT();
  53126. }
  53127. static int test_wolfSSL_X509_LOOKUP_ctrl_hash_dir(void)
  53128. {
  53129. EXPECT_DECLS;
  53130. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  53131. const int MAX_DIR = 4;
  53132. const char paths[][32] = {
  53133. "./certs/ed25519",
  53134. "./certs/ecc",
  53135. "./certs/crl",
  53136. "./certs/",
  53137. };
  53138. char CertCrl_path[MAX_FILENAME_SZ];
  53139. char *p;
  53140. X509_STORE* str = NULL;
  53141. X509_LOOKUP* lookup = NULL;
  53142. WOLFSSL_STACK* sk = NULL;
  53143. int len, total_len, i;
  53144. (void)sk;
  53145. XMEMSET(CertCrl_path, 0, MAX_FILENAME_SZ);
  53146. /* illegal string */
  53147. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53148. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53149. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "",
  53150. SSL_FILETYPE_PEM,NULL), 0);
  53151. /* free store */
  53152. X509_STORE_free(str);
  53153. str = NULL;
  53154. /* short folder string */
  53155. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53156. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53157. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "./",
  53158. SSL_FILETYPE_PEM,NULL), 1);
  53159. #if defined(WOLFSSL_INT_H)
  53160. /* only available when including internal.h */
  53161. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53162. #endif
  53163. /* free store */
  53164. X509_STORE_free(str);
  53165. str = NULL;
  53166. /* typical function check */
  53167. p = &CertCrl_path[0];
  53168. total_len = 0;
  53169. for (i = MAX_DIR - 1; i>=0 && total_len < MAX_FILENAME_SZ; i--) {
  53170. len = (int)XSTRLEN((const char*)&paths[i]);
  53171. total_len += len;
  53172. XSTRNCPY(p, paths[i], MAX_FILENAME_SZ - total_len);
  53173. p += len;
  53174. if (i != 0) *(p++) = SEPARATOR_CHAR;
  53175. }
  53176. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53177. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53178. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, CertCrl_path,
  53179. SSL_FILETYPE_PEM,NULL), 1);
  53180. #if defined(WOLFSSL_INT_H)
  53181. /* only available when including internal.h */
  53182. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53183. #endif
  53184. X509_STORE_free(str);
  53185. #endif
  53186. return EXPECT_RESULT();
  53187. }
  53188. static int test_wolfSSL_X509_LOOKUP_ctrl_file(void)
  53189. {
  53190. EXPECT_DECLS;
  53191. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53192. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  53193. defined(WOLFSSL_SIGNER_DER_CERT)
  53194. X509_STORE_CTX* ctx = NULL;
  53195. X509_STORE* str = NULL;
  53196. X509_LOOKUP* lookup = NULL;
  53197. X509* cert1 = NULL;
  53198. X509* x509Ca = NULL;
  53199. X509* x509Svr = NULL;
  53200. X509* issuer = NULL;
  53201. WOLFSSL_STACK* sk = NULL;
  53202. X509_NAME* caName = NULL;
  53203. X509_NAME* issuerName = NULL;
  53204. XFILE file1 = XBADFILE;
  53205. int i;
  53206. int cert_count = 0;
  53207. int cmp;
  53208. char der[] = "certs/ca-cert.der";
  53209. #ifdef HAVE_CRL
  53210. char pem[][100] = {
  53211. "./certs/crl/crl.pem",
  53212. "./certs/crl/crl2.pem",
  53213. "./certs/crl/caEccCrl.pem",
  53214. "./certs/crl/eccCliCRL.pem",
  53215. "./certs/crl/eccSrvCRL.pem",
  53216. ""
  53217. };
  53218. #endif
  53219. ExpectTrue((file1 = XFOPEN("./certs/ca-cert.pem", "rb")) != XBADFILE);
  53220. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  53221. if (file1 != XBADFILE)
  53222. XFCLOSE(file1);
  53223. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53224. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53225. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53226. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53227. SSL_FILETYPE_PEM,NULL), 1);
  53228. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53229. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53230. /* check if CA cert is loaded into the store */
  53231. for (i = 0; i < cert_count; i++) {
  53232. x509Ca = sk_X509_value(sk, i);
  53233. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53234. }
  53235. ExpectNotNull((x509Svr =
  53236. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53237. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53238. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53239. issuer = X509_STORE_CTX_get0_current_issuer(ctx);
  53240. ExpectNotNull(issuer);
  53241. caName = X509_get_subject_name(x509Ca);
  53242. ExpectNotNull(caName);
  53243. issuerName = X509_get_subject_name(issuer);
  53244. ExpectNotNull(issuerName);
  53245. cmp = X509_NAME_cmp(caName, issuerName);
  53246. ExpectIntEQ(cmp, 0);
  53247. /* load der format */
  53248. X509_free(issuer);
  53249. issuer = NULL;
  53250. X509_STORE_CTX_free(ctx);
  53251. ctx = NULL;
  53252. X509_STORE_free(str);
  53253. str = NULL;
  53254. sk_X509_pop_free(sk, NULL);
  53255. sk = NULL;
  53256. X509_free(x509Svr);
  53257. x509Svr = NULL;
  53258. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53259. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53260. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, der,
  53261. SSL_FILETYPE_ASN1,NULL), 1);
  53262. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53263. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53264. /* check if CA cert is loaded into the store */
  53265. for (i = 0; i < cert_count; i++) {
  53266. x509Ca = sk_X509_value(sk, i);
  53267. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53268. }
  53269. X509_STORE_free(str);
  53270. str = NULL;
  53271. sk_X509_pop_free(sk, NULL);
  53272. sk = NULL;
  53273. X509_free(cert1);
  53274. cert1 = NULL;
  53275. #ifdef HAVE_CRL
  53276. ExpectNotNull(str = wolfSSL_X509_STORE_new());
  53277. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53278. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53279. SSL_FILETYPE_PEM,NULL), 1);
  53280. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD,
  53281. "certs/server-revoked-cert.pem",
  53282. SSL_FILETYPE_PEM,NULL), 1);
  53283. if (str) {
  53284. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm, svrCertFile,
  53285. WOLFSSL_FILETYPE_PEM), 1);
  53286. /* since store hasn't yet known the revoked cert*/
  53287. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53288. "certs/server-revoked-cert.pem",
  53289. WOLFSSL_FILETYPE_PEM), 1);
  53290. }
  53291. for (i = 0; pem[i][0] != '\0'; i++)
  53292. {
  53293. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, pem[i],
  53294. SSL_FILETYPE_PEM, NULL), 1);
  53295. }
  53296. if (str) {
  53297. /* since store knows crl list */
  53298. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53299. "certs/server-revoked-cert.pem",
  53300. WOLFSSL_FILETYPE_PEM ), WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  53301. }
  53302. ExpectIntEQ(X509_LOOKUP_ctrl(NULL, 0, NULL, 0, NULL), 0);
  53303. X509_STORE_free(str);
  53304. #endif
  53305. #endif
  53306. return EXPECT_RESULT();
  53307. }
  53308. static int test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup(void)
  53309. {
  53310. int res = TEST_SKIPPED;
  53311. #if defined(OPENSSL_EXTRA)
  53312. X509_STORE_CTX_cleanup(NULL);
  53313. X509_STORE_CTX_trusted_stack(NULL, NULL);
  53314. res = TEST_SUCCESS;
  53315. #endif
  53316. return res;
  53317. }
  53318. static int test_wolfSSL_X509_STORE_CTX_get0_current_issuer(void)
  53319. {
  53320. EXPECT_DECLS;
  53321. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53322. X509_STORE_CTX* ctx = NULL;
  53323. X509_STORE* str = NULL;
  53324. X509* x509Ca = NULL;
  53325. X509* x509Svr = NULL;
  53326. X509* issuer = NULL;
  53327. X509_NAME* caName = NULL;
  53328. X509_NAME* issuerName = NULL;
  53329. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53330. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53331. ExpectNotNull((x509Ca =
  53332. wolfSSL_X509_load_certificate_file(caCertFile, SSL_FILETYPE_PEM)));
  53333. ExpectIntEQ(X509_STORE_add_cert(str, x509Ca), SSL_SUCCESS);
  53334. ExpectNotNull((x509Svr =
  53335. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53336. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53337. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53338. ExpectNotNull(issuer = X509_STORE_CTX_get0_current_issuer(ctx));
  53339. ExpectNotNull(caName = X509_get_subject_name(x509Ca));
  53340. ExpectNotNull(issuerName = X509_get_subject_name(issuer));
  53341. #ifdef WOLFSSL_SIGNER_DER_CERT
  53342. ExpectIntEQ(X509_NAME_cmp(caName, issuerName), 0);
  53343. #endif
  53344. X509_free(issuer);
  53345. X509_STORE_CTX_free(ctx);
  53346. X509_free(x509Svr);
  53347. X509_STORE_free(str);
  53348. X509_free(x509Ca);
  53349. #endif
  53350. return EXPECT_RESULT();
  53351. }
  53352. static int test_wolfSSL_PKCS7_certs(void)
  53353. {
  53354. EXPECT_DECLS;
  53355. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_BIO) && \
  53356. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7)
  53357. STACK_OF(X509)* sk = NULL;
  53358. STACK_OF(X509_INFO)* info_sk = NULL;
  53359. PKCS7 *p7 = NULL;
  53360. BIO* bio = NULL;
  53361. const byte* p = NULL;
  53362. int buflen = 0;
  53363. int i;
  53364. /* Test twice. Once with d2i and once without to test
  53365. * that everything is free'd correctly. */
  53366. for (i = 0; i < 2; i++) {
  53367. ExpectNotNull(p7 = PKCS7_new());
  53368. if (p7 != NULL) {
  53369. p7->version = 1;
  53370. #ifdef NO_SHA
  53371. p7->hashOID = SHA256h;
  53372. #else
  53373. p7->hashOID = SHAh;
  53374. #endif
  53375. }
  53376. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  53377. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  53378. ExpectNotNull(info_sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  53379. ExpectIntEQ(sk_X509_INFO_num(info_sk), 2);
  53380. ExpectNotNull(sk = sk_X509_new_null());
  53381. while (EXPECT_SUCCESS() && (sk_X509_INFO_num(info_sk) > 0)) {
  53382. X509_INFO* info = NULL;
  53383. ExpectNotNull(info = sk_X509_INFO_shift(info_sk));
  53384. ExpectIntGT(sk_X509_push(sk, info->x509), 0);
  53385. if (EXPECT_SUCCESS() && (info != NULL)) {
  53386. info->x509 = NULL;
  53387. }
  53388. X509_INFO_free(info);
  53389. }
  53390. sk_X509_INFO_pop_free(info_sk, X509_INFO_free);
  53391. info_sk = NULL;
  53392. BIO_free(bio);
  53393. bio = NULL;
  53394. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  53395. ExpectIntEQ(wolfSSL_PKCS7_encode_certs(p7, sk, bio), 1);
  53396. if ((sk != NULL) && ((p7 == NULL) || (bio == NULL))) {
  53397. sk_X509_pop_free(sk, X509_free);
  53398. }
  53399. sk = NULL;
  53400. ExpectIntGT((buflen = BIO_get_mem_data(bio, &p)), 0);
  53401. if (i == 0) {
  53402. PKCS7_free(p7);
  53403. p7 = NULL;
  53404. ExpectNotNull(d2i_PKCS7(&p7, &p, buflen));
  53405. if (p7 != NULL) {
  53406. /* Reset certs to force wolfSSL_PKCS7_to_stack to regenerate
  53407. * them */
  53408. ((WOLFSSL_PKCS7*)p7)->certs = NULL;
  53409. }
  53410. /* PKCS7_free free's the certs */
  53411. ExpectNotNull(wolfSSL_PKCS7_to_stack(p7));
  53412. }
  53413. BIO_free(bio);
  53414. bio = NULL;
  53415. PKCS7_free(p7);
  53416. p7 = NULL;
  53417. }
  53418. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53419. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7) */
  53420. return EXPECT_RESULT();
  53421. }
  53422. static int test_wolfSSL_X509_STORE_CTX(void)
  53423. {
  53424. EXPECT_DECLS;
  53425. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53426. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53427. X509_STORE_CTX* ctx = NULL;
  53428. X509_STORE* str = NULL;
  53429. X509* x509 = NULL;
  53430. #ifdef OPENSSL_ALL
  53431. X509* x5092 = NULL;
  53432. STACK_OF(X509) *sk = NULL;
  53433. STACK_OF(X509) *sk2 = NULL;
  53434. STACK_OF(X509) *sk3 = NULL;
  53435. #endif
  53436. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53437. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53438. ExpectNotNull((x509 =
  53439. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53440. ExpectIntEQ(X509_STORE_add_cert(str, x509), SSL_SUCCESS);
  53441. #ifdef OPENSSL_ALL
  53442. /* sk_X509_new only in OPENSSL_ALL */
  53443. sk = sk_X509_new_null();
  53444. ExpectNotNull(sk);
  53445. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, sk), SSL_SUCCESS);
  53446. #else
  53447. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, NULL), SSL_SUCCESS);
  53448. #endif
  53449. ExpectIntEQ(SSL_get_ex_data_X509_STORE_CTX_idx(), 0);
  53450. X509_STORE_CTX_set_error(ctx, -5);
  53451. X509_STORE_CTX_set_error(NULL, -5);
  53452. X509_STORE_CTX_free(ctx);
  53453. ctx = NULL;
  53454. #ifdef OPENSSL_ALL
  53455. sk_X509_pop_free(sk, NULL);
  53456. sk = NULL;
  53457. #endif
  53458. X509_STORE_free(str);
  53459. str = NULL;
  53460. X509_free(x509);
  53461. x509 = NULL;
  53462. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53463. X509_STORE_CTX_set_verify_cb(ctx, verify_cb);
  53464. X509_STORE_CTX_free(ctx);
  53465. ctx = NULL;
  53466. #ifdef OPENSSL_ALL
  53467. /* test X509_STORE_CTX_get(1)_chain */
  53468. ExpectNotNull((x509 = X509_load_certificate_file(svrCertFile,
  53469. SSL_FILETYPE_PEM)));
  53470. ExpectNotNull((x5092 = X509_load_certificate_file(cliCertFile,
  53471. SSL_FILETYPE_PEM)));
  53472. ExpectNotNull((sk = sk_X509_new_null()));
  53473. ExpectIntEQ(sk_X509_push(sk, x509), 1);
  53474. if (EXPECT_FAIL()) {
  53475. X509_free(x509);
  53476. x509 = NULL;
  53477. }
  53478. ExpectNotNull((str = X509_STORE_new()));
  53479. ExpectNotNull((ctx = X509_STORE_CTX_new()));
  53480. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x5092, sk), 1);
  53481. ExpectNull((sk2 = X509_STORE_CTX_get_chain(NULL)));
  53482. ExpectNotNull((sk2 = X509_STORE_CTX_get_chain(ctx)));
  53483. ExpectIntEQ(sk_num(sk2), 1); /* sanity, make sure chain has 1 cert */
  53484. ExpectNull((sk3 = X509_STORE_CTX_get1_chain(NULL)));
  53485. ExpectNotNull((sk3 = X509_STORE_CTX_get1_chain(ctx)));
  53486. ExpectIntEQ(sk_num(sk3), 1); /* sanity, make sure chain has 1 cert */
  53487. X509_STORE_CTX_free(ctx);
  53488. ctx = NULL;
  53489. X509_STORE_free(str);
  53490. str = NULL;
  53491. /* CTX certs not freed yet */
  53492. X509_free(x5092);
  53493. x5092 = NULL;
  53494. sk_X509_pop_free(sk, NULL);
  53495. sk = NULL;
  53496. /* sk3 is dup so free here */
  53497. sk_X509_pop_free(sk3, NULL);
  53498. sk3 = NULL;
  53499. #endif
  53500. /* test X509_STORE_CTX_get/set_ex_data */
  53501. {
  53502. int i = 0, tmpData = 5;
  53503. void* tmpDataRet;
  53504. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53505. #ifdef HAVE_EX_DATA
  53506. for (i = 0; i < MAX_EX_DATA; i++) {
  53507. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53508. WOLFSSL_SUCCESS);
  53509. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53510. ExpectNotNull(tmpDataRet);
  53511. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  53512. }
  53513. #else
  53514. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53515. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53516. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53517. ExpectNull(tmpDataRet);
  53518. #endif
  53519. X509_STORE_CTX_free(ctx);
  53520. ctx = NULL;
  53521. }
  53522. /* test X509_STORE_get/set_ex_data */
  53523. {
  53524. int i = 0, tmpData = 99;
  53525. void* tmpDataRet;
  53526. ExpectNotNull(str = X509_STORE_new());
  53527. #ifdef HAVE_EX_DATA
  53528. for (i = 0; i < MAX_EX_DATA; i++) {
  53529. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  53530. WOLFSSL_SUCCESS);
  53531. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  53532. ExpectNotNull(tmpDataRet);
  53533. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  53534. }
  53535. #else
  53536. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  53537. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53538. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  53539. ExpectNull(tmpDataRet);
  53540. #endif
  53541. X509_STORE_free(str);
  53542. str = NULL;
  53543. }
  53544. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53545. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  53546. return EXPECT_RESULT();
  53547. }
  53548. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53549. static int test_X509_STORE_untrusted_load_cert_to_stack(const char* filename,
  53550. STACK_OF(X509)* chain)
  53551. {
  53552. EXPECT_DECLS;
  53553. XFILE fp = XBADFILE;
  53554. X509* cert = NULL;
  53555. ExpectTrue((fp = XFOPEN(filename, "rb"))
  53556. != XBADFILE);
  53557. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  53558. if (fp != XBADFILE) {
  53559. XFCLOSE(fp);
  53560. fp = XBADFILE;
  53561. }
  53562. ExpectIntGT(sk_X509_push(chain, cert), 0);
  53563. if (EXPECT_FAIL())
  53564. X509_free(cert);
  53565. return EXPECT_RESULT();
  53566. }
  53567. static int test_X509_STORE_untrusted_certs(const char** filenames, int ret,
  53568. int err, int loadCA)
  53569. {
  53570. EXPECT_DECLS;
  53571. X509_STORE_CTX* ctx = NULL;
  53572. X509_STORE* str = NULL;
  53573. XFILE fp = XBADFILE;
  53574. X509* cert = NULL;
  53575. STACK_OF(X509)* untrusted = NULL;
  53576. ExpectTrue((fp = XFOPEN("./certs/intermediate/server-int-cert.pem", "rb"))
  53577. != XBADFILE);
  53578. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  53579. if (fp != XBADFILE) {
  53580. XFCLOSE(fp);
  53581. fp = XBADFILE;
  53582. }
  53583. ExpectNotNull(str = X509_STORE_new());
  53584. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53585. ExpectNotNull(untrusted = sk_X509_new_null());
  53586. ExpectIntEQ(X509_STORE_set_flags(str, 0), 1);
  53587. if (loadCA) {
  53588. ExpectIntEQ(X509_STORE_load_locations(str, "./certs/ca-cert.pem", NULL),
  53589. 1);
  53590. }
  53591. for (; *filenames; filenames++) {
  53592. ExpectIntEQ(test_X509_STORE_untrusted_load_cert_to_stack(*filenames,
  53593. untrusted), TEST_SUCCESS);
  53594. }
  53595. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, cert, untrusted), 1);
  53596. ExpectIntEQ(X509_verify_cert(ctx), ret);
  53597. ExpectIntEQ(X509_STORE_CTX_get_error(ctx), err);
  53598. X509_free(cert);
  53599. X509_STORE_free(str);
  53600. X509_STORE_CTX_free(ctx);
  53601. sk_X509_pop_free(untrusted, NULL);
  53602. return EXPECT_RESULT();
  53603. }
  53604. #endif
  53605. static int test_X509_STORE_untrusted(void)
  53606. {
  53607. EXPECT_DECLS;
  53608. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53609. const char* untrusted1[] = {
  53610. "./certs/intermediate/ca-int2-cert.pem",
  53611. NULL
  53612. };
  53613. const char* untrusted2[] = {
  53614. "./certs/intermediate/ca-int-cert.pem",
  53615. "./certs/intermediate/ca-int2-cert.pem",
  53616. NULL
  53617. };
  53618. const char* untrusted3[] = {
  53619. "./certs/intermediate/ca-int-cert.pem",
  53620. "./certs/intermediate/ca-int2-cert.pem",
  53621. "./certs/ca-cert.pem",
  53622. NULL
  53623. };
  53624. /* Adding unrelated certs that should be ignored */
  53625. const char* untrusted4[] = {
  53626. "./certs/client-ca.pem",
  53627. "./certs/intermediate/ca-int-cert.pem",
  53628. "./certs/server-cert.pem",
  53629. "./certs/intermediate/ca-int2-cert.pem",
  53630. NULL
  53631. };
  53632. /* Only immediate issuer in untrusted chain. Fails since can't build chain
  53633. * to loaded CA. */
  53634. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted1, 0,
  53635. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 1), TEST_SUCCESS);
  53636. /* Succeeds because path to loaded CA is available. */
  53637. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted2, 1, 0, 1),
  53638. TEST_SUCCESS);
  53639. /* Fails because root CA is in the untrusted stack */
  53640. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 0,
  53641. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 0), TEST_SUCCESS);
  53642. /* Succeeds because path to loaded CA is available. */
  53643. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted4, 1, 0, 1),
  53644. TEST_SUCCESS);
  53645. #endif
  53646. return EXPECT_RESULT();
  53647. }
  53648. static int test_wolfSSL_X509_STORE_set_flags(void)
  53649. {
  53650. EXPECT_DECLS;
  53651. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53652. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53653. X509_STORE* store = NULL;
  53654. X509* x509 = NULL;
  53655. ExpectNotNull((store = wolfSSL_X509_STORE_new()));
  53656. ExpectNotNull((x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  53657. WOLFSSL_FILETYPE_PEM)));
  53658. ExpectIntEQ(X509_STORE_add_cert(store, x509), WOLFSSL_SUCCESS);
  53659. #ifdef HAVE_CRL
  53660. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  53661. WOLFSSL_SUCCESS);
  53662. #else
  53663. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  53664. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  53665. #endif
  53666. wolfSSL_X509_free(x509);
  53667. wolfSSL_X509_STORE_free(store);
  53668. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  53669. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  53670. return EXPECT_RESULT();
  53671. }
  53672. static int test_wolfSSL_X509_LOOKUP_load_file(void)
  53673. {
  53674. EXPECT_DECLS;
  53675. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && \
  53676. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  53677. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  53678. WOLFSSL_X509_STORE* store = NULL;
  53679. WOLFSSL_X509_LOOKUP* lookup = NULL;
  53680. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  53681. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  53682. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/client-ca.pem",
  53683. X509_FILETYPE_PEM), 1);
  53684. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/crl/crl2.pem",
  53685. X509_FILETYPE_PEM), 1);
  53686. if (store != NULL) {
  53687. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, cliCertFile,
  53688. WOLFSSL_FILETYPE_PEM), 1);
  53689. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  53690. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  53691. }
  53692. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  53693. X509_FILETYPE_PEM), 1);
  53694. if (store != NULL) {
  53695. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  53696. WOLFSSL_FILETYPE_PEM), 1);
  53697. }
  53698. wolfSSL_X509_STORE_free(store);
  53699. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_CRL) &&
  53700. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  53701. return EXPECT_RESULT();
  53702. }
  53703. static int test_wolfSSL_X509_STORE_CTX_set_time(void)
  53704. {
  53705. EXPECT_DECLS;
  53706. #if defined(OPENSSL_EXTRA)
  53707. WOLFSSL_X509_STORE_CTX* ctx = NULL;
  53708. time_t c_time;
  53709. ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new());
  53710. c_time = 365*24*60*60;
  53711. wolfSSL_X509_STORE_CTX_set_time(ctx, 0, c_time);
  53712. ExpectTrue((ctx->param->flags & WOLFSSL_USE_CHECK_TIME) ==
  53713. WOLFSSL_USE_CHECK_TIME);
  53714. ExpectTrue(ctx->param->check_time == c_time);
  53715. wolfSSL_X509_STORE_CTX_free(ctx);
  53716. #endif /* OPENSSL_EXTRA */
  53717. return EXPECT_RESULT();
  53718. }
  53719. static int test_wolfSSL_CTX_get0_set1_param(void)
  53720. {
  53721. EXPECT_DECLS;
  53722. #if defined(OPENSSL_EXTRA)
  53723. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53724. SSL_CTX* ctx = NULL;
  53725. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  53726. WOLFSSL_X509_VERIFY_PARAM* pvpm = NULL;
  53727. char testIPv4[] = "127.0.0.1";
  53728. char testhostName[] = "foo.hoge.com";
  53729. #ifndef NO_WOLFSSL_SERVER
  53730. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53731. #else
  53732. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53733. #endif
  53734. ExpectNull(SSL_CTX_get0_param(NULL));
  53735. ExpectNotNull(pParam = SSL_CTX_get0_param(ctx));
  53736. ExpectNotNull(pvpm = (WOLFSSL_X509_VERIFY_PARAM *)XMALLOC(
  53737. sizeof(WOLFSSL_X509_VERIFY_PARAM), NULL, DYNAMIC_TYPE_OPENSSL));
  53738. ExpectNotNull(XMEMSET(pvpm, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM)));
  53739. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(pvpm, testhostName,
  53740. (int)XSTRLEN(testhostName)), WOLFSSL_SUCCESS);
  53741. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(pvpm, testIPv4),
  53742. WOLFSSL_SUCCESS);
  53743. wolfSSL_X509_VERIFY_PARAM_set_hostflags(pvpm, 0x01);
  53744. ExpectIntEQ(SSL_CTX_set1_param(ctx, pvpm), 1);
  53745. ExpectIntEQ(0, XSTRNCMP(pParam->hostName, testhostName,
  53746. (int)XSTRLEN(testhostName)));
  53747. ExpectIntEQ(0x01, pParam->hostFlags);
  53748. ExpectIntEQ(0, XSTRNCMP(pParam->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  53749. /* test for incorrect parameter */
  53750. ExpectIntEQ(1,SSL_CTX_set1_param(ctx, NULL));
  53751. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, pvpm));
  53752. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, NULL));
  53753. SSL_CTX_free(ctx);
  53754. XFREE(pvpm, NULL, DYNAMIC_TYPE_OPENSSL);
  53755. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53756. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  53757. return EXPECT_RESULT();
  53758. }
  53759. static int test_wolfSSL_get0_param(void)
  53760. {
  53761. EXPECT_DECLS;
  53762. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53763. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53764. SSL_CTX* ctx = NULL;
  53765. SSL* ssl = NULL;
  53766. #ifndef NO_WOLFSSL_SERVER
  53767. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53768. #else
  53769. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53770. #endif
  53771. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  53772. SSL_FILETYPE_PEM));
  53773. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  53774. ExpectNotNull(ssl = SSL_new(ctx));
  53775. ExpectNotNull(SSL_get0_param(ssl));
  53776. SSL_free(ssl);
  53777. SSL_CTX_free(ctx);
  53778. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53779. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  53780. return EXPECT_RESULT();
  53781. }
  53782. static int test_wolfSSL_X509_VERIFY_PARAM_set1_host(void)
  53783. {
  53784. EXPECT_DECLS;
  53785. #if defined(OPENSSL_EXTRA)
  53786. const char host[] = "www.example.com";
  53787. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  53788. ExpectNotNull(pParam = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
  53789. sizeof(WOLFSSL_X509_VERIFY_PARAM), HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  53790. if (pParam != NULL) {
  53791. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  53792. X509_VERIFY_PARAM_set1_host(pParam, host, sizeof(host));
  53793. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  53794. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  53795. ExpectIntNE(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  53796. XFREE(pParam, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  53797. }
  53798. #endif /* OPENSSL_EXTRA */
  53799. return EXPECT_RESULT();
  53800. }
  53801. static int test_wolfSSL_set1_host(void)
  53802. {
  53803. EXPECT_DECLS;
  53804. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53805. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53806. const char host[] = "www.test_wolfSSL_set1_host.com";
  53807. const char emptyStr[] = "";
  53808. SSL_CTX* ctx = NULL;
  53809. SSL* ssl = NULL;
  53810. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  53811. #ifndef NO_WOLFSSL_SERVER
  53812. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53813. #else
  53814. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53815. #endif
  53816. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  53817. SSL_FILETYPE_PEM));
  53818. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  53819. ExpectNotNull(ssl = SSL_new(ctx));
  53820. pParam = SSL_get0_param(ssl);
  53821. /* we should get back host string */
  53822. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  53823. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  53824. /* we should get back empty string */
  53825. ExpectIntEQ(SSL_set1_host(ssl, emptyStr), WOLFSSL_SUCCESS);
  53826. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  53827. /* we should get back host string */
  53828. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  53829. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  53830. /* we should get back empty string */
  53831. ExpectIntEQ(SSL_set1_host(ssl, NULL), WOLFSSL_SUCCESS);
  53832. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  53833. SSL_free(ssl);
  53834. SSL_CTX_free(ctx);
  53835. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53836. #endif /* OPENSSL_EXTRA */
  53837. return EXPECT_RESULT();
  53838. }
  53839. static int test_wolfSSL_X509_VERIFY_PARAM_set1_ip(void)
  53840. {
  53841. EXPECT_DECLS;
  53842. #if defined(OPENSSL_EXTRA)
  53843. unsigned char buf[16] = {0};
  53844. WOLFSSL_X509_VERIFY_PARAM* param = NULL;
  53845. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  53846. /* test 127.0.0.1 */
  53847. buf[0] =0x7f; buf[1] = 0; buf[2] = 0; buf[3] = 1;
  53848. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 4), SSL_SUCCESS);
  53849. ExpectIntEQ(XSTRNCMP(param->ipasc, "127.0.0.1", sizeof(param->ipasc)), 0);
  53850. /* test 2001:db8:3333:4444:5555:6666:7777:8888 */
  53851. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  53852. buf[4]=51;buf[5]=51;buf[6]=68;buf[7]=68;
  53853. buf[8]=85;buf[9]=85;buf[10]=102;buf[11]=102;
  53854. buf[12]=119;buf[13]=119;buf[14]=136;buf[15]=136;
  53855. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  53856. ExpectIntEQ(XSTRNCMP(param->ipasc,
  53857. "2001:db8:3333:4444:5555:6666:7777:8888", sizeof(param->ipasc)), 0);
  53858. /* test 2001:db8:: */
  53859. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  53860. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  53861. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  53862. buf[12]=0;buf[13]=0;buf[14]=0;buf[15]=0;
  53863. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  53864. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::", sizeof(param->ipasc)), 0);
  53865. /* test ::1234:5678 */
  53866. buf[0]=0;buf[1]=0;buf[2]=0;buf[3]=0;
  53867. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  53868. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  53869. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  53870. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  53871. ExpectIntEQ(XSTRNCMP(param->ipasc, "::1234:5678", sizeof(param->ipasc)), 0);
  53872. /* test 2001:db8::1234:5678 */
  53873. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  53874. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  53875. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  53876. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  53877. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  53878. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::1234:5678",
  53879. sizeof(param->ipasc)), 0);
  53880. /* test 2001:0db8:0001:0000:0000:0ab9:c0a8:0102*/
  53881. /* 2001:db8:1::ab9:c0a8:102 */
  53882. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  53883. buf[4]=0;buf[5]=1;buf[6]=0;buf[7]=0;
  53884. buf[8]=0;buf[9]=0;buf[10]=10;buf[11]=185;
  53885. buf[12]=192;buf[13]=168;buf[14]=1;buf[15]=2;
  53886. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  53887. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8:1::ab9:c0a8:102",
  53888. sizeof(param->ipasc)), 0);
  53889. XFREE(param, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  53890. #endif /* OPENSSL_EXTRA */
  53891. return EXPECT_RESULT();
  53892. }
  53893. static int test_wolfSSL_X509_STORE_CTX_get0_store(void)
  53894. {
  53895. EXPECT_DECLS;
  53896. #if defined(OPENSSL_EXTRA)
  53897. X509_STORE* store = NULL;
  53898. X509_STORE_CTX* ctx = NULL;
  53899. X509_STORE_CTX* ctx_no_init = NULL;
  53900. ExpectNotNull((store = X509_STORE_new()));
  53901. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53902. ExpectNotNull(ctx_no_init = X509_STORE_CTX_new());
  53903. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, NULL, NULL), SSL_SUCCESS);
  53904. ExpectNull(X509_STORE_CTX_get0_store(NULL));
  53905. /* should return NULL if ctx has not bee initialized */
  53906. ExpectNull(X509_STORE_CTX_get0_store(ctx_no_init));
  53907. ExpectNotNull(X509_STORE_CTX_get0_store(ctx));
  53908. wolfSSL_X509_STORE_CTX_free(ctx);
  53909. wolfSSL_X509_STORE_CTX_free(ctx_no_init);
  53910. X509_STORE_free(store);
  53911. #endif /* OPENSSL_EXTRA */
  53912. return EXPECT_RESULT();
  53913. }
  53914. static int test_wolfSSL_CTX_set_client_CA_list(void)
  53915. {
  53916. EXPECT_DECLS;
  53917. #if defined(OPENSSL_ALL) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  53918. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_BIO)
  53919. WOLFSSL_CTX* ctx = NULL;
  53920. WOLFSSL* ssl = NULL;
  53921. X509_NAME* name = NULL;
  53922. STACK_OF(X509_NAME)* names = NULL;
  53923. STACK_OF(X509_NAME)* ca_list = NULL;
  53924. int names_len = 0;
  53925. int i;
  53926. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  53927. /* Send two X501 names in cert request */
  53928. names = SSL_load_client_CA_file(cliCertFile);
  53929. ExpectNotNull(names);
  53930. ca_list = SSL_load_client_CA_file(caCertFile);
  53931. ExpectNotNull(ca_list);
  53932. ExpectNotNull(name = sk_X509_NAME_value(ca_list, 0));
  53933. ExpectIntEQ(sk_X509_NAME_push(names, name), 2);
  53934. if (EXPECT_FAIL()) {
  53935. wolfSSL_X509_NAME_free(name);
  53936. name = NULL;
  53937. }
  53938. SSL_CTX_set_client_CA_list(ctx, names);
  53939. /* This should only free the stack structure */
  53940. sk_X509_NAME_free(ca_list);
  53941. ca_list = NULL;
  53942. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  53943. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  53944. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  53945. for (i = 0; i < names_len; i++) {
  53946. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  53947. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  53948. }
  53949. /* Needed to be able to create ssl object */
  53950. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  53951. SSL_FILETYPE_PEM));
  53952. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  53953. ExpectNotNull(ssl = wolfSSL_new(ctx));
  53954. /* load again as old names are responsibility of ctx to free*/
  53955. names = SSL_load_client_CA_file(cliCertFile);
  53956. ExpectNotNull(names);
  53957. SSL_set_client_CA_list(ssl, names);
  53958. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl));
  53959. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  53960. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  53961. for (i = 0; i < names_len; i++) {
  53962. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  53963. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  53964. }
  53965. #if !defined(SINGLE_THREADED) && defined(SESSION_CERTS)
  53966. {
  53967. tcp_ready ready;
  53968. func_args server_args;
  53969. callback_functions server_cb;
  53970. THREAD_TYPE serverThread;
  53971. WOLFSSL* ssl_client = NULL;
  53972. WOLFSSL_CTX* ctx_client = NULL;
  53973. SOCKET_T sockfd = 0;
  53974. /* wolfSSL_get_client_CA_list() with handshake */
  53975. StartTCP();
  53976. InitTcpReady(&ready);
  53977. XMEMSET(&server_args, 0, sizeof(func_args));
  53978. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53979. server_args.signal = &ready;
  53980. server_args.callbacks = &server_cb;
  53981. /* we are responsible for free'ing WOLFSSL_CTX */
  53982. server_cb.ctx = ctx;
  53983. server_cb.isSharedCtx = 1;
  53984. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  53985. cliCertFile, 0));
  53986. start_thread(test_server_nofail, &server_args, &serverThread);
  53987. wait_tcp_ready(&server_args);
  53988. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  53989. ExpectNotNull(ctx_client =
  53990. wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  53991. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
  53992. ctx_client, caCertFile, 0));
  53993. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(
  53994. ctx_client, cliCertFile, SSL_FILETYPE_PEM));
  53995. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(
  53996. ctx_client, cliKeyFile, SSL_FILETYPE_PEM));
  53997. ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
  53998. ExpectIntEQ(wolfSSL_set_fd(ssl_client, sockfd), WOLFSSL_SUCCESS);
  53999. ExpectIntEQ(wolfSSL_connect(ssl_client), WOLFSSL_SUCCESS);
  54000. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl_client));
  54001. /* We are expecting two cert names to be sent */
  54002. ExpectIntEQ(sk_X509_NAME_num(ca_list), 2);
  54003. ExpectNotNull(names = SSL_CTX_get_client_CA_list(ctx));
  54004. for (i=0; i<sk_X509_NAME_num(ca_list); i++) {
  54005. ExpectNotNull(name = sk_X509_NAME_value(ca_list, i));
  54006. ExpectIntGE(sk_X509_NAME_find(names, name), 0);
  54007. }
  54008. wolfSSL_shutdown(ssl_client);
  54009. wolfSSL_free(ssl_client);
  54010. wolfSSL_CTX_free(ctx_client);
  54011. CloseSocket(sockfd);
  54012. join_thread(serverThread);
  54013. FreeTcpReady(&ready);
  54014. }
  54015. #endif
  54016. wolfSSL_free(ssl);
  54017. wolfSSL_CTX_free(ctx);
  54018. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT &&
  54019. * !NO_BIO */
  54020. return EXPECT_RESULT();
  54021. }
  54022. static int test_wolfSSL_CTX_add_client_CA(void)
  54023. {
  54024. EXPECT_DECLS;
  54025. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  54026. !defined(NO_WOLFSSL_CLIENT)
  54027. WOLFSSL_CTX* ctx = NULL;
  54028. WOLFSSL_X509* x509 = NULL;
  54029. WOLFSSL_X509* x509_a = NULL;
  54030. STACK_OF(X509_NAME)* ca_list = NULL;
  54031. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54032. /* Add client cert */
  54033. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  54034. SSL_FILETYPE_PEM));
  54035. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509), SSL_SUCCESS);
  54036. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  54037. /* Add another client cert */
  54038. ExpectNotNull(x509_a = X509_load_certificate_file(cliCertFile,
  54039. SSL_FILETYPE_PEM));
  54040. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509_a), SSL_SUCCESS);
  54041. /* test for incorrect parameter */
  54042. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, x509), 0);
  54043. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, NULL), 0);
  54044. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, NULL), 0);
  54045. X509_free(x509);
  54046. X509_free(x509_a);
  54047. SSL_CTX_free(ctx);
  54048. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT */
  54049. return EXPECT_RESULT();
  54050. }
  54051. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54052. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54053. static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
  54054. {
  54055. callback_functions* callbacks = ((func_args*)args)->callbacks;
  54056. WOLFSSL_CTX* ctx = callbacks->ctx;
  54057. WOLFSSL* ssl = NULL;
  54058. SOCKET_T sfd = 0;
  54059. SOCKET_T cfd = 0;
  54060. word16 port;
  54061. char input[1024];
  54062. int idx;
  54063. int ret, err = 0;
  54064. const char* privateName = "ech-private-name.com";
  54065. int privateNameLen = (int)XSTRLEN(privateName);
  54066. ((func_args*)args)->return_code = TEST_FAIL;
  54067. port = ((func_args*)args)->signal->port;
  54068. AssertIntEQ(WOLFSSL_SUCCESS,
  54069. wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0));
  54070. AssertIntEQ(WOLFSSL_SUCCESS,
  54071. wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  54072. WOLFSSL_FILETYPE_PEM));
  54073. AssertIntEQ(WOLFSSL_SUCCESS,
  54074. wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  54075. WOLFSSL_FILETYPE_PEM));
  54076. if (callbacks->ctx_ready)
  54077. callbacks->ctx_ready(ctx);
  54078. ssl = wolfSSL_new(ctx);
  54079. /* set the sni for the server */
  54080. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, privateName, privateNameLen);
  54081. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, NULL, NULL);
  54082. CloseSocket(sfd);
  54083. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  54084. if (callbacks->ssl_ready)
  54085. callbacks->ssl_ready(ssl);
  54086. do {
  54087. err = 0; /* Reset error */
  54088. ret = wolfSSL_accept(ssl);
  54089. if (ret != WOLFSSL_SUCCESS) {
  54090. err = wolfSSL_get_error(ssl, 0);
  54091. }
  54092. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  54093. if (ret != WOLFSSL_SUCCESS) {
  54094. char buff[WOLFSSL_MAX_ERROR_SZ];
  54095. fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_error_string(err, buff));
  54096. }
  54097. else {
  54098. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  54099. input[idx] = 0;
  54100. fprintf(stderr, "Client message: %s\n", input);
  54101. }
  54102. AssertIntEQ(privateNameLen, wolfSSL_write(ssl, privateName,
  54103. privateNameLen));
  54104. ((func_args*)args)->return_code = TEST_SUCCESS;
  54105. }
  54106. if (callbacks->on_result)
  54107. callbacks->on_result(ssl);
  54108. wolfSSL_shutdown(ssl);
  54109. wolfSSL_free(ssl);
  54110. wolfSSL_CTX_free(ctx);
  54111. CloseSocket(cfd);
  54112. #ifdef FP_ECC
  54113. wc_ecc_fp_free();
  54114. #endif
  54115. WOLFSSL_RETURN_FROM_THREAD(0);
  54116. }
  54117. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54118. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54119. static void keyLog_callback(const WOLFSSL* ssl, const char* line)
  54120. {
  54121. XFILE fp;
  54122. const byte lf = '\n';
  54123. AssertNotNull(ssl);
  54124. AssertNotNull(line);
  54125. fp = XFOPEN("./MyKeyLog.txt", "a");
  54126. XFWRITE(line, 1, XSTRLEN(line), fp);
  54127. XFWRITE((void*)&lf, 1, 1, fp);
  54128. XFFLUSH(fp);
  54129. XFCLOSE(fp);
  54130. }
  54131. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54132. static int test_wolfSSL_CTX_set_keylog_callback(void)
  54133. {
  54134. EXPECT_DECLS;
  54135. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54136. !defined(NO_WOLFSSL_CLIENT)
  54137. SSL_CTX* ctx = NULL;
  54138. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54139. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54140. SSL_CTX_free(ctx);
  54141. SSL_CTX_set_keylog_callback(NULL, NULL);
  54142. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54143. return EXPECT_RESULT();
  54144. }
  54145. static int test_wolfSSL_CTX_get_keylog_callback(void)
  54146. {
  54147. EXPECT_DECLS;
  54148. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54149. !defined(NO_WOLFSSL_CLIENT)
  54150. SSL_CTX* ctx = NULL;
  54151. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54152. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54153. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54154. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),keyLog_callback);
  54155. SSL_CTX_set_keylog_callback(ctx, NULL );
  54156. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54157. SSL_CTX_free(ctx);
  54158. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54159. return EXPECT_RESULT();
  54160. }
  54161. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54162. static int test_wolfSSL_Tls12_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54163. {
  54164. /* set keylog callback */
  54165. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54166. return TEST_SUCCESS;
  54167. }
  54168. #endif
  54169. static int test_wolfSSL_Tls12_Key_Logging_test(void)
  54170. {
  54171. EXPECT_DECLS;
  54172. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54173. /* This test is intended for checking whether keylog callback is called
  54174. * in client during TLS handshake between the client and a server.
  54175. */
  54176. test_ssl_cbf server_cbf;
  54177. test_ssl_cbf client_cbf;
  54178. XFILE fp = XBADFILE;
  54179. char buff[500];
  54180. int found = 0;
  54181. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54182. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54183. server_cbf.method = wolfTLSv1_2_server_method;
  54184. client_cbf.ctx_ready = &test_wolfSSL_Tls12_Key_Logging_client_ctx_ready;
  54185. /* clean up keylog file */
  54186. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54187. if (fp != XBADFILE) {
  54188. XFFLUSH(fp);
  54189. XFCLOSE(fp);
  54190. fp = XBADFILE;
  54191. }
  54192. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54193. &server_cbf, NULL), TEST_SUCCESS);
  54194. /* check if the keylog file exists */
  54195. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54196. XFFLUSH(fp); /* Just to make sure any buffers get flushed */
  54197. XMEMSET(buff, 0, sizeof(buff));
  54198. while (EXPECT_SUCCESS() && XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54199. if (0 == strncmp(buff,"CLIENT_RANDOM ", sizeof("CLIENT_RANDOM ")-1)) {
  54200. found = 1;
  54201. break;
  54202. }
  54203. }
  54204. if (fp != XBADFILE) {
  54205. XFCLOSE(fp);
  54206. }
  54207. /* a log starting with "CLIENT_RANDOM " should exit in the file */
  54208. ExpectIntEQ(found, 1);
  54209. /* clean up */
  54210. ExpectIntEQ(rem_file("./MyKeyLog.txt"), 0);
  54211. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54212. return EXPECT_RESULT();
  54213. }
  54214. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54215. defined(HAVE_SECRET_CALLBACK)
  54216. static int test_wolfSSL_Tls13_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54217. {
  54218. /* set keylog callback */
  54219. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54220. return TEST_SUCCESS;
  54221. }
  54222. #endif
  54223. static int test_wolfSSL_Tls13_Key_Logging_test(void)
  54224. {
  54225. EXPECT_DECLS;
  54226. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54227. defined(HAVE_SECRET_CALLBACK)
  54228. /* This test is intended for checking whether keylog callback is called
  54229. * in client during TLS handshake between the client and a server.
  54230. */
  54231. test_ssl_cbf server_cbf;
  54232. test_ssl_cbf client_cbf;
  54233. XFILE fp = XBADFILE;
  54234. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54235. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54236. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54237. client_cbf.ctx_ready = &test_wolfSSL_Tls13_Key_Logging_client_ctx_ready;
  54238. /* clean up keylog file */
  54239. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54240. if (fp != XBADFILE) {
  54241. XFCLOSE(fp);
  54242. fp = XBADFILE;
  54243. }
  54244. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54245. &server_cbf, NULL), TEST_SUCCESS);
  54246. /* check if the keylog file exists */
  54247. {
  54248. char buff[300] = {0};
  54249. int found[4] = {0};
  54250. int numfnd = 0;
  54251. int i;
  54252. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54253. while (EXPECT_SUCCESS() &&
  54254. XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54255. if (0 == strncmp(buff, "CLIENT_HANDSHAKE_TRAFFIC_SECRET ",
  54256. sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54257. found[0] = 1;
  54258. continue;
  54259. }
  54260. else if (0 == strncmp(buff, "SERVER_HANDSHAKE_TRAFFIC_SECRET ",
  54261. sizeof("SERVER_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54262. found[1] = 1;
  54263. continue;
  54264. }
  54265. else if (0 == strncmp(buff, "CLIENT_TRAFFIC_SECRET_0 ",
  54266. sizeof("CLIENT_TRAFFIC_SECRET_0 ")-1)) {
  54267. found[2] = 1;
  54268. continue;
  54269. }
  54270. else if (0 == strncmp(buff, "SERVER_TRAFFIC_SECRET_0 ",
  54271. sizeof("SERVER_TRAFFIC_SECRET_0 ")-1)) {
  54272. found[3] = 1;
  54273. continue;
  54274. }
  54275. }
  54276. if (fp != XBADFILE)
  54277. XFCLOSE(fp);
  54278. for (i = 0; i < 4; i++) {
  54279. if (found[i] != 0)
  54280. numfnd++;
  54281. }
  54282. ExpectIntEQ(numfnd, 4);
  54283. }
  54284. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && WOLFSSL_TLS13 */
  54285. return EXPECT_RESULT();
  54286. }
  54287. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54288. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54289. static int test_wolfSSL_Tls13_ECH_params(void)
  54290. {
  54291. EXPECT_DECLS;
  54292. #if !defined(NO_WOLFSSL_CLIENT)
  54293. word32 outputLen = 0;
  54294. byte testBuf[72];
  54295. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  54296. WOLFSSL *ssl = wolfSSL_new(ctx);
  54297. ExpectNotNull(ctx);
  54298. ExpectNotNull(ssl);
  54299. /* invalid ctx */
  54300. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(NULL,
  54301. "ech-public-name.com", 0, 0, 0));
  54302. /* invalid public name */
  54303. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx, NULL, 0,
  54304. 0, 0));
  54305. /* invalid algorithms */
  54306. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx,
  54307. "ech-public-name.com", 1000, 1000, 1000));
  54308. /* invalid ctx */
  54309. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(NULL, NULL,
  54310. &outputLen));
  54311. /* invalid output len */
  54312. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(ctx, NULL, NULL));
  54313. /* invalid ssl */
  54314. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(NULL,
  54315. (char*)testBuf, sizeof(testBuf)));
  54316. /* invalid configs64 */
  54317. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl, NULL,
  54318. sizeof(testBuf)));
  54319. /* invalid size */
  54320. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
  54321. (char*)testBuf, 0));
  54322. /* invalid ssl */
  54323. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(NULL, testBuf,
  54324. sizeof(testBuf)));
  54325. /* invalid configs */
  54326. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, NULL,
  54327. sizeof(testBuf)));
  54328. /* invalid size */
  54329. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, testBuf, 0));
  54330. /* invalid ssl */
  54331. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(NULL, NULL, &outputLen));
  54332. /* invalid size */
  54333. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(ssl, NULL, NULL));
  54334. wolfSSL_free(ssl);
  54335. wolfSSL_CTX_free(ctx);
  54336. #endif /* !NO_WOLFSSL_CLIENT */
  54337. return EXPECT_RESULT();
  54338. }
  54339. static int test_wolfSSL_Tls13_ECH(void)
  54340. {
  54341. EXPECT_DECLS;
  54342. tcp_ready ready;
  54343. func_args client_args;
  54344. func_args server_args;
  54345. THREAD_TYPE serverThread;
  54346. callback_functions server_cbf;
  54347. callback_functions client_cbf;
  54348. SOCKET_T sockfd = 0;
  54349. WOLFSSL_CTX* ctx = NULL;
  54350. WOLFSSL* ssl = NULL;
  54351. const char* publicName = "ech-public-name.com";
  54352. const char* privateName = "ech-private-name.com";
  54353. int privateNameLen = 20;
  54354. char reply[1024];
  54355. int replyLen = 0;
  54356. byte rawEchConfig[128];
  54357. word32 rawEchConfigLen = sizeof(rawEchConfig);
  54358. InitTcpReady(&ready);
  54359. ready.port = 22222;
  54360. XMEMSET(&client_args, 0, sizeof(func_args));
  54361. XMEMSET(&server_args, 0, sizeof(func_args));
  54362. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  54363. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  54364. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54365. /* create the server context here so we can get the ech config */
  54366. ExpectNotNull(server_cbf.ctx =
  54367. wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  54368. /* generate ech config */
  54369. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(server_cbf.ctx,
  54370. publicName, 0, 0, 0));
  54371. /* get the config for the client to use */
  54372. ExpectIntEQ(WOLFSSL_SUCCESS,
  54373. wolfSSL_CTX_GetEchConfigs(server_cbf.ctx, rawEchConfig,
  54374. &rawEchConfigLen));
  54375. server_args.callbacks = &server_cbf;
  54376. server_args.signal = &ready;
  54377. /* start server task */
  54378. start_thread(server_task_ech, &server_args, &serverThread);
  54379. wait_tcp_ready(&server_args);
  54380. /* run as a TLS1.3 client */
  54381. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  54382. ExpectIntEQ(WOLFSSL_SUCCESS,
  54383. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  54384. ExpectIntEQ(WOLFSSL_SUCCESS,
  54385. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  54386. ExpectIntEQ(WOLFSSL_SUCCESS,
  54387. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  54388. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  54389. /* get connected the server task */
  54390. ExpectNotNull(ssl = wolfSSL_new(ctx));
  54391. /* set the ech configs for the client */
  54392. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, rawEchConfig,
  54393. rawEchConfigLen));
  54394. /* set the sni for the client */
  54395. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME,
  54396. privateName, privateNameLen));
  54397. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  54398. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54399. ExpectIntEQ(wolfSSL_write(ssl, privateName, privateNameLen),
  54400. privateNameLen);
  54401. ExpectIntGT((replyLen = wolfSSL_read(ssl, reply, sizeof(reply))), 0);
  54402. /* add th null terminator for string compare */
  54403. reply[replyLen] = 0;
  54404. /* check that the server replied with the private name */
  54405. ExpectStrEQ(privateName, reply);
  54406. wolfSSL_free(ssl);
  54407. wolfSSL_CTX_free(ctx);
  54408. CloseSocket(sockfd);
  54409. join_thread(serverThread);
  54410. FreeTcpReady(&ready);
  54411. return EXPECT_RESULT();
  54412. }
  54413. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54414. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54415. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54416. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54417. static int post_auth_version_cb(WOLFSSL* ssl)
  54418. {
  54419. EXPECT_DECLS;
  54420. /* do handshake and then test version error */
  54421. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54422. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54423. return EXPECT_RESULT();
  54424. }
  54425. static int post_auth_version_client_cb(WOLFSSL* ssl)
  54426. {
  54427. EXPECT_DECLS;
  54428. /* do handshake and then test version error */
  54429. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54430. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54431. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54432. #if defined(OPENSSL_ALL) && !defined(NO_ERROR_QUEUE)
  54433. /* check was added to error queue */
  54434. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION));
  54435. /* check the string matches expected string */
  54436. #ifndef NO_ERROR_STRINGS
  54437. ExpectStrEQ(wolfSSL_ERR_error_string(-WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION), NULL),
  54438. "WRONG_SSL_VERSION");
  54439. #endif
  54440. #endif
  54441. return EXPECT_RESULT();
  54442. }
  54443. static int post_auth_cb(WOLFSSL* ssl)
  54444. {
  54445. EXPECT_DECLS;
  54446. WOLFSSL_X509* x509 = NULL;
  54447. /* do handshake and then test version error */
  54448. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54449. ExpectStrEQ("TLSv1.3", wolfSSL_get_version(ssl));
  54450. ExpectNull(x509 = wolfSSL_get_peer_certificate(ssl));
  54451. wolfSSL_X509_free(x509);
  54452. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WOLFSSL_SUCCESS);
  54453. return EXPECT_RESULT();
  54454. }
  54455. static int set_post_auth_cb(WOLFSSL* ssl)
  54456. {
  54457. if (!wolfSSL_is_server(ssl)) {
  54458. EXPECT_DECLS;
  54459. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(ssl), 0);
  54460. return EXPECT_RESULT();
  54461. }
  54462. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_POST_HANDSHAKE, NULL);
  54463. return TEST_SUCCESS;
  54464. }
  54465. #endif
  54466. static int test_wolfSSL_Tls13_postauth(void)
  54467. {
  54468. EXPECT_DECLS;
  54469. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54470. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54471. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54472. test_ssl_cbf server_cbf;
  54473. test_ssl_cbf client_cbf;
  54474. /* test version failure doing post auth with TLS 1.2 connection */
  54475. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54476. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54477. server_cbf.method = wolfTLSv1_2_server_method;
  54478. server_cbf.ssl_ready = set_post_auth_cb;
  54479. server_cbf.on_result = post_auth_version_cb;
  54480. client_cbf.ssl_ready = set_post_auth_cb;
  54481. client_cbf.on_result = post_auth_version_client_cb;
  54482. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54483. &server_cbf, NULL), TEST_SUCCESS);
  54484. /* tests on post auth with TLS 1.3 */
  54485. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54486. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54487. server_cbf.method = wolfTLSv1_3_server_method;
  54488. server_cbf.ssl_ready = set_post_auth_cb;
  54489. client_cbf.ssl_ready = set_post_auth_cb;
  54490. server_cbf.on_result = post_auth_cb;
  54491. client_cbf.on_result = NULL;
  54492. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54493. &server_cbf, NULL), TEST_SUCCESS);
  54494. #endif
  54495. return EXPECT_RESULT();
  54496. }
  54497. static int test_wolfSSL_X509_NID(void)
  54498. {
  54499. EXPECT_DECLS;
  54500. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  54501. !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  54502. int sigType;
  54503. int nameSz;
  54504. X509* cert = NULL;
  54505. EVP_PKEY* pubKeyTmp = NULL;
  54506. X509_NAME* name = NULL;
  54507. char commonName[80];
  54508. char countryName[80];
  54509. char localityName[80];
  54510. char stateName[80];
  54511. char orgName[80];
  54512. char orgUnit[80];
  54513. /* ------ PARSE ORIGINAL SELF-SIGNED CERTIFICATE ------ */
  54514. /* convert cert from DER to internal WOLFSSL_X509 struct */
  54515. ExpectNotNull(cert = wolfSSL_X509_d2i_ex(&cert, client_cert_der_2048,
  54516. sizeof_client_cert_der_2048, HEAP_HINT));
  54517. /* ------ EXTRACT CERTIFICATE ELEMENTS ------ */
  54518. /* extract PUBLIC KEY from cert */
  54519. ExpectNotNull(pubKeyTmp = X509_get_pubkey(cert));
  54520. /* extract signatureType */
  54521. ExpectIntNE((sigType = wolfSSL_X509_get_signature_type(cert)), 0);
  54522. /* extract subjectName info */
  54523. ExpectNotNull(name = X509_get_subject_name(cert));
  54524. ExpectIntEQ(X509_NAME_get_text_by_NID(name, -1, NULL, 0), -1);
  54525. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  54526. NULL, 0)), 0);
  54527. ExpectIntEQ(nameSz, 15);
  54528. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  54529. commonName, sizeof(commonName))), 0);
  54530. ExpectIntEQ(nameSz, 15);
  54531. ExpectIntEQ(XMEMCMP(commonName, "www.wolfssl.com", nameSz), 0);
  54532. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  54533. commonName, 9)), 0);
  54534. ExpectIntEQ(nameSz, 8);
  54535. ExpectIntEQ(XMEMCMP(commonName, "www.wolf", nameSz), 0);
  54536. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_countryName,
  54537. countryName, sizeof(countryName))), 0);
  54538. ExpectIntEQ(XMEMCMP(countryName, "US", nameSz), 0);
  54539. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_localityName,
  54540. localityName, sizeof(localityName))), 0);
  54541. ExpectIntEQ(XMEMCMP(localityName, "Bozeman", nameSz), 0);
  54542. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  54543. NID_stateOrProvinceName, stateName, sizeof(stateName))), 0);
  54544. ExpectIntEQ(XMEMCMP(stateName, "Montana", nameSz), 0);
  54545. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_organizationName,
  54546. orgName, sizeof(orgName))), 0);
  54547. ExpectIntEQ(XMEMCMP(orgName, "wolfSSL_2048", nameSz), 0);
  54548. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  54549. NID_organizationalUnitName, orgUnit, sizeof(orgUnit))), 0);
  54550. ExpectIntEQ(XMEMCMP(orgUnit, "Programming-2048", nameSz), 0);
  54551. EVP_PKEY_free(pubKeyTmp);
  54552. X509_free(cert);
  54553. #endif
  54554. return EXPECT_RESULT();
  54555. }
  54556. static int test_wolfSSL_CTX_set_srp_username(void)
  54557. {
  54558. EXPECT_DECLS;
  54559. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \
  54560. && !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  54561. WOLFSSL_CTX* ctx = NULL;
  54562. WOLFSSL* ssl = NULL;
  54563. const char *username = "TESTUSER";
  54564. const char *password = "TESTPASSWORD";
  54565. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54566. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  54567. SSL_SUCCESS);
  54568. wolfSSL_CTX_free(ctx);
  54569. ctx = NULL;
  54570. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54571. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  54572. SSL_SUCCESS);
  54573. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  54574. SSL_SUCCESS);
  54575. ExpectNotNull(ssl = SSL_new(ctx));
  54576. ExpectNotNull(SSL_get_srp_username(ssl));
  54577. ExpectStrEQ(SSL_get_srp_username(ssl), username);
  54578. wolfSSL_free(ssl);
  54579. wolfSSL_CTX_free(ctx);
  54580. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  54581. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  54582. return EXPECT_RESULT();
  54583. }
  54584. static int test_wolfSSL_CTX_set_srp_password(void)
  54585. {
  54586. EXPECT_DECLS;
  54587. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  54588. !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  54589. WOLFSSL_CTX* ctx = NULL;
  54590. const char *username = "TESTUSER";
  54591. const char *password = "TESTPASSWORD";
  54592. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54593. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  54594. SSL_SUCCESS);
  54595. wolfSSL_CTX_free(ctx);
  54596. ctx = NULL;
  54597. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54598. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  54599. SSL_SUCCESS);
  54600. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  54601. SSL_SUCCESS);
  54602. wolfSSL_CTX_free(ctx);
  54603. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  54604. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  54605. return EXPECT_RESULT();
  54606. }
  54607. static int test_wolfSSL_X509_STORE(void)
  54608. {
  54609. EXPECT_DECLS;
  54610. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54611. X509_STORE *store = NULL;
  54612. #ifdef HAVE_CRL
  54613. X509_STORE_CTX *storeCtx = NULL;
  54614. X509 *ca = NULL;
  54615. X509 *cert = NULL;
  54616. const char srvCert[] = "./certs/server-revoked-cert.pem";
  54617. const char caCert[] = "./certs/ca-cert.pem";
  54618. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  54619. X509_CRL *crl = NULL;
  54620. const char crlPem[] = "./certs/crl/crl.revoked";
  54621. XFILE fp = XBADFILE;
  54622. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  54623. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54624. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  54625. SSL_FILETYPE_PEM)));
  54626. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  54627. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  54628. SSL_FILETYPE_PEM)));
  54629. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  54630. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  54631. ExpectIntEQ(X509_verify_cert(storeCtx), SSL_SUCCESS);
  54632. X509_STORE_free(store);
  54633. store = NULL;
  54634. X509_STORE_CTX_free(storeCtx);
  54635. storeCtx = NULL;
  54636. X509_free(cert);
  54637. cert = NULL;
  54638. X509_free(ca);
  54639. ca = NULL;
  54640. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  54641. /* should fail to verify now after adding in CRL */
  54642. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54643. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  54644. SSL_FILETYPE_PEM)));
  54645. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  54646. ExpectTrue((fp = XFOPEN(crlPem, "rb")) != XBADFILE);
  54647. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  54648. NULL, NULL));
  54649. if (fp != XBADFILE)
  54650. XFCLOSE(fp);
  54651. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  54652. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),SSL_SUCCESS);
  54653. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  54654. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  54655. SSL_FILETYPE_PEM)));
  54656. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  54657. ExpectIntNE(X509_verify_cert(storeCtx), SSL_SUCCESS);
  54658. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  54659. WOLFSSL_X509_V_ERR_CERT_REVOKED);
  54660. X509_CRL_free(crl);
  54661. crl = NULL;
  54662. X509_STORE_free(store);
  54663. store = NULL;
  54664. X509_STORE_CTX_free(storeCtx);
  54665. storeCtx = NULL;
  54666. X509_free(cert);
  54667. cert = NULL;
  54668. X509_free(ca);
  54669. ca = NULL;
  54670. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  54671. #endif /* HAVE_CRL */
  54672. #ifndef WOLFCRYPT_ONLY
  54673. {
  54674. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54675. SSL_CTX* ctx = NULL;
  54676. SSL* ssl = NULL;
  54677. int i;
  54678. for (i = 0; i < 2; i++) {
  54679. #ifndef NO_WOLFSSL_SERVER
  54680. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54681. #else
  54682. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54683. #endif
  54684. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54685. SSL_CTX_set_cert_store(ctx, store);
  54686. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54687. SSL_CTX_set_cert_store(ctx, store);
  54688. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54689. ExpectIntEQ(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54690. SSL_FILETYPE_PEM), SSL_SUCCESS);
  54691. ExpectIntEQ(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  54692. SSL_FILETYPE_PEM), SSL_SUCCESS);
  54693. ExpectNotNull(ssl = SSL_new(ctx));
  54694. if (i == 0) {
  54695. ExpectIntEQ(SSL_set0_verify_cert_store(ssl, store),
  54696. SSL_SUCCESS);
  54697. }
  54698. else {
  54699. ExpectIntEQ(SSL_set1_verify_cert_store(ssl, store), SSL_SUCCESS);
  54700. #ifdef OPENSSL_ALL
  54701. ExpectIntEQ(SSL_CTX_set1_verify_cert_store(ctx, store), SSL_SUCCESS);
  54702. #endif
  54703. }
  54704. if (EXPECT_FAIL() || (i == 1)) {
  54705. X509_STORE_free(store);
  54706. store = NULL;
  54707. }
  54708. SSL_free(ssl);
  54709. ssl = NULL;
  54710. SSL_CTX_free(ctx);
  54711. ctx = NULL;
  54712. }
  54713. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54714. }
  54715. #endif
  54716. #endif
  54717. return EXPECT_RESULT();
  54718. }
  54719. static int test_wolfSSL_X509_STORE_load_locations(void)
  54720. {
  54721. EXPECT_DECLS;
  54722. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  54723. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  54724. SSL_CTX *ctx = NULL;
  54725. X509_STORE *store = NULL;
  54726. const char ca_file[] = "./certs/ca-cert.pem";
  54727. const char client_pem_file[] = "./certs/client-cert.pem";
  54728. const char client_der_file[] = "./certs/client-cert.der";
  54729. const char ecc_file[] = "./certs/ecc-key.pem";
  54730. const char certs_path[] = "./certs/";
  54731. const char bad_path[] = "./bad-path/";
  54732. #ifdef HAVE_CRL
  54733. const char crl_path[] = "./certs/crl/";
  54734. const char crl_file[] = "./certs/crl/crl.pem";
  54735. #endif
  54736. #ifndef NO_WOLFSSL_SERVER
  54737. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  54738. #else
  54739. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  54740. #endif
  54741. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  54742. ExpectIntEQ(wolfSSL_CertManagerLoadCA(store->cm, ca_file, NULL),
  54743. WOLFSSL_SUCCESS);
  54744. /* Test bad arguments */
  54745. ExpectIntEQ(X509_STORE_load_locations(NULL, ca_file, NULL),
  54746. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54747. ExpectIntEQ(X509_STORE_load_locations(store, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54748. ExpectIntEQ(X509_STORE_load_locations(store, client_der_file, NULL),
  54749. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54750. ExpectIntEQ(X509_STORE_load_locations(store, ecc_file, NULL),
  54751. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54752. ExpectIntEQ(X509_STORE_load_locations(store, NULL, bad_path),
  54753. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54754. #ifdef HAVE_CRL
  54755. /* Test with CRL */
  54756. ExpectIntEQ(X509_STORE_load_locations(store, crl_file, NULL),
  54757. WOLFSSL_SUCCESS);
  54758. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crl_path),
  54759. WOLFSSL_SUCCESS);
  54760. #endif
  54761. /* Test with CA */
  54762. ExpectIntEQ(X509_STORE_load_locations(store, ca_file, NULL),
  54763. WOLFSSL_SUCCESS);
  54764. /* Test with client_cert and certs path */
  54765. ExpectIntEQ(X509_STORE_load_locations(store, client_pem_file, NULL),
  54766. WOLFSSL_SUCCESS);
  54767. ExpectIntEQ(X509_STORE_load_locations(store, NULL, certs_path),
  54768. WOLFSSL_SUCCESS);
  54769. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  54770. /* Clear nodes */
  54771. ERR_clear_error();
  54772. #endif
  54773. SSL_CTX_free(ctx);
  54774. #endif
  54775. return EXPECT_RESULT();
  54776. }
  54777. static int test_X509_STORE_get0_objects(void)
  54778. {
  54779. EXPECT_DECLS;
  54780. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && \
  54781. !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  54782. X509_STORE *store = NULL;
  54783. X509_STORE *store_cpy = NULL;
  54784. SSL_CTX *ctx = NULL;
  54785. X509_OBJECT *obj = NULL;
  54786. STACK_OF(X509_OBJECT) *objs = NULL;
  54787. int i;
  54788. /* Setup store */
  54789. #ifndef NO_WOLFSSL_SERVER
  54790. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  54791. #else
  54792. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  54793. #endif
  54794. ExpectNotNull(store_cpy = X509_STORE_new());
  54795. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  54796. ExpectIntEQ(X509_STORE_load_locations(store, cliCertFile, NULL),
  54797. WOLFSSL_SUCCESS);
  54798. ExpectIntEQ(X509_STORE_load_locations(store, caCertFile, NULL),
  54799. WOLFSSL_SUCCESS);
  54800. ExpectIntEQ(X509_STORE_load_locations(store, svrCertFile, NULL),
  54801. WOLFSSL_SUCCESS);
  54802. #ifdef HAVE_CRL
  54803. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crlPemDir),
  54804. WOLFSSL_SUCCESS);
  54805. #endif
  54806. /* Store ready */
  54807. /* Similar to HaProxy ssl_set_cert_crl_file use case */
  54808. ExpectNotNull(objs = X509_STORE_get0_objects(store));
  54809. #ifdef HAVE_CRL
  54810. #ifdef WOLFSSL_SIGNER_DER_CERT
  54811. ExpectIntEQ(sk_X509_OBJECT_num(objs), 4);
  54812. #else
  54813. ExpectIntEQ(sk_X509_OBJECT_num(objs), 1);
  54814. #endif
  54815. #else
  54816. #ifdef WOLFSSL_SIGNER_DER_CERT
  54817. ExpectIntEQ(sk_X509_OBJECT_num(objs), 3);
  54818. #else
  54819. ExpectIntEQ(sk_X509_OBJECT_num(objs), 0);
  54820. #endif
  54821. #endif
  54822. for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
  54823. obj = (X509_OBJECT*)sk_X509_OBJECT_value(objs, i);
  54824. switch (X509_OBJECT_get_type(obj)) {
  54825. case X509_LU_X509:
  54826. {
  54827. X509* x509 = NULL;
  54828. X509_NAME *subj_name = NULL;
  54829. ExpectNotNull(x509 = X509_OBJECT_get0_X509(obj));
  54830. ExpectIntEQ(X509_STORE_add_cert(store_cpy, x509), WOLFSSL_SUCCESS);
  54831. ExpectNotNull(subj_name = X509_get_subject_name(x509));
  54832. ExpectPtrEq(obj, X509_OBJECT_retrieve_by_subject(objs, X509_LU_X509,
  54833. subj_name));
  54834. break;
  54835. }
  54836. case X509_LU_CRL:
  54837. #ifdef HAVE_CRL
  54838. {
  54839. X509_CRL* crl = NULL;
  54840. ExpectNotNull(crl = X509_OBJECT_get0_X509_CRL(obj));
  54841. ExpectIntEQ(X509_STORE_add_crl(store_cpy, crl), WOLFSSL_SUCCESS);
  54842. break;
  54843. }
  54844. #endif
  54845. case X509_LU_NONE:
  54846. default:
  54847. Fail(("X509_OBJECT_get_type should return x509 or crl "
  54848. "(when built with crl support)"),
  54849. ("Unrecognized X509_OBJECT type or none"));
  54850. }
  54851. }
  54852. X509_STORE_free(store_cpy);
  54853. SSL_CTX_free(ctx);
  54854. #endif
  54855. return EXPECT_RESULT();
  54856. }
  54857. static int test_wolfSSL_BN_CTX(void)
  54858. {
  54859. EXPECT_DECLS;
  54860. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  54861. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  54862. WOLFSSL_BN_CTX* bn_ctx = NULL;
  54863. WOLFSSL_BIGNUM* t = NULL;
  54864. ExpectNotNull(bn_ctx = wolfSSL_BN_CTX_new());
  54865. /* No implementation. */
  54866. BN_CTX_init(NULL);
  54867. ExpectNotNull(t = BN_CTX_get(NULL));
  54868. BN_free(t);
  54869. ExpectNotNull(t = BN_CTX_get(bn_ctx));
  54870. BN_free(t);
  54871. #ifndef NO_WOLFSSL_STUB
  54872. /* No implementation. */
  54873. BN_CTX_start(NULL);
  54874. BN_CTX_start(bn_ctx);
  54875. #endif
  54876. BN_CTX_free(NULL);
  54877. BN_CTX_free(bn_ctx);
  54878. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  54879. return EXPECT_RESULT();
  54880. }
  54881. static int test_wolfSSL_BN(void)
  54882. {
  54883. EXPECT_DECLS;
  54884. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  54885. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  54886. BIGNUM* a = NULL;
  54887. BIGNUM* b = NULL;
  54888. BIGNUM* c = NULL;
  54889. BIGNUM* d = NULL;
  54890. BIGNUM emptyBN;
  54891. /* Setup */
  54892. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  54893. /* internal not set emptyBN. */
  54894. ExpectNotNull(a = BN_new());
  54895. ExpectNotNull(b = BN_new());
  54896. ExpectNotNull(c = BN_dup(b));
  54897. ExpectNotNull(d = BN_new());
  54898. /* Invalid parameter testing. */
  54899. BN_free(NULL);
  54900. ExpectNull(BN_dup(NULL));
  54901. ExpectNull(BN_dup(&emptyBN));
  54902. ExpectNull(BN_copy(NULL, NULL));
  54903. ExpectNull(BN_copy(b, NULL));
  54904. ExpectNull(BN_copy(NULL, c));
  54905. ExpectNull(BN_copy(b, &emptyBN));
  54906. ExpectNull(BN_copy(&emptyBN, c));
  54907. BN_clear(NULL);
  54908. BN_clear(&emptyBN);
  54909. ExpectIntEQ(BN_num_bytes(NULL), 0);
  54910. ExpectIntEQ(BN_num_bytes(&emptyBN), 0);
  54911. ExpectIntEQ(BN_num_bits(NULL), 0);
  54912. ExpectIntEQ(BN_num_bits(&emptyBN), 0);
  54913. ExpectIntEQ(BN_is_negative(NULL), 0);
  54914. ExpectIntEQ(BN_is_negative(&emptyBN), 0);
  54915. /* END Invalid Parameters */
  54916. ExpectIntEQ(BN_set_word(a, 3), SSL_SUCCESS);
  54917. ExpectIntEQ(BN_set_word(b, 2), SSL_SUCCESS);
  54918. ExpectIntEQ(BN_set_word(c, 5), SSL_SUCCESS);
  54919. ExpectIntEQ(BN_num_bits(a), 2);
  54920. ExpectIntEQ(BN_num_bytes(a), 1);
  54921. #if !defined(WOLFSSL_SP_MATH) && (!defined(WOLFSSL_SP_MATH_ALL) || \
  54922. defined(WOLFSSL_SP_INT_NEGATIVE))
  54923. ExpectIntEQ(BN_set_word(a, 1), SSL_SUCCESS);
  54924. ExpectIntEQ(BN_set_word(b, 5), SSL_SUCCESS);
  54925. ExpectIntEQ(BN_is_word(a, (WOLFSSL_BN_ULONG)BN_get_word(a)), SSL_SUCCESS);
  54926. ExpectIntEQ(BN_is_word(a, 3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54927. ExpectIntEQ(BN_sub(c, a, b), SSL_SUCCESS);
  54928. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  54929. {
  54930. /* Do additional tests on negative BN conversions. */
  54931. char* ret = NULL;
  54932. ASN1_INTEGER* asn1 = NULL;
  54933. BIGNUM* tmp = NULL;
  54934. /* Sanity check we have a negative BN. */
  54935. ExpectIntEQ(BN_is_negative(c), 1);
  54936. ExpectNotNull(ret = BN_bn2dec(c));
  54937. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  54938. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  54939. ret = NULL;
  54940. /* Convert to ASN1_INTEGER and back to BN. */
  54941. ExpectNotNull(asn1 = BN_to_ASN1_INTEGER(c, NULL));
  54942. ExpectNotNull(tmp = ASN1_INTEGER_to_BN(asn1, NULL));
  54943. /* After converting back BN should be negative and correct. */
  54944. ExpectIntEQ(BN_is_negative(tmp), 1);
  54945. ExpectNotNull(ret = BN_bn2dec(tmp));
  54946. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  54947. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  54948. ASN1_INTEGER_free(asn1);
  54949. BN_free(tmp);
  54950. }
  54951. #endif
  54952. ExpectIntEQ(BN_get_word(c), 4);
  54953. #endif
  54954. ExpectIntEQ(BN_set_word(a, 3), 1);
  54955. ExpectIntEQ(BN_set_word(b, 3), 1);
  54956. ExpectIntEQ(BN_set_word(c, 4), 1);
  54957. /* NULL == NULL, NULL < num, num > NULL */
  54958. ExpectIntEQ(BN_cmp(NULL, NULL), 0);
  54959. ExpectIntEQ(BN_cmp(&emptyBN, &emptyBN), 0);
  54960. ExpectIntLT(BN_cmp(NULL, b), 0);
  54961. ExpectIntLT(BN_cmp(&emptyBN, b), 0);
  54962. ExpectIntGT(BN_cmp(a, NULL), 0);
  54963. ExpectIntGT(BN_cmp(a, &emptyBN), 0);
  54964. ExpectIntEQ(BN_cmp(a, b), 0);
  54965. ExpectIntLT(BN_cmp(a, c), 0);
  54966. ExpectIntGT(BN_cmp(c, b), 0);
  54967. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  54968. ExpectIntEQ(BN_print_fp(XBADFILE, NULL), 0);
  54969. ExpectIntEQ(BN_print_fp(XBADFILE, &emptyBN), 0);
  54970. ExpectIntEQ(BN_print_fp(stderr, NULL), 0);
  54971. ExpectIntEQ(BN_print_fp(stderr, &emptyBN), 0);
  54972. ExpectIntEQ(BN_print_fp(XBADFILE, a), 0);
  54973. ExpectIntEQ(BN_print_fp(stderr, a), 1);
  54974. #endif
  54975. BN_clear(a);
  54976. BN_free(a);
  54977. BN_free(b);
  54978. BN_free(c);
  54979. BN_clear_free(d);
  54980. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  54981. return EXPECT_RESULT();
  54982. }
  54983. static int test_wolfSSL_BN_init(void)
  54984. {
  54985. EXPECT_DECLS;
  54986. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  54987. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  54988. #if !defined(USE_INTEGER_HEAP_MATH) && !defined(HAVE_WOLF_BIGINT)
  54989. BIGNUM* ap = NULL;
  54990. BIGNUM bv;
  54991. BIGNUM cv;
  54992. BIGNUM dv;
  54993. ExpectNotNull(ap = BN_new());
  54994. BN_init(NULL);
  54995. XMEMSET(&bv, 0, sizeof(bv));
  54996. ExpectNull(BN_dup(&bv));
  54997. BN_init(&bv);
  54998. BN_init(&cv);
  54999. BN_init(&dv);
  55000. ExpectIntEQ(BN_set_word(ap, 3), SSL_SUCCESS);
  55001. ExpectIntEQ(BN_set_word(&bv, 2), SSL_SUCCESS);
  55002. ExpectIntEQ(BN_set_word(&cv, 5), SSL_SUCCESS);
  55003. /* a^b mod c = */
  55004. ExpectIntEQ(BN_mod_exp(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55005. ExpectIntEQ(BN_mod_exp(&dv, ap, &bv, &cv, NULL), WOLFSSL_SUCCESS);
  55006. /* check result 3^2 mod 5 */
  55007. ExpectIntEQ(BN_get_word(&dv), 4);
  55008. /* a*b mod c = */
  55009. ExpectIntEQ(BN_mod_mul(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55010. ExpectIntEQ(BN_mod_mul(&dv, ap, &bv, &cv, NULL), SSL_SUCCESS);
  55011. /* check result 3*2 mod 5 */
  55012. ExpectIntEQ(BN_get_word(&dv), 1);
  55013. BN_free(ap);
  55014. #endif
  55015. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55016. return EXPECT_RESULT();
  55017. }
  55018. static int test_wolfSSL_BN_enc_dec(void)
  55019. {
  55020. EXPECT_DECLS;
  55021. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55022. BIGNUM* a = NULL;
  55023. BIGNUM* b = NULL;
  55024. BIGNUM* c = NULL;
  55025. BIGNUM emptyBN;
  55026. char* str = NULL;
  55027. const char* emptyStr = "";
  55028. const char* numberStr = "12345";
  55029. const char* badStr = "g12345";
  55030. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55031. const char* twoStr = "2";
  55032. #endif
  55033. unsigned char binNum[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  55034. unsigned char outNum[5];
  55035. /* Setup */
  55036. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55037. ExpectNotNull(a = BN_new());
  55038. ExpectNotNull(b = BN_new());
  55039. /* Invalid parameters */
  55040. ExpectIntEQ(BN_bn2bin(NULL, NULL), -1);
  55041. ExpectIntEQ(BN_bn2bin(&emptyBN, NULL), -1);
  55042. ExpectIntEQ(BN_bn2bin(NULL, outNum), -1);
  55043. ExpectIntEQ(BN_bn2bin(&emptyBN, outNum), -1);
  55044. ExpectNull(BN_bn2hex(NULL));
  55045. ExpectNull(BN_bn2hex(&emptyBN));
  55046. ExpectNull(BN_bn2dec(NULL));
  55047. ExpectNull(BN_bn2dec(&emptyBN));
  55048. ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
  55049. BN_free(a);
  55050. ExpectNotNull(a = BN_new());
  55051. ExpectIntEQ(BN_set_word(a, 2), 1);
  55052. ExpectNull(BN_bin2bn(binNum, -1, a));
  55053. ExpectNull(BN_bin2bn(binNum, -1, NULL));
  55054. ExpectNull(BN_bin2bn(binNum, sizeof(binNum), &emptyBN));
  55055. ExpectIntEQ(BN_hex2bn(NULL, NULL), 0);
  55056. ExpectIntEQ(BN_hex2bn(NULL, numberStr), 0);
  55057. ExpectIntEQ(BN_hex2bn(&a, NULL), 0);
  55058. ExpectIntEQ(BN_hex2bn(&a, emptyStr), 0);
  55059. ExpectIntEQ(BN_hex2bn(&a, badStr), 0);
  55060. ExpectIntEQ(BN_hex2bn(&c, badStr), 0);
  55061. ExpectIntEQ(BN_dec2bn(NULL, NULL), 0);
  55062. ExpectIntEQ(BN_dec2bn(NULL, numberStr), 0);
  55063. ExpectIntEQ(BN_dec2bn(&a, NULL), 0);
  55064. ExpectIntEQ(BN_dec2bn(&a, emptyStr), 0);
  55065. ExpectIntEQ(BN_dec2bn(&a, badStr), 0);
  55066. ExpectIntEQ(BN_dec2bn(&c, badStr), 0);
  55067. ExpectIntEQ(BN_set_word(a, 2), 1);
  55068. ExpectIntEQ(BN_bn2bin(a, NULL), 1);
  55069. ExpectIntEQ(BN_bn2bin(a, outNum), 1);
  55070. ExpectNotNull(BN_bin2bn(outNum, 1, b));
  55071. ExpectIntEQ(BN_cmp(a, b), 0);
  55072. ExpectNotNull(BN_bin2bn(binNum, sizeof(binNum), b));
  55073. ExpectIntEQ(BN_cmp(a, b), -1);
  55074. ExpectNotNull(str = BN_bn2hex(a));
  55075. ExpectNotNull(BN_hex2bn(&b, str));
  55076. ExpectIntEQ(BN_cmp(a, b), 0);
  55077. ExpectNotNull(BN_hex2bn(&b, numberStr));
  55078. ExpectIntEQ(BN_cmp(a, b), -1);
  55079. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55080. str = NULL;
  55081. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55082. ExpectNotNull(str = BN_bn2dec(a));
  55083. ExpectStrEQ(str, twoStr);
  55084. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55085. str = NULL;
  55086. #ifndef NO_RSA
  55087. ExpectNotNull(str = BN_bn2dec(a));
  55088. ExpectNotNull(BN_dec2bn(&b, str));
  55089. ExpectIntEQ(BN_cmp(a, b), 0);
  55090. ExpectNotNull(BN_dec2bn(&b, numberStr));
  55091. ExpectIntEQ(BN_cmp(a, b), -1);
  55092. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55093. str = NULL;
  55094. #else
  55095. /* No implementation - fail with good parameters. */
  55096. ExpectIntEQ(BN_dec2bn(&a, numberStr), 0);
  55097. #endif
  55098. #endif
  55099. BN_free(b);
  55100. BN_free(a);
  55101. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55102. return EXPECT_RESULT();
  55103. }
  55104. static int test_wolfSSL_BN_word(void)
  55105. {
  55106. EXPECT_DECLS;
  55107. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55108. BIGNUM* a = NULL;
  55109. BIGNUM* b = NULL;
  55110. BIGNUM* c = NULL;
  55111. BIGNUM av;
  55112. ExpectNotNull(a = BN_new());
  55113. ExpectNotNull(b = BN_new());
  55114. ExpectNotNull(c = BN_new());
  55115. XMEMSET(&av, 0, sizeof(av));
  55116. /* Invalid parameter. */
  55117. ExpectIntEQ(BN_add_word(NULL, 3), 0);
  55118. ExpectIntEQ(BN_add_word(&av, 3), 0);
  55119. ExpectIntEQ(BN_sub_word(NULL, 3), 0);
  55120. ExpectIntEQ(BN_sub_word(&av, 3), 0);
  55121. ExpectIntEQ(BN_set_word(NULL, 3), 0);
  55122. ExpectIntEQ(BN_set_word(&av, 3), 0);
  55123. ExpectIntEQ(BN_get_word(NULL), 0);
  55124. ExpectIntEQ(BN_get_word(&av), 0);
  55125. ExpectIntEQ(BN_is_word(NULL, 3), 0);
  55126. ExpectIntEQ(BN_is_word(&av, 3), 0);
  55127. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55128. !defined(NO_DSA))
  55129. ExpectIntEQ(BN_mod_word(NULL, 3), -1);
  55130. ExpectIntEQ(BN_mod_word(&av, 3), -1);
  55131. #endif
  55132. ExpectIntEQ(BN_one(NULL), 0);
  55133. ExpectIntEQ(BN_one(&av), 0);
  55134. BN_zero(NULL);
  55135. BN_zero(&av);
  55136. ExpectIntEQ(BN_is_one(NULL), 0);
  55137. ExpectIntEQ(BN_is_one(&av), 0);
  55138. ExpectIntEQ(BN_is_zero(NULL), 0);
  55139. ExpectIntEQ(BN_is_zero(&av), 0);
  55140. ExpectIntEQ(BN_set_word(a, 3), 1);
  55141. ExpectIntEQ(BN_set_word(b, 2), 1);
  55142. ExpectIntEQ(BN_set_word(c, 5), 1);
  55143. /* a + 3 = */
  55144. ExpectIntEQ(BN_add_word(a, 3), 1);
  55145. /* check result 3 + 3*/
  55146. ExpectIntEQ(BN_get_word(a), 6);
  55147. ExpectIntEQ(BN_is_word(a, 6), 1);
  55148. ExpectIntEQ(BN_is_word(a, 5), 0);
  55149. /* set a back to 3 */
  55150. ExpectIntEQ(BN_set_word(a, 3), 1);
  55151. /* a - 3 = */
  55152. ExpectIntEQ(BN_sub_word(a, 3), 1);
  55153. /* check result 3 - 3*/
  55154. ExpectIntEQ(BN_get_word(a), 0);
  55155. ExpectIntEQ(BN_one(a), 1);
  55156. ExpectIntEQ(BN_is_word(a, 1), 1);
  55157. ExpectIntEQ(BN_is_word(a, 0), 0);
  55158. ExpectIntEQ(BN_is_one(a), 1);
  55159. ExpectIntEQ(BN_is_zero(a), 0);
  55160. BN_zero(a);
  55161. ExpectIntEQ(BN_is_word(a, 0), 1);
  55162. ExpectIntEQ(BN_is_word(a, 1), 0);
  55163. ExpectIntEQ(BN_is_zero(a), 1);
  55164. ExpectIntEQ(BN_is_one(a), 0);
  55165. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55166. !defined(NO_DSA))
  55167. ExpectIntEQ(BN_set_word(a, 5), 1);
  55168. ExpectIntEQ(BN_mod_word(a, 3), 2);
  55169. ExpectIntEQ(BN_mod_word(a, 0), -1);
  55170. #endif
  55171. BN_free(c);
  55172. BN_free(b);
  55173. BN_free(a);
  55174. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55175. return EXPECT_RESULT();
  55176. }
  55177. static int test_wolfSSL_BN_bits(void)
  55178. {
  55179. EXPECT_DECLS;
  55180. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55181. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55182. BIGNUM* a = NULL;
  55183. BIGNUM emptyBN;
  55184. /* Setup */
  55185. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55186. ExpectNotNull(a = BN_new());
  55187. /* Invalid parameters. */
  55188. ExpectIntEQ(BN_set_bit(NULL, 1), 0);
  55189. ExpectIntEQ(BN_set_bit(&emptyBN, 1), 0);
  55190. ExpectIntEQ(BN_set_bit(a, -1), 0);
  55191. ExpectIntEQ(BN_clear_bit(NULL, 1), 0);
  55192. ExpectIntEQ(BN_clear_bit(&emptyBN, 1), 0);
  55193. ExpectIntEQ(BN_clear_bit(a, -1), 0);
  55194. ExpectIntEQ(BN_is_bit_set(NULL, 1), 0);
  55195. ExpectIntEQ(BN_is_bit_set(&emptyBN, 1), 0);
  55196. ExpectIntEQ(BN_is_bit_set(a, -1), 0);
  55197. ExpectIntEQ(BN_is_odd(NULL), 0);
  55198. ExpectIntEQ(BN_is_odd(&emptyBN), 0);
  55199. ExpectIntEQ(BN_set_word(a, 0), 1);
  55200. ExpectIntEQ(BN_is_zero(a), 1);
  55201. ExpectIntEQ(BN_set_bit(a, 0x45), 1);
  55202. ExpectIntEQ(BN_is_zero(a), 0);
  55203. ExpectIntEQ(BN_is_bit_set(a, 0x45), 1);
  55204. ExpectIntEQ(BN_clear_bit(a, 0x45), 1);
  55205. ExpectIntEQ(BN_is_bit_set(a, 0x45), 0);
  55206. ExpectIntEQ(BN_is_zero(a), 1);
  55207. ExpectIntEQ(BN_set_bit(a, 0), 1);
  55208. ExpectIntEQ(BN_is_odd(a), 1);
  55209. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  55210. ExpectIntEQ(BN_is_odd(a), 0);
  55211. ExpectIntEQ(BN_set_bit(a, 1), 1);
  55212. ExpectIntEQ(BN_is_odd(a), 0);
  55213. ExpectIntEQ(BN_set_bit(a, 129), 1);
  55214. ExpectIntEQ(BN_get_word(a), WOLFSSL_BN_MAX_VAL);
  55215. #ifndef NO_WOLFSSL_STUB
  55216. ExpectIntEQ(BN_mask_bits(a, 1), 0);
  55217. #endif
  55218. BN_free(a);
  55219. #endif
  55220. return EXPECT_RESULT();
  55221. }
  55222. static int test_wolfSSL_BN_shift(void)
  55223. {
  55224. EXPECT_DECLS;
  55225. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55226. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55227. BIGNUM* a = NULL;
  55228. BIGNUM* b = NULL;
  55229. BIGNUM emptyBN;
  55230. /* Setup */
  55231. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55232. ExpectNotNull(a = BN_new());
  55233. ExpectNotNull(b = BN_new());
  55234. /* Invalid parameters. */
  55235. ExpectIntEQ(BN_lshift(NULL, NULL, 1), 0);
  55236. ExpectIntEQ(BN_lshift(&emptyBN, NULL, 1), 0);
  55237. ExpectIntEQ(BN_lshift(NULL, &emptyBN, 1), 0);
  55238. ExpectIntEQ(BN_lshift(b, NULL, 1), 0);
  55239. ExpectIntEQ(BN_lshift(b, &emptyBN, 1), 0);
  55240. ExpectIntEQ(BN_lshift(NULL, a, 1), 0);
  55241. ExpectIntEQ(BN_lshift(&emptyBN, a, 1), 0);
  55242. ExpectIntEQ(BN_lshift(b, a, -1), 0);
  55243. ExpectIntEQ(BN_rshift(NULL, NULL, 1), 0);
  55244. ExpectIntEQ(BN_rshift(&emptyBN, NULL, 1), 0);
  55245. ExpectIntEQ(BN_rshift(NULL, &emptyBN, 1), 0);
  55246. ExpectIntEQ(BN_rshift(b, NULL, 1), 0);
  55247. ExpectIntEQ(BN_rshift(b, &emptyBN, 1), 0);
  55248. ExpectIntEQ(BN_rshift(NULL, a, 1), 0);
  55249. ExpectIntEQ(BN_rshift(&emptyBN, a, 1), 0);
  55250. ExpectIntEQ(BN_rshift(b, a, -1), 0);
  55251. ExpectIntEQ(BN_set_word(a, 1), 1);
  55252. ExpectIntEQ(BN_lshift(b, a, 1), 1);
  55253. ExpectIntEQ(BN_is_word(b, 2), 1);
  55254. ExpectIntEQ(BN_lshift(a, a, 1), 1);
  55255. ExpectIntEQ(BN_is_word(a, 2), 1);
  55256. ExpectIntEQ(BN_rshift(b, a, 1), 1);
  55257. ExpectIntEQ(BN_is_word(b, 1), 1);
  55258. ExpectIntEQ(BN_rshift(a, a, 1), 1);
  55259. ExpectIntEQ(BN_is_word(a, 1), 1);
  55260. BN_free(b);
  55261. BN_free(a);
  55262. #endif
  55263. return EXPECT_RESULT();
  55264. }
  55265. static int test_wolfSSL_BN_math(void)
  55266. {
  55267. EXPECT_DECLS;
  55268. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55269. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55270. BIGNUM* a = NULL;
  55271. BIGNUM* b = NULL;
  55272. BIGNUM* r = NULL;
  55273. BIGNUM* rem = NULL;
  55274. BIGNUM emptyBN;
  55275. BN_ULONG val1;
  55276. BN_ULONG val2;
  55277. /* Setup */
  55278. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55279. ExpectNotNull(a = BN_new());
  55280. ExpectNotNull(b = BN_new());
  55281. ExpectNotNull(r = BN_new());
  55282. ExpectNotNull(rem = BN_new());
  55283. /* Invalid parameters. */
  55284. ExpectIntEQ(BN_add(NULL, NULL, NULL), 0);
  55285. ExpectIntEQ(BN_add(r, NULL, NULL), 0);
  55286. ExpectIntEQ(BN_add(NULL, a, NULL), 0);
  55287. ExpectIntEQ(BN_add(NULL, NULL, b), 0);
  55288. ExpectIntEQ(BN_add(r, a, NULL), 0);
  55289. ExpectIntEQ(BN_add(r, NULL, b), 0);
  55290. ExpectIntEQ(BN_add(NULL, a, b), 0);
  55291. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, &emptyBN), 0);
  55292. ExpectIntEQ(BN_add(r, &emptyBN, &emptyBN), 0);
  55293. ExpectIntEQ(BN_add(&emptyBN, a, &emptyBN), 0);
  55294. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, b), 0);
  55295. ExpectIntEQ(BN_add(r, a, &emptyBN), 0);
  55296. ExpectIntEQ(BN_add(r, &emptyBN, b), 0);
  55297. ExpectIntEQ(BN_add(&emptyBN, a, b), 0);
  55298. ExpectIntEQ(BN_sub(NULL, NULL, NULL), 0);
  55299. ExpectIntEQ(BN_sub(r, NULL, NULL), 0);
  55300. ExpectIntEQ(BN_sub(NULL, a, NULL), 0);
  55301. ExpectIntEQ(BN_sub(NULL, NULL, b), 0);
  55302. ExpectIntEQ(BN_sub(r, a, NULL), 0);
  55303. ExpectIntEQ(BN_sub(r, NULL, b), 0);
  55304. ExpectIntEQ(BN_sub(NULL, a, b), 0);
  55305. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, &emptyBN), 0);
  55306. ExpectIntEQ(BN_sub(r, &emptyBN, &emptyBN), 0);
  55307. ExpectIntEQ(BN_sub(&emptyBN, a, &emptyBN), 0);
  55308. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, b), 0);
  55309. ExpectIntEQ(BN_sub(r, a, &emptyBN), 0);
  55310. ExpectIntEQ(BN_sub(r, &emptyBN, b), 0);
  55311. ExpectIntEQ(BN_sub(&emptyBN, a, b), 0);
  55312. ExpectIntEQ(BN_mul(NULL, NULL, NULL, NULL), 0);
  55313. ExpectIntEQ(BN_mul(r, NULL, NULL, NULL), 0);
  55314. ExpectIntEQ(BN_mul(NULL, a, NULL, NULL), 0);
  55315. ExpectIntEQ(BN_mul(NULL, NULL, b, NULL), 0);
  55316. ExpectIntEQ(BN_mul(r, a, NULL, NULL), 0);
  55317. ExpectIntEQ(BN_mul(r, NULL, b, NULL), 0);
  55318. ExpectIntEQ(BN_mul(NULL, a, b, NULL), 0);
  55319. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55320. ExpectIntEQ(BN_mul(r, &emptyBN, &emptyBN, NULL), 0);
  55321. ExpectIntEQ(BN_mul(&emptyBN, a, &emptyBN, NULL), 0);
  55322. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, b, NULL), 0);
  55323. ExpectIntEQ(BN_mul(r, a, &emptyBN, NULL), 0);
  55324. ExpectIntEQ(BN_mul(r, &emptyBN, b, NULL), 0);
  55325. ExpectIntEQ(BN_mul(&emptyBN, a, b, NULL), 0);
  55326. ExpectIntEQ(BN_div(NULL, NULL, NULL, NULL, NULL), 0);
  55327. ExpectIntEQ(BN_div(r, NULL, NULL, NULL, NULL), 0);
  55328. ExpectIntEQ(BN_div(NULL, rem, NULL, NULL, NULL), 0);
  55329. ExpectIntEQ(BN_div(NULL, NULL, a, NULL, NULL), 0);
  55330. ExpectIntEQ(BN_div(NULL, NULL, NULL, b, NULL), 0);
  55331. ExpectIntEQ(BN_div(NULL, rem, a, b, NULL), 0);
  55332. ExpectIntEQ(BN_div(r, NULL, a, b, NULL), 0);
  55333. ExpectIntEQ(BN_div(r, rem, NULL, b, NULL), 0);
  55334. ExpectIntEQ(BN_div(r, rem, a, NULL, NULL), 0);
  55335. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55336. ExpectIntEQ(BN_div(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55337. ExpectIntEQ(BN_div(&emptyBN, rem, &emptyBN, &emptyBN, NULL), 0);
  55338. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, a, &emptyBN, NULL), 0);
  55339. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, b, NULL), 0);
  55340. ExpectIntEQ(BN_div(&emptyBN, rem, a, b, NULL), 0);
  55341. ExpectIntEQ(BN_div(r, &emptyBN, a, b, NULL), 0);
  55342. ExpectIntEQ(BN_div(r, rem, &emptyBN, b, NULL), 0);
  55343. ExpectIntEQ(BN_div(r, rem, a, &emptyBN, NULL), 0);
  55344. ExpectIntEQ(BN_mod(NULL, NULL, NULL, NULL), 0);
  55345. ExpectIntEQ(BN_mod(r, NULL, NULL, NULL), 0);
  55346. ExpectIntEQ(BN_mod(NULL, a, NULL, NULL), 0);
  55347. ExpectIntEQ(BN_mod(NULL, NULL, b, NULL), 0);
  55348. ExpectIntEQ(BN_mod(r, a, NULL, NULL), 0);
  55349. ExpectIntEQ(BN_mod(r, NULL, b, NULL), 0);
  55350. ExpectIntEQ(BN_mod(NULL, a, b, NULL), 0);
  55351. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55352. ExpectIntEQ(BN_mod(r, &emptyBN, &emptyBN, NULL), 0);
  55353. ExpectIntEQ(BN_mod(&emptyBN, a, &emptyBN, NULL), 0);
  55354. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, b, NULL), 0);
  55355. ExpectIntEQ(BN_mod(r, a, &emptyBN, NULL), 0);
  55356. ExpectIntEQ(BN_mod(r, &emptyBN, b, NULL), 0);
  55357. ExpectIntEQ(BN_mod(&emptyBN, a, b, NULL), 0);
  55358. /* END Invalid parameters. */
  55359. val1 = 8;
  55360. val2 = 3;
  55361. ExpectIntEQ(BN_set_word(a, val1), 1);
  55362. ExpectIntEQ(BN_set_word(b, val2), 1);
  55363. ExpectIntEQ(BN_add(r, a, b), 1);
  55364. ExpectIntEQ(BN_is_word(r, val1 + val2), 1);
  55365. ExpectIntEQ(BN_sub(r, a, b), 1);
  55366. ExpectIntEQ(BN_is_word(r, val1 - val2), 1);
  55367. ExpectIntEQ(BN_mul(r, a, b, NULL), 1);
  55368. ExpectIntEQ(BN_is_word(r, val1 * val2), 1);
  55369. ExpectIntEQ(BN_div(r, rem, a, b, NULL), 1);
  55370. ExpectIntEQ(BN_is_word(r, val1 / val2), 1);
  55371. ExpectIntEQ(BN_is_word(rem, val1 % val2), 1);
  55372. ExpectIntEQ(BN_mod(r, a, b, NULL), 1);
  55373. ExpectIntEQ(BN_is_word(r, val1 % val2), 1);
  55374. BN_free(rem);
  55375. BN_free(r);
  55376. BN_free(b);
  55377. BN_free(a);
  55378. #endif
  55379. return EXPECT_RESULT();
  55380. }
  55381. static int test_wolfSSL_BN_math_mod(void)
  55382. {
  55383. EXPECT_DECLS;
  55384. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55385. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55386. BIGNUM* a = NULL;
  55387. BIGNUM* b = NULL;
  55388. BIGNUM* m = NULL;
  55389. BIGNUM* r = NULL;
  55390. BIGNUM* t = NULL;
  55391. BIGNUM emptyBN;
  55392. BN_ULONG val1;
  55393. BN_ULONG val2;
  55394. BN_ULONG val3;
  55395. /* Setup */
  55396. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55397. ExpectNotNull(a = BN_new());
  55398. ExpectNotNull(b = BN_new());
  55399. ExpectNotNull(m = BN_new());
  55400. ExpectNotNull(r = BN_new());
  55401. /* Invalid parameters. */
  55402. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, NULL, NULL), 0);
  55403. ExpectIntEQ(BN_mod_add(r, NULL, NULL, NULL, NULL), 0);
  55404. ExpectIntEQ(BN_mod_add(NULL, a, NULL, NULL, NULL), 0);
  55405. ExpectIntEQ(BN_mod_add(NULL, NULL, b, NULL, NULL), 0);
  55406. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, m, NULL), 0);
  55407. ExpectIntEQ(BN_mod_add(NULL, a, b, m, NULL), 0);
  55408. ExpectIntEQ(BN_mod_add(r, NULL, b, m, NULL), 0);
  55409. ExpectIntEQ(BN_mod_add(r, a, NULL, m, NULL), 0);
  55410. ExpectIntEQ(BN_mod_add(r, a, m, NULL, NULL), 0);
  55411. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55412. ExpectIntEQ(BN_mod_add(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55413. ExpectIntEQ(BN_mod_add(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55414. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55415. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55416. ExpectIntEQ(BN_mod_add(&emptyBN, a, b, m, NULL), 0);
  55417. ExpectIntEQ(BN_mod_add(r, &emptyBN, b, m, NULL), 0);
  55418. ExpectIntEQ(BN_mod_add(r, a, &emptyBN, m, NULL), 0);
  55419. ExpectIntEQ(BN_mod_add(r, a, m, &emptyBN, NULL), 0);
  55420. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, NULL, NULL), 0);
  55421. ExpectIntEQ(BN_mod_mul(r, NULL, NULL, NULL, NULL), 0);
  55422. ExpectIntEQ(BN_mod_mul(NULL, a, NULL, NULL, NULL), 0);
  55423. ExpectIntEQ(BN_mod_mul(NULL, NULL, b, NULL, NULL), 0);
  55424. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, m, NULL), 0);
  55425. ExpectIntEQ(BN_mod_mul(NULL, a, b, m, NULL), 0);
  55426. ExpectIntEQ(BN_mod_mul(r, NULL, b, m, NULL), 0);
  55427. ExpectIntEQ(BN_mod_mul(r, a, NULL, m, NULL), 0);
  55428. ExpectIntEQ(BN_mod_mul(r, a, m, NULL, NULL), 0);
  55429. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55430. ExpectIntEQ(BN_mod_mul(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55431. ExpectIntEQ(BN_mod_mul(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55432. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55433. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55434. ExpectIntEQ(BN_mod_mul(&emptyBN, a, b, m, NULL), 0);
  55435. ExpectIntEQ(BN_mod_mul(r, &emptyBN, b, m, NULL), 0);
  55436. ExpectIntEQ(BN_mod_mul(r, a, &emptyBN, m, NULL), 0);
  55437. ExpectIntEQ(BN_mod_mul(r, a, m, &emptyBN, NULL), 0);
  55438. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, NULL, NULL), 0);
  55439. ExpectIntEQ(BN_mod_exp(r, NULL, NULL, NULL, NULL), 0);
  55440. ExpectIntEQ(BN_mod_exp(NULL, a, NULL, NULL, NULL), 0);
  55441. ExpectIntEQ(BN_mod_exp(NULL, NULL, b, NULL, NULL), 0);
  55442. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, m, NULL), 0);
  55443. ExpectIntEQ(BN_mod_exp(NULL, a, b, m, NULL), 0);
  55444. ExpectIntEQ(BN_mod_exp(r, NULL, b, m, NULL), 0);
  55445. ExpectIntEQ(BN_mod_exp(r, a, NULL, m, NULL), 0);
  55446. ExpectIntEQ(BN_mod_exp(r, a, m, NULL, NULL), 0);
  55447. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55448. ExpectIntEQ(BN_mod_exp(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55449. ExpectIntEQ(BN_mod_exp(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55450. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55451. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55452. ExpectIntEQ(BN_mod_exp(&emptyBN, a, b, m, NULL), 0);
  55453. ExpectIntEQ(BN_mod_exp(r, &emptyBN, b, m, NULL), 0);
  55454. ExpectIntEQ(BN_mod_exp(r, a, &emptyBN, m, NULL), 0);
  55455. ExpectIntEQ(BN_mod_exp(r, a, m, &emptyBN, NULL), 0);
  55456. ExpectNull(BN_mod_inverse(r, NULL, NULL, NULL));
  55457. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55458. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55459. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55460. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55461. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, &emptyBN, NULL));
  55462. ExpectNull(BN_mod_inverse(r, &emptyBN, &emptyBN, NULL));
  55463. ExpectNull(BN_mod_inverse(&emptyBN, a, &emptyBN, NULL));
  55464. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, m, NULL));
  55465. ExpectNull(BN_mod_inverse(&emptyBN, a, m, NULL));
  55466. ExpectNull(BN_mod_inverse(r, &emptyBN, m, NULL));
  55467. ExpectNull(BN_mod_inverse(r, a, &emptyBN, NULL));
  55468. /* END Invalid parameters. */
  55469. val1 = 9;
  55470. val2 = 13;
  55471. val3 = 5;
  55472. ExpectIntEQ(BN_set_word(a, val1), 1);
  55473. ExpectIntEQ(BN_set_word(b, val2), 1);
  55474. ExpectIntEQ(BN_set_word(m, val3), 1);
  55475. ExpectIntEQ(BN_mod_add(r, a, b, m, NULL), 1);
  55476. ExpectIntEQ(BN_is_word(r, (val1 + val2) % val3), 1);
  55477. ExpectIntEQ(BN_mod_mul(r, a, b, m, NULL), 1);
  55478. ExpectIntEQ(BN_is_word(r, (val1 * val2) % val3), 1);
  55479. ExpectIntEQ(BN_set_word(a, 2), 1);
  55480. ExpectIntEQ(BN_set_word(b, 3), 1);
  55481. ExpectIntEQ(BN_set_word(m, 5), 1);
  55482. /* (2 ^ 3) % 5 = 8 % 5 = 3 */
  55483. ExpectIntEQ(BN_mod_exp(r, a, b, m, NULL), 1);
  55484. ExpectIntEQ(BN_is_word(r, 3), 1);
  55485. /* (2 * 3) % 5 = 6 % 5 = 1 => inv = 3 */
  55486. ExpectNotNull(BN_mod_inverse(r, a, m, NULL));
  55487. ExpectIntEQ(BN_is_word(r, 3), 1);
  55488. ExpectNotNull(t = BN_mod_inverse(NULL, a, m, NULL));
  55489. ExpectIntEQ(BN_is_word(t, 3), 1);
  55490. BN_free(t);
  55491. /* No inverse case. No inverse when a divides b. */
  55492. ExpectIntEQ(BN_set_word(a, 3), 1);
  55493. ExpectIntEQ(BN_set_word(m, 9), 1);
  55494. ExpectNull(BN_mod_inverse(r, a, m, NULL));
  55495. BN_free(r);
  55496. BN_free(m);
  55497. BN_free(b);
  55498. BN_free(a);
  55499. #endif
  55500. return EXPECT_RESULT();
  55501. }
  55502. static int test_wolfSSL_BN_math_other(void)
  55503. {
  55504. EXPECT_DECLS;
  55505. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55506. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55507. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  55508. BIGNUM* a = NULL;
  55509. BIGNUM* b = NULL;
  55510. BIGNUM* r = NULL;
  55511. BIGNUM emptyBN;
  55512. /* Setup */
  55513. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55514. ExpectNotNull(a = BN_new());
  55515. ExpectNotNull(b = BN_new());
  55516. ExpectNotNull(r = BN_new());
  55517. /* Invalid parameters. */
  55518. ExpectIntEQ(BN_gcd(NULL, NULL, NULL, NULL), 0);
  55519. ExpectIntEQ(BN_gcd(r, NULL, NULL, NULL), 0);
  55520. ExpectIntEQ(BN_gcd(NULL, a, NULL, NULL), 0);
  55521. ExpectIntEQ(BN_gcd(NULL, NULL, b, NULL), 0);
  55522. ExpectIntEQ(BN_gcd(NULL, a, b, NULL), 0);
  55523. ExpectIntEQ(BN_gcd(r, NULL, b, NULL), 0);
  55524. ExpectIntEQ(BN_gcd(r, a, NULL, NULL), 0);
  55525. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55526. ExpectIntEQ(BN_gcd(r, &emptyBN, &emptyBN, NULL), 0);
  55527. ExpectIntEQ(BN_gcd(&emptyBN, a, &emptyBN, NULL), 0);
  55528. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, b, NULL), 0);
  55529. ExpectIntEQ(BN_gcd(&emptyBN, a, b, NULL), 0);
  55530. ExpectIntEQ(BN_gcd(r, &emptyBN, b, NULL), 0);
  55531. ExpectIntEQ(BN_gcd(r, a, &emptyBN, NULL), 0);
  55532. /* END Invalid parameters. */
  55533. /* No common factors between 2 and 3. */
  55534. ExpectIntEQ(BN_set_word(a, 2), 1);
  55535. ExpectIntEQ(BN_set_word(b, 3), 1);
  55536. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  55537. ExpectIntEQ(BN_is_word(r, 1), 1);
  55538. /* 3 is largest value that divides both 6 and 9. */
  55539. ExpectIntEQ(BN_set_word(a, 6), 1);
  55540. ExpectIntEQ(BN_set_word(b, 9), 1);
  55541. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  55542. ExpectIntEQ(BN_is_word(r, 3), 1);
  55543. /* GCD of 0 and 0 is undefined. */
  55544. ExpectIntEQ(BN_set_word(a, 0), 1);
  55545. ExpectIntEQ(BN_set_word(b, 0), 1);
  55546. ExpectIntEQ(BN_gcd(r, a, b, NULL), 0);
  55547. /* Teardown */
  55548. BN_free(r);
  55549. BN_free(b);
  55550. BN_free(a);
  55551. #endif
  55552. #endif
  55553. return EXPECT_RESULT();
  55554. }
  55555. static int test_wolfSSL_BN_rand(void)
  55556. {
  55557. EXPECT_DECLS;
  55558. #if defined(OPENSSL_EXTRA) && !defined(OPENSSL_EXTRA_NO_BN)
  55559. BIGNUM* bn = NULL;
  55560. BIGNUM* range = NULL;
  55561. BIGNUM emptyBN;
  55562. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55563. ExpectNotNull(bn = BN_new());
  55564. ExpectNotNull(range = BN_new());
  55565. /* Invalid parameters. */
  55566. ExpectIntEQ(BN_rand(NULL, -1, 0, 0), 0);
  55567. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  55568. ExpectIntEQ(BN_rand(NULL, 1, 0, 0), 0);
  55569. ExpectIntEQ(BN_rand(&emptyBN, -1, 0, 0), 0);
  55570. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  55571. ExpectIntEQ(BN_rand(&emptyBN, 1, 0, 0), 0);
  55572. ExpectIntEQ(BN_pseudo_rand(NULL, -1, 0, 0), 0);
  55573. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  55574. ExpectIntEQ(BN_pseudo_rand(NULL, 1, 0, 0), 0);
  55575. ExpectIntEQ(BN_pseudo_rand(&emptyBN, -1, 0, 0), 0);
  55576. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  55577. ExpectIntEQ(BN_pseudo_rand(&emptyBN, 1, 0, 0), 0);
  55578. ExpectIntEQ(BN_rand_range(NULL, NULL), 0);
  55579. ExpectIntEQ(BN_rand_range(bn, NULL), 0);
  55580. ExpectIntEQ(BN_rand_range(NULL, range), 0);
  55581. ExpectIntEQ(BN_rand_range(&emptyBN, &emptyBN), 0);
  55582. ExpectIntEQ(BN_rand_range(bn, &emptyBN), 0);
  55583. ExpectIntEQ(BN_rand_range(&emptyBN, range), 0);
  55584. /* 0 bit random value must be 0 and so cannot set bit in any position. */
  55585. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55586. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55587. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55588. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55589. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55590. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55591. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55592. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55593. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55594. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55595. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55596. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55597. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55598. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55599. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55600. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55601. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55602. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55603. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55604. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55605. /* 1 bit random value must have no more than one top bit set. */
  55606. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55607. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55608. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55609. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55610. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55611. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55612. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55613. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55614. /* END Invalid parameters. */
  55615. /* 0 bit random: 0. */
  55616. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55617. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55618. ExpectIntEQ(BN_is_zero(bn), 1);
  55619. ExpectIntEQ(BN_set_word(bn, 2), 1); /* Make sure not zero. */
  55620. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55621. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55622. ExpectIntEQ(BN_is_zero(bn), 1);
  55623. /* 1 bit random: 0 or 1. */
  55624. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  55625. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55626. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  55627. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55628. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55629. ExpectIntEQ(BN_get_word(bn), 1);
  55630. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55631. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55632. ExpectIntEQ(BN_get_word(bn), 1);
  55633. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  55634. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55635. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  55636. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55637. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55638. ExpectIntEQ(BN_get_word(bn), 1);
  55639. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55640. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55641. ExpectIntEQ(BN_get_word(bn), 1);
  55642. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55643. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55644. ExpectIntEQ(BN_num_bits(bn), 8);
  55645. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55646. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55647. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55648. ExpectIntEQ(BN_num_bits(bn), 8);
  55649. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55650. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  55651. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55652. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55653. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  55654. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  55655. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55656. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55657. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  55658. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55659. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55660. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  55661. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55662. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55663. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  55664. /* Regression test: Older versions of wolfSSL_BN_rand would round the
  55665. * requested number of bits up to the nearest multiple of 8. E.g. in this
  55666. * case, requesting a 13-bit random number would actually return a 16-bit
  55667. * random number. */
  55668. ExpectIntEQ(BN_rand(bn, 13, WOLFSSL_BN_RAND_TOP_ONE,
  55669. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55670. ExpectIntEQ(BN_num_bits(bn), 13);
  55671. ExpectIntEQ(BN_rand(range, 64, WOLFSSL_BN_RAND_TOP_ONE,
  55672. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55673. ExpectIntEQ(BN_rand_range(bn, range), 1);
  55674. ExpectIntEQ(BN_set_word(range, 0), 1);
  55675. ExpectIntEQ(BN_rand_range(bn, range), 1);
  55676. ExpectIntEQ(BN_set_word(range, 1), 1);
  55677. ExpectIntEQ(BN_rand_range(bn, range), 1);
  55678. BN_free(bn);
  55679. BN_free(range);
  55680. #endif
  55681. return EXPECT_RESULT();
  55682. }
  55683. static int test_wolfSSL_BN_prime(void)
  55684. {
  55685. EXPECT_DECLS;
  55686. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55687. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55688. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || !defined(NO_DSA))
  55689. BIGNUM* a = NULL;
  55690. BIGNUM* add = NULL;
  55691. BIGNUM* rem = NULL;
  55692. BIGNUM emptyBN;
  55693. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55694. ExpectNotNull(a = BN_new());
  55695. ExpectNotNull(add = BN_new());
  55696. ExpectNotNull(rem = BN_new());
  55697. /* Invalid parameters. */
  55698. /* BN_generate_prime_ex()
  55699. * prime - must have valid BIGNUM
  55700. * bits - Greater then 0
  55701. * safe - not supported, must be 0
  55702. * add - not supported, must be NULL
  55703. * rem - not supported, must be NULL
  55704. * cb - anything
  55705. */
  55706. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, rem, NULL), 0);
  55707. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, rem, NULL), 0);
  55708. ExpectIntEQ(BN_generate_prime_ex(a, -1, 1, add, rem, NULL), 0);
  55709. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 1, add, rem, NULL), 0);
  55710. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 1, add, rem, NULL), 0);
  55711. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 0, add, rem, NULL), 0);
  55712. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 0, add, rem, NULL), 0);
  55713. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, NULL, rem, NULL), 0);
  55714. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, NULL, rem, NULL), 0);
  55715. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, NULL, NULL), 0);
  55716. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, NULL, NULL), 0);
  55717. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 0, NULL, NULL, NULL), 0);
  55718. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 0, NULL, NULL, NULL), 0);
  55719. ExpectIntEQ(BN_generate_prime_ex(a, -1, 0, NULL, NULL, NULL), 0);
  55720. ExpectIntEQ(BN_generate_prime_ex(a, 0, 0, NULL, NULL, NULL), 0);
  55721. ExpectIntEQ(BN_generate_prime_ex(a, 2, 1, NULL, NULL, NULL), 0);
  55722. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, add, NULL, NULL), 0);
  55723. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, NULL, rem, NULL), 0);
  55724. ExpectIntEQ(BN_is_prime_ex(NULL, -1, NULL, NULL), -1);
  55725. ExpectIntEQ(BN_is_prime_ex(&emptyBN, -1, NULL, NULL), -1);
  55726. ExpectIntEQ(BN_is_prime_ex(a, -1, NULL, NULL), -1);
  55727. ExpectIntEQ(BN_is_prime_ex(a, 2048, NULL, NULL), -1);
  55728. ExpectIntEQ(BN_is_prime_ex(NULL, 1, NULL, NULL), -1);
  55729. ExpectIntEQ(BN_is_prime_ex(&emptyBN, 1, NULL, NULL), -1);
  55730. /* END Invalid parameters. */
  55731. ExpectIntEQ(BN_generate_prime_ex(a, 512, 0, NULL, NULL, NULL), 1);
  55732. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 1);
  55733. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  55734. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 0);
  55735. BN_free(rem);
  55736. BN_free(add);
  55737. BN_free(a);
  55738. #endif
  55739. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55740. return EXPECT_RESULT();
  55741. }
  55742. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  55743. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  55744. #define TEST_ARG 0x1234
  55745. static void msg_cb(int write_p, int version, int content_type,
  55746. const void *buf, size_t len, SSL *ssl, void *arg)
  55747. {
  55748. (void)write_p;
  55749. (void)version;
  55750. (void)content_type;
  55751. (void)buf;
  55752. (void)len;
  55753. (void)ssl;
  55754. AssertTrue(arg == (void*)TEST_ARG);
  55755. }
  55756. #endif
  55757. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  55758. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  55759. #if defined(SESSION_CERTS)
  55760. #include "wolfssl/internal.h"
  55761. #endif
  55762. static int msgCb(SSL_CTX *ctx, SSL *ssl)
  55763. {
  55764. EXPECT_DECLS;
  55765. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  55766. STACK_OF(X509)* sk = NULL;
  55767. X509* x509 = NULL;
  55768. int i, num;
  55769. BIO* bio = NULL;
  55770. #endif
  55771. ExpectNotNull(ctx);
  55772. ExpectNotNull(ssl);
  55773. fprintf(stderr, "\n===== msgcb called ====\n");
  55774. #if defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)
  55775. ExpectTrue(SSL_get_peer_cert_chain(ssl) != NULL);
  55776. ExpectIntEQ(((WOLFSSL_X509_CHAIN *)SSL_get_peer_cert_chain(ssl))->count, 2);
  55777. ExpectNotNull(SSL_get0_verified_chain(ssl));
  55778. #endif
  55779. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  55780. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  55781. ExpectNotNull(sk = SSL_get_peer_cert_chain(ssl));
  55782. if (sk == NULL) {
  55783. BIO_free(bio);
  55784. return TEST_FAIL;
  55785. }
  55786. num = sk_X509_num(sk);
  55787. ExpectTrue(num > 0);
  55788. for (i = 0; i < num; i++) {
  55789. ExpectNotNull(x509 = sk_X509_value(sk,i));
  55790. if (x509 == NULL)
  55791. break;
  55792. fprintf(stderr, "Certificate at index [%d] = :\n",i);
  55793. X509_print(bio,x509);
  55794. fprintf(stderr, "\n\n");
  55795. }
  55796. BIO_free(bio);
  55797. #endif
  55798. return EXPECT_RESULT();
  55799. }
  55800. #endif
  55801. static int test_wolfSSL_msgCb(void)
  55802. {
  55803. EXPECT_DECLS;
  55804. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  55805. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  55806. test_ssl_cbf client_cb;
  55807. test_ssl_cbf server_cb;
  55808. XMEMSET(&client_cb, 0, sizeof(client_cb));
  55809. XMEMSET(&server_cb, 0, sizeof(server_cb));
  55810. #ifndef WOLFSSL_NO_TLS12
  55811. client_cb.method = wolfTLSv1_2_client_method;
  55812. server_cb.method = wolfTLSv1_2_server_method;
  55813. #else
  55814. client_cb.method = wolfTLSv1_3_client_method;
  55815. server_cb.method = wolfTLSv1_3_server_method;
  55816. #endif
  55817. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  55818. &server_cb, msgCb), TEST_SUCCESS);
  55819. #endif
  55820. return EXPECT_RESULT();
  55821. }
  55822. static int test_wolfSSL_either_side(void)
  55823. {
  55824. EXPECT_DECLS;
  55825. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  55826. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  55827. test_ssl_cbf client_cb;
  55828. test_ssl_cbf server_cb;
  55829. XMEMSET(&client_cb, 0, sizeof(client_cb));
  55830. XMEMSET(&server_cb, 0, sizeof(server_cb));
  55831. /* Use different CTX for client and server */
  55832. client_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  55833. ExpectNotNull(client_cb.ctx);
  55834. server_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  55835. ExpectNotNull(server_cb.ctx);
  55836. /* we are responsible for free'ing WOLFSSL_CTX */
  55837. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  55838. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  55839. &server_cb, NULL), TEST_SUCCESS);
  55840. wolfSSL_CTX_free(client_cb.ctx);
  55841. wolfSSL_CTX_free(server_cb.ctx);
  55842. #endif
  55843. return EXPECT_RESULT();
  55844. }
  55845. static int test_wolfSSL_DTLS_either_side(void)
  55846. {
  55847. EXPECT_DECLS;
  55848. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  55849. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  55850. test_ssl_cbf client_cb;
  55851. test_ssl_cbf server_cb;
  55852. XMEMSET(&client_cb, 0, sizeof(client_cb));
  55853. XMEMSET(&server_cb, 0, sizeof(server_cb));
  55854. /* Use different CTX for client and server */
  55855. client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  55856. ExpectNotNull(client_cb.ctx);
  55857. server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  55858. ExpectNotNull(server_cb.ctx);
  55859. /* we are responsible for free'ing WOLFSSL_CTX */
  55860. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  55861. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  55862. &server_cb, NULL), TEST_SUCCESS);
  55863. wolfSSL_CTX_free(client_cb.ctx);
  55864. wolfSSL_CTX_free(server_cb.ctx);
  55865. #endif
  55866. return EXPECT_RESULT();
  55867. }
  55868. static int test_generate_cookie(void)
  55869. {
  55870. EXPECT_DECLS;
  55871. #if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO)
  55872. SSL_CTX* ctx = NULL;
  55873. SSL* ssl = NULL;
  55874. byte buf[FOURK_BUF] = {0};
  55875. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method()));
  55876. ExpectNotNull(ssl = SSL_new(ctx));
  55877. /* Test unconnected */
  55878. ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E));
  55879. wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie);
  55880. wolfSSL_SetCookieCtx(ssl, ctx);
  55881. ExpectNotNull(wolfSSL_GetCookieCtx(ssl));
  55882. ExpectNull(wolfSSL_GetCookieCtx(NULL));
  55883. SSL_free(ssl);
  55884. SSL_CTX_free(ctx);
  55885. #endif
  55886. return EXPECT_RESULT();
  55887. }
  55888. static int test_wolfSSL_set_options(void)
  55889. {
  55890. EXPECT_DECLS;
  55891. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  55892. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55893. WOLFSSL* ssl = NULL;
  55894. WOLFSSL_CTX* ctx = NULL;
  55895. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  55896. char appData[] = "extra msg";
  55897. #endif
  55898. #ifdef OPENSSL_EXTRA
  55899. unsigned char protos[] = {
  55900. 7, 't', 'l', 's', '/', '1', '.', '2',
  55901. 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
  55902. };
  55903. unsigned int len = sizeof(protos);
  55904. void *arg = (void *)TEST_ARG;
  55905. #endif
  55906. #ifndef NO_WOLFSSL_SERVER
  55907. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  55908. #else
  55909. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55910. #endif
  55911. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  55912. WOLFSSL_FILETYPE_PEM));
  55913. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  55914. WOLFSSL_FILETYPE_PEM));
  55915. ExpectTrue(wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1)
  55916. == WOLFSSL_OP_NO_TLSv1);
  55917. ExpectTrue(wolfSSL_CTX_get_options(ctx) == WOLFSSL_OP_NO_TLSv1);
  55918. ExpectIntGT((int)wolfSSL_CTX_set_options(ctx, (WOLFSSL_OP_COOKIE_EXCHANGE |
  55919. WOLFSSL_OP_NO_SSLv2)), 0);
  55920. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_COOKIE_EXCHANGE) &
  55921. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  55922. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1_2) &
  55923. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  55924. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  55925. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  55926. ExpectFalse((wolfSSL_CTX_clear_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  55927. WOLFSSL_OP_NO_COMPRESSION));
  55928. wolfSSL_CTX_free(ctx);
  55929. ctx = NULL;
  55930. #ifndef NO_WOLFSSL_SERVER
  55931. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  55932. #else
  55933. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55934. #endif
  55935. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  55936. WOLFSSL_FILETYPE_PEM));
  55937. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  55938. WOLFSSL_FILETYPE_PEM));
  55939. #ifdef OPENSSL_EXTRA
  55940. ExpectTrue(wolfSSL_CTX_set_msg_callback(ctx, msg_cb) == WOLFSSL_SUCCESS);
  55941. #endif
  55942. ExpectNotNull(ssl = wolfSSL_new(ctx));
  55943. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  55944. #ifdef HAVE_EX_DATA
  55945. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WOLFSSL_SUCCESS);
  55946. ExpectNotNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  55947. if (ssl != NULL) {
  55948. ExpectIntEQ(XMEMCMP(wolfSSL_get_app_data((const WOLFSSL*)ssl),
  55949. appData, sizeof(appData)), 0);
  55950. }
  55951. #else
  55952. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55953. ExpectNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  55954. #endif
  55955. #endif
  55956. ExpectTrue(wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1) ==
  55957. WOLFSSL_OP_NO_TLSv1);
  55958. ExpectTrue(wolfSSL_get_options(ssl) == WOLFSSL_OP_NO_TLSv1);
  55959. ExpectIntGT((int)wolfSSL_set_options(ssl, (WOLFSSL_OP_COOKIE_EXCHANGE |
  55960. WOLFSSL_OP_NO_SSLv2)), 0);
  55961. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_COOKIE_EXCHANGE) &
  55962. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  55963. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1_2) &
  55964. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  55965. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  55966. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  55967. #ifdef OPENSSL_EXTRA
  55968. ExpectFalse((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  55969. WOLFSSL_OP_NO_COMPRESSION));
  55970. #endif
  55971. #ifdef OPENSSL_EXTRA
  55972. ExpectTrue(wolfSSL_set_msg_callback(ssl, msg_cb) == WOLFSSL_SUCCESS);
  55973. wolfSSL_set_msg_callback_arg(ssl, arg);
  55974. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  55975. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == 0);
  55976. #else
  55977. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == WOLFSSL_SUCCESS);
  55978. #endif
  55979. #endif
  55980. #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
  55981. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_ALL) || \
  55982. defined(HAVE_LIGHTY) || defined(HAVE_STUNNEL)
  55983. #if defined(HAVE_ALPN) && !defined(NO_BIO)
  55984. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  55985. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == 0);
  55986. #else
  55987. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == WOLFSSL_SUCCESS);
  55988. #endif
  55989. #endif /* HAVE_ALPN && !NO_BIO */
  55990. #endif
  55991. wolfSSL_free(ssl);
  55992. wolfSSL_CTX_free(ctx);
  55993. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55994. #endif /* !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  55995. return EXPECT_RESULT();
  55996. }
  55997. static int test_wolfSSL_sk_SSL_CIPHER(void)
  55998. {
  55999. EXPECT_DECLS;
  56000. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  56001. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56002. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56003. SSL* ssl = NULL;
  56004. SSL_CTX* ctx = NULL;
  56005. STACK_OF(SSL_CIPHER) *sk = NULL;
  56006. STACK_OF(SSL_CIPHER) *dupSk = NULL;
  56007. #ifndef NO_WOLFSSL_SERVER
  56008. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56009. #else
  56010. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56011. #endif
  56012. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  56013. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56014. ExpectNotNull(ssl = SSL_new(ctx));
  56015. ExpectNotNull(sk = SSL_get_ciphers(ssl));
  56016. ExpectNotNull(dupSk = sk_SSL_CIPHER_dup(sk));
  56017. ExpectIntGT(sk_SSL_CIPHER_num(sk), 0);
  56018. ExpectIntEQ(sk_SSL_CIPHER_num(sk), sk_SSL_CIPHER_num(dupSk));
  56019. /* error case because connection has not been established yet */
  56020. ExpectIntEQ(sk_SSL_CIPHER_find(sk, SSL_get_current_cipher(ssl)), -1);
  56021. sk_SSL_CIPHER_free(dupSk);
  56022. /* sk is pointer to internal struct that should be free'd in SSL_free */
  56023. SSL_free(ssl);
  56024. SSL_CTX_free(ctx);
  56025. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56026. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56027. !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56028. return EXPECT_RESULT();
  56029. }
  56030. static int test_wolfSSL_set1_curves_list(void)
  56031. {
  56032. EXPECT_DECLS;
  56033. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  56034. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56035. SSL* ssl = NULL;
  56036. SSL_CTX* ctx = NULL;
  56037. #ifndef NO_WOLFSSL_SERVER
  56038. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56039. #else
  56040. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56041. #endif
  56042. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  56043. SSL_FILETYPE_PEM));
  56044. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, SSL_FILETYPE_PEM));
  56045. ExpectNotNull(ssl = SSL_new(ctx));
  56046. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56047. #ifdef HAVE_ECC
  56048. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56049. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-256"), WOLFSSL_SUCCESS);
  56050. #endif
  56051. #ifdef HAVE_CURVE25519
  56052. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WOLFSSL_SUCCESS);
  56053. #else
  56054. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56055. #endif
  56056. #ifdef HAVE_CURVE448
  56057. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WOLFSSL_SUCCESS);
  56058. #else
  56059. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56060. #endif
  56061. ExpectIntEQ(SSL_set1_curves_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56062. #ifdef HAVE_ECC
  56063. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56064. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-256"), WOLFSSL_SUCCESS);
  56065. #endif
  56066. #ifdef HAVE_CURVE25519
  56067. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WOLFSSL_SUCCESS);
  56068. #else
  56069. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56070. #endif
  56071. #ifdef HAVE_CURVE448
  56072. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WOLFSSL_SUCCESS);
  56073. #else
  56074. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56075. #endif
  56076. SSL_free(ssl);
  56077. SSL_CTX_free(ctx);
  56078. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56079. #endif
  56080. return EXPECT_RESULT();
  56081. }
  56082. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56083. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56084. static int test_wolfSSL_curves_mismatch_ctx_ready(WOLFSSL_CTX* ctx)
  56085. {
  56086. static int counter = 0;
  56087. EXPECT_DECLS;
  56088. if (counter % 2) {
  56089. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-256"),
  56090. WOLFSSL_SUCCESS);
  56091. }
  56092. else {
  56093. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-384"),
  56094. WOLFSSL_SUCCESS);
  56095. }
  56096. /* Ciphersuites that require curves */
  56097. wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384:"
  56098. "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-GCM-SHA256:"
  56099. "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:"
  56100. "ECDHE-ECDSA-AES128-GCM-SHA256:"
  56101. "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:"
  56102. "ECDHE-ECDSA-CHACHA20-POLY1305");
  56103. counter++;
  56104. return EXPECT_RESULT();
  56105. }
  56106. #endif
  56107. static int test_wolfSSL_curves_mismatch(void)
  56108. {
  56109. EXPECT_DECLS;
  56110. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56111. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56112. test_ssl_cbf func_cb_client;
  56113. test_ssl_cbf func_cb_server;
  56114. size_t i;
  56115. struct {
  56116. method_provider client_meth;
  56117. method_provider server_meth;
  56118. const char* desc;
  56119. int client_last_err;
  56120. int server_last_err;
  56121. } test_params[] = {
  56122. #ifdef WOLFSSL_TLS13
  56123. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3",
  56124. WC_NO_ERR_TRACE(FATAL_ERROR), WC_NO_ERR_TRACE(BAD_KEY_SHARE_DATA)},
  56125. #endif
  56126. #ifndef WOLFSSL_NO_TLS12
  56127. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2",
  56128. WC_NO_ERR_TRACE(FATAL_ERROR),
  56129. #ifdef OPENSSL_EXTRA
  56130. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56131. #else
  56132. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56133. #endif
  56134. },
  56135. #endif
  56136. #ifndef NO_OLD_TLS
  56137. {wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLS 1.1",
  56138. WC_NO_ERR_TRACE(FATAL_ERROR),
  56139. #ifdef OPENSSL_EXTRA
  56140. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56141. #else
  56142. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56143. #endif
  56144. },
  56145. #endif
  56146. };
  56147. for (i = 0; i < XELEM_CNT(test_params) && !EXPECT_FAIL(); i++) {
  56148. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  56149. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  56150. printf("\tTesting with %s...\n", test_params[i].desc);
  56151. func_cb_client.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56152. func_cb_server.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56153. func_cb_client.method = test_params[i].client_meth;
  56154. func_cb_server.method = test_params[i].server_meth;
  56155. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  56156. &func_cb_server, NULL), TEST_FAIL);
  56157. ExpectIntEQ(func_cb_client.last_err, test_params[i].client_last_err);
  56158. ExpectIntEQ(func_cb_server.last_err, test_params[i].server_last_err);
  56159. if (!EXPECT_SUCCESS())
  56160. break;
  56161. printf("\t%s passed\n", test_params[i].desc);
  56162. }
  56163. #endif
  56164. return EXPECT_RESULT();
  56165. }
  56166. static int test_wolfSSL_set1_sigalgs_list(void)
  56167. {
  56168. EXPECT_DECLS;
  56169. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56170. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56171. SSL* ssl = NULL;
  56172. SSL_CTX* ctx = NULL;
  56173. #ifndef NO_WOLFSSL_SERVER
  56174. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56175. #else
  56176. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56177. #endif
  56178. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56179. SSL_FILETYPE_PEM));
  56180. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56181. ExpectNotNull(ssl = SSL_new(ctx));
  56182. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56183. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56184. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56185. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56186. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56187. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56188. #ifndef NO_RSA
  56189. #ifndef NO_SHA256
  56190. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56191. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56192. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56193. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56194. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256"),
  56195. WOLFSSL_SUCCESS);
  56196. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256"),
  56197. WOLFSSL_SUCCESS);
  56198. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-SHA256"),
  56199. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56200. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-SHA256"),
  56201. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56202. #ifdef WC_RSA_PSS
  56203. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-PSS+SHA256"),
  56204. WOLFSSL_SUCCESS);
  56205. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-PSS+SHA256"),
  56206. WOLFSSL_SUCCESS);
  56207. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "PSS+SHA256"),
  56208. WOLFSSL_SUCCESS);
  56209. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "PSS+SHA256"),
  56210. WOLFSSL_SUCCESS);
  56211. #endif
  56212. #ifdef WOLFSSL_SHA512
  56213. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56214. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56215. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56216. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56217. #elif defined(WOLFSSL_SHA384)
  56218. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56219. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56220. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56221. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56222. #endif
  56223. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56224. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56225. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA:RSA+SHA256"),
  56226. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56227. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA:RSA+SHA256"),
  56228. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56229. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256+SHA256"),
  56230. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56231. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256+RSA"),
  56232. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56233. #endif
  56234. #endif
  56235. #ifdef HAVE_ECC
  56236. #ifndef NO_SHA256
  56237. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ECDSA+SHA256"),
  56238. WOLFSSL_SUCCESS);
  56239. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ECDSA+SHA256"),
  56240. WOLFSSL_SUCCESS);
  56241. #ifdef WOLFSSL_SHA512
  56242. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56243. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56244. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56245. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56246. #elif defined(WOLFSSL_SHA384)
  56247. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56248. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56249. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56250. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56251. #endif
  56252. #endif
  56253. #endif
  56254. #ifdef HAVE_ED25519
  56255. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED25519"), WOLFSSL_SUCCESS);
  56256. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED25519"), WOLFSSL_SUCCESS);
  56257. #endif
  56258. #ifdef HAVE_ED448
  56259. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED448"), WOLFSSL_SUCCESS);
  56260. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED448"), WOLFSSL_SUCCESS);
  56261. #endif
  56262. #ifndef NO_DSA
  56263. #ifndef NO_SHA256
  56264. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA256"),
  56265. WOLFSSL_SUCCESS);
  56266. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA256"),
  56267. WOLFSSL_SUCCESS);
  56268. #endif
  56269. #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
  56270. defined(WOLFSSL_ALLOW_TLS_SHA1))
  56271. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA1"),
  56272. WOLFSSL_SUCCESS);
  56273. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA1"),
  56274. WOLFSSL_SUCCESS);
  56275. #endif
  56276. #endif
  56277. SSL_free(ssl);
  56278. SSL_CTX_free(ctx);
  56279. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56280. #endif
  56281. return EXPECT_RESULT();
  56282. }
  56283. /* Testing wolfSSL_set_tlsext_status_type function.
  56284. * PRE: OPENSSL and HAVE_CERTIFICATE_STATUS_REQUEST defined.
  56285. */
  56286. static int test_wolfSSL_set_tlsext_status_type(void)
  56287. {
  56288. EXPECT_DECLS;
  56289. #if defined(OPENSSL_EXTRA) && defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  56290. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  56291. SSL* ssl = NULL;
  56292. SSL_CTX* ctx = NULL;
  56293. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56294. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56295. SSL_FILETYPE_PEM));
  56296. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56297. ExpectNotNull(ssl = SSL_new(ctx));
  56298. ExpectIntEQ(SSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp),
  56299. SSL_SUCCESS);
  56300. ExpectIntEQ(SSL_get_tlsext_status_type(ssl), TLSEXT_STATUSTYPE_ocsp);
  56301. SSL_free(ssl);
  56302. SSL_CTX_free(ctx);
  56303. #endif /* OPENSSL_EXTRA && HAVE_CERTIFICATE_STATUS_REQUEST && !NO_RSA */
  56304. return EXPECT_RESULT();
  56305. }
  56306. #ifndef NO_BIO
  56307. static int test_wolfSSL_PEM_read_bio(void)
  56308. {
  56309. EXPECT_DECLS;
  56310. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56311. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56312. byte buff[6000];
  56313. XFILE f = XBADFILE;
  56314. int bytes;
  56315. X509* x509 = NULL;
  56316. BIO* bio = NULL;
  56317. BUF_MEM* buf = NULL;
  56318. ExpectTrue((f = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  56319. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  56320. if (f != XBADFILE)
  56321. XFCLOSE(f);
  56322. ExpectNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56323. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  56324. ExpectIntEQ(BIO_set_mem_eof_return(bio, -0xDEAD), 1);
  56325. ExpectNotNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56326. ExpectIntEQ((int)BIO_set_fd(bio, 0, BIO_CLOSE), 1);
  56327. /* BIO should return the set EOF value */
  56328. ExpectIntEQ(BIO_read(bio, buff, sizeof(buff)), -0xDEAD);
  56329. ExpectIntEQ(BIO_set_close(bio, BIO_NOCLOSE), 1);
  56330. ExpectIntEQ(BIO_set_close(NULL, BIO_NOCLOSE), 1);
  56331. ExpectIntEQ(SSL_SUCCESS, BIO_get_mem_ptr(bio, &buf));
  56332. BIO_free(bio);
  56333. BUF_MEM_free(buf);
  56334. X509_free(x509);
  56335. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  56336. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56337. return EXPECT_RESULT();
  56338. }
  56339. #if defined(OPENSSL_EXTRA)
  56340. static long bioCallback(BIO *bio, int cmd, const char* argp, int argi,
  56341. long argl, long ret)
  56342. {
  56343. (void)bio;
  56344. (void)cmd;
  56345. (void)argp;
  56346. (void)argi;
  56347. (void)argl;
  56348. return ret;
  56349. }
  56350. #endif
  56351. static int test_wolfSSL_BIO(void)
  56352. {
  56353. EXPECT_DECLS;
  56354. #if defined(OPENSSL_EXTRA)
  56355. const unsigned char* p = NULL;
  56356. byte buff[20];
  56357. BIO* bio1 = NULL;
  56358. BIO* bio2 = NULL;
  56359. BIO* bio3 = NULL;
  56360. char* bufPt = NULL;
  56361. int i;
  56362. for (i = 0; i < 20; i++) {
  56363. buff[i] = i;
  56364. }
  56365. /* test BIO_free with NULL */
  56366. ExpectIntEQ(BIO_free(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56367. /* Creating and testing type BIO_s_bio */
  56368. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  56369. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  56370. ExpectNotNull(bio3 = BIO_new(BIO_s_bio()));
  56371. /* read/write before set up */
  56372. ExpectIntEQ(BIO_read(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56373. ExpectIntEQ(BIO_write(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56374. ExpectIntEQ(BIO_set_nbio(bio1, 1), 1);
  56375. ExpectIntEQ(BIO_set_write_buf_size(bio1, 20), WOLFSSL_SUCCESS);
  56376. ExpectIntEQ(BIO_set_write_buf_size(bio2, 8), WOLFSSL_SUCCESS);
  56377. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  56378. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 10), 10);
  56379. ExpectNotNull(XMEMCPY(bufPt, buff, 10));
  56380. ExpectIntEQ(BIO_write(bio1, buff + 10, 10), 10);
  56381. /* write buffer full */
  56382. ExpectIntEQ(BIO_write(bio1, buff, 10), WOLFSSL_BIO_ERROR);
  56383. ExpectIntEQ(BIO_flush(bio1), WOLFSSL_SUCCESS);
  56384. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 0);
  56385. /* write the other direction with pair */
  56386. ExpectIntEQ((int)BIO_nwrite(bio2, &bufPt, 10), 8);
  56387. ExpectNotNull(XMEMCPY(bufPt, buff, 8));
  56388. ExpectIntEQ(BIO_write(bio2, buff, 10), WOLFSSL_BIO_ERROR);
  56389. /* try read */
  56390. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 8);
  56391. ExpectIntEQ((int)BIO_ctrl_pending(bio2), 20);
  56392. /* try read using ctrl function */
  56393. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_WPENDING, 0, NULL), 8);
  56394. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_PENDING, 0, NULL), 8);
  56395. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_WPENDING, 0, NULL), 20);
  56396. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_PENDING, 0, NULL), 20);
  56397. ExpectIntEQ(BIO_nread(bio2, &bufPt, (int)BIO_ctrl_pending(bio2)), 20);
  56398. for (i = 0; i < 20; i++) {
  56399. ExpectIntEQ((int)bufPt[i], i);
  56400. }
  56401. ExpectIntEQ(BIO_nread(bio2, &bufPt, 1), 0);
  56402. ExpectIntEQ(BIO_nread(bio1, &bufPt, (int)BIO_ctrl_pending(bio1)), 8);
  56403. for (i = 0; i < 8; i++) {
  56404. ExpectIntEQ((int)bufPt[i], i);
  56405. }
  56406. ExpectIntEQ(BIO_nread(bio1, &bufPt, 1), 0);
  56407. ExpectIntEQ(BIO_ctrl_reset_read_request(bio1), 1);
  56408. /* new pair */
  56409. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56410. BIO_free(bio2); /* free bio2 and automatically remove from pair */
  56411. bio2 = NULL;
  56412. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WOLFSSL_SUCCESS);
  56413. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56414. ExpectIntEQ(BIO_nread(bio3, &bufPt, 10), 0);
  56415. /* test wrap around... */
  56416. ExpectIntEQ(BIO_reset(bio1), 1);
  56417. ExpectIntEQ(BIO_reset(bio3), 1);
  56418. /* fill write buffer, read only small amount then write again */
  56419. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56420. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56421. ExpectIntEQ(BIO_nread(bio3, &bufPt, 4), 4);
  56422. for (i = 0; i < 4; i++) {
  56423. ExpectIntEQ(bufPt[i], i);
  56424. }
  56425. /* try writing over read index */
  56426. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 5), 4);
  56427. ExpectNotNull(XMEMSET(bufPt, 0, 4));
  56428. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 20);
  56429. /* read and write 0 bytes */
  56430. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56431. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 0), 0);
  56432. /* should read only to end of write buffer then need to read again */
  56433. ExpectIntEQ(BIO_nread(bio3, &bufPt, 20), 16);
  56434. for (i = 0; i < 16; i++) {
  56435. ExpectIntEQ(bufPt[i], buff[4 + i]);
  56436. }
  56437. ExpectIntEQ(BIO_nread(bio3, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56438. ExpectIntEQ(BIO_nread0(bio3, &bufPt), 4);
  56439. for (i = 0; i < 4; i++) {
  56440. ExpectIntEQ(bufPt[i], 0);
  56441. }
  56442. /* read index should not have advanced with nread0 */
  56443. ExpectIntEQ(BIO_nread(bio3, &bufPt, 5), 4);
  56444. for (i = 0; i < 4; i++) {
  56445. ExpectIntEQ(bufPt[i], 0);
  56446. }
  56447. /* write and fill up buffer checking reset of index state */
  56448. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56449. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56450. /* test reset on data in bio1 write buffer */
  56451. ExpectIntEQ(BIO_reset(bio1), 1);
  56452. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56453. ExpectIntEQ(BIO_nread(bio3, &bufPt, 3), 0);
  56454. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56455. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_INFO, 0, &p), 20);
  56456. ExpectNotNull(p);
  56457. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56458. ExpectIntEQ(BIO_nread(bio3, &bufPt, 6), 6);
  56459. for (i = 0; i < 6; i++) {
  56460. ExpectIntEQ(bufPt[i], i);
  56461. }
  56462. /* test case of writing twice with offset read index */
  56463. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 3), 3);
  56464. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 3); /* try overwriting */
  56465. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56466. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56467. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56468. ExpectIntEQ(BIO_nread(bio3, &bufPt, 1), 1);
  56469. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 1);
  56470. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56471. BIO_free(bio1);
  56472. bio1 = NULL;
  56473. BIO_free(bio3);
  56474. bio3 = NULL;
  56475. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)
  56476. {
  56477. BIO* bioA = NULL;
  56478. BIO* bioB = NULL;
  56479. ExpectIntEQ(BIO_new_bio_pair(NULL, 256, NULL, 256), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  56480. ExpectIntEQ(BIO_new_bio_pair(&bioA, 256, &bioB, 256), WOLFSSL_SUCCESS);
  56481. BIO_free(bioA);
  56482. bioA = NULL;
  56483. BIO_free(bioB);
  56484. bioB = NULL;
  56485. }
  56486. #endif /* OPENSSL_ALL || WOLFSSL_ASIO */
  56487. /* BIOs with file pointers */
  56488. #if !defined(NO_FILESYSTEM)
  56489. {
  56490. XFILE f1 = XBADFILE;
  56491. XFILE f2 = XBADFILE;
  56492. BIO* f_bio1 = NULL;
  56493. BIO* f_bio2 = NULL;
  56494. unsigned char cert[300];
  56495. char testFile[] = "tests/bio_write_test.txt";
  56496. char msg[] = "bio_write_test.txt contains the first 300 bytes of certs/server-cert.pem\ncreated by tests/unit.test\n\n";
  56497. ExpectNotNull(f_bio1 = BIO_new(BIO_s_file()));
  56498. ExpectNotNull(f_bio2 = BIO_new(BIO_s_file()));
  56499. /* Failure due to wrong BIO type */
  56500. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  56501. ExpectIntEQ((int)BIO_set_mem_eof_return(NULL, -1), 0);
  56502. ExpectTrue((f1 = XFOPEN(svrCertFile, "rwb")) != XBADFILE);
  56503. ExpectIntEQ((int)BIO_set_fp(f_bio1, f1, BIO_CLOSE), WOLFSSL_SUCCESS);
  56504. ExpectIntEQ(BIO_write_filename(f_bio2, testFile),
  56505. WOLFSSL_SUCCESS);
  56506. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  56507. ExpectIntEQ(BIO_tell(f_bio1),sizeof(cert));
  56508. ExpectIntEQ(BIO_write(f_bio2, msg, sizeof(msg)), sizeof(msg));
  56509. ExpectIntEQ(BIO_tell(f_bio2),sizeof(msg));
  56510. ExpectIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert));
  56511. ExpectIntEQ(BIO_tell(f_bio2),sizeof(cert) + sizeof(msg));
  56512. ExpectIntEQ((int)BIO_get_fp(f_bio2, &f2), WOLFSSL_SUCCESS);
  56513. ExpectIntEQ(BIO_reset(f_bio2), 1);
  56514. ExpectIntEQ(BIO_tell(NULL),-1);
  56515. ExpectIntEQ(BIO_tell(f_bio2),0);
  56516. ExpectIntEQ(BIO_seek(f_bio2, 4), 0);
  56517. ExpectIntEQ(BIO_tell(f_bio2),4);
  56518. BIO_free(f_bio1);
  56519. f_bio1 = NULL;
  56520. BIO_free(f_bio2);
  56521. f_bio2 = NULL;
  56522. ExpectNotNull(f_bio1 = BIO_new_file(svrCertFile, "rwb"));
  56523. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  56524. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  56525. BIO_free(f_bio1);
  56526. f_bio1 = NULL;
  56527. }
  56528. #endif /* !defined(NO_FILESYSTEM) */
  56529. /* BIO info callback */
  56530. {
  56531. const char* testArg = "test";
  56532. BIO* cb_bio = NULL;
  56533. ExpectNotNull(cb_bio = BIO_new(BIO_s_mem()));
  56534. BIO_set_callback(cb_bio, bioCallback);
  56535. ExpectNotNull(BIO_get_callback(cb_bio));
  56536. BIO_set_callback(cb_bio, NULL);
  56537. ExpectNull(BIO_get_callback(cb_bio));
  56538. BIO_set_callback_arg(cb_bio, (char*)testArg);
  56539. ExpectStrEQ(BIO_get_callback_arg(cb_bio), testArg);
  56540. ExpectNull(BIO_get_callback_arg(NULL));
  56541. BIO_free(cb_bio);
  56542. cb_bio = NULL;
  56543. }
  56544. /* BIO_vfree */
  56545. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  56546. BIO_vfree(NULL);
  56547. BIO_vfree(bio1);
  56548. #endif
  56549. return EXPECT_RESULT();
  56550. }
  56551. static int test_wolfSSL_BIO_BIO_ring_read(void)
  56552. {
  56553. EXPECT_DECLS;
  56554. #if defined(OPENSSL_ALL)
  56555. BIO* bio1 = NULL;
  56556. BIO* bio2 = NULL;
  56557. byte data[50];
  56558. byte tmp[50];
  56559. XMEMSET(data, 42, sizeof(data));
  56560. ExpectIntEQ(BIO_new_bio_pair(&bio1, sizeof(data), &bio2, sizeof(data)),
  56561. SSL_SUCCESS);
  56562. ExpectIntEQ(BIO_write(bio1, data, 40), 40);
  56563. ExpectIntEQ(BIO_read(bio1, tmp, 20), -1);
  56564. ExpectIntEQ(BIO_read(bio2, tmp, 20), 20);
  56565. ExpectBufEQ(tmp, data, 20);
  56566. ExpectIntEQ(BIO_write(bio1, data, 20), 20);
  56567. ExpectIntEQ(BIO_read(bio2, tmp, 40), 40);
  56568. ExpectBufEQ(tmp, data, 40);
  56569. BIO_free(bio1);
  56570. BIO_free(bio2);
  56571. #endif
  56572. return EXPECT_RESULT();
  56573. }
  56574. #endif /* !NO_BIO */
  56575. static int test_wolfSSL_a2i_IPADDRESS(void)
  56576. {
  56577. EXPECT_DECLS;
  56578. #if defined(OPENSSL_ALL) && !defined(WOLFSSL_USER_IO)
  56579. const unsigned char* data = NULL;
  56580. int dataSz = 0;
  56581. ASN1_OCTET_STRING *st = NULL;
  56582. const unsigned char ipv4_exp[] = {0x7F, 0, 0, 1};
  56583. const unsigned char ipv6_exp[] = {
  56584. 0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  56585. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77
  56586. };
  56587. const unsigned char ipv6_home[] = {
  56588. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56589. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  56590. };
  56591. ExpectNull(st = a2i_IPADDRESS("127.0.0.1bad"));
  56592. ExpectNotNull(st = a2i_IPADDRESS("127.0.0.1"));
  56593. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  56594. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP4_ADDR_LEN);
  56595. ExpectIntEQ(XMEMCMP(data, ipv4_exp, dataSz), 0);
  56596. ASN1_STRING_free(st);
  56597. st = NULL;
  56598. ExpectNotNull(st = a2i_IPADDRESS("::1"));
  56599. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  56600. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  56601. ExpectIntEQ(XMEMCMP(data, ipv6_home, dataSz), 0);
  56602. ASN1_STRING_free(st);
  56603. st = NULL;
  56604. ExpectNotNull(st = a2i_IPADDRESS("2021:db8::ff00:42:7777"));
  56605. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  56606. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  56607. ExpectIntEQ(XMEMCMP(data, ipv6_exp, dataSz), 0);
  56608. ASN1_STRING_free(st);
  56609. #endif
  56610. return EXPECT_RESULT();
  56611. }
  56612. static int test_wolfSSL_X509_cmp_time(void)
  56613. {
  56614. EXPECT_DECLS;
  56615. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) \
  56616. && !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  56617. WOLFSSL_ASN1_TIME asn_time;
  56618. time_t t;
  56619. ExpectIntEQ(0, wolfSSL_X509_cmp_time(NULL, &t));
  56620. XMEMSET(&asn_time, 0, sizeof(WOLFSSL_ASN1_TIME));
  56621. ExpectIntEQ(0, wolfSSL_X509_cmp_time(&asn_time, &t));
  56622. ExpectIntEQ(ASN1_TIME_set_string(&asn_time, "000222211515Z"), 1);
  56623. ExpectIntEQ(-1, wolfSSL_X509_cmp_time(&asn_time, NULL));
  56624. #endif
  56625. return EXPECT_RESULT();
  56626. }
  56627. static int test_wolfSSL_X509_time_adj(void)
  56628. {
  56629. EXPECT_DECLS;
  56630. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  56631. !defined(USER_TIME) && !defined(TIME_OVERRIDES) && \
  56632. defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA) && \
  56633. !defined(NO_ASN_TIME)
  56634. X509* x509 = NULL;
  56635. time_t t;
  56636. time_t not_before;
  56637. time_t not_after;
  56638. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  56639. client_cert_der_2048, sizeof_client_cert_der_2048,
  56640. WOLFSSL_FILETYPE_ASN1));
  56641. t = 0;
  56642. not_before = wc_Time(0);
  56643. not_after = wc_Time(0) + (60 * 24 * 30); /* 30 days after */
  56644. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before, &t));
  56645. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after, &t));
  56646. /* Check X509_gmtime_adj, too. */
  56647. ExpectNotNull(X509_gmtime_adj(X509_get_notAfter(x509), not_after));
  56648. X509_free(x509);
  56649. #endif
  56650. return EXPECT_RESULT();
  56651. }
  56652. static int test_wolfSSL_X509_bad_altname(void)
  56653. {
  56654. EXPECT_DECLS;
  56655. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56656. const unsigned char malformed_alt_name_cert[] = {
  56657. 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1, 0xa0, 0x03, 0x02, 0x01,
  56658. 0x02, 0x02, 0x02, 0x10, 0x21, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  56659. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d,
  56660. 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61, 0x31,
  56661. 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x32, 0x30, 0x37, 0x31,
  56662. 0x37, 0x32, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34, 0x30, 0x32,
  56663. 0x31, 0x34, 0x30, 0x36, 0x32, 0x36, 0x35, 0x33, 0x5a, 0x30, 0x0f, 0x31,
  56664. 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61,
  56665. 0x61, 0x61, 0x30, 0x82, 0x01, 0x20, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  56666. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
  56667. 0x0d, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa8,
  56668. 0x8a, 0x5e, 0x26, 0x23, 0x1b, 0x31, 0xd3, 0x37, 0x1a, 0x70, 0xb2, 0xec,
  56669. 0x3f, 0x74, 0xd4, 0xb4, 0x44, 0xe3, 0x7a, 0xa5, 0xc0, 0xf5, 0xaa, 0x97,
  56670. 0x26, 0x9a, 0x04, 0xff, 0xda, 0xbe, 0xe5, 0x09, 0x03, 0x98, 0x3d, 0xb5,
  56671. 0xbf, 0x01, 0x2c, 0x9a, 0x0a, 0x3a, 0xfb, 0xbc, 0x3c, 0xe7, 0xbe, 0x83,
  56672. 0x5c, 0xb3, 0x70, 0xe8, 0x5c, 0xe3, 0xd1, 0x83, 0xc3, 0x94, 0x08, 0xcd,
  56673. 0x1a, 0x87, 0xe5, 0xe0, 0x5b, 0x9c, 0x5c, 0x6e, 0xb0, 0x7d, 0xe2, 0x58,
  56674. 0x6c, 0xc3, 0xb5, 0xc8, 0x9d, 0x11, 0xf1, 0x5d, 0x96, 0x0d, 0x66, 0x1e,
  56675. 0x56, 0x7f, 0x8f, 0x59, 0xa7, 0xa5, 0xe1, 0xc5, 0xe7, 0x81, 0x4c, 0x09,
  56676. 0x9d, 0x5e, 0x96, 0xf0, 0x9a, 0xc2, 0x8b, 0x70, 0xd5, 0xab, 0x79, 0x58,
  56677. 0x5d, 0xb7, 0x58, 0xaa, 0xfd, 0x75, 0x52, 0xaa, 0x4b, 0xa7, 0x25, 0x68,
  56678. 0x76, 0x59, 0x00, 0xee, 0x78, 0x2b, 0x91, 0xc6, 0x59, 0x91, 0x99, 0x38,
  56679. 0x3e, 0xa1, 0x76, 0xc3, 0xf5, 0x23, 0x6b, 0xe6, 0x07, 0xea, 0x63, 0x1c,
  56680. 0x97, 0x49, 0xef, 0xa0, 0xfe, 0xfd, 0x13, 0xc9, 0xa9, 0x9f, 0xc2, 0x0b,
  56681. 0xe6, 0x87, 0x92, 0x5b, 0xcc, 0xf5, 0x42, 0x95, 0x4a, 0xa4, 0x6d, 0x64,
  56682. 0xba, 0x7d, 0xce, 0xcb, 0x04, 0xd0, 0xf8, 0xe7, 0xe3, 0xda, 0x75, 0x60,
  56683. 0xd3, 0x8b, 0x6a, 0x64, 0xfc, 0x78, 0x56, 0x21, 0x69, 0x5a, 0xe8, 0xa7,
  56684. 0x8f, 0xfb, 0x8f, 0x82, 0xe3, 0xae, 0x36, 0xa2, 0x93, 0x66, 0x92, 0xcb,
  56685. 0x82, 0xa3, 0xbe, 0x84, 0x00, 0x86, 0xdc, 0x7e, 0x6d, 0x53, 0x77, 0x84,
  56686. 0x17, 0xb9, 0x55, 0x43, 0x0d, 0xf1, 0x16, 0x1f, 0xd5, 0x43, 0x75, 0x99,
  56687. 0x66, 0x19, 0x52, 0xd0, 0xac, 0x5f, 0x74, 0xad, 0xb2, 0x90, 0x15, 0x50,
  56688. 0x04, 0x74, 0x43, 0xdf, 0x6c, 0x35, 0xd0, 0xfd, 0x32, 0x37, 0xb3, 0x8d,
  56689. 0xf5, 0xe5, 0x09, 0x02, 0x01, 0x03, 0xa3, 0x61, 0x30, 0x5f, 0x30, 0x0c,
  56690. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
  56691. 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82,
  56692. 0x04, 0x61, 0x2a, 0x00, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
  56693. 0x04, 0x16, 0x04, 0x14, 0x92, 0x6a, 0x1e, 0x52, 0x3a, 0x1a, 0x57, 0x9f,
  56694. 0xc9, 0x82, 0x9a, 0xce, 0xc8, 0xc0, 0xa9, 0x51, 0x9d, 0x2f, 0xc7, 0x72,
  56695. 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
  56696. 0x14, 0x6b, 0xf9, 0xa4, 0x2d, 0xa5, 0xe9, 0x39, 0x89, 0xa8, 0x24, 0x58,
  56697. 0x79, 0x87, 0x11, 0xfc, 0x6f, 0x07, 0x91, 0xef, 0xa6, 0x30, 0x0d, 0x06,
  56698. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
  56699. 0x03, 0x82, 0x01, 0x01, 0x00, 0x3f, 0xd5, 0x37, 0x2f, 0xc7, 0xf8, 0x8b,
  56700. 0x39, 0x1c, 0xe3, 0xdf, 0x77, 0xee, 0xc6, 0x4b, 0x5f, 0x84, 0xcf, 0xfa,
  56701. 0x33, 0x2c, 0xb2, 0xb5, 0x4b, 0x09, 0xee, 0x56, 0xc0, 0xf2, 0xf0, 0xeb,
  56702. 0xad, 0x1c, 0x02, 0xef, 0xae, 0x09, 0x53, 0xc0, 0x06, 0xad, 0x4e, 0xfd,
  56703. 0x3e, 0x8c, 0x13, 0xb3, 0xbf, 0x80, 0x05, 0x36, 0xb5, 0x3f, 0x2b, 0xc7,
  56704. 0x60, 0x53, 0x14, 0xbf, 0x33, 0x63, 0x47, 0xc3, 0xc6, 0x28, 0xda, 0x10,
  56705. 0x12, 0xe2, 0xc4, 0xeb, 0xc5, 0x64, 0x66, 0xc0, 0xcc, 0x6b, 0x84, 0xda,
  56706. 0x0c, 0xe9, 0xf6, 0xe3, 0xf8, 0x8e, 0x3d, 0x95, 0x5f, 0xba, 0x9f, 0xe1,
  56707. 0xc7, 0xed, 0x6e, 0x97, 0xcc, 0xbd, 0x7d, 0xe5, 0x4e, 0xab, 0xbc, 0x1b,
  56708. 0xf1, 0x3a, 0x09, 0x33, 0x09, 0xe1, 0xcc, 0xec, 0x21, 0x16, 0x8e, 0xb1,
  56709. 0x74, 0x9e, 0xc8, 0x13, 0x7c, 0xdf, 0x07, 0xaa, 0xeb, 0x70, 0xd7, 0x91,
  56710. 0x5c, 0xc4, 0xef, 0x83, 0x88, 0xc3, 0xe4, 0x97, 0xfa, 0xe4, 0xdf, 0xd7,
  56711. 0x0d, 0xff, 0xba, 0x78, 0x22, 0xfc, 0x3f, 0xdc, 0xd8, 0x02, 0x8d, 0x93,
  56712. 0x57, 0xf9, 0x9e, 0x39, 0x3a, 0x77, 0x00, 0xd9, 0x19, 0xaa, 0x68, 0xa1,
  56713. 0xe6, 0x9e, 0x13, 0xeb, 0x37, 0x16, 0xf5, 0x77, 0xa4, 0x0b, 0x40, 0x04,
  56714. 0xd3, 0xa5, 0x49, 0x78, 0x35, 0xfa, 0x3b, 0xf6, 0x02, 0xab, 0x85, 0xee,
  56715. 0xcb, 0x9b, 0x62, 0xda, 0x05, 0x00, 0x22, 0x2f, 0xf8, 0xbd, 0x0b, 0xe5,
  56716. 0x2c, 0xb2, 0x53, 0x78, 0x0a, 0xcb, 0x69, 0xc0, 0xb6, 0x9f, 0x96, 0xff,
  56717. 0x58, 0x22, 0x70, 0x9c, 0x01, 0x2e, 0x56, 0x60, 0x5d, 0x37, 0xe3, 0x40,
  56718. 0x25, 0xc9, 0x90, 0xc8, 0x0f, 0x41, 0x68, 0xb4, 0xfd, 0x10, 0xe2, 0x09,
  56719. 0x99, 0x08, 0x5d, 0x7b, 0xc9, 0xe3, 0x29, 0xd4, 0x5a, 0xcf, 0xc9, 0x34,
  56720. 0x55, 0xa1, 0x40, 0x44, 0xd6, 0x88, 0x16, 0xbb, 0xdd
  56721. };
  56722. X509* x509 = NULL;
  56723. int certSize = (int)sizeof(malformed_alt_name_cert) / sizeof(unsigned char);
  56724. const char *name = "aaaaa";
  56725. int nameLen = (int)XSTRLEN(name);
  56726. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  56727. malformed_alt_name_cert, certSize, SSL_FILETYPE_ASN1));
  56728. /* malformed_alt_name_cert has a malformed alternative
  56729. * name of "a*\0*". Ensure that it does not match "aaaaa" */
  56730. ExpectIntNE(wolfSSL_X509_check_host(x509, name, nameLen,
  56731. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  56732. X509_free(x509);
  56733. #endif
  56734. return EXPECT_RESULT();
  56735. }
  56736. static int test_wolfSSL_X509_name_match(void)
  56737. {
  56738. EXPECT_DECLS;
  56739. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56740. /* A certificate with the subject alternative name a* */
  56741. const unsigned char cert_der[] = {
  56742. 0x30, 0x82, 0x03, 0xac, 0x30, 0x82, 0x02, 0x94, 0xa0, 0x03, 0x02, 0x01,
  56743. 0x02, 0x02, 0x14, 0x0f, 0xa5, 0x10, 0x85, 0xef, 0x58, 0x10, 0x59, 0xfc,
  56744. 0x0f, 0x20, 0x1f, 0x53, 0xf5, 0x30, 0x39, 0x34, 0x49, 0x54, 0x05, 0x30,
  56745. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  56746. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  56747. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  56748. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  56749. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  56750. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  56751. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  56752. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  56753. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  56754. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  56755. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  56756. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  56757. 0x30, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  56758. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x30,
  56759. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  56760. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  56761. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  56762. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  56763. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  56764. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  56765. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  56766. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  56767. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  56768. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  56769. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  56770. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  56771. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf4, 0xca, 0x3d,
  56772. 0xd4, 0xbc, 0x9b, 0xea, 0x74, 0xfe, 0x73, 0xf4, 0x16, 0x23, 0x0b, 0x4a,
  56773. 0x09, 0x54, 0xf6, 0x7b, 0x10, 0x99, 0x11, 0x93, 0xb2, 0xdb, 0x4d, 0x7d,
  56774. 0x23, 0xab, 0xf9, 0xcd, 0xf6, 0x54, 0xd4, 0xf6, 0x39, 0x57, 0xee, 0x97,
  56775. 0xb2, 0xb9, 0xfc, 0x7e, 0x9c, 0xb3, 0xfb, 0x56, 0xb6, 0x84, 0xd6, 0x2d,
  56776. 0x59, 0x1c, 0xed, 0xda, 0x9b, 0x19, 0xf5, 0x8a, 0xa7, 0x8a, 0x89, 0xd6,
  56777. 0xa1, 0xc0, 0xe6, 0x16, 0xad, 0x04, 0xcf, 0x5a, 0x1f, 0xdf, 0x62, 0x6c,
  56778. 0x68, 0x45, 0xe9, 0x55, 0x2e, 0x42, 0xa3, 0x1b, 0x3b, 0x86, 0x23, 0x22,
  56779. 0xa1, 0x20, 0x48, 0xd1, 0x52, 0xc0, 0x8b, 0xab, 0xe2, 0x8a, 0x15, 0x68,
  56780. 0xbd, 0x89, 0x6f, 0x9f, 0x45, 0x75, 0xb4, 0x27, 0xc1, 0x72, 0x41, 0xfd,
  56781. 0x79, 0x89, 0xb0, 0x74, 0xa2, 0xe9, 0x61, 0x48, 0x4c, 0x54, 0xad, 0x6b,
  56782. 0x61, 0xbf, 0x0e, 0x27, 0x58, 0xb4, 0xf6, 0x9c, 0x2c, 0x9f, 0xc2, 0x3e,
  56783. 0x3b, 0xb3, 0x90, 0x41, 0xbc, 0x61, 0xcd, 0x01, 0x57, 0x90, 0x82, 0xec,
  56784. 0x46, 0xba, 0x4f, 0x89, 0x8e, 0x7f, 0x49, 0x4f, 0x46, 0x69, 0x37, 0x8b,
  56785. 0xa0, 0xba, 0x85, 0xe8, 0x42, 0xff, 0x9a, 0xa1, 0x53, 0x81, 0x5c, 0xf3,
  56786. 0x8e, 0x85, 0x1c, 0xd4, 0x90, 0x60, 0xa0, 0x37, 0x59, 0x04, 0x65, 0xa6,
  56787. 0xb5, 0x12, 0x00, 0xc3, 0x04, 0x51, 0xa7, 0x83, 0x96, 0x62, 0x3d, 0x49,
  56788. 0x97, 0xe8, 0x6b, 0x9a, 0x5d, 0x51, 0x24, 0xee, 0xad, 0x45, 0x18, 0x0f,
  56789. 0x3f, 0x97, 0xec, 0xdf, 0xcf, 0x42, 0x8a, 0x96, 0xc7, 0xd8, 0x82, 0x87,
  56790. 0x7f, 0x57, 0x70, 0x22, 0xfb, 0x29, 0x3e, 0x3c, 0xa3, 0xc1, 0xd5, 0x71,
  56791. 0xb3, 0x84, 0x06, 0x53, 0xa3, 0x86, 0x20, 0x35, 0xe3, 0x41, 0xb9, 0xd8,
  56792. 0x00, 0x22, 0x4f, 0x6d, 0xe6, 0xfd, 0xf0, 0xf4, 0xa2, 0x39, 0x0a, 0x1a,
  56793. 0x23, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x30, 0x30, 0x2e, 0x30, 0x0d,
  56794. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x06, 0x30, 0x04, 0x82, 0x02, 0x61,
  56795. 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
  56796. 0x45, 0x05, 0xf3, 0x4d, 0x3e, 0x7e, 0x9c, 0xf5, 0x08, 0xee, 0x2c, 0x13,
  56797. 0x32, 0xe3, 0xf2, 0x14, 0xe8, 0x0e, 0x71, 0x21, 0x30, 0x0d, 0x06, 0x09,
  56798. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
  56799. 0x82, 0x01, 0x01, 0x00, 0xa8, 0x28, 0xe5, 0x22, 0x65, 0xcf, 0x47, 0xfe,
  56800. 0x82, 0x17, 0x99, 0x20, 0xdb, 0xb1, 0x57, 0xd4, 0x91, 0x1a, 0x83, 0xde,
  56801. 0xc1, 0xaf, 0xc4, 0x1f, 0xfb, 0xa4, 0x6a, 0xad, 0xdc, 0x58, 0x72, 0xd9,
  56802. 0x9b, 0xab, 0xa5, 0xbb, 0xf4, 0x98, 0xd4, 0xdf, 0x36, 0xcb, 0xb5, 0x78,
  56803. 0xce, 0x4b, 0x25, 0x5b, 0x24, 0x92, 0xfe, 0xe8, 0xd4, 0xe4, 0xbd, 0x6f,
  56804. 0x71, 0x1a, 0x81, 0x2a, 0x6f, 0x35, 0x93, 0xf7, 0xcc, 0xed, 0xe5, 0x06,
  56805. 0xd2, 0x96, 0x41, 0xb5, 0xa9, 0x8a, 0xc0, 0xc9, 0x17, 0xe3, 0x13, 0x5e,
  56806. 0x94, 0x5e, 0xfa, 0xfc, 0xf0, 0x00, 0x2e, 0xe1, 0xd8, 0x1b, 0x23, 0x3f,
  56807. 0x7c, 0x4d, 0x9f, 0xfb, 0xb7, 0x95, 0xc1, 0x94, 0x7f, 0x7f, 0xb5, 0x4f,
  56808. 0x93, 0x6d, 0xc3, 0x2b, 0xb2, 0x28, 0x36, 0xd2, 0x7c, 0x01, 0x3c, 0xae,
  56809. 0x35, 0xdb, 0xc8, 0x95, 0x1b, 0x5f, 0x6c, 0x0f, 0x57, 0xb3, 0xcc, 0x97,
  56810. 0x98, 0x80, 0x06, 0xaa, 0xe4, 0x93, 0x1f, 0xb7, 0xa0, 0x54, 0xf1, 0x4f,
  56811. 0x6f, 0x11, 0xdf, 0xab, 0xd3, 0xbf, 0xf0, 0x3a, 0x81, 0x60, 0xaf, 0x7a,
  56812. 0xf7, 0x09, 0xd5, 0xae, 0x0c, 0x7d, 0xae, 0x8d, 0x47, 0x06, 0xbe, 0x11,
  56813. 0x6e, 0xf8, 0x7e, 0x49, 0xf8, 0xac, 0x24, 0x0a, 0x4b, 0xc2, 0xf6, 0xe8,
  56814. 0x2c, 0xec, 0x35, 0xef, 0xa9, 0x13, 0xb8, 0xd2, 0x9c, 0x92, 0x61, 0x91,
  56815. 0xec, 0x7b, 0x0c, 0xea, 0x9a, 0x71, 0x36, 0x15, 0x34, 0x2b, 0x7a, 0x25,
  56816. 0xac, 0xfe, 0xc7, 0x26, 0x89, 0x70, 0x3e, 0x64, 0x68, 0x97, 0x4b, 0xaa,
  56817. 0xc1, 0x24, 0x14, 0xbd, 0x45, 0x2f, 0xe0, 0xfe, 0xf4, 0x2b, 0x8e, 0x08,
  56818. 0x3e, 0xe4, 0xb5, 0x3d, 0x5d, 0xf4, 0xc3, 0xd6, 0x9c, 0xb5, 0x33, 0x1b,
  56819. 0x3b, 0xda, 0x6e, 0x99, 0x7b, 0x09, 0xd1, 0x30, 0x97, 0x23, 0x52, 0x6d,
  56820. 0x1b, 0x71, 0x3a, 0xf4, 0x54, 0xf0, 0xe5, 0x9e
  56821. };
  56822. WOLFSSL_X509* x509 = NULL;
  56823. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  56824. const char *name1 = "aaaaa";
  56825. int nameLen1 = (int)(XSTRLEN(name1));
  56826. const char *name2 = "a";
  56827. int nameLen2 = (int)(XSTRLEN(name2));
  56828. const char *name3 = "abbbb";
  56829. int nameLen3 = (int)(XSTRLEN(name3));
  56830. const char *name4 = "bbb";
  56831. int nameLen4 = (int)(XSTRLEN(name4));
  56832. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  56833. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  56834. /* Ensure that "a*" matches "aaaaa" */
  56835. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  56836. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56837. /* Ensure that "a*" matches "a" */
  56838. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  56839. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56840. /* Ensure that "a*" matches "abbbb" */
  56841. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  56842. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56843. /* Ensure that "a*" does not match "bbb" */
  56844. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  56845. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  56846. wolfSSL_X509_free(x509);
  56847. #endif
  56848. return EXPECT_RESULT();
  56849. }
  56850. static int test_wolfSSL_X509_name_match2(void)
  56851. {
  56852. EXPECT_DECLS;
  56853. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56854. /* A certificate with the subject alternative name a*b* */
  56855. const unsigned char cert_der[] = {
  56856. 0x30, 0x82, 0x03, 0xae, 0x30, 0x82, 0x02, 0x96, 0xa0, 0x03, 0x02, 0x01,
  56857. 0x02, 0x02, 0x14, 0x41, 0x8c, 0x8b, 0xaa, 0x0e, 0xd8, 0x5a, 0xc0, 0x52,
  56858. 0x46, 0x0e, 0xe5, 0xd8, 0xb9, 0x48, 0x93, 0x7e, 0x8a, 0x7c, 0x65, 0x30,
  56859. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  56860. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  56861. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  56862. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  56863. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  56864. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  56865. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  56866. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  56867. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  56868. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  56869. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  56870. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  56871. 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  56872. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x30,
  56873. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  56874. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  56875. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  56876. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  56877. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  56878. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  56879. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  56880. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  56881. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  56882. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  56883. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  56884. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  56885. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa5, 0x60, 0x80,
  56886. 0xf3, 0xee, 0x19, 0xd2, 0xe4, 0x15, 0x94, 0x54, 0x12, 0x88, 0xee, 0xda,
  56887. 0x11, 0x11, 0x87, 0x99, 0x88, 0xb3, 0x71, 0xc7, 0x97, 0x78, 0x1b, 0x57,
  56888. 0x37, 0x1d, 0x0b, 0x1f, 0x2f, 0x2c, 0x35, 0x13, 0x75, 0xd3, 0x31, 0x3e,
  56889. 0x6f, 0x80, 0x21, 0xa5, 0xa3, 0xad, 0x10, 0x81, 0xb6, 0x37, 0xd4, 0x55,
  56890. 0x2e, 0xc1, 0xb8, 0x37, 0xa3, 0x3c, 0xe8, 0x81, 0x03, 0x3c, 0xda, 0x5f,
  56891. 0x6f, 0x45, 0x32, 0x2b, 0x0e, 0x99, 0x27, 0xfd, 0xe5, 0x6c, 0x07, 0xd9,
  56892. 0x4e, 0x0a, 0x8b, 0x23, 0x74, 0x96, 0x25, 0x97, 0xae, 0x6d, 0x19, 0xba,
  56893. 0xbf, 0x0f, 0xc8, 0xa1, 0xe5, 0xea, 0xa8, 0x00, 0x09, 0xc3, 0x9a, 0xef,
  56894. 0x09, 0x33, 0xc1, 0x33, 0x2e, 0x7b, 0x6d, 0xa7, 0x66, 0x87, 0xb6, 0x3a,
  56895. 0xb9, 0xdb, 0x4c, 0x5e, 0xb5, 0x55, 0x69, 0x37, 0x17, 0x92, 0x1f, 0xe3,
  56896. 0x53, 0x1a, 0x2d, 0x25, 0xd0, 0xcf, 0x72, 0x37, 0xc2, 0x89, 0x83, 0x78,
  56897. 0xcf, 0xac, 0x2e, 0x46, 0x92, 0x5c, 0x4a, 0xba, 0x7d, 0xa0, 0x22, 0x34,
  56898. 0xb1, 0x22, 0x26, 0x99, 0xda, 0xe8, 0x97, 0xe2, 0x0c, 0xd3, 0xbc, 0x97,
  56899. 0x7e, 0xa8, 0xb9, 0xe3, 0xe2, 0x7f, 0x56, 0xef, 0x22, 0xee, 0x15, 0x95,
  56900. 0xa6, 0xd1, 0xf4, 0xa7, 0xac, 0x4a, 0xab, 0xc1, 0x1a, 0xda, 0xc5, 0x5f,
  56901. 0xa5, 0x5e, 0x2f, 0x15, 0x9c, 0x36, 0xbe, 0xd3, 0x47, 0xb6, 0x86, 0xb9,
  56902. 0xc6, 0x59, 0x39, 0x36, 0xad, 0x84, 0x53, 0x95, 0x72, 0x91, 0x89, 0x51,
  56903. 0x32, 0x77, 0xf1, 0xa5, 0x93, 0xfe, 0xf0, 0x41, 0x7c, 0x64, 0xf1, 0xb0,
  56904. 0x8b, 0x81, 0x8d, 0x3a, 0x2c, 0x9e, 0xbe, 0x2e, 0x8b, 0xf7, 0x80, 0x63,
  56905. 0x35, 0x32, 0xfa, 0x26, 0xe0, 0x63, 0xbf, 0x5e, 0xaf, 0xf0, 0x08, 0xe0,
  56906. 0x80, 0x65, 0x38, 0xfa, 0x21, 0xaa, 0x91, 0x34, 0x48, 0x3d, 0x32, 0x5c,
  56907. 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x32, 0x30, 0x30, 0x30, 0x0f,
  56908. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82, 0x04, 0x61,
  56909. 0x2a, 0x62, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
  56910. 0x04, 0x14, 0x3d, 0x55, 0x74, 0xf8, 0x3a, 0x26, 0x03, 0x8c, 0x6a, 0x2e,
  56911. 0x91, 0x0e, 0x18, 0x70, 0xb4, 0xa4, 0xcc, 0x04, 0x00, 0xd3, 0x30, 0x0d,
  56912. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  56913. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8f, 0x3b, 0xff, 0x46, 0x0c, 0xb5,
  56914. 0x21, 0xdc, 0xcf, 0x61, 0x9a, 0x25, 0x93, 0x99, 0x68, 0x2f, 0x16, 0x71,
  56915. 0x15, 0x00, 0x5f, 0xb0, 0x9b, 0x43, 0x5c, 0x47, 0xe2, 0x8e, 0xc8, 0xea,
  56916. 0xb3, 0x30, 0x4d, 0x87, 0x90, 0xcf, 0x24, 0x37, 0x5c, 0xfd, 0xc8, 0xc6,
  56917. 0x09, 0x36, 0xb2, 0xfb, 0xfd, 0xc1, 0x82, 0x92, 0x77, 0x5b, 0x9d, 0xeb,
  56918. 0xac, 0x47, 0xbc, 0xda, 0x7c, 0x89, 0x19, 0x03, 0x9e, 0xcd, 0x96, 0x2a,
  56919. 0x90, 0x55, 0x23, 0x19, 0xac, 0x9d, 0x49, 0xfb, 0xa0, 0x31, 0x7d, 0x6b,
  56920. 0x1a, 0x16, 0x13, 0xb1, 0xa9, 0xc9, 0xc4, 0xaf, 0xf1, 0xb4, 0xa7, 0x9b,
  56921. 0x08, 0x64, 0x6a, 0x09, 0xcd, 0x4a, 0x03, 0x4c, 0x93, 0xb6, 0xcf, 0x29,
  56922. 0xdb, 0x56, 0x88, 0x8e, 0xed, 0x08, 0x6d, 0x8d, 0x76, 0xa3, 0xd7, 0xc6,
  56923. 0x69, 0xa1, 0xf5, 0xd2, 0xd0, 0x0a, 0x4b, 0xfa, 0x88, 0x66, 0x6c, 0xe5,
  56924. 0x4a, 0xee, 0x13, 0xad, 0xad, 0x22, 0x25, 0x73, 0x39, 0x56, 0x74, 0x0e,
  56925. 0xda, 0xcd, 0x35, 0x67, 0xe3, 0x81, 0x5c, 0xc5, 0xae, 0x3c, 0x4f, 0x47,
  56926. 0x3e, 0x97, 0xde, 0xac, 0xf6, 0xe1, 0x26, 0xe2, 0xe0, 0x66, 0x48, 0x20,
  56927. 0x7c, 0x02, 0x81, 0x3e, 0x7d, 0x34, 0xb7, 0x73, 0x3e, 0x2e, 0xd6, 0x20,
  56928. 0x1c, 0xdf, 0xf1, 0xae, 0x86, 0x8b, 0xb2, 0xc2, 0x9b, 0x68, 0x9c, 0xf6,
  56929. 0x1a, 0x5e, 0x30, 0x06, 0x39, 0x0a, 0x1f, 0x7b, 0xd7, 0x18, 0x4b, 0x06,
  56930. 0x9d, 0xff, 0x84, 0x57, 0xcc, 0x92, 0xad, 0x81, 0x0a, 0x19, 0x11, 0xc4,
  56931. 0xac, 0x59, 0x00, 0xe8, 0x5a, 0x70, 0x78, 0xd6, 0x9f, 0xe0, 0x82, 0x2a,
  56932. 0x1f, 0x09, 0x36, 0x1c, 0x52, 0x98, 0xf7, 0x95, 0x8f, 0xf9, 0x48, 0x4f,
  56933. 0x30, 0x52, 0xb5, 0xf3, 0x8d, 0x13, 0x93, 0x27, 0xbe, 0xb4, 0x75, 0x39,
  56934. 0x65, 0xc6, 0x48, 0x4e, 0x32, 0xd7, 0xf4, 0xc3, 0x26, 0x8d
  56935. };
  56936. WOLFSSL_X509* x509 = NULL;
  56937. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  56938. const char *name1 = "ab";
  56939. int nameLen1 = (int)(XSTRLEN(name1));
  56940. const char *name2 = "acccbccc";
  56941. int nameLen2 = (int)(XSTRLEN(name2));
  56942. const char *name3 = "accb";
  56943. int nameLen3 = (int)(XSTRLEN(name3));
  56944. const char *name4 = "accda";
  56945. int nameLen4 = (int)(XSTRLEN(name4));
  56946. const char *name5 = "acc\0bcc";
  56947. int nameLen5 = 7;
  56948. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  56949. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  56950. /* Ensure that "a*b*" matches "ab" */
  56951. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  56952. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56953. /* Ensure that "a*b*" matches "acccbccc" */
  56954. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  56955. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56956. /* Ensure that "a*b*" matches "accb" */
  56957. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  56958. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56959. /* Ensure that "a*b*" does not match "accda" */
  56960. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  56961. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56962. /* Ensure that "a*b*" matches "ab", testing openssl behavior replication
  56963. * on check len input handling, 0 for len is OK as it should then use
  56964. * strlen(name1) */
  56965. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, 0,
  56966. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56967. /* Openssl also allows for len to include NULL terminator */
  56968. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1 + 1,
  56969. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56970. /* Ensure that check string with NULL terminator in middle is
  56971. * rejected */
  56972. ExpectIntNE(wolfSSL_X509_check_host(x509, name5, nameLen5,
  56973. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  56974. wolfSSL_X509_free(x509);
  56975. #endif
  56976. return EXPECT_RESULT();
  56977. }
  56978. static int test_wolfSSL_X509_name_match3(void)
  56979. {
  56980. EXPECT_DECLS;
  56981. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56982. /* A certificate with the subject alternative name *.example.com */
  56983. const unsigned char cert_der[] = {
  56984. 0x30, 0x82, 0x03, 0xb7, 0x30, 0x82, 0x02, 0x9f, 0xa0, 0x03, 0x02, 0x01,
  56985. 0x02, 0x02, 0x14, 0x59, 0xbb, 0xf6, 0xde, 0xb8, 0x3d, 0x0e, 0x8c, 0xe4,
  56986. 0xbd, 0x98, 0xa3, 0xbe, 0x3e, 0x8f, 0xdc, 0xbd, 0x7f, 0xcc, 0xae, 0x30,
  56987. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  56988. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  56989. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  56990. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  56991. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  56992. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  56993. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  56994. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  56995. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  56996. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  56997. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  56998. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  56999. 0x31, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57000. 0x30, 0x35, 0x32, 0x39, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x30,
  57001. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57002. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57003. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57004. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57005. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57006. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57007. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57008. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57009. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57010. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57011. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57012. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57013. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xda, 0x78, 0x16,
  57014. 0x05, 0x65, 0xf2, 0x85, 0xf2, 0x61, 0x7f, 0xb1, 0x4d, 0x73, 0xe2, 0x82,
  57015. 0xb5, 0x3d, 0xf7, 0x9d, 0x05, 0x65, 0xed, 0x9d, 0xc3, 0x29, 0x7a, 0x92,
  57016. 0x2c, 0x06, 0x5f, 0xc8, 0x13, 0x55, 0x42, 0x4e, 0xbd, 0xe2, 0x56, 0x2a,
  57017. 0x4b, 0xac, 0xe6, 0x1b, 0x10, 0xc9, 0xdb, 0x9a, 0x45, 0x36, 0xed, 0xf3,
  57018. 0x26, 0x8c, 0x22, 0x88, 0x1e, 0x6d, 0x2b, 0x41, 0xfa, 0x0d, 0x43, 0x88,
  57019. 0x88, 0xde, 0x8d, 0x2e, 0xca, 0x6e, 0x7c, 0x62, 0x66, 0x3e, 0xfa, 0x4e,
  57020. 0x71, 0xea, 0x7d, 0x3b, 0x32, 0x33, 0x5c, 0x7a, 0x7e, 0xea, 0x74, 0xbd,
  57021. 0xb6, 0x8f, 0x4c, 0x1c, 0x7a, 0x79, 0x94, 0xf1, 0xe8, 0x02, 0x67, 0x98,
  57022. 0x25, 0xb4, 0x31, 0x80, 0xc1, 0xae, 0xbf, 0xef, 0xf2, 0x6c, 0x78, 0x42,
  57023. 0xef, 0xb5, 0xc6, 0x01, 0x47, 0x79, 0x8d, 0x92, 0xce, 0xc1, 0xb5, 0x98,
  57024. 0x76, 0xf0, 0x84, 0xa2, 0x53, 0x90, 0xe5, 0x39, 0xc7, 0xbd, 0xf2, 0xbb,
  57025. 0xe3, 0x3f, 0x00, 0xf6, 0xf0, 0x46, 0x86, 0xee, 0x55, 0xbd, 0x2c, 0x1f,
  57026. 0x97, 0x24, 0x7c, 0xbc, 0xda, 0x2f, 0x1b, 0x53, 0xef, 0x26, 0x56, 0xcc,
  57027. 0xb7, 0xd8, 0xca, 0x17, 0x20, 0x4e, 0x62, 0x03, 0x66, 0x32, 0xb3, 0xd1,
  57028. 0x71, 0x26, 0x6c, 0xff, 0xd1, 0x9e, 0x44, 0x86, 0x2a, 0xae, 0xba, 0x43,
  57029. 0x00, 0x13, 0x7e, 0x50, 0xdd, 0x3e, 0x27, 0x39, 0x70, 0x1c, 0x0c, 0x0b,
  57030. 0xe8, 0xa2, 0xae, 0x03, 0x09, 0x2e, 0xd8, 0x71, 0xee, 0x7b, 0x1a, 0x09,
  57031. 0x2d, 0xe1, 0xd5, 0xde, 0xf5, 0xa3, 0x36, 0x77, 0x90, 0x97, 0x99, 0xd7,
  57032. 0x6c, 0xb7, 0x5c, 0x9d, 0xf7, 0x7e, 0x41, 0x89, 0xfe, 0xe4, 0x08, 0xc6,
  57033. 0x0b, 0xe4, 0x9b, 0x5f, 0x51, 0xa6, 0x08, 0xb8, 0x99, 0x81, 0xe9, 0xce,
  57034. 0xb4, 0x2d, 0xb2, 0x92, 0x9f, 0xe5, 0x1a, 0x98, 0x76, 0x20, 0x70, 0x54,
  57035. 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x18,
  57036. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x11, 0x30, 0x0f, 0x82, 0x0d, 0x2a,
  57037. 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
  57038. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x60,
  57039. 0xd4, 0x26, 0xbb, 0xcc, 0x7c, 0x29, 0xa2, 0x88, 0x3c, 0x76, 0x7d, 0xb4,
  57040. 0x86, 0x8b, 0x47, 0x64, 0x5b, 0x87, 0xe0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  57041. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  57042. 0x01, 0x01, 0x00, 0xc3, 0x0d, 0x03, 0x67, 0xbb, 0x47, 0x8b, 0xf3, 0x20,
  57043. 0xdc, 0x7d, 0x2e, 0xe1, 0xd9, 0xf0, 0x01, 0xc4, 0x66, 0xc2, 0xe1, 0xcd,
  57044. 0xc3, 0x4a, 0x72, 0xf0, 0x6e, 0x38, 0xcf, 0x63, 0x01, 0x96, 0x9e, 0x84,
  57045. 0xb9, 0xce, 0x1d, 0xba, 0x4b, 0xe0, 0x70, 0x86, 0x2b, 0x5a, 0xab, 0xec,
  57046. 0xbf, 0xc2, 0xaa, 0x64, 0xa2, 0x6c, 0xd2, 0x42, 0x52, 0xd4, 0xbe, 0x8a,
  57047. 0xca, 0x9c, 0x03, 0xf3, 0xd6, 0x5f, 0xcd, 0x23, 0x9f, 0xf5, 0xa9, 0x04,
  57048. 0x40, 0x5b, 0x66, 0x78, 0xc0, 0xac, 0xa1, 0xdb, 0x5d, 0xd1, 0x94, 0xfc,
  57049. 0x47, 0x94, 0xf5, 0x45, 0xe3, 0x70, 0x13, 0x3f, 0x66, 0x6d, 0xdd, 0x73,
  57050. 0x68, 0x68, 0xe2, 0xd2, 0x89, 0xcb, 0x7f, 0xc6, 0xca, 0xd6, 0x96, 0x0b,
  57051. 0xcc, 0xdd, 0xa1, 0x74, 0xda, 0x33, 0xe8, 0x9e, 0xda, 0xb7, 0xd9, 0x12,
  57052. 0xab, 0x85, 0x9d, 0x0c, 0xde, 0xa0, 0x7d, 0x7e, 0xa1, 0x91, 0xed, 0xe5,
  57053. 0x32, 0x7c, 0xc5, 0xea, 0x1d, 0x4a, 0xb5, 0x38, 0x63, 0x17, 0xf3, 0x4f,
  57054. 0x2c, 0x4a, 0x58, 0x86, 0x09, 0x33, 0x86, 0xc4, 0xe7, 0x56, 0x6f, 0x32,
  57055. 0x71, 0xb7, 0xd0, 0x83, 0x12, 0x9e, 0x26, 0x0a, 0x3a, 0x45, 0xcb, 0xd7,
  57056. 0x4e, 0xab, 0xa4, 0xc3, 0xee, 0x4c, 0xc0, 0x38, 0xa1, 0xfa, 0xba, 0xfa,
  57057. 0xb7, 0x80, 0x69, 0x67, 0xa3, 0xef, 0x89, 0xba, 0xce, 0x89, 0x91, 0x3d,
  57058. 0x6a, 0x76, 0xe9, 0x3b, 0x32, 0x86, 0x76, 0x85, 0x6b, 0x4f, 0x7f, 0xbc,
  57059. 0x7a, 0x5b, 0x31, 0x92, 0x79, 0x35, 0xf8, 0xb9, 0xb1, 0xd7, 0xdb, 0xa9,
  57060. 0x6a, 0x8a, 0x91, 0x60, 0x65, 0xd4, 0x76, 0x54, 0x55, 0x57, 0xb9, 0x35,
  57061. 0xe0, 0xf5, 0xbb, 0x8f, 0xd4, 0x40, 0x75, 0xbb, 0x47, 0xa8, 0xf9, 0x0f,
  57062. 0xea, 0xc9, 0x6e, 0x84, 0xd5, 0xf5, 0x58, 0x2d, 0xe5, 0x76, 0x7b, 0xdf,
  57063. 0x97, 0x05, 0x5e, 0xaf, 0x50, 0xf5, 0x48
  57064. };
  57065. WOLFSSL_X509* x509 = NULL;
  57066. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57067. const char *name1 = "foo.example.com";
  57068. int nameLen1 = (int)(XSTRLEN(name1));
  57069. const char *name2 = "x.y.example.com";
  57070. int nameLen2 = (int)(XSTRLEN(name2));
  57071. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57072. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57073. /* Ensure that "*.example.com" matches "foo.example.com" */
  57074. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57075. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57076. /* Ensure that "*.example.com" does NOT match "x.y.example.com" */
  57077. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57078. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57079. wolfSSL_X509_free(x509);
  57080. #endif
  57081. return EXPECT_RESULT();
  57082. }
  57083. static int test_wolfSSL_X509_max_altnames(void)
  57084. {
  57085. EXPECT_DECLS;
  57086. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  57087. /* Only test if max alt names has not been modified */
  57088. #if WOLFSSL_MAX_ALT_NAMES <= 1024
  57089. WOLFSSL_CTX* ctx = NULL;
  57090. /* File contains a certificate encoded with 130 subject alternative names */
  57091. const char* over_max_altnames_cert = \
  57092. "./certs/test/cert-over-max-altnames.pem";
  57093. #ifndef NO_WOLFSSL_SERVER
  57094. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57095. #else
  57096. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57097. #endif
  57098. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx,
  57099. over_max_altnames_cert, NULL, WOLFSSL_LOAD_FLAG_NONE),
  57100. WOLFSSL_SUCCESS);
  57101. wolfSSL_CTX_free(ctx);
  57102. #endif
  57103. #endif
  57104. return EXPECT_RESULT();
  57105. }
  57106. static int test_wolfSSL_X509_max_name_constraints(void)
  57107. {
  57108. EXPECT_DECLS;
  57109. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  57110. !defined(IGNORE_NAME_CONSTRAINTS)
  57111. /* Only test if max name constraints has not been modified */
  57112. #if WOLFSSL_MAX_NAME_CONSTRAINTS == 128
  57113. WOLFSSL_CTX* ctx = NULL;
  57114. /* File contains a certificate with 130 name constraints */
  57115. const char* over_max_nc = "./certs/test/cert-over-max-nc.pem";
  57116. #ifndef NO_WOLFSSL_SERVER
  57117. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57118. #else
  57119. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57120. #endif
  57121. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, over_max_nc,
  57122. NULL, WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  57123. wolfSSL_CTX_free(ctx);
  57124. #endif
  57125. #endif
  57126. return EXPECT_RESULT();
  57127. }
  57128. static int test_wolfSSL_X509(void)
  57129. {
  57130. EXPECT_DECLS;
  57131. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57132. !defined(NO_RSA)
  57133. X509* x509 = NULL;
  57134. #ifndef NO_BIO
  57135. BIO* bio = NULL;
  57136. X509_STORE_CTX* ctx = NULL;
  57137. X509_STORE* store = NULL;
  57138. #endif
  57139. char der[] = "certs/ca-cert.der";
  57140. XFILE fp = XBADFILE;
  57141. ExpectNotNull(x509 = X509_new());
  57142. X509_free(x509);
  57143. x509 = NULL;
  57144. #ifndef NO_BIO
  57145. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  57146. SSL_FILETYPE_PEM));
  57147. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  57148. #ifdef WOLFSSL_CERT_GEN
  57149. ExpectIntEQ(i2d_X509_bio(bio, x509), SSL_SUCCESS);
  57150. #endif
  57151. ExpectNotNull(ctx = X509_STORE_CTX_new());
  57152. ExpectIntEQ(X509_verify_cert(ctx), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  57153. ExpectNotNull(store = X509_STORE_new());
  57154. ExpectIntEQ(X509_STORE_add_cert(store, x509), SSL_SUCCESS);
  57155. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, x509, NULL), SSL_SUCCESS);
  57156. ExpectIntEQ(X509_verify_cert(ctx), SSL_SUCCESS);
  57157. X509_STORE_CTX_free(ctx);
  57158. X509_STORE_free(store);
  57159. X509_free(x509);
  57160. x509 = NULL;
  57161. BIO_free(bio);
  57162. #endif
  57163. /** d2i_X509_fp test **/
  57164. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57165. ExpectNotNull(x509 = (X509 *)d2i_X509_fp(fp, (X509 **)NULL));
  57166. ExpectNotNull(x509);
  57167. X509_free(x509);
  57168. x509 = NULL;
  57169. if (fp != XBADFILE) {
  57170. XFCLOSE(fp);
  57171. fp = XBADFILE;
  57172. }
  57173. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57174. ExpectNotNull((X509 *)d2i_X509_fp(fp, (X509 **)&x509));
  57175. ExpectNotNull(x509);
  57176. X509_free(x509);
  57177. if (fp != XBADFILE)
  57178. XFCLOSE(fp);
  57179. /* X509_up_ref test */
  57180. ExpectIntEQ(X509_up_ref(NULL), 0);
  57181. ExpectNotNull(x509 = X509_new()); /* refCount = 1 */
  57182. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 2 */
  57183. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 3 */
  57184. X509_free(x509); /* refCount = 2 */
  57185. X509_free(x509); /* refCount = 1 */
  57186. X509_free(x509); /* refCount = 0, free */
  57187. #endif
  57188. return EXPECT_RESULT();
  57189. }
  57190. static int test_wolfSSL_X509_get_ext_count(void)
  57191. {
  57192. EXPECT_DECLS;
  57193. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57194. !defined(NO_RSA)
  57195. int ret = 0;
  57196. WOLFSSL_X509* x509 = NULL;
  57197. const char ocspRootCaFile[] = "./certs/ocsp/root-ca-cert.pem";
  57198. XFILE f = XBADFILE;
  57199. /* NULL parameter check */
  57200. ExpectIntEQ(X509_get_ext_count(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57201. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  57202. SSL_FILETYPE_PEM));
  57203. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57204. wolfSSL_X509_free(x509);
  57205. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ocspRootCaFile,
  57206. SSL_FILETYPE_PEM));
  57207. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57208. wolfSSL_X509_free(x509);
  57209. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  57210. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  57211. if (f != XBADFILE)
  57212. XFCLOSE(f);
  57213. /* wolfSSL_X509_get_ext_count() valid input */
  57214. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  57215. /* wolfSSL_X509_get_ext_count() NULL argument */
  57216. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(NULL)), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57217. wolfSSL_X509_free(x509);
  57218. #endif
  57219. return EXPECT_RESULT();
  57220. }
  57221. static int test_wolfSSL_X509_sign2(void)
  57222. {
  57223. EXPECT_DECLS;
  57224. /* test requires WOLFSSL_AKID_NAME to match expected output */
  57225. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  57226. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_ALT_NAMES) && \
  57227. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_AKID_NAME) && \
  57228. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  57229. defined(WOLFSSL_IP_ALT_NAME))
  57230. WOLFSSL_X509 *x509 = NULL;
  57231. WOLFSSL_X509 *ca = NULL;
  57232. const unsigned char *der = NULL;
  57233. const unsigned char *pt = NULL;
  57234. WOLFSSL_EVP_PKEY *priv = NULL;
  57235. WOLFSSL_X509_NAME *name = NULL;
  57236. int derSz;
  57237. #ifndef NO_ASN_TIME
  57238. WOLFSSL_ASN1_TIME *notBefore = NULL;
  57239. WOLFSSL_ASN1_TIME *notAfter = NULL;
  57240. const int year = 365*24*60*60;
  57241. const int day = 24*60*60;
  57242. const int hour = 60*60;
  57243. const int mini = 60;
  57244. time_t t;
  57245. #endif
  57246. const unsigned char expected[] = {
  57247. 0x30, 0x82, 0x05, 0x13, 0x30, 0x82, 0x03, 0xFB, 0xA0, 0x03, 0x02, 0x01,
  57248. 0x02, 0x02, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55, 0x8A,
  57249. 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8, 0x30,
  57250. 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
  57251. 0x05, 0x00, 0x30, 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55,
  57252. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  57253. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61,
  57254. 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  57255. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03,
  57256. 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74,
  57257. 0x68, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x0A,
  57258. 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18,
  57259. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77,
  57260. 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D,
  57261. 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57262. 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F,
  57263. 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x1E, 0x17,
  57264. 0x0D, 0x30, 0x30, 0x30, 0x32, 0x31, 0x35, 0x32, 0x30, 0x33, 0x30, 0x30,
  57265. 0x30, 0x5A, 0x17, 0x0D, 0x30, 0x31, 0x30, 0x32, 0x31, 0x34, 0x32, 0x30,
  57266. 0x33, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30, 0x09,
  57267. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30,
  57268. 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74,
  57269. 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07,
  57270. 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15, 0x30,
  57271. 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C, 0x77, 0x6F, 0x6C, 0x66,
  57272. 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38, 0x31, 0x19, 0x30, 0x17,
  57273. 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50, 0x72, 0x6F, 0x67, 0x72,
  57274. 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32, 0x30, 0x34, 0x38, 0x31,
  57275. 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77,
  57276. 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F,
  57277. 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
  57278. 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77,
  57279. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x82,
  57280. 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57281. 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82,
  57282. 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC3, 0x03, 0xD1, 0x2B, 0xFE,
  57283. 0x39, 0xA4, 0x32, 0x45, 0x3B, 0x53, 0xC8, 0x84, 0x2B, 0x2A, 0x7C, 0x74,
  57284. 0x9A, 0xBD, 0xAA, 0x2A, 0x52, 0x07, 0x47, 0xD6, 0xA6, 0x36, 0xB2, 0x07,
  57285. 0x32, 0x8E, 0xD0, 0xBA, 0x69, 0x7B, 0xC6, 0xC3, 0x44, 0x9E, 0xD4, 0x81,
  57286. 0x48, 0xFD, 0x2D, 0x68, 0xA2, 0x8B, 0x67, 0xBB, 0xA1, 0x75, 0xC8, 0x36,
  57287. 0x2C, 0x4A, 0xD2, 0x1B, 0xF7, 0x8B, 0xBA, 0xCF, 0x0D, 0xF9, 0xEF, 0xEC,
  57288. 0xF1, 0x81, 0x1E, 0x7B, 0x9B, 0x03, 0x47, 0x9A, 0xBF, 0x65, 0xCC, 0x7F,
  57289. 0x65, 0x24, 0x69, 0xA6, 0xE8, 0x14, 0x89, 0x5B, 0xE4, 0x34, 0xF7, 0xC5,
  57290. 0xB0, 0x14, 0x93, 0xF5, 0x67, 0x7B, 0x3A, 0x7A, 0x78, 0xE1, 0x01, 0x56,
  57291. 0x56, 0x91, 0xA6, 0x13, 0x42, 0x8D, 0xD2, 0x3C, 0x40, 0x9C, 0x4C, 0xEF,
  57292. 0xD1, 0x86, 0xDF, 0x37, 0x51, 0x1B, 0x0C, 0xA1, 0x3B, 0xF5, 0xF1, 0xA3,
  57293. 0x4A, 0x35, 0xE4, 0xE1, 0xCE, 0x96, 0xDF, 0x1B, 0x7E, 0xBF, 0x4E, 0x97,
  57294. 0xD0, 0x10, 0xE8, 0xA8, 0x08, 0x30, 0x81, 0xAF, 0x20, 0x0B, 0x43, 0x14,
  57295. 0xC5, 0x74, 0x67, 0xB4, 0x32, 0x82, 0x6F, 0x8D, 0x86, 0xC2, 0x88, 0x40,
  57296. 0x99, 0x36, 0x83, 0xBA, 0x1E, 0x40, 0x72, 0x22, 0x17, 0xD7, 0x52, 0x65,
  57297. 0x24, 0x73, 0xB0, 0xCE, 0xEF, 0x19, 0xCD, 0xAE, 0xFF, 0x78, 0x6C, 0x7B,
  57298. 0xC0, 0x12, 0x03, 0xD4, 0x4E, 0x72, 0x0D, 0x50, 0x6D, 0x3B, 0xA3, 0x3B,
  57299. 0xA3, 0x99, 0x5E, 0x9D, 0xC8, 0xD9, 0x0C, 0x85, 0xB3, 0xD9, 0x8A, 0xD9,
  57300. 0x54, 0x26, 0xDB, 0x6D, 0xFA, 0xAC, 0xBB, 0xFF, 0x25, 0x4C, 0xC4, 0xD1,
  57301. 0x79, 0xF4, 0x71, 0xD3, 0x86, 0x40, 0x18, 0x13, 0xB0, 0x63, 0xB5, 0x72,
  57302. 0x4E, 0x30, 0xC4, 0x97, 0x84, 0x86, 0x2D, 0x56, 0x2F, 0xD7, 0x15, 0xF7,
  57303. 0x7F, 0xC0, 0xAE, 0xF5, 0xFC, 0x5B, 0xE5, 0xFB, 0xA1, 0xBA, 0xD3, 0x02,
  57304. 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, 0x4F, 0x30, 0x82, 0x01, 0x4B,
  57305. 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  57306. 0x01, 0xFF, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30,
  57307. 0x13, 0x82, 0x0B, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63,
  57308. 0x6F, 0x6D, 0x87, 0x04, 0x7F, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03,
  57309. 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57310. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57311. 0x85, 0x65, 0xC0, 0x30, 0x81, 0xDE, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04,
  57312. 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x80, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57313. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57314. 0x85, 0x65, 0xC0, 0xA1, 0x81, 0xA4, 0xA4, 0x81, 0xA1, 0x30, 0x81, 0x9E,
  57315. 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  57316. 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07,
  57317. 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06,
  57318. 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61,
  57319. 0x6E, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C,
  57320. 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38,
  57321. 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50,
  57322. 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32,
  57323. 0x30, 0x34, 0x38, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03,
  57324. 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  57325. 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A,
  57326. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E,
  57327. 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  57328. 0x6F, 0x6D, 0x82, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55,
  57329. 0x8A, 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8,
  57330. 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06,
  57331. 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2B,
  57332. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0D, 0x06, 0x09, 0x2A,
  57333. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82,
  57334. 0x01, 0x01, 0x00, 0x14, 0xFB, 0xD0, 0xCE, 0x31, 0x7F, 0xA5, 0x59, 0xFA,
  57335. 0x7C, 0x68, 0x26, 0xA7, 0xE8, 0x0D, 0x9F, 0x50, 0x57, 0xFA, 0x1C, 0x7C,
  57336. 0x5E, 0x43, 0xA4, 0x97, 0x47, 0xB6, 0x41, 0xAC, 0x63, 0xD3, 0x61, 0x8C,
  57337. 0x1F, 0x42, 0xEF, 0x53, 0xD0, 0xBA, 0x31, 0x4D, 0x99, 0x74, 0xA4, 0x60,
  57338. 0xDC, 0xC6, 0x6F, 0xCC, 0x1E, 0x25, 0x98, 0xE1, 0xA4, 0xA0, 0x67, 0x69,
  57339. 0x97, 0xE3, 0x97, 0x7C, 0x83, 0x28, 0xF1, 0xF4, 0x7D, 0x03, 0xA8, 0x31,
  57340. 0x77, 0xCC, 0xD1, 0x37, 0xEF, 0x7B, 0x4A, 0x71, 0x2D, 0x11, 0x7E, 0x92,
  57341. 0xF5, 0x67, 0xB7, 0x56, 0xBA, 0x28, 0xF8, 0xD6, 0xCE, 0x2A, 0x71, 0xE3,
  57342. 0x70, 0x6B, 0x09, 0x0F, 0x67, 0x6F, 0x7A, 0xE0, 0x89, 0xF6, 0x5E, 0x23,
  57343. 0x0C, 0x0A, 0x44, 0x4E, 0x65, 0x8E, 0x7B, 0x68, 0xD0, 0xAD, 0x76, 0x3E,
  57344. 0x2A, 0x0E, 0xA2, 0x05, 0x11, 0x74, 0x24, 0x08, 0x60, 0xED, 0x9F, 0x98,
  57345. 0x18, 0xE9, 0x91, 0x58, 0x36, 0xEC, 0xEC, 0x25, 0x6B, 0xBA, 0x9C, 0x87,
  57346. 0x38, 0x68, 0xDC, 0xDC, 0x15, 0x6F, 0x20, 0x68, 0xC4, 0xBF, 0x05, 0x5B,
  57347. 0x4A, 0x0C, 0x44, 0x2B, 0x92, 0x3F, 0x10, 0x99, 0xDC, 0xF6, 0x6C, 0x0E,
  57348. 0x34, 0x26, 0x6E, 0x6D, 0x4E, 0x12, 0xBC, 0x60, 0x8F, 0x27, 0x1D, 0x7A,
  57349. 0x00, 0x50, 0xBE, 0x23, 0xDE, 0x48, 0x47, 0x9F, 0xAD, 0x2F, 0x94, 0x3D,
  57350. 0x16, 0x73, 0x48, 0x6B, 0xC8, 0x97, 0xE6, 0xB4, 0xB3, 0x4B, 0xE1, 0x68,
  57351. 0x08, 0xC3, 0xE5, 0x34, 0x5F, 0x9B, 0xDA, 0xAB, 0xCA, 0x6D, 0x55, 0x32,
  57352. 0xEF, 0x6C, 0xEF, 0x9B, 0x8B, 0x5B, 0xC7, 0xF0, 0xC2, 0x0F, 0x8E, 0x93,
  57353. 0x09, 0x60, 0x3C, 0x0B, 0xDC, 0xBD, 0xDB, 0x4A, 0x2D, 0xD0, 0x98, 0xAA,
  57354. 0xAB, 0x6C, 0x6F, 0x6D, 0x6B, 0x6A, 0x5C, 0x33, 0xAC, 0xAD, 0xA8, 0x1B,
  57355. 0x38, 0x5D, 0x9F, 0xDA, 0xE7, 0x70, 0x07
  57356. };
  57357. pt = ca_key_der_2048;
  57358. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  57359. sizeof_ca_key_der_2048));
  57360. pt = client_cert_der_2048;
  57361. ExpectNotNull(x509 = wolfSSL_d2i_X509(NULL, &pt,
  57362. sizeof_client_cert_der_2048));
  57363. pt = ca_cert_der_2048;
  57364. ExpectNotNull(ca = wolfSSL_d2i_X509(NULL, &pt, sizeof_ca_cert_der_2048));
  57365. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  57366. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  57367. #ifndef NO_ASN_TIME
  57368. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  57369. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  57370. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  57371. ExpectIntEQ(notAfter->length, 13);
  57372. ExpectTrue(wolfSSL_X509_set_notBefore(x509, notBefore));
  57373. ExpectTrue(wolfSSL_X509_set_notAfter(x509, notAfter));
  57374. #endif
  57375. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  57376. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  57377. ExpectIntEQ(derSz, sizeof(expected));
  57378. #ifndef NO_ASN_TIME
  57379. ExpectIntEQ(XMEMCMP(der, expected, derSz), 0);
  57380. #endif
  57381. wolfSSL_X509_free(ca);
  57382. wolfSSL_X509_free(x509);
  57383. wolfSSL_EVP_PKEY_free(priv);
  57384. #ifndef NO_ASN_TIME
  57385. wolfSSL_ASN1_TIME_free(notBefore);
  57386. wolfSSL_ASN1_TIME_free(notAfter);
  57387. #endif
  57388. #endif
  57389. return EXPECT_RESULT();
  57390. }
  57391. static int test_wolfSSL_X509_sign(void)
  57392. {
  57393. EXPECT_DECLS;
  57394. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_ASN_TIME) && \
  57395. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA)
  57396. int ret = 0;
  57397. char *cn = NULL;
  57398. word32 cnSz = 0;
  57399. X509_NAME *name = NULL;
  57400. X509 *x509 = NULL;
  57401. X509 *ca = NULL;
  57402. DecodedCert dCert;
  57403. EVP_PKEY *pub = NULL;
  57404. EVP_PKEY *priv = NULL;
  57405. EVP_MD_CTX *mctx = NULL;
  57406. #if defined(USE_CERT_BUFFERS_1024)
  57407. const unsigned char* rsaPriv = client_key_der_1024;
  57408. const unsigned char* rsaPub = client_keypub_der_1024;
  57409. const unsigned char* certIssuer = client_cert_der_1024;
  57410. long clientKeySz = (long)sizeof_client_key_der_1024;
  57411. long clientPubKeySz = (long)sizeof_client_keypub_der_1024;
  57412. long certIssuerSz = (long)sizeof_client_cert_der_1024;
  57413. #elif defined(USE_CERT_BUFFERS_2048)
  57414. const unsigned char* rsaPriv = client_key_der_2048;
  57415. const unsigned char* rsaPub = client_keypub_der_2048;
  57416. const unsigned char* certIssuer = client_cert_der_2048;
  57417. long clientKeySz = (long)sizeof_client_key_der_2048;
  57418. long clientPubKeySz = (long)sizeof_client_keypub_der_2048;
  57419. long certIssuerSz = (long)sizeof_client_cert_der_2048;
  57420. #endif
  57421. byte sn[16];
  57422. int snSz = sizeof(sn);
  57423. /* Set X509_NAME fields */
  57424. ExpectNotNull(name = X509_NAME_new());
  57425. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  57426. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  57427. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  57428. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  57429. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  57430. (byte*)"support@wolfssl.com", 19, -1, 0), SSL_SUCCESS);
  57431. /* Get private and public keys */
  57432. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  57433. clientKeySz));
  57434. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &rsaPub, clientPubKeySz));
  57435. ExpectNotNull(x509 = X509_new());
  57436. /* Set version 3 */
  57437. ExpectIntNE(X509_set_version(x509, 2L), 0);
  57438. /* Set subject name, add pubkey, and sign certificate */
  57439. ExpectIntEQ(X509_set_subject_name(x509, name), SSL_SUCCESS);
  57440. X509_NAME_free(name);
  57441. name = NULL;
  57442. ExpectIntEQ(X509_set_pubkey(x509, pub), SSL_SUCCESS);
  57443. #ifdef WOLFSSL_ALT_NAMES
  57444. /* Add some subject alt names */
  57445. ExpectIntNE(wolfSSL_X509_add_altname(NULL,
  57446. "ipsum", ASN_DNS_TYPE), SSL_SUCCESS);
  57447. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57448. NULL, ASN_DNS_TYPE), SSL_SUCCESS);
  57449. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57450. "sphygmomanometer",
  57451. ASN_DNS_TYPE), SSL_SUCCESS);
  57452. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57453. "supercalifragilisticexpialidocious",
  57454. ASN_DNS_TYPE), SSL_SUCCESS);
  57455. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57456. "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
  57457. ASN_DNS_TYPE), SSL_SUCCESS);
  57458. #ifdef WOLFSSL_IP_ALT_NAME
  57459. {
  57460. unsigned char ip4_type[] = {127,128,0,255};
  57461. unsigned char ip6_type[] = {0xdd, 0xcc, 0xba, 0xab,
  57462. 0xff, 0xee, 0x99, 0x88,
  57463. 0x77, 0x66, 0x55, 0x44,
  57464. 0x00, 0x33, 0x22, 0x11};
  57465. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip4_type,
  57466. sizeof(ip4_type), ASN_IP_TYPE), SSL_SUCCESS);
  57467. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip6_type,
  57468. sizeof(ip6_type), ASN_IP_TYPE), SSL_SUCCESS);
  57469. }
  57470. #endif
  57471. #endif /* WOLFSSL_ALT_NAMES */
  57472. {
  57473. ASN1_UTCTIME* infinite_past = NULL;
  57474. ExpectNotNull(infinite_past = ASN1_UTCTIME_set(NULL, 0));
  57475. ExpectIntEQ(X509_set1_notBefore(x509, infinite_past), 1);
  57476. ASN1_UTCTIME_free(infinite_past);
  57477. }
  57478. /* test valid sign case */
  57479. ExpectIntGT(ret = X509_sign(x509, priv, EVP_sha256()), 0);
  57480. /* test valid X509_sign_ctx case */
  57481. ExpectNotNull(mctx = EVP_MD_CTX_new());
  57482. ExpectIntEQ(EVP_DigestSignInit(mctx, NULL, EVP_sha256(), NULL, priv), 1);
  57483. ExpectIntGT(X509_sign_ctx(x509, mctx), 0);
  57484. #if defined(OPENSSL_ALL) && defined(WOLFSSL_ALT_NAMES)
  57485. ExpectIntEQ(X509_get_ext_count(x509), 1);
  57486. #endif
  57487. #if defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_IP_ALT_NAME)
  57488. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.128.0.255", 0), 1);
  57489. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "DDCC:BAAB:FFEE:9988:7766:5544:0033:2211", 0), 1);
  57490. #endif
  57491. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, sn, &snSz),
  57492. WOLFSSL_SUCCESS);
  57493. DEBUG_WRITE_CERT_X509(x509, "signed.pem");
  57494. /* Variation in size depends on ASN.1 encoding when MSB is set.
  57495. * WOLFSSL_ASN_TEMPLATE code does not generate a serial number
  57496. * with the MSB set. See GenerateInteger in asn.c */
  57497. #ifndef USE_CERT_BUFFERS_1024
  57498. #ifndef WOLFSSL_ALT_NAMES
  57499. /* Valid case - size should be 781-786 with 16 byte serial number */
  57500. ExpectTrue((781 + snSz <= ret) && (ret <= 781 + 5 + snSz));
  57501. #elif defined(WOLFSSL_IP_ALT_NAME)
  57502. /* Valid case - size should be 955-960 with 16 byte serial number */
  57503. ExpectTrue((939 + snSz <= ret) && (ret <= 939 + 5 + snSz));
  57504. #else
  57505. /* Valid case - size should be 926-931 with 16 byte serial number */
  57506. ExpectTrue((910 + snSz <= ret) && (ret <= 910 + 5 + snSz));
  57507. #endif
  57508. #else
  57509. #ifndef WOLFSSL_ALT_NAMES
  57510. /* Valid case - size should be 537-542 with 16 byte serial number */
  57511. ExpectTrue((521 + snSz <= ret) && (ret <= 521 + 5 + snSz));
  57512. #elif defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  57513. /* Valid case - size should be 695-670 with 16 byte serial number */
  57514. ExpectTrue((679 + snSz <= ret) && (ret <= 679 + 5 + snSz));
  57515. #else
  57516. /* Valid case - size should be 666-671 with 16 byte serial number */
  57517. ExpectTrue((650 + snSz <= ret) && (ret <= 650 + 5 + snSz));
  57518. #endif
  57519. #endif
  57520. /* check that issuer name is as expected after signature */
  57521. InitDecodedCert(&dCert, certIssuer, (word32)certIssuerSz, 0);
  57522. ExpectIntEQ(ParseCert(&dCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  57523. ExpectNotNull(ca = d2i_X509(NULL, &certIssuer, (int)certIssuerSz));
  57524. ExpectNotNull(name = X509_get_subject_name(ca));
  57525. cnSz = X509_NAME_get_sz(name);
  57526. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  57527. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  57528. ExpectIntEQ(0, XSTRNCMP(cn, dCert.subject, XSTRLEN(cn)));
  57529. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  57530. cn = NULL;
  57531. #ifdef WOLFSSL_MULTI_ATTRIB
  57532. /* test adding multiple OU's to the signer */
  57533. ExpectNotNull(name = X509_get_subject_name(ca));
  57534. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  57535. (byte*)"OU1", 3, -1, 0), SSL_SUCCESS);
  57536. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  57537. (byte*)"OU2", 3, -1, 0), SSL_SUCCESS);
  57538. ExpectIntGT(X509_sign(ca, priv, EVP_sha256()), 0);
  57539. #endif
  57540. ExpectNotNull(name = X509_get_subject_name(ca));
  57541. ExpectIntEQ(X509_set_issuer_name(x509, name), SSL_SUCCESS);
  57542. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  57543. ExpectNotNull(name = X509_get_issuer_name(x509));
  57544. cnSz = X509_NAME_get_sz(name);
  57545. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  57546. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  57547. /* compare and don't include the multi-attrib "/OU=OU1/OU=OU2" above */
  57548. ExpectIntEQ(0, XSTRNCMP(cn, dCert.issuer, XSTRLEN(dCert.issuer)));
  57549. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  57550. cn = NULL;
  57551. FreeDecodedCert(&dCert);
  57552. /* Test invalid parameters */
  57553. ExpectIntEQ(X509_sign(NULL, priv, EVP_sha256()), 0);
  57554. ExpectIntEQ(X509_sign(x509, NULL, EVP_sha256()), 0);
  57555. ExpectIntEQ(X509_sign(x509, priv, NULL), 0);
  57556. ExpectIntEQ(X509_sign_ctx(NULL, mctx), 0);
  57557. EVP_MD_CTX_free(mctx);
  57558. mctx = NULL;
  57559. ExpectNotNull(mctx = EVP_MD_CTX_new());
  57560. ExpectIntEQ(X509_sign_ctx(x509, mctx), 0);
  57561. ExpectIntEQ(X509_sign_ctx(x509, NULL), 0);
  57562. /* test invalid version number */
  57563. #if defined(OPENSSL_ALL)
  57564. ExpectIntNE(X509_set_version(x509, 6L), 0);
  57565. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  57566. /* uses ParseCert which fails on bad version number */
  57567. ExpectIntEQ(X509_get_ext_count(x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57568. #endif
  57569. EVP_MD_CTX_free(mctx);
  57570. EVP_PKEY_free(priv);
  57571. EVP_PKEY_free(pub);
  57572. X509_free(x509);
  57573. X509_free(ca);
  57574. #endif
  57575. return EXPECT_RESULT();
  57576. }
  57577. static int test_wolfSSL_X509_get0_tbs_sigalg(void)
  57578. {
  57579. EXPECT_DECLS;
  57580. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  57581. X509* x509 = NULL;
  57582. const X509_ALGOR* alg;
  57583. ExpectNotNull(x509 = X509_new());
  57584. ExpectNull(alg = X509_get0_tbs_sigalg(NULL));
  57585. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  57586. X509_free(x509);
  57587. #endif
  57588. return EXPECT_RESULT();
  57589. }
  57590. static int test_wolfSSL_X509_ALGOR_get0(void)
  57591. {
  57592. EXPECT_DECLS;
  57593. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  57594. !defined(NO_SHA256) && !defined(NO_RSA)
  57595. X509* x509 = NULL;
  57596. const ASN1_OBJECT* obj = NULL;
  57597. const X509_ALGOR* alg = NULL;
  57598. X509_ALGOR* alg2 = NULL;
  57599. int pptype = 0;
  57600. const void *ppval = NULL;
  57601. byte* der = NULL;
  57602. const byte* tmp = NULL;
  57603. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  57604. SSL_FILETYPE_PEM));
  57605. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  57606. /* Invalid case */
  57607. X509_ALGOR_get0(&obj, NULL, NULL, NULL);
  57608. ExpectNull(obj);
  57609. /* Valid case */
  57610. X509_ALGOR_get0(&obj, &pptype, &ppval, alg);
  57611. ExpectNotNull(obj);
  57612. ExpectNull(ppval);
  57613. ExpectIntNE(pptype, 0);
  57614. /* Make sure NID of X509_ALGOR is Sha256 with RSA */
  57615. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256WithRSAEncryption);
  57616. ExpectIntEQ(i2d_X509_ALGOR(alg, &der), 15);
  57617. tmp = der;
  57618. ExpectNotNull(d2i_X509_ALGOR(&alg2, &tmp, 15));
  57619. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  57620. X509_free(x509);
  57621. X509_ALGOR_free(alg2);
  57622. #endif
  57623. return EXPECT_RESULT();
  57624. }
  57625. static int test_wolfSSL_X509_VERIFY_PARAM(void)
  57626. {
  57627. EXPECT_DECLS;
  57628. #if defined(OPENSSL_EXTRA)
  57629. X509_VERIFY_PARAM *paramTo = NULL;
  57630. X509_VERIFY_PARAM *paramFrom = NULL;
  57631. char testIPv4[] = "127.0.0.1";
  57632. char testIPv6[] = "0001:0000:0000:0000:0000:0000:0000:0000/32";
  57633. char testhostName1[] = "foo.hoge.com";
  57634. char testhostName2[] = "foobar.hoge.com";
  57635. ExpectNotNull(paramTo = X509_VERIFY_PARAM_new());
  57636. ExpectNotNull(XMEMSET(paramTo, 0, sizeof(X509_VERIFY_PARAM)));
  57637. ExpectNotNull(paramFrom = X509_VERIFY_PARAM_new());
  57638. ExpectNotNull(XMEMSET(paramFrom, 0, sizeof(X509_VERIFY_PARAM)));
  57639. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramFrom, testhostName1,
  57640. (int)XSTRLEN(testhostName1)), 1);
  57641. ExpectIntEQ(0, XSTRNCMP(paramFrom->hostName, testhostName1,
  57642. (int)XSTRLEN(testhostName1)));
  57643. X509_VERIFY_PARAM_set_hostflags(NULL, 0x00);
  57644. X509_VERIFY_PARAM_set_hostflags(paramFrom, 0x01);
  57645. ExpectIntEQ(0x01, paramFrom->hostFlags);
  57646. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(NULL, testIPv4), 0);
  57647. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv4), 1);
  57648. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  57649. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, NULL), 1);
  57650. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv6), 1);
  57651. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57652. /* null pointer */
  57653. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, paramFrom), 0);
  57654. /* in the case of "from" null, returns success */
  57655. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, NULL), 1);
  57656. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, NULL), 0);
  57657. /* inherit flags test : VPARAM_DEFAULT */
  57658. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57659. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  57660. (int)XSTRLEN(testhostName1)));
  57661. ExpectIntEQ(0x01, paramTo->hostFlags);
  57662. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57663. /* inherit flags test : VPARAM OVERWRITE */
  57664. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  57665. (int)XSTRLEN(testhostName2)), 1);
  57666. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  57667. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  57668. if (paramTo != NULL) {
  57669. paramTo->inherit_flags = X509_VP_FLAG_OVERWRITE;
  57670. }
  57671. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57672. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  57673. (int)XSTRLEN(testhostName1)));
  57674. ExpectIntEQ(0x01, paramTo->hostFlags);
  57675. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57676. /* inherit flags test : VPARAM_RESET_FLAGS */
  57677. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  57678. (int)XSTRLEN(testhostName2)), 1);
  57679. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  57680. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x10);
  57681. if (paramTo != NULL) {
  57682. paramTo->inherit_flags = X509_VP_FLAG_RESET_FLAGS;
  57683. }
  57684. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57685. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  57686. (int)XSTRLEN(testhostName1)));
  57687. ExpectIntEQ(0x01, paramTo->hostFlags);
  57688. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57689. /* inherit flags test : VPARAM_LOCKED */
  57690. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  57691. (int)XSTRLEN(testhostName2)), 1);
  57692. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  57693. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  57694. if (paramTo != NULL) {
  57695. paramTo->inherit_flags = X509_VP_FLAG_LOCKED;
  57696. }
  57697. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57698. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName2,
  57699. (int)XSTRLEN(testhostName2)));
  57700. ExpectIntEQ(0x00, paramTo->hostFlags);
  57701. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  57702. /* test for incorrect parameters */
  57703. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, X509_V_FLAG_CRL_CHECK_ALL),
  57704. 0);
  57705. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, 0), 0);
  57706. /* inherit flags test : VPARAM_ONCE, not testable yet */
  57707. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(paramTo, X509_V_FLAG_CRL_CHECK_ALL),
  57708. 1);
  57709. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo),
  57710. X509_V_FLAG_CRL_CHECK_ALL);
  57711. ExpectIntEQ(X509_VERIFY_PARAM_clear_flags(paramTo,
  57712. X509_V_FLAG_CRL_CHECK_ALL), 1);
  57713. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo), 0);
  57714. X509_VERIFY_PARAM_free(paramTo);
  57715. X509_VERIFY_PARAM_free(paramFrom);
  57716. X509_VERIFY_PARAM_free(NULL); /* to confirm NULL parameter gives no harm */
  57717. #endif
  57718. return EXPECT_RESULT();
  57719. }
  57720. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  57721. !defined(WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY)
  57722. static int test_wolfSSL_check_domain_verify_count = 0;
  57723. static WC_INLINE int test_wolfSSL_check_domain_verify_cb(int preverify,
  57724. WOLFSSL_X509_STORE_CTX* store)
  57725. {
  57726. EXPECT_DECLS;
  57727. ExpectIntEQ(X509_STORE_CTX_get_error(store), 0);
  57728. ExpectIntEQ(preverify, 1);
  57729. ExpectIntGT(++test_wolfSSL_check_domain_verify_count, 0);
  57730. return EXPECT_SUCCESS();
  57731. }
  57732. static int test_wolfSSL_check_domain_client_cb(WOLFSSL* ssl)
  57733. {
  57734. EXPECT_DECLS;
  57735. X509_VERIFY_PARAM *param = NULL;
  57736. ExpectNotNull(param = SSL_get0_param(ssl));
  57737. /* Domain check should only be done on the leaf cert */
  57738. X509_VERIFY_PARAM_set_hostflags(param,
  57739. X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
  57740. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(param,
  57741. "wolfSSL Server Chain", 0), 1);
  57742. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER,
  57743. test_wolfSSL_check_domain_verify_cb);
  57744. return EXPECT_RESULT();
  57745. }
  57746. static int test_wolfSSL_check_domain_server_cb(WOLFSSL_CTX* ctx)
  57747. {
  57748. EXPECT_DECLS;
  57749. /* Use a cert with different domains in chain */
  57750. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  57751. "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS);
  57752. return EXPECT_RESULT();
  57753. }
  57754. static int test_wolfSSL_check_domain(void)
  57755. {
  57756. EXPECT_DECLS;
  57757. test_ssl_cbf func_cb_client;
  57758. test_ssl_cbf func_cb_server;
  57759. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  57760. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  57761. func_cb_client.ssl_ready = &test_wolfSSL_check_domain_client_cb;
  57762. func_cb_server.ctx_ready = &test_wolfSSL_check_domain_server_cb;
  57763. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  57764. &func_cb_server, NULL), TEST_SUCCESS);
  57765. /* Should have been called once for each cert in sent chain */
  57766. #ifdef WOLFSSL_VERIFY_CB_ALL_CERTS
  57767. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 3);
  57768. #else
  57769. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 1);
  57770. #endif
  57771. return EXPECT_RESULT();
  57772. }
  57773. #else
  57774. static int test_wolfSSL_check_domain(void)
  57775. {
  57776. EXPECT_DECLS;
  57777. return EXPECT_RESULT();
  57778. }
  57779. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  57780. static int test_wolfSSL_X509_get_X509_PUBKEY(void)
  57781. {
  57782. EXPECT_DECLS;
  57783. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  57784. X509* x509 = NULL;
  57785. X509_PUBKEY* pubKey;
  57786. ExpectNotNull(x509 = X509_new());
  57787. ExpectNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(NULL));
  57788. ExpectNotNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(x509));
  57789. X509_free(x509);
  57790. #endif
  57791. return EXPECT_RESULT();
  57792. }
  57793. static int test_wolfSSL_X509_PUBKEY_RSA(void)
  57794. {
  57795. EXPECT_DECLS;
  57796. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  57797. !defined(NO_SHA256) && !defined(NO_RSA)
  57798. X509* x509 = NULL;
  57799. ASN1_OBJECT* obj = NULL;
  57800. const ASN1_OBJECT* pa_oid = NULL;
  57801. X509_PUBKEY* pubKey = NULL;
  57802. X509_PUBKEY* pubKey2 = NULL;
  57803. EVP_PKEY* evpKey = NULL;
  57804. const unsigned char *pk = NULL;
  57805. int ppklen;
  57806. int pptype;
  57807. X509_ALGOR *pa = NULL;
  57808. const void *pval;
  57809. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  57810. SSL_FILETYPE_PEM));
  57811. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  57812. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  57813. ExpectNotNull(pk);
  57814. ExpectNotNull(pa);
  57815. ExpectNotNull(pubKey);
  57816. ExpectIntGT(ppklen, 0);
  57817. ExpectIntEQ(OBJ_obj2nid(obj), NID_rsaEncryption);
  57818. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  57819. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  57820. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  57821. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  57822. ExpectNotNull(pk);
  57823. ExpectNotNull(pa);
  57824. ExpectIntGT(ppklen, 0);
  57825. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  57826. ExpectNotNull(pa_oid);
  57827. ExpectNull(pval);
  57828. ExpectIntEQ(pptype, V_ASN1_NULL);
  57829. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_RSA);
  57830. X509_PUBKEY_free(pubKey2);
  57831. X509_free(x509);
  57832. EVP_PKEY_free(evpKey);
  57833. #endif
  57834. return EXPECT_RESULT();
  57835. }
  57836. static int test_wolfSSL_X509_PUBKEY_EC(void)
  57837. {
  57838. EXPECT_DECLS;
  57839. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && defined(HAVE_ECC)
  57840. X509* x509 = NULL;
  57841. ASN1_OBJECT* obj = NULL;
  57842. ASN1_OBJECT* poid = NULL;
  57843. const ASN1_OBJECT* pa_oid = NULL;
  57844. X509_PUBKEY* pubKey = NULL;
  57845. X509_PUBKEY* pubKey2 = NULL;
  57846. EVP_PKEY* evpKey = NULL;
  57847. const unsigned char *pk = NULL;
  57848. int ppklen;
  57849. int pptype;
  57850. X509_ALGOR *pa = NULL;
  57851. const void *pval;
  57852. char buf[50];
  57853. ExpectNotNull(x509 = X509_load_certificate_file(cliEccCertFile,
  57854. SSL_FILETYPE_PEM));
  57855. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  57856. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  57857. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  57858. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  57859. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  57860. ExpectNotNull(pk);
  57861. ExpectNotNull(pa);
  57862. ExpectIntGT(ppklen, 0);
  57863. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  57864. ExpectNotNull(pa_oid);
  57865. ExpectNotNull(pval);
  57866. ExpectIntEQ(pptype, V_ASN1_OBJECT);
  57867. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_EC);
  57868. poid = (ASN1_OBJECT *)pval;
  57869. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), poid, 0), 0);
  57870. ExpectIntEQ(OBJ_txt2nid(buf), NID_X9_62_prime256v1);
  57871. X509_PUBKEY_free(pubKey2);
  57872. X509_free(x509);
  57873. EVP_PKEY_free(evpKey);
  57874. #endif
  57875. return EXPECT_RESULT();
  57876. }
  57877. static int test_wolfSSL_X509_PUBKEY_DSA(void)
  57878. {
  57879. EXPECT_DECLS;
  57880. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && !defined(NO_DSA)
  57881. word32 bytes;
  57882. #ifdef USE_CERT_BUFFERS_1024
  57883. byte tmp[ONEK_BUF];
  57884. #elif defined(USE_CERT_BUFFERS_2048)
  57885. byte tmp[TWOK_BUF];
  57886. #else
  57887. byte tmp[TWOK_BUF];
  57888. #endif /* END USE_CERT_BUFFERS_1024 */
  57889. const unsigned char* dsaKeyDer = tmp;
  57890. ASN1_OBJECT* obj = NULL;
  57891. ASN1_STRING* str;
  57892. const ASN1_OBJECT* pa_oid = NULL;
  57893. X509_PUBKEY* pubKey = NULL;
  57894. EVP_PKEY* evpKey = NULL;
  57895. const unsigned char *pk = NULL;
  57896. int ppklen, pptype;
  57897. X509_ALGOR *pa = NULL;
  57898. const void *pval;
  57899. #ifdef USE_CERT_BUFFERS_1024
  57900. XMEMSET(tmp, 0, sizeof(tmp));
  57901. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  57902. bytes = sizeof_dsa_key_der_1024;
  57903. #elif defined(USE_CERT_BUFFERS_2048)
  57904. XMEMSET(tmp, 0, sizeof(tmp));
  57905. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  57906. bytes = sizeof_dsa_key_der_2048;
  57907. #else
  57908. {
  57909. XFILE fp = XBADFILE;
  57910. XMEMSET(tmp, 0, sizeof(tmp));
  57911. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  57912. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  57913. if (fp != XBADFILE)
  57914. XFCLOSE(fp);
  57915. }
  57916. #endif
  57917. /* Initialize pkey with der format dsa key */
  57918. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &evpKey, &dsaKeyDer, bytes));
  57919. ExpectNotNull(pubKey = X509_PUBKEY_new());
  57920. ExpectIntEQ(X509_PUBKEY_set(&pubKey, evpKey), 1);
  57921. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  57922. ExpectNotNull(pk);
  57923. ExpectNotNull(pa);
  57924. ExpectIntGT(ppklen, 0);
  57925. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  57926. ExpectNotNull(pa_oid);
  57927. ExpectNotNull(pval);
  57928. ExpectIntEQ(pptype, V_ASN1_SEQUENCE);
  57929. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_DSA);
  57930. str = (ASN1_STRING *)pval;
  57931. DEBUG_WRITE_DER(ASN1_STRING_data(str), ASN1_STRING_length(str), "str.der");
  57932. #ifdef USE_CERT_BUFFERS_1024
  57933. ExpectIntEQ(ASN1_STRING_length(str), 291);
  57934. #else
  57935. ExpectIntEQ(ASN1_STRING_length(str), 549);
  57936. #endif /* END USE_CERT_BUFFERS_1024 */
  57937. X509_PUBKEY_free(pubKey);
  57938. EVP_PKEY_free(evpKey);
  57939. #endif
  57940. return EXPECT_RESULT();
  57941. }
  57942. static int test_wolfSSL_BUF(void)
  57943. {
  57944. EXPECT_DECLS;
  57945. #if defined(OPENSSL_EXTRA)
  57946. BUF_MEM* buf = NULL;
  57947. ExpectNotNull(buf = BUF_MEM_new());
  57948. ExpectIntEQ(BUF_MEM_grow(buf, 10), 10);
  57949. ExpectIntEQ(BUF_MEM_grow(buf, -1), 0);
  57950. BUF_MEM_free(buf);
  57951. #endif
  57952. return EXPECT_RESULT();
  57953. }
  57954. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  57955. static int stub_rand_seed(const void *buf, int num)
  57956. {
  57957. (void)buf;
  57958. (void)num;
  57959. return 123;
  57960. }
  57961. static int stub_rand_bytes(unsigned char *buf, int num)
  57962. {
  57963. (void)buf;
  57964. (void)num;
  57965. return 456;
  57966. }
  57967. static byte* was_stub_rand_cleanup_called(void)
  57968. {
  57969. static byte was_called = 0;
  57970. return &was_called;
  57971. }
  57972. static void stub_rand_cleanup(void)
  57973. {
  57974. byte* was_called = was_stub_rand_cleanup_called();
  57975. *was_called = 1;
  57976. return;
  57977. }
  57978. static byte* was_stub_rand_add_called(void)
  57979. {
  57980. static byte was_called = 0;
  57981. return &was_called;
  57982. }
  57983. static int stub_rand_add(const void *buf, int num, double entropy)
  57984. {
  57985. byte* was_called = was_stub_rand_add_called();
  57986. (void)buf;
  57987. (void)num;
  57988. (void)entropy;
  57989. *was_called = 1;
  57990. return 0;
  57991. }
  57992. static int stub_rand_pseudo_bytes(unsigned char *buf, int num)
  57993. {
  57994. (void)buf;
  57995. (void)num;
  57996. return 9876;
  57997. }
  57998. static int stub_rand_status(void)
  57999. {
  58000. return 5432;
  58001. }
  58002. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58003. static int test_wolfSSL_RAND_set_rand_method(void)
  58004. {
  58005. EXPECT_DECLS;
  58006. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  58007. RAND_METHOD rand_methods = {NULL, NULL, NULL, NULL, NULL, NULL};
  58008. unsigned char* buf = NULL;
  58009. int num = 0;
  58010. double entropy = 0;
  58011. int ret;
  58012. byte* was_cleanup_called = was_stub_rand_cleanup_called();
  58013. byte* was_add_called = was_stub_rand_add_called();
  58014. ExpectNotNull(buf = (byte*)XMALLOC(32 * sizeof(byte), NULL,
  58015. DYNAMIC_TYPE_TMP_BUFFER));
  58016. ExpectIntNE(wolfSSL_RAND_status(), 5432);
  58017. ExpectIntEQ(*was_cleanup_called, 0);
  58018. RAND_cleanup();
  58019. ExpectIntEQ(*was_cleanup_called, 0);
  58020. rand_methods.seed = &stub_rand_seed;
  58021. rand_methods.bytes = &stub_rand_bytes;
  58022. rand_methods.cleanup = &stub_rand_cleanup;
  58023. rand_methods.add = &stub_rand_add;
  58024. rand_methods.pseudorand = &stub_rand_pseudo_bytes;
  58025. rand_methods.status = &stub_rand_status;
  58026. ExpectIntEQ(RAND_set_rand_method(&rand_methods), WOLFSSL_SUCCESS);
  58027. ExpectIntEQ(RAND_seed(buf, num), 123);
  58028. ExpectIntEQ(RAND_bytes(buf, num), 456);
  58029. ExpectIntEQ(RAND_pseudo_bytes(buf, num), 9876);
  58030. ExpectIntEQ(RAND_status(), 5432);
  58031. ExpectIntEQ(*was_add_called, 0);
  58032. /* The function pointer for RAND_add returns int, but RAND_add itself
  58033. * returns void. */
  58034. RAND_add(buf, num, entropy);
  58035. ExpectIntEQ(*was_add_called, 1);
  58036. was_add_called = 0;
  58037. ExpectIntEQ(*was_cleanup_called, 0);
  58038. RAND_cleanup();
  58039. ExpectIntEQ(*was_cleanup_called, 1);
  58040. *was_cleanup_called = 0;
  58041. ret = RAND_set_rand_method(NULL);
  58042. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  58043. ExpectIntNE(RAND_status(), 5432);
  58044. ExpectIntEQ(*was_cleanup_called, 0);
  58045. RAND_cleanup();
  58046. ExpectIntEQ(*was_cleanup_called, 0);
  58047. RAND_set_rand_method(NULL);
  58048. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58049. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58050. return EXPECT_RESULT();
  58051. }
  58052. static int test_wolfSSL_RAND_bytes(void)
  58053. {
  58054. EXPECT_DECLS;
  58055. #if defined(OPENSSL_EXTRA)
  58056. const int size1 = RNG_MAX_BLOCK_LEN; /* in bytes */
  58057. const int size2 = RNG_MAX_BLOCK_LEN + 1; /* in bytes */
  58058. const int size3 = RNG_MAX_BLOCK_LEN * 2; /* in bytes */
  58059. const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */
  58060. int max_bufsize;
  58061. byte *my_buf = NULL;
  58062. /* sanity check */
  58063. ExpectIntEQ(RAND_bytes(NULL, 16), 0);
  58064. ExpectIntEQ(RAND_bytes(NULL, 0), 0);
  58065. max_bufsize = size4;
  58066. ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL,
  58067. DYNAMIC_TYPE_TMP_BUFFER));
  58068. ExpectIntEQ(RAND_bytes(my_buf, 0), 1);
  58069. ExpectIntEQ(RAND_bytes(my_buf, -1), 0);
  58070. ExpectNotNull(XMEMSET(my_buf, 0, max_bufsize));
  58071. ExpectIntEQ(RAND_bytes(my_buf, size1), 1);
  58072. ExpectIntEQ(RAND_bytes(my_buf, size2), 1);
  58073. ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
  58074. ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
  58075. XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58076. #endif
  58077. return EXPECT_RESULT();
  58078. }
  58079. static int test_wolfSSL_RAND(void)
  58080. {
  58081. EXPECT_DECLS;
  58082. #if defined(OPENSSL_EXTRA)
  58083. byte seed[16];
  58084. XMEMSET(seed, 0, sizeof(seed));
  58085. /* No global methods set. */
  58086. ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
  58087. ExpectIntEQ(RAND_poll(), 1);
  58088. RAND_cleanup();
  58089. ExpectIntEQ(RAND_egd(NULL), -1);
  58090. #ifndef NO_FILESYSTEM
  58091. {
  58092. char fname[100];
  58093. ExpectNotNull(RAND_file_name(fname, (sizeof(fname) - 1)));
  58094. ExpectIntEQ(RAND_write_file(NULL), 0);
  58095. }
  58096. #endif
  58097. #endif
  58098. return EXPECT_RESULT();
  58099. }
  58100. static int test_wolfSSL_PKCS8_Compat(void)
  58101. {
  58102. EXPECT_DECLS;
  58103. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC) && \
  58104. !defined(NO_BIO)
  58105. PKCS8_PRIV_KEY_INFO* pt = NULL;
  58106. BIO* bio = NULL;
  58107. XFILE f = XBADFILE;
  58108. int bytes;
  58109. char pkcs8_buffer[512];
  58110. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58111. EVP_PKEY *pkey = NULL;
  58112. #endif
  58113. /* file from wolfssl/certs/ directory */
  58114. ExpectTrue((f = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb")) != XBADFILE);
  58115. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer), f)),
  58116. 0);
  58117. if (f != XBADFILE)
  58118. XFCLOSE(f);
  58119. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58120. ExpectNotNull(pt = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL));
  58121. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58122. ExpectNotNull(pkey = EVP_PKCS82PKEY(pt));
  58123. ExpectIntEQ(EVP_PKEY_type(pkey->type), EVP_PKEY_EC);
  58124. /* gets PKCS8 pointer to pkey */
  58125. ExpectNotNull(EVP_PKEY2PKCS8(pkey));
  58126. EVP_PKEY_free(pkey);
  58127. #endif
  58128. BIO_free(bio);
  58129. PKCS8_PRIV_KEY_INFO_free(pt);
  58130. #endif
  58131. return EXPECT_RESULT();
  58132. }
  58133. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  58134. static int NoPasswordCallBack(char* passwd, int sz, int rw, void* userdata)
  58135. {
  58136. (void)passwd;
  58137. (void)sz;
  58138. (void)rw;
  58139. (void)userdata;
  58140. return -1;
  58141. }
  58142. #endif
  58143. static int test_wolfSSL_PKCS8_d2i(void)
  58144. {
  58145. EXPECT_DECLS;
  58146. #if !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  58147. /* This test ends up using HMAC as a part of PBKDF2, and HMAC
  58148. * requires a 12 byte password in FIPS mode. This test ends up
  58149. * trying to use an 8 byte password. */
  58150. #ifndef NO_FILESYSTEM
  58151. unsigned char pkcs8_buffer[2048];
  58152. const unsigned char* p = NULL;
  58153. int bytes = 0;
  58154. XFILE file = XBADFILE;
  58155. WOLFSSL_EVP_PKEY* pkey = NULL;
  58156. #ifndef NO_BIO
  58157. BIO* bio = NULL;
  58158. #if defined(OPENSSL_ALL) && \
  58159. ((!defined(NO_RSA) && !defined(NO_DES3)) || \
  58160. defined(HAVE_ECC)) && \
  58161. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58162. WOLFSSL_EVP_PKEY* evpPkey = NULL;
  58163. #endif
  58164. #endif
  58165. #ifndef NO_RSA
  58166. const char rsaDerPkcs8File[] = "./certs/server-keyPkcs8.der";
  58167. const char rsaPemPkcs8File[] = "./certs/server-keyPkcs8.pem";
  58168. #ifndef NO_DES3
  58169. const char rsaDerPkcs8EncFile[] = "./certs/server-keyPkcs8Enc.der";
  58170. #endif
  58171. #endif /* NO_RSA */
  58172. #ifdef HAVE_ECC
  58173. const char ecDerPkcs8File[] = "certs/ecc-keyPkcs8.der";
  58174. const char ecPemPkcs8File[] = "certs/ecc-keyPkcs8.pem";
  58175. #ifndef NO_DES3
  58176. const char ecDerPkcs8EncFile[] = "certs/ecc-keyPkcs8Enc.der";
  58177. #endif
  58178. #endif /* HAVE_ECC */
  58179. #endif /* !NO_FILESYSTEM */
  58180. #if defined(OPENSSL_ALL) && (!defined(NO_RSA) || defined(HAVE_ECC))
  58181. #ifndef NO_RSA
  58182. #ifdef USE_CERT_BUFFERS_1024
  58183. const unsigned char* rsa = (unsigned char*)server_key_der_1024;
  58184. int rsaSz = sizeof_server_key_der_1024;
  58185. #else
  58186. const unsigned char* rsa = (unsigned char*)server_key_der_2048;
  58187. int rsaSz = sizeof_server_key_der_2048;
  58188. #endif
  58189. #endif
  58190. #ifdef HAVE_ECC
  58191. const unsigned char* ec = (unsigned char*)ecc_key_der_256;
  58192. int ecSz = sizeof_ecc_key_der_256;
  58193. #endif
  58194. #endif /* OPENSSL_ALL && (!NO_RSA || HAVE_ECC) */
  58195. #ifndef NO_FILESYSTEM
  58196. (void)pkcs8_buffer;
  58197. (void)p;
  58198. (void)bytes;
  58199. (void)file;
  58200. #ifndef NO_BIO
  58201. (void)bio;
  58202. #endif
  58203. #endif
  58204. #ifdef OPENSSL_ALL
  58205. #ifndef NO_RSA
  58206. /* Try to auto-detect normal RSA private key */
  58207. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &rsa, rsaSz));
  58208. EVP_PKEY_free(pkey);
  58209. pkey = NULL;
  58210. #endif
  58211. #ifdef HAVE_ECC
  58212. /* Try to auto-detect normal EC private key */
  58213. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &ec, ecSz));
  58214. EVP_PKEY_free(pkey);
  58215. pkey = NULL;
  58216. #endif
  58217. #endif /* OPENSSL_ALL */
  58218. #ifndef NO_FILESYSTEM
  58219. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58220. ExpectIntEQ(PEM_write_PKCS8PrivateKey(XBADFILE, pkey, NULL, NULL, 0, NULL,
  58221. NULL), 0);
  58222. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  58223. NULL), 0);
  58224. #endif
  58225. #ifndef NO_RSA
  58226. /* Get DER encoded RSA PKCS#8 data. */
  58227. ExpectTrue((file = XFOPEN(rsaDerPkcs8File, "rb")) != XBADFILE);
  58228. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58229. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58230. file)), 0);
  58231. if (file != XBADFILE) {
  58232. XFCLOSE(file);
  58233. file = XBADFILE;
  58234. }
  58235. p = pkcs8_buffer;
  58236. #ifdef OPENSSL_ALL
  58237. /* Try to decode - auto-detect key type. */
  58238. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58239. #else
  58240. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, bytes));
  58241. #endif
  58242. /* Get PEM encoded RSA PKCS#8 data. */
  58243. ExpectTrue((file = XFOPEN(rsaPemPkcs8File, "rb")) != XBADFILE);
  58244. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58245. file)), 0);
  58246. if (file != XBADFILE) {
  58247. XFCLOSE(file);
  58248. file = XBADFILE;
  58249. }
  58250. #if defined(OPENSSL_ALL) && \
  58251. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58252. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58253. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(NULL, pkey, NULL, NULL, 0, NULL,
  58254. NULL), 0);
  58255. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  58256. NULL), 0);
  58257. /* Write PKCS#8 PEM to BIO. */
  58258. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58259. NULL), bytes);
  58260. /* Write PKCS#8 PEM to stderr. */
  58261. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58262. NULL), bytes);
  58263. /* Compare file and written data */
  58264. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58265. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58266. BIO_free(bio);
  58267. bio = NULL;
  58268. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  58269. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_gcm(),
  58270. NULL, 0, PasswordCallBack, (void*)"yassl123"), 0);
  58271. #endif
  58272. #if !defined(NO_DES3) && !defined(NO_SHA)
  58273. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58274. /* Write Encrypted PKCS#8 PEM to BIO. */
  58275. bytes = 1834;
  58276. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_des_ede3_cbc(),
  58277. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58278. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_des_ede3_cbc(),
  58279. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58280. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58281. (void*)"yassl123"));
  58282. EVP_PKEY_free(evpPkey);
  58283. evpPkey = NULL;
  58284. BIO_free(bio);
  58285. bio = NULL;
  58286. #endif /* !NO_DES3 && !NO_SHA */
  58287. #endif /* !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58288. EVP_PKEY_free(pkey);
  58289. pkey = NULL;
  58290. /* PKCS#8 encrypted RSA key */
  58291. #ifndef NO_DES3
  58292. ExpectTrue((file = XFOPEN(rsaDerPkcs8EncFile, "rb")) != XBADFILE);
  58293. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58294. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58295. file)), 0);
  58296. if (file != XBADFILE) {
  58297. XFCLOSE(file);
  58298. file = XBADFILE;
  58299. }
  58300. #if defined(OPENSSL_ALL) && \
  58301. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58302. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58303. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58304. (void*)"yassl123"));
  58305. EVP_PKEY_free(pkey);
  58306. pkey = NULL;
  58307. BIO_free(bio);
  58308. bio = NULL;
  58309. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58310. #endif /* !NO_DES3 */
  58311. #endif /* NO_RSA */
  58312. #ifdef HAVE_ECC
  58313. /* PKCS#8 encode EC key */
  58314. ExpectTrue((file = XFOPEN(ecDerPkcs8File, "rb")) != XBADFILE);
  58315. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58316. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58317. file)), 0);
  58318. if (file != XBADFILE) {
  58319. XFCLOSE(file);
  58320. file = XBADFILE;
  58321. }
  58322. p = pkcs8_buffer;
  58323. #ifdef OPENSSL_ALL
  58324. /* Try to decode - auto-detect key type. */
  58325. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58326. #else
  58327. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p, bytes));
  58328. #endif
  58329. /* Get PEM encoded RSA PKCS#8 data. */
  58330. ExpectTrue((file = XFOPEN(ecPemPkcs8File, "rb")) != XBADFILE);
  58331. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58332. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58333. file)), 0);
  58334. if (file != XBADFILE) {
  58335. XFCLOSE(file);
  58336. file = XBADFILE;
  58337. }
  58338. #if defined(OPENSSL_ALL) && \
  58339. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8) && \
  58340. defined(HAVE_AES_CBC)
  58341. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58342. /* Write PKCS#8 PEM to BIO. */
  58343. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58344. NULL), bytes);
  58345. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58346. NULL), bytes);
  58347. /* Compare file and written data */
  58348. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58349. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58350. BIO_free(bio);
  58351. bio = NULL;
  58352. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58353. /* Write Encrypted PKCS#8 PEM to BIO. */
  58354. bytes = 379;
  58355. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58356. NULL, 0, NoPasswordCallBack, (void*)"yassl123"), 0);
  58357. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58358. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58359. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58360. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58361. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58362. (char*)"yassl123", 8, PasswordCallBack, NULL), bytes);
  58363. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_256_cbc(),
  58364. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58365. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58366. (void*)"yassl123"));
  58367. EVP_PKEY_free(evpPkey);
  58368. evpPkey = NULL;
  58369. BIO_free(bio);
  58370. bio = NULL;
  58371. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 && HAVE_AES_CBC */
  58372. EVP_PKEY_free(pkey);
  58373. pkey = NULL;
  58374. /* PKCS#8 encrypted EC key */
  58375. #ifndef NO_DES3
  58376. ExpectTrue((file = XFOPEN(ecDerPkcs8EncFile, "rb")) != XBADFILE);
  58377. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58378. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58379. file)), 0);
  58380. if (file != XBADFILE) {
  58381. XFCLOSE(file);
  58382. file = XBADFILE;
  58383. }
  58384. #if defined(OPENSSL_ALL) && \
  58385. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58386. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58387. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58388. (void*)"yassl123"));
  58389. EVP_PKEY_free(pkey);
  58390. pkey = NULL;
  58391. BIO_free(bio);
  58392. bio = NULL;
  58393. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58394. #endif /* !NO_DES3 */
  58395. #endif /* HAVE_ECC */
  58396. #endif /* !NO_FILESYSTEM */
  58397. #endif /* HAVE_FIPS && OPENSSL_EXTRA */
  58398. return EXPECT_RESULT();
  58399. }
  58400. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58401. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58402. defined(DEBUG_WOLFSSL)
  58403. #define LOGGING_THREADS 5
  58404. #define ERROR_COUNT 10
  58405. /* copied from logging.c since this is not exposed otherwise */
  58406. #ifndef ERROR_QUEUE_MAX
  58407. #ifdef ERROR_QUEUE_PER_THREAD
  58408. #define ERROR_QUEUE_MAX 16
  58409. #else
  58410. /* this breaks from compat of unlimited error queue size */
  58411. #define ERROR_QUEUE_MAX 100
  58412. #endif
  58413. #endif
  58414. static volatile int loggingThreadsReady;
  58415. static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
  58416. {
  58417. const char* file;
  58418. int line;
  58419. unsigned long err;
  58420. int errorCount = 0;
  58421. int i;
  58422. (void)args;
  58423. while (!loggingThreadsReady);
  58424. for (i = 0; i < ERROR_COUNT; i++)
  58425. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58426. while ((err = ERR_get_error_line(&file, &line))) {
  58427. AssertIntEQ(err, 990 + errorCount);
  58428. errorCount++;
  58429. }
  58430. AssertIntEQ(errorCount, ERROR_COUNT);
  58431. /* test max queue behavior, trying to add an arbitrary 3 errors over */
  58432. ERR_clear_error(); /* ERR_get_error_line() does not remove */
  58433. errorCount = 0;
  58434. for (i = 0; i < ERROR_QUEUE_MAX + 3; i++)
  58435. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58436. while ((err = ERR_get_error_line(&file, &line))) {
  58437. AssertIntEQ(err, 990 + errorCount);
  58438. errorCount++;
  58439. }
  58440. /* test that the 3 errors over the max were dropped */
  58441. AssertIntEQ(errorCount, ERROR_QUEUE_MAX);
  58442. WOLFSSL_RETURN_FROM_THREAD(0);
  58443. }
  58444. #endif
  58445. static int test_error_queue_per_thread(void)
  58446. {
  58447. int res = TEST_SKIPPED;
  58448. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58449. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58450. defined(DEBUG_WOLFSSL)
  58451. THREAD_TYPE loggingThreads[LOGGING_THREADS];
  58452. int i;
  58453. ERR_clear_error(); /* clear out any error nodes */
  58454. loggingThreadsReady = 0;
  58455. for (i = 0; i < LOGGING_THREADS; i++)
  58456. start_thread(test_logging, NULL, &loggingThreads[i]);
  58457. loggingThreadsReady = 1;
  58458. for (i = 0; i < LOGGING_THREADS; i++)
  58459. join_thread(loggingThreads[i]);
  58460. res = TEST_SUCCESS;
  58461. #endif
  58462. return res;
  58463. }
  58464. static int test_wolfSSL_ERR_put_error(void)
  58465. {
  58466. EXPECT_DECLS;
  58467. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58468. defined(DEBUG_WOLFSSL)
  58469. const char* file;
  58470. int line;
  58471. ERR_clear_error(); /* clear out any error nodes */
  58472. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  58473. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58474. ERR_put_error(0,SYS_F_BIND, 1, "this file", 1);
  58475. ExpectIntEQ(ERR_get_error_line(&file, &line), 1);
  58476. ERR_put_error(0,SYS_F_CONNECT, 2, "this file", 2);
  58477. ExpectIntEQ(ERR_get_error_line(&file, &line), 2);
  58478. ERR_put_error(0,SYS_F_FOPEN, 3, "this file", 3);
  58479. ExpectIntEQ(ERR_get_error_line(&file, &line), 3);
  58480. ERR_put_error(0,SYS_F_FREAD, 4, "this file", 4);
  58481. ExpectIntEQ(ERR_get_error_line(&file, &line), 4);
  58482. ERR_put_error(0,SYS_F_GETADDRINFO, 5, "this file", 5);
  58483. ExpectIntEQ(ERR_get_error_line(&file, &line), 5);
  58484. ERR_put_error(0,SYS_F_GETSOCKOPT, 6, "this file", 6);
  58485. ExpectIntEQ(ERR_get_error_line(&file, &line), 6);
  58486. ERR_put_error(0,SYS_F_GETSOCKNAME, 7, "this file", 7);
  58487. ExpectIntEQ(ERR_get_error_line(&file, &line), 7);
  58488. ERR_put_error(0,SYS_F_GETHOSTBYNAME, 8, "this file", 8);
  58489. ExpectIntEQ(ERR_get_error_line(&file, &line), 8);
  58490. ERR_put_error(0,SYS_F_GETNAMEINFO, 9, "this file", 9);
  58491. ExpectIntEQ(ERR_get_error_line(&file, &line), 9);
  58492. ERR_put_error(0,SYS_F_GETSERVBYNAME, 10, "this file", 10);
  58493. ExpectIntEQ(ERR_get_error_line(&file, &line), 10);
  58494. ERR_put_error(0,SYS_F_IOCTLSOCKET, 11, "this file", 11);
  58495. ExpectIntEQ(ERR_get_error_line(&file, &line), 11);
  58496. ERR_put_error(0,SYS_F_LISTEN, 12, "this file", 12);
  58497. ExpectIntEQ(ERR_get_error_line(&file, &line), 12);
  58498. ERR_put_error(0,SYS_F_OPENDIR, 13, "this file", 13);
  58499. ExpectIntEQ(ERR_get_error_line(&file, &line), 13);
  58500. ERR_put_error(0,SYS_F_SETSOCKOPT, 14, "this file", 14);
  58501. ExpectIntEQ(ERR_get_error_line(&file, &line), 14);
  58502. ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
  58503. ExpectIntEQ(ERR_get_error_line(&file, &line), 15);
  58504. #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
  58505. ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG,
  58506. "this file", 100);
  58507. ExpectIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line),
  58508. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58509. ExpectIntEQ(line, 100);
  58510. ExpectIntEQ(wolfSSL_ERR_peek_error(),
  58511. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58512. ExpectIntEQ(ERR_get_error_line(&file, &line), ASN1_R_HEADER_TOO_LONG);
  58513. #endif
  58514. /* try reading past end of error queue */
  58515. file = NULL;
  58516. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58517. ExpectNull(file);
  58518. ExpectIntEQ(ERR_get_error_line_data(&file, &line, NULL, NULL), 0);
  58519. PEMerr(4,4);
  58520. ExpectIntEQ(ERR_get_error(), 4);
  58521. /* Empty and free up all error nodes */
  58522. ERR_clear_error();
  58523. /* Verify all nodes are cleared */
  58524. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  58525. ERR_clear_error();
  58526. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58527. #endif
  58528. return EXPECT_RESULT();
  58529. }
  58530. /*
  58531. * This is a regression test for a bug where the peek/get error functions were
  58532. * drawing from the end of the queue rather than the front.
  58533. */
  58534. static int test_wolfSSL_ERR_get_error_order(void)
  58535. {
  58536. EXPECT_DECLS;
  58537. #if defined(WOLFSSL_HAVE_ERROR_QUEUE) && defined(OPENSSL_EXTRA)
  58538. /* Empty the queue. */
  58539. wolfSSL_ERR_clear_error();
  58540. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), "test", 0);
  58541. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E), "test", 0);
  58542. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  58543. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  58544. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  58545. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  58546. #endif /* WOLFSSL_HAVE_ERROR_QUEUE && OPENSSL_EXTRA */
  58547. return EXPECT_RESULT();
  58548. }
  58549. #ifndef NO_BIO
  58550. static int test_wolfSSL_ERR_print_errors(void)
  58551. {
  58552. EXPECT_DECLS;
  58553. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58554. defined(DEBUG_WOLFSSL) && !defined(NO_ERROR_STRINGS)
  58555. BIO* bio = NULL;
  58556. char buf[1024];
  58557. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58558. ERR_clear_error(); /* clear out any error nodes */
  58559. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  58560. /* Choosing -600 as an unused errno. */
  58561. ERR_put_error(0,SYS_F_BIND, -600, "asn.c", 100);
  58562. ERR_print_errors(bio);
  58563. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 56);
  58564. ExpectIntEQ(XSTRNCMP(
  58565. "error:173:wolfSSL library:Bad function argument:ssl.c:0",
  58566. buf, 55), 0);
  58567. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 57);
  58568. ExpectIntEQ(XSTRNCMP(
  58569. "error:600:wolfSSL library:unknown error number:asn.c:100",
  58570. buf, 56), 0);
  58571. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 1);
  58572. ExpectIntEQ(buf[0], '\0');
  58573. ExpectIntEQ(ERR_get_error_line(NULL, NULL), 0);
  58574. BIO_free(bio);
  58575. #endif
  58576. return EXPECT_RESULT();
  58577. }
  58578. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58579. defined(DEBUG_WOLFSSL)
  58580. static int test_wolfSSL_error_cb(const char *str, size_t len, void *u)
  58581. {
  58582. wolfSSL_BIO_write((BIO*)u, str, (int)len);
  58583. return 0;
  58584. }
  58585. #endif
  58586. static int test_wolfSSL_ERR_print_errors_cb(void)
  58587. {
  58588. EXPECT_DECLS;
  58589. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58590. defined(DEBUG_WOLFSSL)
  58591. BIO* bio = NULL;
  58592. char buf[1024];
  58593. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58594. ERR_clear_error(); /* clear out any error nodes */
  58595. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  58596. ERR_put_error(0,SYS_F_BIND, -275, "asn.c", 100);
  58597. ERR_print_errors_cb(test_wolfSSL_error_cb, bio);
  58598. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 108);
  58599. ExpectIntEQ(XSTRNCMP(
  58600. "wolfSSL error occurred, error = 173 line:0 file:ssl.c",
  58601. buf, 53), 0);
  58602. ExpectIntEQ(XSTRNCMP(
  58603. "wolfSSL error occurred, error = 275 line:100 file:asn.c",
  58604. buf + 53, 55), 0);
  58605. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 0);
  58606. BIO_free(bio);
  58607. #endif
  58608. return EXPECT_RESULT();
  58609. }
  58610. /*
  58611. * Testing WOLFSSL_ERROR_MSG
  58612. */
  58613. static int test_WOLFSSL_ERROR_MSG(void)
  58614. {
  58615. int res = TEST_SKIPPED;
  58616. #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
  58617. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
  58618. const char* msg = TEST_STRING;
  58619. WOLFSSL_ERROR_MSG(msg);
  58620. res = TEST_SUCCESS;
  58621. #endif
  58622. return res;
  58623. } /* End test_WOLFSSL_ERROR_MSG */
  58624. /*
  58625. * Testing wc_ERR_remove_state
  58626. */
  58627. static int test_wc_ERR_remove_state(void)
  58628. {
  58629. int res = TEST_SKIPPED;
  58630. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  58631. wc_ERR_remove_state();
  58632. res = TEST_SUCCESS;
  58633. #endif
  58634. return res;
  58635. } /* End test_wc_ERR_remove_state */
  58636. /*
  58637. * Testing wc_ERR_print_errors_fp
  58638. */
  58639. static int test_wc_ERR_print_errors_fp(void)
  58640. {
  58641. EXPECT_DECLS;
  58642. #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \
  58643. (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM))
  58644. long sz;
  58645. XFILE fp = XBADFILE;
  58646. WOLFSSL_ERROR(WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58647. ExpectTrue((fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar")) !=
  58648. XBADFILE);
  58649. wc_ERR_print_errors_fp(fp);
  58650. #if defined(DEBUG_WOLFSSL)
  58651. ExpectTrue(XFSEEK(fp, 0, XSEEK_END) == 0);
  58652. #ifdef NO_ERROR_QUEUE
  58653. ExpectIntEQ(sz = XFTELL(fp), 0);
  58654. #else
  58655. ExpectIntNE(sz = XFTELL(fp), 0);
  58656. #endif
  58657. #endif
  58658. if (fp != XBADFILE)
  58659. XFCLOSE(fp);
  58660. (void)sz;
  58661. #endif
  58662. return EXPECT_RESULT();
  58663. } /* End test_wc_ERR_print_errors_fp */
  58664. #ifdef DEBUG_WOLFSSL
  58665. static void Logging_cb(const int logLevel, const char *const logMessage)
  58666. {
  58667. (void)logLevel;
  58668. (void)logMessage;
  58669. }
  58670. #endif
  58671. /*
  58672. * Testing wolfSSL_GetLoggingCb
  58673. */
  58674. static int test_wolfSSL_GetLoggingCb(void)
  58675. {
  58676. EXPECT_DECLS;
  58677. #ifdef DEBUG_WOLFSSL
  58678. /* Testing without wolfSSL_SetLoggingCb() */
  58679. ExpectNull(wolfSSL_GetLoggingCb());
  58680. /* Testing with wolfSSL_SetLoggingCb() */
  58681. ExpectIntEQ(wolfSSL_SetLoggingCb(Logging_cb), 0);
  58682. ExpectNotNull(wolfSSL_GetLoggingCb());
  58683. ExpectIntEQ(wolfSSL_SetLoggingCb(NULL), 0);
  58684. #endif
  58685. ExpectNull(wolfSSL_GetLoggingCb());
  58686. return EXPECT_RESULT();
  58687. } /* End test_wolfSSL_GetLoggingCb */
  58688. #endif /* !NO_BIO */
  58689. static int test_wolfSSL_MD4(void)
  58690. {
  58691. EXPECT_DECLS;
  58692. #if defined(OPENSSL_EXTRA) && !defined(NO_MD4)
  58693. MD4_CTX md4;
  58694. unsigned char out[16]; /* MD4_DIGEST_SIZE */
  58695. const char* msg = "12345678901234567890123456789012345678901234567890123456"
  58696. "789012345678901234567890";
  58697. const char* test = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f"
  58698. "\xcc\x05\x36";
  58699. int msgSz = (int)XSTRLEN(msg);
  58700. XMEMSET(out, 0, sizeof(out));
  58701. MD4_Init(&md4);
  58702. MD4_Update(&md4, (const void*)msg, (unsigned long)msgSz);
  58703. MD4_Final(out, &md4);
  58704. ExpectIntEQ(XMEMCMP(out, test, sizeof(out)), 0);
  58705. #endif
  58706. return EXPECT_RESULT();
  58707. }
  58708. static int test_wolfSSL_MD5(void)
  58709. {
  58710. EXPECT_DECLS;
  58711. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  58712. byte input1[] = "";
  58713. byte input2[] = "message digest";
  58714. byte hash[WC_MD5_DIGEST_SIZE];
  58715. unsigned char output1[] =
  58716. "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e";
  58717. unsigned char output2[] =
  58718. "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0";
  58719. WOLFSSL_MD5_CTX md5;
  58720. XMEMSET(&md5, 0, sizeof(md5));
  58721. /* Test cases for illegal parameters */
  58722. ExpectIntEQ(MD5_Init(NULL), 0);
  58723. ExpectIntEQ(MD5_Init(&md5), 1);
  58724. ExpectIntEQ(MD5_Update(NULL, input1, 0), 0);
  58725. ExpectIntEQ(MD5_Update(NULL, NULL, 0), 0);
  58726. ExpectIntEQ(MD5_Update(&md5, NULL, 1), 0);
  58727. ExpectIntEQ(MD5_Final(NULL, &md5), 0);
  58728. ExpectIntEQ(MD5_Final(hash, NULL), 0);
  58729. ExpectIntEQ(MD5_Final(NULL, NULL), 0);
  58730. /* Init MD5 CTX */
  58731. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  58732. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input1, XSTRLEN((const char*)&input1)),
  58733. 1);
  58734. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  58735. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  58736. /* Init MD5 CTX */
  58737. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  58738. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input2,
  58739. (int)XSTRLEN((const char*)input2)), 1);
  58740. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  58741. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  58742. #if !defined(NO_OLD_NAMES) && \
  58743. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  58744. ExpectPtrNE(MD5(NULL, 1, (byte*)&hash), &hash);
  58745. ExpectPtrEq(MD5(input1, 0, (byte*)&hash), &hash);
  58746. ExpectPtrNE(MD5(input1, 1, NULL), NULL);
  58747. ExpectPtrNE(MD5(NULL, 0, NULL), NULL);
  58748. ExpectPtrEq(MD5(input1, (int)XSTRLEN((const char*)&input1), (byte*)&hash),
  58749. &hash);
  58750. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  58751. ExpectPtrEq(MD5(input2, (int)XSTRLEN((const char*)&input2), (byte*)&hash),
  58752. &hash);
  58753. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  58754. {
  58755. byte data[] = "Data to be hashed.";
  58756. XMEMSET(hash, 0, WC_MD5_DIGEST_SIZE);
  58757. ExpectNotNull(MD5(data, sizeof(data), NULL));
  58758. ExpectNotNull(MD5(data, sizeof(data), hash));
  58759. ExpectNotNull(MD5(NULL, 0, hash));
  58760. ExpectNull(MD5(NULL, sizeof(data), hash));
  58761. }
  58762. #endif
  58763. #endif
  58764. return EXPECT_RESULT();
  58765. }
  58766. static int test_wolfSSL_MD5_Transform(void)
  58767. {
  58768. EXPECT_DECLS;
  58769. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  58770. byte input1[] = "";
  58771. byte input2[] = "abc";
  58772. byte local[WC_MD5_BLOCK_SIZE];
  58773. word32 sLen = 0;
  58774. #ifdef BIG_ENDIAN_ORDER
  58775. unsigned char output1[] =
  58776. "\x03\x1f\x1d\xac\x6e\xa5\x8e\xd0\x1f\xab\x67\xb7\x74\x31\x77\x91";
  58777. unsigned char output2[] =
  58778. "\xef\xd3\x79\x8d\x67\x17\x25\x90\xa4\x13\x79\xc7\xe3\xa7\x7b\xbc";
  58779. #else
  58780. unsigned char output1[] =
  58781. "\xac\x1d\x1f\x03\xd0\x8e\xa5\x6e\xb7\x67\xab\x1f\x91\x77\x31\x74";
  58782. unsigned char output2[] =
  58783. "\x8d\x79\xd3\xef\x90\x25\x17\x67\xc7\x79\x13\xa4\xbc\x7b\xa7\xe3";
  58784. #endif
  58785. union {
  58786. wc_Md5 native;
  58787. MD5_CTX compat;
  58788. } md5;
  58789. XMEMSET(&md5.compat, 0, sizeof(md5.compat));
  58790. XMEMSET(&local, 0, sizeof(local));
  58791. /* sanity check */
  58792. ExpectIntEQ(MD5_Transform(NULL, NULL), 0);
  58793. ExpectIntEQ(MD5_Transform(NULL, (const byte*)&input1), 0);
  58794. ExpectIntEQ(MD5_Transform(&md5.compat, NULL), 0);
  58795. ExpectIntEQ(wc_Md5Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58796. ExpectIntEQ(wc_Md5Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58797. ExpectIntEQ(wc_Md5Transform(&md5.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58798. /* Init MD5 CTX */
  58799. ExpectIntEQ(wolfSSL_MD5_Init(&md5.compat), 1);
  58800. /* Do Transform*/
  58801. sLen = (word32)XSTRLEN((char*)input1);
  58802. XMEMCPY(local, input1, sLen);
  58803. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  58804. ExpectIntEQ(XMEMCMP(md5.native.digest, output1, WC_MD5_DIGEST_SIZE), 0);
  58805. /* Init MD5 CTX */
  58806. ExpectIntEQ(MD5_Init(&md5.compat), 1);
  58807. sLen = (word32)XSTRLEN((char*)input2);
  58808. XMEMSET(local, 0, WC_MD5_BLOCK_SIZE);
  58809. XMEMCPY(local, input2, sLen);
  58810. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  58811. ExpectIntEQ(XMEMCMP(md5.native.digest, output2, WC_MD5_DIGEST_SIZE), 0);
  58812. #endif
  58813. return EXPECT_RESULT();
  58814. }
  58815. static int test_wolfSSL_SHA(void)
  58816. {
  58817. EXPECT_DECLS;
  58818. #if defined(OPENSSL_EXTRA) && !defined(HAVE_SELFTEST)
  58819. #if !defined(NO_SHA) && defined(NO_OLD_SHA_NAMES) && \
  58820. (!defined(HAVE_FIPS) || \
  58821. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  58822. {
  58823. const unsigned char in[] = "abc";
  58824. unsigned char expected[] = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
  58825. "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D";
  58826. unsigned char out[WC_SHA_DIGEST_SIZE];
  58827. unsigned char* p = NULL;
  58828. WOLFSSL_SHA_CTX sha;
  58829. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  58830. ExpectNotNull(SHA1(in, XSTRLEN((char*)in), out));
  58831. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  58832. /* SHA interface test */
  58833. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  58834. ExpectNull(SHA(NULL, XSTRLEN((char*)in), out));
  58835. ExpectNotNull(SHA(in, 0, out));
  58836. ExpectNotNull(SHA(in, XSTRLEN((char*)in), NULL));
  58837. ExpectNotNull(SHA(NULL, 0, out));
  58838. ExpectNotNull(SHA(NULL, 0, NULL));
  58839. ExpectNotNull(SHA(in, XSTRLEN((char*)in), out));
  58840. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  58841. ExpectNotNull(p = SHA(in, XSTRLEN((char*)in), NULL));
  58842. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA_DIGEST_SIZE), 0);
  58843. ExpectIntEQ(wolfSSL_SHA_Init(&sha), 1);
  58844. ExpectIntEQ(wolfSSL_SHA_Update(&sha, in, XSTRLEN((char*)in)), 1);
  58845. ExpectIntEQ(wolfSSL_SHA_Final(out, &sha), 1);
  58846. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  58847. ExpectIntEQ(wolfSSL_SHA1_Init(&sha), 1);
  58848. ExpectIntEQ(wolfSSL_SHA1_Update(&sha, in, XSTRLEN((char*)in)), 1);
  58849. ExpectIntEQ(wolfSSL_SHA1_Final(out, &sha), 1);
  58850. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  58851. }
  58852. #endif
  58853. #if !defined(NO_SHA256)
  58854. {
  58855. const unsigned char in[] = "abc";
  58856. unsigned char expected[] =
  58857. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  58858. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  58859. "\x15\xAD";
  58860. unsigned char out[WC_SHA256_DIGEST_SIZE];
  58861. unsigned char* p = NULL;
  58862. XMEMSET(out, 0, WC_SHA256_DIGEST_SIZE);
  58863. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  58864. ExpectNotNull(SHA256(in, XSTRLEN((char*)in), out));
  58865. #else
  58866. ExpectNotNull(wolfSSL_SHA256(in, XSTRLEN((char*)in), out));
  58867. #endif
  58868. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA256_DIGEST_SIZE), 0);
  58869. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  58870. ExpectNotNull(p = SHA256(in, XSTRLEN((char*)in), NULL));
  58871. #else
  58872. ExpectNotNull(p = wolfSSL_SHA256(in, XSTRLEN((char*)in), NULL));
  58873. #endif
  58874. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA256_DIGEST_SIZE), 0);
  58875. }
  58876. #endif
  58877. #if defined(WOLFSSL_SHA384)
  58878. {
  58879. const unsigned char in[] = "abc";
  58880. unsigned char expected[] =
  58881. "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  58882. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  58883. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  58884. "\xc8\x25\xa7";
  58885. unsigned char out[WC_SHA384_DIGEST_SIZE];
  58886. unsigned char* p = NULL;
  58887. XMEMSET(out, 0, WC_SHA384_DIGEST_SIZE);
  58888. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  58889. ExpectNotNull(SHA384(in, XSTRLEN((char*)in), out));
  58890. #else
  58891. ExpectNotNull(wolfSSL_SHA384(in, XSTRLEN((char*)in), out));
  58892. #endif
  58893. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA384_DIGEST_SIZE), 0);
  58894. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  58895. ExpectNotNull(p = SHA384(in, XSTRLEN((char*)in), NULL));
  58896. #else
  58897. ExpectNotNull(p = wolfSSL_SHA384(in, XSTRLEN((char*)in), NULL));
  58898. #endif
  58899. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA384_DIGEST_SIZE), 0);
  58900. }
  58901. #endif
  58902. #if defined(WOLFSSL_SHA512)
  58903. {
  58904. const unsigned char in[] = "abc";
  58905. unsigned char expected[] =
  58906. "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  58907. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  58908. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  58909. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  58910. "\xa5\x4c\xa4\x9f";
  58911. unsigned char out[WC_SHA512_DIGEST_SIZE];
  58912. unsigned char* p = NULL;
  58913. XMEMSET(out, 0, WC_SHA512_DIGEST_SIZE);
  58914. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  58915. ExpectNotNull(SHA512(in, XSTRLEN((char*)in), out));
  58916. #else
  58917. ExpectNotNull(wolfSSL_SHA512(in, XSTRLEN((char*)in), out));
  58918. #endif
  58919. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA512_DIGEST_SIZE), 0);
  58920. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  58921. ExpectNotNull(p = SHA512(in, XSTRLEN((char*)in), NULL));
  58922. #else
  58923. ExpectNotNull(p = wolfSSL_SHA512(in, XSTRLEN((char*)in), NULL));
  58924. #endif
  58925. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA512_DIGEST_SIZE), 0);
  58926. }
  58927. #endif
  58928. #endif
  58929. return EXPECT_RESULT();
  58930. }
  58931. static int test_wolfSSL_SHA_Transform(void)
  58932. {
  58933. EXPECT_DECLS;
  58934. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA)
  58935. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  58936. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  58937. byte input1[] = "";
  58938. byte input2[] = "abc";
  58939. byte local[WC_SHA_BLOCK_SIZE];
  58940. word32 sLen = 0;
  58941. #ifdef BIG_ENDIAN_ORDER
  58942. unsigned char output1[] =
  58943. "\x92\xb4\x04\xe5\x56\x58\x8c\xed\x6c\x1a\xcd\x4e\xbf\x05\x3f\x68"
  58944. "\x09\xf7\x3a\x93";
  58945. unsigned char output2[] =
  58946. "\x97\xb2\x74\x8b\x4f\x5b\xbc\xca\x5b\xc0\xe6\xea\x2d\x40\xb4\xa0"
  58947. "\x7c\x6e\x08\xb8";
  58948. #else
  58949. unsigned char output1[] =
  58950. "\xe5\x04\xb4\x92\xed\x8c\x58\x56\x4e\xcd\x1a\x6c\x68\x3f\x05\xbf"
  58951. "\x93\x3a\xf7\x09";
  58952. unsigned char output2[] =
  58953. "\x8b\x74\xb2\x97\xca\xbc\x5b\x4f\xea\xe6\xc0\x5b\xa0\xb4\x40\x2d"
  58954. "\xb8\x08\x6e\x7c";
  58955. #endif
  58956. union {
  58957. wc_Sha native;
  58958. SHA_CTX compat;
  58959. } sha;
  58960. union {
  58961. wc_Sha native;
  58962. SHA_CTX compat;
  58963. } sha1;
  58964. XMEMSET(&sha.compat, 0, sizeof(sha.compat));
  58965. XMEMSET(&local, 0, sizeof(local));
  58966. /* sanity check */
  58967. ExpectIntEQ(SHA_Transform(NULL, NULL), 0);
  58968. ExpectIntEQ(SHA_Transform(NULL, (const byte*)&input1), 0);
  58969. ExpectIntEQ(SHA_Transform(&sha.compat, NULL), 0);
  58970. ExpectIntEQ(SHA1_Transform(NULL, NULL), 0);
  58971. ExpectIntEQ(SHA1_Transform(NULL, (const byte*)&input1), 0);
  58972. ExpectIntEQ(SHA1_Transform(&sha.compat, NULL), 0);
  58973. ExpectIntEQ(wc_ShaTransform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58974. ExpectIntEQ(wc_ShaTransform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58975. ExpectIntEQ(wc_ShaTransform(&sha.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58976. /* Init SHA CTX */
  58977. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  58978. /* Do Transform*/
  58979. sLen = (word32)XSTRLEN((char*)input1);
  58980. XMEMCPY(local, input1, sLen);
  58981. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  58982. ExpectIntEQ(XMEMCMP(sha.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  58983. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  58984. /* Init SHA CTX */
  58985. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  58986. sLen = (word32)XSTRLEN((char*)input2);
  58987. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  58988. XMEMCPY(local, input2, sLen);
  58989. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  58990. ExpectIntEQ(XMEMCMP(sha.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  58991. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  58992. /* SHA1 */
  58993. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  58994. /* Init SHA CTX */
  58995. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  58996. /* Do Transform*/
  58997. sLen = (word32)XSTRLEN((char*)input1);
  58998. XMEMCPY(local, input1, sLen);
  58999. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59000. ExpectIntEQ(XMEMCMP(sha1.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  59001. ExpectIntEQ(SHA1_Final(local, &sha1.compat), 1); /* frees resources */
  59002. /* Init SHA CTX */
  59003. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  59004. sLen = (word32)XSTRLEN((char*)input2);
  59005. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59006. XMEMCPY(local, input2, sLen);
  59007. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59008. ExpectIntEQ(XMEMCMP(sha1.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  59009. ExpectIntEQ(SHA_Final(local, &sha1.compat), 1); /* frees resources */
  59010. #endif
  59011. #endif
  59012. return EXPECT_RESULT();
  59013. }
  59014. static int test_wolfSSL_SHA224(void)
  59015. {
  59016. EXPECT_DECLS;
  59017. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA224) && \
  59018. !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59019. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  59020. unsigned char input[] =
  59021. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59022. unsigned char output[] =
  59023. "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  59024. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  59025. size_t inLen;
  59026. byte hash[WC_SHA224_DIGEST_SIZE];
  59027. unsigned char* p;
  59028. inLen = XSTRLEN((char*)input);
  59029. XMEMSET(hash, 0, WC_SHA224_DIGEST_SIZE);
  59030. ExpectNull(SHA224(NULL, inLen, hash));
  59031. ExpectNotNull(SHA224(input, 0, hash));
  59032. ExpectNotNull(SHA224(input, inLen, NULL));
  59033. ExpectNotNull(SHA224(NULL, 0, hash));
  59034. ExpectNotNull(SHA224(NULL, 0, NULL));
  59035. ExpectNotNull(SHA224(input, inLen, hash));
  59036. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA224_DIGEST_SIZE), 0);
  59037. ExpectNotNull(p = SHA224(input, inLen, NULL));
  59038. ExpectIntEQ(XMEMCMP(p, output, WC_SHA224_DIGEST_SIZE), 0);
  59039. #endif
  59040. return EXPECT_RESULT();
  59041. }
  59042. static int test_wolfSSL_SHA256(void)
  59043. {
  59044. EXPECT_DECLS;
  59045. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
  59046. defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  59047. unsigned char input[] =
  59048. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59049. unsigned char output[] =
  59050. "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  59051. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  59052. "\x06\xC1";
  59053. size_t inLen;
  59054. byte hash[WC_SHA256_DIGEST_SIZE];
  59055. inLen = XSTRLEN((char*)input);
  59056. XMEMSET(hash, 0, WC_SHA256_DIGEST_SIZE);
  59057. ExpectNotNull(SHA256(input, inLen, hash));
  59058. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA256_DIGEST_SIZE), 0);
  59059. #endif
  59060. return EXPECT_RESULT();
  59061. }
  59062. static int test_wolfSSL_SHA256_Transform(void)
  59063. {
  59064. EXPECT_DECLS;
  59065. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  59066. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59067. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59068. !defined(WOLFSSL_DEVCRYPTO_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
  59069. !defined(WOLFSSL_KCAPI_HASH)
  59070. byte input1[] = "";
  59071. byte input2[] = "abc";
  59072. byte local[WC_SHA256_BLOCK_SIZE];
  59073. word32 sLen = 0;
  59074. #ifdef BIG_ENDIAN_ORDER
  59075. unsigned char output1[] =
  59076. "\xda\x56\x98\xbe\x17\xb9\xb4\x69\x62\x33\x57\x99\x77\x9f\xbe\xca"
  59077. "\x8c\xe5\xd4\x91\xc0\xd2\x62\x43\xba\xfe\xf9\xea\x18\x37\xa9\xd8";
  59078. unsigned char output2[] =
  59079. "\x1d\x4e\xd4\x67\x67\x7c\x61\x67\x44\x10\x76\x26\x78\x10\xff\xb8"
  59080. "\x40\xc8\x9a\x39\x73\x16\x60\x8c\xa6\x61\xd6\x05\x91\xf2\x8c\x35";
  59081. #else
  59082. unsigned char output1[] =
  59083. "\xbe\x98\x56\xda\x69\xb4\xb9\x17\x99\x57\x33\x62\xca\xbe\x9f\x77"
  59084. "\x91\xd4\xe5\x8c\x43\x62\xd2\xc0\xea\xf9\xfe\xba\xd8\xa9\x37\x18";
  59085. unsigned char output2[] =
  59086. "\x67\xd4\x4e\x1d\x67\x61\x7c\x67\x26\x76\x10\x44\xb8\xff\x10\x78"
  59087. "\x39\x9a\xc8\x40\x8c\x60\x16\x73\x05\xd6\x61\xa6\x35\x8c\xf2\x91";
  59088. #endif
  59089. union {
  59090. wc_Sha256 native;
  59091. SHA256_CTX compat;
  59092. } sha256;
  59093. XMEMSET(&sha256.compat, 0, sizeof(sha256.compat));
  59094. XMEMSET(&local, 0, sizeof(local));
  59095. /* sanity check */
  59096. ExpectIntEQ(SHA256_Transform(NULL, NULL), 0);
  59097. ExpectIntEQ(SHA256_Transform(NULL, (const byte*)&input1), 0);
  59098. ExpectIntEQ(SHA256_Transform(&sha256.compat, NULL), 0);
  59099. ExpectIntEQ(wc_Sha256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59100. ExpectIntEQ(wc_Sha256Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59101. ExpectIntEQ(wc_Sha256Transform(&sha256.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59102. /* Init SHA256 CTX */
  59103. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59104. /* Do Transform*/
  59105. sLen = (word32)XSTRLEN((char*)input1);
  59106. XMEMCPY(local, input1, sLen);
  59107. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59108. ExpectIntEQ(XMEMCMP(sha256.native.digest, output1, WC_SHA256_DIGEST_SIZE),
  59109. 0);
  59110. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59111. /* Init SHA256 CTX */
  59112. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59113. sLen = (word32)XSTRLEN((char*)input2);
  59114. XMEMSET(local, 0, WC_SHA256_BLOCK_SIZE);
  59115. XMEMCPY(local, input2, sLen);
  59116. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59117. ExpectIntEQ(XMEMCMP(sha256.native.digest, output2, WC_SHA256_DIGEST_SIZE),
  59118. 0);
  59119. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59120. #endif
  59121. #endif
  59122. return EXPECT_RESULT();
  59123. }
  59124. static int test_wolfSSL_SHA512_Transform(void)
  59125. {
  59126. EXPECT_DECLS;
  59127. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512)
  59128. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59129. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59130. !defined(WOLFSSL_KCAPI_HASH)
  59131. byte input1[] = "";
  59132. byte input2[] = "abc";
  59133. byte local[WC_SHA512_BLOCK_SIZE];
  59134. word32 sLen = 0;
  59135. #ifdef BIG_ENDIAN_ORDER
  59136. unsigned char output1[] =
  59137. "\xcf\x78\x81\xd5\x77\x4a\xcb\xe8\x53\x33\x62\xe0\xfb\xc7\x80\x70"
  59138. "\x02\x67\x63\x9d\x87\x46\x0e\xda\x30\x86\xcb\x40\xe8\x59\x31\xb0"
  59139. "\x71\x7d\xc9\x52\x88\xa0\x23\xa3\x96\xba\xb2\xc1\x4c\xe0\xb5\xe0"
  59140. "\x6f\xc4\xfe\x04\xea\xe3\x3e\x0b\x91\xf4\xd8\x0c\xbd\x66\x8b\xee";
  59141. unsigned char output2[] =
  59142. "\x11\x10\x93\x4e\xeb\xa0\xcc\x0d\xfd\x33\x43\x9c\xfb\x04\xc8\x21"
  59143. "\xa9\xb4\x26\x3d\xca\xab\x31\x41\xe2\xc6\xaa\xaf\xe1\x67\xd7\xab"
  59144. "\x31\x8f\x2e\x54\x2c\xba\x4e\x83\xbe\x88\xec\x9d\x8f\x2b\x38\x98"
  59145. "\x14\xd2\x4e\x9d\x53\x8b\x5e\x4d\xde\x68\x6c\x69\xaf\x20\x96\xf0";
  59146. #else
  59147. unsigned char output1[] =
  59148. "\xe8\xcb\x4a\x77\xd5\x81\x78\xcf\x70\x80\xc7\xfb\xe0\x62\x33\x53"
  59149. "\xda\x0e\x46\x87\x9d\x63\x67\x02\xb0\x31\x59\xe8\x40\xcb\x86\x30"
  59150. "\xa3\x23\xa0\x88\x52\xc9\x7d\x71\xe0\xb5\xe0\x4c\xc1\xb2\xba\x96"
  59151. "\x0b\x3e\xe3\xea\x04\xfe\xc4\x6f\xee\x8b\x66\xbd\x0c\xd8\xf4\x91";
  59152. unsigned char output2[] =
  59153. "\x0d\xcc\xa0\xeb\x4e\x93\x10\x11\x21\xc8\x04\xfb\x9c\x43\x33\xfd"
  59154. "\x41\x31\xab\xca\x3d\x26\xb4\xa9\xab\xd7\x67\xe1\xaf\xaa\xc6\xe2"
  59155. "\x83\x4e\xba\x2c\x54\x2e\x8f\x31\x98\x38\x2b\x8f\x9d\xec\x88\xbe"
  59156. "\x4d\x5e\x8b\x53\x9d\x4e\xd2\x14\xf0\x96\x20\xaf\x69\x6c\x68\xde";
  59157. #endif
  59158. union {
  59159. wc_Sha512 native;
  59160. SHA512_CTX compat;
  59161. } sha512;
  59162. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59163. XMEMSET(&local, 0, sizeof(local));
  59164. /* sanity check */
  59165. ExpectIntEQ(SHA512_Transform(NULL, NULL), 0);
  59166. ExpectIntEQ(SHA512_Transform(NULL, (const byte*)&input1), 0);
  59167. ExpectIntEQ(SHA512_Transform(&sha512.compat, NULL), 0);
  59168. ExpectIntEQ(wc_Sha512Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59169. ExpectIntEQ(wc_Sha512Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59170. ExpectIntEQ(wc_Sha512Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59171. /* Init SHA512 CTX */
  59172. ExpectIntEQ(wolfSSL_SHA512_Init(&sha512.compat), 1);
  59173. /* Do Transform*/
  59174. sLen = (word32)XSTRLEN((char*)input1);
  59175. XMEMCPY(local, input1, sLen);
  59176. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59177. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59178. WC_SHA512_DIGEST_SIZE), 0);
  59179. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59180. /* Init SHA512 CTX */
  59181. ExpectIntEQ(SHA512_Init(&sha512.compat), 1);
  59182. sLen = (word32)XSTRLEN((char*)input2);
  59183. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59184. XMEMCPY(local, input2, sLen);
  59185. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59186. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59187. WC_SHA512_DIGEST_SIZE), 0);
  59188. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59189. (void)input1;
  59190. #endif
  59191. #endif
  59192. return EXPECT_RESULT();
  59193. }
  59194. static int test_wolfSSL_SHA512_224_Transform(void)
  59195. {
  59196. EXPECT_DECLS;
  59197. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59198. !defined(WOLFSSL_NOSHA512_224)
  59199. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59200. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59201. !defined(WOLFSSL_KCAPI_HASH)
  59202. byte input1[] = "";
  59203. byte input2[] = "abc";
  59204. byte local[WC_SHA512_BLOCK_SIZE];
  59205. word32 sLen = 0;
  59206. unsigned char output1[] =
  59207. "\x94\x24\x66\xd4\x60\x3a\xeb\x23\x1d\xa8\x69\x31\x3c\xd2\xde\x11"
  59208. "\x48\x0f\x4a\x5a\xdf\x3a\x8d\x87\xcf\xcd\xbf\xa5\x03\x21\x50\xf1"
  59209. "\x8a\x0d\x0f\x0d\x3c\x07\xba\x52\xe0\xaa\x3c\xbb\xf1\xd3\x3f\xca"
  59210. "\x12\xa7\x61\xf8\x47\xda\x0d\x1b\x79\xc2\x65\x13\x92\xc1\x9c\xa5";
  59211. unsigned char output2[] =
  59212. "\x51\x28\xe7\x0b\xca\x1e\xbc\x5f\xd7\x34\x0b\x48\x30\xd7\xc2\x75"
  59213. "\x6d\x8d\x48\x2c\x1f\xc7\x9e\x2b\x20\x5e\xbb\x0f\x0e\x4d\xb7\x61"
  59214. "\x31\x76\x33\xa0\xb4\x3d\x5f\x93\xc1\x73\xac\xf7\x21\xff\x69\x17"
  59215. "\xce\x66\xe5\x1e\x31\xe7\xf3\x22\x0f\x0b\x34\xd7\x5a\x57\xeb\xbf";
  59216. union {
  59217. wc_Sha512 native;
  59218. SHA512_CTX compat;
  59219. } sha512;
  59220. #ifdef BIG_ENDIAN_ORDER
  59221. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59222. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59223. #endif
  59224. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59225. XMEMSET(&local, 0, sizeof(local));
  59226. /* sanity check */
  59227. ExpectIntEQ(SHA512_224_Transform(NULL, NULL), 0);
  59228. ExpectIntEQ(SHA512_224_Transform(NULL, (const byte*)&input1), 0);
  59229. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, NULL), 0);
  59230. ExpectIntEQ(wc_Sha512_224Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59231. ExpectIntEQ(wc_Sha512_224Transform(NULL, (const byte*)&input1),
  59232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59233. ExpectIntEQ(wc_Sha512_224Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59234. /* Init SHA512 CTX */
  59235. ExpectIntEQ(wolfSSL_SHA512_224_Init(&sha512.compat), 1);
  59236. /* Do Transform*/
  59237. sLen = (word32)XSTRLEN((char*)input1);
  59238. XMEMCPY(local, input1, sLen);
  59239. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59240. 1);
  59241. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59242. WC_SHA512_DIGEST_SIZE), 0);
  59243. /* frees resources */
  59244. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59245. /* Init SHA512 CTX */
  59246. ExpectIntEQ(SHA512_224_Init(&sha512.compat), 1);
  59247. sLen = (word32)XSTRLEN((char*)input2);
  59248. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59249. XMEMCPY(local, input2, sLen);
  59250. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59251. 1);
  59252. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59253. WC_SHA512_DIGEST_SIZE), 0);
  59254. /* frees resources */
  59255. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59256. #endif
  59257. #endif
  59258. return EXPECT_RESULT();
  59259. }
  59260. static int test_wolfSSL_SHA512_256_Transform(void)
  59261. {
  59262. EXPECT_DECLS;
  59263. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59264. !defined(WOLFSSL_NOSHA512_256)
  59265. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59266. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59267. !defined(WOLFSSL_KCAPI_HASH)
  59268. byte input1[] = "";
  59269. byte input2[] = "abc";
  59270. byte local[WC_SHA512_BLOCK_SIZE];
  59271. word32 sLen = 0;
  59272. unsigned char output1[] =
  59273. "\xf8\x37\x37\x5a\xd7\x2e\x56\xec\xe2\x51\xa8\x31\x3a\xa0\x63\x2b"
  59274. "\x7e\x7c\x64\xcc\xd9\xff\x2b\x6b\xeb\xc3\xd4\x4d\x7f\x8a\x3a\xb5"
  59275. "\x61\x85\x0b\x37\x30\x9f\x3b\x08\x5e\x7b\xd3\xbc\x6d\x00\x61\xc0"
  59276. "\x65\x9a\xd7\x73\xda\x40\xbe\xc1\xe5\x2f\xc6\x5d\xb7\x9f\xbe\x60";
  59277. unsigned char output2[] =
  59278. "\x22\xad\xc0\x30\xee\xd4\x6a\xef\x13\xee\x5a\x95\x8b\x1f\xb7\xb6"
  59279. "\xb6\xba\xc0\x44\xb8\x18\x3b\xf0\xf6\x4b\x70\x9f\x03\xba\x64\xa1"
  59280. "\xe1\xe3\x45\x15\x91\x7d\xcb\x0b\x9a\xf0\xd2\x8e\x47\x8b\x37\x78"
  59281. "\x91\x41\xa6\xc4\xb0\x29\x8f\x8b\xdd\x78\x5c\xf2\x73\x3f\x21\x31";
  59282. union {
  59283. wc_Sha512 native;
  59284. SHA512_CTX compat;
  59285. } sha512;
  59286. #ifdef BIG_ENDIAN_ORDER
  59287. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59288. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59289. #endif
  59290. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59291. XMEMSET(&local, 0, sizeof(local));
  59292. /* sanity check */
  59293. ExpectIntEQ(SHA512_256_Transform(NULL, NULL), 0);
  59294. ExpectIntEQ(SHA512_256_Transform(NULL, (const byte*)&input1), 0);
  59295. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, NULL), 0);
  59296. ExpectIntEQ(wc_Sha512_256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59297. ExpectIntEQ(wc_Sha512_256Transform(NULL, (const byte*)&input1),
  59298. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59299. ExpectIntEQ(wc_Sha512_256Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59300. /* Init SHA512 CTX */
  59301. ExpectIntEQ(wolfSSL_SHA512_256_Init(&sha512.compat), 1);
  59302. /* Do Transform*/
  59303. sLen = (word32)XSTRLEN((char*)input1);
  59304. XMEMCPY(local, input1, sLen);
  59305. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59306. 1);
  59307. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59308. WC_SHA512_DIGEST_SIZE), 0);
  59309. /* frees resources */
  59310. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59311. /* Init SHA512 CTX */
  59312. ExpectIntEQ(SHA512_256_Init(&sha512.compat), 1);
  59313. sLen = (word32)XSTRLEN((char*)input2);
  59314. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59315. XMEMCPY(local, input2, sLen);
  59316. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59317. 1);
  59318. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59319. WC_SHA512_DIGEST_SIZE), 0);
  59320. /* frees resources */
  59321. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59322. #endif
  59323. #endif
  59324. return EXPECT_RESULT();
  59325. }
  59326. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59327. /* helper function for test_wolfSSL_HMAC_CTX, digest size is expected to be a
  59328. * buffer of 64 bytes.
  59329. *
  59330. * returns the size of the digest buffer on success and a negative value on
  59331. * failure.
  59332. */
  59333. static int test_HMAC_CTX_helper(const EVP_MD* type, unsigned char* digest,
  59334. int* sz)
  59335. {
  59336. EXPECT_DECLS;
  59337. HMAC_CTX ctx1;
  59338. HMAC_CTX ctx2;
  59339. unsigned char key[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  59340. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  59341. unsigned char long_key[] =
  59342. "0123456789012345678901234567890123456789"
  59343. "0123456789012345678901234567890123456789"
  59344. "0123456789012345678901234567890123456789"
  59345. "0123456789012345678901234567890123456789";
  59346. unsigned char msg[] = "message to hash";
  59347. unsigned int digestSz = 64;
  59348. int keySz = sizeof(key);
  59349. int long_keySz = sizeof(long_key);
  59350. int msgSz = sizeof(msg);
  59351. unsigned char digest2[64];
  59352. unsigned int digestSz2 = 64;
  59353. HMAC_CTX_init(&ctx1);
  59354. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59355. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59356. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59357. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59358. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59359. HMAC_CTX_cleanup(&ctx1);
  59360. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59361. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz2), SSL_SUCCESS);
  59362. HMAC_CTX_cleanup(&ctx2);
  59363. ExpectIntEQ(digestSz, digestSz2);
  59364. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59365. /* test HMAC_Init with NULL key */
  59366. /* init after copy */
  59367. HMAC_CTX_init(&ctx1);
  59368. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59369. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59370. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59371. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59372. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59373. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59374. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59375. HMAC_CTX_cleanup(&ctx1);
  59376. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59377. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59378. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59379. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59380. HMAC_CTX_cleanup(&ctx2);
  59381. ExpectIntEQ(digestSz, digestSz2);
  59382. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59383. /* long key */
  59384. HMAC_CTX_init(&ctx1);
  59385. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)long_key, long_keySz, type),
  59386. SSL_SUCCESS);
  59387. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59388. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59389. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59390. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59391. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59392. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59393. HMAC_CTX_cleanup(&ctx1);
  59394. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59395. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59396. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59397. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59398. HMAC_CTX_cleanup(&ctx2);
  59399. ExpectIntEQ(digestSz, digestSz2);
  59400. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59401. /* init before copy */
  59402. HMAC_CTX_init(&ctx1);
  59403. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59404. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59405. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59406. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59407. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59408. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59409. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59410. HMAC_CTX_cleanup(&ctx1);
  59411. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59412. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59413. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59414. HMAC_CTX_cleanup(&ctx2);
  59415. ExpectIntEQ(digestSz, digestSz2);
  59416. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59417. *sz = (int)digestSz;
  59418. return EXPECT_RESULT();
  59419. }
  59420. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
  59421. static int test_wolfSSL_HMAC_CTX(void)
  59422. {
  59423. EXPECT_DECLS;
  59424. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59425. unsigned char digest[64];
  59426. int digestSz;
  59427. WOLFSSL_HMAC_CTX* hmac_ctx = NULL;
  59428. WOLFSSL_HMAC_CTX ctx1;
  59429. WOLFSSL_HMAC_CTX ctx2;
  59430. ExpectNotNull(hmac_ctx = wolfSSL_HMAC_CTX_new());
  59431. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(NULL), 1);
  59432. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(hmac_ctx), 1);
  59433. wolfSSL_HMAC_CTX_free(NULL);
  59434. wolfSSL_HMAC_CTX_free(hmac_ctx);
  59435. XMEMSET(&ctx2, 0, sizeof(WOLFSSL_HMAC_CTX));
  59436. ExpectIntEQ(HMAC_CTX_init(NULL), 1);
  59437. ExpectIntEQ(HMAC_CTX_init(&ctx2), 1);
  59438. ExpectIntEQ(HMAC_CTX_copy(NULL, NULL), 0);
  59439. ExpectIntEQ(HMAC_CTX_copy(NULL, &ctx2), 0);
  59440. ExpectIntEQ(HMAC_CTX_copy(&ctx2, NULL), 0);
  59441. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  59442. ((! defined(HAVE_FIPS_VERSION)) || \
  59443. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  59444. /* Copy object that hasn't had a digest set - MD5. */
  59445. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 1);
  59446. #else
  59447. /* Copy object that hasn't had a digest set. */
  59448. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 0);
  59449. #endif
  59450. HMAC_CTX_cleanup(NULL);
  59451. HMAC_CTX_cleanup(&ctx2);
  59452. ExpectNull(HMAC_CTX_get_md(NULL));
  59453. #ifndef NO_SHA
  59454. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha1(), digest, &digestSz)),
  59455. TEST_SUCCESS);
  59456. ExpectIntEQ(digestSz, 20);
  59457. ExpectIntEQ(XMEMCMP("\xD9\x68\x77\x23\x70\xFB\x53\x70\x53\xBA\x0E\xDC\xDA"
  59458. "\xBF\x03\x98\x31\x19\xB2\xCC", digest, digestSz), 0);
  59459. #endif /* !NO_SHA */
  59460. #ifdef WOLFSSL_SHA224
  59461. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha224(), digest, &digestSz)),
  59462. TEST_SUCCESS);
  59463. ExpectIntEQ(digestSz, 28);
  59464. ExpectIntEQ(XMEMCMP("\x57\xFD\xF4\xE1\x2D\xB0\x79\xD7\x4B\x25\x7E\xB1\x95"
  59465. "\x9C\x11\xAC\x2D\x1E\x78\x94\x4F\x3A\x0F\xED\xF8\xAD"
  59466. "\x02\x0E", digest, digestSz), 0);
  59467. #endif /* WOLFSSL_SHA224 */
  59468. #ifndef NO_SHA256
  59469. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha256(), digest, &digestSz)),
  59470. TEST_SUCCESS);
  59471. ExpectIntEQ(digestSz, 32);
  59472. ExpectIntEQ(XMEMCMP("\x13\xAB\x76\x91\x0C\x37\x86\x8D\xB3\x7E\x30\x0C\xFC"
  59473. "\xB0\x2E\x8E\x4A\xD7\xD4\x25\xCC\x3A\xA9\x0F\xA2\xF2"
  59474. "\x47\x1E\x62\x6F\x5D\xF2", digest, digestSz), 0);
  59475. #endif /* !NO_SHA256 */
  59476. #ifdef WOLFSSL_SHA384
  59477. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha384(), digest, &digestSz)),
  59478. TEST_SUCCESS);
  59479. ExpectIntEQ(digestSz, 48);
  59480. ExpectIntEQ(XMEMCMP("\x9E\xCB\x07\x0C\x11\x76\x3F\x23\xC3\x25\x0E\xC4\xB7"
  59481. "\x28\x77\x95\x99\xD5\x9D\x7A\xBB\x1A\x9F\xB7\xFD\x25"
  59482. "\xC9\x72\x47\x9F\x8F\x86\x76\xD6\x20\x57\x87\xB7\xE7"
  59483. "\xCD\xFB\xC2\xCC\x9F\x2B\xC5\x41\xAB",
  59484. digest, digestSz), 0);
  59485. #endif /* WOLFSSL_SHA384 */
  59486. #ifdef WOLFSSL_SHA512
  59487. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha512(), digest, &digestSz)),
  59488. TEST_SUCCESS);
  59489. ExpectIntEQ(digestSz, 64);
  59490. ExpectIntEQ(XMEMCMP("\xD4\x21\x0C\x8B\x60\x6F\xF4\xBF\x07\x2F\x26\xCC\xAD"
  59491. "\xBC\x06\x0B\x34\x78\x8B\x4F\xD6\xC0\x42\xF1\x33\x10"
  59492. "\x6C\x4F\x1E\x55\x59\xDD\x2A\x9F\x15\x88\x62\xF8\x60"
  59493. "\xA3\x99\x91\xE2\x08\x7B\xF7\x95\x3A\xB0\x92\x48\x60"
  59494. "\x88\x8B\x5B\xB8\x5F\xE9\xB6\xB1\x96\xE3\xB5\xF0",
  59495. digest, digestSz), 0);
  59496. #endif /* WOLFSSL_SHA512 */
  59497. #ifdef WOLFSSL_SHA3
  59498. #ifndef WOLFSSL_NOSHA3_224
  59499. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_224(), digest, &digestSz)),
  59500. TEST_SUCCESS);
  59501. ExpectIntEQ(digestSz, 28);
  59502. ExpectIntEQ(XMEMCMP("\xdc\x53\x25\x3f\xc0\x9d\x2b\x0c\x7f\x59\x11\x17\x08"
  59503. "\x5c\xe8\x43\x31\x01\x5a\xb3\xe3\x08\x37\x71\x26\x0b"
  59504. "\x29\x0f", digest, digestSz), 0);
  59505. #endif
  59506. #ifndef WOLFSSL_NOSHA3_256
  59507. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_256(), digest, &digestSz)),
  59508. TEST_SUCCESS);
  59509. ExpectIntEQ(digestSz, 32);
  59510. ExpectIntEQ(XMEMCMP("\x0f\x00\x89\x82\x15\xce\xd6\x45\x01\x83\xce\xc8\x35"
  59511. "\xab\x71\x07\xc9\xfe\x61\x22\x38\xf9\x09\xad\x35\x65"
  59512. "\x43\x77\x24\xd4\x1e\xf4", digest, digestSz), 0);
  59513. #endif
  59514. #ifndef WOLFSSL_NOSHA3_384
  59515. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_384(), digest, &digestSz)),
  59516. TEST_SUCCESS);
  59517. ExpectIntEQ(digestSz, 48);
  59518. ExpectIntEQ(XMEMCMP("\x0f\x6a\xc0\xfb\xc3\xf2\x80\xb1\xb4\x04\xb6\xc8\x45"
  59519. "\x23\x3b\xb4\xbe\xc6\xea\x85\x07\xca\x8c\x71\xbb\x6e"
  59520. "\x79\xf6\xf9\x2b\x98\xf5\xef\x11\x39\xd4\x5d\xd3\xca"
  59521. "\xc0\xe6\x81\xf7\x73\xf9\x85\x5d\x4f",
  59522. digest, digestSz), 0);
  59523. #endif
  59524. #ifndef WOLFSSL_NOSHA3_512
  59525. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_512(), digest, &digestSz)),
  59526. TEST_SUCCESS);
  59527. ExpectIntEQ(digestSz, 64);
  59528. ExpectIntEQ(XMEMCMP("\x3e\x77\xe3\x59\x42\x89\xed\xc3\xa4\x26\x3d\xa4\x75"
  59529. "\xd2\x84\x8c\xb2\xf3\x25\x04\x47\x61\xce\x1c\x42\x86"
  59530. "\xcd\xf4\x56\xaa\x2f\x84\xb1\x3b\x18\xed\xe6\xd6\x48"
  59531. "\x15\xb0\x29\xc5\x9d\x32\xef\xdd\x3e\x09\xf6\xed\x9e"
  59532. "\x70\xbc\x1c\x63\xf7\x3b\x3e\xe1\xdc\x84\x9c\x1c",
  59533. digest, digestSz), 0);
  59534. #endif
  59535. #endif
  59536. #if !defined(NO_MD5) && (!defined(HAVE_FIPS_VERSION) || \
  59537. HAVE_FIPS_VERSION <= 2)
  59538. ExpectIntEQ((test_HMAC_CTX_helper(EVP_md5(), digest, &digestSz)),
  59539. TEST_SUCCESS);
  59540. ExpectIntEQ(digestSz, 16);
  59541. ExpectIntEQ(XMEMCMP("\xB7\x27\xC4\x41\xE5\x2E\x62\xBA\x54\xED\x72\x70\x9F"
  59542. "\xE4\x98\xDD", digest, digestSz), 0);
  59543. #endif /* !NO_MD5 */
  59544. #endif
  59545. return EXPECT_RESULT();
  59546. }
  59547. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  59548. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  59549. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  59550. static int test_openssl_hmac(const WOLFSSL_EVP_MD* md, int md_len)
  59551. {
  59552. EXPECT_DECLS;
  59553. static const unsigned char key[] = "simple test key";
  59554. HMAC_CTX* hmac = NULL;
  59555. ENGINE* e = NULL;
  59556. unsigned char hash[WC_MAX_DIGEST_SIZE];
  59557. unsigned int len;
  59558. ExpectNotNull(hmac = HMAC_CTX_new());
  59559. HMAC_CTX_init(hmac);
  59560. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  59561. ((! defined(HAVE_FIPS_VERSION)) || \
  59562. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  59563. /* Get size on object that hasn't had a digest set - MD5. */
  59564. ExpectIntEQ(HMAC_size(hmac), 16);
  59565. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 1);
  59566. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 1);
  59567. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 1);
  59568. #else
  59569. ExpectIntEQ(HMAC_size(hmac), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59570. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 0);
  59571. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 0);
  59572. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 0);
  59573. #endif
  59574. ExpectIntEQ(HMAC_Init_ex(NULL, (void*)key, (int)sizeof(key), md, e), 0);
  59575. ExpectIntEQ(HMAC_Init_ex(hmac, (void*)key, (int)sizeof(key), md, e), 1);
  59576. /* re-using test key as data to hash */
  59577. ExpectIntEQ(HMAC_Update(NULL, key, (int)sizeof(key)), 0);
  59578. ExpectIntEQ(HMAC_Update(hmac, key, (int)sizeof(key)), 1);
  59579. ExpectIntEQ(HMAC_Update(hmac, key, 0), 1);
  59580. ExpectIntEQ(HMAC_Update(hmac, NULL, 0), 1);
  59581. ExpectIntEQ(HMAC_Update(hmac, NULL, (int)sizeof(key)), 1);
  59582. ExpectIntEQ(HMAC_Final(NULL, NULL, &len), 0);
  59583. ExpectIntEQ(HMAC_Final(hmac, NULL, &len), 0);
  59584. ExpectIntEQ(HMAC_Final(NULL, hash, &len), 0);
  59585. ExpectIntEQ(HMAC_Final(hmac, hash, &len), 1);
  59586. ExpectIntEQ(HMAC_Final(hmac, hash, NULL), 1);
  59587. ExpectIntEQ(len, md_len);
  59588. ExpectIntEQ(HMAC_size(NULL), 0);
  59589. ExpectIntEQ(HMAC_size(hmac), md_len);
  59590. ExpectStrEQ(HMAC_CTX_get_md(hmac), md);
  59591. HMAC_cleanup(NULL);
  59592. HMAC_cleanup(hmac);
  59593. HMAC_CTX_free(hmac);
  59594. len = 0;
  59595. ExpectNull(HMAC(NULL, key, (int)sizeof(key), NULL, 0, hash, &len));
  59596. ExpectNull(HMAC(md, NULL, (int)sizeof(key), NULL, 0, hash, &len));
  59597. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, 0, NULL, &len));
  59598. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, &len));
  59599. ExpectIntEQ(len, md_len);
  59600. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, NULL));
  59601. /* With data. */
  59602. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, (int)sizeof(key), hash,
  59603. &len));
  59604. /* With NULL data. */
  59605. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, (int)sizeof(key), hash,
  59606. &len));
  59607. /* With zero length data. */
  59608. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, 0, hash, &len));
  59609. return EXPECT_RESULT();
  59610. }
  59611. #endif
  59612. static int test_wolfSSL_HMAC(void)
  59613. {
  59614. EXPECT_DECLS;
  59615. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  59616. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  59617. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  59618. #ifndef NO_SHA256
  59619. ExpectIntEQ(test_openssl_hmac(EVP_sha256(), (int)WC_SHA256_DIGEST_SIZE),
  59620. TEST_SUCCESS);
  59621. #endif
  59622. #ifdef WOLFSSL_SHA224
  59623. ExpectIntEQ(test_openssl_hmac(EVP_sha224(), (int)WC_SHA224_DIGEST_SIZE),
  59624. TEST_SUCCESS);
  59625. #endif
  59626. #ifdef WOLFSSL_SHA384
  59627. ExpectIntEQ(test_openssl_hmac(EVP_sha384(), (int)WC_SHA384_DIGEST_SIZE),
  59628. TEST_SUCCESS);
  59629. #endif
  59630. #ifdef WOLFSSL_SHA512
  59631. ExpectIntEQ(test_openssl_hmac(EVP_sha512(), (int)WC_SHA512_DIGEST_SIZE),
  59632. TEST_SUCCESS);
  59633. #endif
  59634. #ifdef WOLFSSL_SHA3
  59635. #ifndef WOLFSSL_NOSHA3_224
  59636. ExpectIntEQ(test_openssl_hmac(EVP_sha3_224(),
  59637. (int)WC_SHA3_224_DIGEST_SIZE), TEST_SUCCESS);
  59638. #endif
  59639. #ifndef WOLFSSL_NOSHA3_256
  59640. ExpectIntEQ(test_openssl_hmac(EVP_sha3_256(),
  59641. (int)WC_SHA3_256_DIGEST_SIZE), TEST_SUCCESS);
  59642. #endif
  59643. #ifndef WOLFSSL_NOSHA3_384
  59644. ExpectIntEQ(test_openssl_hmac(EVP_sha3_384(),
  59645. (int)WC_SHA3_384_DIGEST_SIZE), TEST_SUCCESS);
  59646. #endif
  59647. #ifndef WOLFSSL_NOSHA3_512
  59648. ExpectIntEQ(test_openssl_hmac(EVP_sha3_512(),
  59649. (int)WC_SHA3_512_DIGEST_SIZE), TEST_SUCCESS);
  59650. #endif
  59651. #endif
  59652. #ifndef NO_SHA
  59653. ExpectIntEQ(test_openssl_hmac(EVP_sha1(), (int)WC_SHA_DIGEST_SIZE),
  59654. TEST_SUCCESS);
  59655. #endif
  59656. #endif
  59657. return EXPECT_RESULT();
  59658. }
  59659. static int test_wolfSSL_CMAC(void)
  59660. {
  59661. EXPECT_DECLS;
  59662. #if defined(WOLFSSL_CMAC) && defined(OPENSSL_EXTRA) && \
  59663. defined(WOLFSSL_AES_DIRECT)
  59664. int i;
  59665. byte key[AES_256_KEY_SIZE];
  59666. CMAC_CTX* cmacCtx = NULL;
  59667. byte out[AES_BLOCK_SIZE];
  59668. size_t outLen = AES_BLOCK_SIZE;
  59669. for (i=0; i < AES_256_KEY_SIZE; ++i) {
  59670. key[i] = i;
  59671. }
  59672. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59673. /* Check CMAC_CTX_get0_cipher_ctx; return value not used. */
  59674. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  59675. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  59676. NULL), 1);
  59677. /* re-using test key as data to hash */
  59678. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  59679. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  59680. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 1);
  59681. ExpectIntEQ(outLen, AES_BLOCK_SIZE);
  59682. /* No Update works. */
  59683. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  59684. NULL), 1);
  59685. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59686. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  59687. NULL), 1);
  59688. /* Test parameters with CMAC_Update. */
  59689. ExpectIntEQ(CMAC_Update(NULL, NULL, 0), 0);
  59690. ExpectIntEQ(CMAC_Update(NULL, key, 0), 0);
  59691. ExpectIntEQ(CMAC_Update(NULL, NULL, AES_128_KEY_SIZE), 0);
  59692. ExpectIntEQ(CMAC_Update(NULL, key, AES_128_KEY_SIZE), 0);
  59693. ExpectIntEQ(CMAC_Update(cmacCtx, key, 0), 1);
  59694. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  59695. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, AES_128_KEY_SIZE), 1);
  59696. /* Test parameters with CMAC_Final. */
  59697. ExpectIntEQ(CMAC_Final(NULL, NULL, NULL), 0);
  59698. ExpectIntEQ(CMAC_Final(NULL, out, NULL), 0);
  59699. ExpectIntEQ(CMAC_Final(NULL, NULL, &outLen), 0);
  59700. ExpectIntEQ(CMAC_Final(NULL, out, &outLen), 0);
  59701. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, NULL), 1);
  59702. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, &outLen), 1);
  59703. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59704. CMAC_CTX_free(cmacCtx);
  59705. /* Test parameters with CMAC Init. */
  59706. cmacCtx = NULL;
  59707. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59708. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  59709. ExpectIntEQ(CMAC_Init(NULL, NULL, 0, NULL, NULL), 0);
  59710. ExpectIntEQ(CMAC_Init(NULL, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  59711. NULL), 0);
  59712. ExpectIntEQ(CMAC_Init(cmacCtx, NULL, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  59713. NULL), 0);
  59714. /* give a key too small for the cipher, verify we get failure */
  59715. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_192_cbc(),
  59716. NULL), 0);
  59717. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, NULL, NULL), 0);
  59718. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  59719. /* Only AES-CBC supported. */
  59720. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_gcm(),
  59721. NULL), 0);
  59722. #endif
  59723. CMAC_CTX_free(cmacCtx);
  59724. ExpectNull(CMAC_CTX_get0_cipher_ctx(NULL));
  59725. cmacCtx = NULL;
  59726. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59727. /* No Init. */
  59728. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 0);
  59729. CMAC_CTX_free(cmacCtx);
  59730. /* Test AES-256-CBC */
  59731. cmacCtx = NULL;
  59732. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59733. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_256_KEY_SIZE, EVP_aes_256_cbc(),
  59734. NULL), 1);
  59735. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  59736. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59737. CMAC_CTX_free(cmacCtx);
  59738. /* Test AES-192-CBC */
  59739. cmacCtx = NULL;
  59740. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59741. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  59742. NULL), 1);
  59743. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  59744. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59745. CMAC_CTX_free(cmacCtx);
  59746. cmacCtx = NULL;
  59747. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59748. CMAC_CTX_free(cmacCtx);
  59749. #endif /* WOLFSSL_CMAC && OPENSSL_EXTRA && WOLFSSL_AES_DIRECT */
  59750. return EXPECT_RESULT();
  59751. }
  59752. static int test_wolfSSL_DES(void)
  59753. {
  59754. EXPECT_DECLS;
  59755. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  59756. const_DES_cblock myDes;
  59757. DES_cblock iv;
  59758. DES_key_schedule key;
  59759. word32 i = 0;
  59760. DES_LONG dl = 0;
  59761. unsigned char msg[] = "hello wolfssl";
  59762. unsigned char weakKey[][8] = {
  59763. { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
  59764. { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
  59765. { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
  59766. { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }
  59767. };
  59768. unsigned char semiWeakKey[][8] = {
  59769. { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
  59770. { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
  59771. { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
  59772. { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
  59773. { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
  59774. { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
  59775. { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
  59776. { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
  59777. { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
  59778. { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
  59779. { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
  59780. { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
  59781. };
  59782. DES_check_key(1);
  59783. DES_set_key(&myDes, &key);
  59784. /* check, check of odd parity */
  59785. XMEMSET(myDes, 4, sizeof(const_DES_cblock));
  59786. myDes[0] = 6; /* set even parity */
  59787. XMEMSET(key, 5, sizeof(DES_key_schedule));
  59788. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -1);
  59789. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  59790. ExpectIntEQ(DES_set_key_checked(NULL, NULL), -2);
  59791. ExpectIntEQ(DES_set_key_checked(&myDes, NULL), -2);
  59792. ExpectIntEQ(DES_set_key_checked(NULL, &key), -2);
  59793. /* set odd parity for success case */
  59794. DES_set_odd_parity(&myDes);
  59795. ExpectIntEQ(DES_check_key_parity(&myDes), 1);
  59796. fprintf(stderr, "%02x %02x %02x %02x", myDes[0], myDes[1], myDes[2],
  59797. myDes[3]);
  59798. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  59799. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  59800. ExpectIntEQ(key[i], myDes[i]);
  59801. }
  59802. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  59803. /* check weak key */
  59804. XMEMSET(myDes, 1, sizeof(const_DES_cblock));
  59805. XMEMSET(key, 5, sizeof(DES_key_schedule));
  59806. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -2);
  59807. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  59808. DES_set_key_unchecked(NULL, NULL);
  59809. DES_set_key_unchecked(&myDes, NULL);
  59810. DES_set_key_unchecked(NULL, &key);
  59811. /* compare arrays, should be the same */
  59812. /* now do unchecked copy of a weak key over */
  59813. DES_set_key_unchecked(&myDes, &key);
  59814. /* compare arrays, should be the same */
  59815. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  59816. ExpectIntEQ(key[i], myDes[i]);
  59817. }
  59818. ExpectIntEQ(DES_is_weak_key(&myDes), 1);
  59819. myDes[7] = 2;
  59820. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  59821. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  59822. ExpectIntEQ(DES_is_weak_key(NULL), 1);
  59823. /* Test all weak keys. */
  59824. for (i = 0; i < sizeof(weakKey) / sizeof(*weakKey); i++) {
  59825. ExpectIntEQ(DES_set_key_checked(&weakKey[i], &key), -2);
  59826. }
  59827. /* Test all semi-weak keys. */
  59828. for (i = 0; i < sizeof(semiWeakKey) / sizeof(*semiWeakKey); i++) {
  59829. ExpectIntEQ(DES_set_key_checked(&semiWeakKey[i], &key), -2);
  59830. }
  59831. /* check DES_key_sched API */
  59832. XMEMSET(key, 1, sizeof(DES_key_schedule));
  59833. ExpectIntEQ(DES_key_sched(&myDes, NULL), 0);
  59834. ExpectIntEQ(DES_key_sched(NULL, &key), 0);
  59835. ExpectIntEQ(DES_key_sched(&myDes, &key), 0);
  59836. /* compare arrays, should be the same */
  59837. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  59838. ExpectIntEQ(key[i], myDes[i]);
  59839. }
  59840. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, NULL)), 0);
  59841. ExpectIntEQ((DES_cbc_cksum(msg, NULL, 0, NULL, NULL)), 0);
  59842. ExpectIntEQ((DES_cbc_cksum(NULL, &key, 0, NULL, NULL)), 0);
  59843. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, &myDes, NULL)), 0);
  59844. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, &iv)), 0);
  59845. ExpectIntEQ((DES_cbc_cksum(NULL, &key, sizeof(msg), &myDes, &iv)), 0);
  59846. ExpectIntEQ((DES_cbc_cksum(msg, NULL, sizeof(msg), &myDes, &iv)), 0);
  59847. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), NULL, &iv)), 0);
  59848. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, NULL)), 0);
  59849. /* DES_cbc_cksum should return the last 4 of the last 8 bytes after
  59850. * DES_cbc_encrypt on the input */
  59851. XMEMSET(iv, 0, sizeof(DES_cblock));
  59852. XMEMSET(myDes, 5, sizeof(DES_key_schedule));
  59853. ExpectIntGT((dl = DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, &iv)), 0);
  59854. ExpectIntEQ(dl, 480052723);
  59855. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_DES3) */
  59856. return EXPECT_RESULT();
  59857. }
  59858. static int test_wolfSSL_DES_ncbc(void)
  59859. {
  59860. EXPECT_DECLS;
  59861. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  59862. const_DES_cblock myDes;
  59863. DES_cblock iv = {1};
  59864. DES_key_schedule key = {0};
  59865. unsigned char msg[] = "hello wolfssl";
  59866. unsigned char out[DES_BLOCK_SIZE * 2] = {0};
  59867. unsigned char pln[DES_BLOCK_SIZE * 2] = {0};
  59868. unsigned char exp[] = {0x31, 0x98, 0x2F, 0x3A, 0x55, 0xBF, 0xD8, 0xC4};
  59869. unsigned char exp2[] = {0xC7, 0x45, 0x8B, 0x28, 0x10, 0x53, 0xE0, 0x58};
  59870. /* partial block test */
  59871. DES_set_key(&key, &myDes);
  59872. DES_ncbc_encrypt(msg, out, 3, &myDes, &iv, DES_ENCRYPT);
  59873. ExpectIntEQ(XMEMCMP(exp, out, DES_BLOCK_SIZE), 0);
  59874. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  59875. DES_set_key(&key, &myDes);
  59876. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  59877. *((byte*)&iv) = 1;
  59878. DES_ncbc_encrypt(out, pln, 3, &myDes, &iv, DES_DECRYPT);
  59879. ExpectIntEQ(XMEMCMP(msg, pln, 3), 0);
  59880. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  59881. /* full block test */
  59882. DES_set_key(&key, &myDes);
  59883. XMEMSET(pln, 0, DES_BLOCK_SIZE);
  59884. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  59885. *((byte*)&iv) = 1;
  59886. DES_ncbc_encrypt(msg, out, 8, &myDes, &iv, DES_ENCRYPT);
  59887. ExpectIntEQ(XMEMCMP(exp2, out, DES_BLOCK_SIZE), 0);
  59888. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  59889. DES_set_key(&key, &myDes);
  59890. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  59891. *((byte*)&iv) = 1;
  59892. DES_ncbc_encrypt(out, pln, 8, &myDes, &iv, DES_DECRYPT);
  59893. ExpectIntEQ(XMEMCMP(msg, pln, 8), 0);
  59894. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  59895. #endif
  59896. return EXPECT_RESULT();
  59897. }
  59898. static int test_wolfSSL_DES_ecb_encrypt(void)
  59899. {
  59900. EXPECT_DECLS;
  59901. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  59902. WOLFSSL_DES_cblock input1, input2, output1, output2, back1, back2;
  59903. WOLFSSL_DES_key_schedule key;
  59904. XMEMCPY(key, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  59905. XMEMCPY(input1, "Iamhuman", sizeof(WOLFSSL_DES_cblock));
  59906. XMEMCPY(input2, "Whoisit?", sizeof(WOLFSSL_DES_cblock));
  59907. XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
  59908. XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
  59909. XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
  59910. XMEMSET(back2, 0, sizeof(WOLFSSL_DES_cblock));
  59911. wolfSSL_DES_ecb_encrypt(NULL, NULL, NULL, DES_ENCRYPT);
  59912. wolfSSL_DES_ecb_encrypt(&input1, NULL, NULL, DES_ENCRYPT);
  59913. wolfSSL_DES_ecb_encrypt(NULL, &output1, NULL, DES_ENCRYPT);
  59914. wolfSSL_DES_ecb_encrypt(NULL, NULL, &key, DES_ENCRYPT);
  59915. wolfSSL_DES_ecb_encrypt(&input1, &output1, NULL, DES_ENCRYPT);
  59916. wolfSSL_DES_ecb_encrypt(&input1, NULL, &key, DES_ENCRYPT);
  59917. wolfSSL_DES_ecb_encrypt(NULL, &output1, &key, DES_ENCRYPT);
  59918. /* Encrypt messages */
  59919. wolfSSL_DES_ecb_encrypt(&input1, &output1, &key, DES_ENCRYPT);
  59920. wolfSSL_DES_ecb_encrypt(&input2, &output2, &key, DES_ENCRYPT);
  59921. {
  59922. /* Decrypt messages */
  59923. int ret1 = 0;
  59924. int ret2 = 0;
  59925. wolfSSL_DES_ecb_encrypt(&output1, &back1, &key, DES_DECRYPT);
  59926. ExpectIntEQ(ret1 = XMEMCMP((unsigned char *)back1,
  59927. (unsigned char *)input1, sizeof(WOLFSSL_DES_cblock)), 0);
  59928. wolfSSL_DES_ecb_encrypt(&output2, &back2, &key, DES_DECRYPT);
  59929. ExpectIntEQ(ret2 = XMEMCMP((unsigned char *)back2,
  59930. (unsigned char *)input2, sizeof(WOLFSSL_DES_cblock)), 0);
  59931. }
  59932. #endif
  59933. return EXPECT_RESULT();
  59934. }
  59935. static int test_wolfSSL_DES_ede3_cbc_encrypt(void)
  59936. {
  59937. EXPECT_DECLS;
  59938. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  59939. unsigned char input1[8], input2[8];
  59940. unsigned char output1[8], output2[8];
  59941. unsigned char back1[8], back2[8];
  59942. WOLFSSL_DES_cblock iv1, iv2;
  59943. WOLFSSL_DES_key_schedule key1, key2, key3;
  59944. int i;
  59945. XMEMCPY(key1, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  59946. XMEMCPY(key2, "23456781", sizeof(WOLFSSL_DES_key_schedule));
  59947. XMEMCPY(key3, "34567823", sizeof(WOLFSSL_DES_key_schedule));
  59948. XMEMCPY(input1, "Iamhuman", sizeof(input1));
  59949. XMEMCPY(input2, "Whoisit?", sizeof(input2));
  59950. XMEMSET(output1, 0, sizeof(output1));
  59951. XMEMSET(output2, 0, sizeof(output2));
  59952. XMEMSET(back1, 0, sizeof(back1));
  59953. XMEMSET(back2, 0, sizeof(back2));
  59954. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  59955. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  59956. /* Encrypt messages */
  59957. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, 8, &key1, &key2, &key3, &iv1,
  59958. DES_ENCRYPT);
  59959. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, 8, &key1, &key2, &key3, &iv2,
  59960. DES_ENCRYPT);
  59961. {
  59962. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  59963. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  59964. /* Decrypt messages */
  59965. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, 8, &key1, &key2, &key3,
  59966. &iv1, DES_DECRYPT);
  59967. ExpectIntEQ(XMEMCMP(back1, input1, sizeof(input1)), 0);
  59968. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, 8, &key1, &key2, &key3,
  59969. &iv2, DES_DECRYPT);
  59970. ExpectIntEQ(XMEMCMP(back2, input2, sizeof(input2)), 0);
  59971. }
  59972. for (i = 0; i < 8; i++) {
  59973. XMEMSET(output1, 0, sizeof(output1));
  59974. XMEMSET(output2, 0, sizeof(output2));
  59975. XMEMSET(back1, 0, sizeof(back1));
  59976. XMEMSET(back2, 0, sizeof(back2));
  59977. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  59978. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  59979. /* Encrypt partial messages */
  59980. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, i, &key1, &key2, &key3,
  59981. &iv1, DES_ENCRYPT);
  59982. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, i, &key1, &key2, &key3,
  59983. &iv2, DES_ENCRYPT);
  59984. {
  59985. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  59986. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  59987. /* Decrypt messages */
  59988. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, i, &key1, &key2,
  59989. &key3, &iv1, DES_DECRYPT);
  59990. ExpectIntEQ(XMEMCMP(back1, input1, i), 0);
  59991. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, i, &key1, &key2,
  59992. &key3, &iv2, DES_DECRYPT);
  59993. ExpectIntEQ(XMEMCMP(back2, input2, i), 0);
  59994. }
  59995. }
  59996. #endif
  59997. return EXPECT_RESULT();
  59998. }
  59999. static int test_wolfSSL_AES_encrypt(void)
  60000. {
  60001. EXPECT_DECLS;
  60002. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60003. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60004. AES_KEY enc;
  60005. AES_KEY dec;
  60006. const byte msg[] = {
  60007. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60008. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60009. };
  60010. const byte exp[] = {
  60011. 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
  60012. 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
  60013. };
  60014. const byte key[] = {
  60015. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60016. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60017. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60018. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60019. };
  60020. byte eout[sizeof(msg)];
  60021. byte dout[sizeof(msg)];
  60022. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &enc), 0);
  60023. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &dec), 0);
  60024. wolfSSL_AES_encrypt(NULL, NULL, NULL);
  60025. wolfSSL_AES_encrypt(msg, NULL, NULL);
  60026. wolfSSL_AES_encrypt(NULL, eout, NULL);
  60027. wolfSSL_AES_encrypt(NULL, NULL, &enc);
  60028. wolfSSL_AES_encrypt(msg, eout, NULL);
  60029. wolfSSL_AES_encrypt(msg, NULL, &enc);
  60030. wolfSSL_AES_encrypt(NULL, eout, &enc);
  60031. wolfSSL_AES_decrypt(NULL, NULL, NULL);
  60032. wolfSSL_AES_decrypt(eout, NULL, NULL);
  60033. wolfSSL_AES_decrypt(NULL, dout, NULL);
  60034. wolfSSL_AES_decrypt(NULL, NULL, &dec);
  60035. wolfSSL_AES_decrypt(eout, dout, NULL);
  60036. wolfSSL_AES_decrypt(eout, NULL, &dec);
  60037. wolfSSL_AES_decrypt(NULL, dout, &dec);
  60038. wolfSSL_AES_encrypt(msg, eout, &enc);
  60039. ExpectIntEQ(XMEMCMP(eout, exp, AES_BLOCK_SIZE), 0);
  60040. wolfSSL_AES_decrypt(eout, dout, &dec);
  60041. ExpectIntEQ(XMEMCMP(dout, msg, AES_BLOCK_SIZE), 0);
  60042. #endif
  60043. return EXPECT_RESULT();
  60044. }
  60045. static int test_wolfSSL_AES_ecb_encrypt(void)
  60046. {
  60047. EXPECT_DECLS;
  60048. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60049. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60050. AES_KEY aes;
  60051. const byte msg[] =
  60052. {
  60053. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60054. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  60055. };
  60056. const byte verify[] =
  60057. {
  60058. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  60059. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  60060. };
  60061. const byte key[] =
  60062. {
  60063. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60064. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60065. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60066. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  60067. };
  60068. byte out[AES_BLOCK_SIZE];
  60069. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aes), 0);
  60070. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60071. AES_ecb_encrypt(msg, out, &aes, AES_ENCRYPT);
  60072. ExpectIntEQ(XMEMCMP(out, verify, AES_BLOCK_SIZE), 0);
  60073. #ifdef HAVE_AES_DECRYPT
  60074. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &aes), 0);
  60075. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60076. AES_ecb_encrypt(verify, out, &aes, AES_DECRYPT);
  60077. ExpectIntEQ(XMEMCMP(out, msg, AES_BLOCK_SIZE), 0);
  60078. #endif
  60079. /* test bad arguments */
  60080. AES_ecb_encrypt(NULL, out, &aes, AES_DECRYPT);
  60081. AES_ecb_encrypt(verify, NULL, &aes, AES_DECRYPT);
  60082. AES_ecb_encrypt(verify, out, NULL, AES_DECRYPT);
  60083. #endif
  60084. return EXPECT_RESULT();
  60085. }
  60086. static int test_wolfSSL_AES_cbc_encrypt(void)
  60087. {
  60088. EXPECT_DECLS;
  60089. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60090. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60091. AES_KEY aes;
  60092. AES_KEY* aesN = NULL;
  60093. size_t len = 0;
  60094. size_t lenB = 0;
  60095. int keySz0 = 0;
  60096. int keySzN = -1;
  60097. byte out[AES_BLOCK_SIZE] = {0};
  60098. byte* outN = NULL;
  60099. /* Test vectors retrieved from:
  60100. * <begin URL>
  60101. * https://csrc.nist.gov/
  60102. * CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/
  60103. * documents/aes/KAT_AES.zip
  60104. * </end URL>
  60105. */
  60106. const byte* pt128N = NULL;
  60107. byte* key128N = NULL;
  60108. byte* iv128N = NULL;
  60109. byte iv128tmp[AES_BLOCK_SIZE] = {0};
  60110. const byte pt128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60111. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60112. const byte ct128[] = { 0x87,0x85,0xb1,0xa7,0x5b,0x0f,0x3b,0xd9,
  60113. 0x58,0xdc,0xd0,0xe2,0x93,0x18,0xc5,0x21 };
  60114. const byte iv128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60115. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60116. byte key128[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  60117. 0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00 };
  60118. len = sizeof(pt128);
  60119. #define STRESS_T(a, b, c, d, e, f, g, h, i) \
  60120. wolfSSL_AES_cbc_encrypt(a, b, c, d, e, f); \
  60121. ExpectIntNE(XMEMCMP(b, g, h), i)
  60122. #define RESET_IV(x, y) XMEMCPY(x, y, AES_BLOCK_SIZE)
  60123. /* Stressing wolfSSL_AES_cbc_encrypt() */
  60124. STRESS_T(pt128N, out, len, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60125. STRESS_T(pt128, out, len, &aes, iv128N, 1, ct128, AES_BLOCK_SIZE, 0);
  60126. wolfSSL_AES_cbc_encrypt(pt128, outN, len, &aes, iv128tmp, AES_ENCRYPT);
  60127. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60128. wolfSSL_AES_cbc_encrypt(pt128, out, len, aesN, iv128tmp, AES_ENCRYPT);
  60129. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60130. STRESS_T(pt128, out, lenB, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60131. /* Stressing wolfSSL_AES_set_encrypt_key */
  60132. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60133. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, aesN),0);
  60134. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySz0, &aes), 0);
  60135. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySzN, &aes), 0);
  60136. /* Stressing wolfSSL_AES_set_decrypt_key */
  60137. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60138. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, aesN),0);
  60139. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySz0, &aes), 0);
  60140. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySzN, &aes), 0);
  60141. #ifdef WOLFSSL_AES_128
  60142. /* wolfSSL_AES_cbc_encrypt() 128-bit */
  60143. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60144. RESET_IV(iv128tmp, iv128);
  60145. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60146. wolfSSL_AES_cbc_encrypt(pt128, out, len, &aes, iv128tmp, AES_ENCRYPT);
  60147. ExpectIntEQ(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60148. wc_AesFree((Aes*)&aes);
  60149. #ifdef HAVE_AES_DECRYPT
  60150. /* wolfSSL_AES_cbc_encrypt() 128-bit in decrypt mode */
  60151. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60152. RESET_IV(iv128tmp, iv128);
  60153. len = sizeof(ct128);
  60154. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60155. wolfSSL_AES_cbc_encrypt(ct128, out, len, &aes, iv128tmp, AES_DECRYPT);
  60156. ExpectIntEQ(XMEMCMP(out, pt128, AES_BLOCK_SIZE), 0);
  60157. wc_AesFree((Aes*)&aes);
  60158. #endif
  60159. #endif /* WOLFSSL_AES_128 */
  60160. #ifdef WOLFSSL_AES_192
  60161. {
  60162. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  60163. * Appendix F.2.3 */
  60164. byte iv192tmp[AES_BLOCK_SIZE] = {0};
  60165. const byte pt192[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60166. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60167. const byte ct192[] = { 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  60168. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8 };
  60169. const byte iv192[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60170. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60171. byte key192[] = { 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  60172. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  60173. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b };
  60174. len = sizeof(pt192);
  60175. /* wolfSSL_AES_cbc_encrypt() 192-bit */
  60176. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60177. RESET_IV(iv192tmp, iv192);
  60178. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60179. wolfSSL_AES_cbc_encrypt(pt192, out, len, &aes, iv192tmp, AES_ENCRYPT);
  60180. ExpectIntEQ(XMEMCMP(out, ct192, AES_BLOCK_SIZE), 0);
  60181. wc_AesFree((Aes*)&aes);
  60182. #ifdef HAVE_AES_DECRYPT
  60183. /* wolfSSL_AES_cbc_encrypt() 192-bit in decrypt mode */
  60184. len = sizeof(ct192);
  60185. RESET_IV(iv192tmp, iv192);
  60186. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60187. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60188. wolfSSL_AES_cbc_encrypt(ct192, out, len, &aes, iv192tmp, AES_DECRYPT);
  60189. ExpectIntEQ(XMEMCMP(out, pt192, AES_BLOCK_SIZE), 0);
  60190. wc_AesFree((Aes*)&aes);
  60191. #endif
  60192. }
  60193. #endif /* WOLFSSL_AES_192 */
  60194. #ifdef WOLFSSL_AES_256
  60195. {
  60196. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  60197. * Appendix F.2.5 */
  60198. byte iv256tmp[AES_BLOCK_SIZE] = {0};
  60199. const byte pt256[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60200. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60201. const byte ct256[] = { 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  60202. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6 };
  60203. const byte iv256[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60204. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60205. byte key256[] = { 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60206. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60207. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60208. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 };
  60209. len = sizeof(pt256);
  60210. /* wolfSSL_AES_cbc_encrypt() 256-bit */
  60211. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60212. RESET_IV(iv256tmp, iv256);
  60213. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60214. wolfSSL_AES_cbc_encrypt(pt256, out, len, &aes, iv256tmp, AES_ENCRYPT);
  60215. ExpectIntEQ(XMEMCMP(out, ct256, AES_BLOCK_SIZE), 0);
  60216. wc_AesFree((Aes*)&aes);
  60217. #ifdef HAVE_AES_DECRYPT
  60218. /* wolfSSL_AES_cbc_encrypt() 256-bit in decrypt mode */
  60219. len = sizeof(ct256);
  60220. RESET_IV(iv256tmp, iv256);
  60221. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60222. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60223. wolfSSL_AES_cbc_encrypt(ct256, out, len, &aes, iv256tmp, AES_DECRYPT);
  60224. ExpectIntEQ(XMEMCMP(out, pt256, AES_BLOCK_SIZE), 0);
  60225. wc_AesFree((Aes*)&aes);
  60226. #endif
  60227. #if defined(HAVE_AES_KEYWRAP) && !defined(HAVE_FIPS) && \
  60228. !defined(HAVE_SELFTEST)
  60229. {
  60230. byte wrapCipher[sizeof(key256) + KEYWRAP_BLOCK_SIZE] = { 0 };
  60231. byte wrapPlain[sizeof(key256)] = { 0 };
  60232. byte wrapIV[KEYWRAP_BLOCK_SIZE] = { 0 };
  60233. /* wolfSSL_AES_wrap_key() 256-bit NULL iv */
  60234. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60235. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60236. 15), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60237. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60238. sizeof(key256)), sizeof(wrapCipher));
  60239. wc_AesFree((Aes*)&aes);
  60240. /* wolfSSL_AES_unwrap_key() 256-bit NULL iv */
  60241. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60242. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60243. 23), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60244. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60245. sizeof(wrapCipher)), sizeof(wrapPlain));
  60246. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60247. XMEMSET(wrapCipher, 0, sizeof(wrapCipher));
  60248. XMEMSET(wrapPlain, 0, sizeof(wrapPlain));
  60249. wc_AesFree((Aes*)&aes);
  60250. /* wolfSSL_AES_wrap_key() 256-bit custom iv */
  60251. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60252. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, key256,
  60253. sizeof(key256)), sizeof(wrapCipher));
  60254. wc_AesFree((Aes*)&aes);
  60255. /* wolfSSL_AES_unwrap_key() 256-bit custom iv */
  60256. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60257. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, wrapPlain, wrapCipher,
  60258. sizeof(wrapCipher)), sizeof(wrapPlain));
  60259. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60260. wc_AesFree((Aes*)&aes);
  60261. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60262. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60263. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60264. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, wrapCipher, NULL, 0), 0);
  60265. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, key256, 0), 0);
  60266. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, wrapCipher, key256, 0), 0);
  60267. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256, 0), 0);
  60268. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, NULL, key256, 0), 0);
  60269. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, NULL, 0), 0);
  60270. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60271. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60272. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60273. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, wrapPlain, NULL, 0), 0);
  60274. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, wrapCipher, 0), 0);
  60275. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, wrapPlain, wrapCipher, 0),
  60276. 0);
  60277. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher, 0),
  60278. 0);
  60279. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, NULL, wrapCipher, 0), 0);
  60280. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapPlain, NULL, 0), 0);
  60281. }
  60282. #endif /* HAVE_AES_KEYWRAP */
  60283. }
  60284. #endif /* WOLFSSL_AES_256 */
  60285. #endif
  60286. return EXPECT_RESULT();
  60287. }
  60288. static int test_wolfSSL_AES_cfb128_encrypt(void)
  60289. {
  60290. EXPECT_DECLS;
  60291. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB) && \
  60292. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60293. AES_KEY aesEnc;
  60294. AES_KEY aesDec;
  60295. const byte msg[] = {
  60296. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60297. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60298. };
  60299. const byte exp[] = {
  60300. 0x16, 0xc9, 0x90, 0x6c, 0x04, 0x0c, 0xd1, 0x2f,
  60301. 0x84, 0x7b, 0x18, 0xed, 0xed, 0x6a, 0xb5, 0xfd
  60302. };
  60303. const byte key[] = {
  60304. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60305. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60306. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60307. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60308. };
  60309. const byte ivData[] = {
  60310. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60311. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60312. };
  60313. byte out[AES_BLOCK_SIZE];
  60314. byte iv[AES_BLOCK_SIZE];
  60315. word32 i;
  60316. int num;
  60317. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60318. XMEMCPY(iv, ivData, sizeof(iv));
  60319. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60320. AES_cfb128_encrypt(msg, out, sizeof(msg), &aesEnc, iv, NULL, AES_ENCRYPT);
  60321. ExpectIntEQ(XMEMCMP(out, exp, sizeof(msg)), 0);
  60322. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60323. #ifdef HAVE_AES_DECRYPT
  60324. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60325. XMEMCPY(iv, ivData, sizeof(iv));
  60326. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60327. AES_cfb128_encrypt(exp, out, sizeof(msg), &aesDec, iv, NULL, AES_DECRYPT);
  60328. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  60329. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60330. #endif
  60331. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(msg)); i++) {
  60332. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60333. XMEMCPY(iv, ivData, sizeof(iv));
  60334. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60335. AES_cfb128_encrypt(msg, out, i, &aesEnc, iv, &num, AES_ENCRYPT);
  60336. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60337. ExpectIntEQ(XMEMCMP(out, exp, i), 0);
  60338. if (i == 0) {
  60339. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60340. }
  60341. else {
  60342. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60343. }
  60344. #ifdef HAVE_AES_DECRYPT
  60345. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60346. XMEMCPY(iv, ivData, sizeof(iv));
  60347. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60348. AES_cfb128_encrypt(exp, out, i, &aesDec, iv, &num, AES_DECRYPT);
  60349. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60350. ExpectIntEQ(XMEMCMP(out, msg, i), 0);
  60351. if (i == 0) {
  60352. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60353. }
  60354. else {
  60355. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60356. }
  60357. #endif
  60358. }
  60359. if (EXPECT_SUCCESS()) {
  60360. /* test bad arguments */
  60361. AES_cfb128_encrypt(NULL, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60362. AES_cfb128_encrypt(msg, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60363. AES_cfb128_encrypt(NULL, out, 0, NULL, NULL, NULL, AES_DECRYPT);
  60364. AES_cfb128_encrypt(NULL, NULL, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60365. AES_cfb128_encrypt(NULL, NULL, 0, NULL, iv, NULL, AES_DECRYPT);
  60366. AES_cfb128_encrypt(NULL, out, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60367. AES_cfb128_encrypt(msg, NULL, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60368. AES_cfb128_encrypt(msg, out, 0, NULL, iv, NULL, AES_DECRYPT);
  60369. AES_cfb128_encrypt(msg, out, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60370. }
  60371. #endif
  60372. return EXPECT_RESULT();
  60373. }
  60374. static int test_wolfSSL_CRYPTO_cts128(void)
  60375. {
  60376. EXPECT_DECLS;
  60377. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60378. defined(HAVE_CTS) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60379. byte tmp[64]; /* Largest vector size */
  60380. /* Test vectors taken form RFC3962 Appendix B */
  60381. const testVector vects[] = {
  60382. {
  60383. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60384. "\x20",
  60385. "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"
  60386. "\x97",
  60387. 17, 17
  60388. },
  60389. {
  60390. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60391. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20",
  60392. "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
  60393. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5",
  60394. 31, 31
  60395. },
  60396. {
  60397. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60398. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43",
  60399. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60400. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
  60401. 32, 32
  60402. },
  60403. {
  60404. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60405. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60406. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c",
  60407. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60408. "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
  60409. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5",
  60410. 47, 47
  60411. },
  60412. {
  60413. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60414. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60415. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20",
  60416. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60417. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
  60418. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
  60419. 48, 48
  60420. },
  60421. {
  60422. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60423. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60424. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
  60425. "\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e",
  60426. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60427. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60428. "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
  60429. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
  60430. 64, 64
  60431. }
  60432. };
  60433. byte keyBytes[AES_128_KEY_SIZE] = {
  60434. 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
  60435. 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
  60436. };
  60437. size_t i;
  60438. AES_KEY encKey;
  60439. byte iv[AES_IV_SIZE]; /* All-zero IV for all cases */
  60440. XMEMSET(tmp, 0, sizeof(tmp));
  60441. for (i = 0; i < sizeof(vects)/sizeof(vects[0]); i++) {
  60442. AES_KEY decKey;
  60443. ExpectIntEQ(AES_set_encrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60444. &encKey), 0);
  60445. ExpectIntEQ(AES_set_decrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60446. &decKey), 0);
  60447. XMEMSET(iv, 0, sizeof(iv));
  60448. ExpectIntEQ(CRYPTO_cts128_encrypt((const unsigned char*)vects[i].input,
  60449. tmp, vects[i].inLen, &encKey, iv, (cbc128_f)AES_cbc_encrypt),
  60450. vects[i].outLen);
  60451. ExpectIntEQ(XMEMCMP(tmp, vects[i].output, vects[i].outLen), 0);
  60452. XMEMSET(iv, 0, sizeof(iv));
  60453. ExpectIntEQ(CRYPTO_cts128_decrypt((const unsigned char*)vects[i].output,
  60454. tmp, vects[i].outLen, &decKey, iv, (cbc128_f)AES_cbc_encrypt),
  60455. vects[i].inLen);
  60456. ExpectIntEQ(XMEMCMP(tmp, vects[i].input, vects[i].inLen), 0);
  60457. }
  60458. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60459. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60460. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60461. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60462. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60463. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL,
  60464. (cbc128_f)AES_cbc_encrypt), 0);
  60465. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, &encKey, iv,
  60466. (cbc128_f)AES_cbc_encrypt), 0);
  60467. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, &encKey, iv,
  60468. (cbc128_f)AES_cbc_encrypt), 0);
  60469. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, NULL, iv,
  60470. (cbc128_f)AES_cbc_encrypt), 0);
  60471. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, NULL,
  60472. (cbc128_f)AES_cbc_encrypt), 0);
  60473. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60474. /* Length too small. */
  60475. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 0, &encKey, iv,
  60476. (cbc128_f)AES_cbc_encrypt), 0);
  60477. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60478. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60479. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60480. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60481. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60482. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL,
  60483. (cbc128_f)AES_cbc_encrypt), 0);
  60484. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, &encKey, iv,
  60485. (cbc128_f)AES_cbc_encrypt), 0);
  60486. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, &encKey, iv,
  60487. (cbc128_f)AES_cbc_encrypt), 0);
  60488. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, NULL, iv,
  60489. (cbc128_f)AES_cbc_encrypt), 0);
  60490. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, NULL,
  60491. (cbc128_f)AES_cbc_encrypt), 0);
  60492. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60493. /* Length too small. */
  60494. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 0, &encKey, iv,
  60495. (cbc128_f)AES_cbc_encrypt), 0);
  60496. #endif /* !NO_AES && HAVE_AES_CBC && OPENSSL_EXTRA && HAVE_CTS */
  60497. return EXPECT_RESULT();
  60498. }
  60499. static int test_wolfSSL_RC4(void)
  60500. {
  60501. EXPECT_DECLS;
  60502. #if !defined(NO_RC4) && defined(OPENSSL_EXTRA)
  60503. WOLFSSL_RC4_KEY rc4Key;
  60504. unsigned char key[] = {
  60505. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60506. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60507. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60508. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60509. };
  60510. unsigned char data[] = {
  60511. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60512. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60513. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60514. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60515. };
  60516. unsigned char enc[sizeof(data)];
  60517. unsigned char dec[sizeof(data)];
  60518. word32 i;
  60519. word32 j;
  60520. wolfSSL_RC4_set_key(NULL, -1, NULL);
  60521. wolfSSL_RC4_set_key(&rc4Key, -1, NULL);
  60522. wolfSSL_RC4_set_key(NULL, 0, NULL);
  60523. wolfSSL_RC4_set_key(NULL, -1, key);
  60524. wolfSSL_RC4_set_key(&rc4Key, 0, NULL);
  60525. wolfSSL_RC4_set_key(&rc4Key, -1, key);
  60526. wolfSSL_RC4_set_key(NULL, 0, key);
  60527. wolfSSL_RC4(NULL, 0, NULL, NULL);
  60528. wolfSSL_RC4(&rc4Key, 0, NULL, NULL);
  60529. wolfSSL_RC4(NULL, 0, data, NULL);
  60530. wolfSSL_RC4(NULL, 0, NULL, enc);
  60531. wolfSSL_RC4(&rc4Key, 0, data, NULL);
  60532. wolfSSL_RC4(&rc4Key, 0, NULL, enc);
  60533. wolfSSL_RC4(NULL, 0, data, enc);
  60534. ExpectIntEQ(1, 1);
  60535. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(key)); i++) {
  60536. for (j = 0; EXPECT_SUCCESS() && (j <= sizeof(data)); j++) {
  60537. XMEMSET(enc, 0, sizeof(enc));
  60538. XMEMSET(dec, 0, sizeof(dec));
  60539. /* Encrypt */
  60540. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  60541. wolfSSL_RC4(&rc4Key, j, data, enc);
  60542. /* Decrypt */
  60543. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  60544. wolfSSL_RC4(&rc4Key, j, enc, dec);
  60545. ExpectIntEQ(XMEMCMP(dec, data, j), 0);
  60546. }
  60547. }
  60548. #endif
  60549. return EXPECT_RESULT();
  60550. }
  60551. static int test_wolfSSL_OBJ(void)
  60552. {
  60553. /* Password "wolfSSL test" is only 12 (96-bit) too short for testing in FIPS
  60554. * mode
  60555. */
  60556. EXPECT_DECLS;
  60557. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_ASN) && \
  60558. !defined(HAVE_FIPS) && !defined(NO_SHA) && defined(WOLFSSL_CERT_EXT) && \
  60559. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && \
  60560. !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  60561. ASN1_OBJECT *obj = NULL;
  60562. ASN1_OBJECT *obj2 = NULL;
  60563. char buf[50];
  60564. XFILE fp = XBADFILE;
  60565. X509 *x509 = NULL;
  60566. X509_NAME *x509Name = NULL;
  60567. X509_NAME_ENTRY *x509NameEntry = NULL;
  60568. ASN1_OBJECT *asn1Name = NULL;
  60569. int numNames = 0;
  60570. BIO *bio = NULL;
  60571. int nid;
  60572. int i, j;
  60573. const char *f[] = {
  60574. #ifndef NO_RSA
  60575. "./certs/ca-cert.der",
  60576. #endif
  60577. #ifdef HAVE_ECC
  60578. "./certs/ca-ecc-cert.der",
  60579. "./certs/ca-ecc384-cert.der",
  60580. #endif
  60581. NULL};
  60582. ASN1_OBJECT *field_name_obj = NULL;
  60583. int lastpos = -1;
  60584. int tmp = -1;
  60585. ASN1_STRING *asn1 = NULL;
  60586. unsigned char *buf_dyn = NULL;
  60587. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60588. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  60589. ExpectIntEQ(OBJ_obj2nid(obj), NID_any_policy);
  60590. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 11);
  60591. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  60592. ASN1_OBJECT_free(obj);
  60593. obj = NULL;
  60594. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  60595. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256);
  60596. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 22);
  60597. #ifdef WOLFSSL_CERT_EXT
  60598. ExpectIntEQ(OBJ_txt2nid(buf), NID_sha256);
  60599. #endif
  60600. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  60601. ExpectNotNull(obj2 = OBJ_dup(obj));
  60602. ExpectIntEQ(OBJ_cmp(obj, obj2), 0);
  60603. ASN1_OBJECT_free(obj);
  60604. obj = NULL;
  60605. ASN1_OBJECT_free(obj2);
  60606. obj2 = NULL;
  60607. for (i = 0; f[i] != NULL; i++)
  60608. {
  60609. ExpectTrue((fp = XFOPEN(f[i], "rb")) != XBADFILE);
  60610. ExpectNotNull(x509 = d2i_X509_fp(fp, NULL));
  60611. if (fp != XBADFILE) {
  60612. XFCLOSE(fp);
  60613. fp = XBADFILE;
  60614. }
  60615. ExpectNotNull(x509Name = X509_get_issuer_name(x509));
  60616. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  60617. /* Get the Common Name by using OBJ_txt2obj */
  60618. ExpectNotNull(field_name_obj = OBJ_txt2obj("CN", 0));
  60619. do
  60620. {
  60621. lastpos = tmp;
  60622. tmp = X509_NAME_get_index_by_OBJ(x509Name, field_name_obj, lastpos);
  60623. } while (tmp > -1);
  60624. ExpectIntNE(lastpos, -1);
  60625. ASN1_OBJECT_free(field_name_obj);
  60626. field_name_obj = NULL;
  60627. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, lastpos));
  60628. ExpectNotNull(asn1 = X509_NAME_ENTRY_get_data(x509NameEntry));
  60629. ExpectIntGE(ASN1_STRING_to_UTF8(&buf_dyn, asn1), 0);
  60630. /*
  60631. * All Common Names should be www.wolfssl.com
  60632. * This makes testing easier as we can test for the expected value.
  60633. */
  60634. ExpectStrEQ((char*)buf_dyn, "www.wolfssl.com");
  60635. OPENSSL_free(buf_dyn);
  60636. buf_dyn = NULL;
  60637. bio = BIO_new(BIO_s_mem());
  60638. ExpectTrue(bio != NULL);
  60639. for (j = 0; j < numNames; j++)
  60640. {
  60641. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  60642. ExpectNotNull(asn1Name = X509_NAME_ENTRY_get_object(x509NameEntry));
  60643. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  60644. }
  60645. BIO_free(bio);
  60646. bio = NULL;
  60647. X509_free(x509);
  60648. x509 = NULL;
  60649. }
  60650. #ifdef HAVE_PKCS12
  60651. {
  60652. PKCS12 *p12 = NULL;
  60653. int boolRet;
  60654. EVP_PKEY *pkey = NULL;
  60655. const char *p12_f[] = {
  60656. #if !defined(NO_DES3) && !defined(NO_RSA)
  60657. "./certs/test-servercert.p12",
  60658. #endif
  60659. NULL};
  60660. for (i = 0; p12_f[i] != NULL; i++)
  60661. {
  60662. ExpectTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE);
  60663. ExpectNotNull(p12 = d2i_PKCS12_fp(fp, NULL));
  60664. if (fp != XBADFILE) {
  60665. XFCLOSE(fp);
  60666. fp = XBADFILE;
  60667. }
  60668. ExpectTrue((boolRet = PKCS12_parse(p12, "wolfSSL test",
  60669. &pkey, &x509, NULL)) > 0);
  60670. wc_PKCS12_free(p12);
  60671. p12 = NULL;
  60672. EVP_PKEY_free(pkey);
  60673. x509Name = X509_get_issuer_name(x509);
  60674. ExpectNotNull(x509Name);
  60675. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  60676. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  60677. for (j = 0; j < numNames; j++)
  60678. {
  60679. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  60680. ExpectNotNull(asn1Name =
  60681. X509_NAME_ENTRY_get_object(x509NameEntry));
  60682. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  60683. }
  60684. BIO_free(bio);
  60685. bio = NULL;
  60686. X509_free(x509);
  60687. x509 = NULL;
  60688. }
  60689. }
  60690. #endif /* HAVE_PKCS12 */
  60691. #endif
  60692. return EXPECT_RESULT();
  60693. }
  60694. static int test_wolfSSL_OBJ_cmp(void)
  60695. {
  60696. EXPECT_DECLS;
  60697. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  60698. ASN1_OBJECT *obj = NULL;
  60699. ASN1_OBJECT *obj2 = NULL;
  60700. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  60701. ExpectNotNull(obj2 = OBJ_nid2obj(NID_sha256));
  60702. ExpectIntEQ(OBJ_cmp(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60703. ExpectIntEQ(OBJ_cmp(obj, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60704. ExpectIntEQ(OBJ_cmp(NULL, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60705. ExpectIntEQ(OBJ_cmp(obj, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60706. ExpectIntEQ(OBJ_cmp(obj, obj), 0);
  60707. ExpectIntEQ(OBJ_cmp(obj2, obj2), 0);
  60708. ASN1_OBJECT_free(obj);
  60709. ASN1_OBJECT_free(obj2);
  60710. #endif
  60711. return EXPECT_RESULT();
  60712. }
  60713. static int test_wolfSSL_OBJ_txt2nid(void)
  60714. {
  60715. EXPECT_DECLS;
  60716. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  60717. defined(WOLFSSL_APACHE_HTTPD)
  60718. int i;
  60719. static const struct {
  60720. const char* sn;
  60721. const char* ln;
  60722. const char* oid;
  60723. int nid;
  60724. } testVals[] = {
  60725. #ifdef WOLFSSL_APACHE_HTTPD
  60726. { "tlsfeature", "TLS Feature", "1.3.6.1.5.5.7.1.24", NID_tlsfeature },
  60727. { "id-on-dnsSRV", "SRVName", "1.3.6.1.5.5.7.8.7",
  60728. NID_id_on_dnsSRV },
  60729. { "msUPN", "Microsoft User Principal Name",
  60730. "1.3.6.1.4.1.311.20.2.3", NID_ms_upn },
  60731. #endif
  60732. { NULL, NULL, NULL, NID_undef }
  60733. };
  60734. /* Invalid cases */
  60735. ExpectIntEQ(OBJ_txt2nid(NULL), NID_undef);
  60736. ExpectIntEQ(OBJ_txt2nid("Bad name"), NID_undef);
  60737. /* Valid cases */
  60738. for (i = 0; testVals[i].sn != NULL; i++) {
  60739. ExpectIntEQ(OBJ_txt2nid(testVals[i].sn), testVals[i].nid);
  60740. ExpectIntEQ(OBJ_txt2nid(testVals[i].ln), testVals[i].nid);
  60741. ExpectIntEQ(OBJ_txt2nid(testVals[i].oid), testVals[i].nid);
  60742. }
  60743. #endif
  60744. return EXPECT_RESULT();
  60745. }
  60746. static int test_wolfSSL_OBJ_txt2obj(void)
  60747. {
  60748. EXPECT_DECLS;
  60749. #if defined(WOLFSSL_APACHE_HTTPD) || (defined(OPENSSL_EXTRA) && \
  60750. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN))
  60751. int i;
  60752. char buf[50];
  60753. ASN1_OBJECT* obj = NULL;
  60754. static const struct {
  60755. const char* oidStr;
  60756. const char* sn;
  60757. const char* ln;
  60758. } objs_list[] = {
  60759. #if defined(WOLFSSL_APACHE_HTTPD)
  60760. { "1.3.6.1.5.5.7.1.24", "tlsfeature", "TLS Feature" },
  60761. { "1.3.6.1.5.5.7.8.7", "id-on-dnsSRV", "SRVName" },
  60762. #endif
  60763. { "2.5.29.19", "basicConstraints", "X509v3 Basic Constraints"},
  60764. { NULL, NULL, NULL }
  60765. };
  60766. static const struct {
  60767. const char* numeric;
  60768. const char* name;
  60769. } objs_named[] = {
  60770. /* In dictionary but not in normal list. */
  60771. { "1.3.6.1.5.5.7.3.8", "Time Stamping" },
  60772. /* Made up OID. */
  60773. { "1.3.5.7", "1.3.5.7" },
  60774. { NULL, NULL }
  60775. };
  60776. ExpectNull(obj = OBJ_txt2obj("Bad name", 0));
  60777. ASN1_OBJECT_free(obj);
  60778. obj = NULL;
  60779. ExpectNull(obj = OBJ_txt2obj(NULL, 0));
  60780. ASN1_OBJECT_free(obj);
  60781. obj = NULL;
  60782. for (i = 0; objs_list[i].oidStr != NULL; i++) {
  60783. /* Test numerical value of oid (oidStr) */
  60784. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].oidStr, 1));
  60785. /* Convert object back to text to confirm oid is correct */
  60786. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  60787. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  60788. ASN1_OBJECT_free(obj);
  60789. obj = NULL;
  60790. XMEMSET(buf, 0, sizeof(buf));
  60791. /* Test short name (sn) */
  60792. ExpectNull(obj = OBJ_txt2obj(objs_list[i].sn, 1));
  60793. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].sn, 0));
  60794. /* Convert object back to text to confirm oid is correct */
  60795. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  60796. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  60797. ASN1_OBJECT_free(obj);
  60798. obj = NULL;
  60799. XMEMSET(buf, 0, sizeof(buf));
  60800. /* Test long name (ln) - should fail when no_name = 1 */
  60801. ExpectNull(obj = OBJ_txt2obj(objs_list[i].ln, 1));
  60802. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].ln, 0));
  60803. /* Convert object back to text to confirm oid is correct */
  60804. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  60805. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  60806. ASN1_OBJECT_free(obj);
  60807. obj = NULL;
  60808. XMEMSET(buf, 0, sizeof(buf));
  60809. }
  60810. for (i = 0; objs_named[i].numeric != NULL; i++) {
  60811. ExpectNotNull(obj = OBJ_txt2obj(objs_named[i].numeric, 1));
  60812. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0);
  60813. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].name, (int)XSTRLEN(buf)), 0);
  60814. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  60815. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].numeric, (int)XSTRLEN(buf)), 0);
  60816. ASN1_OBJECT_free(obj);
  60817. obj = NULL;
  60818. }
  60819. #endif
  60820. return EXPECT_RESULT();
  60821. }
  60822. static int test_wolfSSL_PEM_write_bio_X509(void)
  60823. {
  60824. EXPECT_DECLS;
  60825. #if defined(OPENSSL_EXTRA) && defined(OPENSSL_ALL) && \
  60826. defined(WOLFSSL_AKID_NAME) && defined(WOLFSSL_CERT_EXT) && \
  60827. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && !defined(NO_RSA) && \
  60828. !defined(NO_FILESYSTEM)
  60829. /* This test contains the hard coded expected
  60830. * lengths. Update if necessary */
  60831. XFILE fp = XBADFILE;
  60832. WOLFSSL_EVP_PKEY *priv = NULL;
  60833. BIO* input = NULL;
  60834. BIO* output = NULL;
  60835. X509* x509a = NULL;
  60836. X509* x509b = NULL;
  60837. ASN1_TIME* notBeforeA = NULL;
  60838. ASN1_TIME* notAfterA = NULL;
  60839. #ifndef NO_ASN_TIME
  60840. ASN1_TIME* notBeforeB = NULL;
  60841. ASN1_TIME* notAfterB = NULL;
  60842. #endif
  60843. int expectedLen;
  60844. ExpectTrue((fp = XFOPEN("certs/server-key.pem", "rb")) != XBADFILE);
  60845. ExpectNotNull(priv = wolfSSL_PEM_read_PrivateKey(fp, NULL, NULL, NULL));
  60846. if (fp != XBADFILE) {
  60847. XFCLOSE(fp);
  60848. fp = XBADFILE;
  60849. }
  60850. ExpectNotNull(input = BIO_new_file("certs/test/cert-ext-multiple.pem",
  60851. "rb"));
  60852. ExpectIntEQ(wolfSSL_BIO_get_len(input), 2000);
  60853. /* read PEM into X509 struct, get notBefore / notAfter to verify against */
  60854. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  60855. ExpectNotNull(notBeforeA = X509_get_notBefore(x509a));
  60856. ExpectNotNull(notAfterA = X509_get_notAfter(x509a));
  60857. /* write X509 back to PEM BIO; no need to sign as nothing changed. */
  60858. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  60859. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  60860. /* compare length against expected */
  60861. expectedLen = 2000;
  60862. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  60863. #ifndef NO_ASN_TIME
  60864. /* read exported X509 PEM back into struct, sanity check on export,
  60865. * make sure notBefore/notAfter are the same and certs are identical. */
  60866. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  60867. ExpectNotNull(notBeforeB = X509_get_notBefore(x509b));
  60868. ExpectNotNull(notAfterB = X509_get_notAfter(x509b));
  60869. ExpectIntEQ(ASN1_TIME_compare(notBeforeA, notBeforeB), 0);
  60870. ExpectIntEQ(ASN1_TIME_compare(notAfterA, notAfterB), 0);
  60871. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  60872. X509_free(x509b);
  60873. x509b = NULL;
  60874. #endif
  60875. /* Reset output buffer */
  60876. BIO_free(output);
  60877. output = NULL;
  60878. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  60879. /* Test forcing the AKID to be generated just from KeyIdentifier */
  60880. if (EXPECT_SUCCESS() && x509a->authKeyIdSrc != NULL) {
  60881. XMEMMOVE(x509a->authKeyIdSrc, x509a->authKeyId, x509a->authKeyIdSz);
  60882. x509a->authKeyId = x509a->authKeyIdSrc;
  60883. x509a->authKeyIdSrc = NULL;
  60884. x509a->authKeyIdSrcSz = 0;
  60885. }
  60886. /* Resign to re-generate the der */
  60887. ExpectIntGT(wolfSSL_X509_sign(x509a, priv, EVP_sha256()), 0);
  60888. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  60889. /* Check that we generate a smaller output since the AKID will
  60890. * only contain the KeyIdentifier without any additional
  60891. * information */
  60892. /* Here we copy the validity struct from the original */
  60893. expectedLen = 1688;
  60894. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  60895. /* Reset buffers and x509 */
  60896. BIO_free(input);
  60897. input = NULL;
  60898. BIO_free(output);
  60899. output = NULL;
  60900. X509_free(x509a);
  60901. x509a = NULL;
  60902. /* test CA and basicConstSet values are encoded when
  60903. * the cert is a CA */
  60904. ExpectNotNull(input = BIO_new_file("certs/server-cert.pem", "rb"));
  60905. /* read PEM into X509 struct */
  60906. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  60907. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  60908. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  60909. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  60910. /* read exported X509 PEM back into struct, ensure isCa and basicConstSet
  60911. * values are maintained and certs are identical.*/
  60912. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  60913. ExpectIntEQ(x509b->isCa, 1);
  60914. ExpectIntEQ(x509b->basicConstSet, 1);
  60915. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  60916. X509_free(x509a);
  60917. x509a = NULL;
  60918. X509_free(x509b);
  60919. x509b = NULL;
  60920. BIO_free(input);
  60921. input = NULL;
  60922. BIO_free(output);
  60923. output = NULL;
  60924. /* test CA and basicConstSet values are encoded when
  60925. * the cert is not CA */
  60926. ExpectNotNull(input = BIO_new_file("certs/client-uri-cert.pem", "rb"));
  60927. /* read PEM into X509 struct */
  60928. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  60929. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  60930. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  60931. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  60932. /* read exported X509 PEM back into struct, ensure isCa and
  60933. * basicConstSet values are maintained and certs are identical */
  60934. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  60935. ExpectIntEQ(x509b->isCa, 0);
  60936. ExpectIntEQ(x509b->basicConstSet, 1);
  60937. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  60938. wolfSSL_EVP_PKEY_free(priv);
  60939. X509_free(x509a);
  60940. X509_free(x509b);
  60941. BIO_free(input);
  60942. BIO_free(output);
  60943. #endif
  60944. return EXPECT_RESULT();
  60945. }
  60946. static int test_wolfSSL_X509_NAME_ENTRY(void)
  60947. {
  60948. EXPECT_DECLS;
  60949. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  60950. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN)
  60951. X509* x509 = NULL;
  60952. #ifndef NO_BIO
  60953. BIO* bio = NULL;
  60954. #endif
  60955. X509_NAME* nm = NULL;
  60956. X509_NAME_ENTRY* entry = NULL;
  60957. unsigned char cn[] = "another name to add";
  60958. #ifdef OPENSSL_ALL
  60959. int i;
  60960. int names_len = 0;
  60961. #endif
  60962. ExpectNotNull(x509 =
  60963. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  60964. #ifndef NO_BIO
  60965. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  60966. ExpectIntEQ(PEM_write_bio_X509_AUX(bio, x509), SSL_SUCCESS);
  60967. #endif
  60968. #ifdef WOLFSSL_CERT_REQ
  60969. {
  60970. X509_REQ* req = NULL;
  60971. #ifndef NO_BIO
  60972. BIO* bReq = NULL;
  60973. #endif
  60974. ExpectNotNull(req =
  60975. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  60976. #ifndef NO_BIO
  60977. ExpectNotNull(bReq = BIO_new(BIO_s_mem()));
  60978. ExpectIntEQ(PEM_write_bio_X509_REQ(bReq, req), SSL_SUCCESS);
  60979. BIO_free(bReq);
  60980. #endif
  60981. X509_free(req);
  60982. }
  60983. #endif
  60984. ExpectNotNull(nm = X509_get_subject_name(x509));
  60985. /* Test add entry */
  60986. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_NID(NULL, NID_commonName,
  60987. 0x0c, cn, (int)sizeof(cn)));
  60988. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  60989. #ifdef WOLFSSL_CERT_EXT
  60990. ExpectIntEQ(X509_NAME_add_entry_by_txt(nm, "emailAddress", MBSTRING_UTF8,
  60991. (byte*)"support@wolfssl.com", 19, -1,
  60992. 1), WOLFSSL_SUCCESS);
  60993. #endif
  60994. X509_NAME_ENTRY_free(entry);
  60995. entry = NULL;
  60996. #ifdef WOLFSSL_CERT_REQ
  60997. {
  60998. unsigned char srv_pkcs9p[] = "Server";
  60999. unsigned char fvrtDrnk[] = "tequila";
  61000. unsigned char* der = NULL;
  61001. char* subject = NULL;
  61002. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_pkcs9_contentType,
  61003. MBSTRING_ASC, srv_pkcs9p, -1, -1, 0), SSL_SUCCESS);
  61004. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_favouriteDrink,
  61005. MBSTRING_ASC, fvrtDrnk, -1, -1, 0), SSL_SUCCESS);
  61006. ExpectIntGT(wolfSSL_i2d_X509_NAME(nm, &der), 0);
  61007. ExpectNotNull(der);
  61008. ExpectNotNull(subject = X509_NAME_oneline(nm, 0, 0));
  61009. ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
  61010. ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
  61011. #ifdef DEBUG_WOLFSSL
  61012. if (subject != NULL) {
  61013. fprintf(stderr, "\n\t%s\n", subject);
  61014. }
  61015. #endif
  61016. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  61017. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  61018. }
  61019. #endif
  61020. /* Test add entry by text */
  61021. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_txt(NULL, "commonName",
  61022. 0x0c, cn, (int)sizeof(cn)));
  61023. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) \
  61024. || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  61025. ExpectNull(X509_NAME_ENTRY_create_by_txt(&entry, "unknown",
  61026. V_ASN1_UTF8STRING, cn, (int)sizeof(cn)));
  61027. #endif
  61028. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  61029. X509_NAME_ENTRY_free(entry);
  61030. entry = NULL;
  61031. /* Test add entry by NID */
  61032. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_commonName, MBSTRING_UTF8,
  61033. cn, -1, -1, 0), SSL_SUCCESS);
  61034. #ifdef OPENSSL_ALL
  61035. /* stack of name entry */
  61036. ExpectIntGT((names_len = sk_X509_NAME_ENTRY_num(nm->entries)), 0);
  61037. for (i = 0; i < names_len; i++) {
  61038. ExpectNotNull(entry = sk_X509_NAME_ENTRY_value(nm->entries, i));
  61039. }
  61040. #endif
  61041. #ifndef NO_BIO
  61042. BIO_free(bio);
  61043. #endif
  61044. X509_free(x509); /* free's nm */
  61045. #endif
  61046. return EXPECT_RESULT();
  61047. }
  61048. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61049. static int test_GENERAL_NAME_set0_othername(void) {
  61050. EXPECT_DECLS;
  61051. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61052. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61053. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61054. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61055. defined(WOLFSSL_FPKI)
  61056. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61057. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61058. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61059. const char * cert_fname = "./certs/server-cert.der";
  61060. const char * key_fname = "./certs/server-key.der";
  61061. X509* x509 = NULL;
  61062. GENERAL_NAME* gn = NULL;
  61063. GENERAL_NAMES* gns = NULL;
  61064. ASN1_OBJECT* upn_oid = NULL;
  61065. ASN1_UTF8STRING *utf8str = NULL;
  61066. ASN1_TYPE *value = NULL;
  61067. X509_EXTENSION * ext = NULL;
  61068. byte* pt = NULL;
  61069. byte der[4096];
  61070. int derSz = 0;
  61071. EVP_PKEY* priv = NULL;
  61072. XFILE f = XBADFILE;
  61073. ExpectTrue((f = XFOPEN(cert_fname, "rb")) != XBADFILE);
  61074. ExpectNotNull(x509 = d2i_X509_fp(f, NULL));
  61075. if (f != XBADFILE) {
  61076. XFCLOSE(f);
  61077. f = XBADFILE;
  61078. }
  61079. ExpectNotNull(gn = GENERAL_NAME_new());
  61080. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61081. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61082. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61083. ExpectNotNull(value = ASN1_TYPE_new());
  61084. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61085. if ((value == NULL) || (value->value.ptr != (char*)utf8str)) {
  61086. wolfSSL_ASN1_STRING_free(utf8str);
  61087. }
  61088. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61089. if (EXPECT_FAIL()) {
  61090. ASN1_TYPE_free(value);
  61091. }
  61092. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61093. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61094. if (EXPECT_FAIL()) {
  61095. GENERAL_NAME_free(gn);
  61096. gn = NULL;
  61097. }
  61098. ExpectNotNull(ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61099. ExpectIntEQ(X509_add_ext(x509, ext, -1), 1);
  61100. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61101. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61102. if (f != XBADFILE) {
  61103. XFCLOSE(f);
  61104. f = XBADFILE;
  61105. }
  61106. pt = der;
  61107. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61108. (const unsigned char**)&pt, derSz));
  61109. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  61110. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61111. gns = NULL;
  61112. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61113. NID_subject_alt_name, NULL, NULL));
  61114. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 3);
  61115. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 2));
  61116. ExpectIntEQ(gn->type, 0);
  61117. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61118. ASN1_OBJECT_free(upn_oid);
  61119. X509_EXTENSION_free(ext);
  61120. X509_free(x509);
  61121. EVP_PKEY_free(priv);
  61122. #endif
  61123. return EXPECT_RESULT();
  61124. }
  61125. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61126. static int test_othername_and_SID_ext(void) {
  61127. EXPECT_DECLS;
  61128. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61129. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61130. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61131. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61132. defined(WOLFSSL_FPKI) && defined(WOLFSSL_ASN_TEMPLATE)
  61133. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61134. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61135. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61136. const char* csr_fname = "./certs/csr.signed.der";
  61137. const char* key_fname = "./certs/server-key.der";
  61138. byte der[4096];
  61139. int derSz = 0;
  61140. X509_REQ* x509 = NULL;
  61141. STACK_OF(X509_EXTENSION) *exts = NULL;
  61142. X509_EXTENSION * san_ext = NULL;
  61143. X509_EXTENSION * ext = NULL;
  61144. GENERAL_NAME* gn = NULL;
  61145. GENERAL_NAMES* gns = NULL;
  61146. ASN1_OBJECT* upn_oid = NULL;
  61147. ASN1_UTF8STRING *utf8str = NULL;
  61148. ASN1_TYPE *value = NULL;
  61149. ASN1_STRING *extval = NULL;
  61150. /* SID extension. SID data format explained here:
  61151. * https://blog.qdsecurity.se/2022/05/27/manually-injecting-a-sid-in-a-certificate/
  61152. */
  61153. byte SidExtension[] = {
  61154. 48, 64, 160, 62, 6, 10, 43, 6, 1, 4, 1, 130, 55, 25, 2, 1, 160,
  61155. 48, 4, 46, 83, 45, 49, 45, 53, 45, 50, 49, 45, 50, 56, 52, 51, 57,
  61156. 48, 55, 52, 49, 56, 45, 51, 57, 50, 54, 50, 55, 55, 52, 50, 49, 45,
  61157. 51, 56, 49, 53, 57, 57, 51, 57, 55, 50, 45, 52, 54, 48, 49};
  61158. byte expectedAltName[] = {
  61159. 0x30, 0x27, 0xA0, 0x25, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82,
  61160. 0x37, 0x14, 0x02, 0x03, 0xA0, 0x17, 0x0C, 0x15, 0x6F, 0x74, 0x68, 0x65,
  61161. 0x72, 0x6E, 0x61, 0x6D, 0x65, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  61162. 0x6C, 0x2E, 0x63, 0x6F, 0x6D};
  61163. X509_EXTENSION *sid_ext = NULL;
  61164. ASN1_OBJECT* sid_oid = NULL;
  61165. ASN1_OCTET_STRING *sid_data = NULL;
  61166. ASN1_OBJECT* alt_names_oid = NULL;
  61167. EVP_PKEY* priv = NULL;
  61168. XFILE f = XBADFILE;
  61169. byte* pt = NULL;
  61170. BIO* bio = NULL;
  61171. ExpectTrue((f = XFOPEN(csr_fname, "rb")) != XBADFILE);
  61172. ExpectNotNull(x509 = d2i_X509_REQ_fp(f, NULL));
  61173. if (f != XBADFILE) {
  61174. XFCLOSE(f);
  61175. f = XBADFILE;
  61176. }
  61177. ExpectIntEQ(X509_REQ_set_version(x509, 2), 1);
  61178. ExpectNotNull(gn = GENERAL_NAME_new());
  61179. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61180. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61181. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61182. ExpectNotNull(value = ASN1_TYPE_new());
  61183. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61184. if (EXPECT_FAIL()) {
  61185. ASN1_UTF8STRING_free(utf8str);
  61186. }
  61187. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61188. if (EXPECT_FAIL()) {
  61189. ASN1_TYPE_free(value);
  61190. GENERAL_NAME_free(gn);
  61191. gn = NULL;
  61192. }
  61193. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61194. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61195. if (EXPECT_FAIL()) {
  61196. GENERAL_NAME_free(gn);
  61197. }
  61198. ExpectNotNull(san_ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61199. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61200. ExpectNotNull(sid_data = ASN1_OCTET_STRING_new());
  61201. ASN1_OCTET_STRING_set(sid_data, SidExtension, sizeof(SidExtension));
  61202. ExpectNotNull(sid_ext = X509_EXTENSION_create_by_OBJ(NULL, sid_oid, 0,
  61203. sid_data));
  61204. ExpectNotNull(exts = sk_X509_EXTENSION_new_null());
  61205. /* Ensure an empty stack doesn't raise an error. */
  61206. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61207. ExpectIntEQ(sk_X509_EXTENSION_push(exts, san_ext), 1);
  61208. if (EXPECT_FAIL()) {
  61209. X509_EXTENSION_free(san_ext);
  61210. }
  61211. ExpectIntEQ(sk_X509_EXTENSION_push(exts, sid_ext), 2);
  61212. if (EXPECT_FAIL()) {
  61213. X509_EXTENSION_free(sid_ext);
  61214. }
  61215. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61216. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61217. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61218. if (f != XBADFILE)
  61219. XFCLOSE(f);
  61220. pt = der;
  61221. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61222. (const unsigned char**)&pt, derSz));
  61223. ExpectIntGT(X509_REQ_sign(x509, priv, EVP_sha256()), 0);
  61224. pt = der;
  61225. ExpectIntGT(derSz = i2d_X509_REQ(x509, &pt), 0);
  61226. X509_REQ_free(x509);
  61227. x509 = NULL;
  61228. pt = der;
  61229. ExpectNotNull(d2i_X509_REQ_INFO(&x509, (const unsigned char**)&pt, derSz));
  61230. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61231. gns = NULL;
  61232. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61233. exts = NULL;
  61234. ASN1_OBJECT_free(upn_oid);
  61235. ASN1_OBJECT_free(sid_oid);
  61236. ASN1_OCTET_STRING_free(sid_data);
  61237. X509_REQ_free(x509);
  61238. EVP_PKEY_free(priv);
  61239. /* At this point everything used to generate what is in der is cleaned up.
  61240. * We now read back from der to confirm the extensions were inserted
  61241. * correctly. */
  61242. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  61243. ExpectNotNull(bio);
  61244. ExpectIntEQ(BIO_write(bio, der, derSz), derSz); /* d2i consumes BIO */
  61245. ExpectNotNull(d2i_X509_REQ_bio(bio, &x509));
  61246. ExpectNotNull(x509);
  61247. BIO_free(bio);
  61248. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  61249. x509));
  61250. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  61251. /* Check the SID extension. */
  61252. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61253. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61254. X509_get_ext_by_OBJ(x509, sid_oid, -1)));
  61255. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61256. ExpectIntEQ(extval->length, sizeof(SidExtension));
  61257. ExpectIntEQ(XMEMCMP(SidExtension, extval->data, sizeof(SidExtension)), 0);
  61258. ASN1_OBJECT_free(sid_oid);
  61259. /* Check the AltNames extension. */
  61260. ExpectNotNull(alt_names_oid = OBJ_txt2obj("subjectAltName", 0));
  61261. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61262. X509_get_ext_by_OBJ(x509, alt_names_oid, -1)));
  61263. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61264. ExpectIntEQ(extval->length, sizeof(expectedAltName));
  61265. ExpectIntEQ(XMEMCMP(expectedAltName, extval->data, sizeof(expectedAltName)),
  61266. 0);
  61267. ASN1_OBJECT_free(alt_names_oid);
  61268. /* Cleanup */
  61269. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61270. NID_subject_alt_name, NULL, NULL));
  61271. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  61272. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 0));
  61273. ExpectIntEQ(gn->type, 0);
  61274. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61275. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61276. X509_REQ_free(x509);
  61277. #endif
  61278. return EXPECT_RESULT();
  61279. }
  61280. static int test_wolfSSL_X509_set_name(void)
  61281. {
  61282. EXPECT_DECLS;
  61283. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61284. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61285. X509* x509 = NULL;
  61286. X509_NAME* name = NULL;
  61287. ExpectNotNull(name = X509_NAME_new());
  61288. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  61289. (byte*)"wolfssl.com", 11, 0, 1),
  61290. WOLFSSL_SUCCESS);
  61291. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  61292. (byte*)"support@wolfssl.com", 19, -1,
  61293. 1), WOLFSSL_SUCCESS);
  61294. ExpectNotNull(x509 = X509_new());
  61295. ExpectIntEQ(X509_set_subject_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61296. ExpectIntEQ(X509_set_subject_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61297. ExpectIntEQ(X509_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61298. ExpectIntEQ(X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  61299. ExpectIntEQ(X509_set_issuer_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61300. ExpectIntEQ(X509_set_issuer_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61301. ExpectIntEQ(X509_set_issuer_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61302. ExpectIntEQ(X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  61303. X509_free(x509);
  61304. X509_NAME_free(name);
  61305. #endif /* OPENSSL_ALL && !NO_CERTS */
  61306. return EXPECT_RESULT();
  61307. }
  61308. static int test_wolfSSL_X509_set_notAfter(void)
  61309. {
  61310. EXPECT_DECLS;
  61311. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61312. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61313. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61314. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) &&\
  61315. !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) && !defined(NO_BIO)
  61316. /* Generalized time will overflow time_t if not long */
  61317. X509* x = NULL;
  61318. BIO* bio = NULL;
  61319. ASN1_TIME *asn_time = NULL;
  61320. ASN1_TIME *time_check = NULL;
  61321. const int year = 365*24*60*60;
  61322. const int day = 24*60*60;
  61323. const int hour = 60*60;
  61324. const int mini = 60;
  61325. int offset_day;
  61326. unsigned char buf[25];
  61327. time_t t;
  61328. /*
  61329. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61330. */
  61331. t = (time_t)107 * year + 31 * day + 34 * hour + 30 * mini + 7 * day;
  61332. offset_day = 7;
  61333. /*
  61334. * Free these.
  61335. */
  61336. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61337. ExpectNotNull(asn_time);
  61338. ExpectNotNull(x = X509_new());
  61339. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61340. /*
  61341. * Tests
  61342. */
  61343. ExpectTrue(wolfSSL_X509_set_notAfter(x, asn_time));
  61344. /* time_check is simply (ANS1_TIME*)x->notAfter */
  61345. ExpectNotNull(time_check = X509_get_notAfter(x));
  61346. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61347. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61348. /* Convert to human readable format and compare to intended date */
  61349. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61350. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61351. ExpectIntEQ(XMEMCMP(buf, "Jan 20 10:30:00 2077 GMT", sizeof(buf) - 1), 0);
  61352. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, NULL));
  61353. ExpectFalse(wolfSSL_X509_set_notAfter(x, NULL));
  61354. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, asn_time));
  61355. /*
  61356. * Cleanup
  61357. */
  61358. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61359. X509_free(x);
  61360. BIO_free(bio);
  61361. #endif
  61362. return EXPECT_RESULT();
  61363. }
  61364. static int test_wolfSSL_X509_set_notBefore(void)
  61365. {
  61366. EXPECT_DECLS;
  61367. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61368. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61369. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61370. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  61371. X509* x = NULL;
  61372. BIO* bio = NULL;
  61373. ASN1_TIME *asn_time = NULL;
  61374. ASN1_TIME *time_check = NULL;
  61375. const int year = 365*24*60*60;
  61376. const int day = 24*60*60;
  61377. const int hour = 60*60;
  61378. const int mini = 60;
  61379. int offset_day;
  61380. unsigned char buf[25];
  61381. time_t t;
  61382. /*
  61383. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61384. */
  61385. t = (time_t)49 * year + 125 * day + 20 * hour + 30 * mini + 7 * day;
  61386. offset_day = 7;
  61387. /*
  61388. * Free these.
  61389. */
  61390. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61391. ExpectNotNull(asn_time);
  61392. ExpectNotNull(x = X509_new());
  61393. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61394. ExpectIntEQ(ASN1_TIME_check(asn_time), WOLFSSL_SUCCESS);
  61395. /*
  61396. * Main Tests
  61397. */
  61398. ExpectTrue(wolfSSL_X509_set_notBefore(x, asn_time));
  61399. /* time_check == (ANS1_TIME*)x->notBefore */
  61400. ExpectNotNull(time_check = X509_get_notBefore(x));
  61401. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61402. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61403. /* Convert to human readable format and compare to intended date */
  61404. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61405. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61406. ExpectIntEQ(XMEMCMP(buf, "May 8 20:30:00 2019 GMT", sizeof(buf) - 1), 0);
  61407. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, NULL));
  61408. ExpectFalse(wolfSSL_X509_set_notBefore(x, NULL));
  61409. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, asn_time));
  61410. /*
  61411. * Cleanup
  61412. */
  61413. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61414. X509_free(x);
  61415. BIO_free(bio);
  61416. #endif
  61417. return EXPECT_RESULT();
  61418. }
  61419. static int test_wolfSSL_X509_set_version(void)
  61420. {
  61421. EXPECT_DECLS;
  61422. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  61423. !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61424. X509* x509 = NULL;
  61425. long v = 2L;
  61426. long maxInt = INT_MAX;
  61427. ExpectNotNull(x509 = X509_new());
  61428. /* These should pass. */
  61429. ExpectTrue(wolfSSL_X509_set_version(x509, v));
  61430. ExpectIntEQ(v, wolfSSL_X509_get_version(x509));
  61431. /* Fail Case: When v(long) is greater than x509->version(int). */
  61432. v = maxInt+1;
  61433. ExpectFalse(wolfSSL_X509_set_version(x509, v));
  61434. ExpectFalse(wolfSSL_X509_set_version(NULL, 2L));
  61435. ExpectFalse(wolfSSL_X509_set_version(NULL, maxInt+1));
  61436. /* Cleanup */
  61437. X509_free(x509);
  61438. #endif
  61439. return EXPECT_RESULT();
  61440. }
  61441. #ifndef NO_BIO
  61442. static int test_wolfSSL_BIO_gets(void)
  61443. {
  61444. EXPECT_DECLS;
  61445. #if defined(OPENSSL_EXTRA)
  61446. BIO* bio = NULL;
  61447. BIO* bio2 = NULL;
  61448. char msg[] = "\nhello wolfSSL\n security plus\t---...**adf\na...b.c";
  61449. char emp[] = "";
  61450. char bio_buffer[20];
  61451. int bufferSz = 20;
  61452. #ifdef OPENSSL_ALL
  61453. BUF_MEM* emp_bm = NULL;
  61454. BUF_MEM* msg_bm = NULL;
  61455. #endif
  61456. /* try with bad args */
  61457. ExpectNull(bio = BIO_new_mem_buf(NULL, sizeof(msg)));
  61458. #ifdef OPENSSL_ALL
  61459. ExpectIntEQ(BIO_set_mem_buf(bio, NULL, BIO_NOCLOSE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  61460. #endif
  61461. /* try with real msg */
  61462. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61463. XMEMSET(bio_buffer, 0, bufferSz);
  61464. ExpectNotNull(BIO_push(bio, BIO_new(BIO_s_bio())));
  61465. ExpectNull(bio2 = BIO_find_type(bio, BIO_TYPE_FILE));
  61466. ExpectNotNull(bio2 = BIO_find_type(bio, BIO_TYPE_BIO));
  61467. ExpectFalse(bio2 != BIO_next(bio));
  61468. /* make buffer filled with no terminating characters */
  61469. XMEMSET(bio_buffer, 1, bufferSz);
  61470. /* BIO_gets reads a line of data */
  61471. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61472. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61473. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61474. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61475. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61476. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61477. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61478. #ifdef OPENSSL_ALL
  61479. /* test setting the mem_buf manually */
  61480. BIO_free(bio);
  61481. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61482. ExpectNotNull(emp_bm = BUF_MEM_new());
  61483. ExpectNotNull(msg_bm = BUF_MEM_new());
  61484. ExpectIntEQ(BUF_MEM_grow(msg_bm, sizeof(msg)), sizeof(msg));
  61485. if (EXPECT_SUCCESS()) {
  61486. XFREE(msg_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61487. msg_bm->data = NULL;
  61488. }
  61489. /* emp size is 1 for terminator */
  61490. ExpectIntEQ(BUF_MEM_grow(emp_bm, sizeof(emp)), sizeof(emp));
  61491. if (EXPECT_SUCCESS()) {
  61492. XFREE(emp_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61493. emp_bm->data = emp;
  61494. msg_bm->data = msg;
  61495. }
  61496. ExpectIntEQ(BIO_set_mem_buf(bio, emp_bm, BIO_CLOSE), WOLFSSL_SUCCESS);
  61497. /* check reading an empty string */
  61498. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  61499. ExpectStrEQ(emp, bio_buffer);
  61500. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61501. /* BIO_gets reads a line of data */
  61502. ExpectIntEQ(BIO_set_mem_buf(bio, msg_bm, BIO_NOCLOSE), WOLFSSL_SUCCESS);
  61503. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61504. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61505. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61506. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61507. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61508. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61509. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61510. if (EXPECT_SUCCESS())
  61511. emp_bm->data = NULL;
  61512. BUF_MEM_free(emp_bm);
  61513. if (EXPECT_SUCCESS())
  61514. msg_bm->data = NULL;
  61515. BUF_MEM_free(msg_bm);
  61516. #endif
  61517. /* check not null terminated string */
  61518. BIO_free(bio);
  61519. bio = NULL;
  61520. msg[0] = 0x33;
  61521. msg[1] = 0x33;
  61522. msg[2] = 0x33;
  61523. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  61524. ExpectIntEQ(BIO_gets(bio, bio_buffer, 3), 2);
  61525. ExpectIntEQ(bio_buffer[0], msg[0]);
  61526. ExpectIntEQ(bio_buffer[1], msg[1]);
  61527. ExpectIntNE(bio_buffer[2], msg[2]);
  61528. BIO_free(bio);
  61529. bio = NULL;
  61530. msg[3] = 0x33;
  61531. bio_buffer[3] = 0x33;
  61532. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  61533. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 3);
  61534. ExpectIntEQ(bio_buffer[0], msg[0]);
  61535. ExpectIntEQ(bio_buffer[1], msg[1]);
  61536. ExpectIntEQ(bio_buffer[2], msg[2]);
  61537. ExpectIntNE(bio_buffer[3], 0x33); /* make sure null terminator was set */
  61538. /* check reading an empty string */
  61539. BIO_free(bio);
  61540. bio = NULL;
  61541. ExpectNotNull(bio = BIO_new_mem_buf((void*)emp, sizeof(emp)));
  61542. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  61543. ExpectStrEQ(emp, bio_buffer);
  61544. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61545. /* check error cases */
  61546. BIO_free(bio);
  61547. bio = NULL;
  61548. ExpectIntEQ(BIO_gets(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61549. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61550. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  61551. #if !defined(NO_FILESYSTEM)
  61552. {
  61553. BIO* f_bio = NULL;
  61554. XFILE f = XBADFILE;
  61555. ExpectNotNull(f_bio = BIO_new(BIO_s_file()));
  61556. ExpectIntLE(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  61557. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  61558. ExpectIntEQ((int)BIO_set_fp(f_bio, f, BIO_CLOSE), SSL_SUCCESS);
  61559. if (EXPECT_FAIL() && (f != XBADFILE)) {
  61560. XFCLOSE(f);
  61561. }
  61562. ExpectIntGT(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  61563. BIO_free(f_bio);
  61564. f_bio = NULL;
  61565. }
  61566. #endif /* NO_FILESYSTEM */
  61567. BIO_free(bio);
  61568. bio = NULL;
  61569. BIO_free(bio2);
  61570. bio2 = NULL;
  61571. /* try with type BIO */
  61572. XMEMCPY(msg, "\nhello wolfSSL\n security plus\t---...**adf\na...b.c",
  61573. sizeof(msg));
  61574. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  61575. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  61576. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  61577. ExpectIntEQ(BIO_set_write_buf_size(bio, 10), SSL_SUCCESS);
  61578. ExpectIntEQ(BIO_set_write_buf_size(bio2, sizeof(msg)), SSL_SUCCESS);
  61579. ExpectIntEQ(BIO_make_bio_pair(bio, bio2), SSL_SUCCESS);
  61580. ExpectIntEQ(BIO_write(bio2, msg, sizeof(msg)), sizeof(msg));
  61581. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61582. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61583. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61584. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61585. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61586. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61587. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61588. BIO_free(bio);
  61589. bio = NULL;
  61590. BIO_free(bio2);
  61591. bio2 = NULL;
  61592. /* check reading an empty string */
  61593. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  61594. ExpectIntEQ(BIO_set_write_buf_size(bio, sizeof(emp)), SSL_SUCCESS);
  61595. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61596. ExpectStrEQ(emp, bio_buffer);
  61597. BIO_free(bio);
  61598. bio = NULL;
  61599. #endif
  61600. return EXPECT_RESULT();
  61601. }
  61602. static int test_wolfSSL_BIO_puts(void)
  61603. {
  61604. EXPECT_DECLS;
  61605. #if defined(OPENSSL_EXTRA)
  61606. BIO* bio = NULL;
  61607. char input[] = "hello\0world\n.....ok\n\0";
  61608. char output[128];
  61609. XMEMSET(output, 0, sizeof(output));
  61610. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61611. ExpectIntEQ(BIO_puts(bio, input), 5);
  61612. ExpectIntEQ(BIO_pending(bio), 5);
  61613. ExpectIntEQ(BIO_puts(bio, input + 6), 14);
  61614. ExpectIntEQ(BIO_pending(bio), 19);
  61615. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 11);
  61616. ExpectStrEQ(output, "helloworld\n");
  61617. ExpectIntEQ(BIO_pending(bio), 8);
  61618. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 8);
  61619. ExpectStrEQ(output, ".....ok\n");
  61620. ExpectIntEQ(BIO_pending(bio), 0);
  61621. ExpectIntEQ(BIO_puts(bio, ""), -1);
  61622. BIO_free(bio);
  61623. #endif
  61624. return EXPECT_RESULT();
  61625. }
  61626. static int test_wolfSSL_BIO_dump(void)
  61627. {
  61628. EXPECT_DECLS;
  61629. #if defined(OPENSSL_EXTRA)
  61630. BIO* bio;
  61631. static const unsigned char data[] = {
  61632. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
  61633. 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
  61634. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
  61635. 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
  61636. 0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
  61637. 0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
  61638. 0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
  61639. 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
  61640. 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
  61641. 0xB4
  61642. };
  61643. /* Generated with OpenSSL. */
  61644. static const char expected[] =
  61645. "0000 - 30 59 30 13 06 07 2a 86-48 ce 3d 02 01 06 08 2a 0Y0...*.H.=....*\n"
  61646. "0010 - 86 48 ce 3d 03 01 07 03-42 00 04 55 bf f4 0f 44 .H.=....B..U...D\n"
  61647. "0020 - 50 9a 3d ce 9b b7 f0 c5-4d f5 70 7b d4 ec 24 8e P.=.....M.p{..$.\n"
  61648. "0030 - 19 80 ec 5a 4c a2 24 03-62 2c 9b da ef a2 35 12 ...ZL.$.b,....5.\n"
  61649. "0040 - 43 84 76 16 c6 56 95 06-cc 01 a9 bd f6 75 1a 42 C.v..V.......u.B\n"
  61650. "0050 - f7 bd a9 b2 36 22 5f c7-5d 7f b4 ....6\"_.]..\n";
  61651. static const char expectedAll[] =
  61652. "0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
  61653. "0010 - 10 11 12 13 14 15 16 17-18 19 1a 1b 1c 1d 1e 1f ................\n"
  61654. "0020 - 20 21 22 23 24 25 26 27-28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
  61655. "0030 - 30 31 32 33 34 35 36 37-38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n"
  61656. "0040 - 40 41 42 43 44 45 46 47-48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n"
  61657. "0050 - 50 51 52 53 54 55 56 57-58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n"
  61658. "0060 - 60 61 62 63 64 65 66 67-68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n"
  61659. "0070 - 70 71 72 73 74 75 76 77-78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"
  61660. "0080 - 80 81 82 83 84 85 86 87-88 89 8a 8b 8c 8d 8e 8f ................\n"
  61661. "0090 - 90 91 92 93 94 95 96 97-98 99 9a 9b 9c 9d 9e 9f ................\n"
  61662. "00a0 - a0 a1 a2 a3 a4 a5 a6 a7-a8 a9 aa ab ac ad ae af ................\n"
  61663. "00b0 - b0 b1 b2 b3 b4 b5 b6 b7-b8 b9 ba bb bc bd be bf ................\n"
  61664. "00c0 - c0 c1 c2 c3 c4 c5 c6 c7-c8 c9 ca cb cc cd ce cf ................\n"
  61665. "00d0 - d0 d1 d2 d3 d4 d5 d6 d7-d8 d9 da db dc dd de df ................\n"
  61666. "00e0 - e0 e1 e2 e3 e4 e5 e6 e7-e8 e9 ea eb ec ed ee ef ................\n"
  61667. "00f0 - f0 f1 f2 f3 f4 f5 f6 f7-f8 f9 fa fb fc fd fe ff ................\n";
  61668. char output[16 * 80];
  61669. int i;
  61670. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61671. /* Example key dumped. */
  61672. ExpectIntEQ(BIO_dump(bio, (const char*)data, (int)sizeof(data)),
  61673. sizeof(expected) - 1);
  61674. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expected) - 1);
  61675. ExpectIntEQ(XMEMCMP(output, expected, sizeof(expected) - 1), 0);
  61676. /* Try every possible value for a character. */
  61677. for (i = 0; i < 256; i++)
  61678. output[i] = i;
  61679. ExpectIntEQ(BIO_dump(bio, output, 256), sizeof(expectedAll) - 1);
  61680. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expectedAll) - 1);
  61681. ExpectIntEQ(XMEMCMP(output, expectedAll, sizeof(expectedAll) - 1), 0);
  61682. BIO_free(bio);
  61683. #endif
  61684. return EXPECT_RESULT();
  61685. }
  61686. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  61687. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  61688. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  61689. static int forceWantRead(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  61690. {
  61691. (void)ssl;
  61692. (void)buf;
  61693. (void)sz;
  61694. (void)ctx;
  61695. return WOLFSSL_CBIO_ERR_WANT_READ;
  61696. }
  61697. #endif
  61698. static int test_wolfSSL_BIO_should_retry(void)
  61699. {
  61700. EXPECT_DECLS;
  61701. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  61702. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  61703. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  61704. tcp_ready ready;
  61705. func_args server_args;
  61706. THREAD_TYPE serverThread;
  61707. SOCKET_T sockfd = 0;
  61708. WOLFSSL_CTX* ctx = NULL;
  61709. WOLFSSL* ssl = NULL;
  61710. char msg[64] = "hello wolfssl!";
  61711. char reply[1024];
  61712. int msgSz = (int)XSTRLEN(msg);
  61713. int ret;
  61714. BIO* bio = NULL;
  61715. XMEMSET(&server_args, 0, sizeof(func_args));
  61716. #ifdef WOLFSSL_TIRTOS
  61717. fdOpenSession(Task_self());
  61718. #endif
  61719. StartTCP();
  61720. InitTcpReady(&ready);
  61721. #if defined(USE_WINDOWS_API)
  61722. /* use RNG to get random port if using windows */
  61723. ready.port = GetRandomPort();
  61724. #endif
  61725. server_args.signal = &ready;
  61726. start_thread(test_server_nofail, &server_args, &serverThread);
  61727. wait_tcp_ready(&server_args);
  61728. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  61729. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  61730. ExpectIntEQ(wolfSSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY), 0);
  61731. #endif
  61732. ExpectIntEQ(WOLFSSL_SUCCESS,
  61733. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  61734. ExpectIntEQ(WOLFSSL_SUCCESS,
  61735. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  61736. ExpectIntEQ(WOLFSSL_SUCCESS,
  61737. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  61738. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  61739. /* force retry */
  61740. ExpectNotNull(bio = wolfSSL_BIO_new_ssl(ctx, 1));
  61741. ExpectIntEQ(BIO_get_ssl(bio, &ssl), 1);
  61742. ExpectNotNull(ssl);
  61743. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  61744. wolfSSL_SSLSetIORecv(ssl, forceWantRead);
  61745. if (EXPECT_FAIL()) {
  61746. wolfSSL_free(ssl);
  61747. ssl = NULL;
  61748. }
  61749. ExpectIntLE(BIO_write(bio, msg, msgSz), 0);
  61750. ExpectIntNE(BIO_should_retry(bio), 0);
  61751. ExpectIntEQ(BIO_should_read(bio), 0);
  61752. ExpectIntEQ(BIO_should_write(bio), 0);
  61753. /* now perform successful connection */
  61754. wolfSSL_SSLSetIORecv(ssl, EmbedReceive);
  61755. ExpectIntEQ(BIO_write(bio, msg, msgSz), msgSz);
  61756. ExpectIntNE(BIO_read(bio, reply, sizeof(reply)), 0);
  61757. ret = wolfSSL_get_error(ssl, -1);
  61758. if (ret == WOLFSSL_ERROR_WANT_READ || ret == WOLFSSL_ERROR_WANT_WRITE) {
  61759. ExpectIntNE(BIO_should_retry(bio), 0);
  61760. if (ret == WOLFSSL_ERROR_WANT_READ)
  61761. ExpectIntEQ(BIO_should_read(bio), 1);
  61762. else
  61763. ExpectIntEQ(BIO_should_read(bio), 0);
  61764. if (ret == WOLFSSL_ERROR_WANT_WRITE)
  61765. ExpectIntEQ(BIO_should_write(bio), 1);
  61766. else
  61767. ExpectIntEQ(BIO_should_write(bio), 0);
  61768. }
  61769. else {
  61770. ExpectIntEQ(BIO_should_retry(bio), 0);
  61771. ExpectIntEQ(BIO_should_read(bio), 0);
  61772. ExpectIntEQ(BIO_should_write(bio), 0);
  61773. }
  61774. ExpectIntEQ(XMEMCMP(reply, "I hear you fa shizzle!",
  61775. XSTRLEN("I hear you fa shizzle!")), 0);
  61776. BIO_free(bio);
  61777. wolfSSL_CTX_free(ctx);
  61778. CloseSocket(sockfd);
  61779. join_thread(serverThread);
  61780. FreeTcpReady(&ready);
  61781. #ifdef WOLFSSL_TIRTOS
  61782. fdOpenSession(Task_self());
  61783. #endif
  61784. #endif
  61785. return EXPECT_RESULT();
  61786. }
  61787. static int test_wolfSSL_BIO_connect(void)
  61788. {
  61789. EXPECT_DECLS;
  61790. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  61791. defined(HAVE_HTTP_CLIENT) && !defined(NO_WOLFSSL_CLIENT)
  61792. tcp_ready ready;
  61793. func_args server_args;
  61794. THREAD_TYPE serverThread;
  61795. BIO *tcpBio = NULL;
  61796. BIO *sslBio = NULL;
  61797. SSL_CTX* ctx = NULL;
  61798. SSL *ssl = NULL;
  61799. SSL *sslPtr;
  61800. char msg[] = "hello wolfssl!";
  61801. char reply[30];
  61802. char buff[10] = {0};
  61803. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  61804. ExpectIntEQ(WOLFSSL_SUCCESS,
  61805. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  61806. ExpectIntEQ(WOLFSSL_SUCCESS,
  61807. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  61808. ExpectIntEQ(WOLFSSL_SUCCESS,
  61809. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  61810. /* Setup server */
  61811. XMEMSET(&server_args, 0, sizeof(func_args));
  61812. StartTCP();
  61813. InitTcpReady(&ready);
  61814. #if defined(USE_WINDOWS_API)
  61815. /* use RNG to get random port if using windows */
  61816. ready.port = GetRandomPort();
  61817. #endif
  61818. server_args.signal = &ready;
  61819. start_thread(test_server_nofail, &server_args, &serverThread);
  61820. wait_tcp_ready(&server_args);
  61821. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  61822. /* Start the test proper */
  61823. /* Setup the TCP BIO */
  61824. ExpectNotNull(tcpBio = BIO_new_connect(wolfSSLIP));
  61825. ExpectIntEQ(BIO_set_conn_port(tcpBio, buff), 1);
  61826. /* Setup the SSL object */
  61827. ExpectNotNull(ssl = SSL_new(ctx));
  61828. SSL_set_connect_state(ssl);
  61829. /* Setup the SSL BIO */
  61830. ExpectNotNull(sslBio = BIO_new(BIO_f_ssl()));
  61831. ExpectIntEQ(BIO_set_ssl(sslBio, ssl, BIO_CLOSE), 1);
  61832. if (EXPECT_FAIL()) {
  61833. wolfSSL_free(ssl);
  61834. }
  61835. /* Verify that BIO_get_ssl works. */
  61836. ExpectIntEQ(BIO_get_ssl(sslBio, &sslPtr), 1);
  61837. ExpectPtrEq(ssl, sslPtr);
  61838. /* Link BIO's so that sslBio uses tcpBio for IO */
  61839. ExpectPtrEq(BIO_push(sslBio, tcpBio), sslBio);
  61840. /* Do TCP connect */
  61841. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  61842. /* Do TLS handshake */
  61843. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  61844. /* Test writing */
  61845. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  61846. /* Expect length of default wolfSSL reply */
  61847. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  61848. /* Clean it all up */
  61849. BIO_free_all(sslBio);
  61850. /* Server clean up */
  61851. join_thread(serverThread);
  61852. FreeTcpReady(&ready);
  61853. /* Run the same test, but use BIO_new_ssl_connect and set the IP and port
  61854. * after. */
  61855. XMEMSET(&server_args, 0, sizeof(func_args));
  61856. StartTCP();
  61857. InitTcpReady(&ready);
  61858. #if defined(USE_WINDOWS_API)
  61859. /* use RNG to get random port if using windows */
  61860. ready.port = GetRandomPort();
  61861. #endif
  61862. server_args.signal = &ready;
  61863. start_thread(test_server_nofail, &server_args, &serverThread);
  61864. wait_tcp_ready(&server_args);
  61865. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  61866. ExpectNotNull(sslBio = BIO_new_ssl_connect(ctx));
  61867. ExpectIntEQ(BIO_set_conn_hostname(sslBio, (char*)wolfSSLIP), 1);
  61868. ExpectIntEQ(BIO_set_conn_port(sslBio, buff), 1);
  61869. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  61870. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  61871. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  61872. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  61873. /* Attempt to close the TLS connection gracefully. */
  61874. BIO_ssl_shutdown(sslBio);
  61875. BIO_free_all(sslBio);
  61876. join_thread(serverThread);
  61877. FreeTcpReady(&ready);
  61878. SSL_CTX_free(ctx);
  61879. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  61880. wc_ecc_fp_free(); /* free per thread cache */
  61881. #endif
  61882. #endif
  61883. return EXPECT_RESULT();
  61884. }
  61885. static int test_wolfSSL_BIO_tls(void)
  61886. {
  61887. EXPECT_DECLS;
  61888. #if !defined(NO_BIO) && defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT)
  61889. SSL_CTX* ctx = NULL;
  61890. SSL *ssl = NULL;
  61891. BIO *readBio = NULL;
  61892. BIO *writeBio = NULL;
  61893. int ret;
  61894. int err = 0;
  61895. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  61896. ExpectNotNull(ssl = SSL_new(ctx));
  61897. ExpectNotNull(readBio = BIO_new(BIO_s_mem()));
  61898. ExpectNotNull(writeBio = BIO_new(BIO_s_mem()));
  61899. /* Qt reads data from write-bio,
  61900. * then writes the read data into plain packet.
  61901. * Qt reads data from plain packet,
  61902. * then writes the read data into read-bio.
  61903. */
  61904. SSL_set_bio(ssl, readBio, writeBio);
  61905. do {
  61906. #ifdef WOLFSSL_ASYNC_CRYPT
  61907. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  61908. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  61909. if (ret < 0) { break; } else if (ret == 0) { continue; }
  61910. }
  61911. #endif
  61912. ret = SSL_connect(ssl);
  61913. err = SSL_get_error(ssl, 0);
  61914. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  61915. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61916. /* in this use case, should return WANT READ
  61917. * so that Qt will read the data from plain packet for next state.
  61918. */
  61919. ExpectIntEQ(err, SSL_ERROR_WANT_READ);
  61920. SSL_free(ssl);
  61921. SSL_CTX_free(ctx);
  61922. #endif
  61923. return EXPECT_RESULT();
  61924. }
  61925. static int test_wolfSSL_BIO_datagram(void)
  61926. {
  61927. EXPECT_DECLS;
  61928. #if !defined(NO_BIO) && defined(WOLFSSL_DTLS) && defined(WOLFSSL_HAVE_BIO_ADDR) && defined(OPENSSL_EXTRA)
  61929. int ret;
  61930. SOCKET_T fd1 = SOCKET_INVALID, fd2 = SOCKET_INVALID;
  61931. WOLFSSL_BIO *bio1 = NULL, *bio2 = NULL;
  61932. WOLFSSL_BIO_ADDR *bio_addr1 = NULL, *bio_addr2 = NULL;
  61933. SOCKADDR_IN sin1, sin2;
  61934. socklen_t slen;
  61935. static const char test_msg[] = "I am a datagram, short and stout.";
  61936. char test_msg_recvd[sizeof(test_msg) + 10];
  61937. #ifdef USE_WINDOWS_API
  61938. static const DWORD timeout = 250; /* ms */
  61939. #else
  61940. static const struct timeval timeout = { 0, 250000 };
  61941. #endif
  61942. StartTCP();
  61943. if (EXPECT_SUCCESS()) {
  61944. fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  61945. ExpectIntNE(fd1, SOCKET_INVALID);
  61946. }
  61947. if (EXPECT_SUCCESS()) {
  61948. fd2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  61949. ExpectIntNE(fd2, SOCKET_INVALID);
  61950. }
  61951. if (EXPECT_SUCCESS()) {
  61952. bio1 = wolfSSL_BIO_new_dgram(fd1, 1 /* closeF */);
  61953. ExpectNotNull(bio1);
  61954. }
  61955. if (EXPECT_SUCCESS()) {
  61956. bio2 = wolfSSL_BIO_new_dgram(fd2, 1 /* closeF */);
  61957. ExpectNotNull(bio2);
  61958. }
  61959. if (EXPECT_SUCCESS()) {
  61960. sin1.sin_family = AF_INET;
  61961. sin1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  61962. sin1.sin_port = 0;
  61963. slen = (socklen_t)sizeof(sin1);
  61964. ExpectIntEQ(bind(fd1, (const struct sockaddr *)&sin1, slen), 0);
  61965. ExpectIntEQ(setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  61966. ExpectIntEQ(getsockname(fd1, (struct sockaddr *)&sin1, &slen), 0);
  61967. }
  61968. if (EXPECT_SUCCESS()) {
  61969. sin2.sin_family = AF_INET;
  61970. sin2.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  61971. sin2.sin_port = 0;
  61972. slen = (socklen_t)sizeof(sin2);
  61973. ExpectIntEQ(bind(fd2, (const struct sockaddr *)&sin2, slen), 0);
  61974. ExpectIntEQ(setsockopt(fd2, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  61975. ExpectIntEQ(getsockname(fd2, (struct sockaddr *)&sin2, &slen), 0);
  61976. }
  61977. if (EXPECT_SUCCESS()) {
  61978. bio_addr1 = wolfSSL_BIO_ADDR_new();
  61979. ExpectNotNull(bio_addr1);
  61980. }
  61981. if (EXPECT_SUCCESS()) {
  61982. bio_addr2 = wolfSSL_BIO_ADDR_new();
  61983. ExpectNotNull(bio_addr2);
  61984. }
  61985. if (EXPECT_SUCCESS()) {
  61986. /* for OpenSSL compatibility, direct copying of sockaddrs into BIO_ADDRs must work right. */
  61987. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  61988. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  61989. wolfSSL_BIO_ADDR_clear(bio_addr2);
  61990. }
  61991. test_msg_recvd[0] = 0;
  61992. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  61993. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  61994. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  61995. #ifdef WOLFSSL_BIO_HAVE_FLOW_STATS
  61996. ExpectIntEQ(wolfSSL_BIO_number_written(bio1), sizeof(test_msg));
  61997. ExpectIntEQ(wolfSSL_BIO_number_read(bio2), sizeof(test_msg));
  61998. #endif
  61999. /* bio2 should now have bio1's addr stored as its peer_addr, because the
  62000. * BIOs aren't "connected" yet. use it to send a reply.
  62001. */
  62002. test_msg_recvd[0] = 0;
  62003. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62004. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62005. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62006. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62007. ExpectIntNE(BIO_should_retry(bio1), 0);
  62008. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62009. ExpectIntNE(BIO_should_retry(bio2), 0);
  62010. /* now "connect" the sockets. */
  62011. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin2, (socklen_t)sizeof(sin2)), 0);
  62012. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62013. if (EXPECT_SUCCESS()) {
  62014. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62015. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr2), WOLFSSL_SUCCESS);
  62016. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62017. }
  62018. if (EXPECT_SUCCESS()) {
  62019. XMEMCPY(&bio_addr1->sa_in, &sin1, sizeof(sin1));
  62020. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr1), WOLFSSL_SUCCESS);
  62021. wolfSSL_BIO_ADDR_clear(bio_addr1);
  62022. }
  62023. test_msg_recvd[0] = 0;
  62024. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62025. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62026. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62027. test_msg_recvd[0] = 0;
  62028. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62029. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62030. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62031. #ifdef __linux__
  62032. /* now "disconnect" the sockets and attempt transmits expected to fail. */
  62033. sin1.sin_family = AF_UNSPEC;
  62034. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62035. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62036. sin1.sin_family = AF_INET;
  62037. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62038. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62039. if (EXPECT_SUCCESS()) {
  62040. sin2.sin_addr.s_addr = htonl(0xc0a8c0a8); /* 192.168.192.168 -- invalid for loopback interface. */
  62041. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62042. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  62043. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62044. }
  62045. test_msg_recvd[0] = 0;
  62046. errno = 0;
  62047. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), -1);
  62048. ExpectTrue((errno == EINVAL) || (errno == ENETUNREACH));
  62049. #endif /* __linux__ */
  62050. if (bio1) {
  62051. ret = wolfSSL_BIO_free(bio1);
  62052. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62053. } else if (fd1 != SOCKET_INVALID)
  62054. CloseSocket(fd1);
  62055. if (bio2) {
  62056. ret = wolfSSL_BIO_free(bio2);
  62057. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62058. } else if (fd2 != SOCKET_INVALID)
  62059. CloseSocket(fd2);
  62060. if (bio_addr1)
  62061. wolfSSL_BIO_ADDR_free(bio_addr1);
  62062. if (bio_addr2)
  62063. wolfSSL_BIO_ADDR_free(bio_addr2);
  62064. #endif /* !NO_BIO && WOLFSSL_DTLS && WOLFSSL_HAVE_BIO_ADDR && OPENSSL_EXTRA */
  62065. return EXPECT_RESULT();
  62066. }
  62067. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62068. defined(HAVE_HTTP_CLIENT)
  62069. static THREAD_RETURN WOLFSSL_THREAD test_wolfSSL_BIO_accept_client(void* args)
  62070. {
  62071. BIO* clientBio;
  62072. SSL* sslClient;
  62073. SSL_CTX* ctx;
  62074. char connectAddr[20]; /* IP + port */;
  62075. (void)args;
  62076. AssertIntGT(snprintf(connectAddr, sizeof(connectAddr), "%s:%d", wolfSSLIP, wolfSSLPort), 0);
  62077. AssertNotNull(clientBio = BIO_new_connect(connectAddr));
  62078. AssertIntEQ(BIO_do_connect(clientBio), 1);
  62079. AssertNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62080. AssertNotNull(sslClient = SSL_new(ctx));
  62081. AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), WOLFSSL_SUCCESS);
  62082. SSL_set_bio(sslClient, clientBio, clientBio);
  62083. AssertIntEQ(SSL_connect(sslClient), 1);
  62084. SSL_free(sslClient);
  62085. SSL_CTX_free(ctx);
  62086. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62087. wc_ecc_fp_free(); /* free per thread cache */
  62088. #endif
  62089. WOLFSSL_RETURN_FROM_THREAD(0);
  62090. }
  62091. #endif
  62092. static int test_wolfSSL_BIO_accept(void)
  62093. {
  62094. EXPECT_DECLS;
  62095. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62096. defined(HAVE_HTTP_CLIENT)
  62097. BIO* serverBindBio = NULL;
  62098. BIO* serverAcceptBio = NULL;
  62099. SSL* sslServer = NULL;
  62100. SSL_CTX* ctx = NULL;
  62101. func_args args;
  62102. THREAD_TYPE thread;
  62103. char port[10]; /* 10 bytes should be enough to store the string
  62104. * representation of the port */
  62105. ExpectIntGT(snprintf(port, sizeof(port), "%d", wolfSSLPort), 0);
  62106. ExpectNotNull(serverBindBio = BIO_new_accept(port));
  62107. /* First BIO_do_accept binds the port */
  62108. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62109. XMEMSET(&args, 0, sizeof(func_args));
  62110. start_thread(test_wolfSSL_BIO_accept_client, &args, &thread);
  62111. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62112. /* Let's plug it into SSL to test */
  62113. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62114. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  62115. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62116. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  62117. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62118. ExpectNotNull(sslServer = SSL_new(ctx));
  62119. ExpectNotNull(serverAcceptBio = BIO_pop(serverBindBio));
  62120. SSL_set_bio(sslServer, serverAcceptBio, serverAcceptBio);
  62121. ExpectIntEQ(SSL_accept(sslServer), 1);
  62122. join_thread(thread);
  62123. BIO_free(serverBindBio);
  62124. SSL_free(sslServer);
  62125. SSL_CTX_free(ctx);
  62126. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62127. wc_ecc_fp_free(); /* free per thread cache */
  62128. #endif
  62129. #endif
  62130. return EXPECT_RESULT();
  62131. }
  62132. static int test_wolfSSL_BIO_write(void)
  62133. {
  62134. EXPECT_DECLS;
  62135. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  62136. BIO* bio = NULL;
  62137. BIO* bio64 = NULL;
  62138. BIO* bio_mem = NULL;
  62139. BIO* ptr = NULL;
  62140. int sz;
  62141. char msg[] = "conversion test";
  62142. char out[40];
  62143. char expected[] = "Y29udmVyc2lvbiB0ZXN0AA==\n";
  62144. void* bufPtr = NULL;
  62145. BUF_MEM* buf = NULL;
  62146. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62147. ExpectNotNull(bio = BIO_push(bio64, BIO_new(BIO_s_mem())));
  62148. if (EXPECT_FAIL()) {
  62149. BIO_free(bio64);
  62150. }
  62151. /* now should convert to base64 then write to memory */
  62152. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62153. BIO_flush(bio);
  62154. /* test BIO chain */
  62155. ExpectIntEQ(SSL_SUCCESS, (int)BIO_get_mem_ptr(bio, &buf));
  62156. ExpectNotNull(buf);
  62157. ExpectIntEQ(buf->length, 25);
  62158. ExpectIntEQ(BIO_get_mem_data(bio, &bufPtr), 25);
  62159. ExpectPtrEq(buf->data, bufPtr);
  62160. ExpectNotNull(ptr = BIO_find_type(bio, BIO_TYPE_MEM));
  62161. sz = sizeof(out);
  62162. XMEMSET(out, 0, sz);
  62163. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 25);
  62164. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62165. /* write then read should return the same message */
  62166. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62167. sz = sizeof(out);
  62168. XMEMSET(out, 0, sz);
  62169. ExpectIntEQ(BIO_read(bio, out, sz), 16);
  62170. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62171. /* now try encoding with no line ending */
  62172. BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
  62173. #ifdef HAVE_EX_DATA
  62174. BIO_set_ex_data(bio64, 0, (void*) "data");
  62175. ExpectIntEQ(strcmp((const char*)BIO_get_ex_data(bio64, 0), "data"), 0);
  62176. #endif
  62177. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62178. BIO_flush(bio);
  62179. sz = sizeof(out);
  62180. XMEMSET(out, 0, sz);
  62181. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 24);
  62182. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62183. BIO_free_all(bio); /* frees bio64 also */
  62184. bio = NULL;
  62185. /* test with more than one bio64 in list */
  62186. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62187. ExpectNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
  62188. if (EXPECT_FAIL()) {
  62189. BIO_free(bio64);
  62190. bio64 = NULL;
  62191. }
  62192. ExpectNotNull(bio_mem = BIO_new(BIO_s_mem()));
  62193. ExpectNotNull(BIO_push(bio64, bio_mem));
  62194. if (EXPECT_FAIL()) {
  62195. BIO_free(bio_mem);
  62196. }
  62197. /* now should convert to base64 when stored and then decode with read */
  62198. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
  62199. BIO_flush(bio);
  62200. sz = sizeof(out);
  62201. XMEMSET(out, 0, sz);
  62202. ExpectIntEQ((sz = BIO_read(bio, out, sz)), 16);
  62203. ExpectIntEQ(XMEMCMP(out, msg, sz), 0);
  62204. BIO_clear_flags(bio64, ~0);
  62205. BIO_set_retry_read(bio);
  62206. BIO_free_all(bio); /* frees bio64s also */
  62207. bio = NULL;
  62208. ExpectNotNull(bio = BIO_new_mem_buf(out, 0));
  62209. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62210. BIO_free(bio);
  62211. #endif
  62212. return EXPECT_RESULT();
  62213. }
  62214. static int test_wolfSSL_BIO_printf(void)
  62215. {
  62216. EXPECT_DECLS;
  62217. #if defined(OPENSSL_ALL)
  62218. BIO* bio = NULL;
  62219. int sz = 7;
  62220. char msg[] = "TLS 1.3 for the world";
  62221. char out[60];
  62222. char expected[] = "TLS 1.3 for the world : sz = 7";
  62223. XMEMSET(out, 0, sizeof(out));
  62224. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62225. ExpectIntEQ(BIO_printf(bio, "%s : sz = %d", msg, sz), 30);
  62226. ExpectIntEQ(BIO_printf(NULL, ""), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62227. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 30);
  62228. ExpectIntEQ(XSTRNCMP(out, expected, sizeof(expected)), 0);
  62229. BIO_free(bio);
  62230. #endif
  62231. return EXPECT_RESULT();
  62232. }
  62233. static int test_wolfSSL_BIO_f_md(void)
  62234. {
  62235. EXPECT_DECLS;
  62236. #if defined(OPENSSL_ALL) && !defined(NO_SHA256)
  62237. BIO* bio = NULL;
  62238. BIO* mem = NULL;
  62239. char msg[] = "message to hash";
  62240. char out[60];
  62241. EVP_MD_CTX* ctx = NULL;
  62242. const unsigned char testKey[] =
  62243. {
  62244. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62245. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62246. 0x0b, 0x0b, 0x0b, 0x0b
  62247. };
  62248. const char testData[] = "Hi There";
  62249. const unsigned char testResult[] =
  62250. {
  62251. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  62252. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  62253. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  62254. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  62255. };
  62256. const unsigned char expectedHash[] =
  62257. {
  62258. 0x66, 0x49, 0x3C, 0xE8, 0x8A, 0x57, 0xB0, 0x60,
  62259. 0xDC, 0x55, 0x7D, 0xFC, 0x1F, 0xA5, 0xE5, 0x07,
  62260. 0x70, 0x5A, 0xF6, 0xD7, 0xC4, 0x1F, 0x1A, 0xE4,
  62261. 0x2D, 0xA6, 0xFD, 0xD1, 0x29, 0x7D, 0x60, 0x0D
  62262. };
  62263. const unsigned char emptyHash[] =
  62264. {
  62265. 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
  62266. 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
  62267. 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
  62268. 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55
  62269. };
  62270. unsigned char check[sizeof(testResult) + 1];
  62271. size_t checkSz = -1;
  62272. EVP_PKEY* key = NULL;
  62273. XMEMSET(out, 0, sizeof(out));
  62274. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62275. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62276. ExpectIntEQ(BIO_get_md_ctx(bio, &ctx), 1);
  62277. ExpectIntEQ(EVP_DigestInit(ctx, EVP_sha256()), 1);
  62278. /* should not be able to write/read yet since just digest wrapper and no
  62279. * data is passing through the bio */
  62280. ExpectIntEQ(BIO_write(bio, msg, 0), 0);
  62281. ExpectIntEQ(BIO_pending(bio), 0);
  62282. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 0);
  62283. ExpectIntEQ(BIO_gets(bio, out, 3), 0);
  62284. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62285. ExpectIntEQ(XMEMCMP(emptyHash, out, 32), 0);
  62286. BIO_reset(bio);
  62287. /* append BIO mem to bio in order to read/write */
  62288. ExpectNotNull(bio = BIO_push(bio, mem));
  62289. XMEMSET(out, 0, sizeof(out));
  62290. ExpectIntEQ(BIO_write(mem, msg, sizeof(msg)), 16);
  62291. ExpectIntEQ(BIO_pending(bio), 16);
  62292. /* this just reads the message and does not hash it (gets calls final) */
  62293. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 16);
  62294. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62295. /* create a message digest using BIO */
  62296. XMEMSET(out, 0, sizeof(out));
  62297. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 16);
  62298. ExpectIntEQ(BIO_pending(mem), 16);
  62299. ExpectIntEQ(BIO_pending(bio), 16);
  62300. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62301. ExpectIntEQ(XMEMCMP(expectedHash, out, 32), 0);
  62302. BIO_free(bio);
  62303. bio = NULL;
  62304. BIO_free(mem);
  62305. mem = NULL;
  62306. /* test with HMAC */
  62307. XMEMSET(out, 0, sizeof(out));
  62308. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62309. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62310. BIO_get_md_ctx(bio, &ctx);
  62311. ExpectNotNull(key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, testKey,
  62312. (int)sizeof(testKey)));
  62313. EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, key);
  62314. ExpectNotNull(bio = BIO_push(bio, mem));
  62315. BIO_write(bio, testData, (int)strlen(testData));
  62316. ExpectIntEQ(EVP_DigestSignFinal(ctx, NULL, &checkSz), 1);
  62317. ExpectIntEQ(EVP_DigestSignFinal(ctx, check, &checkSz), 1);
  62318. ExpectIntEQ(XMEMCMP(check, testResult, sizeof(testResult)), 0);
  62319. EVP_PKEY_free(key);
  62320. BIO_free(bio);
  62321. BIO_free(mem);
  62322. #endif
  62323. return EXPECT_RESULT();
  62324. }
  62325. static int test_wolfSSL_BIO_up_ref(void)
  62326. {
  62327. EXPECT_DECLS;
  62328. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62329. BIO* bio = NULL;
  62330. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62331. ExpectIntEQ(BIO_up_ref(NULL), 0);
  62332. ExpectIntEQ(BIO_up_ref(bio), 1);
  62333. BIO_free(bio);
  62334. ExpectIntEQ(BIO_up_ref(bio), 1);
  62335. BIO_free(bio);
  62336. BIO_free(bio);
  62337. #endif
  62338. return EXPECT_RESULT();
  62339. }
  62340. static int test_wolfSSL_BIO_reset(void)
  62341. {
  62342. EXPECT_DECLS;
  62343. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62344. BIO* bio = NULL;
  62345. byte buf[16];
  62346. ExpectNotNull(bio = BIO_new_mem_buf("secure your data",
  62347. (word32)XSTRLEN("secure your data")));
  62348. ExpectIntEQ(BIO_read(bio, buf, 6), 6);
  62349. ExpectIntEQ(XMEMCMP(buf, "secure", 6), 0);
  62350. XMEMSET(buf, 0, 16);
  62351. ExpectIntEQ(BIO_read(bio, buf, 16), 10);
  62352. ExpectIntEQ(XMEMCMP(buf, " your data", 10), 0);
  62353. /* You cannot write to MEM BIO with read-only mode. */
  62354. ExpectIntEQ(BIO_write(bio, "WriteToReadonly", 15), 0);
  62355. ExpectIntEQ(BIO_read(bio, buf, 16), -1);
  62356. XMEMSET(buf, 0, 16);
  62357. ExpectIntEQ(BIO_reset(bio), 1);
  62358. ExpectIntEQ(BIO_read(bio, buf, 16), 16);
  62359. ExpectIntEQ(XMEMCMP(buf, "secure your data", 16), 0);
  62360. BIO_free(bio);
  62361. #endif
  62362. return EXPECT_RESULT();
  62363. }
  62364. #endif /* !NO_BIO */
  62365. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62366. /* test that the callback arg is correct */
  62367. static int certCbArg = 0;
  62368. static int certCb(WOLFSSL* ssl, void* arg)
  62369. {
  62370. if (ssl == NULL || arg != &certCbArg)
  62371. return 0;
  62372. if (wolfSSL_is_server(ssl)) {
  62373. if (wolfSSL_use_certificate_file(ssl, svrCertFile,
  62374. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62375. return 0;
  62376. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  62377. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62378. return 0;
  62379. }
  62380. else {
  62381. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  62382. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62383. return 0;
  62384. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  62385. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62386. return 0;
  62387. }
  62388. return 1;
  62389. }
  62390. static int certSetupCb(WOLFSSL_CTX* ctx)
  62391. {
  62392. SSL_CTX_set_cert_cb(ctx, certCb, &certCbArg);
  62393. return TEST_SUCCESS;
  62394. }
  62395. /**
  62396. * This is only done because test_wolfSSL_client_server_nofail_memio has no way
  62397. * to stop certificate and key loading
  62398. */
  62399. static int certClearCb(WOLFSSL* ssl)
  62400. {
  62401. /* Clear the loaded certs to force the callbacks to set them up */
  62402. SSL_certs_clear(ssl);
  62403. return TEST_SUCCESS;
  62404. }
  62405. #endif
  62406. static int test_wolfSSL_cert_cb(void)
  62407. {
  62408. EXPECT_DECLS;
  62409. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62410. test_ssl_cbf func_cb_client;
  62411. test_ssl_cbf func_cb_server;
  62412. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  62413. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  62414. func_cb_client.ctx_ready = certSetupCb;
  62415. func_cb_client.ssl_ready = certClearCb;
  62416. func_cb_server.ctx_ready = certSetupCb;
  62417. func_cb_server.ssl_ready = certClearCb;
  62418. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  62419. &func_cb_server, NULL), TEST_SUCCESS);
  62420. #endif
  62421. return EXPECT_RESULT();
  62422. }
  62423. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62424. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_cipher = NULL;
  62425. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs = NULL;
  62426. static int test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready(WOLFSSL_CTX* ctx)
  62427. {
  62428. EXPECT_DECLS;
  62429. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx,
  62430. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher), WOLFSSL_SUCCESS);
  62431. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  62432. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs), WOLFSSL_SUCCESS);
  62433. return EXPECT_RESULT();
  62434. }
  62435. static int test_wolfSSL_cert_cb_dyn_ciphers_certCB(WOLFSSL* ssl, void* arg)
  62436. {
  62437. const byte* suites = NULL;
  62438. word16 suiteSz = 0;
  62439. const byte* hashSigAlgo = NULL;
  62440. word16 hashSigAlgoSz = 0;
  62441. word16 idx = 0;
  62442. int haveRSA = 0;
  62443. int haveECC = 0;
  62444. (void)arg;
  62445. if (wolfSSL_get_client_suites_sigalgs(ssl, &suites, &suiteSz, &hashSigAlgo,
  62446. &hashSigAlgoSz) != WOLFSSL_SUCCESS)
  62447. return 0;
  62448. if (suites == NULL || suiteSz == 0 || hashSigAlgo == NULL ||
  62449. hashSigAlgoSz == 0)
  62450. return 0;
  62451. for (idx = 0; idx < suiteSz; idx += 2) {
  62452. WOLFSSL_CIPHERSUITE_INFO info =
  62453. wolfSSL_get_ciphersuite_info(suites[idx], suites[idx+1]);
  62454. if (info.rsaAuth)
  62455. haveRSA = 1;
  62456. else if (info.eccAuth)
  62457. haveECC = 1;
  62458. }
  62459. if (hashSigAlgoSz > 0) {
  62460. /* sigalgs extension takes precedence over ciphersuites */
  62461. haveRSA = 0;
  62462. haveECC = 0;
  62463. }
  62464. for (idx = 0; idx < hashSigAlgoSz; idx += 2) {
  62465. int hashAlgo = 0;
  62466. int sigAlgo = 0;
  62467. if (wolfSSL_get_sigalg_info(hashSigAlgo[idx+0], hashSigAlgo[idx+1],
  62468. &hashAlgo, &sigAlgo) != 0)
  62469. return 0;
  62470. if (sigAlgo == RSAk || sigAlgo == RSAPSSk)
  62471. haveRSA = 1;
  62472. else if (sigAlgo == ECDSAk)
  62473. haveECC = 1;
  62474. }
  62475. if (haveRSA) {
  62476. if (wolfSSL_use_certificate_file(ssl, svrCertFile, WOLFSSL_FILETYPE_PEM)
  62477. != WOLFSSL_SUCCESS)
  62478. return 0;
  62479. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile, WOLFSSL_FILETYPE_PEM)
  62480. != WOLFSSL_SUCCESS)
  62481. return 0;
  62482. }
  62483. else if (haveECC) {
  62484. if (wolfSSL_use_certificate_file(ssl, eccCertFile, WOLFSSL_FILETYPE_PEM)
  62485. != WOLFSSL_SUCCESS)
  62486. return 0;
  62487. if (wolfSSL_use_PrivateKey_file(ssl, eccKeyFile, WOLFSSL_FILETYPE_PEM)
  62488. != WOLFSSL_SUCCESS)
  62489. return 0;
  62490. }
  62491. return 1;
  62492. }
  62493. static int test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready(WOLFSSL_CTX* ctx)
  62494. {
  62495. SSL_CTX_set_cert_cb(ctx, test_wolfSSL_cert_cb_dyn_ciphers_certCB, NULL);
  62496. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
  62497. return TEST_SUCCESS;
  62498. }
  62499. #endif
  62500. /* Testing dynamic ciphers offered by client */
  62501. static int test_wolfSSL_cert_cb_dyn_ciphers(void)
  62502. {
  62503. EXPECT_DECLS;
  62504. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62505. test_ssl_cbf func_cb_client;
  62506. test_ssl_cbf func_cb_server;
  62507. struct {
  62508. method_provider client_meth;
  62509. const char* client_ciphers;
  62510. const char* client_sigalgs;
  62511. const char* client_ca;
  62512. method_provider server_meth;
  62513. } test_params[] = {
  62514. #if !defined(NO_SHA256) && defined(HAVE_AESGCM)
  62515. #ifdef WOLFSSL_TLS13
  62516. #if !defined(NO_RSA) && defined(WC_RSA_PSS)
  62517. {wolfTLSv1_3_client_method,
  62518. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  62519. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_3_server_method},
  62520. #endif
  62521. #ifdef HAVE_ECC
  62522. {wolfTLSv1_3_client_method,
  62523. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  62524. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_3_server_method},
  62525. #endif
  62526. #endif
  62527. #ifndef WOLFSSL_NO_TLS12
  62528. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_DH)
  62529. {wolfTLSv1_2_client_method,
  62530. "DHE-RSA-AES128-GCM-SHA256",
  62531. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_2_server_method},
  62532. #endif
  62533. #ifdef HAVE_ECC
  62534. {wolfTLSv1_2_client_method,
  62535. "ECDHE-ECDSA-AES128-GCM-SHA256",
  62536. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_2_server_method},
  62537. #endif
  62538. #endif
  62539. #endif
  62540. };
  62541. size_t i;
  62542. size_t testCount = sizeof(test_params)/sizeof(*test_params);
  62543. if (testCount > 0) {
  62544. for (i = 0; i < testCount; i++) {
  62545. printf("\tTesting %s ciphers with %s sigalgs\n",
  62546. test_params[i].client_ciphers,
  62547. test_params[i].client_sigalgs);
  62548. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  62549. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  62550. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher =
  62551. test_params[i].client_ciphers;
  62552. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs =
  62553. test_params[i].client_sigalgs;
  62554. func_cb_client.method = test_params[i].client_meth;
  62555. func_cb_client.caPemFile = test_params[i].client_ca;
  62556. func_cb_client.ctx_ready =
  62557. test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready;
  62558. func_cb_server.ctx_ready =
  62559. test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready;
  62560. func_cb_server.ssl_ready = certClearCb; /* Reuse from prev test */
  62561. func_cb_server.method = test_params[i].server_meth;
  62562. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  62563. &func_cb_server, NULL), TEST_SUCCESS);
  62564. }
  62565. }
  62566. #endif
  62567. return EXPECT_RESULT();
  62568. }
  62569. static int test_wolfSSL_ciphersuite_auth(void)
  62570. {
  62571. EXPECT_DECLS;
  62572. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  62573. WOLFSSL_CIPHERSUITE_INFO info;
  62574. (void)info;
  62575. #ifndef WOLFSSL_NO_TLS12
  62576. #ifdef HAVE_CHACHA
  62577. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  62578. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
  62579. ExpectIntEQ(info.rsaAuth, 1);
  62580. ExpectIntEQ(info.eccAuth, 0);
  62581. ExpectIntEQ(info.eccStatic, 0);
  62582. ExpectIntEQ(info.psk, 0);
  62583. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  62584. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
  62585. ExpectIntEQ(info.rsaAuth, 0);
  62586. ExpectIntEQ(info.eccAuth, 1);
  62587. ExpectIntEQ(info.eccStatic, 0);
  62588. ExpectIntEQ(info.psk, 0);
  62589. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  62590. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256);
  62591. ExpectIntEQ(info.rsaAuth, 0);
  62592. ExpectIntEQ(info.eccAuth, 0);
  62593. ExpectIntEQ(info.eccStatic, 0);
  62594. ExpectIntEQ(info.psk, 1);
  62595. #endif
  62596. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  62597. #ifndef NO_RSA
  62598. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62599. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA);
  62600. ExpectIntEQ(info.rsaAuth, 1);
  62601. ExpectIntEQ(info.eccAuth, 0);
  62602. ExpectIntEQ(info.eccStatic, 0);
  62603. ExpectIntEQ(info.psk, 0);
  62604. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62605. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA);
  62606. ExpectIntEQ(info.rsaAuth, 1);
  62607. ExpectIntEQ(info.eccAuth, 0);
  62608. ExpectIntEQ(info.eccStatic, 1);
  62609. ExpectIntEQ(info.psk, 0);
  62610. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62611. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA);
  62612. ExpectIntEQ(info.rsaAuth, 1);
  62613. ExpectIntEQ(info.eccAuth, 0);
  62614. ExpectIntEQ(info.eccStatic, 1);
  62615. ExpectIntEQ(info.psk, 0);
  62616. #endif
  62617. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62618. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
  62619. ExpectIntEQ(info.rsaAuth, 0);
  62620. ExpectIntEQ(info.eccAuth, 1);
  62621. ExpectIntEQ(info.eccStatic, 0);
  62622. ExpectIntEQ(info.psk, 0);
  62623. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62624. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA);
  62625. ExpectIntEQ(info.rsaAuth, 0);
  62626. ExpectIntEQ(info.eccAuth, 1);
  62627. ExpectIntEQ(info.eccStatic, 1);
  62628. ExpectIntEQ(info.psk, 0);
  62629. info = wolfSSL_get_ciphersuite_info(ECDHE_PSK_BYTE,
  62630. TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256);
  62631. ExpectIntEQ(info.rsaAuth, 0);
  62632. ExpectIntEQ(info.eccAuth, 0);
  62633. ExpectIntEQ(info.eccStatic, 0);
  62634. ExpectIntEQ(info.psk, 1);
  62635. #endif
  62636. #endif
  62637. #ifdef WOLFSSL_TLS13
  62638. info = wolfSSL_get_ciphersuite_info(TLS13_BYTE,
  62639. TLS_AES_128_GCM_SHA256);
  62640. ExpectIntEQ(info.rsaAuth, 0);
  62641. ExpectIntEQ(info.eccAuth, 0);
  62642. ExpectIntEQ(info.eccStatic, 0);
  62643. ExpectIntEQ(info.psk, 0);
  62644. #endif
  62645. #endif
  62646. return EXPECT_RESULT();
  62647. }
  62648. static int test_wolfSSL_sigalg_info(void)
  62649. {
  62650. EXPECT_DECLS;
  62651. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  62652. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO];
  62653. word16 len = 0;
  62654. word16 idx = 0;
  62655. int allSigAlgs = SIG_ECDSA | SIG_RSA | SIG_SM2 | SIG_FALCON | SIG_DILITHIUM;
  62656. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs, 1, 0xFFFFFFFF, &len);
  62657. for (idx = 0; idx < len; idx += 2) {
  62658. int hashAlgo = 0;
  62659. int sigAlgo = 0;
  62660. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  62661. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  62662. ExpectIntNE(hashAlgo, 0);
  62663. ExpectIntNE(sigAlgo, 0);
  62664. }
  62665. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs | SIG_ANON, 1,
  62666. 0xFFFFFFFF, &len);
  62667. for (idx = 0; idx < len; idx += 2) {
  62668. int hashAlgo = 0;
  62669. int sigAlgo = 0;
  62670. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  62671. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  62672. ExpectIntNE(hashAlgo, 0);
  62673. }
  62674. #endif
  62675. return EXPECT_RESULT();
  62676. }
  62677. static int test_wolfSSL_SESSION(void)
  62678. {
  62679. EXPECT_DECLS;
  62680. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62681. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62682. !defined(NO_SESSION_CACHE)
  62683. WOLFSSL* ssl = NULL;
  62684. WOLFSSL_CTX* ctx = NULL;
  62685. WOLFSSL_SESSION* sess = NULL;
  62686. WOLFSSL_SESSION* sess_copy = NULL;
  62687. #ifdef OPENSSL_EXTRA
  62688. #ifdef HAVE_EXT_CACHE
  62689. unsigned char* sessDer = NULL;
  62690. unsigned char* ptr = NULL;
  62691. int sz = 0;
  62692. #endif
  62693. const unsigned char context[] = "user app context";
  62694. unsigned int contextSz = (unsigned int)sizeof(context);
  62695. #endif
  62696. int ret = 0, err = 0;
  62697. SOCKET_T sockfd;
  62698. tcp_ready ready;
  62699. func_args server_args;
  62700. THREAD_TYPE serverThread;
  62701. char msg[80];
  62702. const char* sendGET = "GET";
  62703. /* TLS v1.3 requires session tickets */
  62704. /* CHACHA and POLY1305 required for myTicketEncCb */
  62705. #if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \
  62706. !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \
  62707. defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))))
  62708. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  62709. #else
  62710. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  62711. #endif
  62712. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  62713. WOLFSSL_FILETYPE_PEM));
  62714. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  62715. WOLFSSL_FILETYPE_PEM));
  62716. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  62717. WOLFSSL_SUCCESS);
  62718. #ifdef WOLFSSL_ENCRYPTED_KEYS
  62719. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  62720. #endif
  62721. #ifdef HAVE_SESSION_TICKET
  62722. /* Use session tickets, for ticket tests below */
  62723. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  62724. #endif
  62725. XMEMSET(&server_args, 0, sizeof(func_args));
  62726. #ifdef WOLFSSL_TIRTOS
  62727. fdOpenSession(Task_self());
  62728. #endif
  62729. StartTCP();
  62730. InitTcpReady(&ready);
  62731. #if defined(USE_WINDOWS_API)
  62732. /* use RNG to get random port if using windows */
  62733. ready.port = GetRandomPort();
  62734. #endif
  62735. server_args.signal = &ready;
  62736. start_thread(test_server_nofail, &server_args, &serverThread);
  62737. wait_tcp_ready(&server_args);
  62738. /* client connection */
  62739. ExpectNotNull(ssl = wolfSSL_new(ctx));
  62740. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  62741. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  62742. #ifdef WOLFSSL_ASYNC_CRYPT
  62743. err = 0; /* Reset error */
  62744. #endif
  62745. do {
  62746. #ifdef WOLFSSL_ASYNC_CRYPT
  62747. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62748. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62749. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62750. }
  62751. #endif
  62752. ret = wolfSSL_connect(ssl);
  62753. err = wolfSSL_get_error(ssl, 0);
  62754. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62755. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62756. #ifdef WOLFSSL_ASYNC_CRYPT
  62757. err = 0; /* Reset error */
  62758. #endif
  62759. do {
  62760. #ifdef WOLFSSL_ASYNC_CRYPT
  62761. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62762. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62763. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62764. }
  62765. #endif
  62766. ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET));
  62767. err = wolfSSL_get_error(ssl, 0);
  62768. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62769. ExpectIntEQ(ret, (int)XSTRLEN(sendGET));
  62770. #ifdef WOLFSSL_ASYNC_CRYPT
  62771. err = 0; /* Reset error */
  62772. #endif
  62773. do {
  62774. #ifdef WOLFSSL_ASYNC_CRYPT
  62775. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62776. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62777. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62778. }
  62779. #endif
  62780. ret = wolfSSL_read(ssl, msg, sizeof(msg));
  62781. err = wolfSSL_get_error(ssl, 0);
  62782. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62783. ExpectIntEQ(ret, 23);
  62784. ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */
  62785. ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */
  62786. ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1);
  62787. #ifdef HAVE_EXT_CACHE
  62788. ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without
  62789. * HAVE_EXT_CACHE we get new objects each time */
  62790. #endif
  62791. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  62792. wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */
  62793. sess = wolfSSL_get_session(ssl);
  62794. #ifdef OPENSSL_EXTRA
  62795. ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0);
  62796. ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1);
  62797. ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0);
  62798. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0);
  62799. #ifdef HAVE_SESSION_TICKET
  62800. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1);
  62801. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess),
  62802. SESSION_TICKET_HINT_DEFAULT);
  62803. #else
  62804. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0);
  62805. #endif
  62806. #else
  62807. (void)sess;
  62808. #endif /* OPENSSL_EXTRA */
  62809. /* Retain copy of the session for later testing */
  62810. ExpectNotNull(sess = wolfSSL_get1_session(ssl));
  62811. wolfSSL_shutdown(ssl);
  62812. wolfSSL_free(ssl); ssl = NULL;
  62813. CloseSocket(sockfd);
  62814. join_thread(serverThread);
  62815. FreeTcpReady(&ready);
  62816. #ifdef WOLFSSL_TIRTOS
  62817. fdOpenSession(Task_self());
  62818. #endif
  62819. #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
  62820. {
  62821. X509 *x509 = NULL;
  62822. char buf[30];
  62823. int bufSz = 0;
  62824. ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess));
  62825. ExpectIntGT((bufSz = X509_NAME_get_text_by_NID(
  62826. X509_get_subject_name(x509), NID_organizationalUnitName, buf,
  62827. sizeof(buf))), 0);
  62828. ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/
  62829. if (bufSz == 7) {
  62830. ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0);
  62831. }
  62832. if (bufSz == 16) {
  62833. ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0);
  62834. }
  62835. }
  62836. #endif
  62837. #ifdef HAVE_EXT_CACHE
  62838. ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess));
  62839. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  62840. sess_copy = NULL;
  62841. #endif
  62842. #if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE)
  62843. /* get session from DER and update the timeout */
  62844. ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  62845. ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0);
  62846. wolfSSL_SESSION_free(sess); sess = NULL;
  62847. sess = NULL;
  62848. ptr = sessDer;
  62849. ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz));
  62850. ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL,
  62851. (const unsigned char**)&ptr, sz));
  62852. XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL);
  62853. sessDer = NULL;
  62854. ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0);
  62855. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  62856. #endif
  62857. /* successful set session test */
  62858. ExpectNotNull(ssl = wolfSSL_new(ctx));
  62859. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  62860. #ifdef HAVE_SESSION_TICKET
  62861. /* Test set/get session ticket */
  62862. {
  62863. const char* ticket = "This is a session ticket";
  62864. char buf[64] = {0};
  62865. word32 bufSz = (word32)sizeof(buf);
  62866. ExpectIntEQ(SSL_SUCCESS,
  62867. wolfSSL_set_SessionTicket(ssl, (byte *)ticket,
  62868. (word32)XSTRLEN(ticket)));
  62869. ExpectIntEQ(SSL_SUCCESS,
  62870. wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz));
  62871. ExpectStrEQ(ticket, buf);
  62872. }
  62873. #endif
  62874. #ifdef OPENSSL_EXTRA
  62875. /* session timeout case */
  62876. /* make the session to be expired */
  62877. ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS);
  62878. XSLEEP_MS(1200);
  62879. /* SSL_set_session should reject specified session but return success
  62880. * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility.
  62881. */
  62882. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  62883. ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS);
  62884. #else
  62885. ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62886. #endif
  62887. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  62888. #ifdef WOLFSSL_SESSION_ID_CTX
  62889. /* fail case with miss match session context IDs (use compatibility API) */
  62890. ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz),
  62891. SSL_SUCCESS);
  62892. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62893. wolfSSL_free(ssl); ssl = NULL;
  62894. ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz),
  62895. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62896. ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz),
  62897. SSL_SUCCESS);
  62898. ExpectNotNull(ssl = wolfSSL_new(ctx));
  62899. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62900. #endif
  62901. #endif /* OPENSSL_EXTRA */
  62902. wolfSSL_free(ssl);
  62903. wolfSSL_SESSION_free(sess);
  62904. wolfSSL_CTX_free(ctx);
  62905. #endif
  62906. return EXPECT_RESULT();
  62907. }
  62908. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62909. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62910. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  62911. !defined(WOLFSSL_NO_TLS12)
  62912. static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL;
  62913. static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  62914. {
  62915. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  62916. /* returns previous timeout value */
  62917. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500);
  62918. #else
  62919. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS);
  62920. #endif
  62921. }
  62922. /* set the session to timeout in a second */
  62923. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl)
  62924. {
  62925. AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1);
  62926. }
  62927. /* store the client side session from the first successful connection */
  62928. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl)
  62929. {
  62930. AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)),
  62931. NULL); /* ref count 1 */
  62932. }
  62933. /* wait till session is expired then set it in the WOLFSSL struct for use */
  62934. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl)
  62935. {
  62936. AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1);
  62937. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  62938. WOLFSSL_SUCCESS);
  62939. XSLEEP_MS(2000); /* wait 2 seconds for session to expire */
  62940. }
  62941. /* set expired session in the WOLFSSL struct for use */
  62942. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl)
  62943. {
  62944. XSLEEP_MS(1200); /* wait a second for session to expire */
  62945. /* set the expired session, call to set session fails but continuing on
  62946. after failure should be handled here */
  62947. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL)
  62948. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  62949. WOLFSSL_SUCCESS);
  62950. #else
  62951. AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  62952. WOLFSSL_SUCCESS);
  62953. #endif
  62954. }
  62955. /* check that the expired session was not reused */
  62956. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl)
  62957. {
  62958. /* since the session has expired it should not have been reused */
  62959. AssertIntEQ(wolfSSL_session_reused(ssl), 0);
  62960. }
  62961. #endif
  62962. static int test_wolfSSL_SESSION_expire_downgrade(void)
  62963. {
  62964. EXPECT_DECLS;
  62965. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62966. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62967. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  62968. !defined(WOLFSSL_NO_TLS12)
  62969. WOLFSSL_CTX* ctx = NULL;
  62970. callback_functions server_cbf, client_cbf;
  62971. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  62972. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  62973. /* force server side to use TLS 1.2 */
  62974. server_cbf.ctx = ctx;
  62975. server_cbf.method = wolfTLSv1_2_server_method;
  62976. client_cbf.method = wolfSSLv23_client_method;
  62977. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  62978. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready;
  62979. client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result;
  62980. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  62981. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  62982. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  62983. /* set the previously created session and wait till expired */
  62984. server_cbf.ctx = ctx;
  62985. client_cbf.method = wolfSSLv23_client_method;
  62986. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  62987. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait;
  62988. client_cbf.on_result =
  62989. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  62990. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  62991. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  62992. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  62993. /* set the previously created expired session */
  62994. server_cbf.ctx = ctx;
  62995. client_cbf.method = wolfSSLv23_client_method;
  62996. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  62997. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set;
  62998. client_cbf.on_result =
  62999. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  63000. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63001. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63002. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63003. wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess);
  63004. wolfSSL_CTX_free(ctx);
  63005. #endif
  63006. return EXPECT_RESULT();
  63007. }
  63008. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63009. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63010. static int clientSessRemCountMalloc = 0;
  63011. static int serverSessRemCountMalloc = 0;
  63012. static int clientSessRemCountFree = 0;
  63013. static int serverSessRemCountFree = 0;
  63014. static WOLFSSL_CTX* serverSessCtx = NULL;
  63015. static WOLFSSL_SESSION* serverSess = NULL;
  63016. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63017. !defined(NO_SESSION_CACHE_REF)
  63018. static WOLFSSL_CTX* clientSessCtx = NULL;
  63019. static WOLFSSL_SESSION* clientSess = NULL;
  63020. #endif
  63021. static int serverSessRemIdx = 3;
  63022. static int sessRemCtx_Server = WOLFSSL_SERVER_END;
  63023. static int sessRemCtx_Client = WOLFSSL_CLIENT_END;
  63024. static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  63025. {
  63026. int* side;
  63027. (void)ctx;
  63028. side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx);
  63029. if (side != NULL) {
  63030. if (*side == WOLFSSL_CLIENT_END)
  63031. clientSessRemCountFree++;
  63032. else
  63033. serverSessRemCountFree++;
  63034. SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL);
  63035. }
  63036. }
  63037. static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx)
  63038. {
  63039. SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb);
  63040. #if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \
  63041. !defined(NO_SESSION_CACHE_REF)
  63042. {
  63043. EXPECT_DECLS;
  63044. /* Allow downgrade, set min version, and disable TLS 1.3.
  63045. * Do this because without NO_SESSION_CACHE_REF we will want to return a
  63046. * reference to the session cache. But with WOLFSSL_TLS13 and without
  63047. * HAVE_SESSION_TICKET we won't have a session ID to be able to place
  63048. * the session in the cache. In this case we need to downgrade to
  63049. * previous versions to just use the legacy session ID field. */
  63050. ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  63051. SSL_SUCCESS);
  63052. ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  63053. SSL_SUCCESS);
  63054. return EXPECT_RESULT();
  63055. }
  63056. #else
  63057. return TEST_SUCCESS;
  63058. #endif
  63059. }
  63060. static int SessRemSslSetupCb(WOLFSSL* ssl)
  63061. {
  63062. EXPECT_DECLS;
  63063. int* side;
  63064. if (SSL_is_server(ssl)) {
  63065. side = &sessRemCtx_Server;
  63066. serverSessRemCountMalloc++;
  63067. ExpectNotNull(serverSess = SSL_get1_session(ssl));
  63068. ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)),
  63069. SSL_SUCCESS);
  63070. }
  63071. else {
  63072. side = &sessRemCtx_Client;
  63073. clientSessRemCountMalloc++;
  63074. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63075. !defined(NO_SESSION_CACHE_REF)
  63076. ExpectNotNull(clientSess = SSL_get1_session(ssl));
  63077. ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)),
  63078. SSL_SUCCESS);
  63079. #endif
  63080. }
  63081. ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl),
  63082. serverSessRemIdx, side), SSL_SUCCESS);
  63083. return EXPECT_RESULT();
  63084. }
  63085. #endif
  63086. static int test_wolfSSL_CTX_sess_set_remove_cb(void)
  63087. {
  63088. EXPECT_DECLS;
  63089. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63090. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63091. /* Check that the remove callback gets called for external data in a
  63092. * session object */
  63093. test_ssl_cbf func_cb;
  63094. XMEMSET(&func_cb, 0, sizeof(func_cb));
  63095. func_cb.ctx_ready = SessRemCtxSetupCb;
  63096. func_cb.on_result = SessRemSslSetupCb;
  63097. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb,
  63098. NULL), TEST_SUCCESS);
  63099. /* Both should have been allocated */
  63100. ExpectIntEQ(clientSessRemCountMalloc, 1);
  63101. ExpectIntEQ(serverSessRemCountMalloc, 1);
  63102. /* This should not be called yet. Session wasn't evicted from cache yet. */
  63103. ExpectIntEQ(clientSessRemCountFree, 0);
  63104. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63105. !defined(NO_SESSION_CACHE_REF)
  63106. /* Force a cache lookup */
  63107. ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63108. /* Force a cache update */
  63109. ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0));
  63110. /* This should set the timeout to 0 and call the remove callback from within
  63111. * the session cache. */
  63112. ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 0);
  63113. ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63114. ExpectIntEQ(clientSessRemCountFree, 1);
  63115. #endif
  63116. /* Server session is in the cache so ex_data isn't free'd with the SSL
  63117. * object */
  63118. ExpectIntEQ(serverSessRemCountFree, 0);
  63119. /* Force a cache lookup */
  63120. ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63121. /* Force a cache update */
  63122. ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0));
  63123. /* This should set the timeout to 0 and call the remove callback from within
  63124. * the session cache. */
  63125. ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
  63126. ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63127. ExpectIntEQ(serverSessRemCountFree, 1);
  63128. /* Need to free the references that we kept */
  63129. SSL_CTX_free(serverSessCtx);
  63130. SSL_SESSION_free(serverSess);
  63131. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63132. !defined(NO_SESSION_CACHE_REF)
  63133. SSL_CTX_free(clientSessCtx);
  63134. SSL_SESSION_free(clientSess);
  63135. #endif
  63136. #endif
  63137. return EXPECT_RESULT();
  63138. }
  63139. static int test_wolfSSL_ticket_keys(void)
  63140. {
  63141. EXPECT_DECLS;
  63142. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  63143. !defined(NO_WOLFSSL_SERVER)
  63144. WOLFSSL_CTX* ctx = NULL;
  63145. byte keys[WOLFSSL_TICKET_KEYS_SZ];
  63146. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  63147. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0),
  63148. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63149. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0),
  63150. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63151. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0),
  63152. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63153. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0),
  63154. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63155. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63156. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63157. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63158. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63159. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63160. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63161. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0),
  63162. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63163. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0),
  63164. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63165. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0),
  63166. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63167. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0),
  63168. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63169. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63170. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63171. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63172. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63173. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63174. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63175. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63176. WOLFSSL_SUCCESS);
  63177. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63178. WOLFSSL_SUCCESS);
  63179. wolfSSL_CTX_free(ctx);
  63180. #endif
  63181. return EXPECT_RESULT();
  63182. }
  63183. #ifndef NO_BIO
  63184. static int test_wolfSSL_d2i_PUBKEY(void)
  63185. {
  63186. EXPECT_DECLS;
  63187. #if defined(OPENSSL_EXTRA)
  63188. BIO* bio = NULL;
  63189. EVP_PKEY* pkey = NULL;
  63190. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63191. ExpectNull(d2i_PUBKEY_bio(NULL, NULL));
  63192. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  63193. /* RSA PUBKEY test */
  63194. ExpectIntGT(BIO_write(bio, client_keypub_der_2048,
  63195. sizeof_client_keypub_der_2048), 0);
  63196. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63197. EVP_PKEY_free(pkey);
  63198. pkey = NULL;
  63199. #endif
  63200. #if defined(USE_CERT_BUFFERS_256) && defined(HAVE_ECC)
  63201. /* ECC PUBKEY test */
  63202. ExpectIntGT(BIO_write(bio, ecc_clikeypub_der_256,
  63203. sizeof_ecc_clikeypub_der_256), 0);
  63204. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63205. EVP_PKEY_free(pkey);
  63206. pkey = NULL;
  63207. #endif
  63208. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DSA)
  63209. /* DSA PUBKEY test */
  63210. ExpectIntGT(BIO_write(bio, dsa_pub_key_der_2048,
  63211. sizeof_dsa_pub_key_der_2048), 0);
  63212. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63213. EVP_PKEY_free(pkey);
  63214. pkey = NULL;
  63215. #endif
  63216. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DH) && \
  63217. defined(OPENSSL_EXTRA) && defined(WOLFSSL_DH_EXTRA)
  63218. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  63219. (HAVE_FIPS_VERSION > 2))
  63220. /* DH PUBKEY test */
  63221. ExpectIntGT(BIO_write(bio, dh_pub_key_der_2048,
  63222. sizeof_dh_pub_key_der_2048), 0);
  63223. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63224. EVP_PKEY_free(pkey);
  63225. pkey = NULL;
  63226. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  63227. #endif /* USE_CERT_BUFFERS_2048 && !NO_DH && && OPENSSL_EXTRA */
  63228. BIO_free(bio);
  63229. (void)pkey;
  63230. #endif
  63231. return EXPECT_RESULT();
  63232. }
  63233. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  63234. static int test_wolfSSL_d2i_PrivateKeys_bio(void)
  63235. {
  63236. EXPECT_DECLS;
  63237. BIO* bio = NULL;
  63238. EVP_PKEY* pkey = NULL;
  63239. WOLFSSL_CTX* ctx = NULL;
  63240. #if defined(WOLFSSL_KEY_GEN)
  63241. unsigned char buff[4096];
  63242. unsigned char* bufPtr = buff;
  63243. #endif
  63244. /* test creating new EVP_PKEY with bad arg */
  63245. ExpectNull((pkey = d2i_PrivateKey_bio(NULL, NULL)));
  63246. /* test loading RSA key using BIO */
  63247. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  63248. {
  63249. XFILE file = XBADFILE;
  63250. const char* fname = "./certs/server-key.der";
  63251. size_t sz = 0;
  63252. byte* buf = NULL;
  63253. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63254. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63255. ExpectTrue((sz = XFTELL(file)) != 0);
  63256. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63257. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63258. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63259. if (file != XBADFILE) {
  63260. XFCLOSE(file);
  63261. }
  63262. /* Test using BIO new mem and loading DER private key */
  63263. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63264. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63265. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63266. BIO_free(bio);
  63267. bio = NULL;
  63268. EVP_PKEY_free(pkey);
  63269. pkey = NULL;
  63270. }
  63271. #endif
  63272. /* test loading ECC key using BIO */
  63273. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  63274. {
  63275. XFILE file = XBADFILE;
  63276. const char* fname = "./certs/ecc-key.der";
  63277. size_t sz = 0;
  63278. byte* buf = NULL;
  63279. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63280. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63281. ExpectTrue((sz = XFTELL(file)) != 0);
  63282. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63283. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63284. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63285. if (file != XBADFILE)
  63286. XFCLOSE(file);
  63287. /* Test using BIO new mem and loading DER private key */
  63288. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63289. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63290. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63291. BIO_free(bio);
  63292. bio = NULL;
  63293. EVP_PKEY_free(pkey);
  63294. pkey = NULL;
  63295. }
  63296. #endif
  63297. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63298. #ifndef NO_WOLFSSL_SERVER
  63299. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  63300. #else
  63301. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  63302. #endif
  63303. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  63304. {
  63305. RSA* rsa = NULL;
  63306. /* Tests bad parameters */
  63307. ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
  63308. /* RSA not set yet, expecting to fail*/
  63309. rsa = wolfSSL_RSA_new();
  63310. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63311. wolfSSL_RSA_free(rsa);
  63312. rsa = NULL;
  63313. #if defined(USE_CERT_BUFFERS_2048) && defined(WOLFSSL_KEY_GEN)
  63314. /* set RSA using bio*/
  63315. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63316. sizeof_client_key_der_2048), 0);
  63317. ExpectNotNull(d2i_RSAPrivateKey_bio(bio, &rsa));
  63318. ExpectNotNull(rsa);
  63319. /* Tests bad parameters */
  63320. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63321. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63322. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, rsa), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63323. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS);
  63324. /* i2d RSAprivate key tests */
  63325. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63326. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192);
  63327. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63328. sizeof_client_key_der_2048);
  63329. bufPtr -= sizeof_client_key_der_2048;
  63330. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63331. sizeof_client_key_der_2048), 0);
  63332. bufPtr = NULL;
  63333. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63334. sizeof_client_key_der_2048);
  63335. ExpectNotNull(bufPtr);
  63336. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63337. sizeof_client_key_der_2048), 0);
  63338. XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  63339. RSA_free(rsa);
  63340. rsa = NULL;
  63341. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63342. sizeof_client_key_der_2048), 0);
  63343. ExpectNotNull(d2i_RSA_PUBKEY_bio(bio, &rsa));
  63344. (void)BIO_reset(bio);
  63345. RSA_free(rsa);
  63346. rsa = RSA_new();
  63347. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 0);
  63348. #endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */
  63349. RSA_free(rsa);
  63350. }
  63351. #endif /* WOLFSSL_KEY_GEN && !NO_RSA */
  63352. SSL_CTX_free(ctx);
  63353. ctx = NULL;
  63354. BIO_free(bio);
  63355. bio = NULL;
  63356. return EXPECT_RESULT();
  63357. }
  63358. #endif /* OPENSSL_ALL || (WOLFSSL_ASIO && !NO_RSA) */
  63359. #endif /* !NO_BIO */
  63360. static int test_wolfSSL_sk_GENERAL_NAME(void)
  63361. {
  63362. EXPECT_DECLS;
  63363. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63364. !defined(NO_RSA)
  63365. X509* x509 = NULL;
  63366. GENERAL_NAME* gn = NULL;
  63367. unsigned char buf[4096];
  63368. const unsigned char* bufPt = NULL;
  63369. int bytes = 0;
  63370. int i;
  63371. int j;
  63372. XFILE f = XBADFILE;
  63373. STACK_OF(GENERAL_NAME)* sk = NULL;
  63374. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63375. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63376. if (f != XBADFILE)
  63377. XFCLOSE(f);
  63378. for (j = 0; j < 2; ++j) {
  63379. bufPt = buf;
  63380. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63381. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63382. NID_subject_alt_name, NULL, NULL));
  63383. ExpectIntEQ(sk_GENERAL_NAME_num(sk), 1);
  63384. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  63385. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, i));
  63386. if (gn != NULL) {
  63387. switch (gn->type) {
  63388. case GEN_DNS:
  63389. fprintf(stderr, "found type GEN_DNS\n");
  63390. break;
  63391. case GEN_EMAIL:
  63392. fprintf(stderr, "found type GEN_EMAIL\n");
  63393. break;
  63394. case GEN_URI:
  63395. fprintf(stderr, "found type GEN_URI\n");
  63396. break;
  63397. }
  63398. }
  63399. }
  63400. X509_free(x509);
  63401. x509 = NULL;
  63402. if (j == 0) {
  63403. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63404. }
  63405. else {
  63406. /*
  63407. * We had a bug where GENERAL_NAMES_free didn't free all the memory
  63408. * it was supposed to. This is a regression test for that bug.
  63409. */
  63410. GENERAL_NAMES_free(sk);
  63411. }
  63412. sk = NULL;
  63413. }
  63414. #endif
  63415. return EXPECT_RESULT();
  63416. }
  63417. static int test_wolfSSL_GENERAL_NAME_print(void)
  63418. {
  63419. EXPECT_DECLS;
  63420. #if defined(OPENSSL_ALL) && !defined(NO_BIO) && !defined(NO_RSA)
  63421. X509* x509 = NULL;
  63422. GENERAL_NAME* gn = NULL;
  63423. unsigned char buf[4096];
  63424. const unsigned char* bufPt = NULL;
  63425. int bytes;
  63426. XFILE f = XBADFILE;
  63427. STACK_OF(GENERAL_NAME)* sk = NULL;
  63428. BIO* out = NULL;
  63429. unsigned char outbuf[128];
  63430. X509_EXTENSION* ext = NULL;
  63431. AUTHORITY_INFO_ACCESS* aia = NULL;
  63432. ACCESS_DESCRIPTION* ad = NULL;
  63433. ASN1_IA5STRING *dnsname = NULL;
  63434. const unsigned char v4Addr[] = {192,168,53,1};
  63435. const unsigned char v6Addr[] =
  63436. {0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  63437. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77};
  63438. const unsigned char email[] =
  63439. {'i', 'n', 'f', 'o', '@', 'w', 'o', 'l',
  63440. 'f', 's', 's', 'l', '.', 'c', 'o', 'm'};
  63441. const char* dnsStr = "DNS:example.com";
  63442. const char* uriStr = "URI:http://127.0.0.1:22220";
  63443. const char* v4addStr = "IP Address:192.168.53.1";
  63444. const char* v6addStr = "IP Address:2021:DB8:0:0:0:FF00:42:7777";
  63445. const char* emailStr = "email:info@wolfssl.com";
  63446. const char* othrStr = "othername:<unsupported>";
  63447. const char* x400Str = "X400Name:<unsupported>";
  63448. const char* ediStr = "EdiPartyName:<unsupported>";
  63449. /* BIO to output */
  63450. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  63451. /* test for NULL param */
  63452. gn = NULL;
  63453. ExpectIntEQ(GENERAL_NAME_print(NULL, NULL), 0);
  63454. ExpectIntEQ(GENERAL_NAME_print(NULL, gn), 0);
  63455. ExpectIntEQ(GENERAL_NAME_print(out, NULL), 0);
  63456. /* test for GEN_DNS */
  63457. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63458. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63459. if (f != XBADFILE) {
  63460. XFCLOSE(f);
  63461. f = XBADFILE;
  63462. }
  63463. bufPt = buf;
  63464. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63465. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63466. NID_subject_alt_name, NULL, NULL));
  63467. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, 0));
  63468. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63469. XMEMSET(outbuf, 0, sizeof(outbuf));
  63470. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63471. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63472. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63473. gn = NULL;
  63474. sk = NULL;
  63475. X509_free(x509);
  63476. x509 = NULL;
  63477. /* Lets test for setting as well. */
  63478. ExpectNotNull(gn = GENERAL_NAME_new());
  63479. ExpectNotNull(dnsname = ASN1_IA5STRING_new());
  63480. ExpectIntEQ(ASN1_STRING_set(dnsname, "example.com", -1), 1);
  63481. GENERAL_NAME_set0_value(gn, GEN_DNS, dnsname);
  63482. dnsname = NULL;
  63483. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63484. XMEMSET(outbuf, 0, sizeof(outbuf));
  63485. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63486. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63487. GENERAL_NAME_free(gn);
  63488. /* test for GEN_URI */
  63489. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  63490. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  63491. if (f != XBADFILE) {
  63492. XFCLOSE(f);
  63493. f = XBADFILE;
  63494. }
  63495. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 4));
  63496. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  63497. ext));
  63498. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION *)wolfSSL_sk_value(aia, 0));
  63499. if (ad != NULL) {
  63500. gn = ad->location;
  63501. }
  63502. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63503. gn = NULL;
  63504. XMEMSET(outbuf,0,sizeof(outbuf));
  63505. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63506. ExpectIntEQ(XSTRNCMP((const char*)outbuf, uriStr, XSTRLEN(uriStr)), 0);
  63507. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  63508. aia = NULL;
  63509. aia = (AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(ext);
  63510. ExpectNotNull(aia);
  63511. AUTHORITY_INFO_ACCESS_pop_free(aia, NULL);
  63512. aia = NULL;
  63513. X509_free(x509);
  63514. x509 = NULL;
  63515. /* test for GEN_IPADD */
  63516. /* ip v4 address */
  63517. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63518. if (gn != NULL) {
  63519. gn->type = GEN_IPADD;
  63520. if (gn->d.iPAddress != NULL) {
  63521. gn->d.iPAddress->length = sizeof(v4Addr);
  63522. }
  63523. }
  63524. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v4Addr,
  63525. sizeof(v4Addr)), 1);
  63526. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63527. XMEMSET(outbuf,0,sizeof(outbuf));
  63528. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63529. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v4addStr, XSTRLEN(v4addStr)), 0);
  63530. GENERAL_NAME_free(gn);
  63531. gn = NULL;
  63532. /* ip v6 address */
  63533. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63534. if (gn != NULL) {
  63535. gn->type = GEN_IPADD;
  63536. if (gn->d.iPAddress != NULL) {
  63537. gn->d.iPAddress->length = sizeof(v6Addr);
  63538. }
  63539. }
  63540. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v6Addr,
  63541. sizeof(v6Addr)), 1);
  63542. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63543. XMEMSET(outbuf,0,sizeof(outbuf));
  63544. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63545. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v6addStr, XSTRLEN(v6addStr)), 0);
  63546. GENERAL_NAME_free(gn);
  63547. gn = NULL;
  63548. /* test for GEN_EMAIL */
  63549. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63550. if (gn != NULL) {
  63551. gn->type = GEN_EMAIL;
  63552. if (gn->d.rfc822Name != NULL) {
  63553. gn->d.rfc822Name->length = sizeof(email);
  63554. }
  63555. }
  63556. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.rfc822Name, email, sizeof(email)),
  63557. 1);
  63558. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63559. XMEMSET(outbuf,0,sizeof(outbuf));
  63560. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63561. ExpectIntEQ(XSTRNCMP((const char*)outbuf, emailStr, XSTRLEN(emailStr)), 0);
  63562. GENERAL_NAME_free(gn);
  63563. gn = NULL;
  63564. /* test for GEN_OTHERNAME */
  63565. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63566. if (gn != NULL) {
  63567. gn->type = GEN_OTHERNAME;
  63568. }
  63569. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63570. XMEMSET(outbuf,0,sizeof(outbuf));
  63571. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63572. ExpectIntEQ(XSTRNCMP((const char*)outbuf, othrStr, XSTRLEN(othrStr)), 0);
  63573. GENERAL_NAME_free(gn);
  63574. gn = NULL;
  63575. /* test for GEN_X400 */
  63576. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63577. if (gn != NULL) {
  63578. gn->type = GEN_X400;
  63579. }
  63580. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63581. XMEMSET(outbuf,0,sizeof(outbuf));
  63582. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63583. ExpectIntEQ(XSTRNCMP((const char*)outbuf, x400Str, XSTRLEN(x400Str)), 0);
  63584. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  63585. if (gn != NULL) {
  63586. gn->type = GEN_IA5;
  63587. }
  63588. GENERAL_NAME_free(gn);
  63589. gn = NULL;
  63590. /* test for GEN_EDIPARTY */
  63591. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63592. if (gn != NULL) {
  63593. gn->type = GEN_EDIPARTY;
  63594. }
  63595. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63596. XMEMSET(outbuf,0,sizeof(outbuf));
  63597. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63598. ExpectIntEQ(XSTRNCMP((const char*)outbuf, ediStr, XSTRLEN(ediStr)), 0);
  63599. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  63600. if (gn != NULL) {
  63601. gn->type = GEN_IA5;
  63602. }
  63603. GENERAL_NAME_free(gn);
  63604. gn = NULL;
  63605. BIO_free(out);
  63606. #endif /* OPENSSL_ALL */
  63607. return EXPECT_RESULT();
  63608. }
  63609. static int test_wolfSSL_sk_DIST_POINT(void)
  63610. {
  63611. EXPECT_DECLS;
  63612. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63613. !defined(NO_RSA)
  63614. X509* x509 = NULL;
  63615. unsigned char buf[4096];
  63616. const unsigned char* bufPt;
  63617. int bytes = 0;
  63618. int i = 0;
  63619. int j = 0;
  63620. XFILE f = XBADFILE;
  63621. DIST_POINT* dp = NULL;
  63622. DIST_POINT_NAME* dpn = NULL;
  63623. GENERAL_NAME* gn = NULL;
  63624. ASN1_IA5STRING* uri = NULL;
  63625. STACK_OF(DIST_POINT)* dps = NULL;
  63626. STACK_OF(GENERAL_NAME)* gns = NULL;
  63627. const char cliCertDerCrlDistPoint[] = "./certs/client-crl-dist.der";
  63628. ExpectTrue((f = XFOPEN(cliCertDerCrlDistPoint, "rb")) != XBADFILE);
  63629. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63630. if (f != XBADFILE)
  63631. XFCLOSE(f);
  63632. bufPt = buf;
  63633. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63634. ExpectNotNull(dps = (STACK_OF(DIST_POINT)*)X509_get_ext_d2i(x509,
  63635. NID_crl_distribution_points, NULL, NULL));
  63636. ExpectIntEQ(sk_DIST_POINT_num(dps), 1);
  63637. for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
  63638. ExpectNotNull(dp = sk_DIST_POINT_value(dps, i));
  63639. ExpectNotNull(dpn = dp->distpoint);
  63640. /* this should be type 0, fullname */
  63641. ExpectIntEQ(dpn->type, 0);
  63642. ExpectNotNull(gns = dp->distpoint->name.fullname);
  63643. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  63644. for (j = 0; j < sk_GENERAL_NAME_num(gns); j++) {
  63645. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, j));
  63646. ExpectIntEQ(gn->type, GEN_URI);
  63647. ExpectNotNull(uri = gn->d.uniformResourceIdentifier);
  63648. ExpectNotNull(uri->data);
  63649. ExpectIntGT(uri->length, 0);
  63650. }
  63651. }
  63652. X509_free(x509);
  63653. CRL_DIST_POINTS_free(dps);
  63654. #endif
  63655. return EXPECT_RESULT();
  63656. }
  63657. static int test_wolfSSL_verify_mode(void)
  63658. {
  63659. EXPECT_DECLS;
  63660. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  63661. WOLFSSL* ssl = NULL;
  63662. WOLFSSL_CTX* ctx = NULL;
  63663. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63664. ExpectNotNull(ssl = SSL_new(ctx));
  63665. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  63666. SSL_free(ssl);
  63667. ssl = NULL;
  63668. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  63669. ExpectNotNull(ssl = SSL_new(ctx));
  63670. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  63671. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  63672. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  63673. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx), SSL_VERIFY_PEER);
  63674. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  63675. SSL_free(ssl);
  63676. ssl = NULL;
  63677. wolfSSL_CTX_set_verify(ctx,
  63678. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  63679. ExpectNotNull(ssl = SSL_new(ctx));
  63680. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  63681. ExpectIntEQ(SSL_get_verify_mode(ssl),
  63682. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63683. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER, 0);
  63684. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  63685. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63686. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  63687. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  63688. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  63689. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  63690. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63691. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_EXCEPT_PSK, 0);
  63692. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_EXCEPT_PSK);
  63693. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  63694. wolfSSL_set_verify(ssl, SSL_VERIFY_POST_HANDSHAKE, 0);
  63695. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_POST_HANDSHAKE);
  63696. #endif
  63697. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  63698. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63699. SSL_free(ssl);
  63700. SSL_CTX_free(ctx);
  63701. #endif
  63702. return EXPECT_RESULT();
  63703. }
  63704. static int test_wolfSSL_verify_depth(void)
  63705. {
  63706. EXPECT_DECLS;
  63707. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  63708. WOLFSSL* ssl = NULL;
  63709. WOLFSSL_CTX* ctx = NULL;
  63710. long depth;
  63711. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63712. ExpectIntGT((depth = SSL_CTX_get_verify_depth(ctx)), 0);
  63713. ExpectNotNull(ssl = SSL_new(ctx));
  63714. ExpectIntEQ(SSL_get_verify_depth(ssl), SSL_CTX_get_verify_depth(ctx));
  63715. SSL_free(ssl);
  63716. ssl = NULL;
  63717. SSL_CTX_set_verify_depth(ctx, -1);
  63718. ExpectIntEQ(depth, SSL_CTX_get_verify_depth(ctx));
  63719. SSL_CTX_set_verify_depth(ctx, 2);
  63720. ExpectIntEQ(2, SSL_CTX_get_verify_depth(ctx));
  63721. ExpectNotNull(ssl = SSL_new(ctx));
  63722. ExpectIntEQ(2, SSL_get_verify_depth(ssl));
  63723. SSL_free(ssl);
  63724. SSL_CTX_free(ctx);
  63725. #endif
  63726. return EXPECT_RESULT();
  63727. }
  63728. static int test_wolfSSL_verify_result(void)
  63729. {
  63730. EXPECT_DECLS;
  63731. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  63732. defined(OPENSSL_ALL)) && !defined(NO_WOLFSSL_CLIENT)
  63733. WOLFSSL* ssl = NULL;
  63734. WOLFSSL_CTX* ctx = NULL;
  63735. long result = 0xDEADBEEF;
  63736. ExpectIntEQ(WC_NO_ERR_TRACE(WOLFSSL_FAILURE), wolfSSL_get_verify_result(ssl));
  63737. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63738. ExpectNotNull(ssl = SSL_new(ctx));
  63739. wolfSSL_set_verify_result(ssl, result);
  63740. ExpectIntEQ(result, wolfSSL_get_verify_result(ssl));
  63741. SSL_free(ssl);
  63742. SSL_CTX_free(ctx);
  63743. #endif
  63744. return EXPECT_RESULT();
  63745. }
  63746. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  63747. static void sslMsgCb(int w, int version, int type, const void* buf,
  63748. size_t sz, SSL* ssl, void* arg)
  63749. {
  63750. int i;
  63751. unsigned char* pt = (unsigned char*)buf;
  63752. fprintf(stderr, "%s %d bytes of version %d , type %d : ",
  63753. (w)?"Writing":"Reading", (int)sz, version, type);
  63754. for (i = 0; i < (int)sz; i++) fprintf(stderr, "%02X", pt[i]);
  63755. fprintf(stderr, "\n");
  63756. (void)ssl;
  63757. (void)arg;
  63758. }
  63759. #endif /* OPENSSL_EXTRA */
  63760. static int test_wolfSSL_msg_callback(void)
  63761. {
  63762. EXPECT_DECLS;
  63763. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  63764. WOLFSSL* ssl = NULL;
  63765. WOLFSSL_CTX* ctx = NULL;
  63766. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63767. ExpectNotNull(ssl = SSL_new(ctx));
  63768. ExpectIntEQ(SSL_set_msg_callback(ssl, NULL), SSL_SUCCESS);
  63769. ExpectIntEQ(SSL_set_msg_callback(ssl, &sslMsgCb), SSL_SUCCESS);
  63770. ExpectIntEQ(SSL_set_msg_callback(NULL, &sslMsgCb), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63771. SSL_free(ssl);
  63772. SSL_CTX_free(ctx);
  63773. #endif
  63774. return EXPECT_RESULT();
  63775. }
  63776. /* test_EVP_Cipher_extra, Extra-test on EVP_CipherUpdate/Final. see also test.c */
  63777. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  63778. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  63779. static void binary_dump(void *ptr, int size)
  63780. {
  63781. #ifdef WOLFSSL_EVP_PRINT
  63782. int i = 0;
  63783. unsigned char *p = (unsigned char *) ptr;
  63784. fprintf(stderr, "{");
  63785. while ((p != NULL) && (i < size)) {
  63786. if ((i % 8) == 0) {
  63787. fprintf(stderr, "\n");
  63788. fprintf(stderr, " ");
  63789. }
  63790. fprintf(stderr, "0x%02x, ", p[i]);
  63791. i++;
  63792. }
  63793. fprintf(stderr, "\n};\n");
  63794. #else
  63795. (void) ptr;
  63796. (void) size;
  63797. #endif
  63798. }
  63799. static int last_val = 0x0f;
  63800. static int check_result(unsigned char *data, int len)
  63801. {
  63802. int i;
  63803. for ( ; len; ) {
  63804. last_val = (last_val + 1) % 16;
  63805. for (i = 0; i < 16; len--, i++, data++)
  63806. if (*data != last_val) {
  63807. return -1;
  63808. }
  63809. }
  63810. return 0;
  63811. }
  63812. static int r_offset;
  63813. static int w_offset;
  63814. static void init_offset(void)
  63815. {
  63816. r_offset = 0;
  63817. w_offset = 0;
  63818. }
  63819. static void get_record(unsigned char *data, unsigned char *buf, int len)
  63820. {
  63821. XMEMCPY(buf, data+r_offset, len);
  63822. r_offset += len;
  63823. }
  63824. static void set_record(unsigned char *data, unsigned char *buf, int len)
  63825. {
  63826. XMEMCPY(data+w_offset, buf, len);
  63827. w_offset += len;
  63828. }
  63829. static void set_plain(unsigned char *plain, int rec)
  63830. {
  63831. int i, j;
  63832. unsigned char *p = plain;
  63833. #define BLOCKSZ 16
  63834. for (i=0; i<(rec/BLOCKSZ); i++) {
  63835. for (j=0; j<BLOCKSZ; j++)
  63836. *p++ = (i % 16);
  63837. }
  63838. }
  63839. #endif
  63840. static int test_wolfSSL_EVP_Cipher_extra(void)
  63841. {
  63842. EXPECT_DECLS;
  63843. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  63844. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  63845. /* aes128-cbc, keylen=16, ivlen=16 */
  63846. byte aes128_cbc_key[] = {
  63847. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  63848. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  63849. };
  63850. byte aes128_cbc_iv[] = {
  63851. 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
  63852. 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
  63853. };
  63854. /* teset data size table */
  63855. int test_drive1[] = {8, 3, 5, 512, 8, 3, 8, 512, 0};
  63856. int test_drive2[] = {8, 3, 8, 512, 0};
  63857. int test_drive3[] = {512, 512, 504, 512, 512, 8, 512, 0};
  63858. int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL};
  63859. int test_drive_len[100];
  63860. int ret = 0;
  63861. EVP_CIPHER_CTX *evp = NULL;
  63862. int ilen = 0;
  63863. int klen = 0;
  63864. int i, j;
  63865. const EVP_CIPHER *type;
  63866. byte *iv;
  63867. byte *key;
  63868. int ivlen;
  63869. int keylen;
  63870. #define RECORDS 16
  63871. #define BUFFSZ 512
  63872. byte plain [BUFFSZ * RECORDS];
  63873. byte cipher[BUFFSZ * RECORDS];
  63874. byte inb[BUFFSZ];
  63875. byte outb[BUFFSZ+16];
  63876. int outl = 0;
  63877. int inl;
  63878. iv = aes128_cbc_iv;
  63879. ivlen = sizeof(aes128_cbc_iv);
  63880. key = aes128_cbc_key;
  63881. keylen = sizeof(aes128_cbc_key);
  63882. type = EVP_aes_128_cbc();
  63883. set_plain(plain, BUFFSZ * RECORDS);
  63884. SSL_library_init();
  63885. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  63886. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  63887. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  63888. klen = EVP_CIPHER_CTX_key_length(evp);
  63889. if (klen > 0 && keylen != klen) {
  63890. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  63891. }
  63892. ilen = EVP_CIPHER_CTX_iv_length(evp);
  63893. if (ilen > 0 && ivlen != ilen) {
  63894. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  63895. }
  63896. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  63897. for (j = 0; j<RECORDS; j++)
  63898. {
  63899. inl = BUFFSZ;
  63900. get_record(plain, inb, inl);
  63901. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, inb, inl)), 0);
  63902. set_record(cipher, outb, outl);
  63903. }
  63904. for (i = 0; test_drive[i]; i++) {
  63905. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  63906. init_offset();
  63907. test_drive_len[i] = 0;
  63908. for (j = 0; test_drive[i][j]; j++)
  63909. {
  63910. inl = test_drive[i][j];
  63911. test_drive_len[i] += inl;
  63912. get_record(plain, inb, inl);
  63913. ExpectIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)),
  63914. 0);
  63915. /* output to cipher buffer, so that following Dec test can detect
  63916. if any error */
  63917. set_record(cipher, outb, outl);
  63918. }
  63919. EVP_CipherFinal(evp, outb, &outl);
  63920. if (outl > 0)
  63921. set_record(cipher, outb, outl);
  63922. }
  63923. for (i = 0; test_drive[i]; i++) {
  63924. last_val = 0x0f;
  63925. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0);
  63926. init_offset();
  63927. for (j = 0; test_drive[i][j]; j++) {
  63928. inl = test_drive[i][j];
  63929. get_record(cipher, inb, inl);
  63930. ExpectIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)),
  63931. 0);
  63932. binary_dump(outb, outl);
  63933. ExpectIntEQ((ret = check_result(outb, outl)), 0);
  63934. ExpectFalse(outl > ((inl/16+1)*16) && outl > 16);
  63935. }
  63936. ret = EVP_CipherFinal(evp, outb, &outl);
  63937. binary_dump(outb, outl);
  63938. ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) ||
  63939. (((test_drive_len[i] % 16) == 0) && (ret == 1));
  63940. ExpectTrue(ret);
  63941. }
  63942. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(evp), WOLFSSL_SUCCESS);
  63943. EVP_CIPHER_CTX_free(evp);
  63944. evp = NULL;
  63945. /* Do an extra test to verify correct behavior with empty input. */
  63946. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  63947. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  63948. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  63949. klen = EVP_CIPHER_CTX_key_length(evp);
  63950. if (klen > 0 && keylen != klen) {
  63951. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  63952. }
  63953. ilen = EVP_CIPHER_CTX_iv_length(evp);
  63954. if (ilen > 0 && ivlen != ilen) {
  63955. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  63956. }
  63957. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  63958. /* outl should be set to 0 after passing NULL, 0 for input args. */
  63959. outl = -1;
  63960. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, NULL, 0)), 0);
  63961. ExpectIntEQ(outl, 0);
  63962. EVP_CIPHER_CTX_free(evp);
  63963. #endif /* test_EVP_Cipher */
  63964. return EXPECT_RESULT();
  63965. }
  63966. static int test_wolfSSL_PEM_read_DHparams(void)
  63967. {
  63968. EXPECT_DECLS;
  63969. #if defined(OPENSSL_ALL) && !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && \
  63970. !defined(NO_FILESYSTEM)
  63971. DH* dh = NULL;
  63972. XFILE fp = XBADFILE;
  63973. unsigned char derOut[300];
  63974. unsigned char* derOutBuf = derOut;
  63975. int derOutSz = 0;
  63976. unsigned char derExpected[300];
  63977. int derExpectedSz = 0;
  63978. XMEMSET(derOut, 0, sizeof(derOut));
  63979. XMEMSET(derExpected, 0, sizeof(derExpected));
  63980. /* open DH param file, read into DH struct */
  63981. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  63982. /* bad args */
  63983. ExpectNull(dh = PEM_read_DHparams(NULL, &dh, NULL, NULL));
  63984. ExpectNull(dh = PEM_read_DHparams(NULL, NULL, NULL, NULL));
  63985. /* good args */
  63986. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  63987. if (fp != XBADFILE) {
  63988. XFCLOSE(fp);
  63989. fp = XBADFILE;
  63990. }
  63991. /* read in certs/dh2048.der for comparison against exported params */
  63992. ExpectTrue((fp = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  63993. ExpectIntGT(derExpectedSz = (int)XFREAD(derExpected, 1, sizeof(derExpected),
  63994. fp), 0);
  63995. if (fp != XBADFILE) {
  63996. XFCLOSE(fp);
  63997. fp = XBADFILE;
  63998. }
  63999. /* export DH back to DER and compare */
  64000. derOutSz = wolfSSL_i2d_DHparams(dh, &derOutBuf);
  64001. ExpectIntEQ(derOutSz, derExpectedSz);
  64002. ExpectIntEQ(XMEMCMP(derOut, derExpected, derOutSz), 0);
  64003. DH_free(dh);
  64004. dh = NULL;
  64005. /* Test parsing with X9.42 header */
  64006. ExpectTrue((fp = XFOPEN("./certs/x942dh2048.pem", "rb")) != XBADFILE);
  64007. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  64008. if (fp != XBADFILE)
  64009. XFCLOSE(fp);
  64010. DH_free(dh);
  64011. dh = NULL;
  64012. #endif
  64013. return EXPECT_RESULT();
  64014. }
  64015. static int test_wolfSSL_X509_get_serialNumber(void)
  64016. {
  64017. EXPECT_DECLS;
  64018. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  64019. ASN1_INTEGER* a = NULL;
  64020. BIGNUM* bn = NULL;
  64021. X509* x509 = NULL;
  64022. char *serialHex = NULL;
  64023. byte serial[3];
  64024. int serialSz;
  64025. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64026. SSL_FILETYPE_PEM));
  64027. ExpectNotNull(a = X509_get_serialNumber(x509));
  64028. /* check on value of ASN1 Integer */
  64029. ExpectNotNull(bn = ASN1_INTEGER_to_BN(a, NULL));
  64030. a = NULL;
  64031. /* test setting serial number and then retrieving it */
  64032. ExpectNotNull(a = ASN1_INTEGER_new());
  64033. ExpectIntEQ(ASN1_INTEGER_set(a, 3), 1);
  64034. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64035. serialSz = sizeof(serial);
  64036. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64037. WOLFSSL_SUCCESS);
  64038. ExpectIntEQ(serialSz, 1);
  64039. ExpectIntEQ(serial[0], 3);
  64040. ASN1_INTEGER_free(a);
  64041. a = NULL;
  64042. /* test setting serial number with 0's in it */
  64043. serial[0] = 0x01;
  64044. serial[1] = 0x00;
  64045. serial[2] = 0x02;
  64046. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  64047. if (a != NULL) {
  64048. a->data[0] = ASN_INTEGER;
  64049. a->data[1] = sizeof(serial);
  64050. XMEMCPY(&a->data[2], serial, sizeof(serial));
  64051. a->length = sizeof(serial) + 2;
  64052. }
  64053. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64054. XMEMSET(serial, 0, sizeof(serial));
  64055. serialSz = sizeof(serial);
  64056. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64057. WOLFSSL_SUCCESS);
  64058. ExpectIntEQ(serialSz, 3);
  64059. ExpectIntEQ(serial[0], 0x01);
  64060. ExpectIntEQ(serial[1], 0x00);
  64061. ExpectIntEQ(serial[2], 0x02);
  64062. ASN1_INTEGER_free(a);
  64063. a = NULL;
  64064. X509_free(x509); /* free's a */
  64065. ExpectNotNull(serialHex = BN_bn2hex(bn));
  64066. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  64067. ExpectStrEQ(serialHex, "01");
  64068. #else
  64069. ExpectStrEQ(serialHex, "1");
  64070. #endif
  64071. OPENSSL_free(serialHex);
  64072. ExpectIntEQ(BN_get_word(bn), 1);
  64073. BN_free(bn);
  64074. /* hard test free'ing with dynamic buffer to make sure there is no leaks */
  64075. ExpectNotNull(a = ASN1_INTEGER_new());
  64076. if (a != NULL) {
  64077. ExpectNotNull(a->data = (unsigned char*)XMALLOC(100, NULL,
  64078. DYNAMIC_TYPE_OPENSSL));
  64079. a->isDynamic = 1;
  64080. ASN1_INTEGER_free(a);
  64081. }
  64082. #endif
  64083. return EXPECT_RESULT();
  64084. }
  64085. static int test_wolfSSL_OpenSSL_add_all_algorithms(void)
  64086. {
  64087. EXPECT_DECLS;
  64088. #if defined(OPENSSL_EXTRA)
  64089. ExpectIntEQ(wolfSSL_add_all_algorithms(), WOLFSSL_SUCCESS);
  64090. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_noconf(), WOLFSSL_SUCCESS);
  64091. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_conf(), WOLFSSL_SUCCESS);
  64092. #endif
  64093. return EXPECT_RESULT();
  64094. }
  64095. static int test_wolfSSL_OPENSSL_hexstr2buf(void)
  64096. {
  64097. EXPECT_DECLS;
  64098. #if defined(OPENSSL_EXTRA)
  64099. #define MAX_HEXSTR_BUFSZ 9
  64100. #define NUM_CASES 5
  64101. struct Output {
  64102. const unsigned char buffer[MAX_HEXSTR_BUFSZ];
  64103. long ret;
  64104. };
  64105. int i;
  64106. int j;
  64107. const char* inputs[NUM_CASES] = {
  64108. "aabcd1357e",
  64109. "01:12:23:34:a5:b6:c7:d8:e9",
  64110. ":01:02",
  64111. "012",
  64112. ":ab:ac:d"
  64113. };
  64114. struct Output expectedOutputs[NUM_CASES] = {
  64115. {{0xaa, 0xbc, 0xd1, 0x35, 0x7e}, 5},
  64116. {{0x01, 0x12, 0x23, 0x34, 0xa5, 0xb6, 0xc7, 0xd8, 0xe9}, 9},
  64117. {{0x01, 0x02}, 2},
  64118. {{0x00}, 0},
  64119. {{0x00}, 0}
  64120. };
  64121. long len = 0;
  64122. unsigned char* returnedBuf = NULL;
  64123. for (i = 0; i < NUM_CASES && !EXPECT_FAIL(); ++i) {
  64124. returnedBuf = wolfSSL_OPENSSL_hexstr2buf(inputs[i], &len);
  64125. if (returnedBuf == NULL) {
  64126. ExpectIntEQ(expectedOutputs[i].ret, 0);
  64127. continue;
  64128. }
  64129. ExpectIntEQ(expectedOutputs[i].ret, len);
  64130. for (j = 0; j < len; ++j) {
  64131. ExpectIntEQ(expectedOutputs[i].buffer[j], returnedBuf[j]);
  64132. }
  64133. OPENSSL_free(returnedBuf);
  64134. returnedBuf = NULL;
  64135. }
  64136. #endif
  64137. return EXPECT_RESULT();
  64138. }
  64139. static int test_wolfSSL_X509_CA_num(void)
  64140. {
  64141. EXPECT_DECLS;
  64142. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  64143. defined(HAVE_ECC) && !defined(NO_RSA)
  64144. WOLFSSL_X509_STORE *store = NULL;
  64145. WOLFSSL_X509 *x509_1 = NULL;
  64146. WOLFSSL_X509 *x509_2 = NULL;
  64147. int ca_num = 0;
  64148. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  64149. ExpectNotNull(x509_1 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64150. WOLFSSL_FILETYPE_PEM));
  64151. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_1), 1);
  64152. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 1);
  64153. ExpectNotNull(x509_2 = wolfSSL_X509_load_certificate_file(eccCertFile,
  64154. WOLFSSL_FILETYPE_PEM));
  64155. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_2), 1);
  64156. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 2);
  64157. wolfSSL_X509_free(x509_1);
  64158. wolfSSL_X509_free(x509_2);
  64159. wolfSSL_X509_STORE_free(store);
  64160. #endif
  64161. return EXPECT_RESULT();
  64162. }
  64163. static int test_wolfSSL_X509_check_ca(void)
  64164. {
  64165. EXPECT_DECLS;
  64166. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64167. WOLFSSL_X509 *x509 = NULL;
  64168. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64169. WOLFSSL_FILETYPE_PEM));
  64170. ExpectIntEQ(wolfSSL_X509_check_ca(x509), 1);
  64171. wolfSSL_X509_free(x509);
  64172. #endif
  64173. return EXPECT_RESULT();
  64174. }
  64175. static int test_wolfSSL_X509_check_ip_asc(void)
  64176. {
  64177. EXPECT_DECLS;
  64178. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64179. WOLFSSL_X509 *x509 = NULL;
  64180. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  64181. WOLFSSL_FILETYPE_PEM));
  64182. #if 0
  64183. /* TODO: add cert gen for testing positive case */
  64184. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.0.0.1", 0), 1);
  64185. #endif
  64186. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "0.0.0.0", 0), 0);
  64187. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, NULL, 0), 0);
  64188. wolfSSL_X509_free(x509);
  64189. #endif
  64190. return EXPECT_RESULT();
  64191. }
  64192. static int test_wolfSSL_make_cert(void)
  64193. {
  64194. EXPECT_DECLS;
  64195. #if !defined(NO_RSA) && !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && \
  64196. defined(WOLFSSL_CERT_EXT)
  64197. int ret = 0;
  64198. Cert cert;
  64199. CertName name;
  64200. RsaKey key;
  64201. WC_RNG rng;
  64202. byte der[FOURK_BUF];
  64203. word32 idx = 0;
  64204. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  64205. #ifdef OPENSSL_EXTRA
  64206. const unsigned char* pt = NULL;
  64207. int certSz = 0;
  64208. X509* x509 = NULL;
  64209. X509_NAME* x509name = NULL;
  64210. X509_NAME_ENTRY* entry = NULL;
  64211. ASN1_STRING* entryValue = NULL;
  64212. #endif
  64213. XMEMSET(&name, 0, sizeof(CertName));
  64214. /* set up cert name */
  64215. XMEMCPY(name.country, "US", sizeof("US"));
  64216. name.countryEnc = CTC_PRINTABLE;
  64217. XMEMCPY(name.state, "Oregon", sizeof("Oregon"));
  64218. name.stateEnc = CTC_UTF8;
  64219. XMEMCPY(name.locality, "Portland", sizeof("Portland"));
  64220. name.localityEnc = CTC_UTF8;
  64221. XMEMCPY(name.sur, "Test", sizeof("Test"));
  64222. name.surEnc = CTC_UTF8;
  64223. XMEMCPY(name.org, "wolfSSL", sizeof("wolfSSL"));
  64224. name.orgEnc = CTC_UTF8;
  64225. XMEMCPY(name.unit, "Development", sizeof("Development"));
  64226. name.unitEnc = CTC_UTF8;
  64227. XMEMCPY(name.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  64228. name.commonNameEnc = CTC_UTF8;
  64229. XMEMCPY(name.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  64230. name.serialDevEnc = CTC_PRINTABLE;
  64231. XMEMCPY(name.userId, "TestUserID", sizeof("TestUserID"));
  64232. name.userIdEnc = CTC_PRINTABLE;
  64233. #ifdef WOLFSSL_MULTI_ATTRIB
  64234. #if CTC_MAX_ATTRIB > 2
  64235. {
  64236. NameAttrib* n;
  64237. n = &name.name[0];
  64238. n->id = ASN_DOMAIN_COMPONENT;
  64239. n->type = CTC_UTF8;
  64240. n->sz = sizeof("com");
  64241. XMEMCPY(n->value, "com", sizeof("com"));
  64242. n = &name.name[1];
  64243. n->id = ASN_DOMAIN_COMPONENT;
  64244. n->type = CTC_UTF8;
  64245. n->sz = sizeof("wolfssl");
  64246. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  64247. }
  64248. #endif
  64249. #endif /* WOLFSSL_MULTI_ATTRIB */
  64250. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  64251. #ifndef HAVE_FIPS
  64252. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  64253. #else
  64254. ExpectIntEQ(wc_InitRng(&rng), 0);
  64255. #endif
  64256. /* load test RSA key */
  64257. idx = 0;
  64258. #if defined(USE_CERT_BUFFERS_1024)
  64259. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_1024, &idx, &key,
  64260. sizeof_server_key_der_1024), 0);
  64261. #elif defined(USE_CERT_BUFFERS_2048)
  64262. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  64263. sizeof_server_key_der_2048), 0);
  64264. #else
  64265. /* error case, no RSA key loaded, happens later */
  64266. (void)idx;
  64267. #endif
  64268. XMEMSET(&cert, 0 , sizeof(Cert));
  64269. ExpectIntEQ(wc_InitCert(&cert), 0);
  64270. XMEMCPY(&cert.subject, &name, sizeof(CertName));
  64271. XMEMCPY(cert.serial, mySerial, sizeof(mySerial));
  64272. cert.serialSz = (int)sizeof(mySerial);
  64273. cert.isCA = 1;
  64274. #ifndef NO_SHA256
  64275. cert.sigType = CTC_SHA256wRSA;
  64276. #else
  64277. cert.sigType = CTC_SHAwRSA;
  64278. #endif
  64279. /* add SKID from the Public Key */
  64280. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64281. /* add AKID from the Public Key */
  64282. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64283. ret = 0;
  64284. do {
  64285. #if defined(WOLFSSL_ASYNC_CRYPT)
  64286. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  64287. #endif
  64288. if (ret >= 0) {
  64289. ret = wc_MakeSelfCert(&cert, der, FOURK_BUF, &key, &rng);
  64290. }
  64291. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  64292. ExpectIntGT(ret, 0);
  64293. #ifdef OPENSSL_EXTRA
  64294. /* der holds a certificate with DC's now check X509 parsing of it */
  64295. certSz = ret;
  64296. pt = der;
  64297. ExpectNotNull(x509 = d2i_X509(NULL, &pt, certSz));
  64298. ExpectNotNull(x509name = X509_get_subject_name(x509));
  64299. #ifdef WOLFSSL_MULTI_ATTRIB
  64300. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64301. -1)), 5);
  64302. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64303. (int)idx)), 6);
  64304. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64305. (int)idx)), -1);
  64306. #endif /* WOLFSSL_MULTI_ATTRIB */
  64307. /* compare DN at index 0 */
  64308. ExpectNotNull(entry = X509_NAME_get_entry(x509name, 0));
  64309. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64310. ExpectIntEQ(ASN1_STRING_length(entryValue), 2);
  64311. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "US");
  64312. #ifndef WOLFSSL_MULTI_ATTRIB
  64313. /* compare Serial Number */
  64314. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_serialNumber,
  64315. -1)), 7);
  64316. ExpectNotNull(entry = X509_NAME_get_entry(x509name, idx));
  64317. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64318. ExpectIntEQ(ASN1_STRING_length(entryValue), XSTRLEN("wolfSSL12345"));
  64319. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "wolfSSL12345");
  64320. #endif
  64321. #ifdef WOLFSSL_MULTI_ATTRIB
  64322. /* get first and second DC and compare result */
  64323. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64324. -1)), 5);
  64325. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64326. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64327. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "com");
  64328. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64329. (int)idx)), 6);
  64330. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64331. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64332. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "wolfssl");
  64333. #endif /* WOLFSSL_MULTI_ATTRIB */
  64334. /* try invalid index locations for regression test and sanity check */
  64335. ExpectNull(entry = X509_NAME_get_entry(x509name, 11));
  64336. ExpectNull(entry = X509_NAME_get_entry(x509name, 20));
  64337. X509_free(x509);
  64338. #endif /* OPENSSL_EXTRA */
  64339. wc_FreeRsaKey(&key);
  64340. wc_FreeRng(&rng);
  64341. #endif
  64342. return EXPECT_RESULT();
  64343. }
  64344. static int test_x509_get_key_id(void)
  64345. {
  64346. EXPECT_DECLS;
  64347. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64348. X509 *x509 = NULL;
  64349. const ASN1_STRING* str = NULL;
  64350. byte* keyId = NULL;
  64351. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  64352. WOLFSSL_FILETYPE_PEM));
  64353. ExpectNotNull(str = X509_get0_subject_key_id(x509));
  64354. ExpectNotNull(keyId = wolfSSL_X509_get_subjectKeyID(x509, NULL, NULL));
  64355. ExpectBufEQ(keyId, ASN1_STRING_data((ASN1_STRING*)str),
  64356. ASN1_STRING_length(str));
  64357. X509_free(x509);
  64358. #endif
  64359. return EXPECT_RESULT();
  64360. }
  64361. static int test_wolfSSL_X509_get_version(void)
  64362. {
  64363. EXPECT_DECLS;
  64364. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64365. WOLFSSL_X509 *x509 = NULL;
  64366. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64367. WOLFSSL_FILETYPE_PEM));
  64368. ExpectIntEQ((int)wolfSSL_X509_get_version(x509), 2);
  64369. wolfSSL_X509_free(x509);
  64370. #endif
  64371. return EXPECT_RESULT();
  64372. }
  64373. #if defined(OPENSSL_ALL)
  64374. static int test_wolfSSL_sk_CIPHER_description(void)
  64375. {
  64376. EXPECT_DECLS;
  64377. #if !defined(NO_RSA)
  64378. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64379. int i;
  64380. int numCiphers = 0;
  64381. const SSL_METHOD *method = NULL;
  64382. const SSL_CIPHER *cipher = NULL;
  64383. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64384. SSL_CTX *ctx = NULL;
  64385. SSL *ssl = NULL;
  64386. char buf[256];
  64387. char test_str[9] = "0000000";
  64388. const char badStr[] = "unknown";
  64389. const char certPath[] = "./certs/client-cert.pem";
  64390. XMEMSET(buf, 0, sizeof(buf));
  64391. ExpectNotNull(method = TLSv1_2_client_method());
  64392. ExpectNotNull(ctx = SSL_CTX_new(method));
  64393. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64394. SSL_CTX_set_verify_depth(ctx, 4);
  64395. SSL_CTX_set_options(ctx, flags);
  64396. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64397. WOLFSSL_SUCCESS);
  64398. ExpectNotNull(ssl = SSL_new(ctx));
  64399. /* SSL_get_ciphers returns a stack of all configured ciphers
  64400. * A flag, getCipherAtOffset, is set to later have SSL_CIPHER_description
  64401. */
  64402. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64403. /* loop through the amount of supportedCiphers */
  64404. numCiphers = sk_num(supportedCiphers);
  64405. for (i = 0; i < numCiphers; ++i) {
  64406. int j;
  64407. /* sk_value increments "sk->data.cipher->cipherOffset".
  64408. * wolfSSL_sk_CIPHER_description sets the description for
  64409. * the cipher based on the provided offset.
  64410. */
  64411. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  64412. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  64413. }
  64414. /* Search cipher description string for "unknown" descriptor */
  64415. for (j = 0; j < (int)XSTRLEN(buf); j++) {
  64416. int k = 0;
  64417. while ((k < (int)XSTRLEN(badStr)) && (buf[j] == badStr[k])) {
  64418. test_str[k] = badStr[k];
  64419. j++;
  64420. k++;
  64421. }
  64422. }
  64423. /* Fail if test_str == badStr == "unknown" */
  64424. ExpectStrNE(test_str,badStr);
  64425. }
  64426. SSL_free(ssl);
  64427. SSL_CTX_free(ctx);
  64428. #endif
  64429. return EXPECT_RESULT();
  64430. }
  64431. static int test_wolfSSL_get_ciphers_compat(void)
  64432. {
  64433. EXPECT_DECLS;
  64434. #if !defined(NO_RSA)
  64435. const SSL_METHOD *method = NULL;
  64436. const char certPath[] = "./certs/client-cert.pem";
  64437. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64438. SSL_CTX *ctx = NULL;
  64439. WOLFSSL *ssl = NULL;
  64440. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64441. ExpectNotNull(method = SSLv23_client_method());
  64442. ExpectNotNull(ctx = SSL_CTX_new(method));
  64443. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64444. SSL_CTX_set_verify_depth(ctx, 4);
  64445. SSL_CTX_set_options(ctx, flags);
  64446. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64447. WOLFSSL_SUCCESS);
  64448. ExpectNotNull(ssl = SSL_new(ctx));
  64449. /* Test Bad NULL input */
  64450. ExpectNull(supportedCiphers = SSL_get_ciphers(NULL));
  64451. /* Test for Good input */
  64452. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64453. /* Further usage of SSL_get_ciphers/wolfSSL_get_ciphers_compat is
  64454. * tested in test_wolfSSL_sk_CIPHER_description according to Qt usage */
  64455. SSL_free(ssl);
  64456. SSL_CTX_free(ctx);
  64457. #endif
  64458. return EXPECT_RESULT();
  64459. }
  64460. static int test_wolfSSL_X509_PUBKEY_get(void)
  64461. {
  64462. EXPECT_DECLS;
  64463. WOLFSSL_X509_PUBKEY pubkey;
  64464. WOLFSSL_X509_PUBKEY* key;
  64465. WOLFSSL_EVP_PKEY evpkey ;
  64466. WOLFSSL_EVP_PKEY* evpPkey;
  64467. WOLFSSL_EVP_PKEY* retEvpPkey;
  64468. XMEMSET(&pubkey, 0, sizeof(WOLFSSL_X509_PUBKEY));
  64469. XMEMSET(&evpkey, 0, sizeof(WOLFSSL_EVP_PKEY));
  64470. key = &pubkey;
  64471. evpPkey = &evpkey;
  64472. evpPkey->type = WOLFSSL_SUCCESS;
  64473. key->pkey = evpPkey;
  64474. ExpectNotNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64475. ExpectIntEQ(retEvpPkey->type, WOLFSSL_SUCCESS);
  64476. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(NULL));
  64477. key->pkey = NULL;
  64478. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64479. return EXPECT_RESULT();
  64480. }
  64481. static int test_wolfSSL_EVP_PKEY_set1_get1_DSA(void)
  64482. {
  64483. EXPECT_DECLS;
  64484. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  64485. DSA *dsa = NULL;
  64486. DSA *setDsa = NULL;
  64487. EVP_PKEY *pkey = NULL;
  64488. EVP_PKEY *set1Pkey = NULL;
  64489. SHA_CTX sha;
  64490. byte signature[DSA_SIG_SIZE];
  64491. byte hash[WC_SHA_DIGEST_SIZE];
  64492. word32 bytes;
  64493. int answer;
  64494. #ifdef USE_CERT_BUFFERS_1024
  64495. const unsigned char* dsaKeyDer = dsa_key_der_1024;
  64496. int dsaKeySz = sizeof_dsa_key_der_1024;
  64497. byte tmp[ONEK_BUF];
  64498. XMEMSET(tmp, 0, sizeof(tmp));
  64499. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64500. bytes = dsaKeySz;
  64501. #elif defined(USE_CERT_BUFFERS_2048)
  64502. const unsigned char* dsaKeyDer = dsa_key_der_2048;
  64503. int dsaKeySz = sizeof_dsa_key_der_2048;
  64504. byte tmp[TWOK_BUF];
  64505. XMEMSET(tmp, 0, sizeof(tmp));
  64506. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64507. bytes = (word32)dsaKeySz;
  64508. #else
  64509. byte tmp[TWOK_BUF];
  64510. const unsigned char* dsaKeyDer = (const unsigned char*)tmp;
  64511. int dsaKeySz;
  64512. XFILE fp = XBADFILE;
  64513. XMEMSET(tmp, 0, sizeof(tmp));
  64514. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  64515. ExpectIntGT(dsaKeySz = bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  64516. if (fp != XBADFILE)
  64517. XFCLOSE(fp);
  64518. #endif /* END USE_CERT_BUFFERS_1024 */
  64519. /* Create hash to later Sign and Verify */
  64520. ExpectIntEQ(SHA1_Init(&sha), WOLFSSL_SUCCESS);
  64521. ExpectIntEQ(SHA1_Update(&sha, tmp, bytes), WOLFSSL_SUCCESS);
  64522. ExpectIntEQ(SHA1_Final(hash,&sha), WOLFSSL_SUCCESS);
  64523. /* Initialize pkey with der format dsa key */
  64524. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &pkey, &dsaKeyDer,
  64525. (long)dsaKeySz));
  64526. /* Test wolfSSL_EVP_PKEY_get1_DSA */
  64527. /* Should Fail: NULL argument */
  64528. ExpectNull(dsa = EVP_PKEY_get0_DSA(NULL));
  64529. ExpectNull(dsa = EVP_PKEY_get1_DSA(NULL));
  64530. /* Should Pass: Initialized pkey argument */
  64531. ExpectNotNull(dsa = EVP_PKEY_get0_DSA(pkey));
  64532. ExpectNotNull(dsa = EVP_PKEY_get1_DSA(pkey));
  64533. #ifdef USE_CERT_BUFFERS_1024
  64534. ExpectIntEQ(DSA_bits(dsa), 1024);
  64535. #else
  64536. ExpectIntEQ(DSA_bits(dsa), 2048);
  64537. #endif
  64538. /* Sign */
  64539. ExpectIntEQ(wolfSSL_DSA_do_sign(hash, signature, dsa), WOLFSSL_SUCCESS);
  64540. /* Verify. */
  64541. ExpectIntEQ(wolfSSL_DSA_do_verify(hash, signature, dsa, &answer),
  64542. WOLFSSL_SUCCESS);
  64543. /* Test wolfSSL_EVP_PKEY_set1_DSA */
  64544. /* Should Fail: set1Pkey not initialized */
  64545. ExpectIntNE(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  64546. /* Initialize set1Pkey */
  64547. set1Pkey = EVP_PKEY_new();
  64548. /* Should Fail Verify: setDsa not initialized from set1Pkey */
  64549. ExpectIntNE(wolfSSL_DSA_do_verify(hash,signature,setDsa,&answer),
  64550. WOLFSSL_SUCCESS);
  64551. /* Should Pass: set dsa into set1Pkey */
  64552. ExpectIntEQ(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  64553. DSA_free(dsa);
  64554. DSA_free(setDsa);
  64555. EVP_PKEY_free(pkey);
  64556. EVP_PKEY_free(set1Pkey);
  64557. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  64558. return EXPECT_RESULT();
  64559. } /* END test_EVP_PKEY_set1_get1_DSA */
  64560. static int test_wolfSSL_DSA_generate_parameters(void)
  64561. {
  64562. EXPECT_DECLS;
  64563. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  64564. !defined(HAVE_FIPS)
  64565. DSA *dsa = NULL;
  64566. ExpectNotNull(dsa = DSA_generate_parameters(2048, NULL, 0, NULL, NULL, NULL,
  64567. NULL));
  64568. DSA_free(dsa);
  64569. #endif
  64570. return EXPECT_RESULT();
  64571. }
  64572. static int test_wolfSSL_DSA_SIG(void)
  64573. {
  64574. EXPECT_DECLS;
  64575. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  64576. !defined(HAVE_FIPS)
  64577. DSA *dsa = NULL;
  64578. DSA *dsa2 = NULL;
  64579. DSA_SIG *sig = NULL;
  64580. const BIGNUM *p = NULL;
  64581. const BIGNUM *q = NULL;
  64582. const BIGNUM *g = NULL;
  64583. const BIGNUM *pub = NULL;
  64584. const BIGNUM *priv = NULL;
  64585. BIGNUM *dup_p = NULL;
  64586. BIGNUM *dup_q = NULL;
  64587. BIGNUM *dup_g = NULL;
  64588. BIGNUM *dup_pub = NULL;
  64589. BIGNUM *dup_priv = NULL;
  64590. const byte digest[WC_SHA_DIGEST_SIZE] = {0};
  64591. ExpectNotNull(dsa = DSA_new());
  64592. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048, NULL, 0, NULL, NULL,
  64593. NULL), 1);
  64594. ExpectIntEQ(DSA_generate_key(dsa), 1);
  64595. DSA_get0_pqg(dsa, &p, &q, &g);
  64596. DSA_get0_key(dsa, &pub, &priv);
  64597. ExpectNotNull(dup_p = BN_dup(p));
  64598. ExpectNotNull(dup_q = BN_dup(q));
  64599. ExpectNotNull(dup_g = BN_dup(g));
  64600. ExpectNotNull(dup_pub = BN_dup(pub));
  64601. ExpectNotNull(dup_priv = BN_dup(priv));
  64602. ExpectNotNull(sig = DSA_do_sign(digest, sizeof(digest), dsa));
  64603. ExpectNotNull(dsa2 = DSA_new());
  64604. ExpectIntEQ(DSA_set0_pqg(dsa2, dup_p, dup_q, dup_g), 1);
  64605. if (EXPECT_FAIL()) {
  64606. BN_free(dup_p);
  64607. BN_free(dup_q);
  64608. BN_free(dup_g);
  64609. }
  64610. ExpectIntEQ(DSA_set0_key(dsa2, dup_pub, dup_priv), 1);
  64611. if (EXPECT_FAIL()) {
  64612. BN_free(dup_pub);
  64613. BN_free(dup_priv);
  64614. }
  64615. ExpectIntEQ(DSA_do_verify(digest, sizeof(digest), sig, dsa2), 1);
  64616. DSA_free(dsa);
  64617. DSA_free(dsa2);
  64618. DSA_SIG_free(sig);
  64619. #endif
  64620. return EXPECT_RESULT();
  64621. }
  64622. static int test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY (void)
  64623. {
  64624. EXPECT_DECLS;
  64625. #ifdef HAVE_ECC
  64626. WOLFSSL_EC_KEY* ecKey = NULL;
  64627. WOLFSSL_EC_KEY* ecGet1 = NULL;
  64628. EVP_PKEY* pkey = NULL;
  64629. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  64630. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64631. /* Test wolfSSL_EVP_PKEY_set1_EC_KEY */
  64632. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64633. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64634. /* Should fail since ecKey is empty */
  64635. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64636. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  64637. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  64638. /* Test wolfSSL_EVP_PKEY_get1_EC_KEY */
  64639. ExpectNull(wolfSSL_EVP_PKEY_get1_EC_KEY(NULL));
  64640. ExpectNotNull(ecGet1 = wolfSSL_EVP_PKEY_get1_EC_KEY(pkey));
  64641. wolfSSL_EC_KEY_free(ecKey);
  64642. wolfSSL_EC_KEY_free(ecGet1);
  64643. EVP_PKEY_free(pkey);
  64644. #endif /* HAVE_ECC */
  64645. return EXPECT_RESULT();
  64646. } /* END test_EVP_PKEY_set1_get1_EC_KEY */
  64647. static int test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
  64648. {
  64649. EXPECT_DECLS;
  64650. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  64651. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  64652. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  64653. DH *dh = NULL;
  64654. DH *setDh = NULL;
  64655. EVP_PKEY *pkey = NULL;
  64656. XFILE f = XBADFILE;
  64657. unsigned char buf[4096];
  64658. const unsigned char* pt = buf;
  64659. const char* dh2048 = "./certs/dh2048.der";
  64660. long len = 0;
  64661. int code = -1;
  64662. XMEMSET(buf, 0, sizeof(buf));
  64663. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  64664. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  64665. if (f != XBADFILE)
  64666. XFCLOSE(f);
  64667. /* Load dh2048.der into DH with internal format */
  64668. ExpectNotNull(setDh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  64669. ExpectIntEQ(wolfSSL_DH_check(setDh, &code), WOLFSSL_SUCCESS);
  64670. ExpectIntEQ(code, 0);
  64671. code = -1;
  64672. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64673. /* Set DH into PKEY */
  64674. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  64675. /* Get DH from PKEY */
  64676. ExpectNotNull(dh = wolfSSL_EVP_PKEY_get1_DH(pkey));
  64677. ExpectIntEQ(wolfSSL_DH_check(dh, &code), WOLFSSL_SUCCESS);
  64678. ExpectIntEQ(code, 0);
  64679. EVP_PKEY_free(pkey);
  64680. DH_free(setDh);
  64681. setDh = NULL;
  64682. DH_free(dh);
  64683. dh = NULL;
  64684. #endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */
  64685. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  64686. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  64687. return EXPECT_RESULT();
  64688. } /* END test_EVP_PKEY_set1_get1_DH */
  64689. static int test_wolfSSL_CTX_ctrl(void)
  64690. {
  64691. EXPECT_DECLS;
  64692. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  64693. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64694. char caFile[] = "./certs/client-ca.pem";
  64695. char clientFile[] = "./certs/client-cert.pem";
  64696. SSL_CTX* ctx = NULL;
  64697. X509* x509 = NULL;
  64698. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  64699. byte buf[6000];
  64700. char file[] = "./certs/dsaparams.pem";
  64701. XFILE f = XBADFILE;
  64702. int bytes = 0;
  64703. BIO* bio = NULL;
  64704. DSA* dsa = NULL;
  64705. DH* dh = NULL;
  64706. #endif
  64707. #ifdef HAVE_ECC
  64708. WOLFSSL_EC_KEY* ecKey = NULL;
  64709. #endif
  64710. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  64711. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  64712. WOLFSSL_FILETYPE_PEM));
  64713. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  64714. if (EXPECT_FAIL()) {
  64715. wolfSSL_X509_free(x509);
  64716. }
  64717. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  64718. WOLFSSL_FILETYPE_PEM));
  64719. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  64720. /* Initialize DH */
  64721. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  64722. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  64723. if (f != XBADFILE)
  64724. XFCLOSE(f);
  64725. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  64726. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  64727. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  64728. #endif
  64729. #ifdef HAVE_ECC
  64730. /* Initialize WOLFSSL_EC_KEY */
  64731. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  64732. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  64733. #endif
  64734. /* additional test of getting EVP_PKEY key size from X509
  64735. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  64736. * allowed with user RSA */
  64737. {
  64738. EVP_PKEY* pkey = NULL;
  64739. #if defined(HAVE_ECC)
  64740. X509* ecX509 = NULL;
  64741. #endif /* HAVE_ECC */
  64742. ExpectNotNull(pkey = X509_get_pubkey(x509));
  64743. /* current RSA key is 2048 bit (256 bytes) */
  64744. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  64745. EVP_PKEY_free(pkey);
  64746. pkey = NULL;
  64747. #if defined(HAVE_ECC)
  64748. #if defined(USE_CERT_BUFFERS_256)
  64749. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  64750. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  64751. SSL_FILETYPE_ASN1));
  64752. #else
  64753. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  64754. cliEccCertFile, SSL_FILETYPE_PEM));
  64755. #endif
  64756. ExpectNotNull(pkey = X509_get_pubkey(ecX509));
  64757. /* current ECC key is 256 bit (32 bytes) */
  64758. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  64759. X509_free(ecX509);
  64760. EVP_PKEY_free(pkey);
  64761. #endif /* HAVE_ECC */
  64762. }
  64763. /* Tests should fail with passed in NULL pointer */
  64764. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, NULL),
  64765. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64766. #if !defined(NO_DH) && !defined(NO_DSA)
  64767. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, NULL),
  64768. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64769. #endif
  64770. #ifdef HAVE_ECC
  64771. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, NULL),
  64772. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64773. #endif
  64774. /* Test with SSL_CTRL_EXTRA_CHAIN_CERT
  64775. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_add_extra_chain_cert
  64776. */
  64777. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, x509),
  64778. SSL_SUCCESS);
  64779. if (EXPECT_FAIL()) {
  64780. wolfSSL_X509_free(x509);
  64781. }
  64782. /* Test with SSL_CTRL_OPTIONS
  64783. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_set_options
  64784. */
  64785. ExpectTrue(wolfSSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, SSL_OP_NO_TLSv1,
  64786. NULL) == SSL_OP_NO_TLSv1);
  64787. ExpectTrue(SSL_CTX_get_options(ctx) == SSL_OP_NO_TLSv1);
  64788. /* Test with SSL_CTRL_SET_TMP_DH
  64789. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_dh
  64790. */
  64791. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  64792. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh),
  64793. SSL_SUCCESS);
  64794. #endif
  64795. /* Test with SSL_CTRL_SET_TMP_ECDH
  64796. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_ecdh
  64797. */
  64798. #ifdef HAVE_ECC
  64799. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, ecKey),
  64800. SSL_SUCCESS);
  64801. #endif
  64802. #ifdef WOLFSSL_ENCRYPTED_KEYS
  64803. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  64804. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  64805. #endif
  64806. /* Test for min/max proto */
  64807. #ifndef WOLFSSL_NO_TLS12
  64808. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  64809. 0, NULL), SSL_SUCCESS);
  64810. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  64811. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  64812. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  64813. #endif
  64814. #ifdef WOLFSSL_TLS13
  64815. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  64816. 0, NULL), SSL_SUCCESS);
  64817. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  64818. TLS1_3_VERSION, NULL), SSL_SUCCESS);
  64819. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_3_VERSION);
  64820. #ifndef WOLFSSL_NO_TLS12
  64821. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  64822. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  64823. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
  64824. #endif
  64825. #endif
  64826. /* Cleanup and Pass */
  64827. #if !defined(NO_DH) && !defined(NO_DSA)
  64828. #ifndef NO_BIO
  64829. BIO_free(bio);
  64830. DSA_free(dsa);
  64831. DH_free(dh);
  64832. dh = NULL;
  64833. #endif
  64834. #endif
  64835. #ifdef HAVE_ECC
  64836. wolfSSL_EC_KEY_free(ecKey);
  64837. #endif
  64838. SSL_CTX_free(ctx);
  64839. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  64840. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  64841. return EXPECT_RESULT();
  64842. }
  64843. static int test_wolfSSL_EVP_PKEY_assign(void)
  64844. {
  64845. EXPECT_DECLS;
  64846. #if !defined(NO_RSA) || !defined(NO_DSA) || defined(HAVE_ECC)
  64847. int type;
  64848. WOLFSSL_EVP_PKEY* pkey = NULL;
  64849. #ifndef NO_RSA
  64850. WOLFSSL_RSA* rsa = NULL;
  64851. #endif
  64852. #ifndef NO_DSA
  64853. WOLFSSL_DSA* dsa = NULL;
  64854. #endif
  64855. #ifdef HAVE_ECC
  64856. WOLFSSL_EC_KEY* ecKey = NULL;
  64857. #endif
  64858. #ifndef NO_RSA
  64859. type = EVP_PKEY_RSA;
  64860. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64861. ExpectNotNull(rsa = wolfSSL_RSA_new());
  64862. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64863. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64864. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64865. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, rsa), WOLFSSL_SUCCESS);
  64866. if (EXPECT_FAIL()) {
  64867. wolfSSL_RSA_free(rsa);
  64868. }
  64869. wolfSSL_EVP_PKEY_free(pkey);
  64870. pkey = NULL;
  64871. #endif /* NO_RSA */
  64872. #ifndef NO_DSA
  64873. type = EVP_PKEY_DSA;
  64874. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64875. ExpectNotNull(dsa = wolfSSL_DSA_new());
  64876. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64877. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64878. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64879. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, dsa), WOLFSSL_SUCCESS);
  64880. if (EXPECT_FAIL()) {
  64881. wolfSSL_DSA_free(dsa);
  64882. }
  64883. wolfSSL_EVP_PKEY_free(pkey);
  64884. pkey = NULL;
  64885. #endif /* NO_DSA */
  64886. #ifdef HAVE_ECC
  64887. type = EVP_PKEY_EC;
  64888. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64889. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  64890. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64891. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64892. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64893. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64894. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  64895. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WOLFSSL_SUCCESS);
  64896. if (EXPECT_FAIL()) {
  64897. wolfSSL_EC_KEY_free(ecKey);
  64898. }
  64899. wolfSSL_EVP_PKEY_free(pkey);
  64900. pkey = NULL;
  64901. #endif /* HAVE_ECC */
  64902. #endif /* !NO_RSA || !NO_DSA || HAVE_ECC */
  64903. return EXPECT_RESULT();
  64904. }
  64905. static int test_wolfSSL_EVP_PKEY_assign_DH(void)
  64906. {
  64907. EXPECT_DECLS;
  64908. #if !defined(NO_DH) && \
  64909. !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  64910. XFILE f = XBADFILE;
  64911. unsigned char buf[4096];
  64912. const unsigned char* pt = buf;
  64913. const char* params1 = "./certs/dh2048.der";
  64914. long len = 0;
  64915. WOLFSSL_DH* dh = NULL;
  64916. WOLFSSL_EVP_PKEY* pkey = NULL;
  64917. XMEMSET(buf, 0, sizeof(buf));
  64918. /* Load DH parameters DER. */
  64919. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  64920. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  64921. if (f != XBADFILE)
  64922. XFCLOSE(f);
  64923. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  64924. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  64925. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64926. /* Bad cases */
  64927. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64928. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64929. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64930. /* Good case */
  64931. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, dh), WOLFSSL_SUCCESS);
  64932. if (EXPECT_FAIL()) {
  64933. wolfSSL_DH_free(dh);
  64934. }
  64935. EVP_PKEY_free(pkey);
  64936. #endif
  64937. return EXPECT_RESULT();
  64938. }
  64939. static int test_wolfSSL_EVP_PKEY_base_id(void)
  64940. {
  64941. EXPECT_DECLS;
  64942. WOLFSSL_EVP_PKEY* pkey = NULL;
  64943. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64944. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef);
  64945. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), EVP_PKEY_RSA);
  64946. EVP_PKEY_free(pkey);
  64947. return EXPECT_RESULT();
  64948. }
  64949. static int test_wolfSSL_EVP_PKEY_id(void)
  64950. {
  64951. EXPECT_DECLS;
  64952. WOLFSSL_EVP_PKEY* pkey = NULL;
  64953. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64954. ExpectIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0);
  64955. ExpectIntEQ(wolfSSL_EVP_PKEY_id(pkey), EVP_PKEY_RSA);
  64956. EVP_PKEY_free(pkey);
  64957. return EXPECT_RESULT();
  64958. }
  64959. static int test_wolfSSL_EVP_PKEY_paramgen(void)
  64960. {
  64961. EXPECT_DECLS;
  64962. /* ECC check taken from ecc.c. It is the condition that defines ECC256 */
  64963. #if defined(OPENSSL_ALL) && !defined(NO_ECC_SECP) && \
  64964. ((!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  64965. ECC_MIN_KEY_SZ <= 256)
  64966. EVP_PKEY_CTX* ctx = NULL;
  64967. EVP_PKEY* pkey = NULL;
  64968. /* Test error conditions. */
  64969. ExpectIntEQ(EVP_PKEY_paramgen(NULL, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64970. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  64971. ExpectIntEQ(EVP_PKEY_paramgen(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64972. #ifndef NO_RSA
  64973. EVP_PKEY_CTX_free(ctx);
  64974. /* Parameter generation for RSA not supported yet. */
  64975. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL));
  64976. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64977. #endif
  64978. #ifdef HAVE_ECC
  64979. EVP_PKEY_CTX_free(ctx);
  64980. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  64981. ExpectIntEQ(EVP_PKEY_paramgen_init(ctx), WOLFSSL_SUCCESS);
  64982. ExpectIntEQ(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx,
  64983. NID_X9_62_prime256v1), WOLFSSL_SUCCESS);
  64984. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WOLFSSL_SUCCESS);
  64985. ExpectIntEQ(EVP_PKEY_CTX_set_ec_param_enc(ctx, OPENSSL_EC_NAMED_CURVE),
  64986. WOLFSSL_SUCCESS);
  64987. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  64988. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  64989. #endif
  64990. EVP_PKEY_CTX_free(ctx);
  64991. EVP_PKEY_free(pkey);
  64992. #endif
  64993. return EXPECT_RESULT();
  64994. }
  64995. static int test_wolfSSL_EVP_PKEY_keygen(void)
  64996. {
  64997. EXPECT_DECLS;
  64998. WOLFSSL_EVP_PKEY* pkey = NULL;
  64999. EVP_PKEY_CTX* ctx = NULL;
  65000. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65001. WOLFSSL_EVP_PKEY* params = NULL;
  65002. DH* dh = NULL;
  65003. const BIGNUM* pubkey = NULL;
  65004. const BIGNUM* privkey = NULL;
  65005. ASN1_INTEGER* asn1int = NULL;
  65006. unsigned int length = 0;
  65007. byte* derBuffer = NULL;
  65008. #endif
  65009. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65010. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65011. /* Bad cases */
  65012. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, &pkey), 0);
  65013. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, NULL), 0);
  65014. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, NULL), 0);
  65015. /* Good case */
  65016. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, &pkey), 0);
  65017. EVP_PKEY_CTX_free(ctx);
  65018. ctx = NULL;
  65019. EVP_PKEY_free(pkey);
  65020. pkey = NULL;
  65021. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65022. /* Test DH keygen */
  65023. {
  65024. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65025. ExpectNotNull(dh = DH_get_2048_256());
  65026. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65027. ExpectNotNull(ctx = EVP_PKEY_CTX_new(params, NULL));
  65028. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65029. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  65030. DH_free(dh);
  65031. dh = NULL;
  65032. EVP_PKEY_CTX_free(ctx);
  65033. EVP_PKEY_free(params);
  65034. /* try exporting generated key to DER, to verify */
  65035. ExpectNotNull(dh = EVP_PKEY_get1_DH(pkey));
  65036. DH_get0_key(dh, &pubkey, &privkey);
  65037. ExpectNotNull(pubkey);
  65038. ExpectNotNull(privkey);
  65039. ExpectNotNull(asn1int = BN_to_ASN1_INTEGER(pubkey, NULL));
  65040. ExpectIntGT((length = i2d_ASN1_INTEGER(asn1int, &derBuffer)), 0);
  65041. ASN1_INTEGER_free(asn1int);
  65042. DH_free(dh);
  65043. dh = NULL;
  65044. XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  65045. EVP_PKEY_free(pkey);
  65046. }
  65047. #endif
  65048. return EXPECT_RESULT();
  65049. }
  65050. static int test_wolfSSL_EVP_PKEY_keygen_init(void)
  65051. {
  65052. EXPECT_DECLS;
  65053. WOLFSSL_EVP_PKEY* pkey = NULL;
  65054. EVP_PKEY_CTX *ctx = NULL;
  65055. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65056. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65057. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65058. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(NULL), WOLFSSL_SUCCESS);
  65059. EVP_PKEY_CTX_free(ctx);
  65060. EVP_PKEY_free(pkey);
  65061. return EXPECT_RESULT();
  65062. }
  65063. static int test_wolfSSL_EVP_PKEY_missing_parameters(void)
  65064. {
  65065. EXPECT_DECLS;
  65066. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_STUB)
  65067. WOLFSSL_EVP_PKEY* pkey = NULL;
  65068. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65069. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(pkey), 0);
  65070. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(NULL), 0);
  65071. EVP_PKEY_free(pkey);
  65072. #endif
  65073. return EXPECT_RESULT();
  65074. }
  65075. static int test_wolfSSL_EVP_PKEY_copy_parameters(void)
  65076. {
  65077. EXPECT_DECLS;
  65078. #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && defined(WOLFSSL_KEY_GEN) && \
  65079. !defined(HAVE_SELFTEST) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  65080. defined(WOLFSSL_OPENSSH)) && defined(WOLFSSL_DH_EXTRA) && \
  65081. !defined(NO_FILESYSTEM)
  65082. WOLFSSL_EVP_PKEY* params = NULL;
  65083. WOLFSSL_EVP_PKEY* copy = NULL;
  65084. DH* dh = NULL;
  65085. BIGNUM* p1;
  65086. BIGNUM* g1;
  65087. BIGNUM* q1;
  65088. BIGNUM* p2;
  65089. BIGNUM* g2;
  65090. BIGNUM* q2;
  65091. /* create DH with DH_get_2048_256 params */
  65092. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65093. ExpectNotNull(dh = DH_get_2048_256());
  65094. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65095. DH_get0_pqg(dh, (const BIGNUM**)&p1,
  65096. (const BIGNUM**)&q1,
  65097. (const BIGNUM**)&g1);
  65098. DH_free(dh);
  65099. dh = NULL;
  65100. /* create DH with random generated DH params */
  65101. ExpectNotNull(copy = wolfSSL_EVP_PKEY_new());
  65102. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  65103. ExpectIntEQ(EVP_PKEY_set1_DH(copy, dh), WOLFSSL_SUCCESS);
  65104. DH_free(dh);
  65105. dh = NULL;
  65106. ExpectIntEQ(EVP_PKEY_copy_parameters(copy, params), WOLFSSL_SUCCESS);
  65107. ExpectNotNull(dh = EVP_PKEY_get1_DH(copy));
  65108. ExpectNotNull(dh->p);
  65109. ExpectNotNull(dh->g);
  65110. ExpectNotNull(dh->q);
  65111. DH_get0_pqg(dh, (const BIGNUM**)&p2,
  65112. (const BIGNUM**)&q2,
  65113. (const BIGNUM**)&g2);
  65114. ExpectIntEQ(BN_cmp(p1, p2), 0);
  65115. ExpectIntEQ(BN_cmp(q1, q2), 0);
  65116. ExpectIntEQ(BN_cmp(g1, g2), 0);
  65117. DH_free(dh);
  65118. dh = NULL;
  65119. EVP_PKEY_free(copy);
  65120. EVP_PKEY_free(params);
  65121. #endif
  65122. return EXPECT_RESULT();
  65123. }
  65124. static int test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(void)
  65125. {
  65126. EXPECT_DECLS;
  65127. WOLFSSL_EVP_PKEY* pkey = NULL;
  65128. EVP_PKEY_CTX* ctx = NULL;
  65129. int bits = 2048;
  65130. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65131. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65132. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits),
  65133. WOLFSSL_SUCCESS);
  65134. EVP_PKEY_CTX_free(ctx);
  65135. EVP_PKEY_free(pkey);
  65136. return EXPECT_RESULT();
  65137. }
  65138. static int test_wolfSSL_EVP_CIPHER_CTX_iv_length(void)
  65139. {
  65140. EXPECT_DECLS;
  65141. /* This is large enough to be used for all key sizes */
  65142. byte key[AES_256_KEY_SIZE] = {0};
  65143. byte iv[AES_BLOCK_SIZE] = {0};
  65144. int i;
  65145. int nids[] = {
  65146. #ifdef HAVE_AES_CBC
  65147. NID_aes_128_cbc,
  65148. #endif
  65149. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65150. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65151. #ifdef HAVE_AESGCM
  65152. NID_aes_128_gcm,
  65153. #endif
  65154. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65155. #ifdef WOLFSSL_AES_COUNTER
  65156. NID_aes_128_ctr,
  65157. #endif
  65158. #ifndef NO_DES3
  65159. NID_des_cbc,
  65160. NID_des_ede3_cbc,
  65161. #endif
  65162. };
  65163. int iv_lengths[] = {
  65164. #ifdef HAVE_AES_CBC
  65165. AES_BLOCK_SIZE,
  65166. #endif
  65167. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65168. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65169. #ifdef HAVE_AESGCM
  65170. GCM_NONCE_MID_SZ,
  65171. #endif
  65172. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65173. #ifdef WOLFSSL_AES_COUNTER
  65174. AES_BLOCK_SIZE,
  65175. #endif
  65176. #ifndef NO_DES3
  65177. DES_BLOCK_SIZE,
  65178. DES_BLOCK_SIZE,
  65179. #endif
  65180. };
  65181. int nidsLen = (sizeof(nids)/sizeof(int));
  65182. for (i = 0; i < nidsLen; i++) {
  65183. const EVP_CIPHER* init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65184. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65185. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65186. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65187. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]);
  65188. EVP_CIPHER_CTX_free(ctx);
  65189. }
  65190. return EXPECT_RESULT();
  65191. }
  65192. static int test_wolfSSL_EVP_CIPHER_CTX_key_length(void)
  65193. {
  65194. EXPECT_DECLS;
  65195. byte key[AES_256_KEY_SIZE] = {0};
  65196. byte iv[AES_BLOCK_SIZE] = {0};
  65197. int i;
  65198. int nids[] = {
  65199. #ifdef HAVE_AES_CBC
  65200. NID_aes_128_cbc,
  65201. NID_aes_256_cbc,
  65202. #endif
  65203. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65204. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65205. #ifdef HAVE_AESGCM
  65206. NID_aes_128_gcm,
  65207. NID_aes_256_gcm,
  65208. #endif
  65209. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65210. #ifdef WOLFSSL_AES_COUNTER
  65211. NID_aes_128_ctr,
  65212. NID_aes_256_ctr,
  65213. #endif
  65214. #ifndef NO_DES3
  65215. NID_des_cbc,
  65216. NID_des_ede3_cbc,
  65217. #endif
  65218. };
  65219. int key_lengths[] = {
  65220. #ifdef HAVE_AES_CBC
  65221. AES_128_KEY_SIZE,
  65222. AES_256_KEY_SIZE,
  65223. #endif
  65224. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65225. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65226. #ifdef HAVE_AESGCM
  65227. AES_128_KEY_SIZE,
  65228. AES_256_KEY_SIZE,
  65229. #endif
  65230. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65231. #ifdef WOLFSSL_AES_COUNTER
  65232. AES_128_KEY_SIZE,
  65233. AES_256_KEY_SIZE,
  65234. #endif
  65235. #ifndef NO_DES3
  65236. DES_KEY_SIZE,
  65237. DES3_KEY_SIZE,
  65238. #endif
  65239. };
  65240. int nidsLen = (sizeof(nids)/sizeof(int));
  65241. for (i = 0; i < nidsLen; i++) {
  65242. const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65243. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65244. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65245. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65246. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), key_lengths[i]);
  65247. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, key_lengths[i]),
  65248. WOLFSSL_SUCCESS);
  65249. EVP_CIPHER_CTX_free(ctx);
  65250. }
  65251. return EXPECT_RESULT();
  65252. }
  65253. static int test_wolfSSL_EVP_CIPHER_CTX_set_iv(void)
  65254. {
  65255. EXPECT_DECLS;
  65256. #if defined(HAVE_AESGCM) && !defined(NO_DES3)
  65257. int ivLen, keyLen;
  65258. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  65259. #ifdef HAVE_AESGCM
  65260. byte key[AES_128_KEY_SIZE] = {0};
  65261. byte iv[AES_BLOCK_SIZE] = {0};
  65262. const EVP_CIPHER *init = EVP_aes_128_gcm();
  65263. #else
  65264. byte key[DES3_KEY_SIZE] = {0};
  65265. byte iv[DES_BLOCK_SIZE] = {0};
  65266. const EVP_CIPHER *init = EVP_des_ede3_cbc();
  65267. #endif
  65268. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65269. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65270. ivLen = wolfSSL_EVP_CIPHER_CTX_iv_length(ctx);
  65271. keyLen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx);
  65272. /* Bad cases */
  65273. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, iv, ivLen),
  65274. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65275. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, NULL, ivLen),
  65276. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65277. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65278. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65279. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, keyLen),
  65280. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65281. /* Good case */
  65282. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, ivLen), 1);
  65283. EVP_CIPHER_CTX_free(ctx);
  65284. #endif
  65285. return EXPECT_RESULT();
  65286. }
  65287. static int test_wolfSSL_EVP_PKEY_CTX_new_id(void)
  65288. {
  65289. EXPECT_DECLS;
  65290. WOLFSSL_ENGINE* e = NULL;
  65291. int id = 0;
  65292. EVP_PKEY_CTX *ctx = NULL;
  65293. ExpectNotNull(ctx = wolfSSL_EVP_PKEY_CTX_new_id(id, e));
  65294. EVP_PKEY_CTX_free(ctx);
  65295. return EXPECT_RESULT();
  65296. }
  65297. static int test_wolfSSL_EVP_rc4(void)
  65298. {
  65299. EXPECT_DECLS;
  65300. #if !defined(NO_RC4)
  65301. ExpectNotNull(wolfSSL_EVP_rc4());
  65302. #endif
  65303. return EXPECT_RESULT();
  65304. }
  65305. static int test_wolfSSL_EVP_enc_null(void)
  65306. {
  65307. EXPECT_DECLS;
  65308. ExpectNotNull(wolfSSL_EVP_enc_null());
  65309. return EXPECT_RESULT();
  65310. }
  65311. static int test_wolfSSL_EVP_rc2_cbc(void)
  65312. {
  65313. EXPECT_DECLS;
  65314. #if defined(WOLFSSL_QT) && !defined(NO_WOLFSSL_STUB)
  65315. ExpectNull(wolfSSL_EVP_rc2_cbc());
  65316. #endif
  65317. return EXPECT_RESULT();
  65318. }
  65319. static int test_wolfSSL_EVP_mdc2(void)
  65320. {
  65321. EXPECT_DECLS;
  65322. #if !defined(NO_WOLFSSL_STUB)
  65323. ExpectNull(wolfSSL_EVP_mdc2());
  65324. #endif
  65325. return EXPECT_RESULT();
  65326. }
  65327. static int test_wolfSSL_EVP_md4(void)
  65328. {
  65329. EXPECT_DECLS;
  65330. #if !defined(NO_MD4)
  65331. ExpectNotNull(wolfSSL_EVP_md4());
  65332. #endif
  65333. return EXPECT_RESULT();
  65334. }
  65335. static int test_wolfSSL_EVP_aes_256_gcm(void)
  65336. {
  65337. EXPECT_DECLS;
  65338. #ifdef HAVE_AESGCM
  65339. ExpectNotNull(wolfSSL_EVP_aes_256_gcm());
  65340. #endif
  65341. return EXPECT_RESULT();
  65342. }
  65343. static int test_wolfSSL_EVP_aes_192_gcm(void)
  65344. {
  65345. EXPECT_DECLS;
  65346. #ifdef HAVE_AESGCM
  65347. ExpectNotNull(wolfSSL_EVP_aes_192_gcm());
  65348. #endif
  65349. return EXPECT_RESULT();
  65350. }
  65351. static int test_wolfSSL_EVP_aes_256_ccm(void)
  65352. {
  65353. EXPECT_DECLS;
  65354. #ifdef HAVE_AESCCM
  65355. ExpectNotNull(wolfSSL_EVP_aes_256_ccm());
  65356. #endif
  65357. return EXPECT_RESULT();
  65358. }
  65359. static int test_wolfSSL_EVP_aes_192_ccm(void)
  65360. {
  65361. EXPECT_DECLS;
  65362. #ifdef HAVE_AESCCM
  65363. ExpectNotNull(wolfSSL_EVP_aes_192_ccm());
  65364. #endif
  65365. return EXPECT_RESULT();
  65366. }
  65367. static int test_wolfSSL_EVP_aes_128_ccm(void)
  65368. {
  65369. EXPECT_DECLS;
  65370. #ifdef HAVE_AESCCM
  65371. ExpectNotNull(wolfSSL_EVP_aes_128_ccm());
  65372. #endif
  65373. return EXPECT_RESULT();
  65374. }
  65375. static int test_wolfSSL_EVP_ripemd160(void)
  65376. {
  65377. EXPECT_DECLS;
  65378. #if !defined(NO_WOLFSSL_STUB)
  65379. ExpectNull(wolfSSL_EVP_ripemd160());
  65380. #endif
  65381. return EXPECT_RESULT();
  65382. }
  65383. static int test_wolfSSL_EVP_get_digestbynid(void)
  65384. {
  65385. EXPECT_DECLS;
  65386. #ifndef NO_MD5
  65387. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_md5));
  65388. #endif
  65389. #ifndef NO_SHA
  65390. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha1));
  65391. #endif
  65392. #ifndef NO_SHA256
  65393. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha256));
  65394. #endif
  65395. ExpectNull(wolfSSL_EVP_get_digestbynid(0));
  65396. return EXPECT_RESULT();
  65397. }
  65398. static int test_wolfSSL_EVP_MD_nid(void)
  65399. {
  65400. EXPECT_DECLS;
  65401. #ifndef NO_MD5
  65402. ExpectIntEQ(EVP_MD_nid(EVP_md5()), NID_md5);
  65403. #endif
  65404. #ifndef NO_SHA
  65405. ExpectIntEQ(EVP_MD_nid(EVP_sha1()), NID_sha1);
  65406. #endif
  65407. #ifndef NO_SHA256
  65408. ExpectIntEQ(EVP_MD_nid(EVP_sha256()), NID_sha256);
  65409. #endif
  65410. ExpectIntEQ(EVP_MD_nid(NULL), NID_undef);
  65411. return EXPECT_RESULT();
  65412. }
  65413. static int test_wolfSSL_EVP_PKEY_get0_EC_KEY(void)
  65414. {
  65415. EXPECT_DECLS;
  65416. #if defined(HAVE_ECC)
  65417. WOLFSSL_EVP_PKEY* pkey = NULL;
  65418. ExpectNull(EVP_PKEY_get0_EC_KEY(NULL));
  65419. ExpectNotNull(pkey = EVP_PKEY_new());
  65420. ExpectNull(EVP_PKEY_get0_EC_KEY(pkey));
  65421. EVP_PKEY_free(pkey);
  65422. #endif
  65423. return EXPECT_RESULT();
  65424. }
  65425. static int test_wolfSSL_EVP_X_STATE(void)
  65426. {
  65427. EXPECT_DECLS;
  65428. #if !defined(NO_DES3) && !defined(NO_RC4)
  65429. byte key[DES3_KEY_SIZE] = {0};
  65430. byte iv[DES_IV_SIZE] = {0};
  65431. EVP_CIPHER_CTX *ctx = NULL;
  65432. const EVP_CIPHER *init = NULL;
  65433. /* Bad test cases */
  65434. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65435. ExpectNotNull(init = EVP_des_ede3_cbc());
  65436. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65437. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65438. ExpectNull(wolfSSL_EVP_X_STATE(NULL));
  65439. ExpectNull(wolfSSL_EVP_X_STATE(ctx));
  65440. EVP_CIPHER_CTX_free(ctx);
  65441. ctx = NULL;
  65442. /* Good test case */
  65443. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65444. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65445. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65446. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65447. ExpectNotNull(wolfSSL_EVP_X_STATE(ctx));
  65448. EVP_CIPHER_CTX_free(ctx);
  65449. #endif
  65450. return EXPECT_RESULT();
  65451. }
  65452. static int test_wolfSSL_EVP_X_STATE_LEN(void)
  65453. {
  65454. EXPECT_DECLS;
  65455. #if !defined(NO_DES3) && !defined(NO_RC4)
  65456. byte key[DES3_KEY_SIZE] = {0};
  65457. byte iv[DES_IV_SIZE] = {0};
  65458. EVP_CIPHER_CTX *ctx = NULL;
  65459. const EVP_CIPHER *init = NULL;
  65460. /* Bad test cases */
  65461. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65462. ExpectNotNull(init = EVP_des_ede3_cbc());
  65463. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65464. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65465. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(NULL), 0);
  65466. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 0);
  65467. EVP_CIPHER_CTX_free(ctx);
  65468. ctx = NULL;
  65469. /* Good test case */
  65470. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65471. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65472. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65473. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65474. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), sizeof(Arc4));
  65475. EVP_CIPHER_CTX_free(ctx);
  65476. #endif
  65477. return EXPECT_RESULT();
  65478. }
  65479. static int test_wolfSSL_EVP_CIPHER_block_size(void)
  65480. {
  65481. EXPECT_DECLS;
  65482. #if defined(HAVE_AES_CBC) || defined(HAVE_AESGCM) || \
  65483. defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) || \
  65484. defined(WOLFSSL_AES_OFB) || !defined(NO_RC4) || \
  65485. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
  65486. #ifdef HAVE_AES_CBC
  65487. #ifdef WOLFSSL_AES_128
  65488. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_cbc()), AES_BLOCK_SIZE);
  65489. #endif
  65490. #ifdef WOLFSSL_AES_192
  65491. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_cbc()), AES_BLOCK_SIZE);
  65492. #endif
  65493. #ifdef WOLFSSL_AES_256
  65494. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_cbc()), AES_BLOCK_SIZE);
  65495. #endif
  65496. #endif
  65497. #ifdef HAVE_AESGCM
  65498. #ifdef WOLFSSL_AES_128
  65499. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_gcm()), 1);
  65500. #endif
  65501. #ifdef WOLFSSL_AES_192
  65502. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_gcm()), 1);
  65503. #endif
  65504. #ifdef WOLFSSL_AES_256
  65505. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_gcm()), 1);
  65506. #endif
  65507. #endif
  65508. #ifdef HAVE_AESCCM
  65509. #ifdef WOLFSSL_AES_128
  65510. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ccm()), 1);
  65511. #endif
  65512. #ifdef WOLFSSL_AES_192
  65513. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ccm()), 1);
  65514. #endif
  65515. #ifdef WOLFSSL_AES_256
  65516. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ccm()), 1);
  65517. #endif
  65518. #endif
  65519. #ifdef WOLFSSL_AES_COUNTER
  65520. #ifdef WOLFSSL_AES_128
  65521. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ctr()), 1);
  65522. #endif
  65523. #ifdef WOLFSSL_AES_192
  65524. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ctr()), 1);
  65525. #endif
  65526. #ifdef WOLFSSL_AES_256
  65527. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ctr()), 1);
  65528. #endif
  65529. #endif
  65530. #ifdef HAVE_AES_ECB
  65531. #ifdef WOLFSSL_AES_128
  65532. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ecb()), AES_BLOCK_SIZE);
  65533. #endif
  65534. #ifdef WOLFSSL_AES_192
  65535. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ecb()), AES_BLOCK_SIZE);
  65536. #endif
  65537. #ifdef WOLFSSL_AES_256
  65538. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ecb()), AES_BLOCK_SIZE);
  65539. #endif
  65540. #endif
  65541. #ifdef WOLFSSL_AES_OFB
  65542. #ifdef WOLFSSL_AES_128
  65543. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ofb()), 1);
  65544. #endif
  65545. #ifdef WOLFSSL_AES_192
  65546. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ofb()), 1);
  65547. #endif
  65548. #ifdef WOLFSSL_AES_256
  65549. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ofb()), 1);
  65550. #endif
  65551. #endif
  65552. #ifndef NO_RC4
  65553. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_rc4()), 1);
  65554. #endif
  65555. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  65556. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_chacha20_poly1305()), 1);
  65557. #endif
  65558. #endif
  65559. #ifdef WOLFSSL_SM4_ECB
  65560. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ecb()), SM4_BLOCK_SIZE);
  65561. #endif
  65562. #ifdef WOLFSSL_SM4_CBC
  65563. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_cbc()), SM4_BLOCK_SIZE);
  65564. #endif
  65565. #ifdef WOLFSSL_SM4_CTR
  65566. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ctr()), 1);
  65567. #endif
  65568. #ifdef WOLFSSL_SM4_GCM
  65569. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_gcm()), 1);
  65570. #endif
  65571. #ifdef WOLFSSL_SM4_CCM
  65572. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ccm()), 1);
  65573. #endif
  65574. return EXPECT_RESULT();
  65575. }
  65576. static int test_wolfSSL_EVP_CIPHER_iv_length(void)
  65577. {
  65578. EXPECT_DECLS;
  65579. int nids[] = {
  65580. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  65581. #ifdef WOLFSSL_AES_128
  65582. NID_aes_128_cbc,
  65583. #endif
  65584. #ifdef WOLFSSL_AES_192
  65585. NID_aes_192_cbc,
  65586. #endif
  65587. #ifdef WOLFSSL_AES_256
  65588. NID_aes_256_cbc,
  65589. #endif
  65590. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  65591. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65592. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65593. #ifdef HAVE_AESGCM
  65594. #ifdef WOLFSSL_AES_128
  65595. NID_aes_128_gcm,
  65596. #endif
  65597. #ifdef WOLFSSL_AES_192
  65598. NID_aes_192_gcm,
  65599. #endif
  65600. #ifdef WOLFSSL_AES_256
  65601. NID_aes_256_gcm,
  65602. #endif
  65603. #endif /* HAVE_AESGCM */
  65604. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65605. #ifdef WOLFSSL_AES_COUNTER
  65606. #ifdef WOLFSSL_AES_128
  65607. NID_aes_128_ctr,
  65608. #endif
  65609. #ifdef WOLFSSL_AES_192
  65610. NID_aes_192_ctr,
  65611. #endif
  65612. #ifdef WOLFSSL_AES_256
  65613. NID_aes_256_ctr,
  65614. #endif
  65615. #endif
  65616. #ifndef NO_DES3
  65617. NID_des_cbc,
  65618. NID_des_ede3_cbc,
  65619. #endif
  65620. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  65621. NID_chacha20_poly1305,
  65622. #endif
  65623. };
  65624. int iv_lengths[] = {
  65625. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  65626. #ifdef WOLFSSL_AES_128
  65627. AES_BLOCK_SIZE,
  65628. #endif
  65629. #ifdef WOLFSSL_AES_192
  65630. AES_BLOCK_SIZE,
  65631. #endif
  65632. #ifdef WOLFSSL_AES_256
  65633. AES_BLOCK_SIZE,
  65634. #endif
  65635. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  65636. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65637. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65638. #ifdef HAVE_AESGCM
  65639. #ifdef WOLFSSL_AES_128
  65640. GCM_NONCE_MID_SZ,
  65641. #endif
  65642. #ifdef WOLFSSL_AES_192
  65643. GCM_NONCE_MID_SZ,
  65644. #endif
  65645. #ifdef WOLFSSL_AES_256
  65646. GCM_NONCE_MID_SZ,
  65647. #endif
  65648. #endif /* HAVE_AESGCM */
  65649. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65650. #ifdef WOLFSSL_AES_COUNTER
  65651. #ifdef WOLFSSL_AES_128
  65652. AES_BLOCK_SIZE,
  65653. #endif
  65654. #ifdef WOLFSSL_AES_192
  65655. AES_BLOCK_SIZE,
  65656. #endif
  65657. #ifdef WOLFSSL_AES_256
  65658. AES_BLOCK_SIZE,
  65659. #endif
  65660. #endif
  65661. #ifndef NO_DES3
  65662. DES_BLOCK_SIZE,
  65663. DES_BLOCK_SIZE,
  65664. #endif
  65665. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  65666. CHACHA20_POLY1305_AEAD_IV_SIZE,
  65667. #endif
  65668. };
  65669. int i;
  65670. int nidsLen = (sizeof(nids)/sizeof(int));
  65671. for (i = 0; i < nidsLen; i++) {
  65672. const EVP_CIPHER *c = EVP_get_cipherbynid(nids[i]);
  65673. ExpectIntEQ(EVP_CIPHER_iv_length(c), iv_lengths[i]);
  65674. }
  65675. return EXPECT_RESULT();
  65676. }
  65677. static int test_wolfSSL_EVP_SignInit_ex(void)
  65678. {
  65679. EXPECT_DECLS;
  65680. WOLFSSL_EVP_MD_CTX mdCtx;
  65681. WOLFSSL_ENGINE* e = 0;
  65682. const EVP_MD* md = EVP_sha256();
  65683. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65684. ExpectIntEQ(wolfSSL_EVP_SignInit_ex(&mdCtx, md, e), WOLFSSL_SUCCESS);
  65685. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  65686. return EXPECT_RESULT();
  65687. }
  65688. static int test_wolfSSL_EVP_DigestFinal_ex(void)
  65689. {
  65690. EXPECT_DECLS;
  65691. #if !defined(NO_SHA256)
  65692. WOLFSSL_EVP_MD_CTX mdCtx;
  65693. unsigned int s = 0;
  65694. unsigned char md[WC_SHA256_DIGEST_SIZE];
  65695. unsigned char md2[WC_SHA256_DIGEST_SIZE];
  65696. /* Bad Case */
  65697. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  65698. (HAVE_FIPS_VERSION > 2))
  65699. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65700. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0);
  65701. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  65702. #else
  65703. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65704. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), WOLFSSL_SUCCESS);
  65705. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  65706. #endif
  65707. /* Good Case */
  65708. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65709. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, EVP_sha256()), WOLFSSL_SUCCESS);
  65710. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md2, &s), WOLFSSL_SUCCESS);
  65711. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  65712. #endif
  65713. return EXPECT_RESULT();
  65714. }
  65715. static int test_wolfSSL_QT_EVP_PKEY_CTX_free(void)
  65716. {
  65717. EXPECT_DECLS;
  65718. #if defined(OPENSSL_EXTRA)
  65719. EVP_PKEY* pkey = NULL;
  65720. EVP_PKEY_CTX* ctx = NULL;
  65721. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65722. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65723. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  65724. /* void */
  65725. EVP_PKEY_CTX_free(ctx);
  65726. #else
  65727. /* int */
  65728. ExpectIntEQ(EVP_PKEY_CTX_free(ctx), WOLFSSL_SUCCESS);
  65729. #endif
  65730. EVP_PKEY_free(pkey);
  65731. #endif
  65732. return EXPECT_RESULT();
  65733. }
  65734. static int test_wolfSSL_EVP_PKEY_param_check(void)
  65735. {
  65736. EXPECT_DECLS;
  65737. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  65738. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  65739. DH *dh = NULL;
  65740. DH *setDh = NULL;
  65741. EVP_PKEY *pkey = NULL;
  65742. EVP_PKEY_CTX* ctx = NULL;
  65743. FILE* f = NULL;
  65744. unsigned char buf[512];
  65745. const unsigned char* pt = buf;
  65746. const char* dh2048 = "./certs/dh2048.der";
  65747. long len = 0;
  65748. int code = -1;
  65749. XMEMSET(buf, 0, sizeof(buf));
  65750. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  65751. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65752. if (f != XBADFILE)
  65753. XFCLOSE(f);
  65754. /* Load dh2048.der into DH with internal format */
  65755. ExpectNotNull(setDh = d2i_DHparams(NULL, &pt, len));
  65756. ExpectIntEQ(DH_check(setDh, &code), WOLFSSL_SUCCESS);
  65757. ExpectIntEQ(code, 0);
  65758. code = -1;
  65759. pkey = wolfSSL_EVP_PKEY_new();
  65760. /* Set DH into PKEY */
  65761. ExpectIntEQ(EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  65762. /* create ctx from pkey */
  65763. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65764. ExpectIntEQ(EVP_PKEY_param_check(ctx), 1/* valid */);
  65765. /* TODO: more invalid cases */
  65766. ExpectIntEQ(EVP_PKEY_param_check(NULL), 0);
  65767. EVP_PKEY_CTX_free(ctx);
  65768. EVP_PKEY_free(pkey);
  65769. DH_free(setDh);
  65770. setDh = NULL;
  65771. DH_free(dh);
  65772. dh = NULL;
  65773. #endif
  65774. #endif
  65775. return EXPECT_RESULT();
  65776. }
  65777. static int test_wolfSSL_EVP_BytesToKey(void)
  65778. {
  65779. EXPECT_DECLS;
  65780. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  65781. byte key[AES_BLOCK_SIZE] = {0};
  65782. byte iv[AES_BLOCK_SIZE] = {0};
  65783. int count = 0;
  65784. const EVP_MD* md = EVP_sha256();
  65785. const EVP_CIPHER *type;
  65786. const unsigned char *salt = (unsigned char *)"salt1234";
  65787. int sz = 5;
  65788. const byte data[] = {
  65789. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  65790. 0x72,0x6c,0x64
  65791. };
  65792. type = wolfSSL_EVP_get_cipherbynid(NID_aes_128_cbc);
  65793. /* Bad cases */
  65794. ExpectIntEQ(EVP_BytesToKey(NULL, md, salt, data, sz, count, key, iv),
  65795. 0);
  65796. ExpectIntEQ(EVP_BytesToKey(type, md, salt, NULL, sz, count, key, iv),
  65797. 16);
  65798. md = "2";
  65799. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  65800. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65801. /* Good case */
  65802. md = EVP_sha256();
  65803. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  65804. 16);
  65805. #endif
  65806. return EXPECT_RESULT();
  65807. }
  65808. static int test_evp_cipher_aes_gcm(void)
  65809. {
  65810. EXPECT_DECLS;
  65811. #if defined(HAVE_AESGCM) && ((!defined(HAVE_FIPS) && \
  65812. !defined(HAVE_SELFTEST)) || (defined(HAVE_FIPS_VERSION) && \
  65813. (HAVE_FIPS_VERSION >= 2)))
  65814. /*
  65815. * This test checks data at various points in the encrypt/decrypt process
  65816. * against known values produced using the same test with OpenSSL. This
  65817. * interop testing is critical for verifying the correctness of our
  65818. * EVP_Cipher implementation with AES-GCM. Specifically, this test exercises
  65819. * a flow supported by OpenSSL that uses the control command
  65820. * EVP_CTRL_GCM_IV_GEN to increment the IV between cipher operations without
  65821. * the need to call EVP_CipherInit. OpenSSH uses this flow, for example. We
  65822. * had a bug with OpenSSH where wolfSSL OpenSSH servers could only talk to
  65823. * wolfSSL OpenSSH clients because there was a bug in this flow that
  65824. * happened to "cancel out" if both sides of the connection had the bug.
  65825. */
  65826. enum {
  65827. NUM_ENCRYPTIONS = 3,
  65828. AAD_SIZE = 4
  65829. };
  65830. byte plainText1[] = {
  65831. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  65832. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  65833. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
  65834. };
  65835. byte plainText2[] = {
  65836. 0x42, 0x49, 0x3b, 0x27, 0x03, 0x35, 0x59, 0x14, 0x41, 0x47, 0x37, 0x14,
  65837. 0x0e, 0x34, 0x0d, 0x28, 0x63, 0x09, 0x0a, 0x5b, 0x22, 0x57, 0x42, 0x22,
  65838. 0x0f, 0x5c, 0x1e, 0x53, 0x45, 0x15, 0x62, 0x08, 0x60, 0x43, 0x50, 0x2c
  65839. };
  65840. byte plainText3[] = {
  65841. 0x36, 0x0d, 0x2b, 0x09, 0x4a, 0x56, 0x3b, 0x4c, 0x21, 0x22, 0x58, 0x0e,
  65842. 0x5b, 0x57, 0x10
  65843. };
  65844. byte* plainTexts[NUM_ENCRYPTIONS] = {
  65845. plainText1,
  65846. plainText2,
  65847. plainText3
  65848. };
  65849. const int plainTextSzs[NUM_ENCRYPTIONS] = {
  65850. sizeof(plainText1),
  65851. sizeof(plainText2),
  65852. sizeof(plainText3)
  65853. };
  65854. byte aad1[AAD_SIZE] = {
  65855. 0x00, 0x00, 0x00, 0x01
  65856. };
  65857. byte aad2[AAD_SIZE] = {
  65858. 0x00, 0x00, 0x00, 0x10
  65859. };
  65860. byte aad3[AAD_SIZE] = {
  65861. 0x00, 0x00, 0x01, 0x00
  65862. };
  65863. byte* aads[NUM_ENCRYPTIONS] = {
  65864. aad1,
  65865. aad2,
  65866. aad3
  65867. };
  65868. const byte iv[GCM_NONCE_MID_SZ] = {
  65869. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  65870. };
  65871. byte currentIv[GCM_NONCE_MID_SZ];
  65872. const byte key[] = {
  65873. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  65874. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  65875. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  65876. };
  65877. const byte expIvs[NUM_ENCRYPTIONS][GCM_NONCE_MID_SZ] = {
  65878. {
  65879. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  65880. 0xEF
  65881. },
  65882. {
  65883. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  65884. 0xF0
  65885. },
  65886. {
  65887. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  65888. 0xF1
  65889. }
  65890. };
  65891. const byte expTags[NUM_ENCRYPTIONS][AES_BLOCK_SIZE] = {
  65892. {
  65893. 0x65, 0x4F, 0xF7, 0xA0, 0xBB, 0x7B, 0x90, 0xB7, 0x9C, 0xC8, 0x14,
  65894. 0x3D, 0x32, 0x18, 0x34, 0xA9
  65895. },
  65896. {
  65897. 0x50, 0x3A, 0x13, 0x8D, 0x91, 0x1D, 0xEC, 0xBB, 0xBA, 0x5B, 0x57,
  65898. 0xA2, 0xFD, 0x2D, 0x6B, 0x7F
  65899. },
  65900. {
  65901. 0x3B, 0xED, 0x18, 0x9C, 0xB3, 0xE3, 0x61, 0x1E, 0x11, 0xEB, 0x13,
  65902. 0x5B, 0xEC, 0x52, 0x49, 0x32,
  65903. }
  65904. };
  65905. const byte expCipherText1[] = {
  65906. 0xCB, 0x93, 0x4F, 0xC8, 0x22, 0xE2, 0xC0, 0x35, 0xAA, 0x6B, 0x41, 0x15,
  65907. 0x17, 0x30, 0x2F, 0x97, 0x20, 0x74, 0x39, 0x28, 0xF8, 0xEB, 0xC5, 0x51,
  65908. 0x7B, 0xD9, 0x8A, 0x36, 0xB8, 0xDA, 0x24, 0x80, 0xE7, 0x9E, 0x09, 0xDE
  65909. };
  65910. const byte expCipherText2[] = {
  65911. 0xF9, 0x32, 0xE1, 0x87, 0x37, 0x0F, 0x04, 0xC1, 0xB5, 0x59, 0xF0, 0x45,
  65912. 0x3A, 0x0D, 0xA0, 0x26, 0xFF, 0xA6, 0x8D, 0x38, 0xFE, 0xB8, 0xE5, 0xC2,
  65913. 0x2A, 0x98, 0x4A, 0x54, 0x8F, 0x1F, 0xD6, 0x13, 0x03, 0xB2, 0x1B, 0xC0
  65914. };
  65915. const byte expCipherText3[] = {
  65916. 0xD0, 0x37, 0x59, 0x1C, 0x2F, 0x85, 0x39, 0x4D, 0xED, 0xC2, 0x32, 0x5B,
  65917. 0x80, 0x5E, 0x6B,
  65918. };
  65919. const byte* expCipherTexts[NUM_ENCRYPTIONS] = {
  65920. expCipherText1,
  65921. expCipherText2,
  65922. expCipherText3
  65923. };
  65924. byte* cipherText = NULL;
  65925. byte* calcPlainText = NULL;
  65926. byte tag[AES_BLOCK_SIZE];
  65927. EVP_CIPHER_CTX* encCtx = NULL;
  65928. EVP_CIPHER_CTX* decCtx = NULL;
  65929. int i, j, outl;
  65930. /****************************************************/
  65931. for (i = 0; i < 3; ++i) {
  65932. ExpectNotNull(encCtx = EVP_CIPHER_CTX_new());
  65933. ExpectNotNull(decCtx = EVP_CIPHER_CTX_new());
  65934. /* First iteration, set key before IV. */
  65935. if (i == 0) {
  65936. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), key, NULL, 1),
  65937. SSL_SUCCESS);
  65938. /*
  65939. * The call to EVP_CipherInit below (with NULL key) should clear the
  65940. * authIvGenEnable flag set by EVP_CTRL_GCM_SET_IV_FIXED. As such, a
  65941. * subsequent EVP_CTRL_GCM_IV_GEN should fail. This matches OpenSSL
  65942. * behavior.
  65943. */
  65944. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  65945. (void*)iv), SSL_SUCCESS);
  65946. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, NULL, iv, 1),
  65947. SSL_SUCCESS);
  65948. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  65949. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65950. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), key, NULL, 0),
  65951. SSL_SUCCESS);
  65952. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, NULL, iv, 0),
  65953. SSL_SUCCESS);
  65954. }
  65955. /* Second iteration, IV before key. */
  65956. else {
  65957. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), NULL, iv, 1),
  65958. SSL_SUCCESS);
  65959. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, key, NULL, 1),
  65960. SSL_SUCCESS);
  65961. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), NULL, iv, 0),
  65962. SSL_SUCCESS);
  65963. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, key, NULL, 0),
  65964. SSL_SUCCESS);
  65965. }
  65966. /*
  65967. * EVP_CTRL_GCM_IV_GEN should fail if EVP_CTRL_GCM_SET_IV_FIXED hasn't
  65968. * been issued first.
  65969. */
  65970. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  65971. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65972. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  65973. (void*)iv), SSL_SUCCESS);
  65974. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  65975. (void*)iv), SSL_SUCCESS);
  65976. for (j = 0; j < NUM_ENCRYPTIONS; ++j) {
  65977. /*************** Encrypt ***************/
  65978. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  65979. currentIv), SSL_SUCCESS);
  65980. /* Check current IV against expected. */
  65981. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  65982. /* Add AAD. */
  65983. if (i == 2) {
  65984. /* Test streaming API. */
  65985. ExpectIntEQ(EVP_CipherUpdate(encCtx, NULL, &outl, aads[j],
  65986. AAD_SIZE), SSL_SUCCESS);
  65987. }
  65988. else {
  65989. ExpectIntEQ(EVP_Cipher(encCtx, NULL, aads[j], AAD_SIZE),
  65990. AAD_SIZE);
  65991. }
  65992. ExpectNotNull(cipherText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  65993. DYNAMIC_TYPE_TMP_BUFFER));
  65994. /* Encrypt plaintext. */
  65995. if (i == 2) {
  65996. ExpectIntEQ(EVP_CipherUpdate(encCtx, cipherText, &outl,
  65997. plainTexts[j], plainTextSzs[j]),
  65998. SSL_SUCCESS);
  65999. }
  66000. else {
  66001. ExpectIntEQ(EVP_Cipher(encCtx, cipherText, plainTexts[j],
  66002. plainTextSzs[j]), plainTextSzs[j]);
  66003. }
  66004. if (i == 2) {
  66005. ExpectIntEQ(EVP_CipherFinal(encCtx, cipherText, &outl),
  66006. SSL_SUCCESS);
  66007. }
  66008. else {
  66009. /*
  66010. * Calling EVP_Cipher with NULL input and output for AES-GCM is
  66011. * akin to calling EVP_CipherFinal.
  66012. */
  66013. ExpectIntGE(EVP_Cipher(encCtx, NULL, NULL, 0), 0);
  66014. }
  66015. /* Check ciphertext against expected. */
  66016. ExpectIntEQ(XMEMCMP(cipherText, expCipherTexts[j], plainTextSzs[j]),
  66017. 0);
  66018. /* Get and check tag against expected. */
  66019. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_GET_TAG,
  66020. sizeof(tag), tag), SSL_SUCCESS);
  66021. ExpectIntEQ(XMEMCMP(tag, expTags[j], sizeof(tag)), 0);
  66022. /*************** Decrypt ***************/
  66023. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66024. currentIv), SSL_SUCCESS);
  66025. /* Check current IV against expected. */
  66026. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  66027. /* Add AAD. */
  66028. if (i == 2) {
  66029. /* Test streaming API. */
  66030. ExpectIntEQ(EVP_CipherUpdate(decCtx, NULL, &outl, aads[j],
  66031. AAD_SIZE), SSL_SUCCESS);
  66032. }
  66033. else {
  66034. ExpectIntEQ(EVP_Cipher(decCtx, NULL, aads[j], AAD_SIZE),
  66035. AAD_SIZE);
  66036. }
  66037. /* Set expected tag. */
  66038. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_TAG,
  66039. sizeof(tag), tag), SSL_SUCCESS);
  66040. /* Decrypt ciphertext. */
  66041. ExpectNotNull(calcPlainText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  66042. DYNAMIC_TYPE_TMP_BUFFER));
  66043. if (i == 2) {
  66044. ExpectIntEQ(EVP_CipherUpdate(decCtx, calcPlainText, &outl,
  66045. cipherText, plainTextSzs[j]),
  66046. SSL_SUCCESS);
  66047. }
  66048. else {
  66049. /* This first EVP_Cipher call will check the tag, too. */
  66050. ExpectIntEQ(EVP_Cipher(decCtx, calcPlainText, cipherText,
  66051. plainTextSzs[j]), plainTextSzs[j]);
  66052. }
  66053. if (i == 2) {
  66054. ExpectIntEQ(EVP_CipherFinal(decCtx, calcPlainText, &outl),
  66055. SSL_SUCCESS);
  66056. }
  66057. else {
  66058. ExpectIntGE(EVP_Cipher(decCtx, NULL, NULL, 0), 0);
  66059. }
  66060. /* Check plaintext against expected. */
  66061. ExpectIntEQ(XMEMCMP(calcPlainText, plainTexts[j], plainTextSzs[j]),
  66062. 0);
  66063. XFREE(cipherText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66064. cipherText = NULL;
  66065. XFREE(calcPlainText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66066. calcPlainText = NULL;
  66067. }
  66068. EVP_CIPHER_CTX_free(encCtx);
  66069. encCtx = NULL;
  66070. EVP_CIPHER_CTX_free(decCtx);
  66071. decCtx = NULL;
  66072. }
  66073. #endif
  66074. return EXPECT_RESULT();
  66075. }
  66076. static int test_wolfSSL_OBJ_ln(void)
  66077. {
  66078. EXPECT_DECLS;
  66079. const int nid_set[] = {
  66080. NID_commonName,
  66081. NID_serialNumber,
  66082. NID_countryName,
  66083. NID_localityName,
  66084. NID_stateOrProvinceName,
  66085. NID_organizationName,
  66086. NID_organizationalUnitName,
  66087. NID_domainComponent,
  66088. NID_businessCategory,
  66089. NID_jurisdictionCountryName,
  66090. NID_jurisdictionStateOrProvinceName,
  66091. NID_emailAddress
  66092. };
  66093. const char* ln_set[] = {
  66094. "commonName",
  66095. "serialNumber",
  66096. "countryName",
  66097. "localityName",
  66098. "stateOrProvinceName",
  66099. "organizationName",
  66100. "organizationalUnitName",
  66101. "domainComponent",
  66102. "businessCategory",
  66103. "jurisdictionCountryName",
  66104. "jurisdictionStateOrProvinceName",
  66105. "emailAddress",
  66106. };
  66107. size_t i = 0, maxIdx = sizeof(ln_set)/sizeof(char*);
  66108. ExpectIntEQ(OBJ_ln2nid(NULL), NID_undef);
  66109. #ifdef HAVE_ECC
  66110. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  66111. {
  66112. EC_builtin_curve r[27];
  66113. size_t nCurves = sizeof(r) / sizeof(r[0]);
  66114. nCurves = EC_get_builtin_curves(r, nCurves);
  66115. for (i = 0; i < nCurves; i++) {
  66116. /* skip ECC_CURVE_INVALID */
  66117. if (r[i].nid != ECC_CURVE_INVALID) {
  66118. ExpectIntEQ(OBJ_ln2nid(r[i].comment), r[i].nid);
  66119. ExpectStrEQ(OBJ_nid2ln(r[i].nid), r[i].comment);
  66120. }
  66121. }
  66122. }
  66123. #endif
  66124. #endif
  66125. for (i = 0; i < maxIdx; i++) {
  66126. ExpectIntEQ(OBJ_ln2nid(ln_set[i]), nid_set[i]);
  66127. ExpectStrEQ(OBJ_nid2ln(nid_set[i]), ln_set[i]);
  66128. }
  66129. return EXPECT_RESULT();
  66130. }
  66131. static int test_wolfSSL_OBJ_sn(void)
  66132. {
  66133. EXPECT_DECLS;
  66134. int i = 0, maxIdx = 7;
  66135. const int nid_set[] = {NID_commonName,NID_countryName,NID_localityName,
  66136. NID_stateOrProvinceName,NID_organizationName,
  66137. NID_organizationalUnitName,NID_emailAddress};
  66138. const char* sn_open_set[] = {"CN","C","L","ST","O","OU","emailAddress"};
  66139. const char* sn_wolf_set[] = {WOLFSSL_COMMON_NAME,WOLFSSL_COUNTRY_NAME,
  66140. WOLFSSL_LOCALITY_NAME, WOLFSSL_STATE_NAME,
  66141. WOLFSSL_ORG_NAME, WOLFSSL_ORGUNIT_NAME,
  66142. WOLFSSL_EMAIL_ADDR};
  66143. ExpectIntEQ(wolfSSL_OBJ_sn2nid(NULL), NID_undef);
  66144. for (i = 0; i < maxIdx; i++) {
  66145. ExpectIntEQ(wolfSSL_OBJ_sn2nid(sn_wolf_set[i]), nid_set[i]);
  66146. ExpectStrEQ(wolfSSL_OBJ_nid2sn(nid_set[i]), sn_open_set[i]);
  66147. }
  66148. return EXPECT_RESULT();
  66149. }
  66150. #if !defined(NO_BIO)
  66151. static unsigned long TXT_DB_hash(const WOLFSSL_STRING *s)
  66152. {
  66153. return lh_strhash(s[3]);
  66154. }
  66155. static int TXT_DB_cmp(const WOLFSSL_STRING *a, const WOLFSSL_STRING *b)
  66156. {
  66157. return XSTRCMP(a[3], b[3]);
  66158. }
  66159. #endif
  66160. static int test_wolfSSL_TXT_DB(void)
  66161. {
  66162. EXPECT_DECLS;
  66163. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66164. BIO *bio = NULL;
  66165. TXT_DB *db = NULL;
  66166. const int columns = 6;
  66167. const char *fields[6] = {
  66168. "V",
  66169. "320926161116Z",
  66170. "",
  66171. "12BD",
  66172. "unknown",
  66173. "/CN=rsa doe",
  66174. };
  66175. char** fields_copy = NULL;
  66176. /* Test read */
  66177. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  66178. ExpectIntGT(BIO_read_filename(bio, "./tests/TXT_DB.txt"), 0);
  66179. ExpectNotNull(db = TXT_DB_read(bio, columns));
  66180. ExpectNotNull(fields_copy = (char**)XMALLOC(sizeof(fields), NULL,
  66181. DYNAMIC_TYPE_OPENSSL));
  66182. if (fields_copy != NULL) {
  66183. XMEMCPY(fields_copy, fields, sizeof(fields));
  66184. }
  66185. ExpectIntEQ(TXT_DB_insert(db, fields_copy), 1);
  66186. if (EXPECT_FAIL()) {
  66187. XFREE(fields_copy, NULL, DYNAMIC_TYPE_OPENSSL);
  66188. }
  66189. BIO_free(bio);
  66190. bio = NULL;
  66191. /* Test write */
  66192. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  66193. ExpectIntEQ(TXT_DB_write(bio, db), 1484);
  66194. BIO_free(bio);
  66195. /* Test index */
  66196. ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, (wolf_sk_hash_cb)TXT_DB_hash,
  66197. (wolf_lh_compare_cb)TXT_DB_cmp), 1);
  66198. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66199. fields[3] = "12DA";
  66200. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66201. fields[3] = "FFFF";
  66202. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66203. fields[3] = "";
  66204. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66205. TXT_DB_free(db);
  66206. #endif
  66207. return EXPECT_RESULT();
  66208. }
  66209. static int test_wolfSSL_NCONF(void)
  66210. {
  66211. EXPECT_DECLS;
  66212. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66213. const char* confFile = "./tests/NCONF_test.cnf";
  66214. CONF* conf = NULL;
  66215. long eline = 0;
  66216. long num = 0;
  66217. ExpectNotNull(conf = NCONF_new(NULL));
  66218. ExpectIntEQ(NCONF_load(conf, confFile, &eline), 1);
  66219. ExpectIntEQ(NCONF_get_number(conf, NULL, "port", &num), 1);
  66220. ExpectIntEQ(num, 1234);
  66221. ExpectIntEQ(NCONF_get_number(conf, "section2", "port", &num), 1);
  66222. ExpectIntEQ(num, 4321);
  66223. ExpectStrEQ(NCONF_get_string(conf, NULL, "dir"), "./test-dir");
  66224. ExpectStrEQ(NCONF_get_string(conf, "section1", "file1_copy"),
  66225. "./test-dir/file1");
  66226. ExpectStrEQ(NCONF_get_string(conf, "section2", "file_list"),
  66227. "./test-dir/file1:./test-dir/file2:./section1:file2");
  66228. NCONF_free(conf);
  66229. #endif
  66230. return EXPECT_RESULT();
  66231. }
  66232. #endif /* OPENSSL_ALL */
  66233. static int test_wolfSSL_X509V3_EXT_get(void) {
  66234. EXPECT_DECLS;
  66235. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66236. XFILE f = XBADFILE;
  66237. int numOfExt =0;
  66238. int extNid = 0;
  66239. int i = 0;
  66240. WOLFSSL_X509* x509 = NULL;
  66241. WOLFSSL_X509_EXTENSION* ext = NULL;
  66242. const WOLFSSL_v3_ext_method* method = NULL;
  66243. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66244. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66245. if (f != XBADFILE)
  66246. XFCLOSE(f);
  66247. /* wolfSSL_X509V3_EXT_get() return struct and nid test */
  66248. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66249. for (i = 0; i < numOfExt; i++) {
  66250. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66251. ExpectIntNE((extNid = ext->obj->nid), NID_undef);
  66252. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66253. ExpectIntEQ(method->ext_nid, extNid);
  66254. }
  66255. /* wolfSSL_X509V3_EXT_get() NULL argument test */
  66256. ExpectNull(method = wolfSSL_X509V3_EXT_get(NULL));
  66257. wolfSSL_X509_free(x509);
  66258. #endif
  66259. return EXPECT_RESULT();
  66260. }
  66261. static int test_wolfSSL_X509V3_EXT_nconf(void)
  66262. {
  66263. EXPECT_DECLS;
  66264. #ifdef OPENSSL_ALL
  66265. const char *ext_names[] = {
  66266. "subjectKeyIdentifier",
  66267. "authorityKeyIdentifier",
  66268. "subjectAltName",
  66269. "keyUsage",
  66270. "extendedKeyUsage",
  66271. };
  66272. size_t ext_names_count = sizeof(ext_names)/sizeof(*ext_names);
  66273. int ext_nids[] = {
  66274. NID_subject_key_identifier,
  66275. NID_authority_key_identifier,
  66276. NID_subject_alt_name,
  66277. NID_key_usage,
  66278. NID_ext_key_usage,
  66279. };
  66280. size_t ext_nids_count = sizeof(ext_nids)/sizeof(*ext_nids);
  66281. const char *ext_values[] = {
  66282. "hash",
  66283. "hash",
  66284. "DNS:example.com, IP:127.0.0.1",
  66285. "digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,"
  66286. "keyAgreement,keyCertSign,cRLSign,encipherOnly,decipherOnly",
  66287. "serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,"
  66288. "OCSPSigning",
  66289. };
  66290. size_t i;
  66291. X509_EXTENSION* ext = NULL;
  66292. X509* x509 = NULL;
  66293. unsigned int keyUsageFlags;
  66294. unsigned int extKeyUsageFlags;
  66295. ExpectNotNull(x509 = X509_new());
  66296. /* keyUsage / extKeyUsage should match string above */
  66297. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66298. | KU_NON_REPUDIATION
  66299. | KU_KEY_ENCIPHERMENT
  66300. | KU_DATA_ENCIPHERMENT
  66301. | KU_KEY_AGREEMENT
  66302. | KU_KEY_CERT_SIGN
  66303. | KU_CRL_SIGN
  66304. | KU_ENCIPHER_ONLY
  66305. | KU_DECIPHER_ONLY;
  66306. extKeyUsageFlags = XKU_SSL_CLIENT
  66307. | XKU_SSL_SERVER
  66308. | XKU_CODE_SIGN
  66309. | XKU_SMIME
  66310. | XKU_TIMESTAMP
  66311. | XKU_OCSP_SIGN;
  66312. for (i = 0; i < ext_names_count; i++) {
  66313. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66314. ext_values[i]));
  66315. X509_EXTENSION_free(ext);
  66316. ext = NULL;
  66317. }
  66318. for (i = 0; i < ext_nids_count; i++) {
  66319. ExpectNotNull(ext = X509V3_EXT_nconf_nid(NULL, NULL, ext_nids[i],
  66320. ext_values[i]));
  66321. X509_EXTENSION_free(ext);
  66322. ext = NULL;
  66323. }
  66324. /* Test adding extension to X509 */
  66325. for (i = 0; i < ext_nids_count; i++) {
  66326. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66327. ext_values[i]));
  66328. ExpectIntEQ(X509_add_ext(x509, ext, -1), WOLFSSL_SUCCESS);
  66329. if (ext_nids[i] == NID_key_usage) {
  66330. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66331. }
  66332. else if (ext_nids[i] == NID_ext_key_usage) {
  66333. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  66334. }
  66335. X509_EXTENSION_free(ext);
  66336. ext = NULL;
  66337. }
  66338. X509_free(x509);
  66339. #endif
  66340. return EXPECT_RESULT();
  66341. }
  66342. static int test_wolfSSL_X509V3_EXT(void) {
  66343. EXPECT_DECLS;
  66344. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66345. XFILE f = XBADFILE;
  66346. int numOfExt = 0, nid = 0, i = 0, expected, actual = 0;
  66347. char* str = NULL;
  66348. unsigned char* data = NULL;
  66349. const WOLFSSL_v3_ext_method* method = NULL;
  66350. WOLFSSL_X509* x509 = NULL;
  66351. WOLFSSL_X509_EXTENSION* ext = NULL;
  66352. WOLFSSL_X509_EXTENSION* ext2 = NULL;
  66353. WOLFSSL_ASN1_OBJECT *obj = NULL;
  66354. WOLFSSL_ASN1_OBJECT *adObj = NULL;
  66355. WOLFSSL_ASN1_STRING* asn1str = NULL;
  66356. WOLFSSL_AUTHORITY_KEYID* aKeyId = NULL;
  66357. WOLFSSL_AUTHORITY_INFO_ACCESS* aia = NULL;
  66358. WOLFSSL_BASIC_CONSTRAINTS* bc = NULL;
  66359. WOLFSSL_ACCESS_DESCRIPTION* ad = NULL;
  66360. WOLFSSL_GENERAL_NAME* gn = NULL;
  66361. /* Check NULL argument */
  66362. ExpectNull(wolfSSL_X509V3_EXT_d2i(NULL));
  66363. /* Using OCSP cert with X509V3 extensions */
  66364. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  66365. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66366. if (f != XBADFILE)
  66367. XFCLOSE(f);
  66368. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66369. /* Basic Constraints */
  66370. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66371. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66372. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_basic_constraints);
  66373. ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext));
  66374. ExpectIntEQ(bc->ca, 1);
  66375. ExpectNull(bc->pathlen);
  66376. wolfSSL_BASIC_CONSTRAINTS_free(bc);
  66377. bc = NULL;
  66378. i++;
  66379. /* Subject Key Identifier */
  66380. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66381. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66382. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_subject_key_identifier);
  66383. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66384. ExpectNotNull(ext2 = wolfSSL_X509V3_EXT_i2d(NID_subject_key_identifier, 0,
  66385. asn1str));
  66386. X509_EXTENSION_free(ext2);
  66387. ext2 = NULL;
  66388. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66389. ExpectNotNull(method->i2s);
  66390. ExpectNotNull(str = method->i2s((WOLFSSL_v3_ext_method*)method, asn1str));
  66391. wolfSSL_ASN1_STRING_free(asn1str);
  66392. asn1str = NULL;
  66393. if (str != NULL) {
  66394. actual = strcmp(str,
  66395. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66396. }
  66397. ExpectIntEQ(actual, 0);
  66398. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66399. str = NULL;
  66400. i++;
  66401. /* Authority Key Identifier */
  66402. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66403. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66404. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_authority_key_identifier);
  66405. ExpectNotNull(aKeyId = (WOLFSSL_AUTHORITY_KEYID*)wolfSSL_X509V3_EXT_d2i(
  66406. ext));
  66407. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66408. ExpectNotNull(asn1str = aKeyId->keyid);
  66409. ExpectNotNull(str = wolfSSL_i2s_ASN1_STRING((WOLFSSL_v3_ext_method*)method,
  66410. asn1str));
  66411. asn1str = NULL;
  66412. if (str != NULL) {
  66413. actual = strcmp(str,
  66414. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66415. }
  66416. ExpectIntEQ(actual, 0);
  66417. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66418. str = NULL;
  66419. wolfSSL_AUTHORITY_KEYID_free(aKeyId);
  66420. aKeyId = NULL;
  66421. i++;
  66422. /* Key Usage */
  66423. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66424. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66425. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_key_usage);
  66426. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66427. #if defined(WOLFSSL_QT)
  66428. ExpectNotNull(data = (unsigned char*)ASN1_STRING_get0_data(asn1str));
  66429. #else
  66430. ExpectNotNull(data = wolfSSL_ASN1_STRING_data(asn1str));
  66431. #endif
  66432. expected = KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN;
  66433. if (data != NULL) {
  66434. #ifdef BIG_ENDIAN_ORDER
  66435. actual = data[1];
  66436. #else
  66437. actual = data[0];
  66438. #endif
  66439. }
  66440. ExpectIntEQ(actual, expected);
  66441. wolfSSL_ASN1_STRING_free(asn1str);
  66442. asn1str = NULL;
  66443. #if 1
  66444. i++;
  66445. /* Authority Info Access */
  66446. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66447. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66448. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_info_access);
  66449. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  66450. ext));
  66451. #if defined(WOLFSSL_QT)
  66452. ExpectIntEQ(OPENSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66453. #else
  66454. ExpectIntEQ(wolfSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66455. #endif
  66456. /* URI entry is an ACCESS_DESCRIPTION type */
  66457. #if defined(WOLFSSL_QT)
  66458. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)wolfSSL_sk_value(aia, 0));
  66459. #else
  66460. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)OPENSSL_sk_value(aia, 0));
  66461. #endif
  66462. ExpectNotNull(adObj = ad->method);
  66463. /* Make sure nid is OCSP */
  66464. ExpectIntEQ(wolfSSL_OBJ_obj2nid(adObj), NID_ad_OCSP);
  66465. /* GENERAL_NAME stores URI as an ASN1_STRING */
  66466. ExpectNotNull(gn = ad->location);
  66467. ExpectIntEQ(gn->type, GEN_URI); /* Type should always be GEN_URI */
  66468. ExpectNotNull(asn1str = gn->d.uniformResourceIdentifier);
  66469. ExpectIntEQ(wolfSSL_ASN1_STRING_length(asn1str), 22);
  66470. #if defined(WOLFSSL_QT)
  66471. ExpectNotNull(str = (char*)ASN1_STRING_get0_data(asn1str));
  66472. #else
  66473. ExpectNotNull(str = (char*)wolfSSL_ASN1_STRING_data(asn1str));
  66474. #endif
  66475. if (str != NULL) {
  66476. actual = strcmp(str, "http://127.0.0.1:22220");
  66477. }
  66478. ExpectIntEQ(actual, 0);
  66479. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  66480. aia = NULL;
  66481. #else
  66482. (void) aia; (void) ad; (void) adObj; (void) gn;
  66483. #endif
  66484. wolfSSL_X509_free(x509);
  66485. #endif
  66486. return EXPECT_RESULT();
  66487. }
  66488. static int test_wolfSSL_X509_get_extension_flags(void)
  66489. {
  66490. EXPECT_DECLS;
  66491. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66492. XFILE f = XBADFILE;
  66493. X509* x509 = NULL;
  66494. unsigned int extFlags;
  66495. unsigned int keyUsageFlags;
  66496. unsigned int extKeyUsageFlags;
  66497. /* client-int-cert.pem has the following extension flags. */
  66498. extFlags = EXFLAG_KUSAGE | EXFLAG_XKUSAGE;
  66499. /* and the following key usage flags. */
  66500. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66501. | KU_NON_REPUDIATION
  66502. | KU_KEY_ENCIPHERMENT;
  66503. /* and the following extended key usage flags. */
  66504. extKeyUsageFlags = XKU_SSL_CLIENT | XKU_SMIME;
  66505. ExpectTrue((f = XFOPEN("./certs/intermediate/client-int-cert.pem", "rb")) !=
  66506. XBADFILE);
  66507. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66508. if (f != XBADFILE) {
  66509. XFCLOSE(f);
  66510. f = XBADFILE;
  66511. }
  66512. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  66513. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66514. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  66515. X509_free(x509);
  66516. x509 = NULL;
  66517. /* client-cert-ext.pem has the following extension flags. */
  66518. extFlags = EXFLAG_KUSAGE;
  66519. /* and the following key usage flags. */
  66520. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66521. | KU_KEY_CERT_SIGN
  66522. | KU_CRL_SIGN;
  66523. ExpectTrue((f = fopen("./certs/client-cert-ext.pem", "rb")) != XBADFILE);
  66524. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66525. if (f != XBADFILE)
  66526. XFCLOSE(f);
  66527. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  66528. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66529. X509_free(x509);
  66530. #endif /* OPENSSL_ALL */
  66531. return EXPECT_RESULT();
  66532. }
  66533. static int test_wolfSSL_X509_get_ext(void)
  66534. {
  66535. EXPECT_DECLS;
  66536. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66537. int ret = 0;
  66538. XFILE f = XBADFILE;
  66539. WOLFSSL_X509* x509 = NULL;
  66540. WOLFSSL_X509_EXTENSION* foundExtension;
  66541. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66542. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66543. if (f != XBADFILE)
  66544. XFCLOSE(f);
  66545. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  66546. /* wolfSSL_X509_get_ext() valid input */
  66547. ExpectNotNull(foundExtension = wolfSSL_X509_get_ext(x509, 0));
  66548. /* wolfSSL_X509_get_ext() valid x509, idx out of bounds */
  66549. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, -1));
  66550. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, 100));
  66551. /* wolfSSL_X509_get_ext() NULL x509, idx out of bounds */
  66552. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, -1));
  66553. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 100));
  66554. /* wolfSSL_X509_get_ext() NULL x509, valid idx */
  66555. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 0));
  66556. wolfSSL_X509_free(x509);
  66557. #endif
  66558. return EXPECT_RESULT();
  66559. }
  66560. static int test_wolfSSL_X509_get_ext_by_NID(void)
  66561. {
  66562. EXPECT_DECLS;
  66563. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66564. int rc = 0;
  66565. XFILE f = XBADFILE;
  66566. WOLFSSL_X509* x509 = NULL;
  66567. ASN1_OBJECT* obj = NULL;
  66568. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66569. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66570. if (f != XBADFILE)
  66571. XFCLOSE(f);
  66572. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  66573. -1), 0);
  66574. /* Start search from last location (should fail) */
  66575. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  66576. rc), -1);
  66577. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  66578. -2), -1);
  66579. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(NULL, NID_basic_constraints,
  66580. -1), -1);
  66581. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_undef, -1), -1);
  66582. /* NID_ext_key_usage, check also its nid and oid */
  66583. ExpectIntGT(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_ext_key_usage, -1),
  66584. -1);
  66585. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(wolfSSL_X509_get_ext(
  66586. x509, rc)));
  66587. ExpectIntEQ(obj->nid, NID_ext_key_usage);
  66588. ExpectIntEQ(obj->type, EXT_KEY_USAGE_OID);
  66589. wolfSSL_X509_free(x509);
  66590. #endif
  66591. return EXPECT_RESULT();
  66592. }
  66593. static int test_wolfSSL_X509_get_ext_subj_alt_name(void)
  66594. {
  66595. EXPECT_DECLS;
  66596. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66597. int rc = 0;
  66598. XFILE f = XBADFILE;
  66599. WOLFSSL_X509* x509 = NULL;
  66600. WOLFSSL_X509_EXTENSION* ext = NULL;
  66601. WOLFSSL_ASN1_STRING* sanString = NULL;
  66602. byte* sanDer = NULL;
  66603. const byte expectedDer[] = {
  66604. 0x30, 0x13, 0x82, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
  66605. 0x63, 0x6f, 0x6d, 0x87, 0x04, 0x7f, 0x00, 0x00, 0x01};
  66606. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66607. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66608. if (f != XBADFILE)
  66609. XFCLOSE(f);
  66610. ExpectIntNE(rc = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1), -1);
  66611. ExpectNotNull(ext = X509_get_ext(x509, rc));
  66612. ExpectNotNull(sanString = X509_EXTENSION_get_data(ext));
  66613. ExpectIntEQ(ASN1_STRING_length(sanString), sizeof(expectedDer));
  66614. ExpectNotNull(sanDer = ASN1_STRING_data(sanString));
  66615. ExpectIntEQ(XMEMCMP(sanDer, expectedDer, sizeof(expectedDer)), 0);
  66616. X509_free(x509);
  66617. #endif
  66618. return EXPECT_RESULT();
  66619. }
  66620. static int test_wolfSSL_X509_EXTENSION_new(void)
  66621. {
  66622. EXPECT_DECLS;
  66623. #if defined (OPENSSL_ALL)
  66624. WOLFSSL_X509_EXTENSION* ext = NULL;
  66625. ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new());
  66626. ExpectNotNull(ext->obj = wolfSSL_ASN1_OBJECT_new());
  66627. wolfSSL_X509_EXTENSION_free(ext);
  66628. #endif
  66629. return EXPECT_RESULT();
  66630. }
  66631. static int test_wolfSSL_X509_EXTENSION_get_object(void)
  66632. {
  66633. EXPECT_DECLS;
  66634. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66635. WOLFSSL_X509* x509 = NULL;
  66636. WOLFSSL_X509_EXTENSION* ext = NULL;
  66637. WOLFSSL_ASN1_OBJECT* o = NULL;
  66638. XFILE file = XBADFILE;
  66639. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66640. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  66641. if (file != XBADFILE)
  66642. XFCLOSE(file);
  66643. /* wolfSSL_X509_EXTENSION_get_object() testing ext idx 0 */
  66644. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  66645. ExpectNull(wolfSSL_X509_EXTENSION_get_object(NULL));
  66646. ExpectNotNull(o = wolfSSL_X509_EXTENSION_get_object(ext));
  66647. ExpectIntEQ(o->nid, 128);
  66648. /* wolfSSL_X509_EXTENSION_get_object() NULL argument */
  66649. ExpectNull(o = wolfSSL_X509_EXTENSION_get_object(NULL));
  66650. wolfSSL_X509_free(x509);
  66651. #endif
  66652. return EXPECT_RESULT();
  66653. }
  66654. static int test_wolfSSL_X509_EXTENSION_get_data(void)
  66655. {
  66656. EXPECT_DECLS;
  66657. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66658. WOLFSSL_X509* x509 = NULL;
  66659. WOLFSSL_X509_EXTENSION* ext = NULL;
  66660. WOLFSSL_ASN1_STRING* str = NULL;
  66661. XFILE file = XBADFILE;
  66662. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66663. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  66664. if (file != XBADFILE)
  66665. XFCLOSE(file);
  66666. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  66667. ExpectNull(str = wolfSSL_X509_EXTENSION_get_data(NULL));
  66668. ExpectNotNull(str = wolfSSL_X509_EXTENSION_get_data(ext));
  66669. wolfSSL_X509_free(x509);
  66670. #endif
  66671. return EXPECT_RESULT();
  66672. }
  66673. static int test_wolfSSL_X509_EXTENSION_get_critical(void)
  66674. {
  66675. EXPECT_DECLS;
  66676. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66677. WOLFSSL_X509* x509 = NULL;
  66678. WOLFSSL_X509_EXTENSION* ext = NULL;
  66679. XFILE file = XBADFILE;
  66680. int crit = 0;
  66681. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66682. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  66683. if (file != XBADFILE)
  66684. XFCLOSE(file);
  66685. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  66686. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  66687. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(ext), 0);
  66688. wolfSSL_X509_free(x509);
  66689. #endif
  66690. return EXPECT_RESULT();
  66691. }
  66692. static int test_wolfSSL_X509V3_EXT_print(void)
  66693. {
  66694. EXPECT_DECLS;
  66695. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_BIO) && \
  66696. !defined(NO_RSA)
  66697. {
  66698. XFILE f = XBADFILE;
  66699. WOLFSSL_X509* x509 = NULL;
  66700. X509_EXTENSION * ext = NULL;
  66701. int loc = 0;
  66702. BIO *bio = NULL;
  66703. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  66704. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66705. if (f != XBADFILE)
  66706. fclose(f);
  66707. ExpectNotNull(bio = wolfSSL_BIO_new(BIO_s_mem()));
  66708. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  66709. NID_basic_constraints, -1), -1);
  66710. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  66711. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  66712. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  66713. NID_subject_key_identifier, -1), -1);
  66714. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  66715. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  66716. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  66717. NID_authority_key_identifier, -1), -1);
  66718. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  66719. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  66720. wolfSSL_BIO_free(bio);
  66721. wolfSSL_X509_free(x509);
  66722. }
  66723. {
  66724. X509 *x509 = NULL;
  66725. BIO *bio = NULL;
  66726. X509_EXTENSION *ext = NULL;
  66727. unsigned int i = 0;
  66728. unsigned int idx = 0;
  66729. /* Some NIDs to test with */
  66730. int nids[] = {
  66731. /* NID_key_usage, currently X509_get_ext returns this as a bit
  66732. * string, which messes up X509V3_EXT_print */
  66733. /* NID_ext_key_usage, */
  66734. NID_subject_alt_name,
  66735. };
  66736. int* n = NULL;
  66737. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  66738. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  66739. WOLFSSL_FILETYPE_PEM));
  66740. ExpectIntGT(fprintf(stderr, "\nPrinting extension values:\n"), 0);
  66741. for (i = 0, n = nids; i<(sizeof(nids)/sizeof(int)); i++, n++) {
  66742. /* X509_get_ext_by_NID should return 3 for now. If that changes then
  66743. * update the index */
  66744. ExpectIntEQ((idx = X509_get_ext_by_NID(x509, *n, -1)), 3);
  66745. ExpectNotNull(ext = X509_get_ext(x509, (int)idx));
  66746. ExpectIntEQ(X509V3_EXT_print(bio, ext, 0, 0), 1);
  66747. ExpectIntGT(fprintf(stderr, "\n"), 0);
  66748. }
  66749. BIO_free(bio);
  66750. X509_free(x509);
  66751. }
  66752. #endif
  66753. return EXPECT_RESULT();
  66754. }
  66755. static int test_wolfSSL_X509_cmp(void)
  66756. {
  66757. EXPECT_DECLS;
  66758. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66759. XFILE file1 = XBADFILE;
  66760. XFILE file2 = XBADFILE;
  66761. WOLFSSL_X509* cert1 = NULL;
  66762. WOLFSSL_X509* cert2 = NULL;
  66763. ExpectTrue((file1 = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66764. ExpectTrue((file2 = XFOPEN("./certs/3072/client-cert.pem", "rb")) !=
  66765. XBADFILE);
  66766. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  66767. ExpectNotNull(cert2 = wolfSSL_PEM_read_X509(file2, NULL, NULL, NULL));
  66768. if (file1 != XBADFILE)
  66769. fclose(file1);
  66770. if (file2 != XBADFILE)
  66771. fclose(file2);
  66772. /* wolfSSL_X509_cmp() testing matching certs */
  66773. ExpectIntEQ(0, wolfSSL_X509_cmp(cert1, cert1));
  66774. /* wolfSSL_X509_cmp() testing mismatched certs */
  66775. ExpectIntEQ(-1, wolfSSL_X509_cmp(cert1, cert2));
  66776. /* wolfSSL_X509_cmp() testing NULL, valid args */
  66777. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, cert2));
  66778. /* wolfSSL_X509_cmp() testing valid, NULL args */
  66779. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(cert1, NULL));
  66780. /* wolfSSL_X509_cmp() testing NULL, NULL args */
  66781. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, NULL));
  66782. wolfSSL_X509_free(cert1);
  66783. wolfSSL_X509_free(cert2);
  66784. #endif
  66785. return EXPECT_RESULT();
  66786. }
  66787. static int test_wolfSSL_EVP_PKEY_up_ref(void)
  66788. {
  66789. EXPECT_DECLS;
  66790. #if defined(OPENSSL_ALL)
  66791. EVP_PKEY* pkey;
  66792. pkey = EVP_PKEY_new();
  66793. ExpectNotNull(pkey);
  66794. ExpectIntEQ(EVP_PKEY_up_ref(NULL), 0);
  66795. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  66796. EVP_PKEY_free(pkey);
  66797. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  66798. EVP_PKEY_free(pkey);
  66799. EVP_PKEY_free(pkey);
  66800. #endif
  66801. return EXPECT_RESULT();
  66802. }
  66803. static int test_wolfSSL_d2i_and_i2d_PublicKey(void)
  66804. {
  66805. EXPECT_DECLS;
  66806. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  66807. EVP_PKEY* pkey = NULL;
  66808. const unsigned char* p;
  66809. unsigned char *der = NULL;
  66810. unsigned char *tmp = NULL;
  66811. int derLen;
  66812. p = client_keypub_der_2048;
  66813. /* Check that key can be successfully decoded. */
  66814. ExpectNotNull(pkey = wolfSSL_d2i_PublicKey(EVP_PKEY_RSA, NULL, &p,
  66815. sizeof_client_keypub_der_2048));
  66816. /* Check that key can be successfully encoded. */
  66817. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  66818. /* Ensure that the encoded version matches the original. */
  66819. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  66820. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  66821. /* Do same test except with pre-allocated buffer to ensure the der pointer
  66822. * is advanced. */
  66823. tmp = der;
  66824. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  66825. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  66826. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  66827. ExpectTrue(der + derLen == tmp);
  66828. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  66829. EVP_PKEY_free(pkey);
  66830. #endif
  66831. return EXPECT_RESULT();
  66832. }
  66833. static int test_wolfSSL_d2i_and_i2d_PublicKey_ecc(void)
  66834. {
  66835. EXPECT_DECLS;
  66836. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(NO_CERTS) && \
  66837. !defined(NO_ASN) && !defined(NO_PWDBASED)
  66838. EVP_PKEY* pkey = NULL;
  66839. const unsigned char* p;
  66840. unsigned char *der = NULL;
  66841. unsigned char *tmp = NULL;
  66842. int derLen;
  66843. unsigned char pub_buf[65];
  66844. const int pub_len = 65;
  66845. BN_CTX* ctx;
  66846. EC_GROUP* curve = NULL;
  66847. EC_KEY* ephemeral_key = NULL;
  66848. const EC_POINT* h;
  66849. /* Generate an x963 key pair and get public part into pub_buf */
  66850. ExpectNotNull(ctx = BN_CTX_new());
  66851. ExpectNotNull(curve = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  66852. ExpectNotNull(ephemeral_key = EC_KEY_new_by_curve_name(
  66853. NID_X9_62_prime256v1));
  66854. ExpectIntEQ(EC_KEY_generate_key(ephemeral_key), 1);
  66855. ExpectNotNull(h = EC_KEY_get0_public_key(ephemeral_key));
  66856. ExpectIntEQ(pub_len, EC_POINT_point2oct(curve, h,
  66857. POINT_CONVERSION_UNCOMPRESSED, pub_buf, pub_len, ctx));
  66858. /* Prepare the EVP_PKEY */
  66859. ExpectNotNull(pkey = EVP_PKEY_new());
  66860. p = pub_buf;
  66861. /* Check that key can be successfully decoded. */
  66862. ExpectNotNull(wolfSSL_d2i_PublicKey(EVP_PKEY_EC, &pkey, &p,
  66863. pub_len));
  66864. /* Check that key can be successfully encoded. */
  66865. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  66866. /* Ensure that the encoded version matches the original. */
  66867. ExpectIntEQ(derLen, pub_len);
  66868. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  66869. /* Do same test except with pre-allocated buffer to ensure the der pointer
  66870. * is advanced. */
  66871. tmp = der;
  66872. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  66873. ExpectIntEQ(derLen, pub_len);
  66874. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  66875. ExpectTrue(der + derLen == tmp);
  66876. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  66877. EVP_PKEY_free(pkey);
  66878. EC_KEY_free(ephemeral_key);
  66879. EC_GROUP_free(curve);
  66880. #endif
  66881. return EXPECT_RESULT();
  66882. }
  66883. static int test_wolfSSL_d2i_and_i2d_DSAparams(void)
  66884. {
  66885. EXPECT_DECLS;
  66886. #if defined(OPENSSL_EXTRA) && !defined(NO_DSA)
  66887. DSA* dsa = NULL;
  66888. byte derIn[] = {
  66889. 0x30, 0x82, 0x01, 0x1f, 0x02, 0x81, 0x81, 0x00,
  66890. 0xcd, 0xde, 0x25, 0x68, 0x80, 0x53, 0x0d, 0xe5,
  66891. 0x77, 0xd6, 0xd2, 0x90, 0x39, 0x3f, 0x90, 0xa2,
  66892. 0x3f, 0x33, 0x94, 0x6e, 0xe8, 0x4f, 0x2b, 0x63,
  66893. 0xab, 0x30, 0xab, 0x15, 0xba, 0x11, 0xea, 0x8a,
  66894. 0x5d, 0x8d, 0xcc, 0xb8, 0xd4, 0xa1, 0xd5, 0xc1,
  66895. 0x47, 0x9d, 0x5a, 0x73, 0x6a, 0x62, 0x49, 0xd1,
  66896. 0x06, 0x07, 0x67, 0xf6, 0x2f, 0xa3, 0x39, 0xbd,
  66897. 0x4e, 0x0d, 0xb4, 0xd3, 0x22, 0x23, 0x84, 0xec,
  66898. 0x93, 0x26, 0x5a, 0x49, 0xee, 0x7c, 0x89, 0x48,
  66899. 0x66, 0x4d, 0xe8, 0xe8, 0xd8, 0x50, 0xfb, 0xa5,
  66900. 0x71, 0x9f, 0x22, 0x18, 0xe5, 0xe6, 0x0b, 0x46,
  66901. 0x87, 0x66, 0xee, 0x52, 0x8f, 0x46, 0x4f, 0xb5,
  66902. 0x03, 0xce, 0xed, 0xe3, 0xbe, 0xe5, 0xb5, 0x81,
  66903. 0xd2, 0x59, 0xe9, 0xc0, 0xad, 0x4d, 0xd0, 0x4d,
  66904. 0x26, 0xf7, 0xba, 0x50, 0xe8, 0xc9, 0x8f, 0xfe,
  66905. 0x24, 0x19, 0x3d, 0x2e, 0xa7, 0x52, 0x3c, 0x6d,
  66906. 0x02, 0x15, 0x00, 0xfb, 0x47, 0xfb, 0xec, 0x81,
  66907. 0x20, 0xc8, 0x1c, 0xe9, 0x4a, 0xba, 0x04, 0x6f,
  66908. 0x19, 0x9b, 0x94, 0xee, 0x82, 0x67, 0xd3, 0x02,
  66909. 0x81, 0x81, 0x00, 0x9b, 0x95, 0xbb, 0x85, 0xc5,
  66910. 0x58, 0x4a, 0x32, 0x9c, 0xaa, 0x44, 0x85, 0xd6,
  66911. 0x68, 0xdc, 0x3e, 0x14, 0xf4, 0xce, 0x6d, 0xa3,
  66912. 0x49, 0x38, 0xea, 0xd6, 0x61, 0x48, 0x92, 0x5a,
  66913. 0x40, 0x95, 0x49, 0x38, 0xaa, 0xe1, 0x39, 0x29,
  66914. 0x68, 0x58, 0x47, 0x8a, 0x4b, 0x01, 0xe1, 0x2e,
  66915. 0x8e, 0x6c, 0x63, 0x6f, 0x40, 0xca, 0x50, 0x3f,
  66916. 0x8c, 0x0b, 0x99, 0xe4, 0x72, 0x42, 0xb8, 0xb1,
  66917. 0xc2, 0x26, 0x48, 0xf1, 0x9c, 0x83, 0xc6, 0x37,
  66918. 0x2e, 0x5a, 0xae, 0x11, 0x09, 0xd9, 0xf3, 0xad,
  66919. 0x1f, 0x6f, 0xad, 0xad, 0x50, 0xe3, 0x78, 0x32,
  66920. 0xe6, 0xde, 0x8e, 0xaa, 0xbf, 0xd1, 0x00, 0x9f,
  66921. 0xb3, 0x02, 0x12, 0x19, 0xa2, 0x15, 0xec, 0x14,
  66922. 0x18, 0x5c, 0x0e, 0x26, 0xce, 0xf9, 0xae, 0xcc,
  66923. 0x7b, 0xb5, 0xd1, 0x26, 0xfc, 0x85, 0xfe, 0x14,
  66924. 0x93, 0xb6, 0x9d, 0x7d, 0x76, 0xe3, 0x35, 0x97,
  66925. 0x1e, 0xde, 0xc4
  66926. };
  66927. int derInLen = sizeof(derIn);
  66928. byte* derOut = NULL;
  66929. int derOutLen;
  66930. byte* p = derIn;
  66931. /* Check that params can be successfully decoded. */
  66932. ExpectNotNull(dsa = d2i_DSAparams(NULL, (const byte**)&p, derInLen));
  66933. /* Check that params can be successfully encoded. */
  66934. ExpectIntGE((derOutLen = i2d_DSAparams(dsa, &derOut)), 0);
  66935. /* Ensure that the encoded version matches the original. */
  66936. ExpectIntEQ(derInLen, derOutLen);
  66937. ExpectIntEQ(XMEMCMP(derIn, derOut, derInLen), 0);
  66938. XFREE(derOut, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  66939. DSA_free(dsa);
  66940. #endif
  66941. return EXPECT_RESULT();
  66942. }
  66943. static int test_wolfSSL_i2d_PrivateKey(void)
  66944. {
  66945. EXPECT_DECLS;
  66946. #if (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(OPENSSL_EXTRA) && \
  66947. !defined(NO_ASN) && !defined(NO_PWDBASED)
  66948. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  66949. {
  66950. EVP_PKEY* pkey = NULL;
  66951. const unsigned char* server_key =
  66952. (const unsigned char*)server_key_der_2048;
  66953. unsigned char buf[FOURK_BUF];
  66954. unsigned char* pt = NULL;
  66955. int bufSz = 0;
  66956. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &server_key,
  66957. (long)sizeof_server_key_der_2048));
  66958. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 1193);
  66959. pt = buf;
  66960. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 1193);
  66961. ExpectIntNE((pt - buf), 0);
  66962. ExpectIntEQ(XMEMCMP(buf, server_key_der_2048, bufSz), 0);
  66963. EVP_PKEY_free(pkey);
  66964. }
  66965. #endif
  66966. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  66967. {
  66968. EVP_PKEY* pkey = NULL;
  66969. const unsigned char* client_key =
  66970. (const unsigned char*)ecc_clikey_der_256;
  66971. unsigned char buf[FOURK_BUF];
  66972. unsigned char* pt = NULL;
  66973. int bufSz = 0;
  66974. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &client_key,
  66975. (long)sizeof_ecc_clikey_der_256)));
  66976. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 121);
  66977. pt = buf;
  66978. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 121);
  66979. ExpectIntNE((pt - buf), 0);
  66980. ExpectIntEQ(XMEMCMP(buf, ecc_clikey_der_256, bufSz), 0);
  66981. EVP_PKEY_free(pkey);
  66982. }
  66983. #endif
  66984. #endif
  66985. return EXPECT_RESULT();
  66986. }
  66987. static int test_wolfSSL_OCSP_id_get0_info(void)
  66988. {
  66989. EXPECT_DECLS;
  66990. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && \
  66991. defined(HAVE_OCSP) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  66992. X509* cert = NULL;
  66993. X509* issuer = NULL;
  66994. OCSP_CERTID* id = NULL;
  66995. OCSP_CERTID* id2 = NULL;
  66996. ASN1_STRING* name = NULL;
  66997. ASN1_OBJECT* pmd = NULL;
  66998. ASN1_STRING* keyHash = NULL;
  66999. ASN1_INTEGER* serial = NULL;
  67000. ASN1_INTEGER* x509Int = NULL;
  67001. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(svrCertFile,
  67002. SSL_FILETYPE_PEM));
  67003. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caCertFile,
  67004. SSL_FILETYPE_PEM));
  67005. ExpectNotNull(id = OCSP_cert_to_id(NULL, cert, issuer));
  67006. ExpectNotNull(id2 = OCSP_cert_to_id(NULL, cert, issuer));
  67007. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, NULL), 0);
  67008. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, id), 1);
  67009. /* name, pmd, keyHash not supported yet, expect failure if not NULL */
  67010. ExpectIntEQ(OCSP_id_get0_info(&name, NULL, NULL, NULL, id), 0);
  67011. ExpectIntEQ(OCSP_id_get0_info(NULL, &pmd, NULL, NULL, id), 0);
  67012. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, &keyHash, NULL, id), 0);
  67013. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, &serial, id), 1);
  67014. ExpectNotNull(serial);
  67015. /* compare serial number to one in cert, should be equal */
  67016. ExpectNotNull(x509Int = X509_get_serialNumber(cert));
  67017. ExpectIntEQ(x509Int->length, serial->length);
  67018. ExpectIntEQ(XMEMCMP(x509Int->data, serial->data, serial->length), 0);
  67019. /* test OCSP_id_cmp */
  67020. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67021. ExpectIntNE(OCSP_id_cmp(id, NULL), 0);
  67022. ExpectIntNE(OCSP_id_cmp(NULL, id2), 0);
  67023. ExpectIntEQ(OCSP_id_cmp(id, id2), 0);
  67024. if (id != NULL) {
  67025. id->issuerHash[0] = ~id->issuerHash[0];
  67026. }
  67027. ExpectIntNE(OCSP_id_cmp(id, id2), 0);
  67028. OCSP_CERTID_free(id);
  67029. OCSP_CERTID_free(id2);
  67030. X509_free(cert); /* free's x509Int */
  67031. X509_free(issuer);
  67032. #endif
  67033. return EXPECT_RESULT();
  67034. }
  67035. static int test_wolfSSL_i2d_OCSP_CERTID(void)
  67036. {
  67037. EXPECT_DECLS;
  67038. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67039. WOLFSSL_OCSP_CERTID certId;
  67040. byte* targetBuffer = NULL;
  67041. byte* p;
  67042. /* OCSP CertID bytes taken from PCAP */
  67043. byte rawCertId[] = {
  67044. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67045. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67046. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67047. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67048. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67049. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67050. 0xcf, 0xbc, 0x91
  67051. };
  67052. int ret = 0;
  67053. int i;
  67054. XMEMSET(&certId, 0, sizeof(WOLFSSL_OCSP_CERTID));
  67055. certId.rawCertId = rawCertId;
  67056. certId.rawCertIdSize = sizeof(rawCertId);
  67057. ExpectNotNull(targetBuffer = (byte*)XMALLOC(sizeof(rawCertId), NULL,
  67058. DYNAMIC_TYPE_TMP_BUFFER));
  67059. p = targetBuffer;
  67060. /* Function returns the size of the encoded data. */
  67061. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &p), sizeof(rawCertId));
  67062. /* If target buffer is not null, function increments targetBuffer to point
  67063. * just past the end of the encoded data. */
  67064. ExpectPtrEq(p, (targetBuffer + sizeof(rawCertId)));
  67065. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67066. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67067. }
  67068. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67069. targetBuffer = NULL;
  67070. /* If target buffer is null, function allocates memory for a buffer and
  67071. * copies the encoded data into it. targetBuffer then points to the start of
  67072. * this newly allocate buffer. */
  67073. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &targetBuffer),
  67074. sizeof(rawCertId));
  67075. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67076. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67077. }
  67078. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_OPENSSL);
  67079. #endif
  67080. return EXPECT_RESULT();
  67081. }
  67082. static int test_wolfSSL_d2i_OCSP_CERTID(void)
  67083. {
  67084. EXPECT_DECLS;
  67085. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67086. WOLFSSL_OCSP_CERTID* certId;
  67087. WOLFSSL_OCSP_CERTID* certIdGood;
  67088. WOLFSSL_OCSP_CERTID* certIdBad;
  67089. const unsigned char* rawCertIdPtr;
  67090. const unsigned char rawCertId[] = {
  67091. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67092. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67093. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67094. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67095. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67096. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67097. 0xcf, 0xbc, 0x91
  67098. };
  67099. rawCertIdPtr = &rawCertId[0];
  67100. /* If the cert ID is NULL the function should allocate it and copy the
  67101. * data to it. */
  67102. certId = NULL;
  67103. ExpectNotNull(certId = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67104. sizeof(rawCertId)));
  67105. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67106. if (certId != NULL) {
  67107. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67108. XFREE(certId, NULL, DYNAMIC_TYPE_OPENSSL);
  67109. }
  67110. /* If the cert ID is not NULL the function will just copy the data to it. */
  67111. ExpectNotNull(certId = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*certId), NULL,
  67112. DYNAMIC_TYPE_TMP_BUFFER));
  67113. ExpectNotNull(certId);
  67114. ExpectNotNull(XMEMSET(certId, 0, sizeof(*certId)));
  67115. /* Reset rawCertIdPtr since it was push forward in the previous call. */
  67116. rawCertIdPtr = &rawCertId[0];
  67117. ExpectNotNull(certIdGood = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67118. sizeof(rawCertId)));
  67119. ExpectPtrEq(certIdGood, certId);
  67120. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67121. if (certId != NULL) {
  67122. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67123. XFREE(certId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67124. certId = NULL;
  67125. }
  67126. /* The below tests should fail when passed bad parameters. NULL should
  67127. * always be returned. */
  67128. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(NULL, &rawCertIdPtr,
  67129. sizeof(rawCertId)));
  67130. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, NULL,
  67131. sizeof(rawCertId)));
  67132. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr, 0));
  67133. #endif
  67134. return EXPECT_RESULT();
  67135. }
  67136. static int test_wolfSSL_OCSP_id_cmp(void)
  67137. {
  67138. EXPECT_DECLS;
  67139. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP)
  67140. OCSP_CERTID id1;
  67141. OCSP_CERTID id2;
  67142. XMEMSET(&id1, 0, sizeof(id1));
  67143. XMEMSET(&id2, 0, sizeof(id2));
  67144. ExpectIntEQ(OCSP_id_cmp(&id1, &id2), 0);
  67145. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67146. ExpectIntNE(OCSP_id_cmp(&id1, NULL), 0);
  67147. ExpectIntNE(OCSP_id_cmp(NULL, &id2), 0);
  67148. #endif
  67149. return EXPECT_RESULT();
  67150. }
  67151. static int test_wolfSSL_OCSP_SINGLERESP_get0_id(void)
  67152. {
  67153. EXPECT_DECLS;
  67154. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67155. WOLFSSL_OCSP_SINGLERESP single;
  67156. const WOLFSSL_OCSP_CERTID* certId;
  67157. XMEMSET(&single, 0, sizeof(single));
  67158. certId = wolfSSL_OCSP_SINGLERESP_get0_id(&single);
  67159. ExpectPtrEq(&single, certId);
  67160. ExpectNull(wolfSSL_OCSP_SINGLERESP_get0_id(NULL));
  67161. #endif
  67162. return EXPECT_RESULT();
  67163. }
  67164. static int test_wolfSSL_OCSP_single_get0_status(void)
  67165. {
  67166. EXPECT_DECLS;
  67167. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  67168. defined(WOLFSSL_OCSP_PARSE_STATUS)
  67169. WOLFSSL_OCSP_SINGLERESP single;
  67170. CertStatus certStatus;
  67171. WOLFSSL_ASN1_TIME* thisDate;
  67172. WOLFSSL_ASN1_TIME* nextDate;
  67173. int ret, i;
  67174. XMEMSET(&single, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67175. XMEMSET(&certStatus, 0, sizeof(CertStatus));
  67176. /* Fill the date fields with some dummy data. */
  67177. for (i = 0; i < CTC_DATE_SIZE; ++i) {
  67178. certStatus.thisDateParsed.data[i] = i;
  67179. certStatus.nextDateParsed.data[i] = i;
  67180. }
  67181. certStatus.status = CERT_GOOD;
  67182. single.status = &certStatus;
  67183. ret = wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, &thisDate,
  67184. &nextDate);
  67185. ExpectIntEQ(ret, CERT_GOOD);
  67186. ExpectPtrEq(thisDate, &certStatus.thisDateParsed);
  67187. ExpectPtrEq(nextDate, &certStatus.nextDateParsed);
  67188. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(NULL, NULL, NULL, NULL, NULL),
  67189. CERT_GOOD);
  67190. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, NULL,
  67191. NULL), CERT_GOOD);
  67192. #endif
  67193. return EXPECT_RESULT();
  67194. }
  67195. static int test_wolfSSL_OCSP_resp_count(void)
  67196. {
  67197. EXPECT_DECLS;
  67198. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67199. WOLFSSL_OCSP_BASICRESP basicResp;
  67200. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67201. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67202. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67203. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67204. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67205. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 0);
  67206. basicResp.single = &singleRespOne;
  67207. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 1);
  67208. singleRespOne.next = &singleRespTwo;
  67209. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 2);
  67210. #endif
  67211. return EXPECT_RESULT();
  67212. }
  67213. static int test_wolfSSL_OCSP_resp_get0(void)
  67214. {
  67215. EXPECT_DECLS;
  67216. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67217. WOLFSSL_OCSP_BASICRESP basicResp;
  67218. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67219. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67220. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67221. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67222. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67223. basicResp.single = &singleRespOne;
  67224. singleRespOne.next = &singleRespTwo;
  67225. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 0), &singleRespOne);
  67226. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 1), &singleRespTwo);
  67227. #endif
  67228. return EXPECT_RESULT();
  67229. }
  67230. static int test_wolfSSL_OCSP_parse_url(void)
  67231. {
  67232. EXPECT_DECLS;
  67233. #if defined(OPENSSL_EXTRA) && defined(HAVE_OCSP)
  67234. #define CK_OPU_OK(u, h, po, pa, s) do { \
  67235. char* host = NULL; \
  67236. char* port = NULL; \
  67237. char* path = NULL; \
  67238. int isSsl = 0; \
  67239. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 1); \
  67240. ExpectStrEQ(host, h); \
  67241. ExpectStrEQ(port, po); \
  67242. ExpectStrEQ(path, pa); \
  67243. ExpectIntEQ(isSsl, s); \
  67244. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67245. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67246. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67247. } while(0)
  67248. #define CK_OPU_FAIL(u) do { \
  67249. char* host = NULL; \
  67250. char* port = NULL; \
  67251. char* path = NULL; \
  67252. int isSsl = 0; \
  67253. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 0); \
  67254. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67255. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67256. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67257. } while(0)
  67258. CK_OPU_OK("http://localhost", "localhost", "80", "/", 0);
  67259. CK_OPU_OK("https://wolfssl.com", "wolfssl.com", "443", "/", 1);
  67260. CK_OPU_OK("https://www.wolfssl.com/fips-140-3-announcement-to-the-world/",
  67261. "www.wolfssl.com", "443", "/fips-140-3-announcement-to-the-world/", 1);
  67262. CK_OPU_OK("http://localhost:1234", "localhost", "1234", "/", 0);
  67263. CK_OPU_OK("https://localhost:1234", "localhost", "1234", "/", 1);
  67264. CK_OPU_FAIL("ftp://localhost");
  67265. /* two strings to cppcheck doesn't mark it as a c++ style comment */
  67266. CK_OPU_FAIL("http/""/localhost");
  67267. CK_OPU_FAIL("http:/localhost");
  67268. CK_OPU_FAIL("https://localhost/path:1234");
  67269. #undef CK_OPU_OK
  67270. #undef CK_OPU_FAIL
  67271. #endif
  67272. return EXPECT_RESULT();
  67273. }
  67274. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67275. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67276. static time_t test_wolfSSL_OCSP_REQ_CTX_time_cb(time_t* t)
  67277. {
  67278. if (t != NULL) {
  67279. *t = 1722006780;
  67280. }
  67281. return 1722006780;
  67282. }
  67283. #endif
  67284. static int test_wolfSSL_OCSP_REQ_CTX(void)
  67285. {
  67286. EXPECT_DECLS;
  67287. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67288. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67289. /* This buffer was taken from the ocsp-stapling.test test case 1. The ocsp
  67290. * response was captured in wireshark. It contains both the http and binary
  67291. * parts. The time test_wolfSSL_OCSP_REQ_CTX_time_cb is set exactly so that
  67292. * the time check passes. */
  67293. unsigned char ocspRespBin[] = {
  67294. 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30,
  67295. 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
  67296. 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69,
  67297. 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2d,
  67298. 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x0d, 0x0a, 0x43, 0x6f,
  67299. 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
  67300. 0x3a, 0x20, 0x31, 0x38, 0x32, 0x31, 0x0d, 0x0a, 0x0d, 0x0a, 0x30, 0x82,
  67301. 0x07, 0x19, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x12, 0x30, 0x82, 0x07,
  67302. 0x0e, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01,
  67303. 0x04, 0x82, 0x06, 0xff, 0x30, 0x82, 0x06, 0xfb, 0x30, 0x82, 0x01, 0x19,
  67304. 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
  67305. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06,
  67306. 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e,
  67307. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67308. 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10,
  67309. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c,
  67310. 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04,
  67311. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69,
  67312. 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  67313. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53,
  67314. 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31,
  67315. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
  67316. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  67317. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, 0x32, 0x30,
  67318. 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35,
  67319. 0x5a, 0x30, 0x62, 0x30, 0x60, 0x30, 0x38, 0x30, 0x07, 0x06, 0x05, 0x2b,
  67320. 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59,
  67321. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18,
  67322. 0xda, 0x04, 0x04, 0x14, 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02,
  67323. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e,
  67324. 0x02, 0x01, 0x05, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30,
  67325. 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35, 0x5a, 0xa0, 0x11,
  67326. 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35,
  67327. 0x31, 0x33, 0x30, 0x35, 0x5a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67328. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
  67329. 0x00, 0x89, 0x7a, 0xe9, 0x6b, 0x66, 0x47, 0x8e, 0x52, 0x16, 0xf9, 0x8a,
  67330. 0x5a, 0x1e, 0x7a, 0x35, 0xbb, 0x1d, 0x6c, 0xd8, 0x31, 0xbb, 0x24, 0xd2,
  67331. 0xd7, 0xa4, 0x30, 0x27, 0x06, 0x17, 0x66, 0xd1, 0xf9, 0x8d, 0x24, 0xb0,
  67332. 0x49, 0x37, 0x62, 0x13, 0x78, 0x5e, 0xa6, 0x6d, 0xea, 0xe3, 0xd0, 0x30,
  67333. 0x82, 0x7d, 0xb6, 0xf6, 0x55, 0x82, 0x11, 0xdc, 0xe7, 0x0f, 0xd6, 0x24,
  67334. 0xb4, 0x80, 0x23, 0x4f, 0xfd, 0xa7, 0x9a, 0x4b, 0xac, 0xf2, 0xd3, 0xde,
  67335. 0x42, 0x10, 0xfb, 0x4b, 0x29, 0x06, 0x02, 0x7b, 0x47, 0x36, 0x70, 0x75,
  67336. 0x45, 0x38, 0x8d, 0x3e, 0x55, 0x9c, 0xce, 0x78, 0xd8, 0x18, 0x45, 0x47,
  67337. 0x2d, 0x2a, 0x46, 0x65, 0x13, 0x93, 0x1a, 0x98, 0x90, 0xc6, 0x2d, 0xd5,
  67338. 0x05, 0x2a, 0xfc, 0xcb, 0xac, 0x53, 0x73, 0x93, 0x42, 0x4e, 0xdb, 0x17,
  67339. 0x91, 0xcb, 0xe1, 0x08, 0x03, 0xd1, 0x33, 0x57, 0x4b, 0x1d, 0xb8, 0x71,
  67340. 0x84, 0x01, 0x04, 0x47, 0x6f, 0x06, 0xfa, 0x76, 0x7d, 0xd9, 0x37, 0x64,
  67341. 0x57, 0x37, 0x3a, 0x8f, 0x4d, 0x88, 0x11, 0xa5, 0xd4, 0xaa, 0xcb, 0x49,
  67342. 0x47, 0x86, 0xdd, 0xcf, 0x46, 0xa6, 0xfa, 0x8e, 0xf2, 0x62, 0x0f, 0xc9,
  67343. 0x25, 0xf2, 0x39, 0x62, 0x3e, 0x2d, 0x35, 0xc4, 0x76, 0x7b, 0xae, 0xd5,
  67344. 0xe8, 0x85, 0xa1, 0xa6, 0x2d, 0x41, 0xd6, 0x8e, 0x3c, 0xfa, 0xdc, 0x6c,
  67345. 0x66, 0xe2, 0x61, 0xe7, 0xe5, 0x90, 0xa1, 0xfd, 0x7f, 0xdb, 0x18, 0xd0,
  67346. 0xeb, 0x6d, 0x73, 0x08, 0x5f, 0x6a, 0x65, 0x44, 0x50, 0xad, 0x38, 0x9d,
  67347. 0xb6, 0xfb, 0xbf, 0x28, 0x55, 0x84, 0x65, 0xfa, 0x0e, 0x34, 0xfc, 0x43,
  67348. 0x19, 0x80, 0x5c, 0x7d, 0x2d, 0x5b, 0xd8, 0x60, 0xec, 0x0e, 0xf9, 0x1e,
  67349. 0x6e, 0x32, 0x3f, 0x35, 0xf7, 0xec, 0x7e, 0x47, 0xba, 0xb5, 0xd2, 0xaa,
  67350. 0x5a, 0x9d, 0x07, 0x2c, 0xc5, 0xa0, 0x82, 0x04, 0xc6, 0x30, 0x82, 0x04,
  67351. 0xc2, 0x30, 0x82, 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, 0x02,
  67352. 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67353. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, 0x31,
  67354. 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  67355. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57,
  67356. 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30,
  67357. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74,
  67358. 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
  67359. 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30,
  67360. 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69,
  67361. 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, 0x06,
  67362. 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53,
  67363. 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30,
  67364. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01,
  67365. 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73,
  67366. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,
  67367. 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x34, 0x5a, 0x17,
  67368. 0x0d, 0x32, 0x37, 0x30, 0x34, 0x32, 0x32, 0x31, 0x35, 0x31, 0x32, 0x30,
  67369. 0x34, 0x5a, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
  67370. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
  67371. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67,
  67372. 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07,
  67373. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30,
  67374. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66,
  67375. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  67376. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  67377. 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16,
  67378. 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53, 0x50,
  67379. 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f,
  67380. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67381. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67382. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30,
  67383. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  67384. 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
  67385. 0x82, 0x01, 0x01, 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, 0x14,
  67386. 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, 0x1e, 0x63, 0xb9, 0x85, 0x23,
  67387. 0x34, 0x50, 0x6d, 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, 0x5c,
  67388. 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, 0xea, 0x0b, 0x45, 0x35, 0x2b,
  67389. 0xeb, 0x1f, 0xb1, 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, 0xd6,
  67390. 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, 0xca, 0x3f, 0x46, 0x2b, 0xfe,
  67391. 0xe5, 0x5a, 0x3f, 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, 0xc3,
  67392. 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, 0xe1, 0xd9, 0x65, 0xb7, 0x43,
  67393. 0xc4, 0x18, 0xde, 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, 0x55,
  67394. 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, 0x0a, 0x5a, 0x4f, 0x4a, 0x73,
  67395. 0x31, 0x50, 0xee, 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, 0x87,
  67396. 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, 0x67, 0xca, 0x5c, 0xd1, 0x97,
  67397. 0xbd, 0xc8, 0xf1, 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, 0x66,
  67398. 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, 0xb4, 0x90, 0x30, 0xbb, 0x17,
  67399. 0xb0, 0xfe, 0x97, 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, 0x19,
  67400. 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, 0xae, 0x3f, 0x32, 0xb2, 0x08,
  67401. 0x71, 0xb2, 0x1b, 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, 0xcf,
  67402. 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, 0x24, 0x87, 0x17, 0x3b, 0xd8,
  67403. 0x04, 0x65, 0x6c, 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, 0x73,
  67404. 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, 0x6e, 0x61, 0xb8, 0x87, 0x84,
  67405. 0xfa, 0x80, 0x1a, 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, 0x1c,
  67406. 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, 0x39, 0x02, 0x03, 0x01, 0x00,
  67407. 0x01, 0xa3, 0x82, 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, 0x06,
  67408. 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,
  67409. 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, 0x79,
  67410. 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, 0x40, 0x50, 0xb5, 0x46, 0x56,
  67411. 0xb8, 0x30, 0x36, 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
  67412. 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, 0x73, 0xb0, 0x1c, 0xa4, 0x2f,
  67413. 0x82, 0xcb, 0xcf, 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, 0x7e,
  67414. 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, 0x81, 0x9a, 0x30, 0x81, 0x97,
  67415. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  67416. 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a,
  67417. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10,
  67418. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61,
  67419. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67420. 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14,
  67421. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67,
  67422. 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16,
  67423. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53,
  67424. 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f,
  67425. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67426. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67427. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, 0x13,
  67428. 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b,
  67429. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  67430. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  67431. 0x01, 0x01, 0x00, 0x37, 0xb9, 0x66, 0xd3, 0xa1, 0x08, 0xfc, 0x37, 0x58,
  67432. 0x4e, 0xe0, 0x8c, 0xd3, 0x7f, 0xa6, 0x0f, 0x59, 0xd3, 0x14, 0xf7, 0x4b,
  67433. 0x36, 0xf7, 0x2e, 0x98, 0xeb, 0x7c, 0x03, 0x3f, 0x3a, 0xd6, 0x9c, 0xcd,
  67434. 0xb4, 0x9e, 0x8d, 0x5f, 0x92, 0xa6, 0x6f, 0x63, 0x87, 0x34, 0xe8, 0x83,
  67435. 0xfd, 0x6d, 0x34, 0x64, 0xb5, 0xf0, 0x9c, 0x71, 0x02, 0xb8, 0xf6, 0x2f,
  67436. 0x10, 0xa0, 0x92, 0x8f, 0x3f, 0x86, 0x3e, 0xe2, 0x01, 0x5a, 0x56, 0x39,
  67437. 0x0a, 0x8d, 0xb1, 0xbe, 0x03, 0xf7, 0xf8, 0xa7, 0x88, 0x46, 0xef, 0x81,
  67438. 0xa0, 0xad, 0x86, 0xc9, 0xe6, 0x23, 0x89, 0x1d, 0xa6, 0x24, 0x45, 0xf2,
  67439. 0x6a, 0x83, 0x2d, 0x8e, 0x92, 0x17, 0x1e, 0x44, 0x19, 0xfa, 0x0f, 0x47,
  67440. 0x6b, 0x8f, 0x4a, 0xa2, 0xda, 0xab, 0xd5, 0x2b, 0xcd, 0xcb, 0x14, 0xf0,
  67441. 0xb5, 0xcf, 0x7c, 0x76, 0x42, 0x32, 0x90, 0x21, 0xdc, 0xdd, 0x52, 0xfc,
  67442. 0x53, 0x7e, 0xff, 0x7f, 0xd9, 0x58, 0x6b, 0x1f, 0x73, 0xee, 0x83, 0xf4,
  67443. 0x67, 0xfa, 0x4a, 0x4f, 0x24, 0xe4, 0x2b, 0x10, 0x74, 0x89, 0x52, 0x9a,
  67444. 0xf7, 0xa4, 0xe0, 0xaf, 0xf5, 0x63, 0xd7, 0xfa, 0x0b, 0x2c, 0xc9, 0x39,
  67445. 0x5d, 0xbd, 0x44, 0x93, 0x69, 0xa4, 0x1d, 0x01, 0xe2, 0x66, 0xe7, 0xc1,
  67446. 0x11, 0x44, 0x7d, 0x0a, 0x7e, 0x5d, 0x1d, 0x26, 0xc5, 0x4a, 0x26, 0x2e,
  67447. 0xa3, 0x58, 0xc4, 0xf7, 0x10, 0xcb, 0xba, 0xe6, 0x27, 0xfc, 0xdb, 0x54,
  67448. 0xe2, 0x60, 0x08, 0xc2, 0x0e, 0x4b, 0xd4, 0xaa, 0x22, 0x23, 0x93, 0x9f,
  67449. 0xe1, 0xcb, 0x85, 0xa4, 0x41, 0x6f, 0x26, 0xa7, 0x77, 0x8a, 0xef, 0x66,
  67450. 0xd0, 0xf8, 0x33, 0xf6, 0xfd, 0x6d, 0x37, 0x7a, 0x89, 0xcc, 0x88, 0x3b,
  67451. 0x82, 0xd0, 0xa9, 0xdf, 0xf1, 0x3d, 0xdc, 0xb0, 0x06, 0x1c, 0xe4, 0x4b,
  67452. 0x57, 0xb4, 0x0c, 0x65, 0xb9, 0xb4, 0x6c
  67453. };
  67454. OCSP_REQ_CTX *ctx = NULL;
  67455. OCSP_REQUEST *req = NULL;
  67456. OCSP_CERTID *cid = NULL;
  67457. OCSP_RESPONSE *rsp = NULL;
  67458. BIO* bio1 = NULL;
  67459. BIO* bio2 = NULL;
  67460. X509* cert = NULL;
  67461. X509 *issuer = NULL;
  67462. X509_LOOKUP *lookup = NULL;
  67463. X509_STORE *store = NULL;
  67464. STACK_OF(X509_OBJECT) *str_objs = NULL;
  67465. X509_OBJECT *x509_obj = NULL;
  67466. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  67467. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  67468. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  67469. /* Load the leaf cert */
  67470. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(
  67471. "certs/ocsp/server1-cert.pem", WOLFSSL_FILETYPE_PEM));
  67472. ExpectNotNull(store = X509_STORE_new());
  67473. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  67474. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ocsp/server1-cert.pem",
  67475. X509_FILETYPE_PEM), 1);
  67476. ExpectNotNull(str_objs = X509_STORE_get0_objects(store));
  67477. ExpectNotNull(x509_obj = X509_OBJECT_retrieve_by_subject(str_objs,
  67478. X509_LU_X509, X509_get_issuer_name(cert)));
  67479. ExpectNotNull(issuer = X509_OBJECT_get0_X509(x509_obj));
  67480. ExpectNotNull(req = OCSP_REQUEST_new());
  67481. ExpectNotNull(cid = OCSP_cert_to_id(EVP_sha1(), cert, issuer));
  67482. ExpectNotNull(OCSP_request_add0_id(req, cid));
  67483. ExpectIntEQ(OCSP_request_add1_nonce(req, NULL, -1), 1);
  67484. ExpectNotNull(ctx = OCSP_sendreq_new(bio1, "/", NULL, -1));
  67485. ExpectIntEQ(OCSP_REQ_CTX_add1_header(ctx, "Host", "127.0.0.1"), 1);
  67486. ExpectIntEQ(OCSP_REQ_CTX_set1_req(ctx, req), 1);
  67487. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), -1);
  67488. ExpectIntEQ(BIO_write(bio2, ocspRespBin, sizeof(ocspRespBin)),
  67489. sizeof(ocspRespBin));
  67490. ExpectIntEQ(wc_SetTimeCb(test_wolfSSL_OCSP_REQ_CTX_time_cb), 0);
  67491. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), 1);
  67492. ExpectIntEQ(wc_SetTimeCb(NULL), 0);
  67493. ExpectNotNull(rsp);
  67494. OCSP_REQ_CTX_free(ctx);
  67495. OCSP_REQUEST_free(req);
  67496. OCSP_RESPONSE_free(rsp);
  67497. BIO_free(bio1);
  67498. BIO_free(bio2);
  67499. X509_free(cert);
  67500. X509_STORE_free(store);
  67501. #endif
  67502. return EXPECT_RESULT();
  67503. }
  67504. static int test_wolfSSL_EVP_PKEY_derive(void)
  67505. {
  67506. EXPECT_DECLS;
  67507. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  67508. #if (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || defined(HAVE_ECC)
  67509. EVP_PKEY_CTX *ctx = NULL;
  67510. unsigned char *skey = NULL;
  67511. size_t skeylen;
  67512. EVP_PKEY *pkey = NULL;
  67513. EVP_PKEY *peerkey = NULL;
  67514. const unsigned char* key;
  67515. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  67516. /* DH */
  67517. key = dh_key_der_2048;
  67518. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  67519. sizeof_dh_key_der_2048)));
  67520. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(pkey)), 1);
  67521. key = dh_key_der_2048;
  67522. ExpectNotNull((peerkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  67523. sizeof_dh_key_der_2048)));
  67524. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(peerkey)), 1);
  67525. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67526. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  67527. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  67528. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  67529. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  67530. DYNAMIC_TYPE_OPENSSL));
  67531. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  67532. EVP_PKEY_CTX_free(ctx);
  67533. ctx = NULL;
  67534. EVP_PKEY_free(peerkey);
  67535. peerkey = NULL;
  67536. EVP_PKEY_free(pkey);
  67537. pkey = NULL;
  67538. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  67539. skey = NULL;
  67540. #endif
  67541. #ifdef HAVE_ECC
  67542. /* ECDH */
  67543. key = ecc_clikey_der_256;
  67544. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &key,
  67545. sizeof_ecc_clikey_der_256)));
  67546. key = ecc_clikeypub_der_256;
  67547. ExpectNotNull((peerkey = d2i_PUBKEY(NULL, &key,
  67548. sizeof_ecc_clikeypub_der_256)));
  67549. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67550. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  67551. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  67552. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  67553. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  67554. DYNAMIC_TYPE_OPENSSL));
  67555. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  67556. EVP_PKEY_CTX_free(ctx);
  67557. EVP_PKEY_free(peerkey);
  67558. EVP_PKEY_free(pkey);
  67559. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  67560. #endif /* HAVE_ECC */
  67561. #endif /* (!NO_DH && WOLFSSL_DH_EXTRA) || HAVE_ECC */
  67562. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  67563. return EXPECT_RESULT();
  67564. }
  67565. static int test_wolfSSL_EVP_PBE_scrypt(void)
  67566. {
  67567. EXPECT_DECLS;
  67568. #if defined(OPENSSL_EXTRA) && defined(HAVE_SCRYPT) && defined(HAVE_PBKDF2) && \
  67569. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 5))
  67570. #if !defined(NO_PWDBASED) && !defined(NO_SHA256)
  67571. int ret;
  67572. const char pwd[] = {'p','a','s','s','w','o','r','d'};
  67573. int pwdlen = sizeof(pwd);
  67574. const byte salt[] = {'N','a','C','l'};
  67575. int saltlen = sizeof(salt);
  67576. byte key[80];
  67577. word64 numOvr32 = (word64)INT32_MAX + 1;
  67578. /* expected derived key for N:16, r:1, p:1 */
  67579. const byte expectedKey[] = {
  67580. 0xAE, 0xC6, 0xB7, 0x48, 0x3E, 0xD2, 0x6E, 0x08, 0x80, 0x2B,
  67581. 0x41, 0xF4, 0x03, 0x20, 0x86, 0xA0, 0xE8, 0x86, 0xBE, 0x7A,
  67582. 0xC4, 0x8F, 0xCF, 0xD9, 0x2F, 0xF0, 0xCE, 0xF8, 0x10, 0x97,
  67583. 0x52, 0xF4, 0xAC, 0x74, 0xB0, 0x77, 0x26, 0x32, 0x56, 0xA6,
  67584. 0x5A, 0x99, 0x70, 0x1B, 0x7A, 0x30, 0x4D, 0x46, 0x61, 0x1C,
  67585. 0x8A, 0xA3, 0x91, 0xE7, 0x99, 0xCE, 0x10, 0xA2, 0x77, 0x53,
  67586. 0xE7, 0xE9, 0xC0, 0x9A};
  67587. /* N r p mx key keylen */
  67588. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 0, 1, 1, 0, key, 64);
  67589. ExpectIntEQ(ret, 0); /* N must be greater than 1 */
  67590. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 3, 1, 1, 0, key, 64);
  67591. ExpectIntEQ(ret, 0); /* N must be power of 2 */
  67592. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 0, 1, 0, key, 64);
  67593. ExpectIntEQ(ret, 0); /* r must be greater than 0 */
  67594. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 0, 0, key, 64);
  67595. ExpectIntEQ(ret, 0); /* p must be greater than 0 */
  67596. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 0);
  67597. ExpectIntEQ(ret, 0); /* keylen must be greater than 0 */
  67598. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 9, 1, 0, key, 64);
  67599. ExpectIntEQ(ret, 0); /* r must be smaller than 9 */
  67600. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, NULL, 64);
  67601. ExpectIntEQ(ret, 1); /* should succeed if key is NULL */
  67602. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 64);
  67603. ExpectIntEQ(ret, 1); /* should succeed */
  67604. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, numOvr32, 1, 0,
  67605. key, 64);
  67606. ExpectIntEQ(ret, 0); /* should fail since r is greater than INT32_MAC */
  67607. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, numOvr32, 0,
  67608. key, 64);
  67609. ExpectIntEQ(ret, 0); /* should fail since p is greater than INT32_MAC */
  67610. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 0, 2, 1, 1, 0, key, 64);
  67611. ExpectIntEQ(ret, 1); /* should succeed even if salt is NULL */
  67612. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 4, 2, 1, 1, 0, key, 64);
  67613. ExpectIntEQ(ret, 0); /* if salt is NULL, saltlen must be 0, otherwise fail*/
  67614. ret = EVP_PBE_scrypt(NULL, 0, salt, saltlen, 2, 1, 1, 0, key, 64);
  67615. ExpectIntEQ(ret, 1); /* should succeed if pwd is NULL and pwdlen is 0*/
  67616. ret = EVP_PBE_scrypt(NULL, 4, salt, saltlen, 2, 1, 1, 0, key, 64);
  67617. ExpectIntEQ(ret, 0); /* if pwd is NULL, pwdlen must be 0 */
  67618. ret = EVP_PBE_scrypt(NULL, 0, NULL, 0, 2, 1, 1, 0, key, 64);
  67619. ExpectIntEQ(ret, 1); /* should succeed even both pwd and salt are NULL */
  67620. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 16, 1, 1, 0, key, 64);
  67621. ExpectIntEQ(ret, 1);
  67622. ret = XMEMCMP(expectedKey, key, sizeof(expectedKey));
  67623. ExpectIntEQ(ret, 0); /* derived key must be the same as expected-key */
  67624. #endif /* !NO_PWDBASED && !NO_SHA256 */
  67625. #endif /* OPENSSL_EXTRA && HAVE_SCRYPT && HAVE_PBKDF2 */
  67626. return EXPECT_RESULT();
  67627. }
  67628. static int test_no_op_functions(void)
  67629. {
  67630. EXPECT_DECLS;
  67631. #if defined(OPENSSL_EXTRA)
  67632. /* this makes sure wolfSSL can compile and run these no-op functions */
  67633. SSL_load_error_strings();
  67634. ENGINE_load_builtin_engines();
  67635. OpenSSL_add_all_ciphers();
  67636. ExpectIntEQ(CRYPTO_malloc_init(), 0);
  67637. #endif
  67638. return EXPECT_RESULT();
  67639. }
  67640. static int test_wolfSSL_CRYPTO_memcmp(void)
  67641. {
  67642. EXPECT_DECLS;
  67643. #ifdef OPENSSL_EXTRA
  67644. char a[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  67645. "implementation of TLS/SSL for embedded devices to the cloud.";
  67646. char b[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  67647. "implementation of TLS/SSL for embedded devices to the cloud.";
  67648. char c[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  67649. "implementation of TLS/SSL for embedded devices to the cloud!";
  67650. ExpectIntEQ(CRYPTO_memcmp(a, b, sizeof(a)), 0);
  67651. ExpectIntNE(CRYPTO_memcmp(a, c, sizeof(a)), 0);
  67652. #endif
  67653. return EXPECT_RESULT();
  67654. }
  67655. /*----------------------------------------------------------------------------*
  67656. | wolfCrypt ASN
  67657. *----------------------------------------------------------------------------*/
  67658. static int test_wc_CreateEncryptedPKCS8Key(void)
  67659. {
  67660. EXPECT_DECLS;
  67661. #if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \
  67662. && !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \
  67663. !defined(NO_ASN_CRYPT)
  67664. WC_RNG rng;
  67665. byte* encKey = NULL;
  67666. word32 encKeySz = 0;
  67667. word32 decKeySz = 0;
  67668. const char password[] = "Lorem ipsum dolor sit amet";
  67669. word32 passwordSz = (word32)XSTRLEN(password);
  67670. word32 tradIdx = 0;
  67671. XMEMSET(&rng, 0, sizeof(WC_RNG));
  67672. ExpectIntEQ(wc_InitRng(&rng), 0);
  67673. PRIVATE_KEY_UNLOCK();
  67674. /* Call with NULL for out buffer to get necessary length. */
  67675. ExpectIntEQ(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  67676. sizeof_server_key_der_2048, NULL, &encKeySz, password, (int)passwordSz,
  67677. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  67678. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  67679. ExpectNotNull(encKey = (byte*)XMALLOC(encKeySz, HEAP_HINT,
  67680. DYNAMIC_TYPE_TMP_BUFFER));
  67681. /* Call with the allocated out buffer. */
  67682. ExpectIntGT(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  67683. sizeof_server_key_der_2048, encKey, &encKeySz, password, (int)passwordSz,
  67684. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  67685. 0);
  67686. /* Decrypt the encrypted PKCS8 key we just made. */
  67687. ExpectIntGT((decKeySz = (word32)wc_DecryptPKCS8Key(encKey, encKeySz, password,
  67688. (int)passwordSz)), 0);
  67689. /* encKey now holds the decrypted key (decrypted in place). */
  67690. ExpectIntGT(wc_GetPkcs8TraditionalOffset(encKey, &tradIdx, decKeySz), 0);
  67691. /* Check that the decrypted key matches the key prior to encryption. */
  67692. ExpectIntEQ(XMEMCMP(encKey + tradIdx, server_key_der_2048,
  67693. sizeof_server_key_der_2048), 0);
  67694. PRIVATE_KEY_LOCK();
  67695. XFREE(encKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  67696. wc_FreeRng(&rng);
  67697. #endif
  67698. return EXPECT_RESULT();
  67699. }
  67700. static int test_wc_GetPkcs8TraditionalOffset(void)
  67701. {
  67702. EXPECT_DECLS;
  67703. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(HAVE_PKCS8)
  67704. int length;
  67705. int derSz = 0;
  67706. word32 inOutIdx;
  67707. const char* path = "./certs/server-keyPkcs8.der";
  67708. const char* pathAttributes = "./certs/ca-key-pkcs8-attribute.der";
  67709. XFILE file = XBADFILE;
  67710. byte der[2048];
  67711. ExpectTrue((file = XFOPEN(path, "rb")) != XBADFILE);
  67712. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  67713. if (file != XBADFILE)
  67714. XFCLOSE(file);
  67715. file = XBADFILE; /* reset file to avoid warning of use after close */
  67716. /* valid case */
  67717. inOutIdx = 0;
  67718. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  67719. 0);
  67720. /* inOutIdx > sz */
  67721. inOutIdx = 4000;
  67722. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  67723. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  67724. /* null input */
  67725. inOutIdx = 0;
  67726. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(NULL, &inOutIdx, 0),
  67727. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  67728. /* invalid input, fill buffer with 1's */
  67729. XMEMSET(der, 1, sizeof(der));
  67730. inOutIdx = 0;
  67731. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  67732. WC_NO_ERR_TRACE(ASN_PARSE_E));
  67733. /* test parsing with attributes */
  67734. ExpectTrue((file = XFOPEN(pathAttributes, "rb")) != XBADFILE);
  67735. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  67736. if (file != XBADFILE)
  67737. XFCLOSE(file);
  67738. inOutIdx = 0;
  67739. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx,
  67740. (word32)derSz), 0);
  67741. #endif /* NO_ASN */
  67742. return EXPECT_RESULT();
  67743. }
  67744. static int test_wc_SetSubjectRaw(void)
  67745. {
  67746. EXPECT_DECLS;
  67747. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67748. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  67749. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  67750. WOLFSSL_X509* x509 = NULL;
  67751. int peerCertSz;
  67752. const byte* peerCertBuf = NULL;
  67753. Cert forgedCert;
  67754. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  67755. WOLFSSL_FILETYPE_ASN1));
  67756. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  67757. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  67758. ExpectIntEQ(0, wc_SetSubjectRaw(&forgedCert, peerCertBuf, peerCertSz));
  67759. wolfSSL_FreeX509(x509);
  67760. #endif
  67761. return EXPECT_RESULT();
  67762. }
  67763. static int test_wc_GetSubjectRaw(void)
  67764. {
  67765. EXPECT_DECLS;
  67766. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67767. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT)
  67768. Cert cert;
  67769. byte *subjectRaw;
  67770. ExpectIntEQ(0, wc_InitCert(&cert));
  67771. ExpectIntEQ(0, wc_GetSubjectRaw(&subjectRaw, &cert));
  67772. #endif
  67773. return EXPECT_RESULT();
  67774. }
  67775. static int test_wc_SetIssuerRaw(void)
  67776. {
  67777. EXPECT_DECLS;
  67778. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67779. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  67780. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  67781. WOLFSSL_X509* x509 = NULL;
  67782. int peerCertSz;
  67783. const byte* peerCertBuf;
  67784. Cert forgedCert;
  67785. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  67786. WOLFSSL_FILETYPE_ASN1));
  67787. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  67788. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  67789. ExpectIntEQ(0, wc_SetIssuerRaw(&forgedCert, peerCertBuf, peerCertSz));
  67790. wolfSSL_FreeX509(x509);
  67791. #endif
  67792. return EXPECT_RESULT();
  67793. }
  67794. static int test_wc_SetIssueBuffer(void)
  67795. {
  67796. EXPECT_DECLS;
  67797. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67798. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  67799. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  67800. WOLFSSL_X509* x509 = NULL;
  67801. int peerCertSz;
  67802. const byte* peerCertBuf;
  67803. Cert forgedCert;
  67804. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  67805. WOLFSSL_FILETYPE_ASN1));
  67806. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  67807. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  67808. ExpectIntEQ(0, wc_SetIssuerBuffer(&forgedCert, peerCertBuf, peerCertSz));
  67809. wolfSSL_FreeX509(x509);
  67810. #endif
  67811. return EXPECT_RESULT();
  67812. }
  67813. /*
  67814. * Testing wc_SetSubjectKeyId
  67815. */
  67816. static int test_wc_SetSubjectKeyId(void)
  67817. {
  67818. EXPECT_DECLS;
  67819. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67820. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  67821. Cert cert;
  67822. const char* file = "certs/ecc-client-keyPub.pem";
  67823. ExpectIntEQ(0, wc_InitCert(&cert));
  67824. ExpectIntEQ(0, wc_SetSubjectKeyId(&cert, file));
  67825. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubjectKeyId(NULL, file));
  67826. ExpectIntGT(0, wc_SetSubjectKeyId(&cert, "badfile.name"));
  67827. #endif
  67828. return EXPECT_RESULT();
  67829. } /* END test_wc_SetSubjectKeyId */
  67830. /*
  67831. * Testing wc_SetSubject
  67832. */
  67833. static int test_wc_SetSubject(void)
  67834. {
  67835. EXPECT_DECLS;
  67836. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67837. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  67838. Cert cert;
  67839. const char* file = "./certs/ca-ecc-cert.pem";
  67840. ExpectIntEQ(0, wc_InitCert(&cert));
  67841. ExpectIntEQ(0, wc_SetSubject(&cert, file));
  67842. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubject(NULL, file));
  67843. ExpectIntGT(0, wc_SetSubject(&cert, "badfile.name"));
  67844. #endif
  67845. return EXPECT_RESULT();
  67846. } /* END test_wc_SetSubject */
  67847. static int test_CheckCertSignature(void)
  67848. {
  67849. EXPECT_DECLS;
  67850. #if !defined(NO_CERTS) && defined(WOLFSSL_SMALL_CERT_VERIFY)
  67851. WOLFSSL_CERT_MANAGER* cm = NULL;
  67852. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  67853. XFILE fp = XBADFILE;
  67854. byte cert[4096];
  67855. int certSz;
  67856. #endif
  67857. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, NULL));
  67858. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  67859. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, cm));
  67860. #ifndef NO_RSA
  67861. #ifdef USE_CERT_BUFFERS_1024
  67862. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_1024,
  67863. sizeof_server_cert_der_1024, NULL, cm));
  67864. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  67865. ca_cert_der_1024, sizeof_ca_cert_der_1024,
  67866. WOLFSSL_FILETYPE_ASN1));
  67867. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_1024,
  67868. sizeof_server_cert_der_1024, NULL, cm));
  67869. #elif defined(USE_CERT_BUFFERS_2048)
  67870. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_2048,
  67871. sizeof_server_cert_der_2048, NULL, cm));
  67872. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  67873. ca_cert_der_2048, sizeof_ca_cert_der_2048,
  67874. WOLFSSL_FILETYPE_ASN1));
  67875. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_2048,
  67876. sizeof_server_cert_der_2048, NULL, cm));
  67877. #endif
  67878. #endif
  67879. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  67880. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(serv_ecc_der_256,
  67881. sizeof_serv_ecc_der_256, NULL, cm));
  67882. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  67883. ca_ecc_cert_der_256, sizeof_ca_ecc_cert_der_256,
  67884. WOLFSSL_FILETYPE_ASN1));
  67885. ExpectIntEQ(0, wc_CheckCertSignature(serv_ecc_der_256, sizeof_serv_ecc_der_256,
  67886. NULL, cm));
  67887. #endif
  67888. #if !defined(NO_FILESYSTEM)
  67889. wolfSSL_CertManagerFree(cm);
  67890. cm = NULL;
  67891. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  67892. #ifndef NO_RSA
  67893. ExpectTrue((fp = XFOPEN("./certs/server-cert.der", "rb")) != XBADFILE);
  67894. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  67895. if (fp != XBADFILE) {
  67896. XFCLOSE(fp);
  67897. fp = XBADFILE;
  67898. }
  67899. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  67900. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  67901. "./certs/ca-cert.pem", NULL));
  67902. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  67903. #endif
  67904. #ifdef HAVE_ECC
  67905. ExpectTrue((fp = XFOPEN("./certs/server-ecc.der", "rb")) != XBADFILE);
  67906. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  67907. if (fp != XBADFILE) {
  67908. XFCLOSE(fp);
  67909. fp = XBADFILE;
  67910. }
  67911. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  67912. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  67913. "./certs/ca-ecc-cert.pem", NULL));
  67914. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  67915. #endif
  67916. #endif
  67917. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  67918. (void)fp;
  67919. (void)cert;
  67920. (void)certSz;
  67921. #endif
  67922. wolfSSL_CertManagerFree(cm);
  67923. #endif
  67924. return EXPECT_RESULT();
  67925. }
  67926. static int test_wc_ParseCert(void)
  67927. {
  67928. EXPECT_DECLS;
  67929. #if !defined(NO_CERTS) && !defined(NO_RSA)
  67930. DecodedCert decodedCert;
  67931. const byte* rawCert = client_cert_der_2048;
  67932. const int rawCertSize = sizeof_client_cert_der_2048;
  67933. wc_InitDecodedCert(&decodedCert, rawCert, rawCertSize, NULL);
  67934. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  67935. #ifndef IGNORE_NAME_CONSTRAINTS
  67936. /* check that the subjects emailAddress was not put in the alt name list */
  67937. ExpectNotNull(decodedCert.subjectEmail);
  67938. ExpectNull(decodedCert.altEmailNames);
  67939. #endif
  67940. wc_FreeDecodedCert(&decodedCert);
  67941. #endif
  67942. return EXPECT_RESULT();
  67943. }
  67944. /* Test wc_ParseCert decoding of various encodings and scenarios ensuring that
  67945. * the API safely errors out on badly-formed ASN input.
  67946. * NOTE: Test not compatible with released FIPS implementations!
  67947. */
  67948. static int test_wc_ParseCert_Error(void)
  67949. {
  67950. EXPECT_DECLS;
  67951. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(HAVE_SELFTEST) && \
  67952. (!defined(HAVE_FIPS) || \
  67953. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  67954. DecodedCert decodedCert;
  67955. int i;
  67956. /* Certificate data */
  67957. const byte c0[] = { 0x30, 0x04, 0x30, 0x02, 0x02, 0x80, 0x00, 0x00};
  67958. const byte c1[] = { 0x30, 0x04, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  67959. const byte c2[] = { 0x30, 0x06, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  67960. const byte c3[] = { 0x30, 0x07, 0x30, 0x05, 0x02, 0x80, 0x10, 0x00, 0x00};
  67961. const byte c4[] = { 0x02, 0x80, 0x10, 0x00, 0x00};
  67962. /* Test data */
  67963. const struct testStruct {
  67964. const byte* c;
  67965. const int cSz;
  67966. const int expRet;
  67967. } t[] = {
  67968. {c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  67969. {c1, sizeof(c1), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  67970. {c2, sizeof(c2), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid integer length (zero) */
  67971. {c3, sizeof(c3), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but buffer too short */
  67972. {c4, sizeof(c4), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but not in bit-string */
  67973. };
  67974. const int tSz = (int)(sizeof(t) / sizeof(struct testStruct));
  67975. for (i = 0; i < tSz; i++) {
  67976. WOLFSSL_MSG_EX("i == %d", i);
  67977. wc_InitDecodedCert(&decodedCert, t[i].c, t[i].cSz, NULL);
  67978. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), t[i].expRet);
  67979. wc_FreeDecodedCert(&decodedCert);
  67980. }
  67981. #endif
  67982. return EXPECT_RESULT();
  67983. }
  67984. static int test_MakeCertWithPathLen(void)
  67985. {
  67986. EXPECT_DECLS;
  67987. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  67988. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  67989. const byte expectedPathLen = 7;
  67990. Cert cert;
  67991. DecodedCert decodedCert;
  67992. byte der[FOURK_BUF];
  67993. int derSize = 0;
  67994. WC_RNG rng;
  67995. ecc_key key;
  67996. int ret;
  67997. XMEMSET(&rng, 0, sizeof(WC_RNG));
  67998. XMEMSET(&key, 0, sizeof(ecc_key));
  67999. XMEMSET(&cert, 0, sizeof(Cert));
  68000. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68001. ExpectIntEQ(wc_InitRng(&rng), 0);
  68002. ExpectIntEQ(wc_ecc_init(&key), 0);
  68003. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68004. ExpectIntEQ(wc_InitCert(&cert), 0);
  68005. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68006. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68007. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68008. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68009. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68010. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68011. CTC_NAME_SIZE);
  68012. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68013. CTC_NAME_SIZE);
  68014. cert.selfSigned = 1;
  68015. cert.isCA = 1;
  68016. cert.pathLen = expectedPathLen;
  68017. cert.pathLenSet = 1;
  68018. cert.sigType = CTC_SHA256wECDSA;
  68019. #ifdef WOLFSSL_CERT_EXT
  68020. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68021. #endif
  68022. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68023. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68024. FOURK_BUF, NULL, &key, &rng), 0);
  68025. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68026. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68027. ExpectIntEQ(decodedCert.pathLength, expectedPathLen);
  68028. wc_FreeDecodedCert(&decodedCert);
  68029. ret = wc_ecc_free(&key);
  68030. ExpectIntEQ(ret, 0);
  68031. ret = wc_FreeRng(&rng);
  68032. ExpectIntEQ(ret, 0);
  68033. #endif
  68034. return EXPECT_RESULT();
  68035. }
  68036. static int test_MakeCertWith0Ser(void)
  68037. {
  68038. EXPECT_DECLS;
  68039. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  68040. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \
  68041. defined(WOLFSSL_ASN_TEMPLATE)
  68042. Cert cert;
  68043. DecodedCert decodedCert;
  68044. byte der[FOURK_BUF];
  68045. int derSize = 0;
  68046. WC_RNG rng;
  68047. ecc_key key;
  68048. int ret;
  68049. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68050. XMEMSET(&key, 0, sizeof(ecc_key));
  68051. XMEMSET(&cert, 0, sizeof(Cert));
  68052. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68053. ExpectIntEQ(wc_InitRng(&rng), 0);
  68054. ExpectIntEQ(wc_ecc_init(&key), 0);
  68055. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68056. ExpectIntEQ(wc_InitCert(&cert), 0);
  68057. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68058. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68059. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68060. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68061. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68062. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68063. CTC_NAME_SIZE);
  68064. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68065. CTC_NAME_SIZE);
  68066. cert.selfSigned = 1;
  68067. cert.isCA = 1;
  68068. cert.sigType = CTC_SHA256wECDSA;
  68069. #ifdef WOLFSSL_CERT_EXT
  68070. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68071. #endif
  68072. /* set serial number to 0 */
  68073. cert.serialSz = 1;
  68074. cert.serial[0] = 0;
  68075. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68076. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68077. FOURK_BUF, NULL, &key, &rng), 0);
  68078. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68079. #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON)
  68080. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL),
  68081. WC_NO_ERR_TRACE(ASN_PARSE_E));
  68082. #else
  68083. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68084. #endif
  68085. wc_FreeDecodedCert(&decodedCert);
  68086. ret = wc_ecc_free(&key);
  68087. ExpectIntEQ(ret, 0);
  68088. ret = wc_FreeRng(&rng);
  68089. ExpectIntEQ(ret, 0);
  68090. #endif
  68091. return EXPECT_RESULT();
  68092. }
  68093. static int test_MakeCertWithCaFalse(void)
  68094. {
  68095. EXPECT_DECLS;
  68096. #if defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE) && defined(WOLFSSL_CERT_REQ) && \
  68097. !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  68098. const byte expectedIsCa = 0;
  68099. Cert cert;
  68100. DecodedCert decodedCert;
  68101. byte der[FOURK_BUF];
  68102. int derSize = 0;
  68103. WC_RNG rng;
  68104. ecc_key key;
  68105. int ret;
  68106. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68107. XMEMSET(&key, 0, sizeof(ecc_key));
  68108. XMEMSET(&cert, 0, sizeof(Cert));
  68109. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68110. ExpectIntEQ(wc_InitRng(&rng), 0);
  68111. ExpectIntEQ(wc_ecc_init(&key), 0);
  68112. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68113. ExpectIntEQ(wc_InitCert(&cert), 0);
  68114. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68115. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68116. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68117. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68118. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68119. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68120. CTC_NAME_SIZE);
  68121. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68122. CTC_NAME_SIZE);
  68123. cert.selfSigned = 1;
  68124. cert.isCA = expectedIsCa;
  68125. cert.isCaSet = 1;
  68126. cert.sigType = CTC_SHA256wECDSA;
  68127. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68128. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68129. FOURK_BUF, NULL, &key, &rng), 0);
  68130. wc_InitDecodedCert(&decodedCert, der, derSize, NULL);
  68131. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68132. ExpectIntEQ(decodedCert.isCA, expectedIsCa);
  68133. wc_FreeDecodedCert(&decodedCert);
  68134. ret = wc_ecc_free(&key);
  68135. ExpectIntEQ(ret, 0);
  68136. ret = wc_FreeRng(&rng);
  68137. ExpectIntEQ(ret, 0);
  68138. #endif
  68139. return EXPECT_RESULT();
  68140. }
  68141. /*----------------------------------------------------------------------------*
  68142. | wolfCrypt ECC
  68143. *----------------------------------------------------------------------------*/
  68144. static int test_wc_ecc_get_curve_size_from_name(void)
  68145. {
  68146. EXPECT_DECLS;
  68147. #ifdef HAVE_ECC
  68148. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68149. ExpectIntEQ(wc_ecc_get_curve_size_from_name("SECP256R1"), 32);
  68150. #endif
  68151. /* invalid case */
  68152. ExpectIntEQ(wc_ecc_get_curve_size_from_name("BADCURVE"), -1);
  68153. /* NULL input */
  68154. ExpectIntEQ(wc_ecc_get_curve_size_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68155. #endif /* HAVE_ECC */
  68156. return EXPECT_RESULT();
  68157. }
  68158. static int test_wc_ecc_get_curve_id_from_name(void)
  68159. {
  68160. EXPECT_DECLS;
  68161. #ifdef HAVE_ECC
  68162. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68163. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"),
  68164. ECC_SECP256R1);
  68165. #endif
  68166. /* invalid case */
  68167. ExpectIntEQ(wc_ecc_get_curve_id_from_name("BADCURVE"), -1);
  68168. /* NULL input */
  68169. ExpectIntEQ(wc_ecc_get_curve_id_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68170. #endif /* HAVE_ECC */
  68171. return EXPECT_RESULT();
  68172. }
  68173. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  68174. !defined(HAVE_SELFTEST) && \
  68175. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  68176. static int test_wc_ecc_get_curve_id_from_dp_params(void)
  68177. {
  68178. EXPECT_DECLS;
  68179. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68180. ecc_key* key;
  68181. const ecc_set_type* params = NULL;
  68182. int ret;
  68183. #endif
  68184. WOLFSSL_EC_KEY *ecKey = NULL;
  68185. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68186. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"), ECC_SECP256R1);
  68187. ExpectNotNull(ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  68188. if (EXPECT_SUCCESS()) {
  68189. ret = EC_KEY_generate_key(ecKey);
  68190. } else
  68191. ret = 0;
  68192. if (ret == 1) {
  68193. /* normal test */
  68194. key = (ecc_key*)ecKey->internal;
  68195. if (key != NULL) {
  68196. params = key->dp;
  68197. }
  68198. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(params),
  68199. ECC_SECP256R1);
  68200. }
  68201. #endif
  68202. /* invalid case, NULL input*/
  68203. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68204. wolfSSL_EC_KEY_free(ecKey);
  68205. return EXPECT_RESULT();
  68206. }
  68207. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  68208. static int test_wc_ecc_get_curve_id_from_params(void)
  68209. {
  68210. EXPECT_DECLS;
  68211. #ifdef HAVE_ECC
  68212. const byte prime[] =
  68213. {
  68214. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68215. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68216. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68217. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  68218. };
  68219. const byte primeInvalid[] =
  68220. {
  68221. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68222. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68223. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68224. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x01
  68225. };
  68226. const byte Af[] =
  68227. {
  68228. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68229. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68230. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68231. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC
  68232. };
  68233. const byte Bf[] =
  68234. {
  68235. 0x5A,0xC6,0x35,0xD8,0xAA,0x3A,0x93,0xE7,
  68236. 0xB3,0xEB,0xBD,0x55,0x76,0x98,0x86,0xBC,
  68237. 0x65,0x1D,0x06,0xB0,0xCC,0x53,0xB0,0xF6,
  68238. 0x3B,0xCE,0x3C,0x3E,0x27,0xD2,0x60,0x4B
  68239. };
  68240. const byte order[] =
  68241. {
  68242. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
  68243. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  68244. 0xBC,0xE6,0xFA,0xAD,0xA7,0x17,0x9E,0x84,
  68245. 0xF3,0xB9,0xCA,0xC2,0xFC,0x63,0x25,0x51
  68246. };
  68247. const byte Gx[] =
  68248. {
  68249. 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47,
  68250. 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2,
  68251. 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0,
  68252. 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96
  68253. };
  68254. const byte Gy[] =
  68255. {
  68256. 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B,
  68257. 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16,
  68258. 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE,
  68259. 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5
  68260. };
  68261. int cofactor = 1;
  68262. int fieldSize = 256;
  68263. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68264. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68265. prime, sizeof(prime), Af, sizeof(Af), Bf, sizeof(Bf),
  68266. order, sizeof(order), Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor),
  68267. ECC_SECP256R1);
  68268. #endif
  68269. /* invalid case, fieldSize = 0 */
  68270. ExpectIntEQ(wc_ecc_get_curve_id_from_params(0, prime, sizeof(prime),
  68271. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68272. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68273. /* invalid case, NULL prime */
  68274. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize, NULL, sizeof(prime),
  68275. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68276. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68277. /* invalid case, invalid prime */
  68278. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68279. primeInvalid, sizeof(primeInvalid),
  68280. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68281. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68282. #endif
  68283. return EXPECT_RESULT();
  68284. }
  68285. static int test_wolfSSL_EVP_PKEY_encrypt(void)
  68286. {
  68287. EXPECT_DECLS;
  68288. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  68289. WOLFSSL_RSA* rsa = NULL;
  68290. WOLFSSL_EVP_PKEY* pkey = NULL;
  68291. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68292. const char* in = "What is easy to do is easy not to do.";
  68293. size_t inlen = XSTRLEN(in);
  68294. size_t outEncLen = 0;
  68295. byte* outEnc = NULL;
  68296. byte* outDec = NULL;
  68297. size_t outDecLen = 0;
  68298. size_t rsaKeySz = 2048/8; /* Bytes */
  68299. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68300. byte* inTmp = NULL;
  68301. byte* outEncTmp = NULL;
  68302. byte* outDecTmp = NULL;
  68303. #endif
  68304. ExpectNotNull(outEnc = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68305. DYNAMIC_TYPE_TMP_BUFFER));
  68306. if (outEnc != NULL) {
  68307. XMEMSET(outEnc, 0, rsaKeySz);
  68308. }
  68309. ExpectNotNull(outDec = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68310. DYNAMIC_TYPE_TMP_BUFFER));
  68311. if (outDec != NULL) {
  68312. XMEMSET(outDec, 0, rsaKeySz);
  68313. }
  68314. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68315. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68316. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68317. if (EXPECT_FAIL()) {
  68318. RSA_free(rsa);
  68319. }
  68320. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68321. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68322. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68323. WOLFSSL_SUCCESS);
  68324. /* Test pkey references count is decremented. pkey shouldn't be destroyed
  68325. since ctx uses it.*/
  68326. ExpectIntEQ(pkey->ref.count, 2);
  68327. EVP_PKEY_free(pkey);
  68328. ExpectIntEQ(pkey->ref.count, 1);
  68329. /* Encrypt data */
  68330. /* Check that we can get the required output buffer length by passing in a
  68331. * NULL output buffer. */
  68332. ExpectIntEQ(EVP_PKEY_encrypt(ctx, NULL, &outEncLen,
  68333. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68334. ExpectIntEQ(rsaKeySz, outEncLen);
  68335. /* Now do the actual encryption. */
  68336. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEnc, &outEncLen,
  68337. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68338. /* Decrypt data */
  68339. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68340. /* Check that we can get the required output buffer length by passing in a
  68341. * NULL output buffer. */
  68342. ExpectIntEQ(EVP_PKEY_decrypt(ctx, NULL, &outDecLen, outEnc, outEncLen),
  68343. WOLFSSL_SUCCESS);
  68344. ExpectIntEQ(rsaKeySz, outDecLen);
  68345. /* Now do the actual decryption. */
  68346. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDec, &outDecLen, outEnc, outEncLen),
  68347. WOLFSSL_SUCCESS);
  68348. ExpectIntEQ(XMEMCMP(in, outDec, outDecLen), 0);
  68349. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68350. /* The input length must be the same size as the RSA key.*/
  68351. ExpectNotNull(inTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68352. DYNAMIC_TYPE_TMP_BUFFER));
  68353. if (inTmp != NULL) {
  68354. XMEMSET(inTmp, 9, rsaKeySz);
  68355. }
  68356. ExpectNotNull(outEncTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68357. DYNAMIC_TYPE_TMP_BUFFER));
  68358. if (outEncTmp != NULL) {
  68359. XMEMSET(outEncTmp, 0, rsaKeySz);
  68360. }
  68361. ExpectNotNull(outDecTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68362. DYNAMIC_TYPE_TMP_BUFFER));
  68363. if (outDecTmp != NULL) {
  68364. XMEMSET(outDecTmp, 0, rsaKeySz);
  68365. }
  68366. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68367. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  68368. WOLFSSL_SUCCESS);
  68369. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEncTmp, &outEncLen, inTmp, rsaKeySz),
  68370. WOLFSSL_SUCCESS);
  68371. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68372. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDecTmp, &outDecLen, outEncTmp,
  68373. outEncLen), WOLFSSL_SUCCESS);
  68374. ExpectIntEQ(XMEMCMP(inTmp, outDecTmp, outDecLen), 0);
  68375. #endif
  68376. EVP_PKEY_CTX_free(ctx);
  68377. XFREE(outEnc, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68378. XFREE(outDec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68379. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68380. XFREE(inTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68381. XFREE(outEncTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68382. XFREE(outDecTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68383. #endif
  68384. #endif
  68385. return EXPECT_RESULT();
  68386. }
  68387. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68388. !defined(HAVE_SELFTEST)
  68389. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68390. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68391. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68392. #endif
  68393. #endif
  68394. #endif
  68395. #if defined(OPENSSL_EXTRA)
  68396. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68397. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68398. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68399. #endif
  68400. #endif
  68401. #endif
  68402. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68403. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68404. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68405. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68406. #endif
  68407. #endif
  68408. #endif
  68409. #ifdef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68410. static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
  68411. {
  68412. EXPECT_DECLS;
  68413. #if defined(OPENSSL_EXTRA)
  68414. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68415. !defined(HAVE_SELFTEST)
  68416. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68417. WOLFSSL_RSA* rsa = NULL;
  68418. #endif
  68419. #endif
  68420. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68421. WOLFSSL_DSA* dsa = NULL;
  68422. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68423. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68424. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68425. WOLFSSL_EC_KEY* ecKey = NULL;
  68426. #endif
  68427. #endif
  68428. WOLFSSL_EVP_PKEY* pkey = NULL;
  68429. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68430. WOLFSSL_EVP_PKEY_CTX* ctx_verify = NULL;
  68431. const char* in = "What is easy to do is easy not to do.";
  68432. size_t inlen = XSTRLEN(in);
  68433. byte hash[SHA256_DIGEST_LENGTH] = {0};
  68434. byte zero[SHA256_DIGEST_LENGTH] = {0};
  68435. SHA256_CTX c;
  68436. byte* sig = NULL;
  68437. byte* sigVerify = NULL;
  68438. size_t siglen;
  68439. size_t siglenOnlyLen;
  68440. size_t keySz = 2048/8; /* Bytes */
  68441. ExpectNotNull(sig =
  68442. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68443. ExpectNotNull(sigVerify =
  68444. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68445. siglen = keySz;
  68446. ExpectNotNull(XMEMSET(sig, 0, keySz));
  68447. ExpectNotNull(XMEMSET(sigVerify, 0, keySz));
  68448. /* Generate hash */
  68449. SHA256_Init(&c);
  68450. SHA256_Update(&c, in, inlen);
  68451. SHA256_Final(hash, &c);
  68452. #ifdef WOLFSSL_SMALL_STACK_CACHE
  68453. /* workaround for small stack cache case */
  68454. wc_Sha256Free((wc_Sha256*)&c);
  68455. #endif
  68456. /* Generate key */
  68457. ExpectNotNull(pkey = EVP_PKEY_new());
  68458. switch (keyType) {
  68459. case EVP_PKEY_RSA:
  68460. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68461. !defined(HAVE_SELFTEST)
  68462. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68463. {
  68464. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68465. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68466. }
  68467. #endif
  68468. #endif
  68469. break;
  68470. case EVP_PKEY_DSA:
  68471. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68472. ExpectNotNull(dsa = DSA_new());
  68473. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048,
  68474. NULL, 0, NULL, NULL, NULL), 1);
  68475. ExpectIntEQ(DSA_generate_key(dsa), 1);
  68476. ExpectIntEQ(EVP_PKEY_set1_DSA(pkey, dsa), WOLFSSL_SUCCESS);
  68477. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68478. break;
  68479. case EVP_PKEY_EC:
  68480. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68481. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68482. {
  68483. ExpectNotNull(ecKey = EC_KEY_new());
  68484. ExpectIntEQ(EC_KEY_generate_key(ecKey), 1);
  68485. ExpectIntEQ(
  68486. EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  68487. if (EXPECT_FAIL()) {
  68488. EC_KEY_free(ecKey);
  68489. }
  68490. }
  68491. #endif
  68492. #endif
  68493. break;
  68494. }
  68495. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68496. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68497. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68498. !defined(HAVE_SELFTEST)
  68499. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68500. if (keyType == EVP_PKEY_RSA)
  68501. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68502. WOLFSSL_SUCCESS);
  68503. #endif
  68504. #endif
  68505. /* Check returning only length */
  68506. ExpectIntEQ(EVP_PKEY_sign(ctx, NULL, &siglenOnlyLen, hash,
  68507. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68508. ExpectIntGT(siglenOnlyLen, 0);
  68509. /* Sign data */
  68510. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, hash,
  68511. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68512. ExpectIntGE(siglenOnlyLen, siglen);
  68513. /* Verify signature */
  68514. ExpectNotNull(ctx_verify = EVP_PKEY_CTX_new(pkey, NULL));
  68515. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  68516. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68517. !defined(HAVE_SELFTEST)
  68518. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68519. if (keyType == EVP_PKEY_RSA)
  68520. ExpectIntEQ(
  68521. EVP_PKEY_CTX_set_rsa_padding(ctx_verify, RSA_PKCS1_PADDING),
  68522. WOLFSSL_SUCCESS);
  68523. #endif
  68524. #endif
  68525. ExpectIntEQ(EVP_PKEY_verify(
  68526. ctx_verify, sig, siglen, hash, SHA256_DIGEST_LENGTH),
  68527. WOLFSSL_SUCCESS);
  68528. ExpectIntEQ(EVP_PKEY_verify(
  68529. ctx_verify, sig, siglen, zero, SHA256_DIGEST_LENGTH),
  68530. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68531. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68532. !defined(HAVE_SELFTEST)
  68533. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68534. if (keyType == EVP_PKEY_RSA) {
  68535. #if defined(WC_RSA_NO_PADDING) || defined(WC_RSA_DIRECT)
  68536. /* Try RSA sign/verify with no padding. */
  68537. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68538. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  68539. WOLFSSL_SUCCESS);
  68540. ExpectIntEQ(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  68541. siglen), WOLFSSL_SUCCESS);
  68542. ExpectIntGE(siglenOnlyLen, siglen);
  68543. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  68544. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  68545. RSA_NO_PADDING), WOLFSSL_SUCCESS);
  68546. ExpectIntEQ(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  68547. siglen), WOLFSSL_SUCCESS);
  68548. #endif
  68549. /* Wrong padding schemes. */
  68550. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68551. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx,
  68552. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  68553. ExpectIntNE(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  68554. siglen), WOLFSSL_SUCCESS);
  68555. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  68556. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  68557. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  68558. ExpectIntNE(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  68559. siglen), WOLFSSL_SUCCESS);
  68560. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68561. WOLFSSL_SUCCESS);
  68562. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  68563. RSA_PKCS1_PADDING), WOLFSSL_SUCCESS);
  68564. }
  68565. #endif
  68566. #endif
  68567. /* error cases */
  68568. siglen = keySz; /* Reset because sig size may vary slightly */
  68569. ExpectIntNE(EVP_PKEY_sign_init(NULL), WOLFSSL_SUCCESS);
  68570. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68571. ExpectIntNE(EVP_PKEY_sign(NULL, sig, &siglen, (byte*)in, inlen),
  68572. WOLFSSL_SUCCESS);
  68573. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, (byte*)in, inlen),
  68574. WOLFSSL_SUCCESS);
  68575. EVP_PKEY_free(pkey);
  68576. pkey = NULL;
  68577. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68578. DSA_free(dsa);
  68579. dsa = NULL;
  68580. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68581. EVP_PKEY_CTX_free(ctx_verify);
  68582. ctx_verify = NULL;
  68583. EVP_PKEY_CTX_free(ctx);
  68584. ctx = NULL;
  68585. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68586. XFREE(sigVerify, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68587. #endif /* OPENSSL_EXTRA */
  68588. return EXPECT_RESULT();
  68589. }
  68590. #endif
  68591. static int test_wolfSSL_EVP_PKEY_sign_verify_rsa(void)
  68592. {
  68593. EXPECT_DECLS;
  68594. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68595. !defined(HAVE_SELFTEST)
  68596. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68597. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_RSA), TEST_SUCCESS);
  68598. #endif
  68599. #endif
  68600. return EXPECT_RESULT();
  68601. }
  68602. static int test_wolfSSL_EVP_PKEY_sign_verify_dsa(void)
  68603. {
  68604. EXPECT_DECLS;
  68605. #if defined(OPENSSL_EXTRA)
  68606. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68607. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_DSA), TEST_SUCCESS);
  68608. #endif
  68609. #endif
  68610. return EXPECT_RESULT();
  68611. }
  68612. static int test_wolfSSL_EVP_PKEY_sign_verify_ec(void)
  68613. {
  68614. EXPECT_DECLS;
  68615. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68616. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68617. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_EC), TEST_SUCCESS);
  68618. #endif
  68619. #endif
  68620. return EXPECT_RESULT();
  68621. }
  68622. static int test_EVP_PKEY_rsa(void)
  68623. {
  68624. EXPECT_DECLS;
  68625. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  68626. WOLFSSL_RSA* rsa = NULL;
  68627. WOLFSSL_EVP_PKEY* pkey = NULL;
  68628. ExpectNotNull(rsa = wolfSSL_RSA_new());
  68629. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68630. ExpectIntEQ(EVP_PKEY_assign_RSA(NULL, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68631. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68632. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68633. if (EXPECT_FAIL()) {
  68634. wolfSSL_RSA_free(rsa);
  68635. }
  68636. ExpectPtrEq(EVP_PKEY_get0_RSA(pkey), rsa);
  68637. wolfSSL_EVP_PKEY_free(pkey);
  68638. #endif
  68639. return EXPECT_RESULT();
  68640. }
  68641. static int test_EVP_PKEY_ec(void)
  68642. {
  68643. EXPECT_DECLS;
  68644. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68645. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68646. WOLFSSL_EC_KEY* ecKey = NULL;
  68647. WOLFSSL_EVP_PKEY* pkey = NULL;
  68648. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  68649. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68650. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68651. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68652. /* Should fail since ecKey is empty */
  68653. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68654. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  68655. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  68656. if (EXPECT_FAIL()) {
  68657. wolfSSL_EC_KEY_free(ecKey);
  68658. }
  68659. wolfSSL_EVP_PKEY_free(pkey);
  68660. #endif
  68661. #endif
  68662. return EXPECT_RESULT();
  68663. }
  68664. static int test_EVP_PKEY_cmp(void)
  68665. {
  68666. EXPECT_DECLS;
  68667. #if defined(OPENSSL_EXTRA)
  68668. EVP_PKEY *a = NULL;
  68669. EVP_PKEY *b = NULL;
  68670. const unsigned char *in;
  68671. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  68672. in = client_key_der_2048;
  68673. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  68674. &in, (long)sizeof_client_key_der_2048));
  68675. in = client_key_der_2048;
  68676. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  68677. &in, (long)sizeof_client_key_der_2048));
  68678. /* Test success case RSA */
  68679. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68680. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  68681. #else
  68682. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  68683. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  68684. EVP_PKEY_free(b);
  68685. b = NULL;
  68686. EVP_PKEY_free(a);
  68687. a = NULL;
  68688. #endif
  68689. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68690. in = ecc_clikey_der_256;
  68691. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  68692. &in, (long)sizeof_ecc_clikey_der_256));
  68693. in = ecc_clikey_der_256;
  68694. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  68695. &in, (long)sizeof_ecc_clikey_der_256));
  68696. /* Test success case ECC */
  68697. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68698. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  68699. #else
  68700. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  68701. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  68702. EVP_PKEY_free(b);
  68703. b = NULL;
  68704. EVP_PKEY_free(a);
  68705. a = NULL;
  68706. #endif
  68707. /* Test failure cases */
  68708. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && \
  68709. defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68710. in = client_key_der_2048;
  68711. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  68712. &in, (long)sizeof_client_key_der_2048));
  68713. in = ecc_clikey_der_256;
  68714. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  68715. &in, (long)sizeof_ecc_clikey_der_256));
  68716. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68717. ExpectIntEQ(EVP_PKEY_cmp(a, b), -1);
  68718. #else
  68719. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  68720. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  68721. EVP_PKEY_free(b);
  68722. b = NULL;
  68723. EVP_PKEY_free(a);
  68724. a = NULL;
  68725. #endif
  68726. /* invalid or empty failure cases */
  68727. a = EVP_PKEY_new();
  68728. b = EVP_PKEY_new();
  68729. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68730. ExpectIntEQ(EVP_PKEY_cmp(NULL, NULL), 0);
  68731. ExpectIntEQ(EVP_PKEY_cmp(a, NULL), 0);
  68732. ExpectIntEQ(EVP_PKEY_cmp(NULL, b), 0);
  68733. #ifdef NO_RSA
  68734. /* Type check will fail since RSA is the default EVP key type */
  68735. ExpectIntEQ(EVP_PKEY_cmp(a, b), -2);
  68736. #else
  68737. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  68738. #endif
  68739. #else
  68740. ExpectIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
  68741. ExpectIntNE(EVP_PKEY_cmp(a, NULL), 0);
  68742. ExpectIntNE(EVP_PKEY_cmp(NULL, b), 0);
  68743. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  68744. #endif
  68745. EVP_PKEY_free(b);
  68746. EVP_PKEY_free(a);
  68747. (void)in;
  68748. #endif
  68749. return EXPECT_RESULT();
  68750. }
  68751. static int test_ERR_load_crypto_strings(void)
  68752. {
  68753. #if defined(OPENSSL_ALL)
  68754. ERR_load_crypto_strings();
  68755. return TEST_SUCCESS;
  68756. #else
  68757. return TEST_SKIPPED;
  68758. #endif
  68759. }
  68760. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  68761. static void free_x509(X509* x)
  68762. {
  68763. AssertIntEQ((x == (X509*)1 || x == (X509*)2), 1);
  68764. }
  68765. #endif
  68766. static int test_sk_X509(void)
  68767. {
  68768. EXPECT_DECLS;
  68769. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  68770. {
  68771. STACK_OF(X509)* s = NULL;
  68772. ExpectNotNull(s = sk_X509_new_null());
  68773. ExpectIntEQ(sk_X509_num(s), 0);
  68774. sk_X509_pop_free(s, NULL);
  68775. ExpectNotNull(s = sk_X509_new_null());
  68776. ExpectIntEQ(sk_X509_num(s), 0);
  68777. sk_X509_pop_free(s, NULL);
  68778. ExpectNotNull(s = sk_X509_new_null());
  68779. sk_X509_push(s, (X509*)1);
  68780. ExpectIntEQ(sk_X509_num(s), 1);
  68781. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)1), 1);
  68782. sk_X509_push(s, (X509*)2);
  68783. ExpectIntEQ(sk_X509_num(s), 2);
  68784. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)2), 1);
  68785. ExpectIntEQ((sk_X509_value(s, 1) == (X509*)1), 1);
  68786. sk_X509_push(s, (X509*)2);
  68787. sk_X509_pop_free(s, free_x509);
  68788. }
  68789. {
  68790. /* Push a list of 10 X509s onto stack, then verify that
  68791. * value(), push(), shift(), and pop() behave as expected. */
  68792. STACK_OF(X509)* s = NULL;
  68793. X509* xList[10];
  68794. int i = 0;
  68795. const int len = (sizeof(xList) / sizeof(xList[0]));
  68796. for (i = 0; i < len; ++i) {
  68797. xList[i] = NULL;
  68798. ExpectNotNull(xList[i] = X509_new());
  68799. }
  68800. /* test push, pop, and free */
  68801. ExpectNotNull(s = sk_X509_new_null());
  68802. for (i = 0; i < len; ++i) {
  68803. sk_X509_push(s, xList[i]);
  68804. ExpectIntEQ(sk_X509_num(s), i + 1);
  68805. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  68806. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  68807. }
  68808. /* pop returns and removes last pushed on stack, which is index 0
  68809. * in sk_x509_value */
  68810. for (i = 0; i < len; ++i) {
  68811. X509 * x = sk_X509_value(s, 0);
  68812. X509 * y = sk_X509_pop(s);
  68813. X509 * z = xList[len - 1 - i];
  68814. ExpectIntEQ((x == y), 1);
  68815. ExpectIntEQ((x == z), 1);
  68816. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  68817. }
  68818. sk_free(s);
  68819. s = NULL;
  68820. /* test push, shift, and free */
  68821. ExpectNotNull(s = sk_X509_new_null());
  68822. for (i = 0; i < len; ++i) {
  68823. sk_X509_push(s, xList[i]);
  68824. ExpectIntEQ(sk_X509_num(s), i + 1);
  68825. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  68826. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  68827. }
  68828. /* shift returns and removes first pushed on stack, which is index i
  68829. * in sk_x509_value() */
  68830. for (i = 0; i < len; ++i) {
  68831. X509 * x = sk_X509_value(s, len - 1 - i);
  68832. X509 * y = sk_X509_shift(s);
  68833. X509 * z = xList[i];
  68834. ExpectIntEQ((x == y), 1);
  68835. ExpectIntEQ((x == z), 1);
  68836. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  68837. }
  68838. sk_free(s);
  68839. for (i = 0; i < len; ++i)
  68840. X509_free(xList[i]);
  68841. }
  68842. #endif
  68843. return EXPECT_RESULT();
  68844. }
  68845. static int test_sk_X509_CRL(void)
  68846. {
  68847. EXPECT_DECLS;
  68848. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && defined(HAVE_CRL)
  68849. X509_CRL* crl = NULL;
  68850. XFILE fp = XBADFILE;
  68851. STACK_OF(X509_CRL)* s = NULL;
  68852. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  68853. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  68854. NULL, NULL));
  68855. if (fp != XBADFILE)
  68856. XFCLOSE(fp);
  68857. ExpectNotNull(s = sk_X509_CRL_new());
  68858. ExpectIntEQ(sk_X509_CRL_num(s), 0);
  68859. ExpectIntEQ(sk_X509_CRL_push(s, crl), 1);
  68860. if (EXPECT_FAIL()) {
  68861. X509_CRL_free(crl);
  68862. }
  68863. ExpectIntEQ(sk_X509_CRL_num(s), 1);
  68864. ExpectPtrEq(sk_X509_CRL_value(s, 0), crl);
  68865. sk_X509_CRL_free(s);
  68866. #endif
  68867. return EXPECT_RESULT();
  68868. }
  68869. static int test_X509_get_signature_nid(void)
  68870. {
  68871. EXPECT_DECLS;
  68872. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  68873. X509* x509 = NULL;
  68874. ExpectIntEQ(X509_get_signature_nid(NULL), 0);
  68875. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  68876. SSL_FILETYPE_PEM));
  68877. ExpectIntEQ(X509_get_signature_nid(x509), NID_sha256WithRSAEncryption);
  68878. X509_free(x509);
  68879. #endif
  68880. return EXPECT_RESULT();
  68881. }
  68882. static int test_X509_REQ(void)
  68883. {
  68884. EXPECT_DECLS;
  68885. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  68886. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  68887. X509_NAME* name = NULL;
  68888. #ifndef NO_RSA
  68889. X509_NAME* subject = NULL;
  68890. #endif
  68891. #if !defined(NO_RSA) || defined(HAVE_ECC)
  68892. X509_REQ* req = NULL;
  68893. EVP_PKEY* priv = NULL;
  68894. EVP_PKEY* pub = NULL;
  68895. unsigned char* der = NULL;
  68896. int len;
  68897. #endif
  68898. #ifndef NO_RSA
  68899. EVP_MD_CTX *mctx = NULL;
  68900. EVP_PKEY_CTX *pkctx = NULL;
  68901. #ifdef USE_CERT_BUFFERS_1024
  68902. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_1024;
  68903. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_1024;
  68904. #elif defined(USE_CERT_BUFFERS_2048)
  68905. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_2048;
  68906. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_2048;
  68907. #endif
  68908. #endif
  68909. #ifdef HAVE_ECC
  68910. const unsigned char* ecPriv = (const unsigned char*)ecc_clikey_der_256;
  68911. const unsigned char* ecPub = (unsigned char*)ecc_clikeypub_der_256;
  68912. #endif
  68913. ExpectNotNull(name = X509_NAME_new());
  68914. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  68915. (byte*)"wolfssl.com", 11, 0, 1), WOLFSSL_SUCCESS);
  68916. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  68917. (byte*)"support@wolfssl.com", 19, -1, 1), WOLFSSL_SUCCESS);
  68918. #ifndef NO_RSA
  68919. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  68920. (long)sizeof_client_key_der_2048));
  68921. ExpectNotNull(pub = d2i_PUBKEY(NULL, &rsaPub,
  68922. (long)sizeof_client_keypub_der_2048));
  68923. ExpectNotNull(req = X509_REQ_new());
  68924. ExpectIntEQ(X509_REQ_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68925. ExpectIntEQ(X509_REQ_set_subject_name(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68926. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  68927. ExpectIntEQ(X509_REQ_set_pubkey(NULL, pub), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68928. ExpectIntEQ(X509_REQ_set_pubkey(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68929. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  68930. ExpectIntEQ(X509_REQ_sign(NULL, priv, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68931. ExpectIntEQ(X509_REQ_sign(req, NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68932. ExpectIntEQ(X509_REQ_sign(req, priv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68933. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  68934. len = i2d_X509_REQ(req, &der);
  68935. DEBUG_WRITE_DER(der, len, "req.der");
  68936. #ifdef USE_CERT_BUFFERS_1024
  68937. ExpectIntEQ(len, 381);
  68938. #else
  68939. ExpectIntEQ(len, 643);
  68940. #endif
  68941. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  68942. der = NULL;
  68943. mctx = EVP_MD_CTX_new();
  68944. ExpectIntEQ(EVP_DigestSignInit(mctx, &pkctx, EVP_sha256(), NULL, priv),
  68945. WOLFSSL_SUCCESS);
  68946. ExpectIntEQ(X509_REQ_sign_ctx(req, mctx), WOLFSSL_SUCCESS);
  68947. EVP_MD_CTX_free(mctx);
  68948. mctx = NULL;
  68949. X509_REQ_free(NULL);
  68950. X509_REQ_free(req);
  68951. req = NULL;
  68952. /* Test getting the subject from a newly created X509_REQ */
  68953. ExpectNotNull(req = X509_REQ_new());
  68954. ExpectNotNull(subject = X509_REQ_get_subject_name(req));
  68955. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_commonName,
  68956. MBSTRING_UTF8, (unsigned char*)"www.wolfssl.com", -1, -1, 0), 1);
  68957. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_countryName,
  68958. MBSTRING_UTF8, (unsigned char*)"US", -1, -1, 0), 1);
  68959. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_localityName,
  68960. MBSTRING_UTF8, (unsigned char*)"Bozeman", -1, -1, 0), 1);
  68961. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_stateOrProvinceName,
  68962. MBSTRING_UTF8, (unsigned char*)"Montana", -1, -1, 0), 1);
  68963. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationName,
  68964. MBSTRING_UTF8, (unsigned char*)"wolfSSL", -1, -1, 0), 1);
  68965. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationalUnitName,
  68966. MBSTRING_UTF8, (unsigned char*)"Testing", -1, -1, 0), 1);
  68967. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  68968. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  68969. len = i2d_X509_REQ(req, &der);
  68970. DEBUG_WRITE_DER(der, len, "req2.der");
  68971. #ifdef USE_CERT_BUFFERS_1024
  68972. ExpectIntEQ(len, 435);
  68973. #else
  68974. ExpectIntEQ(len, 696);
  68975. #endif
  68976. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  68977. der = NULL;
  68978. EVP_PKEY_free(pub);
  68979. pub = NULL;
  68980. EVP_PKEY_free(priv);
  68981. priv = NULL;
  68982. X509_REQ_free(req);
  68983. req = NULL;
  68984. #endif
  68985. #ifdef HAVE_ECC
  68986. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv,
  68987. sizeof_ecc_clikey_der_256));
  68988. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub,
  68989. sizeof_ecc_clikeypub_der_256));
  68990. ExpectNotNull(req = X509_REQ_new());
  68991. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  68992. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  68993. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  68994. /* Signature is random and may be shorter or longer. */
  68995. ExpectIntGE((len = i2d_X509_REQ(req, &der)), 245);
  68996. ExpectIntLE(len, 253);
  68997. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  68998. X509_REQ_free(req);
  68999. EVP_PKEY_free(pub);
  69000. EVP_PKEY_free(priv);
  69001. #ifdef FP_ECC
  69002. wc_ecc_fp_free();
  69003. #endif
  69004. #endif /* HAVE_ECC */
  69005. X509_NAME_free(name);
  69006. #endif
  69007. return EXPECT_RESULT();
  69008. }
  69009. static int test_wolfssl_PKCS7(void)
  69010. {
  69011. EXPECT_DECLS;
  69012. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69013. !defined(NO_RSA)
  69014. PKCS7* pkcs7 = NULL;
  69015. byte data[FOURK_BUF];
  69016. word32 len = sizeof(data);
  69017. const byte* p = data;
  69018. byte content[] = "Test data to encode.";
  69019. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69020. BIO* bio = NULL;
  69021. byte key[sizeof(client_key_der_2048)];
  69022. word32 keySz = (word32)sizeof(key);
  69023. byte* out = NULL;
  69024. #endif
  69025. ExpectIntGT((len = (word32)CreatePKCS7SignedData(data, (int)len, content,
  69026. (word32)sizeof(content), 0, 0, 0, RSA_TYPE)), 0);
  69027. ExpectNull(pkcs7 = d2i_PKCS7(NULL, NULL, (int)len));
  69028. ExpectNull(pkcs7 = d2i_PKCS7(NULL, &p, 0));
  69029. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69030. ExpectIntEQ(wolfSSL_PKCS7_verify(NULL, NULL, NULL, NULL, NULL,
  69031. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69032. PKCS7_free(pkcs7);
  69033. pkcs7 = NULL;
  69034. /* fail case, without PKCS7_NOVERIFY */
  69035. p = data;
  69036. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69037. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69038. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69039. PKCS7_free(pkcs7);
  69040. pkcs7 = NULL;
  69041. /* success case, with PKCS7_NOVERIFY */
  69042. p = data;
  69043. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69044. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69045. PKCS7_NOVERIFY), WOLFSSL_SUCCESS);
  69046. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69047. /* test i2d */
  69048. XMEMCPY(key, client_key_der_2048, keySz);
  69049. if (pkcs7 != NULL) {
  69050. pkcs7->privateKey = key;
  69051. pkcs7->privateKeySz = (word32)sizeof(key);
  69052. pkcs7->encryptOID = RSAk;
  69053. #ifdef NO_SHA
  69054. pkcs7->hashOID = SHA256h;
  69055. #else
  69056. pkcs7->hashOID = SHAh;
  69057. #endif
  69058. }
  69059. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69060. ExpectIntEQ(i2d_PKCS7_bio(bio, pkcs7), 1);
  69061. #ifndef NO_ASN_TIME
  69062. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 655);
  69063. #else
  69064. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 625);
  69065. #endif
  69066. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69067. BIO_free(bio);
  69068. #endif
  69069. PKCS7_free(NULL);
  69070. PKCS7_free(pkcs7);
  69071. #endif
  69072. return EXPECT_RESULT();
  69073. }
  69074. static int test_wolfSSL_PKCS7_sign(void)
  69075. {
  69076. EXPECT_DECLS;
  69077. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69078. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  69079. PKCS7* p7 = NULL;
  69080. PKCS7* p7Ver = NULL;
  69081. byte* out = NULL;
  69082. byte* tmpPtr = NULL;
  69083. int outLen = 0;
  69084. int flags = 0;
  69085. byte data[] = "Test data to encode.";
  69086. const char* cert = "./certs/server-cert.pem";
  69087. const char* key = "./certs/server-key.pem";
  69088. const char* ca = "./certs/ca-cert.pem";
  69089. WOLFSSL_BIO* certBio = NULL;
  69090. WOLFSSL_BIO* keyBio = NULL;
  69091. WOLFSSL_BIO* caBio = NULL;
  69092. WOLFSSL_BIO* inBio = NULL;
  69093. X509* signCert = NULL;
  69094. EVP_PKEY* signKey = NULL;
  69095. X509* caCert = NULL;
  69096. X509_STORE* store = NULL;
  69097. #ifndef NO_PKCS7_STREAM
  69098. int z;
  69099. int ret;
  69100. #endif /* !NO_PKCS7_STREAM */
  69101. /* read signer cert/key into BIO */
  69102. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  69103. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  69104. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  69105. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  69106. /* read CA cert into store (for verify) */
  69107. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  69108. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  69109. ExpectNotNull(store = X509_STORE_new());
  69110. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  69111. /* data to be signed into BIO */
  69112. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69113. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69114. /* PKCS7_sign, bad args: signer NULL */
  69115. ExpectNull(p7 = PKCS7_sign(NULL, signKey, NULL, inBio, 0));
  69116. /* PKCS7_sign, bad args: signer key NULL */
  69117. ExpectNull(p7 = PKCS7_sign(signCert, NULL, NULL, inBio, 0));
  69118. /* PKCS7_sign, bad args: in data NULL without PKCS7_STREAM */
  69119. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, NULL, 0));
  69120. /* PKCS7_sign, bad args: PKCS7_NOCERTS flag not supported */
  69121. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_NOCERTS));
  69122. /* PKCS7_sign, bad args: PKCS7_PARTIAL flag not supported */
  69123. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_PARTIAL));
  69124. /* TEST SUCCESS: Not detached, not streaming, not MIME */
  69125. {
  69126. flags = PKCS7_BINARY;
  69127. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69128. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69129. /* verify with d2i_PKCS7 */
  69130. tmpPtr = out;
  69131. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69132. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69133. PKCS7_free(p7Ver);
  69134. p7Ver = NULL;
  69135. /* verify with wc_PKCS7_VerifySignedData */
  69136. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69137. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69138. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69139. #ifndef NO_PKCS7_STREAM
  69140. /* verify with wc_PKCS7_VerifySignedData streaming */
  69141. wc_PKCS7_Free(p7Ver);
  69142. p7Ver = NULL;
  69143. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69144. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69145. /* test for streaming */
  69146. ret = -1;
  69147. for (z = 0; z < outLen && ret != 0; z++) {
  69148. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69149. if (ret < 0){
  69150. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69151. }
  69152. }
  69153. ExpectIntEQ(ret, 0);
  69154. #endif /* !NO_PKCS7_STREAM */
  69155. /* compare the signer found to expected signer */
  69156. ExpectIntNE(p7Ver->verifyCertSz, 0);
  69157. tmpPtr = NULL;
  69158. ExpectIntEQ(i2d_X509(signCert, &tmpPtr), p7Ver->verifyCertSz);
  69159. ExpectIntEQ(XMEMCMP(tmpPtr, p7Ver->verifyCert, p7Ver->verifyCertSz), 0);
  69160. XFREE(tmpPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  69161. tmpPtr = NULL;
  69162. wc_PKCS7_Free(p7Ver);
  69163. p7Ver = NULL;
  69164. ExpectNotNull(out);
  69165. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69166. out = NULL;
  69167. PKCS7_free(p7);
  69168. p7 = NULL;
  69169. }
  69170. /* TEST SUCCESS: Not detached, streaming, not MIME. Also bad arg
  69171. * tests for PKCS7_final() while we have a PKCS7 pointer to use */
  69172. {
  69173. /* re-populate input BIO, may have been consumed */
  69174. BIO_free(inBio);
  69175. inBio = NULL;
  69176. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69177. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69178. flags = PKCS7_BINARY | PKCS7_STREAM;
  69179. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69180. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69181. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69182. /* PKCS7_final, bad args: PKCS7 null */
  69183. ExpectIntEQ(PKCS7_final(NULL, inBio, 0), 0);
  69184. /* PKCS7_final, bad args: PKCS7 null */
  69185. ExpectIntEQ(PKCS7_final(p7, NULL, 0), 0);
  69186. tmpPtr = out;
  69187. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69188. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69189. PKCS7_free(p7Ver);
  69190. p7Ver = NULL;
  69191. ExpectNotNull(out);
  69192. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69193. out = NULL;
  69194. PKCS7_free(p7);
  69195. p7 = NULL;
  69196. }
  69197. /* TEST SUCCESS: Detached, not streaming, not MIME */
  69198. {
  69199. /* re-populate input BIO, may have been consumed */
  69200. BIO_free(inBio);
  69201. inBio = NULL;
  69202. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69203. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69204. flags = PKCS7_BINARY | PKCS7_DETACHED;
  69205. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69206. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69207. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69208. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69209. if (p7Ver != NULL) {
  69210. p7Ver->content = data;
  69211. p7Ver->contentSz = sizeof(data);
  69212. }
  69213. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69214. wc_PKCS7_Free(p7Ver);
  69215. p7Ver = NULL;
  69216. #ifndef NO_PKCS7_STREAM
  69217. /* verify with wc_PKCS7_VerifySignedData streaming */
  69218. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69219. if (p7Ver != NULL) {
  69220. p7Ver->content = data;
  69221. p7Ver->contentSz = sizeof(data);
  69222. }
  69223. /* test for streaming */
  69224. ret = -1;
  69225. for (z = 0; z < outLen && ret != 0; z++) {
  69226. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69227. if (ret < 0){
  69228. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69229. }
  69230. }
  69231. ExpectIntEQ(ret, 0);
  69232. wc_PKCS7_Free(p7Ver);
  69233. p7Ver = NULL;
  69234. #endif /* !NO_PKCS7_STREAM */
  69235. /* verify expected failure (NULL return) from d2i_PKCS7, it does not
  69236. * yet support detached content */
  69237. tmpPtr = out;
  69238. ExpectNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69239. PKCS7_free(p7Ver);
  69240. p7Ver = NULL;
  69241. ExpectNotNull(out);
  69242. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69243. out = NULL;
  69244. PKCS7_free(p7);
  69245. p7 = NULL;
  69246. }
  69247. /* TEST SUCCESS: Detached, streaming, not MIME */
  69248. {
  69249. /* re-populate input BIO, may have been consumed */
  69250. BIO_free(inBio);
  69251. inBio = NULL;
  69252. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69253. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69254. flags = PKCS7_BINARY | PKCS7_DETACHED | PKCS7_STREAM;
  69255. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69256. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69257. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69258. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69259. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69260. if (p7Ver != NULL) {
  69261. p7Ver->content = data;
  69262. p7Ver->contentSz = sizeof(data);
  69263. }
  69264. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69265. wc_PKCS7_Free(p7Ver);
  69266. p7Ver = NULL;
  69267. ExpectNotNull(out);
  69268. #ifndef NO_PKCS7_STREAM
  69269. /* verify with wc_PKCS7_VerifySignedData streaming */
  69270. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69271. if (p7Ver != NULL) {
  69272. p7Ver->content = data;
  69273. p7Ver->contentSz = sizeof(data);
  69274. }
  69275. /* test for streaming */
  69276. ret = -1;
  69277. for (z = 0; z < outLen && ret != 0; z++) {
  69278. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69279. if (ret < 0){
  69280. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69281. }
  69282. }
  69283. ExpectIntEQ(ret, 0);
  69284. ExpectNotNull(out);
  69285. wc_PKCS7_Free(p7Ver);
  69286. p7Ver = NULL;
  69287. #endif /* !NO_PKCS7_STREAM */
  69288. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69289. PKCS7_free(p7);
  69290. p7 = NULL;
  69291. }
  69292. X509_STORE_free(store);
  69293. X509_free(caCert);
  69294. X509_free(signCert);
  69295. EVP_PKEY_free(signKey);
  69296. BIO_free(inBio);
  69297. BIO_free(keyBio);
  69298. BIO_free(certBio);
  69299. BIO_free(caBio);
  69300. #endif
  69301. return EXPECT_RESULT();
  69302. }
  69303. static int test_wolfSSL_PKCS7_SIGNED_new(void)
  69304. {
  69305. EXPECT_DECLS;
  69306. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7)
  69307. PKCS7_SIGNED* pkcs7 = NULL;
  69308. ExpectNotNull(pkcs7 = PKCS7_SIGNED_new());
  69309. ExpectIntEQ(pkcs7->contentOID, SIGNED_DATA);
  69310. PKCS7_SIGNED_free(pkcs7);
  69311. #endif
  69312. return EXPECT_RESULT();
  69313. }
  69314. #ifndef NO_BIO
  69315. static int test_wolfSSL_PEM_write_bio_PKCS7(void)
  69316. {
  69317. EXPECT_DECLS;
  69318. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  69319. PKCS7* pkcs7 = NULL;
  69320. BIO* bio = NULL;
  69321. const byte* cert_buf = NULL;
  69322. int ret = 0;
  69323. WC_RNG rng;
  69324. const byte data[] = { /* Hello World */
  69325. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  69326. 0x72,0x6c,0x64
  69327. };
  69328. #ifndef NO_RSA
  69329. #if defined(USE_CERT_BUFFERS_2048)
  69330. byte key[sizeof(client_key_der_2048)];
  69331. byte cert[sizeof(client_cert_der_2048)];
  69332. word32 keySz = (word32)sizeof(key);
  69333. word32 certSz = (word32)sizeof(cert);
  69334. XMEMSET(key, 0, keySz);
  69335. XMEMSET(cert, 0, certSz);
  69336. XMEMCPY(key, client_key_der_2048, keySz);
  69337. XMEMCPY(cert, client_cert_der_2048, certSz);
  69338. #elif defined(USE_CERT_BUFFERS_1024)
  69339. byte key[sizeof_client_key_der_1024];
  69340. byte cert[sizeof(sizeof_client_cert_der_1024)];
  69341. word32 keySz = (word32)sizeof(key);
  69342. word32 certSz = (word32)sizeof(cert);
  69343. XMEMSET(key, 0, keySz);
  69344. XMEMSET(cert, 0, certSz);
  69345. XMEMCPY(key, client_key_der_1024, keySz);
  69346. XMEMCPY(cert, client_cert_der_1024, certSz);
  69347. #else
  69348. unsigned char cert[ONEK_BUF];
  69349. unsigned char key[ONEK_BUF];
  69350. XFILE fp = XBADFILE;
  69351. int certSz;
  69352. int keySz;
  69353. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  69354. XBADFILE);
  69355. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  69356. fp), 0);
  69357. if (fp != XBADFILE) {
  69358. XFCLOSE(fp);
  69359. fp = XBADFILE;
  69360. }
  69361. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  69362. XBADFILE);
  69363. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  69364. 0);
  69365. if (fp != XBADFILE) {
  69366. XFCLOSE(fp);
  69367. fp = XBADFILE;
  69368. }
  69369. #endif
  69370. #elif defined(HAVE_ECC)
  69371. #if defined(USE_CERT_BUFFERS_256)
  69372. unsigned char cert[sizeof(cliecc_cert_der_256)];
  69373. unsigned char key[sizeof(ecc_clikey_der_256)];
  69374. int certSz = (int)sizeof(cert);
  69375. int keySz = (int)sizeof(key);
  69376. XMEMSET(cert, 0, certSz);
  69377. XMEMSET(key, 0, keySz);
  69378. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  69379. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  69380. #else
  69381. unsigned char cert[ONEK_BUF];
  69382. unsigned char key[ONEK_BUF];
  69383. XFILE fp = XBADFILE;
  69384. int certSz, keySz;
  69385. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  69386. XBADFILE);
  69387. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  69388. fp), 0);
  69389. if (fp != XBADFILE) {
  69390. XFCLOSE(fp);
  69391. fp = XBADFILE;
  69392. }
  69393. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  69394. XBADFILE);
  69395. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  69396. 0);
  69397. if (fp != XBADFILE) {
  69398. XFCLOSE(fp);
  69399. fp = XBADFILE;
  69400. }
  69401. #endif
  69402. #else
  69403. #error PKCS7 requires ECC or RSA
  69404. #endif
  69405. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  69406. /* initialize with DER encoded cert */
  69407. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  69408. /* init rng */
  69409. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69410. ExpectIntEQ(wc_InitRng(&rng), 0);
  69411. if (pkcs7 != NULL) {
  69412. pkcs7->rng = &rng;
  69413. pkcs7->content = (byte*)data; /* not used for ex */
  69414. pkcs7->contentSz = (word32)sizeof(data);
  69415. pkcs7->contentOID = SIGNED_DATA;
  69416. pkcs7->privateKey = key;
  69417. pkcs7->privateKeySz = (word32)sizeof(key);
  69418. pkcs7->encryptOID = RSAk;
  69419. #ifdef NO_SHA
  69420. pkcs7->hashOID = SHA256h;
  69421. #else
  69422. pkcs7->hashOID = SHAh;
  69423. #endif
  69424. pkcs7->signedAttribs = NULL;
  69425. pkcs7->signedAttribsSz = 0;
  69426. }
  69427. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69428. /* Write PKCS#7 PEM to BIO, the function converts the DER to PEM cert*/
  69429. ExpectIntEQ(PEM_write_bio_PKCS7(bio, pkcs7), WOLFSSL_SUCCESS);
  69430. /* Read PKCS#7 PEM from BIO */
  69431. ret = wolfSSL_BIO_get_mem_data(bio, &cert_buf);
  69432. ExpectIntGE(ret, 0);
  69433. BIO_free(bio);
  69434. wc_PKCS7_Free(pkcs7);
  69435. wc_FreeRng(&rng);
  69436. #endif
  69437. return EXPECT_RESULT();
  69438. }
  69439. #ifdef HAVE_SMIME
  69440. /* // NOLINTBEGIN(clang-analyzer-unix.Stream) */
  69441. static int test_wolfSSL_SMIME_read_PKCS7(void)
  69442. {
  69443. EXPECT_DECLS;
  69444. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  69445. !defined(NO_RSA)
  69446. PKCS7* pkcs7 = NULL;
  69447. BIO* bio = NULL;
  69448. BIO* bcont = NULL;
  69449. BIO* out = NULL;
  69450. const byte* outBuf = NULL;
  69451. int outBufLen = 0;
  69452. static const char contTypeText[] = "Content-Type: text/plain\r\n\r\n";
  69453. XFILE smimeTestFile = XBADFILE;
  69454. ExpectTrue((smimeTestFile = XFOPEN("./certs/test/smime-test.p7s", "r")) !=
  69455. XBADFILE);
  69456. /* smime-test.p7s */
  69457. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  69458. ExpectNotNull(bio);
  69459. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69460. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69461. ExpectNotNull(pkcs7);
  69462. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69463. PKCS7_NOVERIFY), SSL_SUCCESS);
  69464. if (smimeTestFile != XBADFILE) {
  69465. XFCLOSE(smimeTestFile);
  69466. smimeTestFile = XBADFILE;
  69467. }
  69468. if (bcont) BIO_free(bcont);
  69469. bcont = NULL;
  69470. wolfSSL_PKCS7_free(pkcs7);
  69471. pkcs7 = NULL;
  69472. /* smime-test-multipart.p7s */
  69473. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart.p7s", "r");
  69474. ExpectFalse(smimeTestFile == XBADFILE);
  69475. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69476. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69477. ExpectNotNull(pkcs7);
  69478. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69479. PKCS7_NOVERIFY), SSL_SUCCESS);
  69480. if (smimeTestFile != XBADFILE) {
  69481. XFCLOSE(smimeTestFile);
  69482. smimeTestFile = XBADFILE;
  69483. }
  69484. if (bcont) BIO_free(bcont);
  69485. bcont = NULL;
  69486. wolfSSL_PKCS7_free(pkcs7);
  69487. pkcs7 = NULL;
  69488. /* smime-test-multipart-badsig.p7s */
  69489. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart-badsig.p7s", "r");
  69490. ExpectFalse(smimeTestFile == XBADFILE);
  69491. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69492. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69493. ExpectNotNull(pkcs7); /* can read in the unverified smime bundle */
  69494. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69495. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69496. if (smimeTestFile != XBADFILE) {
  69497. XFCLOSE(smimeTestFile);
  69498. smimeTestFile = XBADFILE;
  69499. }
  69500. if (bcont) BIO_free(bcont);
  69501. bcont = NULL;
  69502. wolfSSL_PKCS7_free(pkcs7);
  69503. pkcs7 = NULL;
  69504. /* smime-test-canon.p7s */
  69505. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  69506. ExpectFalse(smimeTestFile == XBADFILE);
  69507. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69508. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69509. ExpectNotNull(pkcs7);
  69510. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69511. PKCS7_NOVERIFY), SSL_SUCCESS);
  69512. if (smimeTestFile != XBADFILE) {
  69513. XFCLOSE(smimeTestFile);
  69514. smimeTestFile = XBADFILE;
  69515. }
  69516. if (bcont) BIO_free(bcont);
  69517. bcont = NULL;
  69518. wolfSSL_PKCS7_free(pkcs7);
  69519. pkcs7 = NULL;
  69520. /* Test PKCS7_TEXT, PKCS7_verify() should remove Content-Type: text/plain */
  69521. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  69522. ExpectFalse(smimeTestFile == XBADFILE);
  69523. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69524. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69525. ExpectNotNull(pkcs7);
  69526. out = wolfSSL_BIO_new(BIO_s_mem());
  69527. ExpectNotNull(out);
  69528. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, out,
  69529. PKCS7_NOVERIFY | PKCS7_TEXT), SSL_SUCCESS);
  69530. ExpectIntGT((outBufLen = BIO_get_mem_data(out, &outBuf)), 0);
  69531. /* Content-Type should not show up at beginning of output buffer */
  69532. ExpectIntGT(outBufLen, XSTRLEN(contTypeText));
  69533. ExpectIntGT(XMEMCMP(outBuf, contTypeText, XSTRLEN(contTypeText)), 0);
  69534. BIO_free(out);
  69535. BIO_free(bio);
  69536. if (bcont) BIO_free(bcont);
  69537. wolfSSL_PKCS7_free(pkcs7);
  69538. #endif
  69539. return EXPECT_RESULT();
  69540. }
  69541. /* // NOLINTEND(clang-analyzer-unix.Stream) */
  69542. static int test_wolfSSL_SMIME_write_PKCS7(void)
  69543. {
  69544. EXPECT_DECLS;
  69545. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_RSA)
  69546. PKCS7* p7 = NULL;
  69547. PKCS7* p7Ver = NULL;
  69548. int flags = 0;
  69549. byte data[] = "Test data to encode.";
  69550. const char* cert = "./certs/server-cert.pem";
  69551. const char* key = "./certs/server-key.pem";
  69552. const char* ca = "./certs/ca-cert.pem";
  69553. WOLFSSL_BIO* certBio = NULL;
  69554. WOLFSSL_BIO* keyBio = NULL;
  69555. WOLFSSL_BIO* caBio = NULL;
  69556. WOLFSSL_BIO* inBio = NULL;
  69557. WOLFSSL_BIO* outBio = NULL;
  69558. WOLFSSL_BIO* content = NULL;
  69559. X509* signCert = NULL;
  69560. EVP_PKEY* signKey = NULL;
  69561. X509* caCert = NULL;
  69562. X509_STORE* store = NULL;
  69563. /* read signer cert/key into BIO */
  69564. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  69565. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  69566. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  69567. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  69568. /* read CA cert into store (for verify) */
  69569. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  69570. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  69571. ExpectNotNull(store = X509_STORE_new());
  69572. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  69573. /* generate and verify SMIME: not detached */
  69574. {
  69575. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69576. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69577. flags = PKCS7_STREAM;
  69578. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69579. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69580. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69581. /* bad arg: out NULL */
  69582. ExpectIntEQ(SMIME_write_PKCS7(NULL, p7, inBio, flags), 0);
  69583. /* bad arg: pkcs7 NULL */
  69584. ExpectIntEQ(SMIME_write_PKCS7(outBio, NULL, inBio, flags), 0);
  69585. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69586. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69587. BIO_free(content);
  69588. content = NULL;
  69589. BIO_free(inBio);
  69590. inBio = NULL;
  69591. BIO_free(outBio);
  69592. outBio = NULL;
  69593. PKCS7_free(p7Ver);
  69594. p7Ver = NULL;
  69595. PKCS7_free(p7);
  69596. p7 = NULL;
  69597. }
  69598. /* generate and verify SMIME: not detached, add Content-Type */
  69599. {
  69600. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69601. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69602. flags = PKCS7_STREAM | PKCS7_TEXT;
  69603. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69604. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69605. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69606. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69607. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69608. BIO_free(content);
  69609. content = NULL;
  69610. BIO_free(inBio);
  69611. inBio = NULL;
  69612. BIO_free(outBio);
  69613. outBio = NULL;
  69614. PKCS7_free(p7Ver);
  69615. p7Ver = NULL;
  69616. PKCS7_free(p7);
  69617. p7 = NULL;
  69618. }
  69619. /* generate and verify SMIME: detached */
  69620. {
  69621. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69622. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69623. flags = PKCS7_DETACHED | PKCS7_STREAM;
  69624. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69625. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69626. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69627. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69628. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  69629. BIO_free(content);
  69630. content = NULL;
  69631. BIO_free(inBio);
  69632. inBio = NULL;
  69633. BIO_free(outBio);
  69634. outBio = NULL;
  69635. PKCS7_free(p7Ver);
  69636. p7Ver = NULL;
  69637. PKCS7_free(p7);
  69638. p7 = NULL;
  69639. }
  69640. /* generate and verify SMIME: PKCS7_TEXT to add Content-Type header */
  69641. {
  69642. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69643. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69644. flags = PKCS7_STREAM | PKCS7_DETACHED | PKCS7_TEXT;
  69645. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69646. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69647. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69648. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69649. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  69650. BIO_free(content);
  69651. content = NULL;
  69652. BIO_free(inBio);
  69653. inBio = NULL;
  69654. BIO_free(outBio);
  69655. outBio = NULL;
  69656. PKCS7_free(p7Ver);
  69657. p7Ver = NULL;
  69658. PKCS7_free(p7);
  69659. p7 = NULL;
  69660. }
  69661. X509_STORE_free(store);
  69662. X509_free(caCert);
  69663. X509_free(signCert);
  69664. EVP_PKEY_free(signKey);
  69665. BIO_free(keyBio);
  69666. BIO_free(certBio);
  69667. BIO_free(caBio);
  69668. #endif
  69669. return EXPECT_RESULT();
  69670. }
  69671. #endif /* HAVE_SMIME */
  69672. #endif /* !NO_BIO */
  69673. /* Test of X509 store use outside of SSL context w/ CRL lookup (ALWAYS
  69674. * returns 0) */
  69675. static int test_X509_STORE_No_SSL_CTX(void)
  69676. {
  69677. EXPECT_DECLS;
  69678. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  69679. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  69680. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  69681. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  69682. defined(HAVE_CRL) && !defined(NO_RSA)
  69683. X509_STORE * store = NULL;
  69684. X509_STORE_CTX * storeCtx = NULL;
  69685. X509_CRL * crl = NULL;
  69686. X509 * ca = NULL;
  69687. X509 * cert = NULL;
  69688. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  69689. const char srvCert[] = "./certs/server-cert.pem";
  69690. const char caCert[] = "./certs/ca-cert.pem";
  69691. const char caDir[] = "./certs/crl/hash_pem";
  69692. XFILE fp = XBADFILE;
  69693. X509_LOOKUP * lookup = NULL;
  69694. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  69695. /* Set up store with CA */
  69696. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  69697. SSL_FILETYPE_PEM)));
  69698. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  69699. /* Add CRL lookup directory to store
  69700. * NOTE: test uses ./certs/crl/hash_pem/0fdb2da4.r0, which is a copy
  69701. * of crl.pem */
  69702. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  69703. X509_LOOKUP_hash_dir())));
  69704. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, caDir,
  69705. X509_FILETYPE_PEM, NULL), SSL_SUCCESS);
  69706. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  69707. SSL_SUCCESS);
  69708. /* Add CRL to store NOT containing the verified certificate, which
  69709. * forces use of the CRL lookup directory */
  69710. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  69711. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69712. NULL, NULL));
  69713. if (fp != XBADFILE)
  69714. XFCLOSE(fp);
  69715. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  69716. /* Create verification context outside of an SSL session */
  69717. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  69718. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  69719. SSL_FILETYPE_PEM)));
  69720. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  69721. /* Perform verification, which should NOT indicate CRL missing due to the
  69722. * store CM's X509 store pointer being NULL */
  69723. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  69724. X509_CRL_free(crl);
  69725. X509_STORE_free(store);
  69726. X509_STORE_CTX_free(storeCtx);
  69727. X509_free(cert);
  69728. X509_free(ca);
  69729. #endif
  69730. return EXPECT_RESULT();
  69731. }
  69732. /* Test of X509 store use outside of SSL context w/ CRL lookup, but
  69733. * with X509_LOOKUP_add_dir and X509_FILETYPE_ASN1. */
  69734. static int test_X509_LOOKUP_add_dir(void)
  69735. {
  69736. EXPECT_DECLS;
  69737. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  69738. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  69739. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  69740. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  69741. defined(HAVE_CRL) && !defined(NO_RSA)
  69742. X509_STORE * store = NULL;
  69743. X509_STORE_CTX * storeCtx = NULL;
  69744. X509_CRL * crl = NULL;
  69745. X509 * ca = NULL;
  69746. X509 * cert = NULL;
  69747. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  69748. const char srvCert[] = "./certs/server-cert.pem";
  69749. const char caCert[] = "./certs/ca-cert.pem";
  69750. const char caDir[] = "./certs/crl/hash_der";
  69751. XFILE fp = XBADFILE;
  69752. X509_LOOKUP * lookup = NULL;
  69753. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  69754. /* Set up store with CA */
  69755. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  69756. SSL_FILETYPE_PEM)));
  69757. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  69758. /* Add CRL lookup directory to store.
  69759. * Test uses ./certs/crl/hash_der/0fdb2da4.r0, which is a copy
  69760. * of crl.der */
  69761. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  69762. X509_LOOKUP_hash_dir())));
  69763. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_ASN1),
  69764. SSL_SUCCESS);
  69765. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  69766. SSL_SUCCESS);
  69767. /* Add CRL to store NOT containing the verified certificate, which
  69768. * forces use of the CRL lookup directory */
  69769. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  69770. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69771. NULL, NULL));
  69772. if (fp != XBADFILE) {
  69773. XFCLOSE(fp);
  69774. fp = XBADFILE;
  69775. }
  69776. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  69777. /* Create verification context outside of an SSL session */
  69778. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  69779. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  69780. SSL_FILETYPE_PEM)));
  69781. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  69782. /* Perform verification, which should NOT return CRL missing */
  69783. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  69784. X509_CRL_free(crl);
  69785. crl = NULL;
  69786. X509_STORE_free(store);
  69787. store = NULL;
  69788. X509_STORE_CTX_free(storeCtx);
  69789. storeCtx = NULL;
  69790. X509_free(cert);
  69791. cert = NULL;
  69792. X509_free(ca);
  69793. ca = NULL;
  69794. /* Now repeat the same, but look for X509_FILETYPE_PEM.
  69795. * We should get CRL_MISSING at the end, because the lookup
  69796. * dir has only ASN1 CRLs. */
  69797. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  69798. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  69799. SSL_FILETYPE_PEM)));
  69800. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  69801. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  69802. X509_LOOKUP_hash_dir())));
  69803. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_PEM),
  69804. SSL_SUCCESS);
  69805. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  69806. SSL_SUCCESS);
  69807. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  69808. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69809. NULL, NULL));
  69810. if (fp != XBADFILE) {
  69811. XFCLOSE(fp);
  69812. fp = XBADFILE;
  69813. }
  69814. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  69815. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  69816. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  69817. SSL_FILETYPE_PEM)));
  69818. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  69819. /* Now we SHOULD get CRL_MISSING, because we looked for PEM
  69820. * in dir containing only ASN1/DER. */
  69821. ExpectIntEQ(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69822. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  69823. X509_V_ERR_UNABLE_TO_GET_CRL);
  69824. X509_CRL_free(crl);
  69825. X509_STORE_free(store);
  69826. X509_STORE_CTX_free(storeCtx);
  69827. X509_free(cert);
  69828. X509_free(ca);
  69829. #endif
  69830. return EXPECT_RESULT();
  69831. }
  69832. /*----------------------------------------------------------------------------*
  69833. | Certificate Failure Checks
  69834. *----------------------------------------------------------------------------*/
  69835. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  69836. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  69837. #if !defined(NO_RSA) || defined(HAVE_ECC)
  69838. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  69839. static int verify_sig_cm(const char* ca, byte* cert_buf, size_t cert_sz,
  69840. int type)
  69841. {
  69842. int ret;
  69843. WOLFSSL_CERT_MANAGER* cm = NULL;
  69844. switch (type) {
  69845. case TESTING_RSA:
  69846. #ifdef NO_RSA
  69847. fprintf(stderr, "RSA disabled, skipping test\n");
  69848. return ASN_SIG_CONFIRM_E;
  69849. #else
  69850. break;
  69851. #endif
  69852. case TESTING_ECC:
  69853. #ifndef HAVE_ECC
  69854. fprintf(stderr, "ECC disabled, skipping test\n");
  69855. return ASN_SIG_CONFIRM_E;
  69856. #else
  69857. break;
  69858. #endif
  69859. default:
  69860. fprintf(stderr, "Bad function argument\n");
  69861. return BAD_FUNC_ARG;
  69862. }
  69863. cm = wolfSSL_CertManagerNew();
  69864. if (cm == NULL) {
  69865. fprintf(stderr, "wolfSSL_CertManagerNew failed\n");
  69866. return -1;
  69867. }
  69868. #ifndef NO_FILESYSTEM
  69869. ret = wolfSSL_CertManagerLoadCA(cm, ca, 0);
  69870. if (ret != WOLFSSL_SUCCESS) {
  69871. fprintf(stderr, "wolfSSL_CertManagerLoadCA failed\n");
  69872. wolfSSL_CertManagerFree(cm);
  69873. return ret;
  69874. }
  69875. #else
  69876. (void)ca;
  69877. #endif
  69878. ret = wolfSSL_CertManagerVerifyBuffer(cm, cert_buf, (long int)cert_sz,
  69879. WOLFSSL_FILETYPE_ASN1);
  69880. /* Let ExpectIntEQ handle return code */
  69881. wolfSSL_CertManagerFree(cm);
  69882. return ret;
  69883. }
  69884. #endif
  69885. #if !defined(NO_FILESYSTEM)
  69886. static int test_RsaSigFailure_cm(void)
  69887. {
  69888. EXPECT_DECLS;
  69889. #ifndef NO_RSA
  69890. const char* ca_cert = "./certs/ca-cert.pem";
  69891. const char* server_cert = "./certs/server-cert.der";
  69892. byte* cert_buf = NULL;
  69893. size_t cert_sz = 0;
  69894. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  69895. if ((cert_buf != NULL) && (cert_sz > 0)) {
  69896. /* corrupt DER - invert last byte, which is signature */
  69897. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  69898. /* test bad cert */
  69899. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  69900. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  69901. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  69902. #elif defined(NO_ASN_CRYPT)
  69903. /* RSA verify is not called when ASN crypt support is disabled */
  69904. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  69905. WOLFSSL_SUCCESS);
  69906. #else
  69907. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  69908. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  69909. #endif
  69910. }
  69911. /* load_file() uses malloc. */
  69912. if (cert_buf != NULL) {
  69913. free(cert_buf);
  69914. }
  69915. #endif /* !NO_RSA */
  69916. return EXPECT_RESULT();
  69917. }
  69918. static int test_EccSigFailure_cm(void)
  69919. {
  69920. EXPECT_DECLS;
  69921. #ifdef HAVE_ECC
  69922. /* self-signed ECC cert, so use server cert as CA */
  69923. const char* ca_cert = "./certs/ca-ecc-cert.pem";
  69924. const char* server_cert = "./certs/server-ecc.der";
  69925. byte* cert_buf = NULL;
  69926. size_t cert_sz = 0;
  69927. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  69928. if (cert_buf != NULL && cert_sz > 0) {
  69929. /* corrupt DER - invert last byte, which is signature */
  69930. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  69931. /* test bad cert */
  69932. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  69933. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  69934. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  69935. #elif defined(NO_ASN_CRYPT)
  69936. /* ECC verify is not called when ASN crypt support is disabled */
  69937. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  69938. WOLFSSL_SUCCESS);
  69939. #else
  69940. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  69941. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  69942. #endif
  69943. }
  69944. /* load_file() uses malloc. */
  69945. if (cert_buf != NULL) {
  69946. free(cert_buf);
  69947. }
  69948. #ifdef FP_ECC
  69949. wc_ecc_fp_free();
  69950. #endif
  69951. #endif /* HAVE_ECC */
  69952. return EXPECT_RESULT();
  69953. }
  69954. #endif /* !NO_FILESYSTEM */
  69955. #endif /* NO_CERTS */
  69956. #ifdef WOLFSSL_TLS13
  69957. #if defined(WOLFSSL_SEND_HRR_COOKIE) && !defined(NO_WOLFSSL_SERVER)
  69958. #ifdef WC_SHA384_DIGEST_SIZE
  69959. static byte fixedKey[WC_SHA384_DIGEST_SIZE] = { 0, };
  69960. #else
  69961. static byte fixedKey[WC_SHA256_DIGEST_SIZE] = { 0, };
  69962. #endif
  69963. #endif
  69964. #ifdef WOLFSSL_EARLY_DATA
  69965. static const char earlyData[] = "Early Data";
  69966. static char earlyDataBuffer[1];
  69967. #endif
  69968. static int test_tls13_apis(void)
  69969. {
  69970. EXPECT_DECLS;
  69971. int ret;
  69972. #ifndef WOLFSSL_NO_TLS12
  69973. #ifndef NO_WOLFSSL_CLIENT
  69974. WOLFSSL_CTX* clientTls12Ctx = NULL;
  69975. WOLFSSL* clientTls12Ssl = NULL;
  69976. #endif
  69977. #ifndef NO_WOLFSSL_SERVER
  69978. WOLFSSL_CTX* serverTls12Ctx = NULL;
  69979. WOLFSSL* serverTls12Ssl = NULL;
  69980. #endif
  69981. #endif
  69982. #ifndef NO_WOLFSSL_CLIENT
  69983. WOLFSSL_CTX* clientCtx = NULL;
  69984. WOLFSSL* clientSsl = NULL;
  69985. #endif
  69986. #ifndef NO_WOLFSSL_SERVER
  69987. WOLFSSL_CTX* serverCtx = NULL;
  69988. WOLFSSL* serverSsl = NULL;
  69989. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  69990. const char* ourCert = svrCertFile;
  69991. const char* ourKey = svrKeyFile;
  69992. #endif
  69993. #endif
  69994. int required;
  69995. #ifdef WOLFSSL_EARLY_DATA
  69996. int outSz;
  69997. #endif
  69998. #if defined(HAVE_ECC) && defined(HAVE_SUPPORTED_CURVES)
  69999. int groups[2] = { WOLFSSL_ECC_SECP256R1,
  70000. #ifdef WOLFSSL_HAVE_KYBER
  70001. #ifndef WOLFSSL_NO_KYBER512
  70002. WOLFSSL_KYBER_LEVEL1
  70003. #elif !defined(WOLFSSL_NO_KYBER768)
  70004. WOLFSSL_KYBER_LEVEL3
  70005. #else
  70006. WOLFSSL_KYBER_LEVEL5
  70007. #endif
  70008. #else
  70009. WOLFSSL_ECC_SECP256R1
  70010. #endif
  70011. };
  70012. #if !defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT)
  70013. int bad_groups[2] = { 0xDEAD, 0xBEEF };
  70014. #endif /* !NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT */
  70015. int numGroups = 2;
  70016. #endif
  70017. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  70018. char groupList[] =
  70019. #ifdef HAVE_CURVE25519
  70020. "X25519:"
  70021. #endif
  70022. #ifdef HAVE_CURVE448
  70023. "X448:"
  70024. #endif
  70025. #ifndef NO_ECC_SECP
  70026. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  70027. "P-521:secp521r1:"
  70028. #endif
  70029. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  70030. "P-384:secp384r1:"
  70031. #endif
  70032. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  70033. "P-256:secp256r1"
  70034. #if defined(WOLFSSL_HAVE_KYBER)
  70035. #ifndef WOLFSSL_NO_KYBER512
  70036. ":P256_KYBER_LEVEL1"
  70037. #elif !defined(WOLFSSL_NO_KYBER768)
  70038. ":P256_KYBER_LEVEL3"
  70039. #else
  70040. ":P256_KYBER_LEVEL5"
  70041. #endif
  70042. #endif
  70043. #endif
  70044. #endif /* !defined(NO_ECC_SECP) */
  70045. #if defined(WOLFSSL_HAVE_KYBER)
  70046. #ifndef WOLFSSL_NO_KYBER512
  70047. ":KYBER_LEVEL1"
  70048. #elif !defined(WOLFSSL_NO_KYBER768)
  70049. ":KYBER_LEVEL3"
  70050. #else
  70051. ":KYBER_LEVEL5"
  70052. #endif
  70053. #endif
  70054. "";
  70055. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  70056. #if defined(WOLFSSL_HAVE_KYBER)
  70057. int kyberLevel;
  70058. #endif
  70059. (void)ret;
  70060. #ifndef WOLFSSL_NO_TLS12
  70061. #ifndef NO_WOLFSSL_CLIENT
  70062. clientTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
  70063. clientTls12Ssl = wolfSSL_new(clientTls12Ctx);
  70064. #endif
  70065. #ifndef NO_WOLFSSL_SERVER
  70066. serverTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
  70067. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70068. wolfSSL_CTX_use_certificate_chain_file(serverTls12Ctx, ourCert);
  70069. wolfSSL_CTX_use_PrivateKey_file(serverTls12Ctx, ourKey,
  70070. WOLFSSL_FILETYPE_PEM);
  70071. #endif
  70072. serverTls12Ssl = wolfSSL_new(serverTls12Ctx);
  70073. #endif
  70074. #endif
  70075. #ifndef NO_WOLFSSL_CLIENT
  70076. clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  70077. clientSsl = wolfSSL_new(clientCtx);
  70078. #endif
  70079. #ifndef NO_WOLFSSL_SERVER
  70080. serverCtx = wolfSSL_CTX_new(wolfTLSv1_3_server_method());
  70081. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70082. wolfSSL_CTX_use_certificate_chain_file(serverCtx, ourCert);
  70083. wolfSSL_CTX_use_PrivateKey_file(serverCtx, ourKey, WOLFSSL_FILETYPE_PEM);
  70084. #endif
  70085. serverSsl = wolfSSL_new(serverCtx);
  70086. ExpectNotNull(serverSsl);
  70087. #endif
  70088. #ifdef WOLFSSL_SEND_HRR_COOKIE
  70089. ExpectIntEQ(wolfSSL_send_hrr_cookie(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70090. #ifndef NO_WOLFSSL_CLIENT
  70091. ExpectIntEQ(wolfSSL_send_hrr_cookie(clientSsl, NULL, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70092. #endif
  70093. #ifndef NO_WOLFSSL_SERVER
  70094. #ifndef WOLFSSL_NO_TLS12
  70095. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverTls12Ssl, NULL, 0),
  70096. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70097. #endif
  70098. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, NULL, 0), WOLFSSL_SUCCESS);
  70099. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, fixedKey, sizeof(fixedKey)),
  70100. WOLFSSL_SUCCESS);
  70101. #endif
  70102. #endif
  70103. #ifdef HAVE_SUPPORTED_CURVES
  70104. #ifdef HAVE_ECC
  70105. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70106. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70107. #ifndef NO_WOLFSSL_SERVER
  70108. do {
  70109. ret = wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_SECP256R1);
  70110. #ifdef WOLFSSL_ASYNC_CRYPT
  70111. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70112. wolfSSL_AsyncPoll(serverSsl, WOLF_POLL_FLAG_CHECK_HW);
  70113. #endif
  70114. }
  70115. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70116. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70117. #endif
  70118. #ifndef NO_WOLFSSL_CLIENT
  70119. #ifndef WOLFSSL_NO_TLS12
  70120. do {
  70121. ret = wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1);
  70122. #ifdef WOLFSSL_ASYNC_CRYPT
  70123. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70124. wolfSSL_AsyncPoll(clientTls12Ssl, WOLF_POLL_FLAG_CHECK_HW);
  70125. #endif
  70126. }
  70127. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70128. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70129. #endif
  70130. do {
  70131. ret = wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1);
  70132. #ifdef WOLFSSL_ASYNC_CRYPT
  70133. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70134. wolfSSL_AsyncPoll(clientSsl, WOLF_POLL_FLAG_CHECK_HW);
  70135. #endif
  70136. }
  70137. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70138. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70139. #endif
  70140. #elif defined(HAVE_CURVE25519)
  70141. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X25519), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70142. #ifndef NO_WOLFSSL_SERVER
  70143. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X25519),
  70144. WOLFSSL_SUCCESS);
  70145. #endif
  70146. #ifndef NO_WOLFSSL_CLIENT
  70147. #ifndef WOLFSSL_NO_TLS12
  70148. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X25519),
  70149. WOLFSSL_SUCCESS);
  70150. #endif
  70151. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X25519),
  70152. WOLFSSL_SUCCESS);
  70153. #endif
  70154. #elif defined(HAVE_CURVE448)
  70155. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X448), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70156. #ifndef NO_WOLFSSL_SERVER
  70157. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X448),
  70158. WOLFSSL_SUCCESS);
  70159. #endif
  70160. #ifndef NO_WOLFSSL_CLIENT
  70161. #ifndef WOLFSSL_NO_TLS12
  70162. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X448),
  70163. WOLFSSL_SUCCESS);
  70164. #endif
  70165. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X448),
  70166. WOLFSSL_SUCCESS);
  70167. #endif
  70168. #else
  70169. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70170. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70171. #ifndef NO_WOLFSSL_CLIENT
  70172. #ifndef WOLFSSL_NO_TLS12
  70173. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1),
  70174. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70175. #endif
  70176. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1),
  70177. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70178. #endif
  70179. #endif
  70180. #if defined(WOLFSSL_HAVE_KYBER)
  70181. #ifndef WOLFSSL_NO_KYBER768
  70182. kyberLevel = WOLFSSL_KYBER_LEVEL3;
  70183. #elif !defined(WOLFSSL_NO_KYBER1024)
  70184. kyberLevel = WOLFSSL_KYBER_LEVEL5;
  70185. #else
  70186. kyberLevel = WOLFSSL_KYBER_LEVEL1;
  70187. #endif
  70188. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, kyberLevel), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70189. #ifndef NO_WOLFSSL_SERVER
  70190. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, kyberLevel),
  70191. WOLFSSL_SUCCESS);
  70192. #endif
  70193. #ifndef NO_WOLFSSL_CLIENT
  70194. #ifndef WOLFSSL_NO_TLS12
  70195. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, kyberLevel),
  70196. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70197. #endif
  70198. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, kyberLevel),
  70199. WOLFSSL_SUCCESS);
  70200. #endif
  70201. #endif
  70202. ExpectIntEQ(wolfSSL_NoKeyShares(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70203. #ifndef NO_WOLFSSL_SERVER
  70204. ExpectIntEQ(wolfSSL_NoKeyShares(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70205. #endif
  70206. #ifndef NO_WOLFSSL_CLIENT
  70207. #ifndef WOLFSSL_NO_TLS12
  70208. ExpectIntEQ(wolfSSL_NoKeyShares(clientTls12Ssl), WOLFSSL_SUCCESS);
  70209. #endif
  70210. ExpectIntEQ(wolfSSL_NoKeyShares(clientSsl), WOLFSSL_SUCCESS);
  70211. #endif
  70212. #endif /* HAVE_SUPPORTED_CURVES */
  70213. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70214. #ifndef NO_WOLFSSL_CLIENT
  70215. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70216. #endif
  70217. #ifndef NO_WOLFSSL_SERVER
  70218. #ifndef WOLFSSL_NO_TLS12
  70219. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70220. #endif
  70221. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverCtx), 0);
  70222. #endif
  70223. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70224. #ifndef NO_WOLFSSL_CLIENT
  70225. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70226. #endif
  70227. #ifndef NO_WOLFSSL_SERVER
  70228. #ifndef WOLFSSL_NO_TLS12
  70229. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70230. #endif
  70231. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverSsl), 0);
  70232. #endif
  70233. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70234. #ifndef NO_WOLFSSL_CLIENT
  70235. #ifndef WOLFSSL_NO_TLS12
  70236. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70237. #endif
  70238. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientCtx), 0);
  70239. #endif
  70240. #ifndef NO_WOLFSSL_SERVER
  70241. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(serverCtx), 0);
  70242. #endif
  70243. ExpectIntEQ(wolfSSL_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70244. #ifndef NO_WOLFSSL_CLIENT
  70245. #ifndef WOLFSSL_NO_TLS12
  70246. ExpectIntEQ(wolfSSL_no_dhe_psk(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70247. #endif
  70248. ExpectIntEQ(wolfSSL_no_dhe_psk(clientSsl), 0);
  70249. #endif
  70250. #ifndef NO_WOLFSSL_SERVER
  70251. ExpectIntEQ(wolfSSL_no_dhe_psk(serverSsl), 0);
  70252. #endif
  70253. ExpectIntEQ(wolfSSL_update_keys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70254. #ifndef NO_WOLFSSL_CLIENT
  70255. #ifndef WOLFSSL_NO_TLS12
  70256. ExpectIntEQ(wolfSSL_update_keys(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70257. #endif
  70258. ExpectIntEQ(wolfSSL_update_keys(clientSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70259. #endif
  70260. #ifndef NO_WOLFSSL_SERVER
  70261. ExpectIntEQ(wolfSSL_update_keys(serverSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70262. #endif
  70263. ExpectIntEQ(wolfSSL_key_update_response(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70264. ExpectIntEQ(wolfSSL_key_update_response(NULL, &required), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70265. #ifndef NO_WOLFSSL_CLIENT
  70266. #ifndef WOLFSSL_NO_TLS12
  70267. ExpectIntEQ(wolfSSL_key_update_response(clientTls12Ssl, &required),
  70268. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70269. #endif
  70270. ExpectIntEQ(wolfSSL_key_update_response(clientSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70271. #endif
  70272. #ifndef NO_WOLFSSL_SERVER
  70273. ExpectIntEQ(wolfSSL_key_update_response(serverSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70274. #endif
  70275. #if !defined(NO_CERTS) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  70276. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70277. #ifndef NO_WOLFSSL_SERVER
  70278. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(serverCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70279. #endif
  70280. #ifndef NO_WOLFSSL_CLIENT
  70281. #ifndef WOLFSSL_NO_TLS12
  70282. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientTls12Ctx),
  70283. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70284. #endif
  70285. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientCtx), 0);
  70286. #endif
  70287. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70288. #ifndef NO_WOLFSSL_SERVER
  70289. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70290. #endif
  70291. #ifndef NO_WOLFSSL_CLIENT
  70292. #ifndef WOLFSSL_NO_TLS12
  70293. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientTls12Ssl),
  70294. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70295. #endif
  70296. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientSsl), 0);
  70297. #endif
  70298. ExpectIntEQ(wolfSSL_request_certificate(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70299. #ifndef NO_WOLFSSL_CLIENT
  70300. ExpectIntEQ(wolfSSL_request_certificate(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70301. #endif
  70302. #ifndef NO_WOLFSSL_SERVER
  70303. #ifndef WOLFSSL_NO_TLS12
  70304. ExpectIntEQ(wolfSSL_request_certificate(serverTls12Ssl),
  70305. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70306. #endif
  70307. ExpectIntEQ(wolfSSL_request_certificate(serverSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70308. #endif
  70309. #endif
  70310. #ifdef HAVE_ECC
  70311. #ifndef WOLFSSL_NO_SERVER_GROUPS_EXT
  70312. ExpectIntEQ(wolfSSL_preferred_group(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70313. #ifndef NO_WOLFSSL_SERVER
  70314. ExpectIntEQ(wolfSSL_preferred_group(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70315. #endif
  70316. #ifndef NO_WOLFSSL_CLIENT
  70317. #ifndef WOLFSSL_NO_TLS12
  70318. ExpectIntEQ(wolfSSL_preferred_group(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70319. #endif
  70320. ExpectIntEQ(wolfSSL_preferred_group(clientSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70321. #endif
  70322. #endif
  70323. #ifdef HAVE_SUPPORTED_CURVES
  70324. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70325. #ifndef NO_WOLFSSL_CLIENT
  70326. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70327. #endif
  70328. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70329. #ifndef NO_WOLFSSL_CLIENT
  70330. #ifndef WOLFSSL_NO_TLS12
  70331. ExpectIntEQ(wolfSSL_CTX_set_groups(clientTls12Ctx, groups, numGroups),
  70332. WOLFSSL_SUCCESS);
  70333. #endif
  70334. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups,
  70335. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70336. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
  70337. WOLFSSL_SUCCESS);
  70338. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
  70339. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70340. #endif
  70341. #ifndef NO_WOLFSSL_SERVER
  70342. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, groups, numGroups),
  70343. WOLFSSL_SUCCESS);
  70344. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, bad_groups, numGroups),
  70345. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70346. #endif
  70347. ExpectIntEQ(wolfSSL_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70348. #ifndef NO_WOLFSSL_CLIENT
  70349. ExpectIntEQ(wolfSSL_set_groups(clientSsl, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70350. #endif
  70351. ExpectIntEQ(wolfSSL_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70352. #ifndef NO_WOLFSSL_CLIENT
  70353. #ifndef WOLFSSL_NO_TLS12
  70354. ExpectIntEQ(wolfSSL_set_groups(clientTls12Ssl, groups, numGroups),
  70355. WOLFSSL_SUCCESS);
  70356. #endif
  70357. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
  70358. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70359. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
  70360. WOLFSSL_SUCCESS);
  70361. ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
  70362. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70363. #endif
  70364. #ifndef NO_WOLFSSL_SERVER
  70365. ExpectIntEQ(wolfSSL_set_groups(serverSsl, groups, numGroups),
  70366. WOLFSSL_SUCCESS);
  70367. ExpectIntEQ(wolfSSL_set_groups(serverSsl, bad_groups, numGroups),
  70368. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70369. #endif
  70370. #ifdef OPENSSL_EXTRA
  70371. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70372. #ifndef NO_WOLFSSL_CLIENT
  70373. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, NULL),
  70374. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70375. #endif
  70376. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, groupList),
  70377. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70378. #ifndef NO_WOLFSSL_CLIENT
  70379. #ifndef WOLFSSL_NO_TLS12
  70380. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientTls12Ctx, groupList),
  70381. WOLFSSL_SUCCESS);
  70382. #endif
  70383. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, groupList),
  70384. WOLFSSL_SUCCESS);
  70385. #endif
  70386. #ifndef NO_WOLFSSL_SERVER
  70387. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(serverCtx, groupList),
  70388. WOLFSSL_SUCCESS);
  70389. #endif
  70390. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70391. #ifndef NO_WOLFSSL_CLIENT
  70392. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70393. #endif
  70394. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, groupList), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70395. #ifndef NO_WOLFSSL_CLIENT
  70396. #ifndef WOLFSSL_NO_TLS12
  70397. ExpectIntEQ(wolfSSL_set1_groups_list(clientTls12Ssl, groupList),
  70398. WOLFSSL_SUCCESS);
  70399. #endif
  70400. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, groupList),
  70401. WOLFSSL_SUCCESS);
  70402. #endif
  70403. #ifndef NO_WOLFSSL_SERVER
  70404. ExpectIntEQ(wolfSSL_set1_groups_list(serverSsl, groupList),
  70405. WOLFSSL_SUCCESS);
  70406. #endif
  70407. #endif /* OPENSSL_EXTRA */
  70408. #endif /* HAVE_SUPPORTED_CURVES */
  70409. #endif /* HAVE_ECC */
  70410. #ifdef WOLFSSL_EARLY_DATA
  70411. #ifndef OPENSSL_EXTRA
  70412. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70413. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70414. #else
  70415. ExpectIntEQ(SSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70416. ExpectIntEQ(SSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70417. #endif
  70418. #ifndef NO_WOLFSSL_CLIENT
  70419. #ifndef OPENSSL_EXTRA
  70420. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70421. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70422. #else
  70423. ExpectIntEQ(SSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70424. ExpectIntEQ(SSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70425. #endif
  70426. #endif
  70427. #ifndef NO_WOLFSSL_SERVER
  70428. #ifndef WOLFSSL_NO_TLS12
  70429. #ifndef OPENSSL_EXTRA
  70430. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70431. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70432. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70433. #else
  70434. ExpectIntEQ(SSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70435. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70436. ExpectIntEQ(SSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70437. #endif
  70438. #endif
  70439. #ifndef OPENSSL_EXTRA
  70440. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70441. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32),
  70442. WOLFSSL_SUCCESS);
  70443. #else
  70444. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32), 0);
  70445. #endif
  70446. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverCtx), 32);
  70447. #else
  70448. ExpectIntEQ(SSL_CTX_set_max_early_data(serverCtx, 32), 1);
  70449. ExpectIntEQ(SSL_CTX_get_max_early_data(serverCtx), 32);
  70450. #endif
  70451. #endif
  70452. #ifndef OPENSSL_EXTRA
  70453. ExpectIntEQ(wolfSSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70454. ExpectIntEQ(wolfSSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70455. #else
  70456. ExpectIntEQ(SSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70457. ExpectIntEQ(SSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70458. #endif
  70459. #ifndef NO_WOLFSSL_CLIENT
  70460. #ifndef OPENSSL_EXTRA
  70461. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70462. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70463. #else
  70464. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), 0);
  70465. #endif
  70466. ExpectIntEQ(wolfSSL_get_max_early_data(clientSsl), 17);
  70467. #else
  70468. ExpectIntEQ(SSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70469. ExpectIntEQ(SSL_get_max_early_data(clientSsl), 17);
  70470. #endif
  70471. #endif
  70472. #ifndef NO_WOLFSSL_SERVER
  70473. #ifndef WOLFSSL_NO_TLS12
  70474. #ifndef OPENSSL_EXTRA
  70475. ExpectIntEQ(wolfSSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70476. ExpectIntEQ(wolfSSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70477. #else
  70478. ExpectIntEQ(SSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70479. ExpectIntEQ(SSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70480. #endif
  70481. #endif
  70482. #ifndef OPENSSL_EXTRA
  70483. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70484. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), WOLFSSL_SUCCESS);
  70485. #else
  70486. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), 0);
  70487. #endif
  70488. ExpectIntEQ(wolfSSL_get_max_early_data(serverSsl), 16);
  70489. #else
  70490. ExpectIntEQ(SSL_set_max_early_data(serverSsl, 16), 1);
  70491. ExpectIntEQ(SSL_get_max_early_data(serverSsl), 16);
  70492. #endif
  70493. #endif
  70494. ExpectIntEQ(wolfSSL_write_early_data(NULL, earlyData, sizeof(earlyData),
  70495. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70496. #ifndef NO_WOLFSSL_CLIENT
  70497. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, NULL, sizeof(earlyData),
  70498. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70499. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData, -1, &outSz),
  70500. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70501. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  70502. sizeof(earlyData), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70503. #endif
  70504. #ifndef NO_WOLFSSL_SERVER
  70505. ExpectIntEQ(wolfSSL_write_early_data(serverSsl, earlyData,
  70506. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  70507. #endif
  70508. #ifndef NO_WOLFSSL_CLIENT
  70509. #ifndef WOLFSSL_NO_TLS12
  70510. ExpectIntEQ(wolfSSL_write_early_data(clientTls12Ssl, earlyData,
  70511. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70512. #endif
  70513. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  70514. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70515. #endif
  70516. ExpectIntEQ(wolfSSL_read_early_data(NULL, earlyDataBuffer,
  70517. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70518. #ifndef NO_WOLFSSL_SERVER
  70519. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, NULL,
  70520. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70521. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer, -1,
  70522. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70523. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  70524. sizeof(earlyDataBuffer), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70525. #endif
  70526. #ifndef NO_WOLFSSL_CLIENT
  70527. ExpectIntEQ(wolfSSL_read_early_data(clientSsl, earlyDataBuffer,
  70528. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  70529. #endif
  70530. #ifndef NO_WOLFSSL_SERVER
  70531. #ifndef WOLFSSL_NO_TLS12
  70532. ExpectIntEQ(wolfSSL_read_early_data(serverTls12Ssl, earlyDataBuffer,
  70533. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70534. #endif
  70535. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  70536. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70537. #endif
  70538. #endif
  70539. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_EARLY_DATA)
  70540. ExpectIntLT(SSL_get_early_data_status(NULL), 0);
  70541. #endif
  70542. #ifndef NO_WOLFSSL_SERVER
  70543. wolfSSL_free(serverSsl);
  70544. wolfSSL_CTX_free(serverCtx);
  70545. #endif
  70546. #ifndef NO_WOLFSSL_CLIENT
  70547. wolfSSL_free(clientSsl);
  70548. wolfSSL_CTX_free(clientCtx);
  70549. #endif
  70550. #ifndef WOLFSSL_NO_TLS12
  70551. #ifndef NO_WOLFSSL_SERVER
  70552. wolfSSL_free(serverTls12Ssl);
  70553. wolfSSL_CTX_free(serverTls12Ctx);
  70554. #endif
  70555. #ifndef NO_WOLFSSL_CLIENT
  70556. wolfSSL_free(clientTls12Ssl);
  70557. wolfSSL_CTX_free(clientTls12Ctx);
  70558. #endif
  70559. #endif
  70560. return EXPECT_RESULT();
  70561. }
  70562. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  70563. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  70564. defined(BUILD_TLS_AES_256_GCM_SHA384)
  70565. /* Called when writing. */
  70566. static int CsSend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  70567. {
  70568. (void)ssl;
  70569. (void)buf;
  70570. (void)sz;
  70571. (void)ctx;
  70572. /* Force error return from wolfSSL_accept_TLSv13(). */
  70573. return WANT_WRITE;
  70574. }
  70575. /* Called when reading. */
  70576. static int CsRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  70577. {
  70578. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  70579. int len = (int)msg->length;
  70580. (void)ssl;
  70581. (void)sz;
  70582. /* Pass back as much of message as will fit in buffer. */
  70583. if (len > sz)
  70584. len = sz;
  70585. XMEMCPY(buf, msg->buffer, len);
  70586. /* Move over returned data. */
  70587. msg->buffer += len;
  70588. msg->length -= len;
  70589. /* Amount actually copied. */
  70590. return len;
  70591. }
  70592. #endif
  70593. static int test_tls13_cipher_suites(void)
  70594. {
  70595. EXPECT_DECLS;
  70596. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  70597. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  70598. defined(BUILD_TLS_AES_256_GCM_SHA384)
  70599. WOLFSSL_CTX* ctx = NULL;
  70600. WOLFSSL *ssl = NULL;
  70601. int i;
  70602. byte clientHello[] = {
  70603. 0x16, 0x03, 0x03, 0x01, 0x9b, 0x01, 0x00, 0x01,
  70604. 0x97, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  70605. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  70606. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  70607. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  70608. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  70609. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  70610. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  70611. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70612. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  70613. /* Cipher suites: 0x13, 0x01 = TLS13-AES128-GCM-SHA256, twice. */
  70614. 0x13, 0x01,
  70615. 0x13, 0x01, 0x01, 0x00, 0x01, 0x4a, 0x00, 0x2d,
  70616. 0x00, 0x03, 0x02, 0x00, 0x01, 0x00, 0x33, 0x00,
  70617. 0x47, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
  70618. 0x90, 0xfc, 0xe2, 0x97, 0x05, 0x7c, 0xb5, 0x23,
  70619. 0x5d, 0x5f, 0x5b, 0xcd, 0x0c, 0x1e, 0xe0, 0xe9,
  70620. 0xab, 0x38, 0x6b, 0x1e, 0x20, 0x5c, 0x1c, 0x90,
  70621. 0x2a, 0x9e, 0x68, 0x8e, 0x70, 0x05, 0x10, 0xa8,
  70622. 0x02, 0x1b, 0xf9, 0x5c, 0xef, 0xc9, 0xaf, 0xca,
  70623. 0x1a, 0x3b, 0x16, 0x8b, 0xe4, 0x1b, 0x3c, 0x15,
  70624. 0xb8, 0x0d, 0xbd, 0xaf, 0x62, 0x8d, 0xa7, 0x13,
  70625. 0xa0, 0x7c, 0xe0, 0x59, 0x0c, 0x4f, 0x8a, 0x6d,
  70626. 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04, 0x00,
  70627. 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x03, 0x05,
  70628. 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, 0x08,
  70629. 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08,
  70630. 0x09, 0x06, 0x01, 0x05, 0x01, 0x04, 0x01, 0x03,
  70631. 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x04, 0x00,
  70632. 0x02, 0x00, 0x17, 0x00, 0x16, 0x00, 0x00, 0x00,
  70633. 0x23, 0x00, 0x00, 0x00, 0x29, 0x00, 0xb9, 0x00,
  70634. 0x94, 0x00, 0x8e, 0x0f, 0x12, 0xfa, 0x84, 0x1f,
  70635. 0x76, 0x94, 0xd7, 0x09, 0x5e, 0xad, 0x08, 0x51,
  70636. 0xb6, 0x80, 0x28, 0x31, 0x8b, 0xfd, 0xc6, 0xbd,
  70637. 0x9e, 0xf5, 0x3b, 0x4d, 0x02, 0xbe, 0x1d, 0x73,
  70638. 0xea, 0x13, 0x68, 0x00, 0x4c, 0xfd, 0x3d, 0x48,
  70639. 0x51, 0xf9, 0x06, 0xbb, 0x92, 0xed, 0x42, 0x9f,
  70640. 0x7f, 0x2c, 0x73, 0x9f, 0xd9, 0xb4, 0xef, 0x05,
  70641. 0x26, 0x5b, 0x60, 0x5c, 0x0a, 0xfc, 0xa3, 0xbd,
  70642. 0x2d, 0x2d, 0x8b, 0xf9, 0xaa, 0x5c, 0x96, 0x3a,
  70643. 0xf2, 0xec, 0xfa, 0xe5, 0x57, 0x2e, 0x87, 0xbe,
  70644. 0x27, 0xc5, 0x3d, 0x4f, 0x5d, 0xdd, 0xde, 0x1c,
  70645. 0x1b, 0xb3, 0xcc, 0x27, 0x27, 0x57, 0x5a, 0xd9,
  70646. 0xea, 0x99, 0x27, 0x23, 0xa6, 0x0e, 0xea, 0x9c,
  70647. 0x0d, 0x85, 0xcb, 0x72, 0xeb, 0xd7, 0x93, 0xe3,
  70648. 0xfe, 0xf7, 0x5c, 0xc5, 0x5b, 0x75, 0x8c, 0x47,
  70649. 0x0a, 0x0e, 0xc4, 0x1a, 0xda, 0xef, 0x75, 0xe5,
  70650. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70651. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70652. 0x00, 0xfb, 0x92, 0xce, 0xaa, 0x00, 0x21, 0x20,
  70653. 0xcb, 0x73, 0x25, 0x80, 0x46, 0x78, 0x4f, 0xe5,
  70654. 0x34, 0xf6, 0x91, 0x13, 0x7f, 0xc8, 0x8d, 0xdc,
  70655. 0x81, 0x04, 0xb7, 0x0d, 0x49, 0x85, 0x2e, 0x12,
  70656. 0x7a, 0x07, 0x23, 0xe9, 0x13, 0xa4, 0x6d, 0x8c
  70657. };
  70658. WOLFSSL_BUFFER_INFO msg;
  70659. /* Offset into ClientHello message data of first cipher suite. */
  70660. const int csOff = 78;
  70661. /* Server cipher list. */
  70662. const char* serverCs = "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256";
  70663. /* Suite list with duplicates. */
  70664. const char* dupCs = "TLS13-AES128-GCM-SHA256:"
  70665. "TLS13-AES128-GCM-SHA256:"
  70666. "TLS13-AES256-GCM-SHA384:"
  70667. "TLS13-AES256-GCM-SHA384:"
  70668. "TLS13-AES128-GCM-SHA256";
  70669. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  70670. const byte dupCsBytes[] = { TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  70671. TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  70672. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  70673. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  70674. TLS13_BYTE, TLS_AES_256_GCM_SHA384 };
  70675. #endif
  70676. /* Set up wolfSSL context. */
  70677. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  70678. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  70679. WOLFSSL_FILETYPE_PEM));
  70680. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  70681. WOLFSSL_FILETYPE_PEM));
  70682. /* Read from 'msg'. */
  70683. wolfSSL_SetIORecv(ctx, CsRecv);
  70684. /* No where to send to - dummy sender. */
  70685. wolfSSL_SetIOSend(ctx, CsSend);
  70686. /* Test cipher suite list with many copies of a cipher suite. */
  70687. ExpectNotNull(ssl = wolfSSL_new(ctx));
  70688. msg.buffer = clientHello;
  70689. msg.length = (unsigned int)sizeof(clientHello);
  70690. wolfSSL_SetIOReadCtx(ssl, &msg);
  70691. /* Force server to have as many occurrences of same cipher suite as
  70692. * possible. */
  70693. if (ssl != NULL) {
  70694. Suites* suites = (Suites*)WOLFSSL_SUITES(ssl);
  70695. suites->suiteSz = WOLFSSL_MAX_SUITE_SZ;
  70696. for (i = 0; i < suites->suiteSz; i += 2) {
  70697. suites->suites[i + 0] = TLS13_BYTE;
  70698. suites->suites[i + 1] = TLS_AES_128_GCM_SHA256;
  70699. }
  70700. }
  70701. /* Test multiple occurrences of same cipher suite. */
  70702. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70703. wolfSSL_free(ssl);
  70704. ssl = NULL;
  70705. /* Set client order opposite to server order:
  70706. * TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-SHA384 */
  70707. clientHello[csOff + 0] = TLS13_BYTE;
  70708. clientHello[csOff + 1] = TLS_AES_128_GCM_SHA256;
  70709. clientHello[csOff + 2] = TLS13_BYTE;
  70710. clientHello[csOff + 3] = TLS_AES_256_GCM_SHA384;
  70711. /* Test server order negotiation. */
  70712. ExpectNotNull(ssl = wolfSSL_new(ctx));
  70713. msg.buffer = clientHello;
  70714. msg.length = (unsigned int)sizeof(clientHello);
  70715. wolfSSL_SetIOReadCtx(ssl, &msg);
  70716. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  70717. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  70718. /* Negotiate cipher suites in server order: TLS13-AES256-GCM-SHA384 */
  70719. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70720. /* Check refined order - server order. */
  70721. ExpectIntEQ(ssl->suites->suiteSz, 4);
  70722. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  70723. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_256_GCM_SHA384);
  70724. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  70725. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_128_GCM_SHA256);
  70726. wolfSSL_free(ssl);
  70727. ssl = NULL;
  70728. /* Test client order negotiation. */
  70729. ExpectNotNull(ssl = wolfSSL_new(ctx));
  70730. msg.buffer = clientHello;
  70731. msg.length = (unsigned int)sizeof(clientHello);
  70732. wolfSSL_SetIOReadCtx(ssl, &msg);
  70733. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  70734. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  70735. ExpectIntEQ(wolfSSL_UseClientSuites(ssl), 0);
  70736. /* Negotiate cipher suites in client order: TLS13-AES128-GCM-SHA256 */
  70737. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70738. /* Check refined order - client order. */
  70739. ExpectIntEQ(ssl->suites->suiteSz, 4);
  70740. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  70741. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_128_GCM_SHA256);
  70742. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  70743. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_256_GCM_SHA384);
  70744. wolfSSL_free(ssl);
  70745. ssl = NULL;
  70746. /* Check duplicate detection is working. */
  70747. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, dupCs), WOLFSSL_SUCCESS);
  70748. ExpectIntEQ(ctx->suites->suiteSz, 4);
  70749. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  70750. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_128_GCM_SHA256);
  70751. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  70752. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_256_GCM_SHA384);
  70753. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  70754. ExpectIntEQ(wolfSSL_CTX_set_cipher_list_bytes(ctx, dupCsBytes,
  70755. sizeof(dupCsBytes)), WOLFSSL_SUCCESS);
  70756. ExpectIntEQ(ctx->suites->suiteSz, 4);
  70757. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  70758. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_256_GCM_SHA384);
  70759. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  70760. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_128_GCM_SHA256);
  70761. #endif
  70762. wolfSSL_CTX_free(ctx);
  70763. #endif
  70764. return EXPECT_RESULT();
  70765. }
  70766. #endif
  70767. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  70768. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  70769. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  70770. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  70771. static int my_DhCallback(WOLFSSL* ssl, struct DhKey* key,
  70772. const unsigned char* priv, unsigned int privSz,
  70773. const unsigned char* pubKeyDer, unsigned int pubKeySz,
  70774. unsigned char* out, unsigned int* outlen,
  70775. void* ctx)
  70776. {
  70777. int result;
  70778. /* Test fail when context associated with WOLFSSL is NULL */
  70779. if (ctx == NULL) {
  70780. return -1;
  70781. }
  70782. (void)ssl;
  70783. /* return 0 on success */
  70784. PRIVATE_KEY_UNLOCK();
  70785. result = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
  70786. PRIVATE_KEY_LOCK();
  70787. return result;
  70788. }
  70789. static int test_dh_ctx_setup(WOLFSSL_CTX* ctx) {
  70790. EXPECT_DECLS;
  70791. wolfSSL_CTX_SetDhAgreeCb(ctx, my_DhCallback);
  70792. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  70793. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES128-SHA256"),
  70794. WOLFSSL_SUCCESS);
  70795. #endif
  70796. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  70797. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES256-SHA256"),
  70798. WOLFSSL_SUCCESS);
  70799. #endif
  70800. return EXPECT_RESULT();
  70801. }
  70802. static int test_dh_ssl_setup(WOLFSSL* ssl)
  70803. {
  70804. EXPECT_DECLS;
  70805. static int dh_test_ctx = 1;
  70806. int ret;
  70807. wolfSSL_SetDhAgreeCtx(ssl, &dh_test_ctx);
  70808. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), dh_test_ctx);
  70809. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  70810. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  70811. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70812. }
  70813. return EXPECT_RESULT();
  70814. }
  70815. static int test_dh_ssl_setup_fail(WOLFSSL* ssl)
  70816. {
  70817. EXPECT_DECLS;
  70818. int ret;
  70819. wolfSSL_SetDhAgreeCtx(ssl, NULL);
  70820. ExpectNull(wolfSSL_GetDhAgreeCtx(ssl));
  70821. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  70822. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  70823. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70824. }
  70825. return EXPECT_RESULT();
  70826. }
  70827. #endif
  70828. static int test_DhCallbacks(void)
  70829. {
  70830. EXPECT_DECLS;
  70831. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  70832. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  70833. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  70834. WOLFSSL_CTX *ctx = NULL;
  70835. WOLFSSL *ssl = NULL;
  70836. int test;
  70837. test_ssl_cbf func_cb_client;
  70838. test_ssl_cbf func_cb_server;
  70839. /* Test that DH callback APIs work. */
  70840. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  70841. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(NULL, "NONE"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70842. wolfSSL_CTX_SetDhAgreeCb(ctx, &my_DhCallback);
  70843. /* load client ca cert */
  70844. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  70845. WOLFSSL_SUCCESS);
  70846. /* test with NULL arguments */
  70847. wolfSSL_SetDhAgreeCtx(NULL, &test);
  70848. ExpectNull(wolfSSL_GetDhAgreeCtx(NULL));
  70849. /* test success case */
  70850. test = 1;
  70851. ExpectNotNull(ssl = wolfSSL_new(ctx));
  70852. wolfSSL_SetDhAgreeCtx(ssl, &test);
  70853. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), test);
  70854. wolfSSL_free(ssl);
  70855. wolfSSL_CTX_free(ctx);
  70856. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  70857. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  70858. /* set callbacks to use DH functions */
  70859. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  70860. func_cb_client.ssl_ready = &test_dh_ssl_setup;
  70861. func_cb_client.method = wolfTLSv1_2_client_method;
  70862. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  70863. func_cb_server.ssl_ready = &test_dh_ssl_setup;
  70864. func_cb_server.method = wolfTLSv1_2_server_method;
  70865. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  70866. &func_cb_server, NULL), TEST_SUCCESS);
  70867. /* Test fail */
  70868. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  70869. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  70870. /* set callbacks to use DH functions */
  70871. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  70872. func_cb_client.ssl_ready = &test_dh_ssl_setup_fail;
  70873. func_cb_client.method = wolfTLSv1_2_client_method;
  70874. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  70875. func_cb_server.ssl_ready = &test_dh_ssl_setup_fail;
  70876. func_cb_server.method = wolfTLSv1_2_server_method;
  70877. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  70878. &func_cb_server, NULL), TEST_FAIL);
  70879. #endif
  70880. return EXPECT_RESULT();
  70881. }
  70882. #endif /* HAVE_PK_CALLBACKS */
  70883. #ifdef HAVE_HASHDRBG
  70884. #ifdef TEST_RESEED_INTERVAL
  70885. static int test_wc_RNG_GenerateBlock_Reseed(void)
  70886. {
  70887. EXPECT_DECLS;
  70888. int i;
  70889. WC_RNG rng;
  70890. byte key[32];
  70891. XMEMSET(&rng, 0, sizeof(WC_RNG));
  70892. ExpectIntEQ(wc_InitRng(&rng), 0);
  70893. for (i = 0; i < WC_RESEED_INTERVAL + 10; i++) {
  70894. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  70895. }
  70896. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  70897. return EXPECT_RESULT();
  70898. }
  70899. #endif /* TEST_RESEED_INTERVAL */
  70900. static int test_wc_RNG_GenerateBlock(void)
  70901. {
  70902. EXPECT_DECLS;
  70903. int i;
  70904. WC_RNG rng;
  70905. byte key[32];
  70906. XMEMSET(&rng, 0, sizeof(WC_RNG));
  70907. ExpectIntEQ(wc_InitRng(&rng), 0);
  70908. for (i = 0; i < 10; i++) {
  70909. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  70910. }
  70911. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  70912. return EXPECT_RESULT();
  70913. }
  70914. #endif /* HAVE_HASHDRBG */
  70915. /*
  70916. * Testing get_rand_digit
  70917. */
  70918. static int test_get_rand_digit(void)
  70919. {
  70920. EXPECT_DECLS;
  70921. #if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
  70922. WC_RNG rng;
  70923. mp_digit d;
  70924. XMEMSET(&rng, 0, sizeof(WC_RNG));
  70925. ExpectIntEQ(wc_InitRng(&rng), 0);
  70926. ExpectIntEQ(get_rand_digit(&rng, &d), 0);
  70927. ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70928. ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70929. ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70930. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  70931. #endif
  70932. return EXPECT_RESULT();
  70933. } /* End test_get_rand_digit*/
  70934. /*
  70935. * Testing get_digit_count
  70936. */
  70937. static int test_get_digit_count(void)
  70938. {
  70939. EXPECT_DECLS;
  70940. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
  70941. mp_int a;
  70942. XMEMSET(&a, 0, sizeof(mp_int));
  70943. ExpectIntEQ(mp_init(&a), 0);
  70944. ExpectIntEQ(get_digit_count(NULL), 0);
  70945. ExpectIntEQ(get_digit_count(&a), 0);
  70946. mp_clear(&a);
  70947. #endif
  70948. return EXPECT_RESULT();
  70949. } /* End test_get_digit_count*/
  70950. /*
  70951. * Testing mp_cond_copy
  70952. */
  70953. static int test_mp_cond_copy(void)
  70954. {
  70955. EXPECT_DECLS;
  70956. #if (defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)) && \
  70957. defined(WOLFSSL_PUBLIC_MP)
  70958. mp_int a;
  70959. mp_int b;
  70960. int copy = 0;
  70961. XMEMSET(&a, 0, sizeof(mp_int));
  70962. XMEMSET(&b, 0, sizeof(mp_int));
  70963. ExpectIntEQ(mp_init(&a), MP_OKAY);
  70964. ExpectIntEQ(mp_init(&b), MP_OKAY);
  70965. ExpectIntEQ(mp_cond_copy(NULL, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70966. ExpectIntEQ(mp_cond_copy(NULL, copy, &b), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70967. ExpectIntEQ(mp_cond_copy(&a, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70968. ExpectIntEQ(mp_cond_copy(&a, copy, &b), 0);
  70969. mp_clear(&a);
  70970. mp_clear(&b);
  70971. #endif
  70972. return EXPECT_RESULT();
  70973. } /* End test_mp_cond_copy*/
  70974. /*
  70975. * Testing mp_rand
  70976. */
  70977. static int test_mp_rand(void)
  70978. {
  70979. EXPECT_DECLS;
  70980. #if defined(WC_RSA_BLINDING) && defined(WOLFSSL_PUBLIC_MP)
  70981. mp_int a;
  70982. WC_RNG rng;
  70983. int digits = 1;
  70984. XMEMSET(&a, 0, sizeof(mp_int));
  70985. XMEMSET(&rng, 0, sizeof(WC_RNG));
  70986. ExpectIntEQ(mp_init(&a), MP_OKAY);
  70987. ExpectIntEQ(wc_InitRng(&rng), 0);
  70988. ExpectIntEQ(mp_rand(&a, digits, NULL), WC_NO_ERR_TRACE(MISSING_RNG_E));
  70989. ExpectIntEQ(mp_rand(NULL, digits, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70990. ExpectIntEQ(mp_rand(&a, 0, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70991. ExpectIntEQ(mp_rand(&a, digits, &rng), 0);
  70992. mp_clear(&a);
  70993. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  70994. #endif
  70995. return EXPECT_RESULT();
  70996. } /* End test_mp_rand*/
  70997. /*
  70998. * Testing get_digit
  70999. */
  71000. static int test_get_digit(void)
  71001. {
  71002. EXPECT_DECLS;
  71003. #if defined(WOLFSSL_PUBLIC_MP)
  71004. mp_int a;
  71005. int n = 0;
  71006. XMEMSET(&a, 0, sizeof(mp_int));
  71007. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71008. ExpectIntEQ(get_digit(NULL, n), 0);
  71009. ExpectIntEQ(get_digit(&a, n), 0);
  71010. mp_clear(&a);
  71011. #endif
  71012. return EXPECT_RESULT();
  71013. } /* End test_get_digit*/
  71014. /*
  71015. * Testing wc_export_int
  71016. */
  71017. static int test_wc_export_int(void)
  71018. {
  71019. EXPECT_DECLS;
  71020. #if (defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)) && \
  71021. defined(WOLFSSL_PUBLIC_MP)
  71022. mp_int mp;
  71023. byte buf[32];
  71024. word32 keySz = (word32)sizeof(buf);
  71025. word32 len = (word32)sizeof(buf);
  71026. XMEMSET(&mp, 0, sizeof(mp_int));
  71027. ExpectIntEQ(mp_init(&mp), MP_OKAY);
  71028. ExpectIntEQ(mp_set(&mp, 1234), 0);
  71029. ExpectIntEQ(wc_export_int(NULL, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71030. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71031. len = sizeof(buf)-1;
  71032. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71033. WC_NO_ERR_TRACE(BUFFER_E));
  71034. len = sizeof(buf);
  71035. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN), 0);
  71036. len = 4; /* test input too small */
  71037. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), WC_NO_ERR_TRACE(BUFFER_E));
  71038. len = sizeof(buf);
  71039. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), 0);
  71040. /* hex version of 1234 is 04D2 and should be 4 digits + 1 null */
  71041. ExpectIntEQ(len, 5);
  71042. mp_clear(&mp);
  71043. #endif
  71044. return EXPECT_RESULT();
  71045. } /* End test_wc_export_int*/
  71046. static int test_wc_InitRngNonce(void)
  71047. {
  71048. EXPECT_DECLS;
  71049. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71050. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71051. HAVE_FIPS_VERSION >= 2))
  71052. WC_RNG rng;
  71053. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71054. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71055. word32 nonceSz = sizeof(nonce);
  71056. ExpectIntEQ(wc_InitRngNonce(&rng, nonce, nonceSz), 0);
  71057. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71058. #endif
  71059. return EXPECT_RESULT();
  71060. } /* End test_wc_InitRngNonce*/
  71061. /*
  71062. * Testing wc_InitRngNonce_ex
  71063. */
  71064. static int test_wc_InitRngNonce_ex(void)
  71065. {
  71066. EXPECT_DECLS;
  71067. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71068. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71069. HAVE_FIPS_VERSION >= 2))
  71070. WC_RNG rng;
  71071. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71072. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71073. word32 nonceSz = sizeof(nonce);
  71074. ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, testDevId),
  71075. 0);
  71076. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71077. #endif
  71078. return EXPECT_RESULT();
  71079. } /* End test_wc_InitRngNonce_ex */
  71080. static int test_wolfSSL_X509_CRL(void)
  71081. {
  71082. EXPECT_DECLS;
  71083. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL)
  71084. X509_CRL *crl = NULL;
  71085. char pem[][100] = {
  71086. "./certs/crl/crl.pem",
  71087. "./certs/crl/crl2.pem",
  71088. "./certs/crl/caEccCrl.pem",
  71089. "./certs/crl/eccCliCRL.pem",
  71090. "./certs/crl/eccSrvCRL.pem",
  71091. ""
  71092. };
  71093. #ifndef NO_BIO
  71094. BIO *bio = NULL;
  71095. #endif
  71096. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71097. char der[][100] = {
  71098. "./certs/crl/crl.der",
  71099. "./certs/crl/crl2.der",
  71100. ""};
  71101. #endif
  71102. XFILE fp = XBADFILE;
  71103. int i;
  71104. for (i = 0; pem[i][0] != '\0'; i++)
  71105. {
  71106. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71107. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71108. NULL, NULL));
  71109. ExpectNotNull(crl);
  71110. X509_CRL_free(crl);
  71111. if (fp != XBADFILE) {
  71112. XFCLOSE(fp);
  71113. fp = XBADFILE;
  71114. }
  71115. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71116. ExpectNotNull((X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)&crl, NULL,
  71117. NULL));
  71118. if (EXPECT_FAIL()) {
  71119. crl = NULL;
  71120. }
  71121. ExpectNotNull(crl);
  71122. X509_CRL_free(crl);
  71123. crl = NULL;
  71124. if (fp != XBADFILE) {
  71125. XFCLOSE(fp);
  71126. fp = XBADFILE;
  71127. }
  71128. }
  71129. #ifndef NO_BIO
  71130. for (i = 0; pem[i][0] != '\0'; i++)
  71131. {
  71132. ExpectNotNull(bio = BIO_new_file(pem[i], "rb"));
  71133. ExpectNotNull(crl = PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL));
  71134. X509_CRL_free(crl);
  71135. crl = NULL;
  71136. BIO_free(bio);
  71137. bio = NULL;
  71138. }
  71139. #endif
  71140. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71141. for (i = 0; der[i][0] != '\0'; i++) {
  71142. ExpectTrue((fp = XFOPEN(der[i], "rb")) != XBADFILE);
  71143. ExpectTrue((fp != XBADFILE));
  71144. ExpectNotNull(crl = (X509_CRL *)d2i_X509_CRL_fp((fp, X509_CRL **)NULL));
  71145. ExpectNotNull(crl);
  71146. X509_CRL_free(crl);
  71147. if (fp != XBADFILE) {
  71148. XFCLOSE(fp);
  71149. fp = XBADFILE;
  71150. }
  71151. fp = XFOPEN(der[i], "rb");
  71152. ExpectTrue((fp != XBADFILE));
  71153. ExpectNotNull((X509_CRL *)d2i_X509_CRL_fp(fp, (X509_CRL **)&crl));
  71154. if (EXPECT_FAIL()) {
  71155. crl = NULL;
  71156. }
  71157. ExpectNotNull(crl);
  71158. X509_CRL_free(crl);
  71159. crl = NULL;
  71160. if (fp != XBADFILE) {
  71161. XFCLOSE(fp);
  71162. fp = XBADFILE;
  71163. }
  71164. }
  71165. #endif
  71166. #endif
  71167. return EXPECT_RESULT();
  71168. }
  71169. static int test_wolfSSL_X509_load_crl_file(void)
  71170. {
  71171. EXPECT_DECLS;
  71172. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71173. !defined(NO_STDIO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71174. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  71175. int i;
  71176. char pem[][100] = {
  71177. "./certs/crl/crl.pem",
  71178. "./certs/crl/crl2.pem",
  71179. "./certs/crl/caEccCrl.pem",
  71180. "./certs/crl/eccCliCRL.pem",
  71181. "./certs/crl/eccSrvCRL.pem",
  71182. #ifdef WC_RSA_PSS
  71183. "./certs/crl/crl_rsapss.pem",
  71184. #endif
  71185. ""
  71186. };
  71187. char der[][100] = {
  71188. "./certs/crl/crl.der",
  71189. "./certs/crl/crl2.der",
  71190. ""
  71191. };
  71192. WOLFSSL_X509_STORE* store = NULL;
  71193. WOLFSSL_X509_LOOKUP* lookup = NULL;
  71194. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71195. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71196. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71197. X509_FILETYPE_PEM), 1);
  71198. #ifdef WC_RSA_PSS
  71199. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/rsapss/ca-rsapss.pem",
  71200. X509_FILETYPE_PEM), 1);
  71201. #endif
  71202. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71203. X509_FILETYPE_PEM), 1);
  71204. if (store) {
  71205. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71206. WOLFSSL_FILETYPE_PEM), 1);
  71207. /* since store hasn't yet known the revoked cert*/
  71208. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71209. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71210. }
  71211. for (i = 0; pem[i][0] != '\0'; i++) {
  71212. ExpectIntEQ(X509_load_crl_file(lookup, pem[i], WOLFSSL_FILETYPE_PEM),
  71213. 1);
  71214. }
  71215. if (store) {
  71216. /* since store knows crl list */
  71217. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71218. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71219. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71220. #ifdef WC_RSA_PSS
  71221. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71222. "certs/rsapss/server-rsapss-cert.pem", WOLFSSL_FILETYPE_PEM),
  71223. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71224. #endif
  71225. }
  71226. /* once feeing store */
  71227. X509_STORE_free(store);
  71228. store = NULL;
  71229. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71230. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71231. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71232. X509_FILETYPE_PEM), 1);
  71233. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71234. X509_FILETYPE_PEM), 1);
  71235. if (store) {
  71236. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71237. WOLFSSL_FILETYPE_PEM), 1);
  71238. /* since store hasn't yet known the revoked cert*/
  71239. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71240. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71241. }
  71242. for (i = 0; der[i][0] != '\0'; i++) {
  71243. ExpectIntEQ(X509_load_crl_file(lookup, der[i], WOLFSSL_FILETYPE_ASN1),
  71244. 1);
  71245. }
  71246. if (store) {
  71247. /* since store knows crl list */
  71248. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71249. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71250. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71251. }
  71252. /* test for incorrect parameter */
  71253. ExpectIntEQ(X509_load_crl_file(NULL, pem[0], 0), 0);
  71254. ExpectIntEQ(X509_load_crl_file(lookup, NULL, 0), 0);
  71255. ExpectIntEQ(X509_load_crl_file(NULL, NULL, 0), 0);
  71256. X509_STORE_free(store);
  71257. store = NULL;
  71258. #endif
  71259. return EXPECT_RESULT();
  71260. }
  71261. static int test_wolfSSL_i2d_X509(void)
  71262. {
  71263. EXPECT_DECLS;
  71264. #if defined(OPENSSL_EXTRA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  71265. const unsigned char* cert_buf = server_cert_der_2048;
  71266. unsigned char* out = NULL;
  71267. unsigned char* tmp = NULL;
  71268. X509* cert = NULL;
  71269. ExpectNotNull(d2i_X509(&cert, &cert_buf, sizeof_server_cert_der_2048));
  71270. /* Pointer should be advanced */
  71271. ExpectPtrGT(cert_buf, server_cert_der_2048);
  71272. ExpectIntGT(i2d_X509(cert, &out), 0);
  71273. ExpectNotNull(out);
  71274. tmp = out;
  71275. ExpectIntGT(i2d_X509(cert, &tmp), 0);
  71276. ExpectPtrGT(tmp, out);
  71277. if (out != NULL)
  71278. XFREE(out, NULL, DYNAMIC_TYPE_OPENSSL);
  71279. X509_free(cert);
  71280. #endif
  71281. return EXPECT_RESULT();
  71282. }
  71283. static int test_wolfSSL_d2i_X509_REQ(void)
  71284. {
  71285. EXPECT_DECLS;
  71286. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71287. (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)) && \
  71288. !defined(WOLFSSL_SP_MATH)
  71289. /* ./certs/csr.signed.der, ./certs/csr.ext.der, and ./certs/csr.attr.der
  71290. * were generated by libest
  71291. * ./certs/csr.attr.der contains sample attributes
  71292. * ./certs/csr.ext.der contains sample extensions */
  71293. const char* csrFile = "./certs/csr.signed.der";
  71294. const char* csrPopFile = "./certs/csr.attr.der";
  71295. const char* csrExtFile = "./certs/csr.ext.der";
  71296. /* ./certs/csr.dsa.pem is generated using
  71297. * openssl req -newkey dsa:certs/dsaparams.pem \
  71298. * -keyout certs/csr.dsa.key.pem -keyform PEM -out certs/csr.dsa.pem \
  71299. * -outform PEM
  71300. * with the passphrase "wolfSSL"
  71301. */
  71302. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71303. const char* csrDsaFile = "./certs/csr.dsa.pem";
  71304. XFILE f = XBADFILE;
  71305. #endif
  71306. BIO* bio = NULL;
  71307. X509* req = NULL;
  71308. EVP_PKEY *pub_key = NULL;
  71309. {
  71310. ExpectNotNull(bio = BIO_new_file(csrFile, "rb"));
  71311. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71312. /*
  71313. * Extract the public key from the CSR
  71314. */
  71315. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71316. /*
  71317. * Verify the signature in the CSR
  71318. */
  71319. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71320. X509_free(req);
  71321. req = NULL;
  71322. BIO_free(bio);
  71323. bio = NULL;
  71324. EVP_PKEY_free(pub_key);
  71325. pub_key = NULL;
  71326. }
  71327. {
  71328. #ifdef OPENSSL_ALL
  71329. X509_ATTRIBUTE* attr = NULL;
  71330. ASN1_TYPE *at = NULL;
  71331. #endif
  71332. ExpectNotNull(bio = BIO_new_file(csrPopFile, "rb"));
  71333. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71334. /*
  71335. * Extract the public key from the CSR
  71336. */
  71337. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71338. /*
  71339. * Verify the signature in the CSR
  71340. */
  71341. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71342. #ifdef OPENSSL_ALL
  71343. /*
  71344. * Obtain the challenge password from the CSR
  71345. */
  71346. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71347. -1), 1);
  71348. ExpectNotNull(attr = X509_REQ_get_attr(req, 1));
  71349. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71350. ExpectNotNull(at->value.asn1_string);
  71351. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string),
  71352. "2xIE+qqp/rhyTXP+");
  71353. ExpectIntEQ(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), -1);
  71354. #endif
  71355. X509_free(req);
  71356. req = NULL;
  71357. BIO_free(bio);
  71358. bio = NULL;
  71359. EVP_PKEY_free(pub_key);
  71360. pub_key = NULL;
  71361. }
  71362. {
  71363. #ifdef OPENSSL_ALL
  71364. X509_ATTRIBUTE* attr = NULL;
  71365. ASN1_TYPE *at = NULL;
  71366. STACK_OF(X509_EXTENSION) *exts = NULL;
  71367. #endif
  71368. ExpectNotNull(bio = BIO_new_file(csrExtFile, "rb"));
  71369. /* This CSR contains an Extension Request attribute so
  71370. * we test extension parsing in a CSR attribute here. */
  71371. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71372. /*
  71373. * Extract the public key from the CSR
  71374. */
  71375. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71376. /*
  71377. * Verify the signature in the CSR
  71378. */
  71379. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71380. #ifdef OPENSSL_ALL
  71381. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  71382. req));
  71383. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  71384. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  71385. /*
  71386. * Obtain the challenge password from the CSR
  71387. */
  71388. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71389. -1), 0);
  71390. ExpectNotNull(attr = X509_REQ_get_attr(req, 0));
  71391. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71392. ExpectNotNull(at->value.asn1_string);
  71393. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string), "IGCu/xNL4/0/wOgo");
  71394. ExpectIntGE(X509_get_ext_by_NID(req, NID_key_usage, -1), 0);
  71395. ExpectIntGE(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), 0);
  71396. #endif
  71397. X509_free(req);
  71398. req = NULL;
  71399. BIO_free(bio);
  71400. bio = NULL;
  71401. EVP_PKEY_free(pub_key);
  71402. pub_key = NULL;
  71403. }
  71404. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71405. {
  71406. ExpectNotNull(bio = BIO_new_file(csrDsaFile, "rb"));
  71407. ExpectNotNull(PEM_read_bio_X509_REQ(bio, &req, NULL, NULL));
  71408. /*
  71409. * Extract the public key from the CSR
  71410. */
  71411. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71412. /*
  71413. * Verify the signature in the CSR
  71414. */
  71415. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71416. X509_free(req);
  71417. req = NULL;
  71418. BIO_free(bio);
  71419. /* Run the same test, but with a file pointer instead of a BIO.
  71420. * (PEM_read_X509_REQ)*/
  71421. ExpectTrue((f = XFOPEN(csrDsaFile, "rb")) != XBADFILE);
  71422. ExpectNotNull(PEM_read_X509_REQ(f, &req, NULL, NULL));
  71423. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71424. X509_free(req);
  71425. EVP_PKEY_free(pub_key);
  71426. }
  71427. #endif /* !NO_DSA && !HAVE_SELFTEST */
  71428. #endif /* WOLFSSL_CERT_REQ && (OPENSSL_ALL || OPENSSL_EXTRA) */
  71429. return EXPECT_RESULT();
  71430. }
  71431. static int test_wolfSSL_PEM_read_X509(void)
  71432. {
  71433. EXPECT_DECLS;
  71434. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71435. !defined(NO_RSA)
  71436. X509 *x509 = NULL;
  71437. XFILE fp = XBADFILE;
  71438. ExpectTrue((fp = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  71439. ExpectNotNull(x509 = (X509 *)PEM_read_X509(fp, (X509 **)NULL, NULL, NULL));
  71440. X509_free(x509);
  71441. if (fp != XBADFILE)
  71442. XFCLOSE(fp);
  71443. #endif
  71444. return EXPECT_RESULT();
  71445. }
  71446. static int test_wolfSSL_PEM_read(void)
  71447. {
  71448. EXPECT_DECLS;
  71449. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  71450. const char* filename = "./certs/server-keyEnc.pem";
  71451. XFILE fp = XBADFILE;
  71452. char* name = NULL;
  71453. char* header = NULL;
  71454. byte* data = NULL;
  71455. long len;
  71456. EVP_CIPHER_INFO cipher;
  71457. WOLFSSL_BIO* bio = NULL;
  71458. byte* fileData = NULL;
  71459. size_t fileDataSz = 0;
  71460. byte* out;
  71461. ExpectNotNull(bio = BIO_new_file(filename, "rb"));
  71462. ExpectIntEQ(PEM_read_bio(bio, NULL, &header, &data, &len), 0);
  71463. ExpectIntEQ(PEM_read_bio(bio, &name, NULL, &data, &len), 0);
  71464. ExpectIntEQ(PEM_read_bio(bio, &name, &header, NULL, &len), 0);
  71465. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, NULL), 0);
  71466. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  71467. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71468. ExpectIntGT(XSTRLEN(header), 0);
  71469. ExpectIntGT(len, 0);
  71470. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71471. name = NULL;
  71472. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71473. header = NULL;
  71474. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71475. data = NULL;
  71476. BIO_free(bio);
  71477. bio = NULL;
  71478. ExpectTrue((fp = XFOPEN(filename, "rb")) != XBADFILE);
  71479. /* Fail cases. */
  71480. ExpectIntEQ(PEM_read(fp, NULL, &header, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71481. ExpectIntEQ(PEM_read(fp, &name, NULL, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71482. ExpectIntEQ(PEM_read(fp, &name, &header, NULL, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71483. ExpectIntEQ(PEM_read(fp, &name, &header, &data, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71484. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  71485. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71486. ExpectIntGT(XSTRLEN(header), 0);
  71487. ExpectIntGT(len, 0);
  71488. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  71489. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  71490. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  71491. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  71492. DYNAMIC_TYPE_TMP_BUFFER));
  71493. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  71494. if (fp != XBADFILE) {
  71495. XFCLOSE(fp);
  71496. fp = XBADFILE;
  71497. }
  71498. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  71499. /* Fail cases. */
  71500. ExpectIntEQ(PEM_write_bio(NULL, name, header, data, len), 0);
  71501. ExpectIntEQ(PEM_write_bio(bio, NULL, header, data, len), 0);
  71502. ExpectIntEQ(PEM_write_bio(bio, name, NULL, data, len), 0);
  71503. ExpectIntEQ(PEM_write_bio(bio, name, header, NULL, len), 0);
  71504. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  71505. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  71506. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  71507. /* Fail cases. */
  71508. ExpectIntEQ(PEM_write(XBADFILE, name, header, data, len), 0);
  71509. ExpectIntEQ(PEM_write(stderr, NULL, header, data, len), 0);
  71510. ExpectIntEQ(PEM_write(stderr, name, NULL, data, len), 0);
  71511. ExpectIntEQ(PEM_write(stderr, name, header, NULL, len), 0);
  71512. /* Pass case */
  71513. ExpectIntEQ(PEM_write(stderr, name, header, data, len), fileDataSz);
  71514. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71515. name = NULL;
  71516. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71517. header = NULL;
  71518. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71519. data = NULL;
  71520. /* Read out of a fixed buffer BIO - forces malloc in PEM_read_bio. */
  71521. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  71522. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71523. ExpectIntGT(XSTRLEN(header), 0);
  71524. ExpectIntGT(len, 0);
  71525. /* Fail cases. */
  71526. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(NULL, &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71527. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71528. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO((char*)"", &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71529. #ifndef NO_DES3
  71530. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, &cipher), WOLFSSL_SUCCESS);
  71531. #endif
  71532. /* Fail cases. */
  71533. ExpectIntEQ(PEM_do_header(NULL, data, &len, PasswordCallBack,
  71534. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71535. ExpectIntEQ(PEM_do_header(&cipher, NULL, &len, PasswordCallBack,
  71536. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71537. ExpectIntEQ(PEM_do_header(&cipher, data, NULL, PasswordCallBack,
  71538. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71539. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NULL,
  71540. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71541. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NoPasswordCallBack,
  71542. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71543. #if !defined(NO_DES3) && !defined(NO_MD5)
  71544. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  71545. (void*)"yassl123"), WOLFSSL_SUCCESS);
  71546. #else
  71547. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  71548. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71549. #endif
  71550. BIO_free(bio);
  71551. bio = NULL;
  71552. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71553. fileData = NULL;
  71554. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71555. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71556. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71557. name = NULL;
  71558. header = NULL;
  71559. data = NULL;
  71560. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  71561. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  71562. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71563. ExpectIntEQ(XSTRLEN(header), 0);
  71564. ExpectIntGT(len, 0);
  71565. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  71566. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  71567. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  71568. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  71569. DYNAMIC_TYPE_TMP_BUFFER));
  71570. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  71571. if (fp != XBADFILE)
  71572. XFCLOSE(fp);
  71573. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  71574. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  71575. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  71576. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  71577. BIO_free(bio);
  71578. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71579. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71580. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71581. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71582. #endif
  71583. return EXPECT_RESULT();
  71584. }
  71585. static int test_wolfssl_EVP_aes_gcm_AAD_2_parts(void)
  71586. {
  71587. EXPECT_DECLS;
  71588. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  71589. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  71590. const byte iv[12] = { 0 };
  71591. const byte key[16] = { 0 };
  71592. const byte cleartext[16] = { 0 };
  71593. const byte aad[] = {
  71594. 0x01, 0x10, 0x00, 0x2a, 0x08, 0x00, 0x04, 0x00,
  71595. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  71596. 0x00, 0x00, 0xdc, 0x4d, 0xad, 0x6b, 0x06, 0x93,
  71597. 0x4f
  71598. };
  71599. byte out1Part[16];
  71600. byte outTag1Part[16];
  71601. byte out2Part[16];
  71602. byte outTag2Part[16];
  71603. byte decryptBuf[16];
  71604. int len = 0;
  71605. int tlen;
  71606. EVP_CIPHER_CTX* ctx = NULL;
  71607. /* ENCRYPT */
  71608. /* Send AAD and data in 1 part */
  71609. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71610. tlen = 0;
  71611. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71612. 1);
  71613. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71614. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  71615. ExpectIntEQ(EVP_EncryptUpdate(ctx, out1Part, &len, cleartext,
  71616. sizeof(cleartext)), 1);
  71617. tlen += len;
  71618. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out1Part, &len), 1);
  71619. tlen += len;
  71620. ExpectIntEQ(tlen, sizeof(cleartext));
  71621. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  71622. outTag1Part), 1);
  71623. EVP_CIPHER_CTX_free(ctx);
  71624. ctx = NULL;
  71625. /* DECRYPT */
  71626. /* Send AAD and data in 1 part */
  71627. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71628. tlen = 0;
  71629. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71630. 1);
  71631. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71632. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  71633. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part,
  71634. sizeof(cleartext)), 1);
  71635. tlen += len;
  71636. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  71637. outTag1Part), 1);
  71638. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf, &len), 1);
  71639. tlen += len;
  71640. ExpectIntEQ(tlen, sizeof(cleartext));
  71641. EVP_CIPHER_CTX_free(ctx);
  71642. ctx = NULL;
  71643. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  71644. /* ENCRYPT */
  71645. /* Send AAD and data in 2 parts */
  71646. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71647. tlen = 0;
  71648. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71649. 1);
  71650. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71651. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, 1), 1);
  71652. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  71653. 1);
  71654. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part, &len, cleartext, 1), 1);
  71655. tlen += len;
  71656. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part + tlen, &len, cleartext + 1,
  71657. sizeof(cleartext) - 1), 1);
  71658. tlen += len;
  71659. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out2Part + tlen, &len), 1);
  71660. tlen += len;
  71661. ExpectIntEQ(tlen, sizeof(cleartext));
  71662. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  71663. outTag2Part), 1);
  71664. ExpectIntEQ(XMEMCMP(out1Part, out2Part, sizeof(out1Part)), 0);
  71665. ExpectIntEQ(XMEMCMP(outTag1Part, outTag2Part, sizeof(outTag1Part)), 0);
  71666. EVP_CIPHER_CTX_free(ctx);
  71667. ctx = NULL;
  71668. /* DECRYPT */
  71669. /* Send AAD and data in 2 parts */
  71670. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71671. tlen = 0;
  71672. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71673. 1);
  71674. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71675. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, 1), 1);
  71676. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  71677. 1);
  71678. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part, 1), 1);
  71679. tlen += len;
  71680. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf + tlen, &len, out1Part + 1,
  71681. sizeof(cleartext) - 1), 1);
  71682. tlen += len;
  71683. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  71684. outTag1Part), 1);
  71685. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf + tlen, &len), 1);
  71686. tlen += len;
  71687. ExpectIntEQ(tlen, sizeof(cleartext));
  71688. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  71689. /* Test AAD reuse */
  71690. EVP_CIPHER_CTX_free(ctx);
  71691. #endif
  71692. return EXPECT_RESULT();
  71693. }
  71694. static int test_wolfssl_EVP_aes_gcm_zeroLen(void)
  71695. {
  71696. EXPECT_DECLS;
  71697. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  71698. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  71699. /* Zero length plain text */
  71700. byte key[] = {
  71701. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71702. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71703. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71704. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  71705. }; /* align */
  71706. byte iv[] = {
  71707. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  71708. }; /* align */
  71709. byte plaintxt[1];
  71710. int ivSz = 12;
  71711. int plaintxtSz = 0;
  71712. unsigned char tag[16];
  71713. unsigned char tag_kat[] = {
  71714. 0x53,0x0f,0x8a,0xfb,0xc7,0x45,0x36,0xb9,
  71715. 0xa9,0x63,0xb4,0xf1,0xc4,0xcb,0x73,0x8b
  71716. };
  71717. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  71718. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  71719. int ciphertxtSz = 0;
  71720. int decryptedtxtSz = 0;
  71721. int len = 0;
  71722. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  71723. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  71724. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_gcm(), NULL, key, iv));
  71725. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71726. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  71727. plaintxtSz));
  71728. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  71729. ciphertxtSz += len;
  71730. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  71731. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  71732. ExpectIntEQ(0, ciphertxtSz);
  71733. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  71734. EVP_CIPHER_CTX_init(de);
  71735. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_gcm(), NULL, key, iv));
  71736. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71737. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  71738. decryptedtxtSz = len;
  71739. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  71740. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  71741. decryptedtxtSz += len;
  71742. ExpectIntEQ(0, decryptedtxtSz);
  71743. EVP_CIPHER_CTX_free(en);
  71744. EVP_CIPHER_CTX_free(de);
  71745. #endif
  71746. return EXPECT_RESULT();
  71747. }
  71748. static int test_wolfssl_EVP_aes_gcm(void)
  71749. {
  71750. EXPECT_DECLS;
  71751. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  71752. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  71753. /* A 256 bit key, AES_128 will use the first 128 bit*/
  71754. byte *key = (byte*)"01234567890123456789012345678901";
  71755. /* A 128 bit IV */
  71756. byte *iv = (byte*)"0123456789012345";
  71757. int ivSz = AES_BLOCK_SIZE;
  71758. /* Message to be encrypted */
  71759. byte *plaintxt = (byte*)"for things to change you have to change";
  71760. /* Additional non-confidential data */
  71761. byte *aad = (byte*)"Don't spend major time on minor things.";
  71762. unsigned char tag[AES_BLOCK_SIZE] = {0};
  71763. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  71764. int aadSz = (int)XSTRLEN((char*)aad);
  71765. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  71766. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  71767. int ciphertxtSz = 0;
  71768. int decryptedtxtSz = 0;
  71769. int len = 0;
  71770. int i = 0;
  71771. EVP_CIPHER_CTX en[2];
  71772. EVP_CIPHER_CTX de[2];
  71773. for (i = 0; i < 2; i++) {
  71774. EVP_CIPHER_CTX_init(&en[i]);
  71775. if (i == 0) {
  71776. /* Default uses 96-bits IV length */
  71777. #ifdef WOLFSSL_AES_128
  71778. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  71779. key, iv));
  71780. #elif defined(WOLFSSL_AES_192)
  71781. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  71782. key, iv));
  71783. #elif defined(WOLFSSL_AES_256)
  71784. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  71785. key, iv));
  71786. #endif
  71787. }
  71788. else {
  71789. #ifdef WOLFSSL_AES_128
  71790. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  71791. NULL, NULL));
  71792. #elif defined(WOLFSSL_AES_192)
  71793. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  71794. NULL, NULL));
  71795. #elif defined(WOLFSSL_AES_256)
  71796. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  71797. NULL, NULL));
  71798. #endif
  71799. /* non-default must to set the IV length first */
  71800. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  71801. ivSz, NULL));
  71802. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  71803. }
  71804. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  71805. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  71806. plaintxtSz));
  71807. ciphertxtSz = len;
  71808. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  71809. ciphertxtSz += len;
  71810. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  71811. AES_BLOCK_SIZE, tag));
  71812. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  71813. EVP_CIPHER_CTX_init(&de[i]);
  71814. if (i == 0) {
  71815. /* Default uses 96-bits IV length */
  71816. #ifdef WOLFSSL_AES_128
  71817. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  71818. key, iv));
  71819. #elif defined(WOLFSSL_AES_192)
  71820. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  71821. key, iv));
  71822. #elif defined(WOLFSSL_AES_256)
  71823. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  71824. key, iv));
  71825. #endif
  71826. }
  71827. else {
  71828. #ifdef WOLFSSL_AES_128
  71829. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  71830. NULL, NULL));
  71831. #elif defined(WOLFSSL_AES_192)
  71832. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  71833. NULL, NULL));
  71834. #elif defined(WOLFSSL_AES_256)
  71835. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  71836. NULL, NULL));
  71837. #endif
  71838. /* non-default must to set the IV length first */
  71839. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  71840. ivSz, NULL));
  71841. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  71842. }
  71843. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  71844. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  71845. ciphertxtSz));
  71846. decryptedtxtSz = len;
  71847. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  71848. AES_BLOCK_SIZE, tag));
  71849. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  71850. decryptedtxtSz += len;
  71851. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  71852. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  71853. /* modify tag*/
  71854. if (i == 0) {
  71855. /* Default uses 96-bits IV length */
  71856. #ifdef WOLFSSL_AES_128
  71857. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  71858. key, iv));
  71859. #elif defined(WOLFSSL_AES_192)
  71860. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  71861. key, iv));
  71862. #elif defined(WOLFSSL_AES_256)
  71863. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  71864. key, iv));
  71865. #endif
  71866. }
  71867. else {
  71868. #ifdef WOLFSSL_AES_128
  71869. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  71870. NULL, NULL));
  71871. #elif defined(WOLFSSL_AES_192)
  71872. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  71873. NULL, NULL));
  71874. #elif defined(WOLFSSL_AES_256)
  71875. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  71876. NULL, NULL));
  71877. #endif
  71878. /* non-default must to set the IV length first */
  71879. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  71880. ivSz, NULL));
  71881. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  71882. }
  71883. tag[AES_BLOCK_SIZE-1]+=0xBB;
  71884. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  71885. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  71886. AES_BLOCK_SIZE, tag));
  71887. /* fail due to wrong tag */
  71888. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  71889. ciphertxtSz));
  71890. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  71891. ExpectIntEQ(0, len);
  71892. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  71893. }
  71894. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  71895. return EXPECT_RESULT();
  71896. }
  71897. static int test_wolfssl_EVP_aria_gcm(void)
  71898. {
  71899. int res = TEST_SKIPPED;
  71900. #if defined(OPENSSL_EXTRA) && defined(HAVE_ARIA) && \
  71901. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  71902. /* A 256 bit key, AES_128 will use the first 128 bit*/
  71903. byte *key = (byte*)"01234567890123456789012345678901";
  71904. /* A 128 bit IV */
  71905. byte *iv = (byte*)"0123456789012345";
  71906. int ivSz = ARIA_BLOCK_SIZE;
  71907. /* Message to be encrypted */
  71908. const int plaintxtSz = 40;
  71909. byte plaintxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  71910. XMEMCPY(plaintxt,"for things to change you have to change",plaintxtSz);
  71911. /* Additional non-confidential data */
  71912. byte *aad = (byte*)"Don't spend major time on minor things.";
  71913. unsigned char tag[ARIA_BLOCK_SIZE] = {0};
  71914. int aadSz = (int)XSTRLEN((char*)aad);
  71915. byte ciphertxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  71916. byte decryptedtxt[plaintxtSz];
  71917. int ciphertxtSz = 0;
  71918. int decryptedtxtSz = 0;
  71919. int len = 0;
  71920. int i = 0;
  71921. #define TEST_ARIA_GCM_COUNT 6
  71922. EVP_CIPHER_CTX en[TEST_ARIA_GCM_COUNT];
  71923. EVP_CIPHER_CTX de[TEST_ARIA_GCM_COUNT];
  71924. for (i = 0; i < TEST_ARIA_GCM_COUNT; i++) {
  71925. EVP_CIPHER_CTX_init(&en[i]);
  71926. switch (i) {
  71927. case 0:
  71928. /* Default uses 96-bits IV length */
  71929. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, key, iv));
  71930. break;
  71931. case 1:
  71932. /* Default uses 96-bits IV length */
  71933. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, key, iv));
  71934. break;
  71935. case 2:
  71936. /* Default uses 96-bits IV length */
  71937. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, key, iv));
  71938. break;
  71939. case 3:
  71940. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  71941. /* non-default must to set the IV length first */
  71942. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71943. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  71944. break;
  71945. case 4:
  71946. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  71947. /* non-default must to set the IV length first */
  71948. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71949. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  71950. break;
  71951. case 5:
  71952. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  71953. /* non-default must to set the IV length first */
  71954. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71955. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  71956. break;
  71957. }
  71958. XMEMSET(ciphertxt,0,sizeof(ciphertxt));
  71959. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  71960. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt, plaintxtSz));
  71961. ciphertxtSz = len;
  71962. AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  71963. AssertIntNE(0, XMEMCMP(plaintxt, ciphertxt, plaintxtSz));
  71964. ciphertxtSz += len;
  71965. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG, ARIA_BLOCK_SIZE, tag));
  71966. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  71967. EVP_CIPHER_CTX_init(&de[i]);
  71968. switch (i) {
  71969. case 0:
  71970. /* Default uses 96-bits IV length */
  71971. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, key, iv));
  71972. break;
  71973. case 1:
  71974. /* Default uses 96-bits IV length */
  71975. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, key, iv));
  71976. break;
  71977. case 2:
  71978. /* Default uses 96-bits IV length */
  71979. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, key, iv));
  71980. break;
  71981. case 3:
  71982. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  71983. /* non-default must to set the IV length first */
  71984. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71985. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  71986. break;
  71987. case 4:
  71988. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  71989. /* non-default must to set the IV length first */
  71990. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71991. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  71992. break;
  71993. case 5:
  71994. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  71995. /* non-default must to set the IV length first */
  71996. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71997. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  71998. break;
  71999. }
  72000. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72001. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72002. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72003. decryptedtxtSz = len;
  72004. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72005. AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72006. decryptedtxtSz += len;
  72007. AssertIntEQ(plaintxtSz, decryptedtxtSz);
  72008. AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72009. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72010. /* modify tag*/
  72011. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72012. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72013. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72014. /* fail due to wrong tag */
  72015. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72016. AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72017. AssertIntEQ(0, len);
  72018. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72019. }
  72020. res = TEST_RES_CHECK(1);
  72021. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  72022. return res;
  72023. }
  72024. static int test_wolfssl_EVP_aes_ccm_zeroLen(void)
  72025. {
  72026. EXPECT_DECLS;
  72027. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72028. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72029. /* Zero length plain text */
  72030. byte key[] = {
  72031. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72032. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72033. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72034. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72035. }; /* align */
  72036. byte iv[] = {
  72037. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72038. }; /* align */
  72039. byte plaintxt[1];
  72040. int ivSz = 12;
  72041. int plaintxtSz = 0;
  72042. unsigned char tag[16];
  72043. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72044. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72045. int ciphertxtSz = 0;
  72046. int decryptedtxtSz = 0;
  72047. int len = 0;
  72048. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72049. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72050. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_ccm(), NULL, key, iv));
  72051. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72052. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72053. plaintxtSz));
  72054. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72055. ciphertxtSz += len;
  72056. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  72057. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72058. ExpectIntEQ(0, ciphertxtSz);
  72059. EVP_CIPHER_CTX_init(de);
  72060. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_ccm(), NULL, key, iv));
  72061. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72062. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72063. decryptedtxtSz = len;
  72064. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  72065. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72066. decryptedtxtSz += len;
  72067. ExpectIntEQ(0, decryptedtxtSz);
  72068. EVP_CIPHER_CTX_free(en);
  72069. EVP_CIPHER_CTX_free(de);
  72070. #endif
  72071. return EXPECT_RESULT();
  72072. }
  72073. static int test_wolfssl_EVP_aes_ccm(void)
  72074. {
  72075. EXPECT_DECLS;
  72076. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72077. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72078. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72079. byte *key = (byte*)"01234567890123456789012345678901";
  72080. /* A 128 bit IV */
  72081. byte *iv = (byte*)"0123456789012";
  72082. int ivSz = (int)XSTRLEN((char*)iv);
  72083. /* Message to be encrypted */
  72084. byte *plaintxt = (byte*)"for things to change you have to change";
  72085. /* Additional non-confidential data */
  72086. byte *aad = (byte*)"Don't spend major time on minor things.";
  72087. unsigned char tag[AES_BLOCK_SIZE] = {0};
  72088. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72089. int aadSz = (int)XSTRLEN((char*)aad);
  72090. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72091. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72092. int ciphertxtSz = 0;
  72093. int decryptedtxtSz = 0;
  72094. int len = 0;
  72095. int i = 0;
  72096. int ret;
  72097. EVP_CIPHER_CTX en[2];
  72098. EVP_CIPHER_CTX de[2];
  72099. for (i = 0; i < 2; i++) {
  72100. EVP_CIPHER_CTX_init(&en[i]);
  72101. if (i == 0) {
  72102. /* Default uses 96-bits IV length */
  72103. #ifdef WOLFSSL_AES_128
  72104. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72105. key, iv));
  72106. #elif defined(WOLFSSL_AES_192)
  72107. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72108. key, iv));
  72109. #elif defined(WOLFSSL_AES_256)
  72110. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72111. key, iv));
  72112. #endif
  72113. }
  72114. else {
  72115. #ifdef WOLFSSL_AES_128
  72116. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72117. NULL, NULL));
  72118. #elif defined(WOLFSSL_AES_192)
  72119. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72120. NULL, NULL));
  72121. #elif defined(WOLFSSL_AES_256)
  72122. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72123. NULL, NULL));
  72124. #endif
  72125. /* non-default must to set the IV length first */
  72126. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  72127. ivSz, NULL));
  72128. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72129. }
  72130. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72131. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72132. plaintxtSz));
  72133. ciphertxtSz = len;
  72134. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72135. ciphertxtSz += len;
  72136. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  72137. AES_BLOCK_SIZE, tag));
  72138. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]);
  72139. ExpectIntEQ(ret, 1);
  72140. EVP_CIPHER_CTX_init(&de[i]);
  72141. if (i == 0) {
  72142. /* Default uses 96-bits IV length */
  72143. #ifdef WOLFSSL_AES_128
  72144. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72145. key, iv));
  72146. #elif defined(WOLFSSL_AES_192)
  72147. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72148. key, iv));
  72149. #elif defined(WOLFSSL_AES_256)
  72150. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72151. key, iv));
  72152. #endif
  72153. }
  72154. else {
  72155. #ifdef WOLFSSL_AES_128
  72156. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72157. NULL, NULL));
  72158. #elif defined(WOLFSSL_AES_192)
  72159. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72160. NULL, NULL));
  72161. #elif defined(WOLFSSL_AES_256)
  72162. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72163. NULL, NULL));
  72164. #endif
  72165. /* non-default must to set the IV length first */
  72166. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  72167. ivSz, NULL));
  72168. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72169. }
  72170. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72171. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72172. ciphertxtSz));
  72173. decryptedtxtSz = len;
  72174. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72175. AES_BLOCK_SIZE, tag));
  72176. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72177. decryptedtxtSz += len;
  72178. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72179. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72180. /* modify tag*/
  72181. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72182. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72183. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72184. AES_BLOCK_SIZE, tag));
  72185. /* fail due to wrong tag */
  72186. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72187. ciphertxtSz));
  72188. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72189. ExpectIntEQ(0, len);
  72190. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]);
  72191. ExpectIntEQ(ret, 1);
  72192. }
  72193. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESCCM */
  72194. return EXPECT_RESULT();
  72195. }
  72196. static int test_wolfssl_EVP_chacha20_poly1305(void)
  72197. {
  72198. EXPECT_DECLS;
  72199. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  72200. byte key[CHACHA20_POLY1305_AEAD_KEYSIZE];
  72201. byte iv [CHACHA20_POLY1305_AEAD_IV_SIZE];
  72202. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72203. byte aad[] = {0xAA, 0XBB, 0xCC, 0xDD, 0xEE, 0xFF};
  72204. byte cipherText[sizeof(plainText)];
  72205. byte decryptedText[sizeof(plainText)];
  72206. byte tag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  72207. EVP_CIPHER_CTX* ctx = NULL;
  72208. int outSz;
  72209. XMEMSET(key, 0, sizeof(key));
  72210. XMEMSET(iv, 0, sizeof(iv));
  72211. /* Encrypt. */
  72212. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72213. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72214. NULL), WOLFSSL_SUCCESS);
  72215. /* Invalid IV length. */
  72216. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72217. CHACHA20_POLY1305_AEAD_IV_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72218. /* Valid IV length. */
  72219. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72220. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72221. /* Invalid tag length. */
  72222. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72223. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72224. /* Valid tag length. */
  72225. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72226. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, NULL), WOLFSSL_SUCCESS);
  72227. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72228. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72229. WOLFSSL_SUCCESS);
  72230. ExpectIntEQ(outSz, sizeof(aad));
  72231. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72232. sizeof(plainText)), WOLFSSL_SUCCESS);
  72233. ExpectIntEQ(outSz, sizeof(plainText));
  72234. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72235. ExpectIntEQ(outSz, 0);
  72236. /* Invalid tag length. */
  72237. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72238. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, tag), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72239. /* Valid tag length. */
  72240. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72241. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72242. EVP_CIPHER_CTX_free(ctx);
  72243. ctx = NULL;
  72244. /* Decrypt. */
  72245. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72246. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72247. NULL), WOLFSSL_SUCCESS);
  72248. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72249. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72250. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72251. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72252. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72253. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72254. WOLFSSL_SUCCESS);
  72255. ExpectIntEQ(outSz, sizeof(aad));
  72256. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72257. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72258. ExpectIntEQ(outSz, sizeof(cipherText));
  72259. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72260. WOLFSSL_SUCCESS);
  72261. ExpectIntEQ(outSz, 0);
  72262. EVP_CIPHER_CTX_free(ctx);
  72263. ctx = NULL;
  72264. /* Test partial Inits. CipherInit() allow setting of key and iv
  72265. * in separate calls. */
  72266. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72267. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20_poly1305(),
  72268. key, NULL, 1), WOLFSSL_SUCCESS);
  72269. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72270. WOLFSSL_SUCCESS);
  72271. ExpectIntEQ(wolfSSL_EVP_CipherUpdate(ctx, NULL, &outSz,
  72272. aad, sizeof(aad)), WOLFSSL_SUCCESS);
  72273. ExpectIntEQ(outSz, sizeof(aad));
  72274. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72275. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72276. ExpectIntEQ(outSz, sizeof(cipherText));
  72277. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72278. WOLFSSL_SUCCESS);
  72279. ExpectIntEQ(outSz, 0);
  72280. EVP_CIPHER_CTX_free(ctx);
  72281. #endif
  72282. return EXPECT_RESULT();
  72283. }
  72284. static int test_wolfssl_EVP_chacha20(void)
  72285. {
  72286. EXPECT_DECLS;
  72287. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA)
  72288. byte key[CHACHA_MAX_KEY_SZ];
  72289. byte iv [WOLFSSL_EVP_CHACHA_IV_BYTES];
  72290. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72291. byte cipherText[sizeof(plainText)];
  72292. byte decryptedText[sizeof(plainText)];
  72293. EVP_CIPHER_CTX* ctx = NULL;
  72294. int outSz;
  72295. XMEMSET(key, 0, sizeof(key));
  72296. XMEMSET(iv, 0, sizeof(iv));
  72297. /* Encrypt. */
  72298. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72299. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72300. NULL), WOLFSSL_SUCCESS);
  72301. /* Any tag length must fail - not an AEAD cipher. */
  72302. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72303. 16, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72304. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72305. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72306. sizeof(plainText)), WOLFSSL_SUCCESS);
  72307. ExpectIntEQ(outSz, sizeof(plainText));
  72308. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72309. ExpectIntEQ(outSz, 0);
  72310. EVP_CIPHER_CTX_free(ctx);
  72311. ctx = NULL;
  72312. /* Decrypt. */
  72313. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72314. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72315. NULL), WOLFSSL_SUCCESS);
  72316. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72317. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72318. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72319. ExpectIntEQ(outSz, sizeof(cipherText));
  72320. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72321. WOLFSSL_SUCCESS);
  72322. ExpectIntEQ(outSz, 0);
  72323. EVP_CIPHER_CTX_free(ctx);
  72324. ctx = NULL;
  72325. /* Test partial Inits. CipherInit() allow setting of key and iv
  72326. * in separate calls. */
  72327. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72328. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20(),
  72329. key, NULL, 1), WOLFSSL_SUCCESS);
  72330. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72331. WOLFSSL_SUCCESS);
  72332. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72333. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72334. ExpectIntEQ(outSz, sizeof(cipherText));
  72335. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72336. WOLFSSL_SUCCESS);
  72337. ExpectIntEQ(outSz, 0);
  72338. EVP_CIPHER_CTX_free(ctx);
  72339. #endif
  72340. return EXPECT_RESULT();
  72341. }
  72342. static int test_wolfssl_EVP_sm4_ecb(void)
  72343. {
  72344. int res = TEST_SKIPPED;
  72345. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_ECB)
  72346. EXPECT_DECLS;
  72347. byte key[SM4_KEY_SIZE];
  72348. byte plainText[SM4_BLOCK_SIZE] = {
  72349. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72350. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72351. };
  72352. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72353. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72354. EVP_CIPHER_CTX* ctx;
  72355. int outSz;
  72356. XMEMSET(key, 0, sizeof(key));
  72357. /* Encrypt. */
  72358. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72359. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72360. WOLFSSL_SUCCESS);
  72361. /* Any tag length must fail - not an AEAD cipher. */
  72362. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72363. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72364. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL),
  72365. WOLFSSL_SUCCESS);
  72366. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72367. sizeof(plainText)), WOLFSSL_SUCCESS);
  72368. ExpectIntEQ(outSz, sizeof(plainText));
  72369. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72370. WOLFSSL_SUCCESS);
  72371. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72372. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72373. EVP_CIPHER_CTX_free(ctx);
  72374. /* Decrypt. */
  72375. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72376. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72377. WOLFSSL_SUCCESS);
  72378. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, NULL),
  72379. WOLFSSL_SUCCESS);
  72380. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72381. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72382. ExpectIntEQ(outSz, sizeof(plainText));
  72383. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72384. WOLFSSL_SUCCESS);
  72385. ExpectIntEQ(outSz, 0);
  72386. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72387. EVP_CIPHER_CTX_free(ctx);
  72388. res = EXPECT_RESULT();
  72389. #endif
  72390. return res;
  72391. }
  72392. static int test_wolfssl_EVP_sm4_cbc(void)
  72393. {
  72394. int res = TEST_SKIPPED;
  72395. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CBC)
  72396. EXPECT_DECLS;
  72397. byte key[SM4_KEY_SIZE];
  72398. byte iv[SM4_BLOCK_SIZE];
  72399. byte plainText[SM4_BLOCK_SIZE] = {
  72400. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72401. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72402. };
  72403. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72404. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72405. EVP_CIPHER_CTX* ctx;
  72406. int outSz;
  72407. XMEMSET(key, 0, sizeof(key));
  72408. XMEMSET(iv, 0, sizeof(iv));
  72409. /* Encrypt. */
  72410. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72411. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72412. WOLFSSL_SUCCESS);
  72413. /* Any tag length must fail - not an AEAD cipher. */
  72414. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72415. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72416. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72417. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72418. sizeof(plainText)), WOLFSSL_SUCCESS);
  72419. ExpectIntEQ(outSz, sizeof(plainText));
  72420. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72421. WOLFSSL_SUCCESS);
  72422. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72423. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72424. EVP_CIPHER_CTX_free(ctx);
  72425. /* Decrypt. */
  72426. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72427. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72428. WOLFSSL_SUCCESS);
  72429. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72430. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72431. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72432. ExpectIntEQ(outSz, sizeof(plainText));
  72433. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72434. WOLFSSL_SUCCESS);
  72435. ExpectIntEQ(outSz, 0);
  72436. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72437. EVP_CIPHER_CTX_free(ctx);
  72438. /* Test partial Inits. CipherInit() allow setting of key and iv
  72439. * in separate calls. */
  72440. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72441. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_cbc(), key, NULL, 0),
  72442. WOLFSSL_SUCCESS);
  72443. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 0),
  72444. WOLFSSL_SUCCESS);
  72445. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72446. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72447. ExpectIntEQ(outSz, sizeof(plainText));
  72448. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72449. WOLFSSL_SUCCESS);
  72450. ExpectIntEQ(outSz, 0);
  72451. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72452. EVP_CIPHER_CTX_free(ctx);
  72453. res = EXPECT_RESULT();
  72454. #endif
  72455. return res;
  72456. }
  72457. static int test_wolfssl_EVP_sm4_ctr(void)
  72458. {
  72459. int res = TEST_SKIPPED;
  72460. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CTR)
  72461. EXPECT_DECLS;
  72462. byte key[SM4_KEY_SIZE];
  72463. byte iv[SM4_BLOCK_SIZE];
  72464. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72465. byte cipherText[sizeof(plainText)];
  72466. byte decryptedText[sizeof(plainText)];
  72467. EVP_CIPHER_CTX* ctx;
  72468. int outSz;
  72469. XMEMSET(key, 0, sizeof(key));
  72470. XMEMSET(iv, 0, sizeof(iv));
  72471. /* Encrypt. */
  72472. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72473. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72474. WOLFSSL_SUCCESS);
  72475. /* Any tag length must fail - not an AEAD cipher. */
  72476. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72477. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72478. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72479. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72480. sizeof(plainText)), WOLFSSL_SUCCESS);
  72481. ExpectIntEQ(outSz, sizeof(plainText));
  72482. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72483. ExpectIntEQ(outSz, 0);
  72484. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72485. EVP_CIPHER_CTX_free(ctx);
  72486. /* Decrypt. */
  72487. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72488. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72489. WOLFSSL_SUCCESS);
  72490. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72491. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72492. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72493. ExpectIntEQ(outSz, sizeof(cipherText));
  72494. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72495. WOLFSSL_SUCCESS);
  72496. ExpectIntEQ(outSz, 0);
  72497. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72498. EVP_CIPHER_CTX_free(ctx);
  72499. /* Test partial Inits. CipherInit() allow setting of key and iv
  72500. * in separate calls. */
  72501. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72502. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_ctr(), key, NULL, 1),
  72503. WOLFSSL_SUCCESS);
  72504. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72505. WOLFSSL_SUCCESS);
  72506. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72507. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72508. ExpectIntEQ(outSz, sizeof(cipherText));
  72509. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72510. WOLFSSL_SUCCESS);
  72511. ExpectIntEQ(outSz, 0);
  72512. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72513. EVP_CIPHER_CTX_free(ctx);
  72514. res = EXPECT_RESULT();
  72515. #endif
  72516. return res;
  72517. }
  72518. static int test_wolfssl_EVP_sm4_gcm_zeroLen(void)
  72519. {
  72520. int res = TEST_SKIPPED;
  72521. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  72522. /* Zero length plain text */
  72523. EXPECT_DECLS;
  72524. byte key[] = {
  72525. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72526. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72527. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72528. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72529. }; /* align */
  72530. byte iv[] = {
  72531. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72532. }; /* align */
  72533. byte plaintxt[1];
  72534. int ivSz = 12;
  72535. int plaintxtSz = 0;
  72536. unsigned char tag[16];
  72537. unsigned char tag_kat[16] = {
  72538. 0x23,0x2f,0x0c,0xfe,0x30,0x8b,0x49,0xea,
  72539. 0x6f,0xc8,0x82,0x29,0xb5,0xdc,0x85,0x8d
  72540. };
  72541. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72542. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72543. int ciphertxtSz = 0;
  72544. int decryptedtxtSz = 0;
  72545. int len = 0;
  72546. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72547. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72548. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_gcm(), NULL, key, iv));
  72549. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72550. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72551. plaintxtSz));
  72552. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72553. ciphertxtSz += len;
  72554. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  72555. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72556. ExpectIntEQ(0, ciphertxtSz);
  72557. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  72558. EVP_CIPHER_CTX_init(de);
  72559. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_gcm(), NULL, key, iv));
  72560. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72561. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72562. decryptedtxtSz = len;
  72563. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  72564. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72565. decryptedtxtSz += len;
  72566. ExpectIntEQ(0, decryptedtxtSz);
  72567. EVP_CIPHER_CTX_free(en);
  72568. EVP_CIPHER_CTX_free(de);
  72569. res = EXPECT_RESULT();
  72570. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  72571. return res;
  72572. }
  72573. static int test_wolfssl_EVP_sm4_gcm(void)
  72574. {
  72575. int res = TEST_SKIPPED;
  72576. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  72577. EXPECT_DECLS;
  72578. byte *key = (byte*)"0123456789012345";
  72579. /* A 128 bit IV */
  72580. byte *iv = (byte*)"0123456789012345";
  72581. int ivSz = SM4_BLOCK_SIZE;
  72582. /* Message to be encrypted */
  72583. byte *plaintxt = (byte*)"for things to change you have to change";
  72584. /* Additional non-confidential data */
  72585. byte *aad = (byte*)"Don't spend major time on minor things.";
  72586. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  72587. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72588. int aadSz = (int)XSTRLEN((char*)aad);
  72589. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72590. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72591. int ciphertxtSz = 0;
  72592. int decryptedtxtSz = 0;
  72593. int len = 0;
  72594. int i = 0;
  72595. EVP_CIPHER_CTX en[2];
  72596. EVP_CIPHER_CTX de[2];
  72597. for (i = 0; i < 2; i++) {
  72598. EVP_CIPHER_CTX_init(&en[i]);
  72599. if (i == 0) {
  72600. /* Default uses 96-bits IV length */
  72601. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, key,
  72602. iv));
  72603. }
  72604. else {
  72605. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, NULL,
  72606. NULL));
  72607. /* non-default must to set the IV length first */
  72608. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  72609. ivSz, NULL));
  72610. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72611. }
  72612. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72613. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72614. plaintxtSz));
  72615. ciphertxtSz = len;
  72616. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72617. ciphertxtSz += len;
  72618. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  72619. SM4_BLOCK_SIZE, tag));
  72620. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72621. EVP_CIPHER_CTX_init(&de[i]);
  72622. if (i == 0) {
  72623. /* Default uses 96-bits IV length */
  72624. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, key,
  72625. iv));
  72626. }
  72627. else {
  72628. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, NULL,
  72629. NULL));
  72630. /* non-default must to set the IV length first */
  72631. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72632. ivSz, NULL));
  72633. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72634. }
  72635. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72636. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72637. ciphertxtSz));
  72638. decryptedtxtSz = len;
  72639. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72640. SM4_BLOCK_SIZE, tag));
  72641. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72642. decryptedtxtSz += len;
  72643. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72644. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72645. /* modify tag*/
  72646. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  72647. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72648. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72649. SM4_BLOCK_SIZE, tag));
  72650. /* fail due to wrong tag */
  72651. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72652. ciphertxtSz));
  72653. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72654. ExpectIntEQ(0, len);
  72655. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72656. }
  72657. res = EXPECT_RESULT();
  72658. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  72659. return res;
  72660. }
  72661. static int test_wolfssl_EVP_sm4_ccm_zeroLen(void)
  72662. {
  72663. int res = TEST_SKIPPED;
  72664. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  72665. /* Zero length plain text */
  72666. EXPECT_DECLS;
  72667. byte key[] = {
  72668. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72669. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72670. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72671. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72672. }; /* align */
  72673. byte iv[] = {
  72674. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72675. }; /* align */
  72676. byte plaintxt[1];
  72677. int ivSz = 12;
  72678. int plaintxtSz = 0;
  72679. unsigned char tag[16];
  72680. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72681. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72682. int ciphertxtSz = 0;
  72683. int decryptedtxtSz = 0;
  72684. int len = 0;
  72685. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72686. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72687. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_ccm(), NULL, key, iv));
  72688. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72689. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72690. plaintxtSz));
  72691. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72692. ciphertxtSz += len;
  72693. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  72694. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72695. ExpectIntEQ(0, ciphertxtSz);
  72696. EVP_CIPHER_CTX_init(de);
  72697. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_ccm(), NULL, key, iv));
  72698. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72699. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72700. decryptedtxtSz = len;
  72701. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  72702. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72703. decryptedtxtSz += len;
  72704. ExpectIntEQ(0, decryptedtxtSz);
  72705. EVP_CIPHER_CTX_free(en);
  72706. EVP_CIPHER_CTX_free(de);
  72707. res = EXPECT_RESULT();
  72708. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  72709. return res;
  72710. }
  72711. static int test_wolfssl_EVP_sm4_ccm(void)
  72712. {
  72713. int res = TEST_SKIPPED;
  72714. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  72715. EXPECT_DECLS;
  72716. byte *key = (byte*)"0123456789012345";
  72717. byte *iv = (byte*)"0123456789012";
  72718. int ivSz = (int)XSTRLEN((char*)iv);
  72719. /* Message to be encrypted */
  72720. byte *plaintxt = (byte*)"for things to change you have to change";
  72721. /* Additional non-confidential data */
  72722. byte *aad = (byte*)"Don't spend major time on minor things.";
  72723. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  72724. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72725. int aadSz = (int)XSTRLEN((char*)aad);
  72726. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72727. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72728. int ciphertxtSz = 0;
  72729. int decryptedtxtSz = 0;
  72730. int len = 0;
  72731. int i = 0;
  72732. EVP_CIPHER_CTX en[2];
  72733. EVP_CIPHER_CTX de[2];
  72734. for (i = 0; i < 2; i++) {
  72735. EVP_CIPHER_CTX_init(&en[i]);
  72736. if (i == 0) {
  72737. /* Default uses 96-bits IV length */
  72738. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, key,
  72739. iv));
  72740. }
  72741. else {
  72742. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, NULL,
  72743. NULL));
  72744. /* non-default must to set the IV length first */
  72745. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  72746. ivSz, NULL));
  72747. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72748. }
  72749. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72750. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72751. plaintxtSz));
  72752. ciphertxtSz = len;
  72753. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72754. ciphertxtSz += len;
  72755. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  72756. SM4_BLOCK_SIZE, tag));
  72757. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72758. EVP_CIPHER_CTX_init(&de[i]);
  72759. if (i == 0) {
  72760. /* Default uses 96-bits IV length */
  72761. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, key,
  72762. iv));
  72763. }
  72764. else {
  72765. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, NULL,
  72766. NULL));
  72767. /* non-default must to set the IV length first */
  72768. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  72769. ivSz, NULL));
  72770. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72771. }
  72772. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72773. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72774. ciphertxtSz));
  72775. decryptedtxtSz = len;
  72776. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72777. SM4_BLOCK_SIZE, tag));
  72778. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72779. decryptedtxtSz += len;
  72780. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72781. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72782. /* modify tag*/
  72783. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  72784. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72785. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72786. SM4_BLOCK_SIZE, tag));
  72787. /* fail due to wrong tag */
  72788. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72789. ciphertxtSz));
  72790. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72791. ExpectIntEQ(0, len);
  72792. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72793. }
  72794. res = EXPECT_RESULT();
  72795. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  72796. return res;
  72797. }
  72798. static int test_wolfSSL_EVP_PKEY_hkdf(void)
  72799. {
  72800. EXPECT_DECLS;
  72801. #if defined(OPENSSL_EXTRA) && defined(HAVE_HKDF)
  72802. EVP_PKEY_CTX* ctx = NULL;
  72803. byte salt[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  72804. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
  72805. byte key[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  72806. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  72807. byte info[] = {0X01, 0x02, 0x03, 0x04, 0x05};
  72808. byte info2[] = {0X06, 0x07, 0x08, 0x09, 0x0A};
  72809. byte outKey[34];
  72810. size_t outKeySz = sizeof(outKey);
  72811. /* These expected outputs were gathered by running the same test below using
  72812. * OpenSSL. */
  72813. const byte extractAndExpand[] = {
  72814. 0x8B, 0xEB, 0x90, 0xA9, 0x04, 0xFF, 0x05, 0x10, 0xE4, 0xB5, 0xB1, 0x10,
  72815. 0x31, 0x34, 0xFF, 0x07, 0x5B, 0xE3, 0xC6, 0x93, 0xD4, 0xF8, 0xC7, 0xEE,
  72816. 0x96, 0xDA, 0x78, 0x7A, 0xE2, 0x9A, 0x2D, 0x05, 0x4B, 0xF6
  72817. };
  72818. const byte extractOnly[] = {
  72819. 0xE7, 0x6B, 0x9E, 0x0F, 0xE4, 0x02, 0x1D, 0x62, 0xEA, 0x97, 0x74, 0x5E,
  72820. 0xF4, 0x3C, 0x65, 0x4D, 0xC1, 0x46, 0x98, 0xAA, 0x79, 0x9A, 0xCB, 0x9C,
  72821. 0xCC, 0x3E, 0x7F, 0x2A, 0x2B, 0x41, 0xA1, 0x9E
  72822. };
  72823. const byte expandOnly[] = {
  72824. 0xFF, 0x29, 0x29, 0x56, 0x9E, 0xA7, 0x66, 0x02, 0xDB, 0x4F, 0xDB, 0x53,
  72825. 0x7D, 0x21, 0x67, 0x52, 0xC3, 0x0E, 0xF3, 0xFC, 0x71, 0xCE, 0x67, 0x2B,
  72826. 0xEA, 0x3B, 0xE9, 0xFC, 0xDD, 0xC8, 0xCC, 0xB7, 0x42, 0x74
  72827. };
  72828. const byte extractAndExpandAddInfo[] = {
  72829. 0x5A, 0x74, 0x79, 0x83, 0xA3, 0xA4, 0x2E, 0xB7, 0xD4, 0x08, 0xC2, 0x6A,
  72830. 0x2F, 0xA5, 0xE3, 0x4E, 0xF1, 0xF4, 0x87, 0x3E, 0xA6, 0xC7, 0x88, 0x45,
  72831. 0xD7, 0xE2, 0x15, 0xBC, 0xB8, 0x10, 0xEF, 0x6C, 0x4D, 0x7A
  72832. };
  72833. ExpectNotNull((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)));
  72834. ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS);
  72835. /* NULL ctx. */
  72836. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72837. /* NULL md. */
  72838. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72839. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, EVP_sha256()), WOLFSSL_SUCCESS);
  72840. /* NULL ctx. */
  72841. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(NULL, salt, sizeof(salt)),
  72842. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72843. /* NULL salt is ok. */
  72844. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, sizeof(salt)),
  72845. WOLFSSL_SUCCESS);
  72846. /* Salt length <= 0. */
  72847. /* Length 0 salt is ok. */
  72848. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, 0), WOLFSSL_SUCCESS);
  72849. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72850. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, sizeof(salt)),
  72851. WOLFSSL_SUCCESS);
  72852. /* NULL ctx. */
  72853. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(NULL, key, sizeof(key)),
  72854. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72855. /* NULL key. */
  72856. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, NULL, sizeof(key)),
  72857. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72858. /* Key length <= 0 */
  72859. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72860. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72861. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, sizeof(key)),
  72862. WOLFSSL_SUCCESS);
  72863. /* NULL ctx. */
  72864. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(NULL, info, sizeof(info)),
  72865. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72866. /* NULL info is ok. */
  72867. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, NULL, sizeof(info)),
  72868. WOLFSSL_SUCCESS);
  72869. /* Info length <= 0 */
  72870. /* Length 0 info is ok. */
  72871. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, 0), WOLFSSL_SUCCESS);
  72872. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72873. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, sizeof(info)),
  72874. WOLFSSL_SUCCESS);
  72875. /* NULL ctx. */
  72876. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(NULL, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  72877. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72878. /* Extract and expand (default). */
  72879. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  72880. ExpectIntEQ(outKeySz, sizeof(extractAndExpand));
  72881. ExpectIntEQ(XMEMCMP(outKey, extractAndExpand, outKeySz), 0);
  72882. /* Extract only. */
  72883. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  72884. WOLFSSL_SUCCESS);
  72885. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  72886. ExpectIntEQ(outKeySz, sizeof(extractOnly));
  72887. ExpectIntEQ(XMEMCMP(outKey, extractOnly, outKeySz), 0);
  72888. outKeySz = sizeof(outKey);
  72889. /* Expand only. */
  72890. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY),
  72891. WOLFSSL_SUCCESS);
  72892. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  72893. ExpectIntEQ(outKeySz, sizeof(expandOnly));
  72894. ExpectIntEQ(XMEMCMP(outKey, expandOnly, outKeySz), 0);
  72895. outKeySz = sizeof(outKey);
  72896. /* Extract and expand with appended additional info. */
  72897. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info2, sizeof(info2)),
  72898. WOLFSSL_SUCCESS);
  72899. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx,
  72900. EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND), WOLFSSL_SUCCESS);
  72901. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  72902. ExpectIntEQ(outKeySz, sizeof(extractAndExpandAddInfo));
  72903. ExpectIntEQ(XMEMCMP(outKey, extractAndExpandAddInfo, outKeySz), 0);
  72904. EVP_PKEY_CTX_free(ctx);
  72905. #endif /* OPENSSL_EXTRA && HAVE_HKDF */
  72906. return EXPECT_RESULT();
  72907. }
  72908. #ifndef NO_BIO
  72909. static int test_wolfSSL_PEM_X509_INFO_read_bio(void)
  72910. {
  72911. EXPECT_DECLS;
  72912. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  72913. BIO* bio = NULL;
  72914. X509_INFO* info = NULL;
  72915. STACK_OF(X509_INFO)* sk = NULL;
  72916. char* subject = NULL;
  72917. char exp1[] = "/C=US/ST=Montana/L=Bozeman/O=Sawtooth/OU=Consulting/"
  72918. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  72919. char exp2[] = "/C=US/ST=Montana/L=Bozeman/O=wolfSSL/OU=Support/"
  72920. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  72921. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  72922. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  72923. ExpectNotNull(sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  72924. ExpectIntEQ(sk_X509_INFO_num(sk), 2);
  72925. /* using dereference to maintain testing for Apache port*/
  72926. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  72927. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  72928. 0, 0));
  72929. ExpectIntEQ(0, XSTRNCMP(subject, exp1, sizeof(exp1)));
  72930. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  72931. X509_INFO_free(info);
  72932. info = NULL;
  72933. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  72934. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  72935. 0, 0));
  72936. ExpectIntEQ(0, XSTRNCMP(subject, exp2, sizeof(exp2)));
  72937. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  72938. X509_INFO_free(info);
  72939. ExpectNull(info = sk_X509_INFO_pop(sk));
  72940. sk_X509_INFO_pop_free(sk, X509_INFO_free);
  72941. BIO_free(bio);
  72942. #endif
  72943. return EXPECT_RESULT();
  72944. }
  72945. #endif /* !NO_BIO */
  72946. static int test_wolfSSL_X509_NAME_ENTRY_get_object(void)
  72947. {
  72948. EXPECT_DECLS;
  72949. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  72950. X509 *x509 = NULL;
  72951. X509_NAME* name = NULL;
  72952. int idx = 0;
  72953. X509_NAME_ENTRY *ne = NULL;
  72954. ASN1_OBJECT *object = NULL;
  72955. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  72956. WOLFSSL_FILETYPE_PEM));
  72957. ExpectNotNull(name = X509_get_subject_name(x509));
  72958. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  72959. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  72960. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  72961. X509_free(x509);
  72962. #endif
  72963. return EXPECT_RESULT();
  72964. }
  72965. static int test_wolfSSL_X509_STORE_get1_certs(void)
  72966. {
  72967. EXPECT_DECLS;
  72968. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SIGNER_DER_CERT) && \
  72969. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  72970. X509_STORE_CTX *storeCtx = NULL;
  72971. X509_STORE *store = NULL;
  72972. X509 *caX509 = NULL;
  72973. X509 *svrX509 = NULL;
  72974. X509_NAME *subject = NULL;
  72975. WOLF_STACK_OF(WOLFSSL_X509) *certs = NULL;
  72976. ExpectNotNull(caX509 = X509_load_certificate_file(caCertFile,
  72977. SSL_FILETYPE_PEM));
  72978. ExpectNotNull((svrX509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  72979. SSL_FILETYPE_PEM)));
  72980. ExpectNotNull(storeCtx = X509_STORE_CTX_new());
  72981. ExpectNotNull(store = X509_STORE_new());
  72982. ExpectNotNull(subject = X509_get_subject_name(caX509));
  72983. /* Errors */
  72984. ExpectNull(X509_STORE_get1_certs(storeCtx, subject));
  72985. ExpectNull(X509_STORE_get1_certs(NULL, subject));
  72986. ExpectNull(X509_STORE_get1_certs(storeCtx, NULL));
  72987. ExpectIntEQ(X509_STORE_add_cert(store, caX509), SSL_SUCCESS);
  72988. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, caX509, NULL),
  72989. SSL_SUCCESS);
  72990. /* Should find the cert */
  72991. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  72992. ExpectIntEQ(1, wolfSSL_sk_X509_num(certs));
  72993. sk_X509_pop_free(certs, NULL);
  72994. certs = NULL;
  72995. /* Should not find the cert */
  72996. ExpectNotNull(subject = X509_get_subject_name(svrX509));
  72997. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  72998. ExpectIntEQ(0, wolfSSL_sk_X509_num(certs));
  72999. sk_X509_pop_free(certs, NULL);
  73000. certs = NULL;
  73001. X509_STORE_free(store);
  73002. X509_STORE_CTX_free(storeCtx);
  73003. X509_free(svrX509);
  73004. X509_free(caX509);
  73005. #endif /* OPENSSL_EXTRA && WOLFSSL_SIGNER_DER_CERT && !NO_FILESYSTEM */
  73006. return EXPECT_RESULT();
  73007. }
  73008. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73009. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73010. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73011. static int test_wolfSSL_X509_STORE_set_get_crl_provider(X509_STORE_CTX* ctx,
  73012. X509_CRL** crl_out, X509* cert) {
  73013. X509_CRL *crl = NULL;
  73014. XFILE fp = XBADFILE;
  73015. char* cert_issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
  73016. int ret = 0;
  73017. (void)ctx;
  73018. if (cert_issuer == NULL)
  73019. return 0;
  73020. if ((fp = XFOPEN("certs/crl/crl.pem", "rb")) != XBADFILE) {
  73021. PEM_read_X509_CRL(fp, &crl, NULL, NULL);
  73022. XFCLOSE(fp);
  73023. if (crl != NULL) {
  73024. char* crl_issuer = X509_NAME_oneline(
  73025. X509_CRL_get_issuer(crl), NULL, 0);
  73026. if ((crl_issuer != NULL) &&
  73027. (XSTRCMP(cert_issuer, crl_issuer) == 0)) {
  73028. *crl_out = X509_CRL_dup(crl);
  73029. if (*crl_out != NULL)
  73030. ret = 1;
  73031. }
  73032. OPENSSL_free(crl_issuer);
  73033. }
  73034. }
  73035. X509_CRL_free(crl);
  73036. OPENSSL_free(cert_issuer);
  73037. return ret;
  73038. }
  73039. static int test_wolfSSL_X509_STORE_set_get_crl_provider2(X509_STORE_CTX* ctx,
  73040. X509_CRL** crl_out, X509* cert) {
  73041. (void)ctx;
  73042. (void)cert;
  73043. *crl_out = NULL;
  73044. return 1;
  73045. }
  73046. #ifndef NO_WOLFSSL_STUB
  73047. static int test_wolfSSL_X509_STORE_set_get_crl_check(X509_STORE_CTX* ctx,
  73048. X509_CRL* crl) {
  73049. (void)ctx;
  73050. (void)crl;
  73051. return 1;
  73052. }
  73053. #endif
  73054. static int test_wolfSSL_X509_STORE_set_get_crl_verify(int ok,
  73055. X509_STORE_CTX* ctx) {
  73056. int cert_error = X509_STORE_CTX_get_error(ctx);
  73057. X509_VERIFY_PARAM* param = X509_STORE_CTX_get0_param(ctx);
  73058. int flags = X509_VERIFY_PARAM_get_flags(param);
  73059. if ((flags & (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) !=
  73060. (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) {
  73061. /* Make sure the flags are set */
  73062. return 0;
  73063. }
  73064. /* Ignore CRL missing error */
  73065. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  73066. if (cert_error == WC_NO_ERR_TRACE(CRL_MISSING))
  73067. #else
  73068. if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL)
  73069. #endif
  73070. return 1;
  73071. return ok;
  73072. }
  73073. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready(WOLFSSL_CTX* ctx)
  73074. {
  73075. EXPECT_DECLS;
  73076. X509_STORE* cert_store = NULL;
  73077. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73078. WOLFSSL_SUCCESS);
  73079. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73080. X509_STORE_set_get_crl(cert_store,
  73081. test_wolfSSL_X509_STORE_set_get_crl_provider);
  73082. #ifndef NO_WOLFSSL_STUB
  73083. X509_STORE_set_check_crl(cert_store,
  73084. test_wolfSSL_X509_STORE_set_get_crl_check);
  73085. #endif
  73086. return EXPECT_RESULT();
  73087. }
  73088. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2(WOLFSSL_CTX* ctx)
  73089. {
  73090. EXPECT_DECLS;
  73091. X509_STORE* cert_store = NULL;
  73092. X509_VERIFY_PARAM* param = NULL;
  73093. SSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  73094. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73095. WOLFSSL_SUCCESS);
  73096. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73097. X509_STORE_set_get_crl(cert_store,
  73098. test_wolfSSL_X509_STORE_set_get_crl_provider2);
  73099. #ifndef NO_WOLFSSL_STUB
  73100. X509_STORE_set_check_crl(cert_store,
  73101. test_wolfSSL_X509_STORE_set_get_crl_check);
  73102. #endif
  73103. X509_STORE_set_verify_cb(cert_store,
  73104. test_wolfSSL_X509_STORE_set_get_crl_verify);
  73105. ExpectNotNull(X509_STORE_get0_param(cert_store));
  73106. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  73107. ExpectIntEQ(X509_VERIFY_PARAM_inherit(param,
  73108. X509_STORE_get0_param(cert_store)), 1);
  73109. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(
  73110. param, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73111. ExpectIntEQ(X509_STORE_set1_param(cert_store, param), 1);
  73112. ExpectIntEQ(X509_STORE_set_flags(cert_store,
  73113. X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73114. X509_VERIFY_PARAM_free(param);
  73115. return EXPECT_RESULT();
  73116. }
  73117. #endif
  73118. /* This test mimics the usage of the CRL provider in gRPC */
  73119. static int test_wolfSSL_X509_STORE_set_get_crl(void)
  73120. {
  73121. EXPECT_DECLS;
  73122. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73123. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73124. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73125. test_ssl_cbf func_cb_client;
  73126. test_ssl_cbf func_cb_server;
  73127. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73128. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73129. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready;
  73130. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73131. &func_cb_server, NULL), TEST_SUCCESS);
  73132. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73133. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73134. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2;
  73135. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73136. &func_cb_server, NULL), TEST_SUCCESS);
  73137. #endif
  73138. return EXPECT_RESULT();
  73139. }
  73140. static int test_wolfSSL_dup_CA_list(void)
  73141. {
  73142. int res = TEST_SKIPPED;
  73143. #if defined(OPENSSL_ALL)
  73144. EXPECT_DECLS;
  73145. STACK_OF(X509_NAME) *originalStack = NULL;
  73146. STACK_OF(X509_NAME) *copyStack = NULL;
  73147. int originalCount = 0;
  73148. int copyCount = 0;
  73149. X509_NAME *name = NULL;
  73150. int i;
  73151. originalStack = sk_X509_NAME_new_null();
  73152. ExpectNotNull(originalStack);
  73153. for (i = 0; i < 3; i++) {
  73154. name = X509_NAME_new();
  73155. ExpectNotNull(name);
  73156. ExpectIntEQ(sk_X509_NAME_push(originalStack, name), i+1);
  73157. if (EXPECT_FAIL()) {
  73158. X509_NAME_free(name);
  73159. }
  73160. }
  73161. copyStack = SSL_dup_CA_list(originalStack);
  73162. ExpectNotNull(copyStack);
  73163. originalCount = sk_X509_NAME_num(originalStack);
  73164. copyCount = sk_X509_NAME_num(copyStack);
  73165. ExpectIntEQ(originalCount, copyCount);
  73166. sk_X509_NAME_pop_free(originalStack, X509_NAME_free);
  73167. sk_X509_NAME_pop_free(copyStack, X509_NAME_free);
  73168. originalStack = NULL;
  73169. copyStack = NULL;
  73170. res = EXPECT_RESULT();
  73171. #endif /* OPENSSL_ALL */
  73172. return res;
  73173. }
  73174. static int test_ForceZero(void)
  73175. {
  73176. EXPECT_DECLS;
  73177. unsigned char data[32];
  73178. unsigned int i, j, len;
  73179. /* Test case with 0 length */
  73180. ForceZero(data, 0);
  73181. /* Test ForceZero */
  73182. for (i = 0; i < sizeof(data); i++) {
  73183. for (len = 1; len < sizeof(data) - i; len++) {
  73184. for (j = 0; j < sizeof(data); j++)
  73185. data[j] = j + 1;
  73186. ForceZero(data + i, len);
  73187. for (j = 0; j < sizeof(data); j++) {
  73188. if (j < i || j >= i + len) {
  73189. ExpectIntNE(data[j], 0x00);
  73190. }
  73191. else {
  73192. ExpectIntEQ(data[j], 0x00);
  73193. }
  73194. }
  73195. }
  73196. }
  73197. return EXPECT_RESULT();
  73198. }
  73199. #ifndef NO_BIO
  73200. static int test_wolfSSL_X509_print(void)
  73201. {
  73202. EXPECT_DECLS;
  73203. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  73204. !defined(NO_RSA) && defined(XSNPRINTF)
  73205. X509 *x509 = NULL;
  73206. BIO *bio = NULL;
  73207. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73208. const X509_ALGOR *cert_sig_alg = NULL;
  73209. #endif
  73210. ExpectNotNull(x509 = X509_load_certificate_file(svrCertFile,
  73211. WOLFSSL_FILETYPE_PEM));
  73212. /* print to memory */
  73213. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73214. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73215. #if defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  73216. #if defined(WC_DISABLE_RADIX_ZERO_PAD)
  73217. /* Will print IP address subject alt name. */
  73218. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3349);
  73219. #elif defined(NO_ASN_TIME)
  73220. /* Will print IP address subject alt name but not Validity. */
  73221. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3235);
  73222. #else
  73223. /* Will print IP address subject alt name. */
  73224. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3350);
  73225. #endif
  73226. #elif defined(NO_ASN_TIME)
  73227. /* With NO_ASN_TIME defined, X509_print skips printing Validity. */
  73228. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3213);
  73229. #else
  73230. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3328);
  73231. #endif
  73232. BIO_free(bio);
  73233. bio = NULL;
  73234. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73235. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73236. /* Print signature */
  73237. ExpectNotNull(cert_sig_alg = X509_get0_tbs_sigalg(x509));
  73238. ExpectIntEQ(X509_signature_print(bio, cert_sig_alg, NULL), SSL_SUCCESS);
  73239. #endif
  73240. /* print to stderr */
  73241. #if !defined(NO_WOLFSSL_DIR)
  73242. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73243. #endif
  73244. /* print again */
  73245. ExpectIntEQ(X509_print_fp(stderr, x509), SSL_SUCCESS);
  73246. X509_free(x509);
  73247. BIO_free(bio);
  73248. #endif
  73249. return EXPECT_RESULT();
  73250. }
  73251. static int test_wolfSSL_X509_CRL_print(void)
  73252. {
  73253. EXPECT_DECLS;
  73254. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL)\
  73255. && !defined(NO_FILESYSTEM) && defined(XSNPRINTF)
  73256. X509_CRL* crl = NULL;
  73257. BIO *bio = NULL;
  73258. XFILE fp = XBADFILE;
  73259. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  73260. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  73261. NULL, NULL));
  73262. if (fp != XBADFILE)
  73263. XFCLOSE(fp);
  73264. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73265. ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
  73266. X509_CRL_free(crl);
  73267. BIO_free(bio);
  73268. #endif
  73269. return EXPECT_RESULT();
  73270. }
  73271. static int test_wolfSSL_BIO_get_len(void)
  73272. {
  73273. EXPECT_DECLS;
  73274. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  73275. BIO *bio = NULL;
  73276. const char txt[] = "Some example text to push to the BIO.";
  73277. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  73278. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  73279. ExpectIntEQ(wolfSSL_BIO_write(bio, txt, sizeof(txt)), sizeof(txt));
  73280. ExpectIntEQ(wolfSSL_BIO_get_len(bio), sizeof(txt));
  73281. BIO_free(bio);
  73282. bio = NULL;
  73283. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73284. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  73285. BIO_free(bio);
  73286. #endif
  73287. return EXPECT_RESULT();
  73288. }
  73289. #endif /* !NO_BIO */
  73290. static int test_wolfSSL_RSA(void)
  73291. {
  73292. EXPECT_DECLS;
  73293. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  73294. RSA* rsa = NULL;
  73295. const BIGNUM *n = NULL;
  73296. const BIGNUM *e = NULL;
  73297. const BIGNUM *d = NULL;
  73298. const BIGNUM *p = NULL;
  73299. const BIGNUM *q = NULL;
  73300. const BIGNUM *dmp1 = NULL;
  73301. const BIGNUM *dmq1 = NULL;
  73302. const BIGNUM *iqmp = NULL;
  73303. ExpectNotNull(rsa = RSA_new());
  73304. ExpectIntEQ(RSA_size(NULL), 0);
  73305. ExpectIntEQ(RSA_size(rsa), 0);
  73306. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 0);
  73307. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 0);
  73308. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 0);
  73309. #ifdef WOLFSSL_RSA_KEY_CHECK
  73310. ExpectIntEQ(RSA_check_key(rsa), 0);
  73311. #endif
  73312. RSA_free(rsa);
  73313. rsa = NULL;
  73314. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73315. ExpectIntEQ(RSA_size(rsa), 256);
  73316. #if (!defined(HAVE_FIPS) || FIPS_VERSION3_GT(6,0,0)) && !defined(HAVE_SELFTEST)
  73317. {
  73318. /* Test setting only subset of parameters */
  73319. RSA *rsa2 = NULL;
  73320. unsigned char hash[SHA256_DIGEST_LENGTH];
  73321. unsigned char signature[2048/8];
  73322. unsigned int signatureLen = 0;
  73323. XMEMSET(hash, 0, sizeof(hash));
  73324. RSA_get0_key(rsa, &n, &e, &d);
  73325. RSA_get0_factors(rsa, &p, &q);
  73326. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73327. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73328. &signatureLen, rsa), 1);
  73329. /* Quick sanity check */
  73330. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73331. signatureLen, rsa), 1);
  73332. /* Verifying */
  73333. ExpectNotNull(rsa2 = RSA_new());
  73334. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), NULL), 1);
  73335. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73336. signatureLen, rsa2), 1);
  73337. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73338. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73339. signatureLen, rsa2), 1);
  73340. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73341. BN_dup(iqmp)), 1);
  73342. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73343. signatureLen, rsa2), 1);
  73344. RSA_free(rsa2);
  73345. rsa2 = NULL;
  73346. /* Signing */
  73347. XMEMSET(signature, 0, sizeof(signature));
  73348. ExpectNotNull(rsa2 = RSA_new());
  73349. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), BN_dup(d)), 1);
  73350. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73351. &signatureLen, rsa2), 1);
  73352. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73353. signatureLen, rsa), 1);
  73354. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73355. XMEMSET(signature, 0, sizeof(signature));
  73356. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73357. &signatureLen, rsa2), 1);
  73358. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73359. signatureLen, rsa), 1);
  73360. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73361. BN_dup(iqmp)), 1);
  73362. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73363. &signatureLen, rsa2), 1);
  73364. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73365. signatureLen, rsa), 1);
  73366. RSA_free(rsa2);
  73367. rsa2 = NULL;
  73368. }
  73369. #endif
  73370. #ifdef WOLFSSL_RSA_KEY_CHECK
  73371. ExpectIntEQ(RSA_check_key(NULL), 0);
  73372. ExpectIntEQ(RSA_check_key(rsa), 1);
  73373. #endif
  73374. /* sanity check */
  73375. ExpectIntEQ(RSA_bits(NULL), 0);
  73376. /* key */
  73377. ExpectIntEQ(RSA_bits(rsa), 2048);
  73378. RSA_get0_key(rsa, &n, &e, &d);
  73379. ExpectPtrEq(rsa->n, n);
  73380. ExpectPtrEq(rsa->e, e);
  73381. ExpectPtrEq(rsa->d, d);
  73382. n = NULL;
  73383. e = NULL;
  73384. d = NULL;
  73385. ExpectNotNull(n = BN_new());
  73386. ExpectNotNull(e = BN_new());
  73387. ExpectNotNull(d = BN_new());
  73388. ExpectIntEQ(RSA_set0_key(rsa, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 1);
  73389. if (EXPECT_FAIL()) {
  73390. BN_free((BIGNUM*)n);
  73391. BN_free((BIGNUM*)e);
  73392. BN_free((BIGNUM*)d);
  73393. }
  73394. ExpectPtrEq(rsa->n, n);
  73395. ExpectPtrEq(rsa->e, e);
  73396. ExpectPtrEq(rsa->d, d);
  73397. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 1);
  73398. ExpectIntEQ(RSA_set0_key(NULL, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 0);
  73399. /* crt_params */
  73400. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73401. ExpectPtrEq(rsa->dmp1, dmp1);
  73402. ExpectPtrEq(rsa->dmq1, dmq1);
  73403. ExpectPtrEq(rsa->iqmp, iqmp);
  73404. dmp1 = NULL;
  73405. dmq1 = NULL;
  73406. iqmp = NULL;
  73407. ExpectNotNull(dmp1 = BN_new());
  73408. ExpectNotNull(dmq1 = BN_new());
  73409. ExpectNotNull(iqmp = BN_new());
  73410. ExpectIntEQ(RSA_set0_crt_params(rsa, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73411. (BIGNUM*)iqmp), 1);
  73412. if (EXPECT_FAIL()) {
  73413. BN_free((BIGNUM*)dmp1);
  73414. BN_free((BIGNUM*)dmq1);
  73415. BN_free((BIGNUM*)iqmp);
  73416. }
  73417. ExpectPtrEq(rsa->dmp1, dmp1);
  73418. ExpectPtrEq(rsa->dmq1, dmq1);
  73419. ExpectPtrEq(rsa->iqmp, iqmp);
  73420. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 1);
  73421. ExpectIntEQ(RSA_set0_crt_params(NULL, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73422. (BIGNUM*)iqmp), 0);
  73423. RSA_get0_crt_params(NULL, NULL, NULL, NULL);
  73424. RSA_get0_crt_params(rsa, NULL, NULL, NULL);
  73425. RSA_get0_crt_params(NULL, &dmp1, &dmq1, &iqmp);
  73426. ExpectNull(dmp1);
  73427. ExpectNull(dmq1);
  73428. ExpectNull(iqmp);
  73429. /* factors */
  73430. RSA_get0_factors(rsa, NULL, NULL);
  73431. RSA_get0_factors(rsa, &p, &q);
  73432. ExpectPtrEq(rsa->p, p);
  73433. ExpectPtrEq(rsa->q, q);
  73434. p = NULL;
  73435. q = NULL;
  73436. ExpectNotNull(p = BN_new());
  73437. ExpectNotNull(q = BN_new());
  73438. ExpectIntEQ(RSA_set0_factors(rsa, (BIGNUM*)p, (BIGNUM*)q), 1);
  73439. if (EXPECT_FAIL()) {
  73440. BN_free((BIGNUM*)p);
  73441. BN_free((BIGNUM*)q);
  73442. }
  73443. ExpectPtrEq(rsa->p, p);
  73444. ExpectPtrEq(rsa->q, q);
  73445. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 1);
  73446. ExpectIntEQ(RSA_set0_factors(NULL, (BIGNUM*)p, (BIGNUM*)q), 0);
  73447. RSA_get0_factors(NULL, NULL, NULL);
  73448. RSA_get0_factors(NULL, &p, &q);
  73449. ExpectNull(p);
  73450. ExpectNull(q);
  73451. ExpectIntEQ(BN_hex2bn(&rsa->n, "1FFFFF"), 1);
  73452. ExpectIntEQ(RSA_bits(rsa), 21);
  73453. RSA_free(rsa);
  73454. rsa = NULL;
  73455. #if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
  73456. ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
  73457. ExpectIntEQ(RSA_size(rsa), 384);
  73458. ExpectIntEQ(RSA_bits(rsa), 3072);
  73459. RSA_free(rsa);
  73460. rsa = NULL;
  73461. #endif
  73462. /* remove for now with odd key size until adjusting rsa key size check with
  73463. wc_MakeRsaKey()
  73464. ExpectNotNull(rsa = RSA_generate_key(2999, 65537, NULL, NULL));
  73465. RSA_free(rsa);
  73466. rsa = NULL;
  73467. */
  73468. ExpectNull(RSA_generate_key(-1, 3, NULL, NULL));
  73469. ExpectNull(RSA_generate_key(RSA_MIN_SIZE - 1, 3, NULL, NULL));
  73470. ExpectNull(RSA_generate_key(RSA_MAX_SIZE + 1, 3, NULL, NULL));
  73471. ExpectNull(RSA_generate_key(2048, 0, NULL, NULL));
  73472. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN)
  73473. {
  73474. byte buff[FOURK_BUF];
  73475. byte der[FOURK_BUF];
  73476. const char PrivKeyPemFile[] = "certs/client-keyEnc.pem";
  73477. XFILE f = XBADFILE;
  73478. int bytes = 0;
  73479. /* test loading encrypted RSA private pem w/o password */
  73480. ExpectTrue((f = XFOPEN(PrivKeyPemFile, "rb")) != XBADFILE);
  73481. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  73482. if (f != XBADFILE)
  73483. XFCLOSE(f);
  73484. XMEMSET(der, 0, sizeof(der));
  73485. /* test that error value is returned with no password */
  73486. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der), ""),
  73487. 0);
  73488. }
  73489. #endif
  73490. #endif
  73491. return EXPECT_RESULT();
  73492. }
  73493. static int test_wolfSSL_RSA_DER(void)
  73494. {
  73495. EXPECT_DECLS;
  73496. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  73497. RSA *rsa = NULL;
  73498. int i;
  73499. const unsigned char *buff = NULL;
  73500. unsigned char *newBuff = NULL;
  73501. struct tbl_s
  73502. {
  73503. const unsigned char *der;
  73504. int sz;
  73505. } tbl[] = {
  73506. #ifdef USE_CERT_BUFFERS_1024
  73507. {client_key_der_1024, sizeof_client_key_der_1024},
  73508. {server_key_der_1024, sizeof_server_key_der_1024},
  73509. #endif
  73510. #ifdef USE_CERT_BUFFERS_2048
  73511. {client_key_der_2048, sizeof_client_key_der_2048},
  73512. {server_key_der_2048, sizeof_server_key_der_2048},
  73513. #endif
  73514. {NULL, 0}
  73515. };
  73516. /* Public Key DER */
  73517. struct tbl_s pub[] = {
  73518. #ifdef USE_CERT_BUFFERS_1024
  73519. {client_keypub_der_1024, sizeof_client_keypub_der_1024},
  73520. #endif
  73521. #ifdef USE_CERT_BUFFERS_2048
  73522. {client_keypub_der_2048, sizeof_client_keypub_der_2048},
  73523. #endif
  73524. {NULL, 0}
  73525. };
  73526. ExpectNull(d2i_RSAPublicKey(&rsa, NULL, pub[0].sz));
  73527. buff = pub[0].der;
  73528. ExpectNull(d2i_RSAPublicKey(&rsa, &buff, 1));
  73529. ExpectNull(d2i_RSAPrivateKey(&rsa, NULL, tbl[0].sz));
  73530. buff = tbl[0].der;
  73531. ExpectNull(d2i_RSAPrivateKey(&rsa, &buff, 1));
  73532. ExpectIntEQ(i2d_RSAPublicKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  73533. rsa = RSA_new();
  73534. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), 0);
  73535. RSA_free(rsa);
  73536. rsa = NULL;
  73537. for (i = 0; tbl[i].der != NULL; i++)
  73538. {
  73539. /* Passing in pointer results in pointer moving. */
  73540. buff = tbl[i].der;
  73541. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, tbl[i].sz));
  73542. ExpectNotNull(rsa);
  73543. RSA_free(rsa);
  73544. rsa = NULL;
  73545. }
  73546. for (i = 0; tbl[i].der != NULL; i++)
  73547. {
  73548. /* Passing in pointer results in pointer moving. */
  73549. buff = tbl[i].der;
  73550. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &buff, tbl[i].sz));
  73551. ExpectNotNull(rsa);
  73552. RSA_free(rsa);
  73553. rsa = NULL;
  73554. }
  73555. for (i = 0; pub[i].der != NULL; i++)
  73556. {
  73557. buff = pub[i].der;
  73558. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, pub[i].sz));
  73559. ExpectNotNull(rsa);
  73560. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), pub[i].sz);
  73561. newBuff = NULL;
  73562. ExpectIntEQ(i2d_RSAPublicKey(rsa, &newBuff), pub[i].sz);
  73563. ExpectNotNull(newBuff);
  73564. ExpectIntEQ(XMEMCMP((void *)newBuff, (void *)pub[i].der, pub[i].sz), 0);
  73565. XFREE((void *)newBuff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73566. RSA_free(rsa);
  73567. rsa = NULL;
  73568. }
  73569. #endif
  73570. return EXPECT_RESULT();
  73571. }
  73572. static int test_wolfSSL_RSA_print(void)
  73573. {
  73574. EXPECT_DECLS;
  73575. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  73576. !defined(NO_STDIO_FILESYSTEM) && \
  73577. !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  73578. !defined(NO_BIO) && defined(XFPRINTF)
  73579. BIO *bio = NULL;
  73580. WOLFSSL_RSA* rsa = NULL;
  73581. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73582. ExpectNotNull(rsa = RSA_new());
  73583. ExpectIntEQ(RSA_print(NULL, rsa, 0), -1);
  73584. ExpectIntEQ(RSA_print_fp(XBADFILE, rsa, 0), 0);
  73585. ExpectIntEQ(RSA_print(bio, NULL, 0), -1);
  73586. ExpectIntEQ(RSA_print_fp(stderr, NULL, 0), 0);
  73587. /* Some very large number of indent spaces. */
  73588. ExpectIntEQ(RSA_print(bio, rsa, 128), -1);
  73589. /* RSA is empty. */
  73590. ExpectIntEQ(RSA_print(bio, rsa, 0), 0);
  73591. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 0);
  73592. RSA_free(rsa);
  73593. rsa = NULL;
  73594. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73595. ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
  73596. ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
  73597. ExpectIntEQ(RSA_print(bio, rsa, -1), 1);
  73598. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 1);
  73599. ExpectIntEQ(RSA_print_fp(stderr, rsa, 4), 1);
  73600. ExpectIntEQ(RSA_print_fp(stderr, rsa, -1), 1);
  73601. BIO_free(bio);
  73602. RSA_free(rsa);
  73603. #endif
  73604. return EXPECT_RESULT();
  73605. }
  73606. static int test_wolfSSL_RSA_padding_add_PKCS1_PSS(void)
  73607. {
  73608. EXPECT_DECLS;
  73609. #ifndef NO_RSA
  73610. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  73611. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  73612. RSA *rsa = NULL;
  73613. const unsigned char *derBuf = client_key_der_2048;
  73614. unsigned char em[256] = {0}; /* len = 2048/8 */
  73615. /* Random data simulating a hash */
  73616. const unsigned char mHash[WC_SHA256_DIGEST_SIZE] = {
  73617. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  73618. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  73619. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  73620. };
  73621. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  73622. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(NULL, em, mHash, EVP_sha256(),
  73623. RSA_PSS_SALTLEN_DIGEST), 0);
  73624. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, NULL, mHash, EVP_sha256(),
  73625. RSA_PSS_SALTLEN_DIGEST), 0);
  73626. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, NULL, EVP_sha256(),
  73627. RSA_PSS_SALTLEN_DIGEST), 0);
  73628. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, NULL,
  73629. RSA_PSS_SALTLEN_DIGEST), 0);
  73630. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), -5), 0);
  73631. ExpectIntEQ(RSA_verify_PKCS1_PSS(NULL, mHash, EVP_sha256(), em,
  73632. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73633. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, NULL, EVP_sha256(), em,
  73634. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73635. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, NULL, em,
  73636. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73637. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), NULL,
  73638. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73639. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73640. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73641. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, -5), 0);
  73642. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  73643. RSA_PSS_SALTLEN_DIGEST), 1);
  73644. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73645. RSA_PSS_SALTLEN_DIGEST), 1);
  73646. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  73647. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  73648. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73649. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  73650. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  73651. RSA_PSS_SALTLEN_MAX), 1);
  73652. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73653. RSA_PSS_SALTLEN_MAX), 1);
  73654. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), 10), 1);
  73655. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, 10), 1);
  73656. RSA_free(rsa);
  73657. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  73658. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  73659. #endif
  73660. return EXPECT_RESULT();
  73661. }
  73662. static int test_wolfSSL_RSA_sign_sha3(void)
  73663. {
  73664. EXPECT_DECLS;
  73665. #if !defined(NO_RSA) && defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  73666. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  73667. RSA* rsa = NULL;
  73668. const unsigned char *derBuf = client_key_der_2048;
  73669. unsigned char sigRet[256] = {0};
  73670. unsigned int sigLen = sizeof(sigRet);
  73671. /* Random data simulating a hash */
  73672. const unsigned char mHash[WC_SHA3_256_DIGEST_SIZE] = {
  73673. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  73674. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  73675. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  73676. };
  73677. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  73678. ExpectIntEQ(RSA_sign(NID_sha3_256, mHash, sizeof(mHash), sigRet, &sigLen,
  73679. rsa), 1);
  73680. RSA_free(rsa);
  73681. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  73682. #endif /* !NO_RSA && WOLFSSL_SHA3 && !WOLFSSL_NOSHA3_256*/
  73683. return EXPECT_RESULT();
  73684. }
  73685. static int test_wolfSSL_RSA_get0_key(void)
  73686. {
  73687. EXPECT_DECLS;
  73688. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  73689. RSA *rsa = NULL;
  73690. const BIGNUM* n = NULL;
  73691. const BIGNUM* e = NULL;
  73692. const BIGNUM* d = NULL;
  73693. const unsigned char* der;
  73694. int derSz;
  73695. #ifdef USE_CERT_BUFFERS_1024
  73696. der = client_key_der_1024;
  73697. derSz = sizeof_client_key_der_1024;
  73698. #elif defined(USE_CERT_BUFFERS_2048)
  73699. der = client_key_der_2048;
  73700. derSz = sizeof_client_key_der_2048;
  73701. #else
  73702. der = NULL;
  73703. derSz = 0;
  73704. #endif
  73705. if (der != NULL) {
  73706. RSA_get0_key(NULL, NULL, NULL, NULL);
  73707. RSA_get0_key(rsa, NULL, NULL, NULL);
  73708. RSA_get0_key(NULL, &n, &e, &d);
  73709. ExpectNull(n);
  73710. ExpectNull(e);
  73711. ExpectNull(d);
  73712. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, derSz));
  73713. ExpectNotNull(rsa);
  73714. RSA_get0_key(rsa, NULL, NULL, NULL);
  73715. RSA_get0_key(rsa, &n, NULL, NULL);
  73716. ExpectNotNull(n);
  73717. RSA_get0_key(rsa, NULL, &e, NULL);
  73718. ExpectNotNull(e);
  73719. RSA_get0_key(rsa, NULL, NULL, &d);
  73720. ExpectNotNull(d);
  73721. RSA_get0_key(rsa, &n, &e, &d);
  73722. ExpectNotNull(n);
  73723. ExpectNotNull(e);
  73724. ExpectNotNull(d);
  73725. RSA_free(rsa);
  73726. }
  73727. #endif
  73728. return EXPECT_RESULT();
  73729. }
  73730. static int test_wolfSSL_RSA_meth(void)
  73731. {
  73732. EXPECT_DECLS;
  73733. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  73734. RSA *rsa = NULL;
  73735. RSA_METHOD *rsa_meth = NULL;
  73736. #ifdef WOLFSSL_KEY_GEN
  73737. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73738. RSA_free(rsa);
  73739. rsa = NULL;
  73740. #else
  73741. ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73742. #endif
  73743. ExpectNotNull(RSA_get_default_method());
  73744. wolfSSL_RSA_meth_free(NULL);
  73745. ExpectNull(wolfSSL_RSA_meth_new(NULL, 0));
  73746. ExpectNotNull(rsa_meth = RSA_meth_new("placeholder RSA method",
  73747. RSA_METHOD_FLAG_NO_CHECK));
  73748. #ifndef NO_WOLFSSL_STUB
  73749. ExpectIntEQ(RSA_meth_set_pub_enc(rsa_meth, NULL), 1);
  73750. ExpectIntEQ(RSA_meth_set_pub_dec(rsa_meth, NULL), 1);
  73751. ExpectIntEQ(RSA_meth_set_priv_enc(rsa_meth, NULL), 1);
  73752. ExpectIntEQ(RSA_meth_set_priv_dec(rsa_meth, NULL), 1);
  73753. ExpectIntEQ(RSA_meth_set_init(rsa_meth, NULL), 1);
  73754. ExpectIntEQ(RSA_meth_set_finish(rsa_meth, NULL), 1);
  73755. ExpectIntEQ(RSA_meth_set0_app_data(rsa_meth, NULL), 1);
  73756. #endif
  73757. ExpectIntEQ(RSA_flags(NULL), 0);
  73758. RSA_set_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  73759. RSA_clear_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  73760. ExpectIntEQ(RSA_test_flags(NULL, RSA_FLAG_CACHE_PUBLIC), 0);
  73761. ExpectNotNull(rsa = RSA_new());
  73762. /* No method set. */
  73763. ExpectIntEQ(RSA_flags(rsa), 0);
  73764. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73765. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73766. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  73767. ExpectIntEQ(RSA_set_method(NULL, rsa_meth), 1);
  73768. ExpectIntEQ(RSA_set_method(rsa, rsa_meth), 1);
  73769. if (EXPECT_FAIL()) {
  73770. wolfSSL_RSA_meth_free(rsa_meth);
  73771. }
  73772. ExpectNull(RSA_get_method(NULL));
  73773. ExpectPtrEq(RSA_get_method(rsa), rsa_meth);
  73774. ExpectIntEQ(RSA_flags(rsa), RSA_METHOD_FLAG_NO_CHECK);
  73775. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73776. ExpectIntNE(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  73777. ExpectIntEQ(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC |
  73778. RSA_METHOD_FLAG_NO_CHECK);
  73779. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73780. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  73781. ExpectIntNE(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC);
  73782. /* rsa_meth is freed here */
  73783. RSA_free(rsa);
  73784. #endif
  73785. return EXPECT_RESULT();
  73786. }
  73787. static int test_wolfSSL_RSA_verify(void)
  73788. {
  73789. EXPECT_DECLS;
  73790. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  73791. #ifndef NO_BIO
  73792. XFILE fp = XBADFILE;
  73793. RSA *pKey = NULL;
  73794. RSA *pubKey = NULL;
  73795. X509 *cert = NULL;
  73796. const char *text = "Hello wolfSSL !";
  73797. unsigned char hash[SHA256_DIGEST_LENGTH];
  73798. unsigned char signature[2048/8];
  73799. unsigned int signatureLength;
  73800. byte *buf = NULL;
  73801. BIO *bio = NULL;
  73802. SHA256_CTX c;
  73803. EVP_PKEY *evpPkey = NULL;
  73804. EVP_PKEY *evpPubkey = NULL;
  73805. size_t sz;
  73806. /* generate hash */
  73807. SHA256_Init(&c);
  73808. SHA256_Update(&c, text, strlen(text));
  73809. SHA256_Final(hash, &c);
  73810. #ifdef WOLFSSL_SMALL_STACK_CACHE
  73811. /* workaround for small stack cache case */
  73812. wc_Sha256Free((wc_Sha256*)&c);
  73813. #endif
  73814. /* read privete key file */
  73815. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  73816. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_END), 0);
  73817. ExpectTrue((sz = XFTELL(fp)) > 0);
  73818. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_SET), 0);
  73819. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  73820. ExpectIntEQ(XFREAD(buf, 1, sz, fp), sz);
  73821. if (fp != XBADFILE) {
  73822. XFCLOSE(fp);
  73823. fp = XBADFILE;
  73824. }
  73825. /* read private key and sign hash data */
  73826. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  73827. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL));
  73828. ExpectNotNull(pKey = EVP_PKEY_get1_RSA(evpPkey));
  73829. ExpectIntEQ(RSA_sign(NID_sha256, hash, SHA256_DIGEST_LENGTH,
  73830. signature, &signatureLength, pKey), SSL_SUCCESS);
  73831. /* read public key and verify signed data */
  73832. ExpectTrue((fp = XFOPEN(svrCertFile,"rb")) != XBADFILE);
  73833. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  73834. if (fp != XBADFILE)
  73835. XFCLOSE(fp);
  73836. ExpectNotNull(evpPubkey = X509_get_pubkey(cert));
  73837. ExpectNotNull(pubKey = EVP_PKEY_get1_RSA(evpPubkey));
  73838. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  73839. signatureLength, pubKey), SSL_SUCCESS);
  73840. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, NULL,
  73841. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73842. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, signature,
  73843. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73844. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, NULL,
  73845. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73846. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  73847. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73848. RSA_free(pKey);
  73849. EVP_PKEY_free(evpPkey);
  73850. RSA_free(pubKey);
  73851. EVP_PKEY_free(evpPubkey);
  73852. X509_free(cert);
  73853. BIO_free(bio);
  73854. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  73855. #endif
  73856. #endif
  73857. return EXPECT_RESULT();
  73858. }
  73859. static int test_wolfSSL_RSA_sign(void)
  73860. {
  73861. EXPECT_DECLS;
  73862. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  73863. RSA *rsa;
  73864. unsigned char hash[SHA256_DIGEST_LENGTH];
  73865. #ifdef USE_CERT_BUFFERS_1024
  73866. const unsigned char* privDer = client_key_der_1024;
  73867. size_t privDerSz = sizeof_client_key_der_1024;
  73868. const unsigned char* pubDer = client_keypub_der_1024;
  73869. size_t pubDerSz = sizeof_client_keypub_der_1024;
  73870. unsigned char signature[1024/8];
  73871. #else
  73872. const unsigned char* privDer = client_key_der_2048;
  73873. size_t privDerSz = sizeof_client_key_der_2048;
  73874. const unsigned char* pubDer = client_keypub_der_2048;
  73875. size_t pubDerSz = sizeof_client_keypub_der_2048;
  73876. unsigned char signature[2048/8];
  73877. #endif
  73878. unsigned int signatureLen;
  73879. const unsigned char* der;
  73880. XMEMSET(hash, 0, sizeof(hash));
  73881. der = privDer;
  73882. rsa = NULL;
  73883. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  73884. /* Invalid parameters. */
  73885. ExpectIntEQ(RSA_sign(NID_rsaEncryption, NULL, 0, NULL, NULL, NULL), 0);
  73886. ExpectIntEQ(RSA_sign(NID_rsaEncryption, hash, sizeof(hash), signature,
  73887. &signatureLen, rsa), 0);
  73888. ExpectIntEQ(RSA_sign(NID_sha256, NULL, sizeof(hash), signature,
  73889. &signatureLen, rsa), 0);
  73890. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), NULL,
  73891. &signatureLen, rsa), 0);
  73892. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73893. NULL, rsa), 0);
  73894. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73895. &signatureLen, NULL), 0);
  73896. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73897. &signatureLen, rsa), 1);
  73898. RSA_free(rsa);
  73899. der = pubDer;
  73900. rsa = NULL;
  73901. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  73902. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73903. signatureLen, rsa), 1);
  73904. RSA_free(rsa);
  73905. #endif
  73906. return EXPECT_RESULT();
  73907. }
  73908. static int test_wolfSSL_RSA_sign_ex(void)
  73909. {
  73910. EXPECT_DECLS;
  73911. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  73912. RSA *rsa = NULL;
  73913. unsigned char hash[SHA256_DIGEST_LENGTH];
  73914. #ifdef USE_CERT_BUFFERS_1024
  73915. const unsigned char* privDer = client_key_der_1024;
  73916. size_t privDerSz = sizeof_client_key_der_1024;
  73917. const unsigned char* pubDer = client_keypub_der_1024;
  73918. size_t pubDerSz = sizeof_client_keypub_der_1024;
  73919. unsigned char signature[1024/8];
  73920. #else
  73921. const unsigned char* privDer = client_key_der_2048;
  73922. size_t privDerSz = sizeof_client_key_der_2048;
  73923. const unsigned char* pubDer = client_keypub_der_2048;
  73924. size_t pubDerSz = sizeof_client_keypub_der_2048;
  73925. unsigned char signature[2048/8];
  73926. #endif
  73927. unsigned int signatureLen;
  73928. const unsigned char* der;
  73929. unsigned char encodedHash[51];
  73930. unsigned int encodedHashLen;
  73931. const unsigned char expEncHash[] = {
  73932. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  73933. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  73934. 0x00, 0x04, 0x20,
  73935. /* Hash data */
  73936. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73937. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73938. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73939. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73940. };
  73941. XMEMSET(hash, 0, sizeof(hash));
  73942. ExpectNotNull(rsa = wolfSSL_RSA_new());
  73943. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  73944. &signatureLen, rsa, 1), 0);
  73945. wolfSSL_RSA_free(rsa);
  73946. der = privDer;
  73947. rsa = NULL;
  73948. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  73949. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption,NULL, 0, NULL, NULL, NULL,
  73950. -1), 0);
  73951. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption, hash, sizeof(hash),
  73952. signature, &signatureLen, rsa, 1), 0);
  73953. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  73954. &signatureLen, rsa, 1), 0);
  73955. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  73956. &signatureLen, rsa, 1), 0);
  73957. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  73958. NULL, rsa, 1), 0);
  73959. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  73960. &signatureLen, NULL, 1), 0);
  73961. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  73962. &signatureLen, rsa, -1), 0);
  73963. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  73964. &signatureLen, rsa, 0), 0);
  73965. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  73966. &signatureLen, rsa, 0), 0);
  73967. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  73968. NULL, rsa, 0), 0);
  73969. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  73970. &signatureLen, rsa, 1), 1);
  73971. /* Test returning encoded hash. */
  73972. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), encodedHash,
  73973. &encodedHashLen, rsa, 0), 1);
  73974. ExpectIntEQ(encodedHashLen, sizeof(expEncHash));
  73975. ExpectIntEQ(XMEMCMP(encodedHash, expEncHash, sizeof(expEncHash)), 0);
  73976. RSA_free(rsa);
  73977. der = pubDer;
  73978. rsa = NULL;
  73979. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  73980. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73981. signatureLen, rsa), 1);
  73982. RSA_free(rsa);
  73983. #endif
  73984. return EXPECT_RESULT();
  73985. }
  73986. static int test_wolfSSL_RSA_public_decrypt(void)
  73987. {
  73988. EXPECT_DECLS;
  73989. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  73990. RSA *rsa;
  73991. unsigned char msg[SHA256_DIGEST_LENGTH];
  73992. #ifdef USE_CERT_BUFFERS_1024
  73993. const unsigned char* pubDer = client_keypub_der_1024;
  73994. size_t pubDerSz = sizeof_client_keypub_der_1024;
  73995. unsigned char decMsg[1024/8];
  73996. const unsigned char encMsg[] = {
  73997. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  73998. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  73999. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74000. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74001. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74002. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74003. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74004. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74005. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74006. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74007. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74008. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74009. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74010. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74011. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74012. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74013. };
  74014. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74015. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74016. defined(WC_RSA_NO_PADDING)
  74017. const unsigned char encMsgNoPad[] = {
  74018. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74019. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74020. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74021. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74022. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74023. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74024. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74025. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74026. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74027. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74028. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74029. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74030. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74031. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74032. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74033. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74034. };
  74035. #endif
  74036. #else
  74037. const unsigned char* pubDer = client_keypub_der_2048;
  74038. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74039. unsigned char decMsg[2048/8];
  74040. const unsigned char encMsg[] = {
  74041. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74042. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74043. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74044. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74045. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74046. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74047. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74048. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74049. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74050. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74051. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74052. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74053. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74054. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74055. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74056. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74057. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74058. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74059. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74060. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74061. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74062. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74063. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74064. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74065. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74066. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74067. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74068. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74069. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74070. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74071. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74072. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74073. };
  74074. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74075. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74076. defined(WC_RSA_NO_PADDING)
  74077. const unsigned char encMsgNoPad[] = {
  74078. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74079. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74080. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74081. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74082. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74083. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74084. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74085. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74086. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74087. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74088. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74089. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74090. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74091. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74092. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74093. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74094. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74095. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74096. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74097. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74098. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74099. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74100. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74101. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74102. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74103. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74104. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74105. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74106. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74107. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74108. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74109. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74110. };
  74111. #endif
  74112. #endif
  74113. const unsigned char* der;
  74114. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74115. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74116. defined(WC_RSA_NO_PADDING)
  74117. int i;
  74118. #endif
  74119. XMEMSET(msg, 0, sizeof(msg));
  74120. der = pubDer;
  74121. rsa = NULL;
  74122. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74123. ExpectIntEQ(RSA_public_decrypt(0, NULL, NULL, NULL, 0), -1);
  74124. ExpectIntEQ(RSA_public_decrypt(-1, encMsg, decMsg, rsa,
  74125. RSA_PKCS1_PADDING), -1);
  74126. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), NULL, decMsg, rsa,
  74127. RSA_PKCS1_PADDING), -1);
  74128. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74129. RSA_PKCS1_PADDING), -1);
  74130. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, NULL,
  74131. RSA_PKCS1_PADDING), -1);
  74132. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74133. RSA_PKCS1_PSS_PADDING), -1);
  74134. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74135. RSA_PKCS1_PADDING), 32);
  74136. ExpectIntEQ(XMEMCMP(decMsg, msg, sizeof(msg)), 0);
  74137. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74138. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74139. defined(WC_RSA_NO_PADDING)
  74140. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsgNoPad), encMsgNoPad, decMsg,
  74141. rsa, RSA_NO_PADDING), sizeof(decMsg));
  74142. /* Zeros before actual data. */
  74143. for (i = 0; i < (int)(sizeof(decMsg) - sizeof(msg)); i += sizeof(msg)) {
  74144. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74145. }
  74146. /* Check actual data. */
  74147. XMEMSET(msg, 0x01, sizeof(msg));
  74148. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74149. #endif
  74150. RSA_free(rsa);
  74151. #endif
  74152. return EXPECT_RESULT();
  74153. }
  74154. static int test_wolfSSL_RSA_private_encrypt(void)
  74155. {
  74156. EXPECT_DECLS;
  74157. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74158. RSA *rsa;
  74159. unsigned char msg[SHA256_DIGEST_LENGTH];
  74160. #ifdef USE_CERT_BUFFERS_1024
  74161. const unsigned char* privDer = client_key_der_1024;
  74162. size_t privDerSz = sizeof_client_key_der_1024;
  74163. unsigned char encMsg[1024/8];
  74164. const unsigned char expEncMsg[] = {
  74165. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  74166. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  74167. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74168. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74169. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74170. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74171. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74172. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74173. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74174. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74175. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74176. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74177. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74178. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74179. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74180. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74181. };
  74182. #ifdef WC_RSA_NO_PADDING
  74183. const unsigned char expEncMsgNoPad[] = {
  74184. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74185. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74186. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74187. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74188. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74189. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74190. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74191. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74192. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74193. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74194. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74195. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74196. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74197. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74198. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74199. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74200. };
  74201. #endif
  74202. #else
  74203. const unsigned char* privDer = client_key_der_2048;
  74204. size_t privDerSz = sizeof_client_key_der_2048;
  74205. unsigned char encMsg[2048/8];
  74206. const unsigned char expEncMsg[] = {
  74207. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74208. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74209. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74210. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74211. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74212. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74213. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74214. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74215. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74216. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74217. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74218. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74219. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74220. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74221. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74222. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74223. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74224. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74225. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74226. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74227. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74228. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74229. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74230. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74231. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74232. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74233. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74234. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74235. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74236. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74237. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74238. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74239. };
  74240. #ifdef WC_RSA_NO_PADDING
  74241. const unsigned char expEncMsgNoPad[] = {
  74242. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74243. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74244. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74245. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74246. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74247. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74248. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74249. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74250. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74251. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74252. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74253. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74254. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74255. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74256. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74257. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74258. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74259. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74260. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74261. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74262. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74263. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74264. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74265. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74266. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74267. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74268. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74269. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74270. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74271. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74272. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74273. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74274. };
  74275. #endif
  74276. #endif
  74277. const unsigned char* der;
  74278. XMEMSET(msg, 0x00, sizeof(msg));
  74279. der = privDer;
  74280. rsa = NULL;
  74281. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74282. ExpectIntEQ(RSA_private_encrypt(0, NULL, NULL, NULL, 0), -1);
  74283. ExpectIntEQ(RSA_private_encrypt(0, msg, encMsg, rsa, RSA_PKCS1_PADDING),
  74284. -1);
  74285. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74286. RSA_PKCS1_PADDING), -1);
  74287. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, NULL, rsa,
  74288. RSA_PKCS1_PADDING), -1);
  74289. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, NULL,
  74290. RSA_PKCS1_PADDING), -1);
  74291. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74292. RSA_PKCS1_PSS_PADDING), -1);
  74293. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74294. RSA_PKCS1_PADDING), sizeof(encMsg));
  74295. ExpectIntEQ(XMEMCMP(encMsg, expEncMsg, sizeof(expEncMsg)), 0);
  74296. #ifdef WC_RSA_NO_PADDING
  74297. /* Non-zero message. */
  74298. XMEMSET(msg, 0x01, sizeof(msg));
  74299. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74300. RSA_NO_PADDING), sizeof(encMsg));
  74301. ExpectIntEQ(XMEMCMP(encMsg, expEncMsgNoPad, sizeof(expEncMsgNoPad)), 0);
  74302. #endif
  74303. RSA_free(rsa);
  74304. #endif
  74305. return EXPECT_RESULT();
  74306. }
  74307. static int test_wolfSSL_RSA_public_encrypt(void)
  74308. {
  74309. EXPECT_DECLS;
  74310. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74311. RSA* rsa = NULL;
  74312. const unsigned char msg[2048/8] = { 0 };
  74313. unsigned char encMsg[2048/8];
  74314. ExpectNotNull(rsa = RSA_new());
  74315. ExpectIntEQ(RSA_public_encrypt(-1, msg, encMsg, rsa,
  74316. RSA_PKCS1_PADDING), -1);
  74317. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74318. RSA_PKCS1_PADDING), -1);
  74319. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, NULL, rsa,
  74320. RSA_PKCS1_PADDING), -1);
  74321. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, NULL,
  74322. RSA_PKCS1_PADDING), -1);
  74323. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74324. RSA_PKCS1_PSS_PADDING), -1);
  74325. /* Empty RSA key. */
  74326. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74327. RSA_PKCS1_PADDING), -1);
  74328. RSA_free(rsa);
  74329. #endif
  74330. return EXPECT_RESULT();
  74331. }
  74332. static int test_wolfSSL_RSA_private_decrypt(void)
  74333. {
  74334. EXPECT_DECLS;
  74335. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74336. RSA* rsa = NULL;
  74337. unsigned char msg[2048/8];
  74338. const unsigned char encMsg[2048/8] = { 0 };
  74339. ExpectNotNull(rsa = RSA_new());
  74340. ExpectIntEQ(RSA_private_decrypt(-1, encMsg, msg, rsa,
  74341. RSA_PKCS1_PADDING), -1);
  74342. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), NULL, msg, rsa,
  74343. RSA_PKCS1_PADDING), -1);
  74344. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74345. RSA_PKCS1_PADDING), -1);
  74346. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, NULL,
  74347. RSA_PKCS1_PADDING), -1);
  74348. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74349. RSA_PKCS1_PSS_PADDING), -1);
  74350. /* Empty RSA key. */
  74351. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74352. RSA_PKCS1_PADDING), -1);
  74353. RSA_free(rsa);
  74354. #endif
  74355. return EXPECT_RESULT();
  74356. }
  74357. static int test_wolfSSL_RSA_GenAdd(void)
  74358. {
  74359. EXPECT_DECLS;
  74360. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74361. RSA *rsa;
  74362. #ifdef USE_CERT_BUFFERS_1024
  74363. const unsigned char* privDer = client_key_der_1024;
  74364. size_t privDerSz = sizeof_client_key_der_1024;
  74365. const unsigned char* pubDer = client_keypub_der_1024;
  74366. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74367. #else
  74368. const unsigned char* privDer = client_key_der_2048;
  74369. size_t privDerSz = sizeof_client_key_der_2048;
  74370. const unsigned char* pubDer = client_keypub_der_2048;
  74371. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74372. #endif
  74373. const unsigned char* der;
  74374. der = privDer;
  74375. rsa = NULL;
  74376. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74377. ExpectIntEQ(wolfSSL_RSA_GenAdd(NULL), -1);
  74378. #ifndef RSA_LOW_MEM
  74379. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), 1);
  74380. #else
  74381. /* dmp1 and dmq1 are not set (allocated) when RSA_LOW_MEM. */
  74382. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74383. #endif
  74384. RSA_free(rsa);
  74385. der = pubDer;
  74386. rsa = NULL;
  74387. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74388. /* Need private values. */
  74389. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74390. RSA_free(rsa);
  74391. #endif
  74392. return EXPECT_RESULT();
  74393. }
  74394. static int test_wolfSSL_RSA_blinding_on(void)
  74395. {
  74396. EXPECT_DECLS;
  74397. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_STUB)
  74398. RSA *rsa;
  74399. WOLFSSL_BN_CTX *bnCtx = NULL;
  74400. #ifdef USE_CERT_BUFFERS_1024
  74401. const unsigned char* privDer = client_key_der_1024;
  74402. size_t privDerSz = sizeof_client_key_der_1024;
  74403. #else
  74404. const unsigned char* privDer = client_key_der_2048;
  74405. size_t privDerSz = sizeof_client_key_der_2048;
  74406. #endif
  74407. const unsigned char* der;
  74408. der = privDer;
  74409. rsa = NULL;
  74410. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74411. ExpectNotNull(bnCtx = wolfSSL_BN_CTX_new());
  74412. /* Does nothing so all parameters are valid. */
  74413. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, NULL), 1);
  74414. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, NULL), 1);
  74415. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, bnCtx), 1);
  74416. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, bnCtx), 1);
  74417. wolfSSL_BN_CTX_free(bnCtx);
  74418. RSA_free(rsa);
  74419. #endif
  74420. return EXPECT_RESULT();
  74421. }
  74422. static int test_wolfSSL_RSA_ex_data(void)
  74423. {
  74424. EXPECT_DECLS;
  74425. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  74426. RSA* rsa = NULL;
  74427. unsigned char data[1];
  74428. ExpectNotNull(rsa = RSA_new());
  74429. ExpectNull(wolfSSL_RSA_get_ex_data(NULL, 0));
  74430. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74431. #ifdef MAX_EX_DATA
  74432. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, MAX_EX_DATA));
  74433. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, MAX_EX_DATA, data), 0);
  74434. #endif
  74435. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, NULL), 0);
  74436. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, data), 0);
  74437. #ifdef HAVE_EX_DATA
  74438. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 1);
  74439. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 1);
  74440. ExpectPtrEq(wolfSSL_RSA_get_ex_data(rsa, 0), data);
  74441. #else
  74442. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 0);
  74443. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 0);
  74444. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74445. #endif
  74446. RSA_free(rsa);
  74447. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74448. return EXPECT_RESULT();
  74449. }
  74450. static int test_wolfSSL_RSA_LoadDer(void)
  74451. {
  74452. EXPECT_DECLS;
  74453. #if !defined(NO_RSA) && (defined(OPENSSL_EXTRA) || \
  74454. defined(OPENSSL_EXTRA_X509_SMALL))
  74455. RSA *rsa = NULL;
  74456. #ifdef USE_CERT_BUFFERS_1024
  74457. const unsigned char* privDer = client_key_der_1024;
  74458. size_t privDerSz = sizeof_client_key_der_1024;
  74459. #else
  74460. const unsigned char* privDer = client_key_der_2048;
  74461. size_t privDerSz = sizeof_client_key_der_2048;
  74462. #endif
  74463. ExpectNotNull(rsa = RSA_new());
  74464. ExpectIntEQ(wolfSSL_RSA_LoadDer(NULL, privDer, (int)privDerSz), -1);
  74465. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, NULL, (int)privDerSz), -1);
  74466. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, 0), -1);
  74467. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, (int)privDerSz), 1);
  74468. RSA_free(rsa);
  74469. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74470. return EXPECT_RESULT();
  74471. }
  74472. /* Local API. */
  74473. static int test_wolfSSL_RSA_To_Der(void)
  74474. {
  74475. EXPECT_DECLS;
  74476. #ifdef WOLFSSL_TEST_STATIC_BUILD
  74477. #if defined(WOLFSSL_KEY_GEN) && defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74478. RSA* rsa;
  74479. #ifdef USE_CERT_BUFFERS_1024
  74480. const unsigned char* privDer = client_key_der_1024;
  74481. size_t privDerSz = sizeof_client_key_der_1024;
  74482. const unsigned char* pubDer = client_keypub_der_1024;
  74483. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74484. unsigned char out[sizeof(client_key_der_1024)];
  74485. #else
  74486. const unsigned char* privDer = client_key_der_2048;
  74487. size_t privDerSz = sizeof_client_key_der_2048;
  74488. const unsigned char* pubDer = client_keypub_der_2048;
  74489. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74490. unsigned char out[sizeof(client_key_der_2048)];
  74491. #endif
  74492. const unsigned char* der;
  74493. unsigned char* outDer = NULL;
  74494. der = privDer;
  74495. rsa = NULL;
  74496. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74497. ExpectIntEQ(wolfSSL_RSA_To_Der(NULL, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74498. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 2, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74499. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 0, HEAP_HINT), privDerSz);
  74500. outDer = out;
  74501. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74502. ExpectIntEQ(XMEMCMP(out, privDer, privDerSz), 0);
  74503. outDer = NULL;
  74504. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74505. ExpectNotNull(outDer);
  74506. ExpectIntEQ(XMEMCMP(outDer, privDer, privDerSz), 0);
  74507. XFREE(outDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  74508. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 1, HEAP_HINT), pubDerSz);
  74509. outDer = out;
  74510. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), pubDerSz);
  74511. ExpectIntEQ(XMEMCMP(out, pubDer, pubDerSz), 0);
  74512. RSA_free(rsa);
  74513. ExpectNotNull(rsa = RSA_new());
  74514. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74515. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74516. RSA_free(rsa);
  74517. der = pubDer;
  74518. rsa = NULL;
  74519. ExpectNotNull(wolfSSL_d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74520. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74521. RSA_free(rsa);
  74522. #endif
  74523. #endif
  74524. return EXPECT_RESULT();
  74525. }
  74526. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  74527. static int test_wolfSSL_PEM_read_RSAPublicKey(void)
  74528. {
  74529. EXPECT_DECLS;
  74530. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  74531. XFILE file = XBADFILE;
  74532. const char* fname = "./certs/server-keyPub.pem";
  74533. RSA *rsa = NULL;
  74534. ExpectNull(wolfSSL_PEM_read_RSAPublicKey(XBADFILE, NULL, NULL, NULL));
  74535. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  74536. ExpectNotNull(rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL));
  74537. ExpectIntEQ(RSA_size(rsa), 256);
  74538. RSA_free(rsa);
  74539. if (file != XBADFILE)
  74540. XFCLOSE(file);
  74541. #endif
  74542. return EXPECT_RESULT();
  74543. }
  74544. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  74545. static int test_wolfSSL_PEM_write_RSA_PUBKEY(void)
  74546. {
  74547. EXPECT_DECLS;
  74548. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  74549. defined(WOLFSSL_KEY_GEN)
  74550. RSA* rsa = NULL;
  74551. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(XBADFILE, NULL), 0);
  74552. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, NULL), 0);
  74553. /* Valid but stub so returns 0. */
  74554. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, rsa), 0);
  74555. #endif
  74556. return EXPECT_RESULT();
  74557. }
  74558. static int test_wolfSSL_PEM_write_RSAPrivateKey(void)
  74559. {
  74560. EXPECT_DECLS;
  74561. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  74562. (defined(WOLFSSL_PEM_TO_DER) || \
  74563. defined(WOLFSSL_DER_TO_PEM)) && !defined(NO_FILESYSTEM)
  74564. RSA* rsa = NULL;
  74565. #ifdef USE_CERT_BUFFERS_1024
  74566. const unsigned char* privDer = client_key_der_1024;
  74567. size_t privDerSz = sizeof_client_key_der_1024;
  74568. #else
  74569. const unsigned char* privDer = client_key_der_2048;
  74570. size_t privDerSz = sizeof_client_key_der_2048;
  74571. #endif
  74572. const unsigned char* der;
  74573. #ifndef NO_AES
  74574. unsigned char passwd[] = "password";
  74575. #endif
  74576. ExpectNotNull(rsa = RSA_new());
  74577. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  74578. NULL, NULL), 0);
  74579. RSA_free(rsa);
  74580. der = privDer;
  74581. rsa = NULL;
  74582. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74583. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0,
  74584. NULL, NULL), 0);
  74585. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0,
  74586. NULL, NULL), 0);
  74587. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  74588. NULL, NULL), 1);
  74589. #ifndef NO_AES
  74590. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  74591. NULL, 0, NULL, NULL), 1);
  74592. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  74593. passwd, sizeof(passwd) - 1, NULL, NULL), 1);
  74594. #endif
  74595. RSA_free(rsa);
  74596. #endif
  74597. return EXPECT_RESULT();
  74598. }
  74599. static int test_wolfSSL_PEM_write_mem_RSAPrivateKey(void)
  74600. {
  74601. EXPECT_DECLS;
  74602. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  74603. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  74604. RSA* rsa = NULL;
  74605. #ifdef USE_CERT_BUFFERS_1024
  74606. const unsigned char* privDer = client_key_der_1024;
  74607. size_t privDerSz = sizeof_client_key_der_1024;
  74608. #else
  74609. const unsigned char* privDer = client_key_der_2048;
  74610. size_t privDerSz = sizeof_client_key_der_2048;
  74611. #endif
  74612. const unsigned char* der;
  74613. #ifndef NO_AES
  74614. unsigned char passwd[] = "password";
  74615. #endif
  74616. unsigned char* pem = NULL;
  74617. int plen;
  74618. ExpectNotNull(rsa = RSA_new());
  74619. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  74620. &plen), 0);
  74621. RSA_free(rsa);
  74622. der = privDer;
  74623. rsa = NULL;
  74624. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74625. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(NULL, NULL, NULL, 0, &pem,
  74626. &plen), 0);
  74627. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, NULL,
  74628. &plen), 0);
  74629. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  74630. NULL), 0);
  74631. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  74632. &plen), 1);
  74633. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  74634. pem = NULL;
  74635. #ifndef NO_AES
  74636. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  74637. NULL, 0, &pem, &plen), 1);
  74638. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  74639. pem = NULL;
  74640. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  74641. passwd, sizeof(passwd) - 1, &pem, &plen), 1);
  74642. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  74643. #endif
  74644. RSA_free(rsa);
  74645. #endif
  74646. return EXPECT_RESULT();
  74647. }
  74648. static int test_wolfSSL_DH(void)
  74649. {
  74650. EXPECT_DECLS;
  74651. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  74652. DH *dh = NULL;
  74653. BIGNUM* p;
  74654. BIGNUM* q;
  74655. BIGNUM* g;
  74656. BIGNUM* pub = NULL;
  74657. BIGNUM* priv = NULL;
  74658. #if defined(OPENSSL_ALL)
  74659. #if !defined(HAVE_FIPS) || \
  74660. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  74661. FILE* f = NULL;
  74662. unsigned char buf[268];
  74663. const unsigned char* pt = buf;
  74664. long len = 0;
  74665. dh = NULL;
  74666. XMEMSET(buf, 0, sizeof(buf));
  74667. /* Test 2048 bit parameters */
  74668. ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  74669. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  74670. if (f != XBADFILE)
  74671. XFCLOSE(f);
  74672. ExpectNotNull(dh = d2i_DHparams(NULL, &pt, len));
  74673. ExpectNotNull(dh->p);
  74674. ExpectNotNull(dh->g);
  74675. ExpectTrue(pt == buf);
  74676. ExpectIntEQ(DH_generate_key(dh), 1);
  74677. /* first, test for expected successful key agreement. */
  74678. if (EXPECT_SUCCESS()) {
  74679. DH *dh2 = NULL;
  74680. unsigned char buf2[268];
  74681. int sz1 = 0, sz2 = 0;
  74682. ExpectNotNull(dh2 = d2i_DHparams(NULL, &pt, len));
  74683. ExpectIntEQ(DH_generate_key(dh2), 1);
  74684. ExpectIntGT(sz1=DH_compute_key(buf, dh2->pub_key, dh), 0);
  74685. ExpectIntGT(sz2=DH_compute_key(buf2, dh->pub_key, dh2), 0);
  74686. ExpectIntEQ(sz1, sz2);
  74687. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  74688. ExpectIntNE(sz1 = DH_size(dh), 0);
  74689. ExpectIntEQ(DH_compute_key_padded(buf, dh2->pub_key, dh), sz1);
  74690. ExpectIntEQ(DH_compute_key_padded(buf2, dh->pub_key, dh2), sz1);
  74691. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  74692. if (dh2 != NULL)
  74693. DH_free(dh2);
  74694. }
  74695. ExpectIntEQ(DH_generate_key(dh), 1);
  74696. ExpectIntEQ(DH_compute_key(NULL, NULL, NULL), -1);
  74697. ExpectNotNull(pub = BN_new());
  74698. ExpectIntEQ(BN_set_word(pub, 1), 1);
  74699. ExpectIntEQ(DH_compute_key(buf, NULL, NULL), -1);
  74700. ExpectIntEQ(DH_compute_key(NULL, pub, NULL), -1);
  74701. ExpectIntEQ(DH_compute_key(NULL, NULL, dh), -1);
  74702. ExpectIntEQ(DH_compute_key(buf, pub, NULL), -1);
  74703. ExpectIntEQ(DH_compute_key(buf, NULL, dh), -1);
  74704. ExpectIntEQ(DH_compute_key(NULL, pub, dh), -1);
  74705. ExpectIntEQ(DH_compute_key(buf, pub, dh), -1);
  74706. BN_free(pub);
  74707. pub = NULL;
  74708. DH_get0_pqg(dh, (const BIGNUM**)&p,
  74709. (const BIGNUM**)&q,
  74710. (const BIGNUM**)&g);
  74711. ExpectPtrEq(p, dh->p);
  74712. ExpectPtrEq(q, dh->q);
  74713. ExpectPtrEq(g, dh->g);
  74714. DH_get0_key(NULL, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  74715. DH_get0_key(dh, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  74716. ExpectPtrEq(pub, dh->pub_key);
  74717. ExpectPtrEq(priv, dh->priv_key);
  74718. DH_get0_key(dh, (const BIGNUM**)&pub, NULL);
  74719. ExpectPtrEq(pub, dh->pub_key);
  74720. DH_get0_key(dh, NULL, (const BIGNUM**)&priv);
  74721. ExpectPtrEq(priv, dh->priv_key);
  74722. pub = NULL;
  74723. priv = NULL;
  74724. ExpectNotNull(pub = BN_new());
  74725. ExpectNotNull(priv = BN_new());
  74726. ExpectIntEQ(DH_set0_key(NULL, pub, priv), 0);
  74727. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  74728. if (EXPECT_FAIL()) {
  74729. BN_free(pub);
  74730. BN_free(priv);
  74731. }
  74732. pub = NULL;
  74733. priv = NULL;
  74734. ExpectNotNull(pub = BN_new());
  74735. ExpectIntEQ(DH_set0_key(dh, pub, NULL), 1);
  74736. if (EXPECT_FAIL()) {
  74737. BN_free(pub);
  74738. }
  74739. ExpectNotNull(priv = BN_new());
  74740. ExpectIntEQ(DH_set0_key(dh, NULL, priv), 1);
  74741. if (EXPECT_FAIL()) {
  74742. BN_free(priv);
  74743. }
  74744. ExpectPtrEq(pub, dh->pub_key);
  74745. ExpectPtrEq(priv, dh->priv_key);
  74746. pub = NULL;
  74747. priv = NULL;
  74748. DH_free(dh);
  74749. dh = NULL;
  74750. ExpectNotNull(dh = DH_new());
  74751. p = NULL;
  74752. ExpectNotNull(p = BN_new());
  74753. ExpectIntEQ(BN_set_word(p, 1), 1);
  74754. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  74755. ExpectNotNull(pub = BN_new());
  74756. ExpectNotNull(priv = BN_new());
  74757. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  74758. if (EXPECT_FAIL()) {
  74759. BN_free(pub);
  74760. BN_free(priv);
  74761. }
  74762. pub = NULL;
  74763. priv = NULL;
  74764. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  74765. BN_free(p);
  74766. p = NULL;
  74767. DH_free(dh);
  74768. dh = NULL;
  74769. #ifdef WOLFSSL_KEY_GEN
  74770. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  74771. ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0);
  74772. DH_free(dh);
  74773. dh = NULL;
  74774. #endif
  74775. #endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */
  74776. #endif /* OPENSSL_ALL */
  74777. (void)dh;
  74778. (void)p;
  74779. (void)q;
  74780. (void)g;
  74781. (void)pub;
  74782. (void)priv;
  74783. ExpectNotNull(dh = wolfSSL_DH_new());
  74784. /* invalid parameters test */
  74785. DH_get0_pqg(NULL, (const BIGNUM**)&p,
  74786. (const BIGNUM**)&q,
  74787. (const BIGNUM**)&g);
  74788. DH_get0_pqg(dh, NULL,
  74789. (const BIGNUM**)&q,
  74790. (const BIGNUM**)&g);
  74791. DH_get0_pqg(dh, NULL, NULL, (const BIGNUM**)&g);
  74792. DH_get0_pqg(dh, NULL, NULL, NULL);
  74793. DH_get0_pqg(dh, (const BIGNUM**)&p,
  74794. (const BIGNUM**)&q,
  74795. (const BIGNUM**)&g);
  74796. ExpectPtrEq(p, NULL);
  74797. ExpectPtrEq(q, NULL);
  74798. ExpectPtrEq(g, NULL);
  74799. DH_free(dh);
  74800. dh = NULL;
  74801. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && !defined(WOLFSSL_DH_EXTRA)) \
  74802. || (defined(HAVE_FIPS_VERSION) && FIPS_VERSION_GT(2,0))
  74803. #if defined(OPENSSL_ALL) || \
  74804. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  74805. dh = wolfSSL_DH_new();
  74806. ExpectNotNull(dh);
  74807. p = wolfSSL_BN_new();
  74808. ExpectNotNull(p);
  74809. ExpectIntEQ(BN_set_word(p, 11), 1);
  74810. g = wolfSSL_BN_new();
  74811. ExpectNotNull(g);
  74812. ExpectIntEQ(BN_set_word(g, 2), 1);
  74813. q = wolfSSL_BN_new();
  74814. ExpectNotNull(q);
  74815. ExpectIntEQ(BN_set_word(q, 5), 1);
  74816. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, NULL), 0);
  74817. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 0);
  74818. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, NULL, NULL), 0);
  74819. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, q, NULL), 0);
  74820. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, g), 0);
  74821. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, q, g), 0);
  74822. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, g), 0);
  74823. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, NULL), 0);
  74824. /* Don't need q. */
  74825. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  74826. if (EXPECT_FAIL()) {
  74827. BN_free(p);
  74828. BN_free(g);
  74829. }
  74830. p = NULL;
  74831. g = NULL;
  74832. /* Setting again will free the p and g. */
  74833. wolfSSL_BN_free(q);
  74834. q = NULL;
  74835. DH_free(dh);
  74836. dh = NULL;
  74837. dh = wolfSSL_DH_new();
  74838. ExpectNotNull(dh);
  74839. p = wolfSSL_BN_new();
  74840. ExpectNotNull(p);
  74841. ExpectIntEQ(BN_set_word(p, 11), 1);
  74842. g = wolfSSL_BN_new();
  74843. ExpectNotNull(g);
  74844. ExpectIntEQ(BN_set_word(g, 2), 1);
  74845. q = wolfSSL_BN_new();
  74846. ExpectNotNull(q);
  74847. ExpectIntEQ(BN_set_word(q, 5), 1);
  74848. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, g), 1);
  74849. /* p, q and g are now owned by dh - don't free. */
  74850. if (EXPECT_FAIL()) {
  74851. BN_free(p);
  74852. BN_free(q);
  74853. BN_free(g);
  74854. }
  74855. p = NULL;
  74856. q = NULL;
  74857. g = NULL;
  74858. p = wolfSSL_BN_new();
  74859. ExpectNotNull(p);
  74860. ExpectIntEQ(BN_set_word(p, 11), 1);
  74861. g = wolfSSL_BN_new();
  74862. ExpectNotNull(g);
  74863. ExpectIntEQ(BN_set_word(g, 2), 1);
  74864. q = wolfSSL_BN_new();
  74865. ExpectNotNull(q);
  74866. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, NULL), 1);
  74867. if (EXPECT_FAIL()) {
  74868. BN_free(p);
  74869. }
  74870. p = NULL;
  74871. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, NULL), 1);
  74872. if (EXPECT_FAIL()) {
  74873. BN_free(q);
  74874. }
  74875. q = NULL;
  74876. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, g), 1);
  74877. if (EXPECT_FAIL()) {
  74878. BN_free(g);
  74879. }
  74880. g = NULL;
  74881. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 1);
  74882. /* p, q and g are now owned by dh - don't free. */
  74883. DH_free(dh);
  74884. dh = NULL;
  74885. ExpectIntEQ(DH_generate_key(NULL), 0);
  74886. ExpectNotNull(dh = DH_new());
  74887. ExpectIntEQ(DH_generate_key(dh), 0);
  74888. p = wolfSSL_BN_new();
  74889. ExpectNotNull(p);
  74890. ExpectIntEQ(BN_set_word(p, 0), 1);
  74891. g = wolfSSL_BN_new();
  74892. ExpectNotNull(g);
  74893. ExpectIntEQ(BN_set_word(g, 2), 1);
  74894. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  74895. if (EXPECT_FAIL()) {
  74896. BN_free(p);
  74897. BN_free(g);
  74898. }
  74899. p = NULL;
  74900. g = NULL;
  74901. ExpectIntEQ(DH_generate_key(dh), 0);
  74902. DH_free(dh);
  74903. dh = NULL;
  74904. #endif
  74905. #endif
  74906. /* Test DH_up_ref() */
  74907. dh = wolfSSL_DH_new();
  74908. ExpectNotNull(dh);
  74909. ExpectIntEQ(wolfSSL_DH_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74910. ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS);
  74911. DH_free(dh); /* decrease ref count */
  74912. DH_free(dh); /* free WOLFSSL_DH */
  74913. dh = NULL;
  74914. q = NULL;
  74915. ExpectNull((dh = DH_new_by_nid(NID_sha1)));
  74916. #if (defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && \
  74917. FIPS_VERSION_EQ(2,0))) || (!defined(HAVE_PUBLIC_FFDHE) && \
  74918. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)))
  74919. #ifdef HAVE_FFDHE_2048
  74920. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  74921. DH_free(dh);
  74922. dh = NULL;
  74923. q = NULL;
  74924. #endif
  74925. #ifdef HAVE_FFDHE_3072
  74926. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072)));
  74927. DH_free(dh);
  74928. dh = NULL;
  74929. q = NULL;
  74930. #endif
  74931. #ifdef HAVE_FFDHE_4096
  74932. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096)));
  74933. DH_free(dh);
  74934. dh = NULL;
  74935. q = NULL;
  74936. #endif
  74937. #else
  74938. ExpectNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  74939. #endif /* (HAVE_PUBLIC_FFDHE || (HAVE_FIPS && HAVE_FIPS_VERSION == 2)) ||
  74940. * (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
  74941. ExpectIntEQ(wolfSSL_DH_size(NULL), -1);
  74942. #endif /* OPENSSL_EXTRA && !NO_DH */
  74943. return EXPECT_RESULT();
  74944. }
  74945. static int test_wolfSSL_DH_dup(void)
  74946. {
  74947. EXPECT_DECLS;
  74948. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  74949. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  74950. defined(OPENSSL_EXTRA)
  74951. DH *dh = NULL;
  74952. DH *dhDup = NULL;
  74953. ExpectNotNull(dh = wolfSSL_DH_new());
  74954. ExpectNull(dhDup = wolfSSL_DH_dup(NULL));
  74955. ExpectNull(dhDup = wolfSSL_DH_dup(dh));
  74956. #if defined(OPENSSL_ALL) || \
  74957. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  74958. {
  74959. WOLFSSL_BIGNUM* p = NULL;
  74960. WOLFSSL_BIGNUM* g = NULL;
  74961. ExpectNotNull(p = wolfSSL_BN_new());
  74962. ExpectNotNull(g = wolfSSL_BN_new());
  74963. ExpectIntEQ(wolfSSL_BN_set_word(p, 11), WOLFSSL_SUCCESS);
  74964. ExpectIntEQ(wolfSSL_BN_set_word(g, 2), WOLFSSL_SUCCESS);
  74965. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  74966. if (EXPECT_FAIL()) {
  74967. wolfSSL_BN_free(p);
  74968. wolfSSL_BN_free(g);
  74969. }
  74970. ExpectNotNull(dhDup = wolfSSL_DH_dup(dh));
  74971. wolfSSL_DH_free(dhDup);
  74972. }
  74973. #endif
  74974. wolfSSL_DH_free(dh);
  74975. #endif
  74976. #endif
  74977. return EXPECT_RESULT();
  74978. }
  74979. static int test_wolfSSL_DH_check(void)
  74980. {
  74981. EXPECT_DECLS;
  74982. #ifdef OPENSSL_ALL
  74983. #ifndef NO_DH
  74984. #ifndef NO_BIO
  74985. #ifndef NO_DSA
  74986. byte buf[6000];
  74987. char file[] = "./certs/dsaparams.pem";
  74988. XFILE f = XBADFILE;
  74989. int bytes;
  74990. BIO* bio = NULL;
  74991. DSA* dsa = NULL;
  74992. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  74993. static const byte dh2048[] = {
  74994. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  74995. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  74996. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  74997. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  74998. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  74999. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75000. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75001. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75002. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75003. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75004. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75005. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75006. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75007. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75008. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75009. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75010. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75011. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75012. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75013. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75014. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75015. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75016. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75017. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75018. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75019. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75020. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75021. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75022. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75023. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75024. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75025. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75026. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75027. 0x93, 0x02, 0x01, 0x02
  75028. };
  75029. const byte* params;
  75030. #endif
  75031. DH* dh = NULL;
  75032. WOLFSSL_BIGNUM* p = NULL;
  75033. WOLFSSL_BIGNUM* g = NULL;
  75034. WOLFSSL_BIGNUM* pTmp = NULL;
  75035. WOLFSSL_BIGNUM* gTmp = NULL;
  75036. int codes = -1;
  75037. #ifndef NO_DSA
  75038. /* Initialize DH */
  75039. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  75040. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  75041. if (f != XBADFILE)
  75042. XFCLOSE(f);
  75043. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  75044. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  75045. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  75046. ExpectNotNull(dh);
  75047. BIO_free(bio);
  75048. DSA_free(dsa);
  75049. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  75050. params = dh2048;
  75051. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &params,
  75052. (long)sizeof(dh2048)));
  75053. #else
  75054. ExpectNotNull(dh = wolfSSL_DH_new_by_nid(NID_ffdhe2048));
  75055. #endif
  75056. /* Test assumed to be valid dh.
  75057. * Should return WOLFSSL_SUCCESS
  75058. * codes should be 0
  75059. * Invalid codes = {DH_NOT_SUITABLE_GENERATOR, DH_CHECK_P_NOT_PRIME}
  75060. */
  75061. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75062. ExpectIntEQ(codes, 0);
  75063. /* Test NULL dh: expected BAD_FUNC_ARG */
  75064. ExpectIntEQ(wolfSSL_DH_check(NULL, &codes), 0);
  75065. /* Break dh prime to test if codes = DH_CHECK_P_NOT_PRIME */
  75066. if (dh != NULL) {
  75067. pTmp = dh->p;
  75068. dh->p = NULL;
  75069. }
  75070. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75071. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75072. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75073. /* set dh->p back to normal so it won't fail on next tests */
  75074. if (dh != NULL) {
  75075. dh->p = pTmp;
  75076. pTmp = NULL;
  75077. }
  75078. /* Break dh generator to test if codes = DH_NOT_SUITABLE_GENERATOR */
  75079. if (dh != NULL) {
  75080. gTmp = dh->g;
  75081. dh->g = NULL;
  75082. }
  75083. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75084. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75085. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR);
  75086. if (dh != NULL) {
  75087. dh->g = gTmp;
  75088. gTmp = NULL;
  75089. }
  75090. /* Cleanup */
  75091. DH_free(dh);
  75092. dh = NULL;
  75093. dh = DH_new();
  75094. ExpectNotNull(dh);
  75095. /* Check empty DH. */
  75096. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75097. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75098. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR | DH_CHECK_P_NOT_PRIME);
  75099. /* Check non-prime valued p. */
  75100. ExpectNotNull(p = BN_new());
  75101. ExpectIntEQ(BN_set_word(p, 4), 1);
  75102. ExpectNotNull(g = BN_new());
  75103. ExpectIntEQ(BN_set_word(g, 2), 1);
  75104. ExpectIntEQ(DH_set0_pqg(dh, p, NULL, g), 1);
  75105. if (EXPECT_FAIL()) {
  75106. wolfSSL_BN_free(p);
  75107. wolfSSL_BN_free(g);
  75108. }
  75109. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75110. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75111. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75112. DH_free(dh);
  75113. dh = NULL;
  75114. #endif
  75115. #endif /* !NO_DH && !NO_DSA */
  75116. #endif
  75117. return EXPECT_RESULT();
  75118. }
  75119. static int test_wolfSSL_DH_prime(void)
  75120. {
  75121. EXPECT_DECLS;
  75122. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75123. WOLFSSL_BIGNUM* bn = NULL;
  75124. #if WOLFSSL_MAX_BN_BITS >= 768
  75125. WOLFSSL_BIGNUM* bn2 = NULL;
  75126. #endif
  75127. bn = wolfSSL_DH_768_prime(NULL);
  75128. #if WOLFSSL_MAX_BN_BITS >= 768
  75129. ExpectNotNull(bn);
  75130. bn2 = wolfSSL_DH_768_prime(bn);
  75131. ExpectNotNull(bn2);
  75132. ExpectTrue(bn == bn2);
  75133. wolfSSL_BN_free(bn);
  75134. bn = NULL;
  75135. #else
  75136. ExpectNull(bn);
  75137. #endif
  75138. bn = wolfSSL_DH_1024_prime(NULL);
  75139. #if WOLFSSL_MAX_BN_BITS >= 1024
  75140. ExpectNotNull(bn);
  75141. wolfSSL_BN_free(bn);
  75142. bn = NULL;
  75143. #else
  75144. ExpectNull(bn);
  75145. #endif
  75146. bn = wolfSSL_DH_2048_prime(NULL);
  75147. #if WOLFSSL_MAX_BN_BITS >= 2048
  75148. ExpectNotNull(bn);
  75149. wolfSSL_BN_free(bn);
  75150. bn = NULL;
  75151. #else
  75152. ExpectNull(bn);
  75153. #endif
  75154. bn = wolfSSL_DH_3072_prime(NULL);
  75155. #if WOLFSSL_MAX_BN_BITS >= 3072
  75156. ExpectNotNull(bn);
  75157. wolfSSL_BN_free(bn);
  75158. bn = NULL;
  75159. #else
  75160. ExpectNull(bn);
  75161. #endif
  75162. bn = wolfSSL_DH_4096_prime(NULL);
  75163. #if WOLFSSL_MAX_BN_BITS >= 4096
  75164. ExpectNotNull(bn);
  75165. wolfSSL_BN_free(bn);
  75166. bn = NULL;
  75167. #else
  75168. ExpectNull(bn);
  75169. #endif
  75170. bn = wolfSSL_DH_6144_prime(NULL);
  75171. #if WOLFSSL_MAX_BN_BITS >= 6144
  75172. ExpectNotNull(bn);
  75173. wolfSSL_BN_free(bn);
  75174. bn = NULL;
  75175. #else
  75176. ExpectNull(bn);
  75177. #endif
  75178. bn = wolfSSL_DH_8192_prime(NULL);
  75179. #if WOLFSSL_MAX_BN_BITS >= 8192
  75180. ExpectNotNull(bn);
  75181. wolfSSL_BN_free(bn);
  75182. bn = NULL;
  75183. #else
  75184. ExpectNull(bn);
  75185. #endif
  75186. #endif
  75187. return EXPECT_RESULT();
  75188. }
  75189. static int test_wolfSSL_DH_1536_prime(void)
  75190. {
  75191. EXPECT_DECLS;
  75192. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75193. BIGNUM* bn = NULL;
  75194. unsigned char bits[200];
  75195. int sz = 192; /* known binary size */
  75196. const byte expected[] = {
  75197. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75198. 0xC9,0x0F,0xDA,0xA2,0x21,0x68,0xC2,0x34,
  75199. 0xC4,0xC6,0x62,0x8B,0x80,0xDC,0x1C,0xD1,
  75200. 0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,
  75201. 0x02,0x0B,0xBE,0xA6,0x3B,0x13,0x9B,0x22,
  75202. 0x51,0x4A,0x08,0x79,0x8E,0x34,0x04,0xDD,
  75203. 0xEF,0x95,0x19,0xB3,0xCD,0x3A,0x43,0x1B,
  75204. 0x30,0x2B,0x0A,0x6D,0xF2,0x5F,0x14,0x37,
  75205. 0x4F,0xE1,0x35,0x6D,0x6D,0x51,0xC2,0x45,
  75206. 0xE4,0x85,0xB5,0x76,0x62,0x5E,0x7E,0xC6,
  75207. 0xF4,0x4C,0x42,0xE9,0xA6,0x37,0xED,0x6B,
  75208. 0x0B,0xFF,0x5C,0xB6,0xF4,0x06,0xB7,0xED,
  75209. 0xEE,0x38,0x6B,0xFB,0x5A,0x89,0x9F,0xA5,
  75210. 0xAE,0x9F,0x24,0x11,0x7C,0x4B,0x1F,0xE6,
  75211. 0x49,0x28,0x66,0x51,0xEC,0xE4,0x5B,0x3D,
  75212. 0xC2,0x00,0x7C,0xB8,0xA1,0x63,0xBF,0x05,
  75213. 0x98,0xDA,0x48,0x36,0x1C,0x55,0xD3,0x9A,
  75214. 0x69,0x16,0x3F,0xA8,0xFD,0x24,0xCF,0x5F,
  75215. 0x83,0x65,0x5D,0x23,0xDC,0xA3,0xAD,0x96,
  75216. 0x1C,0x62,0xF3,0x56,0x20,0x85,0x52,0xBB,
  75217. 0x9E,0xD5,0x29,0x07,0x70,0x96,0x96,0x6D,
  75218. 0x67,0x0C,0x35,0x4E,0x4A,0xBC,0x98,0x04,
  75219. 0xF1,0x74,0x6C,0x08,0xCA,0x23,0x73,0x27,
  75220. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75221. };
  75222. ExpectNotNull(bn = get_rfc3526_prime_1536(NULL));
  75223. ExpectIntEQ(sz, BN_bn2bin((const BIGNUM*)bn, bits));
  75224. ExpectIntEQ(0, XMEMCMP(expected, bits, sz));
  75225. BN_free(bn);
  75226. #endif
  75227. return EXPECT_RESULT();
  75228. }
  75229. static int test_wolfSSL_DH_get_2048_256(void)
  75230. {
  75231. EXPECT_DECLS;
  75232. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75233. WOLFSSL_DH* dh = NULL;
  75234. const WOLFSSL_BIGNUM* pBn;
  75235. const WOLFSSL_BIGNUM* gBn;
  75236. const WOLFSSL_BIGNUM* qBn;
  75237. const byte pExpected[] = {
  75238. 0x87, 0xA8, 0xE6, 0x1D, 0xB4, 0xB6, 0x66, 0x3C, 0xFF, 0xBB, 0xD1, 0x9C,
  75239. 0x65, 0x19, 0x59, 0x99, 0x8C, 0xEE, 0xF6, 0x08, 0x66, 0x0D, 0xD0, 0xF2,
  75240. 0x5D, 0x2C, 0xEE, 0xD4, 0x43, 0x5E, 0x3B, 0x00, 0xE0, 0x0D, 0xF8, 0xF1,
  75241. 0xD6, 0x19, 0x57, 0xD4, 0xFA, 0xF7, 0xDF, 0x45, 0x61, 0xB2, 0xAA, 0x30,
  75242. 0x16, 0xC3, 0xD9, 0x11, 0x34, 0x09, 0x6F, 0xAA, 0x3B, 0xF4, 0x29, 0x6D,
  75243. 0x83, 0x0E, 0x9A, 0x7C, 0x20, 0x9E, 0x0C, 0x64, 0x97, 0x51, 0x7A, 0xBD,
  75244. 0x5A, 0x8A, 0x9D, 0x30, 0x6B, 0xCF, 0x67, 0xED, 0x91, 0xF9, 0xE6, 0x72,
  75245. 0x5B, 0x47, 0x58, 0xC0, 0x22, 0xE0, 0xB1, 0xEF, 0x42, 0x75, 0xBF, 0x7B,
  75246. 0x6C, 0x5B, 0xFC, 0x11, 0xD4, 0x5F, 0x90, 0x88, 0xB9, 0x41, 0xF5, 0x4E,
  75247. 0xB1, 0xE5, 0x9B, 0xB8, 0xBC, 0x39, 0xA0, 0xBF, 0x12, 0x30, 0x7F, 0x5C,
  75248. 0x4F, 0xDB, 0x70, 0xC5, 0x81, 0xB2, 0x3F, 0x76, 0xB6, 0x3A, 0xCA, 0xE1,
  75249. 0xCA, 0xA6, 0xB7, 0x90, 0x2D, 0x52, 0x52, 0x67, 0x35, 0x48, 0x8A, 0x0E,
  75250. 0xF1, 0x3C, 0x6D, 0x9A, 0x51, 0xBF, 0xA4, 0xAB, 0x3A, 0xD8, 0x34, 0x77,
  75251. 0x96, 0x52, 0x4D, 0x8E, 0xF6, 0xA1, 0x67, 0xB5, 0xA4, 0x18, 0x25, 0xD9,
  75252. 0x67, 0xE1, 0x44, 0xE5, 0x14, 0x05, 0x64, 0x25, 0x1C, 0xCA, 0xCB, 0x83,
  75253. 0xE6, 0xB4, 0x86, 0xF6, 0xB3, 0xCA, 0x3F, 0x79, 0x71, 0x50, 0x60, 0x26,
  75254. 0xC0, 0xB8, 0x57, 0xF6, 0x89, 0x96, 0x28, 0x56, 0xDE, 0xD4, 0x01, 0x0A,
  75255. 0xBD, 0x0B, 0xE6, 0x21, 0xC3, 0xA3, 0x96, 0x0A, 0x54, 0xE7, 0x10, 0xC3,
  75256. 0x75, 0xF2, 0x63, 0x75, 0xD7, 0x01, 0x41, 0x03, 0xA4, 0xB5, 0x43, 0x30,
  75257. 0xC1, 0x98, 0xAF, 0x12, 0x61, 0x16, 0xD2, 0x27, 0x6E, 0x11, 0x71, 0x5F,
  75258. 0x69, 0x38, 0x77, 0xFA, 0xD7, 0xEF, 0x09, 0xCA, 0xDB, 0x09, 0x4A, 0xE9,
  75259. 0x1E, 0x1A, 0x15, 0x97
  75260. };
  75261. const byte gExpected[] = {
  75262. 0x3F, 0xB3, 0x2C, 0x9B, 0x73, 0x13, 0x4D, 0x0B, 0x2E, 0x77, 0x50, 0x66,
  75263. 0x60, 0xED, 0xBD, 0x48, 0x4C, 0xA7, 0xB1, 0x8F, 0x21, 0xEF, 0x20, 0x54,
  75264. 0x07, 0xF4, 0x79, 0x3A, 0x1A, 0x0B, 0xA1, 0x25, 0x10, 0xDB, 0xC1, 0x50,
  75265. 0x77, 0xBE, 0x46, 0x3F, 0xFF, 0x4F, 0xED, 0x4A, 0xAC, 0x0B, 0xB5, 0x55,
  75266. 0xBE, 0x3A, 0x6C, 0x1B, 0x0C, 0x6B, 0x47, 0xB1, 0xBC, 0x37, 0x73, 0xBF,
  75267. 0x7E, 0x8C, 0x6F, 0x62, 0x90, 0x12, 0x28, 0xF8, 0xC2, 0x8C, 0xBB, 0x18,
  75268. 0xA5, 0x5A, 0xE3, 0x13, 0x41, 0x00, 0x0A, 0x65, 0x01, 0x96, 0xF9, 0x31,
  75269. 0xC7, 0x7A, 0x57, 0xF2, 0xDD, 0xF4, 0x63, 0xE5, 0xE9, 0xEC, 0x14, 0x4B,
  75270. 0x77, 0x7D, 0xE6, 0x2A, 0xAA, 0xB8, 0xA8, 0x62, 0x8A, 0xC3, 0x76, 0xD2,
  75271. 0x82, 0xD6, 0xED, 0x38, 0x64, 0xE6, 0x79, 0x82, 0x42, 0x8E, 0xBC, 0x83,
  75272. 0x1D, 0x14, 0x34, 0x8F, 0x6F, 0x2F, 0x91, 0x93, 0xB5, 0x04, 0x5A, 0xF2,
  75273. 0x76, 0x71, 0x64, 0xE1, 0xDF, 0xC9, 0x67, 0xC1, 0xFB, 0x3F, 0x2E, 0x55,
  75274. 0xA4, 0xBD, 0x1B, 0xFF, 0xE8, 0x3B, 0x9C, 0x80, 0xD0, 0x52, 0xB9, 0x85,
  75275. 0xD1, 0x82, 0xEA, 0x0A, 0xDB, 0x2A, 0x3B, 0x73, 0x13, 0xD3, 0xFE, 0x14,
  75276. 0xC8, 0x48, 0x4B, 0x1E, 0x05, 0x25, 0x88, 0xB9, 0xB7, 0xD2, 0xBB, 0xD2,
  75277. 0xDF, 0x01, 0x61, 0x99, 0xEC, 0xD0, 0x6E, 0x15, 0x57, 0xCD, 0x09, 0x15,
  75278. 0xB3, 0x35, 0x3B, 0xBB, 0x64, 0xE0, 0xEC, 0x37, 0x7F, 0xD0, 0x28, 0x37,
  75279. 0x0D, 0xF9, 0x2B, 0x52, 0xC7, 0x89, 0x14, 0x28, 0xCD, 0xC6, 0x7E, 0xB6,
  75280. 0x18, 0x4B, 0x52, 0x3D, 0x1D, 0xB2, 0x46, 0xC3, 0x2F, 0x63, 0x07, 0x84,
  75281. 0x90, 0xF0, 0x0E, 0xF8, 0xD6, 0x47, 0xD1, 0x48, 0xD4, 0x79, 0x54, 0x51,
  75282. 0x5E, 0x23, 0x27, 0xCF, 0xEF, 0x98, 0xC5, 0x82, 0x66, 0x4B, 0x4C, 0x0F,
  75283. 0x6C, 0xC4, 0x16, 0x59
  75284. };
  75285. const byte qExpected[] = {
  75286. 0x8C, 0xF8, 0x36, 0x42, 0xA7, 0x09, 0xA0, 0x97, 0xB4, 0x47, 0x99, 0x76,
  75287. 0x40, 0x12, 0x9D, 0xA2, 0x99, 0xB1, 0xA4, 0x7D, 0x1E, 0xB3, 0x75, 0x0B,
  75288. 0xA3, 0x08, 0xB0, 0xFE, 0x64, 0xF5, 0xFB, 0xD3
  75289. };
  75290. int pSz = 0;
  75291. int qSz = 0;
  75292. int gSz = 0;
  75293. byte* pReturned = NULL;
  75294. byte* qReturned = NULL;
  75295. byte* gReturned = NULL;
  75296. ExpectNotNull((dh = wolfSSL_DH_get_2048_256()));
  75297. wolfSSL_DH_get0_pqg(dh, &pBn, &qBn, &gBn);
  75298. ExpectIntGT((pSz = wolfSSL_BN_num_bytes(pBn)), 0);
  75299. ExpectNotNull(pReturned = (byte*)XMALLOC(pSz, NULL,
  75300. DYNAMIC_TYPE_TMP_BUFFER));
  75301. ExpectIntGT((pSz = wolfSSL_BN_bn2bin(pBn, pReturned)), 0);
  75302. ExpectIntEQ(pSz, sizeof(pExpected));
  75303. ExpectIntEQ(XMEMCMP(pExpected, pReturned, pSz), 0);
  75304. ExpectIntGT((qSz = wolfSSL_BN_num_bytes(qBn)), 0);
  75305. ExpectNotNull(qReturned = (byte*)XMALLOC(qSz, NULL,
  75306. DYNAMIC_TYPE_TMP_BUFFER));
  75307. ExpectIntGT((qSz = wolfSSL_BN_bn2bin(qBn, qReturned)), 0);
  75308. ExpectIntEQ(qSz, sizeof(qExpected));
  75309. ExpectIntEQ(XMEMCMP(qExpected, qReturned, qSz), 0);
  75310. ExpectIntGT((gSz = wolfSSL_BN_num_bytes(gBn)), 0);
  75311. ExpectNotNull(gReturned = (byte*)XMALLOC(gSz, NULL,
  75312. DYNAMIC_TYPE_TMP_BUFFER));
  75313. ExpectIntGT((gSz = wolfSSL_BN_bn2bin(gBn, gReturned)), 0);
  75314. ExpectIntEQ(gSz, sizeof(gExpected));
  75315. ExpectIntEQ(XMEMCMP(gExpected, gReturned, gSz), 0);
  75316. wolfSSL_DH_free(dh);
  75317. XFREE(pReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75318. XFREE(gReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75319. XFREE(qReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75320. #endif
  75321. return EXPECT_RESULT();
  75322. }
  75323. static int test_wolfSSL_PEM_write_DHparams(void)
  75324. {
  75325. EXPECT_DECLS;
  75326. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO) && \
  75327. !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  75328. DH* dh = NULL;
  75329. BIO* bio = NULL;
  75330. XFILE fp = XBADFILE;
  75331. byte pem[2048];
  75332. int pemSz = 0;
  75333. const char expected[] =
  75334. "-----BEGIN DH PARAMETERS-----\n"
  75335. "MIIBCAKCAQEAsKEIBpwIE7pZBjy8MNX1AMFPRKfW70rGJScc6NKWUwpckd2iwpSE\n"
  75336. "v32yRJ+b0sGKxb5yXKfnkebUn3MHhVtmSMdw+rTuAsk9mkraPcFGPhlp0RdGB6NN\n"
  75337. "nyuWFzltMI0q85TTdc+gdebykh8acAWqBINXMPvadpM4UOgn/WPuPOW3yAmub1A1\n"
  75338. "joTOSgDpEn5aMdcz/CETdswWMNsM/MVipzW477ewrMA29tnJRkj5QJAAKxuqbOMa\n"
  75339. "wwsDnhvCRuRITiJzb8Nf1JrWMAdI1oyQq9T28eNI01hLprnNKb9oHwhLY4YvXGvW\n"
  75340. "tgZl96bcAGdru8OpQYP7x/rI4h5+rwA/kwIBAg==\n"
  75341. "-----END DH PARAMETERS-----\n";
  75342. const char badPem[] =
  75343. "-----BEGIN DH PARAMETERS-----\n"
  75344. "-----END DH PARAMETERS-----\n";
  75345. const char emptySeqPem[] =
  75346. "-----BEGIN DH PARAMETERS-----\n"
  75347. "MAA=\n"
  75348. "-----END DH PARAMETERS-----\n";
  75349. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  75350. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75351. if (fp != XBADFILE) {
  75352. XFCLOSE(fp);
  75353. fp = XBADFILE;
  75354. }
  75355. ExpectNull(PEM_read_bio_DHparams(NULL, NULL, NULL, NULL));
  75356. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75357. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75358. ExpectIntEQ(BIO_write(bio, badPem, (int)sizeof(badPem)),
  75359. (int)sizeof(badPem));
  75360. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75361. BIO_free(bio);
  75362. bio = NULL;
  75363. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75364. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75365. ExpectIntEQ(BIO_write(bio, emptySeqPem, (int)sizeof(emptySeqPem)),
  75366. (int)sizeof(emptySeqPem));
  75367. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75368. BIO_free(bio);
  75369. bio = NULL;
  75370. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75371. ExpectIntEQ(BIO_write(bio, pem, pemSz), pemSz);
  75372. ExpectNotNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75373. BIO_free(bio);
  75374. bio = NULL;
  75375. ExpectNotNull(fp = XFOPEN("./test-write-dhparams.pem", "wb"));
  75376. ExpectIntEQ(PEM_write_DHparams(fp, dh), WOLFSSL_SUCCESS);
  75377. ExpectIntEQ(PEM_write_DHparams(fp, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75378. DH_free(dh);
  75379. dh = NULL;
  75380. dh = wolfSSL_DH_new();
  75381. ExpectIntEQ(PEM_write_DHparams(fp, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75382. if (fp != XBADFILE) {
  75383. XFCLOSE(fp);
  75384. fp = XBADFILE;
  75385. }
  75386. wolfSSL_DH_free(dh);
  75387. dh = NULL;
  75388. /* check results */
  75389. XMEMSET(pem, 0, sizeof(pem));
  75390. ExpectTrue((fp = XFOPEN("./test-write-dhparams.pem", "rb")) != XBADFILE);
  75391. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75392. ExpectIntEQ(XMEMCMP(pem, expected, pemSz), 0);
  75393. if (fp != XBADFILE)
  75394. XFCLOSE(fp);
  75395. #endif
  75396. return EXPECT_RESULT();
  75397. }
  75398. static int test_wolfSSL_d2i_DHparams(void)
  75399. {
  75400. EXPECT_DECLS;
  75401. #ifdef OPENSSL_ALL
  75402. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  75403. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  75404. XFILE f = XBADFILE;
  75405. unsigned char buf[4096];
  75406. const unsigned char* pt = buf;
  75407. #ifdef HAVE_FFDHE_2048
  75408. const char* params1 = "./certs/dh2048.der";
  75409. #endif
  75410. #ifdef HAVE_FFDHE_3072
  75411. const char* params2 = "./certs/dh3072.der";
  75412. #endif
  75413. long len = 0;
  75414. WOLFSSL_DH* dh = NULL;
  75415. XMEMSET(buf, 0, sizeof(buf));
  75416. /* Test 2048 bit parameters */
  75417. #ifdef HAVE_FFDHE_2048
  75418. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  75419. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75420. if (f != XBADFILE) {
  75421. XFCLOSE(f);
  75422. f = XBADFILE;
  75423. }
  75424. /* Valid case */
  75425. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75426. ExpectNotNull(dh->p);
  75427. ExpectNotNull(dh->g);
  75428. ExpectTrue(pt == buf);
  75429. ExpectIntEQ(DH_set_length(NULL, BN_num_bits(dh->p)), 0);
  75430. ExpectIntEQ(DH_set_length(dh, BN_num_bits(dh->p)), 1);
  75431. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  75432. /* Invalid cases */
  75433. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75434. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75435. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, 10));
  75436. DH_free(dh);
  75437. dh = NULL;
  75438. *buf = 0;
  75439. pt = buf;
  75440. #endif /* HAVE_FFDHE_2048 */
  75441. /* Test 3072 bit parameters */
  75442. #ifdef HAVE_FFDHE_3072
  75443. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  75444. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75445. if (f != XBADFILE) {
  75446. XFCLOSE(f);
  75447. f = XBADFILE;
  75448. }
  75449. /* Valid case */
  75450. ExpectNotNull(dh = wolfSSL_d2i_DHparams(&dh, &pt, len));
  75451. ExpectNotNull(dh->p);
  75452. ExpectNotNull(dh->g);
  75453. ExpectTrue(pt != buf);
  75454. ExpectIntEQ(DH_generate_key(dh), 1);
  75455. /* Invalid cases */
  75456. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75457. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75458. DH_free(dh);
  75459. dh = NULL;
  75460. #endif /* HAVE_FFDHE_3072 */
  75461. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  75462. #endif /* !NO_DH */
  75463. #endif
  75464. return EXPECT_RESULT();
  75465. }
  75466. static int test_wolfSSL_DH_LoadDer(void)
  75467. {
  75468. EXPECT_DECLS;
  75469. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)) && \
  75470. defined(OPENSSL_EXTRA)
  75471. static const byte dh2048[] = {
  75472. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  75473. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  75474. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  75475. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  75476. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  75477. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75478. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75479. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75480. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75481. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75482. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75483. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75484. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75485. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75486. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75487. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75488. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75489. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75490. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75491. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75492. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75493. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75494. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75495. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75496. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75497. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75498. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75499. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75500. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75501. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75502. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75503. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75504. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75505. 0x93, 0x02, 0x01, 0x02
  75506. };
  75507. WOLFSSL_DH* dh = NULL;
  75508. ExpectNotNull(dh = wolfSSL_DH_new());
  75509. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, NULL, 0), -1);
  75510. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, NULL, 0), -1);
  75511. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, dh2048, sizeof(dh2048)), -1);
  75512. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, dh2048, sizeof(dh2048)), 1);
  75513. wolfSSL_DH_free(dh);
  75514. #endif
  75515. return EXPECT_RESULT();
  75516. }
  75517. static int test_wolfSSL_i2d_DHparams(void)
  75518. {
  75519. EXPECT_DECLS;
  75520. #ifdef OPENSSL_ALL
  75521. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  75522. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  75523. XFILE f = XBADFILE;
  75524. unsigned char buf[4096];
  75525. const unsigned char* pt;
  75526. unsigned char* pt2;
  75527. #ifdef HAVE_FFDHE_2048
  75528. const char* params1 = "./certs/dh2048.der";
  75529. #endif
  75530. #ifdef HAVE_FFDHE_3072
  75531. const char* params2 = "./certs/dh3072.der";
  75532. #endif
  75533. long len = 0;
  75534. WOLFSSL_DH* dh = NULL;
  75535. /* Test 2048 bit parameters */
  75536. #ifdef HAVE_FFDHE_2048
  75537. pt = buf;
  75538. pt2 = buf;
  75539. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  75540. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75541. if (f != XBADFILE) {
  75542. XFCLOSE(f);
  75543. f = XBADFILE;
  75544. }
  75545. /* Valid case */
  75546. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75547. ExpectTrue(pt == buf);
  75548. ExpectIntEQ(DH_generate_key(dh), 1);
  75549. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 268);
  75550. /* Invalid case */
  75551. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  75552. /* Return length only */
  75553. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268);
  75554. DH_free(dh);
  75555. dh = NULL;
  75556. *buf = 0;
  75557. #endif
  75558. /* Test 3072 bit parameters */
  75559. #ifdef HAVE_FFDHE_3072
  75560. pt = buf;
  75561. pt2 = buf;
  75562. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  75563. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75564. if (f != XBADFILE) {
  75565. XFCLOSE(f);
  75566. f = XBADFILE;
  75567. }
  75568. /* Valid case */
  75569. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75570. ExpectTrue(pt == buf);
  75571. ExpectIntEQ(DH_generate_key(dh), 1);
  75572. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 396);
  75573. /* Invalid case */
  75574. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  75575. /* Return length only */
  75576. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396);
  75577. DH_free(dh);
  75578. dh = NULL;
  75579. #endif
  75580. dh = DH_new();
  75581. ExpectNotNull(dh);
  75582. pt2 = buf;
  75583. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0);
  75584. DH_free(dh);
  75585. dh = NULL;
  75586. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  75587. #endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */
  75588. #endif
  75589. return EXPECT_RESULT();
  75590. }
  75591. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  75592. /*----------------------------------------------------------------------------*
  75593. | EC
  75594. *----------------------------------------------------------------------------*/
  75595. static int test_wolfSSL_EC_GROUP(void)
  75596. {
  75597. EXPECT_DECLS;
  75598. #ifdef OPENSSL_EXTRA
  75599. EC_GROUP *group = NULL;
  75600. EC_GROUP *group2 = NULL;
  75601. EC_GROUP *group3 = NULL;
  75602. #ifndef HAVE_ECC_BRAINPOOL
  75603. EC_GROUP *group4 = NULL;
  75604. #endif
  75605. WOLFSSL_BIGNUM* order = NULL;
  75606. int group_bits;
  75607. int i;
  75608. static const int knownEccNids[] = {
  75609. NID_X9_62_prime192v1,
  75610. NID_X9_62_prime192v2,
  75611. NID_X9_62_prime192v3,
  75612. NID_X9_62_prime239v1,
  75613. NID_X9_62_prime239v2,
  75614. NID_X9_62_prime239v3,
  75615. NID_X9_62_prime256v1,
  75616. NID_secp112r1,
  75617. NID_secp112r2,
  75618. NID_secp128r1,
  75619. NID_secp128r2,
  75620. NID_secp160r1,
  75621. NID_secp160r2,
  75622. NID_secp224r1,
  75623. NID_secp384r1,
  75624. NID_secp521r1,
  75625. NID_secp160k1,
  75626. NID_secp192k1,
  75627. NID_secp224k1,
  75628. NID_secp256k1,
  75629. NID_brainpoolP160r1,
  75630. NID_brainpoolP192r1,
  75631. NID_brainpoolP224r1,
  75632. NID_brainpoolP256r1,
  75633. NID_brainpoolP320r1,
  75634. NID_brainpoolP384r1,
  75635. NID_brainpoolP512r1,
  75636. };
  75637. int knowEccNidsLen = (int)(sizeof(knownEccNids) / sizeof(*knownEccNids));
  75638. static const int knownEccEnums[] = {
  75639. ECC_SECP192R1,
  75640. ECC_PRIME192V2,
  75641. ECC_PRIME192V3,
  75642. ECC_PRIME239V1,
  75643. ECC_PRIME239V2,
  75644. ECC_PRIME239V3,
  75645. ECC_SECP256R1,
  75646. ECC_SECP112R1,
  75647. ECC_SECP112R2,
  75648. ECC_SECP128R1,
  75649. ECC_SECP128R2,
  75650. ECC_SECP160R1,
  75651. ECC_SECP160R2,
  75652. ECC_SECP224R1,
  75653. ECC_SECP384R1,
  75654. ECC_SECP521R1,
  75655. ECC_SECP160K1,
  75656. ECC_SECP192K1,
  75657. ECC_SECP224K1,
  75658. ECC_SECP256K1,
  75659. ECC_BRAINPOOLP160R1,
  75660. ECC_BRAINPOOLP192R1,
  75661. ECC_BRAINPOOLP224R1,
  75662. ECC_BRAINPOOLP256R1,
  75663. ECC_BRAINPOOLP320R1,
  75664. ECC_BRAINPOOLP384R1,
  75665. ECC_BRAINPOOLP512R1,
  75666. };
  75667. int knowEccEnumsLen = (int)(sizeof(knownEccEnums) / sizeof(*knownEccEnums));
  75668. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  75669. ExpectNotNull(group2 = EC_GROUP_dup(group));
  75670. ExpectNotNull(group3 = wolfSSL_EC_GROUP_new_by_curve_name(NID_secp384r1));
  75671. #ifndef HAVE_ECC_BRAINPOOL
  75672. ExpectNotNull(group4 = wolfSSL_EC_GROUP_new_by_curve_name(
  75673. NID_brainpoolP256r1));
  75674. #endif
  75675. ExpectNull(EC_GROUP_dup(NULL));
  75676. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(NULL), 0);
  75677. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  75678. ExpectIntEQ((group_bits = EC_GROUP_order_bits(NULL)), 0);
  75679. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group)), 256);
  75680. #ifndef HAVE_ECC_BRAINPOOL
  75681. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group4)), 0);
  75682. #endif
  75683. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(NULL), 0);
  75684. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(group), 256);
  75685. ExpectNotNull(order = BN_new());
  75686. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, NULL, NULL), 0);
  75687. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, NULL, NULL), 0);
  75688. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, order, NULL), 0);
  75689. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, order, NULL), 1);
  75690. wolfSSL_BN_free(order);
  75691. ExpectNotNull(EC_GROUP_method_of(group));
  75692. ExpectIntEQ(EC_METHOD_get_field_type(NULL), 0);
  75693. ExpectIntEQ(EC_METHOD_get_field_type(EC_GROUP_method_of(group)),
  75694. NID_X9_62_prime_field);
  75695. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, NULL, NULL), -1);
  75696. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, NULL, NULL), -1);
  75697. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, group, NULL), -1);
  75698. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, group3, NULL), 1);
  75699. #ifndef NO_WOLFSSL_STUB
  75700. wolfSSL_EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
  75701. #endif
  75702. #ifndef HAVE_ECC_BRAINPOOL
  75703. EC_GROUP_free(group4);
  75704. #endif
  75705. EC_GROUP_free(group3);
  75706. EC_GROUP_free(group2);
  75707. EC_GROUP_free(group);
  75708. for (i = 0; i < knowEccNidsLen; i++) {
  75709. group = NULL;
  75710. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccNids[i]));
  75711. ExpectIntGT(wolfSSL_EC_GROUP_get_degree(group), 0);
  75712. EC_GROUP_free(group);
  75713. }
  75714. for (i = 0; i < knowEccEnumsLen; i++) {
  75715. group = NULL;
  75716. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccEnums[i]));
  75717. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), knownEccNids[i]);
  75718. EC_GROUP_free(group);
  75719. }
  75720. #endif
  75721. return EXPECT_RESULT();
  75722. }
  75723. static int test_wolfSSL_PEM_read_bio_ECPKParameters(void)
  75724. {
  75725. EXPECT_DECLS;
  75726. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  75727. EC_GROUP *group = NULL;
  75728. BIO* bio = NULL;
  75729. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  75730. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  75731. EC_GROUP *ret = NULL;
  75732. static char ec_nc_p384[] = "-----BEGIN EC PARAMETERS-----\n"
  75733. "BgUrgQQAIg==\n"
  75734. "-----END EC PARAMETERS-----";
  75735. #endif
  75736. static char ec_nc_bad_1[] = "-----BEGIN EC PARAMETERS-----\n"
  75737. "MAA=\n"
  75738. "-----END EC PARAMETERS-----";
  75739. static char ec_nc_bad_2[] = "-----BEGIN EC PARAMETERS-----\n"
  75740. "BgA=\n"
  75741. "-----END EC PARAMETERS-----";
  75742. static char ec_nc_bad_3[] = "-----BEGIN EC PARAMETERS-----\n"
  75743. "BgE=\n"
  75744. "-----END EC PARAMETERS-----";
  75745. static char ec_nc_bad_4[] = "-----BEGIN EC PARAMETERS-----\n"
  75746. "BgE*\n"
  75747. "-----END EC PARAMETERS-----";
  75748. /* Test that first parameter, bio, being NULL fails. */
  75749. ExpectNull(PEM_read_bio_ECPKParameters(NULL, NULL, NULL, NULL));
  75750. /* Test that reading named parameters works. */
  75751. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  75752. ExpectIntEQ(BIO_read_filename(bio, eccKeyFile), WOLFSSL_SUCCESS);
  75753. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  75754. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  75755. BIO_free(bio);
  75756. bio = NULL;
  75757. EC_GROUP_free(group);
  75758. group = NULL;
  75759. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  75760. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  75761. /* Test that reusing group works. */
  75762. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  75763. sizeof(ec_nc_p384)));
  75764. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  75765. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  75766. BIO_free(bio);
  75767. bio = NULL;
  75768. EC_GROUP_free(group);
  75769. group = NULL;
  75770. /* Test that returning through group works. */
  75771. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  75772. sizeof(ec_nc_p384)));
  75773. ExpectNotNull(ret = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  75774. ExpectIntEQ(group == ret, 1);
  75775. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  75776. BIO_free(bio);
  75777. bio = NULL;
  75778. EC_GROUP_free(group);
  75779. group = NULL;
  75780. #endif
  75781. /* Test 0x30, 0x00 (not and object id) fails. */
  75782. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_1,
  75783. sizeof(ec_nc_bad_1)));
  75784. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  75785. BIO_free(bio);
  75786. bio = NULL;
  75787. /* Test 0x06, 0x00 (empty object id) fails. */
  75788. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_2,
  75789. sizeof(ec_nc_bad_2)));
  75790. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  75791. BIO_free(bio);
  75792. bio = NULL;
  75793. /* Test 0x06, 0x01 (badly formed object id) fails. */
  75794. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_3,
  75795. sizeof(ec_nc_bad_3)));
  75796. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  75797. BIO_free(bio);
  75798. bio = NULL;
  75799. /* Test invalid PEM encoding - invalid character. */
  75800. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_4,
  75801. sizeof(ec_nc_bad_4)));
  75802. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  75803. BIO_free(bio);
  75804. #endif
  75805. return EXPECT_RESULT();
  75806. }
  75807. static int test_wolfSSL_EC_POINT(void)
  75808. {
  75809. EXPECT_DECLS;
  75810. #if !defined(WOLFSSL_SP_MATH) && \
  75811. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  75812. #ifdef OPENSSL_EXTRA
  75813. BN_CTX* ctx = NULL;
  75814. EC_GROUP* group = NULL;
  75815. #ifndef HAVE_ECC_BRAINPOOL
  75816. EC_GROUP* group2 = NULL;
  75817. #endif
  75818. EC_POINT* Gxy = NULL;
  75819. EC_POINT* new_point = NULL;
  75820. EC_POINT* set_point = NULL;
  75821. EC_POINT* get_point = NULL;
  75822. EC_POINT* infinity = NULL;
  75823. BIGNUM* k = NULL;
  75824. BIGNUM* Gx = NULL;
  75825. BIGNUM* Gy = NULL;
  75826. BIGNUM* Gz = NULL;
  75827. BIGNUM* X = NULL;
  75828. BIGNUM* Y = NULL;
  75829. BIGNUM* set_point_bn = NULL;
  75830. char* hexStr = NULL;
  75831. const char* kTest = "F4F8338AFCC562C5C3F3E1E46A7EFECD"
  75832. "17AF381913FF7A96314EA47055EA0FD0";
  75833. /* NISTP256R1 Gx/Gy */
  75834. const char* kGx = "6B17D1F2E12C4247F8BCE6E563A440F2"
  75835. "77037D812DEB33A0F4A13945D898C296";
  75836. const char* kGy = "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  75837. "2BCE33576B315ECECBB6406837BF51F5";
  75838. const char* uncompG
  75839. = "046B17D1F2E12C4247F8BCE6E563A440F2"
  75840. "77037D812DEB33A0F4A13945D898C296"
  75841. "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  75842. "2BCE33576B315ECECBB6406837BF51F5";
  75843. const char* compG
  75844. = "036B17D1F2E12C4247F8BCE6E563A440F2"
  75845. "77037D812DEB33A0F4A13945D898C296";
  75846. #ifndef HAVE_SELFTEST
  75847. EC_POINT *tmp = NULL;
  75848. size_t bin_len;
  75849. unsigned int blen = 0;
  75850. unsigned char* buf = NULL;
  75851. unsigned char bufInf[1] = { 0x00 };
  75852. const unsigned char binUncompG[] = {
  75853. 0x04, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  75854. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  75855. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  75856. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  75857. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  75858. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  75859. };
  75860. const unsigned char binUncompGBad[] = {
  75861. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  75862. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  75863. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  75864. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  75865. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  75866. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  75867. };
  75868. #ifdef HAVE_COMP_KEY
  75869. const unsigned char binCompG[] = {
  75870. 0x03, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  75871. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  75872. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  75873. };
  75874. #endif
  75875. #endif
  75876. ExpectNotNull(ctx = BN_CTX_new());
  75877. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  75878. #ifndef HAVE_ECC_BRAINPOOL
  75879. /* Used to make groups curve_idx == -1. */
  75880. ExpectNotNull(group2 = EC_GROUP_new_by_curve_name(NID_brainpoolP256r1));
  75881. #endif
  75882. ExpectNull(EC_POINT_new(NULL));
  75883. ExpectNotNull(Gxy = EC_POINT_new(group));
  75884. ExpectNotNull(new_point = EC_POINT_new(group));
  75885. ExpectNotNull(set_point = EC_POINT_new(group));
  75886. ExpectNotNull(X = BN_new());
  75887. ExpectNotNull(Y = BN_new());
  75888. ExpectNotNull(set_point_bn = BN_new());
  75889. ExpectNotNull(infinity = EC_POINT_new(group));
  75890. /* load test values */
  75891. ExpectIntEQ(BN_hex2bn(&k, kTest), WOLFSSL_SUCCESS);
  75892. ExpectIntEQ(BN_hex2bn(&Gx, kGx), WOLFSSL_SUCCESS);
  75893. ExpectIntEQ(BN_hex2bn(&Gy, kGy), WOLFSSL_SUCCESS);
  75894. ExpectIntEQ(BN_hex2bn(&Gz, "1"), WOLFSSL_SUCCESS);
  75895. /* populate coordinates for input point */
  75896. if (Gxy != NULL) {
  75897. Gxy->X = Gx;
  75898. Gxy->Y = Gy;
  75899. Gxy->Z = Gz;
  75900. }
  75901. /* Test handling of NULL point. */
  75902. EC_POINT_clear_free(NULL);
  75903. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  75904. NULL, NULL, ctx), 0);
  75905. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  75906. NULL, NULL, ctx), 0);
  75907. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  75908. NULL, NULL, ctx), 0);
  75909. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  75910. X, NULL, ctx), 0);
  75911. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  75912. NULL, Y, ctx), 0);
  75913. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  75914. X, Y, ctx), 0);
  75915. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  75916. X, Y, ctx), 0);
  75917. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  75918. NULL, Y, ctx), 0);
  75919. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  75920. X, NULL, ctx), 0);
  75921. /* Getting point at infinity returns an error. */
  75922. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, infinity,
  75923. X, Y, ctx), 0);
  75924. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  75925. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  75926. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  75927. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, NULL, ctx), 0);
  75928. ExpectIntEQ(EC_POINT_add(group, NULL, NULL, NULL, ctx), 0);
  75929. ExpectIntEQ(EC_POINT_add(NULL, new_point, NULL, NULL, ctx), 0);
  75930. ExpectIntEQ(EC_POINT_add(NULL, NULL, new_point, NULL, ctx), 0);
  75931. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, Gxy, ctx), 0);
  75932. ExpectIntEQ(EC_POINT_add(NULL, new_point, new_point, Gxy, ctx), 0);
  75933. ExpectIntEQ(EC_POINT_add(group, NULL, new_point, Gxy, ctx), 0);
  75934. ExpectIntEQ(EC_POINT_add(group, new_point, NULL, Gxy, ctx), 0);
  75935. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, NULL, ctx), 0);
  75936. ExpectIntEQ(EC_POINT_mul(NULL, NULL, Gx, Gxy, k, ctx), 0);
  75937. ExpectIntEQ(EC_POINT_mul(NULL, new_point, Gx, Gxy, k, ctx), 0);
  75938. ExpectIntEQ(EC_POINT_mul(group, NULL, Gx, Gxy, k, ctx), 0);
  75939. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, Gxy, ctx), 1);
  75940. /* perform point multiplication */
  75941. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, Gxy, k, ctx), 1);
  75942. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  75943. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  75944. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  75945. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, Gxy, k, ctx), 1);
  75946. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  75947. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  75948. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  75949. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, NULL, NULL, ctx), 1);
  75950. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  75951. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  75952. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  75953. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, NULL, NULL, ctx), 1);
  75954. ExpectIntEQ(BN_is_zero(new_point->X), 1);
  75955. ExpectIntEQ(BN_is_zero(new_point->Y), 1);
  75956. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  75957. /* Set point to something. */
  75958. ExpectIntEQ(EC_POINT_add(group, new_point, Gxy, Gxy, ctx), 1);
  75959. #else
  75960. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, new_point, Gx, Gy,
  75961. ctx), 1);
  75962. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  75963. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  75964. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  75965. #endif
  75966. /* check if point X coordinate is zero */
  75967. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  75968. #if defined(USE_ECC_B_PARAM) && !defined(HAVE_SELFTEST) && \
  75969. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  75970. ExpectIntEQ(EC_POINT_is_on_curve(group, new_point, ctx), 1);
  75971. #endif
  75972. /* extract the coordinates from point */
  75973. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  75974. ctx), WOLFSSL_SUCCESS);
  75975. /* check if point X coordinate is zero */
  75976. ExpectIntEQ(BN_is_zero(X), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75977. /* set the same X and Y points in another object */
  75978. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, set_point, X, Y,
  75979. ctx), WOLFSSL_SUCCESS);
  75980. /* compare points as they should be the same */
  75981. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, NULL, ctx), -1);
  75982. ExpectIntEQ(EC_POINT_cmp(group, NULL, NULL, ctx), -1);
  75983. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, NULL, ctx), -1);
  75984. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, set_point, ctx), -1);
  75985. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, set_point, ctx), -1);
  75986. ExpectIntEQ(EC_POINT_cmp(group, NULL, set_point, ctx), -1);
  75987. ExpectIntEQ(EC_POINT_cmp(group, new_point, NULL, ctx), -1);
  75988. ExpectIntEQ(EC_POINT_cmp(group, new_point, set_point, ctx), 0);
  75989. /* Test copying */
  75990. ExpectIntEQ(EC_POINT_copy(NULL, NULL), 0);
  75991. ExpectIntEQ(EC_POINT_copy(NULL, set_point), 0);
  75992. ExpectIntEQ(EC_POINT_copy(new_point, NULL), 0);
  75993. ExpectIntEQ(EC_POINT_copy(new_point, set_point), 1);
  75994. /* Test inverting */
  75995. ExpectIntEQ(EC_POINT_invert(NULL, NULL, ctx), 0);
  75996. ExpectIntEQ(EC_POINT_invert(NULL, new_point, ctx), 0);
  75997. ExpectIntEQ(EC_POINT_invert(group, NULL, ctx), 0);
  75998. ExpectIntEQ(EC_POINT_invert(group, new_point, ctx), 1);
  75999. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  76000. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  76001. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76002. {
  76003. EC_POINT* orig_point = NULL;
  76004. ExpectNotNull(orig_point = EC_POINT_new(group));
  76005. ExpectIntEQ(EC_POINT_add(group, orig_point, set_point, set_point, NULL),
  76006. 1);
  76007. /* new_point should be set_point inverted so adding it will revert
  76008. * the point back to set_point */
  76009. ExpectIntEQ(EC_POINT_add(group, orig_point, orig_point, new_point,
  76010. NULL), 1);
  76011. ExpectIntEQ(EC_POINT_cmp(group, orig_point, set_point, NULL), 0);
  76012. EC_POINT_free(orig_point);
  76013. }
  76014. #endif
  76015. /* Test getting affine converts from projective. */
  76016. ExpectIntEQ(EC_POINT_copy(set_point, new_point), 1);
  76017. /* Force non-affine coordinates */
  76018. ExpectIntEQ(BN_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76019. (WOLFSSL_BIGNUM*)BN_value_one()), 1);
  76020. if (new_point != NULL) {
  76021. new_point->inSet = 0;
  76022. }
  76023. /* extract the coordinates from point */
  76024. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  76025. ctx), WOLFSSL_SUCCESS);
  76026. /* check if point ordinates have changed. */
  76027. ExpectIntNE(BN_cmp(X, set_point->X), 0);
  76028. ExpectIntNE(BN_cmp(Y, set_point->Y), 0);
  76029. /* Test check for infinity */
  76030. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  76031. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, NULL), 0);
  76032. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, infinity), 0);
  76033. ExpectIntEQ(EC_POINT_is_at_infinity(group, NULL), 0);
  76034. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 1);
  76035. ExpectIntEQ(EC_POINT_is_at_infinity(group, Gxy), 0);
  76036. #else
  76037. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 0);
  76038. #endif
  76039. ExpectPtrEq(EC_POINT_point2bn(group, set_point,
  76040. POINT_CONVERSION_UNCOMPRESSED, set_point_bn, ctx), set_point_bn);
  76041. /* check bn2hex */
  76042. hexStr = BN_bn2hex(k);
  76043. ExpectStrEQ(hexStr, kTest);
  76044. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76045. defined(XFPRINTF)
  76046. BN_print_fp(stderr, k);
  76047. fprintf(stderr, "\n");
  76048. #endif
  76049. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76050. hexStr = BN_bn2hex(Gx);
  76051. ExpectStrEQ(hexStr, kGx);
  76052. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76053. defined(XFPRINTF)
  76054. BN_print_fp(stderr, Gx);
  76055. fprintf(stderr, "\n");
  76056. #endif
  76057. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76058. hexStr = BN_bn2hex(Gy);
  76059. ExpectStrEQ(hexStr, kGy);
  76060. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76061. defined(XFPRINTF)
  76062. BN_print_fp(stderr, Gy);
  76063. fprintf(stderr, "\n");
  76064. #endif
  76065. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76066. /* Test point to hex */
  76067. ExpectNull(EC_POINT_point2hex(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76068. ctx));
  76069. ExpectNull(EC_POINT_point2hex(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76070. ctx));
  76071. ExpectNull(EC_POINT_point2hex(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76072. ctx));
  76073. #ifndef HAVE_ECC_BRAINPOOL
  76074. /* Group not supported in wolfCrypt. */
  76075. ExpectNull(EC_POINT_point2hex(group2, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76076. ctx));
  76077. #endif
  76078. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_UNCOMPRESSED, ctx);
  76079. ExpectNotNull(hexStr);
  76080. ExpectStrEQ(hexStr, uncompG);
  76081. ExpectNotNull(get_point = EC_POINT_hex2point(group, hexStr, NULL, ctx));
  76082. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76083. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76084. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_COMPRESSED, ctx);
  76085. ExpectNotNull(hexStr);
  76086. ExpectStrEQ(hexStr, compG);
  76087. #ifdef HAVE_COMP_KEY
  76088. ExpectNotNull(get_point = EC_POINT_hex2point
  76089. (group, hexStr, get_point, ctx));
  76090. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76091. #endif
  76092. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76093. EC_POINT_free(get_point);
  76094. #ifndef HAVE_SELFTEST
  76095. /* Test point to oct */
  76096. ExpectIntEQ(EC_POINT_point2oct(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76097. NULL, 0, ctx), 0);
  76098. ExpectIntEQ(EC_POINT_point2oct(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76099. NULL, 0, ctx), 0);
  76100. ExpectIntEQ(EC_POINT_point2oct(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76101. NULL, 0, ctx), 0);
  76102. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76103. NULL, 0, ctx);
  76104. ExpectIntEQ(bin_len, sizeof(binUncompG));
  76105. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76106. DYNAMIC_TYPE_ECC));
  76107. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76108. buf, bin_len, ctx), bin_len);
  76109. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76110. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76111. /* Infinity (x=0, y=0) encodes as '0x00'. */
  76112. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76113. POINT_CONVERSION_UNCOMPRESSED, NULL, 0, ctx), 1);
  76114. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76115. POINT_CONVERSION_UNCOMPRESSED, bufInf, 0, ctx), 0);
  76116. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76117. POINT_CONVERSION_UNCOMPRESSED, bufInf, 1, ctx), 1);
  76118. ExpectIntEQ(bufInf[0], 0);
  76119. wolfSSL_EC_POINT_dump(NULL, NULL);
  76120. /* Test point i2d */
  76121. ExpectIntEQ(ECPoint_i2d(NULL, NULL, NULL, &blen), 0);
  76122. ExpectIntEQ(ECPoint_i2d(NULL, Gxy, NULL, &blen), 0);
  76123. ExpectIntEQ(ECPoint_i2d(group, NULL, NULL, &blen), 0);
  76124. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, NULL), 0);
  76125. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, &blen), 1);
  76126. ExpectIntEQ(blen, sizeof(binUncompG));
  76127. ExpectNotNull(buf = (unsigned char*)XMALLOC(blen, NULL, DYNAMIC_TYPE_ECC));
  76128. blen -= 1;
  76129. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 0);
  76130. blen += 1;
  76131. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 1);
  76132. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76133. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76134. #ifdef HAVE_COMP_KEY
  76135. /* Test point to oct compressed */
  76136. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, NULL,
  76137. 0, ctx);
  76138. ExpectIntEQ(bin_len, sizeof(binCompG));
  76139. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76140. DYNAMIC_TYPE_ECC));
  76141. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, buf,
  76142. bin_len, ctx), bin_len);
  76143. ExpectIntEQ(XMEMCMP(buf, binCompG, sizeof(binCompG)), 0);
  76144. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76145. #endif
  76146. /* Test point BN */
  76147. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, NULL,
  76148. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76149. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, Gxy,
  76150. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76151. ExpectNull(wolfSSL_EC_POINT_point2bn(group, NULL,
  76152. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76153. ExpectNull(wolfSSL_EC_POINT_point2bn(group, Gxy, 0, NULL, ctx));
  76154. /* Test oct to point */
  76155. ExpectNotNull(tmp = EC_POINT_new(group));
  76156. ExpectIntEQ(EC_POINT_oct2point(NULL, NULL, binUncompG, sizeof(binUncompG),
  76157. ctx), 0);
  76158. ExpectIntEQ(EC_POINT_oct2point(NULL, tmp, binUncompG, sizeof(binUncompG),
  76159. ctx), 0);
  76160. ExpectIntEQ(EC_POINT_oct2point(group, NULL, binUncompG, sizeof(binUncompG),
  76161. ctx), 0);
  76162. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompGBad,
  76163. sizeof(binUncompGBad), ctx), 0);
  76164. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompG, sizeof(binUncompG),
  76165. ctx), 1);
  76166. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76167. EC_POINT_free(tmp);
  76168. tmp = NULL;
  76169. /* Test setting BN ordinates. */
  76170. ExpectNotNull(tmp = EC_POINT_new(group));
  76171. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76172. NULL, ctx), 0);
  76173. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, NULL,
  76174. NULL, ctx), 0);
  76175. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, NULL,
  76176. NULL, ctx), 0);
  76177. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, Gx,
  76178. NULL, ctx), 0);
  76179. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76180. Gy, ctx), 0);
  76181. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, Gx, Gy,
  76182. ctx), 0);
  76183. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, Gx, Gy,
  76184. ctx), 0);
  76185. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, NULL,
  76186. Gy, ctx), 0);
  76187. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx,
  76188. NULL, ctx), 0);
  76189. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx, Gy,
  76190. ctx), 1);
  76191. EC_POINT_free(tmp);
  76192. tmp = NULL;
  76193. /* Test point d2i */
  76194. ExpectNotNull(tmp = EC_POINT_new(group));
  76195. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, NULL), 0);
  76196. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, NULL), 0);
  76197. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, NULL), 0);
  76198. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, tmp), 0);
  76199. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, tmp), 0);
  76200. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, tmp), 0);
  76201. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, NULL), 0);
  76202. ExpectIntEQ(ECPoint_d2i(binUncompGBad, sizeof(binUncompG), group, tmp), 0);
  76203. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, tmp), 1);
  76204. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76205. EC_POINT_free(tmp);
  76206. tmp = NULL;
  76207. #ifdef HAVE_COMP_KEY
  76208. /* Test oct compressed to point */
  76209. ExpectNotNull(tmp = EC_POINT_new(group));
  76210. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binCompG, sizeof(binCompG), ctx),
  76211. 1);
  76212. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76213. EC_POINT_free(tmp);
  76214. tmp = NULL;
  76215. /* Test point d2i - compressed */
  76216. ExpectNotNull(tmp = EC_POINT_new(group));
  76217. ExpectIntEQ(ECPoint_d2i(binCompG, sizeof(binCompG), group, tmp), 1);
  76218. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76219. EC_POINT_free(tmp);
  76220. tmp = NULL;
  76221. #endif
  76222. #endif
  76223. /* test BN_mod_add */
  76224. ExpectIntEQ(BN_mod_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76225. (WOLFSSL_BIGNUM*)BN_value_one(), (WOLFSSL_BIGNUM*)BN_value_one(), NULL),
  76226. 1);
  76227. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  76228. /* cleanup */
  76229. BN_free(X);
  76230. BN_free(Y);
  76231. BN_free(k);
  76232. BN_free(set_point_bn);
  76233. EC_POINT_free(infinity);
  76234. EC_POINT_free(new_point);
  76235. EC_POINT_free(set_point);
  76236. EC_POINT_clear_free(Gxy);
  76237. #ifndef HAVE_ECC_BRAINPOOL
  76238. EC_GROUP_free(group2);
  76239. #endif
  76240. EC_GROUP_free(group);
  76241. BN_CTX_free(ctx);
  76242. #endif
  76243. #endif /* !WOLFSSL_SP_MATH && ( !HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  76244. return EXPECT_RESULT();
  76245. }
  76246. static int test_wolfSSL_SPAKE(void)
  76247. {
  76248. EXPECT_DECLS;
  76249. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(WOLFSSL_ATECC508A) \
  76250. && !defined(WOLFSSL_ATECC608A) && !defined(HAVE_SELFTEST) && \
  76251. !defined(WOLFSSL_SP_MATH) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76252. BIGNUM* x = NULL; /* kdc priv */
  76253. BIGNUM* y = NULL; /* client priv */
  76254. BIGNUM* w = NULL; /* shared value */
  76255. byte M_bytes[] = {
  76256. /* uncompressed */
  76257. 0x04,
  76258. /* x */
  76259. 0x88, 0x6e, 0x2f, 0x97, 0xac, 0xe4, 0x6e, 0x55, 0xba, 0x9d, 0xd7, 0x24,
  76260. 0x25, 0x79, 0xf2, 0x99, 0x3b, 0x64, 0xe1, 0x6e, 0xf3, 0xdc, 0xab, 0x95,
  76261. 0xaf, 0xd4, 0x97, 0x33, 0x3d, 0x8f, 0xa1, 0x2f,
  76262. /* y */
  76263. 0x5f, 0xf3, 0x55, 0x16, 0x3e, 0x43, 0xce, 0x22, 0x4e, 0x0b, 0x0e, 0x65,
  76264. 0xff, 0x02, 0xac, 0x8e, 0x5c, 0x7b, 0xe0, 0x94, 0x19, 0xc7, 0x85, 0xe0,
  76265. 0xca, 0x54, 0x7d, 0x55, 0xa1, 0x2e, 0x2d, 0x20
  76266. };
  76267. EC_POINT* M = NULL; /* shared value */
  76268. byte N_bytes[] = {
  76269. /* uncompressed */
  76270. 0x04,
  76271. /* x */
  76272. 0xd8, 0xbb, 0xd6, 0xc6, 0x39, 0xc6, 0x29, 0x37, 0xb0, 0x4d, 0x99, 0x7f,
  76273. 0x38, 0xc3, 0x77, 0x07, 0x19, 0xc6, 0x29, 0xd7, 0x01, 0x4d, 0x49, 0xa2,
  76274. 0x4b, 0x4f, 0x98, 0xba, 0xa1, 0x29, 0x2b, 0x49,
  76275. /* y */
  76276. 0x07, 0xd6, 0x0a, 0xa6, 0xbf, 0xad, 0xe4, 0x50, 0x08, 0xa6, 0x36, 0x33,
  76277. 0x7f, 0x51, 0x68, 0xc6, 0x4d, 0x9b, 0xd3, 0x60, 0x34, 0x80, 0x8c, 0xd5,
  76278. 0x64, 0x49, 0x0b, 0x1e, 0x65, 0x6e, 0xdb, 0xe7
  76279. };
  76280. EC_POINT* N = NULL; /* shared value */
  76281. EC_POINT* T = NULL; /* kdc pub */
  76282. EC_POINT* tmp1 = NULL; /* kdc pub */
  76283. EC_POINT* tmp2 = NULL; /* kdc pub */
  76284. EC_POINT* S = NULL; /* client pub */
  76285. EC_POINT* client_secret = NULL;
  76286. EC_POINT* kdc_secret = NULL;
  76287. EC_GROUP* group = NULL;
  76288. BN_CTX* bn_ctx = NULL;
  76289. /* Values taken from a test run of Kerberos 5 */
  76290. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76291. ExpectNotNull(bn_ctx = BN_CTX_new());
  76292. ExpectNotNull(M = EC_POINT_new(group));
  76293. ExpectNotNull(N = EC_POINT_new(group));
  76294. ExpectNotNull(T = EC_POINT_new(group));
  76295. ExpectNotNull(tmp1 = EC_POINT_new(group));
  76296. ExpectNotNull(tmp2 = EC_POINT_new(group));
  76297. ExpectNotNull(S = EC_POINT_new(group));
  76298. ExpectNotNull(client_secret = EC_POINT_new(group));
  76299. ExpectNotNull(kdc_secret = EC_POINT_new(group));
  76300. ExpectIntEQ(BN_hex2bn(&x, "DAC3027CD692B4BDF0EDFE9B7D0E4E7"
  76301. "E5D8768A725EAEEA6FC68EC239A17C0"), 1);
  76302. ExpectIntEQ(BN_hex2bn(&y, "6F6A1D394E26B1655A54B26DCE30D49"
  76303. "90CC47EBE08F809EF3FF7F6AEAABBB5"), 1);
  76304. ExpectIntEQ(BN_hex2bn(&w, "1D992AB8BA851B9BA05353453D81EE9"
  76305. "506AB395478F0AAB647752CF117B36250"), 1);
  76306. ExpectIntEQ(EC_POINT_oct2point(group, M, M_bytes, sizeof(M_bytes), bn_ctx),
  76307. 1);
  76308. ExpectIntEQ(EC_POINT_oct2point(group, N, N_bytes, sizeof(N_bytes), bn_ctx),
  76309. 1);
  76310. /* Function pattern similar to ossl_keygen and ossl_result in krb5 */
  76311. /* kdc */
  76312. /* T=x*P+w*M */
  76313. /* All in one function call */
  76314. ExpectIntEQ(EC_POINT_mul(group, T, x, M, w, bn_ctx), 1);
  76315. /* Spread into separate calls */
  76316. ExpectIntEQ(EC_POINT_mul(group, tmp1, x, NULL, NULL, bn_ctx), 1);
  76317. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, M, w, bn_ctx), 1);
  76318. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76319. 1);
  76320. ExpectIntEQ(EC_POINT_cmp(group, T, tmp1, bn_ctx), 0);
  76321. /* client */
  76322. /* S=y*P+w*N */
  76323. /* All in one function call */
  76324. ExpectIntEQ(EC_POINT_mul(group, S, y, N, w, bn_ctx), 1);
  76325. /* Spread into separate calls */
  76326. ExpectIntEQ(EC_POINT_mul(group, tmp1, y, NULL, NULL, bn_ctx), 1);
  76327. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, N, w, bn_ctx), 1);
  76328. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76329. 1);
  76330. ExpectIntEQ(EC_POINT_cmp(group, S, tmp1, bn_ctx), 0);
  76331. /* K=y*(T-w*M) */
  76332. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, M, w, bn_ctx), 1);
  76333. ExpectIntEQ(EC_POINT_invert(group, client_secret, bn_ctx), 1);
  76334. ExpectIntEQ(EC_POINT_add(group, client_secret, T, client_secret, bn_ctx),
  76335. 1);
  76336. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, client_secret, y,
  76337. bn_ctx), 1);
  76338. /* kdc */
  76339. /* K=x*(S-w*N) */
  76340. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, N, w, bn_ctx), 1);
  76341. ExpectIntEQ(EC_POINT_invert(group, kdc_secret, bn_ctx), 1);
  76342. ExpectIntEQ(EC_POINT_add(group, kdc_secret, S, kdc_secret, bn_ctx),
  76343. 1);
  76344. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, kdc_secret, x, bn_ctx),
  76345. 1);
  76346. /* kdc_secret == client_secret */
  76347. ExpectIntEQ(EC_POINT_cmp(group, client_secret, kdc_secret, bn_ctx), 0);
  76348. BN_free(x);
  76349. BN_free(y);
  76350. BN_free(w);
  76351. EC_POINT_free(M);
  76352. EC_POINT_free(N);
  76353. EC_POINT_free(T);
  76354. EC_POINT_free(tmp1);
  76355. EC_POINT_free(tmp2);
  76356. EC_POINT_free(S);
  76357. EC_POINT_free(client_secret);
  76358. EC_POINT_free(kdc_secret);
  76359. EC_GROUP_free(group);
  76360. BN_CTX_free(bn_ctx);
  76361. #endif
  76362. return EXPECT_RESULT();
  76363. }
  76364. static int test_wolfSSL_EC_KEY_generate(void)
  76365. {
  76366. EXPECT_DECLS;
  76367. #ifdef OPENSSL_EXTRA
  76368. WOLFSSL_EC_KEY* key = NULL;
  76369. #ifndef HAVE_ECC_BRAINPOOL
  76370. WOLFSSL_EC_GROUP* group = NULL;
  76371. #endif
  76372. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76373. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(NULL), 0);
  76374. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  76375. wolfSSL_EC_KEY_free(key);
  76376. key = NULL;
  76377. #ifndef HAVE_ECC_BRAINPOOL
  76378. ExpectNotNull(group = wolfSSL_EC_GROUP_new_by_curve_name(
  76379. NID_brainpoolP256r1));
  76380. ExpectNotNull(key = wolfSSL_EC_KEY_new());
  76381. ExpectIntEQ(wolfSSL_EC_KEY_set_group(key, group), 1);
  76382. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 0);
  76383. wolfSSL_EC_KEY_free(key);
  76384. wolfSSL_EC_GROUP_free(group);
  76385. #endif
  76386. #endif
  76387. return EXPECT_RESULT();
  76388. }
  76389. static int test_EC_i2d(void)
  76390. {
  76391. EXPECT_DECLS;
  76392. #if defined(OPENSSL_EXTRA) && !defined(HAVE_FIPS)
  76393. EC_KEY *key = NULL;
  76394. EC_KEY *copy = NULL;
  76395. int len = 0;
  76396. unsigned char *buf = NULL;
  76397. unsigned char *p = NULL;
  76398. const unsigned char *tmp = NULL;
  76399. const unsigned char octBad[] = {
  76400. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76401. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76402. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76403. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76404. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76405. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76406. };
  76407. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76408. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  76409. ExpectIntGT((len = i2d_EC_PUBKEY(key, NULL)), 0);
  76410. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76411. DYNAMIC_TYPE_TMP_BUFFER));
  76412. p = buf;
  76413. ExpectIntEQ(i2d_EC_PUBKEY(key, &p), len);
  76414. ExpectNull(o2i_ECPublicKey(NULL, NULL, -1));
  76415. ExpectNull(o2i_ECPublicKey(&copy, NULL, -1));
  76416. ExpectNull(o2i_ECPublicKey(&key, NULL, -1));
  76417. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76418. ExpectNull(o2i_ECPublicKey(NULL, NULL, 0));
  76419. ExpectNull(o2i_ECPublicKey(&key, NULL, 0));
  76420. ExpectNull(o2i_ECPublicKey(&key, &tmp, 0));
  76421. tmp = buf;
  76422. ExpectNull(o2i_ECPublicKey(NULL, &tmp, 0));
  76423. ExpectNull(o2i_ECPublicKey(&copy, &tmp, 0));
  76424. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76425. ExpectNull(o2i_ECPublicKey(&key, &tmp, -1));
  76426. ExpectIntEQ(i2o_ECPublicKey(NULL, NULL), 0);
  76427. ExpectIntEQ(i2o_ECPublicKey(NULL, &buf), 0);
  76428. tmp = buf;
  76429. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 0));
  76430. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 1));
  76431. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 0));
  76432. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 1));
  76433. ExpectNull(d2i_ECPrivateKey(&key, &tmp, 0));
  76434. {
  76435. EC_KEY *pubkey = NULL;
  76436. BIO* bio = NULL;
  76437. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76438. ExpectIntGT(BIO_write(bio, buf, len), 0);
  76439. ExpectNotNull(d2i_EC_PUBKEY_bio(bio, &pubkey));
  76440. BIO_free(bio);
  76441. EC_KEY_free(pubkey);
  76442. }
  76443. ExpectIntEQ(i2d_ECPrivateKey(NULL, &p), 0);
  76444. ExpectIntEQ(i2d_ECPrivateKey(NULL, NULL), 0);
  76445. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer(NULL, NULL, -1), -1);
  76446. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1, 0), -1);
  76447. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, -1, 0), -1);
  76448. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, -1, 0), -1);
  76449. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, 0, 0), -1);
  76450. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1,
  76451. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76452. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, len,
  76453. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76454. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, len,
  76455. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76456. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, -1,
  76457. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76458. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len, 0), -1);
  76459. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len,
  76460. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76461. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76462. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76463. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76464. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76465. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76466. buf = NULL;
  76467. buf = NULL;
  76468. ExpectIntGT((len = i2d_ECPrivateKey(key, NULL)), 0);
  76469. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76470. DYNAMIC_TYPE_TMP_BUFFER));
  76471. p = buf;
  76472. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76473. p = NULL;
  76474. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76475. XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76476. p = NULL;
  76477. /* Bad point is also an invalid private key. */
  76478. tmp = octBad;
  76479. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, sizeof(octBad)));
  76480. tmp = buf;
  76481. ExpectNotNull(d2i_ECPrivateKey(&copy, &tmp, len));
  76482. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76483. buf = NULL;
  76484. buf = NULL;
  76485. ExpectIntGT((len = i2o_ECPublicKey(key, NULL)), 0);
  76486. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76487. DYNAMIC_TYPE_TMP_BUFFER));
  76488. p = buf;
  76489. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76490. p = NULL;
  76491. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76492. tmp = buf;
  76493. ExpectNotNull(o2i_ECPublicKey(&copy, &tmp, len));
  76494. tmp = octBad;
  76495. ExpectNull(o2i_ECPublicKey(&key, &tmp, sizeof(octBad)));
  76496. ExpectIntEQ(EC_KEY_check_key(NULL), 0);
  76497. ExpectIntEQ(EC_KEY_check_key(key), 1);
  76498. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  76499. XFREE(buf, NULL, DYNAMIC_TYPE_OPENSSL);
  76500. EC_KEY_free(key);
  76501. EC_KEY_free(copy);
  76502. #endif
  76503. return EXPECT_RESULT();
  76504. }
  76505. static int test_wolfSSL_EC_curve(void)
  76506. {
  76507. EXPECT_DECLS;
  76508. #if defined(OPENSSL_EXTRA)
  76509. int nid = NID_secp160k1;
  76510. const char* nid_name = NULL;
  76511. ExpectNull(EC_curve_nid2nist(NID_sha256));
  76512. ExpectNotNull(nid_name = EC_curve_nid2nist(nid));
  76513. ExpectIntEQ(XMEMCMP(nid_name, "K-160", XSTRLEN("K-160")), 0);
  76514. ExpectIntEQ(EC_curve_nist2nid("INVALID"), 0);
  76515. ExpectIntEQ(EC_curve_nist2nid(nid_name), nid);
  76516. #endif
  76517. return EXPECT_RESULT();
  76518. }
  76519. static int test_wolfSSL_EC_KEY_dup(void)
  76520. {
  76521. EXPECT_DECLS;
  76522. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  76523. WOLFSSL_EC_KEY* ecKey = NULL;
  76524. WOLFSSL_EC_KEY* dupKey = NULL;
  76525. ecc_key* srcKey = NULL;
  76526. ecc_key* destKey = NULL;
  76527. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76528. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76529. /* Valid cases */
  76530. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76531. ExpectIntEQ(EC_KEY_check_key(dupKey), 1);
  76532. /* Compare pubkey */
  76533. if (ecKey != NULL) {
  76534. srcKey = (ecc_key*)ecKey->internal;
  76535. }
  76536. if (dupKey != NULL) {
  76537. destKey = (ecc_key*)dupKey->internal;
  76538. }
  76539. ExpectIntEQ(wc_ecc_cmp_point(&srcKey->pubkey, &destKey->pubkey), 0);
  76540. /* compare EC_GROUP */
  76541. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(ecKey->group, dupKey->group, NULL), MP_EQ);
  76542. /* compare EC_POINT */
  76543. ExpectIntEQ(wolfSSL_EC_POINT_cmp(ecKey->group, ecKey->pub_key, \
  76544. dupKey->pub_key, NULL), MP_EQ);
  76545. /* compare BIGNUM */
  76546. ExpectIntEQ(wolfSSL_BN_cmp(ecKey->priv_key, dupKey->priv_key), MP_EQ);
  76547. wolfSSL_EC_KEY_free(dupKey);
  76548. dupKey = NULL;
  76549. /* Invalid cases */
  76550. /* NULL key */
  76551. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(NULL));
  76552. /* NULL ecc_key */
  76553. if (ecKey != NULL) {
  76554. wc_ecc_free((ecc_key*)ecKey->internal);
  76555. XFREE(ecKey->internal, NULL, DYNAMIC_TYPE_ECC);
  76556. ecKey->internal = NULL; /* Set ecc_key to NULL */
  76557. }
  76558. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76559. wolfSSL_EC_KEY_free(ecKey);
  76560. ecKey = NULL;
  76561. wolfSSL_EC_KEY_free(dupKey);
  76562. dupKey = NULL;
  76563. /* NULL Group */
  76564. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76565. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76566. if (ecKey != NULL) {
  76567. wolfSSL_EC_GROUP_free(ecKey->group);
  76568. ecKey->group = NULL; /* Set group to NULL */
  76569. }
  76570. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76571. wolfSSL_EC_KEY_free(ecKey);
  76572. ecKey = NULL;
  76573. wolfSSL_EC_KEY_free(dupKey);
  76574. dupKey = NULL;
  76575. /* NULL public key */
  76576. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76577. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76578. if (ecKey != NULL) {
  76579. wc_ecc_del_point((ecc_point*)ecKey->pub_key->internal);
  76580. ecKey->pub_key->internal = NULL; /* Set ecc_point to NULL */
  76581. }
  76582. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76583. if (ecKey != NULL) {
  76584. wolfSSL_EC_POINT_free(ecKey->pub_key);
  76585. ecKey->pub_key = NULL; /* Set pub_key to NULL */
  76586. }
  76587. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76588. wolfSSL_EC_KEY_free(ecKey);
  76589. ecKey = NULL;
  76590. wolfSSL_EC_KEY_free(dupKey);
  76591. dupKey = NULL;
  76592. /* NULL private key */
  76593. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76594. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76595. if (ecKey != NULL) {
  76596. wolfSSL_BN_free(ecKey->priv_key);
  76597. ecKey->priv_key = NULL; /* Set priv_key to NULL */
  76598. }
  76599. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76600. wolfSSL_EC_KEY_free(ecKey);
  76601. ecKey = NULL;
  76602. wolfSSL_EC_KEY_free(dupKey);
  76603. dupKey = NULL;
  76604. /* Test EC_KEY_up_ref */
  76605. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76606. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), WOLFSSL_SUCCESS);
  76607. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76608. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(ecKey), WOLFSSL_SUCCESS);
  76609. /* reference count doesn't follow duplicate */
  76610. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76611. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +1 */
  76612. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +2 */
  76613. wolfSSL_EC_KEY_free(dupKey); /* 3 */
  76614. wolfSSL_EC_KEY_free(dupKey); /* 2 */
  76615. wolfSSL_EC_KEY_free(dupKey); /* 1, free */
  76616. wolfSSL_EC_KEY_free(ecKey); /* 2 */
  76617. wolfSSL_EC_KEY_free(ecKey); /* 1, free */
  76618. #endif
  76619. return EXPECT_RESULT();
  76620. }
  76621. static int test_wolfSSL_EC_KEY_set_group(void)
  76622. {
  76623. EXPECT_DECLS;
  76624. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  76625. defined(OPENSSL_EXTRA)
  76626. EC_KEY *key = NULL;
  76627. EC_GROUP *group = NULL;
  76628. const EC_GROUP *group2 = NULL;
  76629. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76630. ExpectNotNull(key = EC_KEY_new());
  76631. ExpectNull(EC_KEY_get0_group(NULL));
  76632. ExpectIntEQ(EC_KEY_set_group(NULL, NULL), 0);
  76633. ExpectIntEQ(EC_KEY_set_group(key, NULL), 0);
  76634. ExpectIntEQ(EC_KEY_set_group(NULL, group), 0);
  76635. ExpectIntEQ(EC_KEY_set_group(key, group), WOLFSSL_SUCCESS);
  76636. ExpectNotNull(group2 = EC_KEY_get0_group(key));
  76637. ExpectIntEQ(EC_GROUP_cmp(group2, group, NULL), 0);
  76638. EC_GROUP_free(group);
  76639. EC_KEY_free(key);
  76640. #endif
  76641. return EXPECT_RESULT();
  76642. }
  76643. static int test_wolfSSL_EC_KEY_set_conv_form(void)
  76644. {
  76645. EXPECT_DECLS;
  76646. #if defined(HAVE_ECC) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76647. BIO* bio = NULL;
  76648. EC_KEY* key = NULL;
  76649. /* Error condition: NULL key. */
  76650. ExpectIntLT(EC_KEY_get_conv_form(NULL), 0);
  76651. ExpectNotNull(bio = BIO_new_file("./certs/ecc-keyPub.pem", "rb"));
  76652. ExpectNotNull(key = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  76653. /* Conversion form defaults to uncompressed. */
  76654. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  76655. #ifdef HAVE_COMP_KEY
  76656. /* Explicitly set to compressed. */
  76657. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  76658. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_COMPRESSED);
  76659. #else
  76660. /* Will still work just won't change anything. */
  76661. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  76662. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  76663. EC_KEY_set_conv_form(key, POINT_CONVERSION_UNCOMPRESSED);
  76664. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  76665. #endif
  76666. EC_KEY_set_conv_form(NULL, POINT_CONVERSION_UNCOMPRESSED);
  76667. BIO_free(bio);
  76668. EC_KEY_free(key);
  76669. #endif
  76670. return EXPECT_RESULT();
  76671. }
  76672. static int test_wolfSSL_EC_KEY_private_key(void)
  76673. {
  76674. EXPECT_DECLS;
  76675. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76676. WOLFSSL_EC_KEY* key = NULL;
  76677. WOLFSSL_BIGNUM* priv = NULL;
  76678. WOLFSSL_BIGNUM* priv2 = NULL;
  76679. WOLFSSL_BIGNUM* bn;
  76680. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76681. ExpectNotNull(priv = wolfSSL_BN_new());
  76682. ExpectNotNull(priv2 = wolfSSL_BN_new());
  76683. ExpectIntNE(BN_set_word(priv, 2), 0);
  76684. ExpectIntNE(BN_set_word(priv2, 2), 0);
  76685. ExpectNull(wolfSSL_EC_KEY_get0_private_key(NULL));
  76686. /* No private key set. */
  76687. ExpectNull(wolfSSL_EC_KEY_get0_private_key(key));
  76688. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, NULL), 0);
  76689. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, NULL), 0);
  76690. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, priv), 0);
  76691. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv), 1);
  76692. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  76693. ExpectPtrNE(bn, priv);
  76694. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv2), 1);
  76695. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  76696. ExpectPtrNE(bn, priv2);
  76697. wolfSSL_BN_free(priv2);
  76698. wolfSSL_BN_free(priv);
  76699. wolfSSL_EC_KEY_free(key);
  76700. #endif
  76701. return EXPECT_RESULT();
  76702. }
  76703. static int test_wolfSSL_EC_KEY_public_key(void)
  76704. {
  76705. EXPECT_DECLS;
  76706. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76707. WOLFSSL_EC_KEY* key = NULL;
  76708. WOLFSSL_EC_POINT* pub = NULL;
  76709. WOLFSSL_EC_POINT* point = NULL;
  76710. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76711. ExpectNull(wolfSSL_EC_KEY_get0_public_key(NULL));
  76712. ExpectNotNull(wolfSSL_EC_KEY_get0_public_key(key));
  76713. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  76714. ExpectNotNull(pub = wolfSSL_EC_KEY_get0_public_key(key));
  76715. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, NULL), 0);
  76716. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, NULL), 0);
  76717. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, pub), 0);
  76718. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, pub), 1);
  76719. ExpectNotNull(point = wolfSSL_EC_KEY_get0_public_key(key));
  76720. ExpectPtrEq(point, pub);
  76721. wolfSSL_EC_KEY_free(key);
  76722. #endif
  76723. return EXPECT_RESULT();
  76724. }
  76725. static int test_wolfSSL_EC_KEY_print_fp(void)
  76726. {
  76727. EXPECT_DECLS;
  76728. #if defined(HAVE_ECC) && ((defined(HAVE_ECC224) && defined(HAVE_ECC256)) || \
  76729. defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224 && \
  76730. defined(OPENSSL_EXTRA) && defined(XFPRINTF) && !defined(NO_FILESYSTEM) && \
  76731. !defined(NO_STDIO_FILESYSTEM)
  76732. EC_KEY* key = NULL;
  76733. /* Bad file pointer. */
  76734. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(NULL, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76735. /* NULL key. */
  76736. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76737. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(NID_secp224r1)));
  76738. /* Negative indent. */
  76739. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76740. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  76741. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  76742. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  76743. wolfSSL_EC_KEY_free(key);
  76744. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(
  76745. NID_X9_62_prime256v1)));
  76746. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  76747. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  76748. wolfSSL_EC_KEY_free(key);
  76749. #endif
  76750. return EXPECT_RESULT();
  76751. }
  76752. static int test_wolfSSL_EC_get_builtin_curves(void)
  76753. {
  76754. EXPECT_DECLS;
  76755. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  76756. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  76757. EC_builtin_curve* curves = NULL;
  76758. size_t crv_len = 0;
  76759. size_t i = 0;
  76760. ExpectIntGT((crv_len = EC_get_builtin_curves(NULL, 0)), 0);
  76761. ExpectNotNull(curves = (EC_builtin_curve*)XMALLOC(
  76762. sizeof(EC_builtin_curve) * crv_len, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  76763. ExpectIntEQ((EC_get_builtin_curves(curves, 0)), crv_len);
  76764. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len), crv_len);
  76765. for (i = 0; EXPECT_SUCCESS() && (i < crv_len); i++) {
  76766. if (curves[i].comment != NULL) {
  76767. ExpectStrEQ(OBJ_nid2sn(curves[i].nid), curves[i].comment);
  76768. }
  76769. }
  76770. if (crv_len > 1) {
  76771. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len - 1), crv_len - 1);
  76772. }
  76773. XFREE(curves, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76774. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  76775. #endif /* OPENSSL_EXTRA || OPENSSL_ALL */
  76776. return EXPECT_RESULT();
  76777. }
  76778. static int test_wolfSSL_ECDSA_SIG(void)
  76779. {
  76780. EXPECT_DECLS;
  76781. #ifdef OPENSSL_EXTRA
  76782. WOLFSSL_ECDSA_SIG* sig = NULL;
  76783. WOLFSSL_ECDSA_SIG* sig2 = NULL;
  76784. WOLFSSL_BIGNUM* r = NULL;
  76785. WOLFSSL_BIGNUM* s = NULL;
  76786. const WOLFSSL_BIGNUM* r2 = NULL;
  76787. const WOLFSSL_BIGNUM* s2 = NULL;
  76788. const unsigned char* cp = NULL;
  76789. unsigned char* p = NULL;
  76790. unsigned char outSig[8];
  76791. unsigned char sigData[8] =
  76792. { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  76793. unsigned char sigDataBad[8] =
  76794. { 0x30, 0x07, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  76795. wolfSSL_ECDSA_SIG_free(NULL);
  76796. ExpectNotNull(sig = wolfSSL_ECDSA_SIG_new());
  76797. ExpectNotNull(r = wolfSSL_BN_new());
  76798. ExpectNotNull(s = wolfSSL_BN_new());
  76799. ExpectIntEQ(wolfSSL_BN_set_word(r, 1), 1);
  76800. ExpectIntEQ(wolfSSL_BN_set_word(s, 1), 1);
  76801. wolfSSL_ECDSA_SIG_get0(NULL, NULL, NULL);
  76802. wolfSSL_ECDSA_SIG_get0(NULL, &r2, NULL);
  76803. wolfSSL_ECDSA_SIG_get0(NULL, NULL, &s2);
  76804. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  76805. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, NULL), 0);
  76806. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, NULL), 0);
  76807. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, NULL), 0);
  76808. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, s), 0);
  76809. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, s), 0);
  76810. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, s), 0);
  76811. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, NULL), 0);
  76812. r2 = NULL;
  76813. s2 = NULL;
  76814. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  76815. ExpectNull(r2);
  76816. ExpectNull(s2);
  76817. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, s), 1);
  76818. if (EXPECT_FAIL()) {
  76819. wolfSSL_BN_free(r);
  76820. wolfSSL_BN_free(s);
  76821. }
  76822. wolfSSL_ECDSA_SIG_get0(sig, &r2, &s2);
  76823. ExpectPtrEq(r2, r);
  76824. ExpectPtrEq(s2, s);
  76825. r2 = NULL;
  76826. wolfSSL_ECDSA_SIG_get0(sig, &r2, NULL);
  76827. ExpectPtrEq(r2, r);
  76828. s2 = NULL;
  76829. wolfSSL_ECDSA_SIG_get0(sig, NULL, &s2);
  76830. ExpectPtrEq(s2, s);
  76831. /* r and s are freed when sig is freed. */
  76832. wolfSSL_ECDSA_SIG_free(sig);
  76833. sig = NULL;
  76834. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, NULL, sizeof(sigData)));
  76835. cp = sigDataBad;
  76836. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigDataBad)));
  76837. cp = sigData;
  76838. ExpectNotNull((sig = wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigData))));
  76839. ExpectIntEQ((cp == sigData + 8), 1);
  76840. cp = sigData;
  76841. ExpectNull(wolfSSL_d2i_ECDSA_SIG(&sig, NULL, sizeof(sigData)));
  76842. ExpectNotNull((sig2 = wolfSSL_d2i_ECDSA_SIG(&sig, &cp, sizeof(sigData))));
  76843. ExpectIntEQ((sig == sig2), 1);
  76844. cp = outSig;
  76845. p = outSig;
  76846. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, &p), 0);
  76847. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, NULL), 0);
  76848. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, NULL), 8);
  76849. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), sizeof(sigData));
  76850. ExpectIntEQ((p == outSig + 8), 1);
  76851. ExpectIntEQ(XMEMCMP(sigData, outSig, 8), 0);
  76852. p = NULL;
  76853. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), 8);
  76854. #ifndef WOLFSSL_I2D_ECDSA_SIG_ALLOC
  76855. ExpectNull(p);
  76856. #else
  76857. ExpectNotNull(p);
  76858. ExpectIntEQ(XMEMCMP(p, outSig, 8), 0);
  76859. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  76860. #endif
  76861. wolfSSL_ECDSA_SIG_free(sig);
  76862. #endif
  76863. return EXPECT_RESULT();
  76864. }
  76865. static int test_ECDSA_size_sign(void)
  76866. {
  76867. EXPECT_DECLS;
  76868. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  76869. EC_KEY* key = NULL;
  76870. ECDSA_SIG* ecdsaSig = NULL;
  76871. int id;
  76872. byte hash[WC_MAX_DIGEST_SIZE];
  76873. byte hash2[WC_MAX_DIGEST_SIZE];
  76874. byte sig[ECC_MAX_SIG_SIZE];
  76875. unsigned int sigSz = sizeof(sig);
  76876. XMEMSET(hash, 123, sizeof(hash));
  76877. XMEMSET(hash2, 234, sizeof(hash2));
  76878. id = wc_ecc_get_curve_id_from_name("SECP256R1");
  76879. ExpectIntEQ(id, ECC_SECP256R1);
  76880. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76881. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  76882. ExpectIntGE(ECDSA_size(NULL), 0);
  76883. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, NULL), 0);
  76884. ExpectIntEQ(ECDSA_sign(0, NULL, sizeof(hash), sig, &sigSz, key), 0);
  76885. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), NULL, &sigSz, key), 0);
  76886. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, NULL), 0);
  76887. ExpectIntEQ(ECDSA_verify(0, NULL, sizeof(hash), sig, (int)sigSz, key), 0);
  76888. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), NULL, (int)sigSz, key), 0);
  76889. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
  76890. ExpectIntGE(ECDSA_size(key), sigSz);
  76891. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, key), 1);
  76892. ExpectIntEQ(ECDSA_verify(0, hash2, sizeof(hash2), sig, (int)sigSz, key), 0);
  76893. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), NULL));
  76894. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), key));
  76895. ExpectNull(ECDSA_do_sign(hash, sizeof(hash), NULL));
  76896. ExpectNotNull(ecdsaSig = ECDSA_do_sign(hash, sizeof(hash), key));
  76897. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, NULL), -1);
  76898. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, NULL), -1);
  76899. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, NULL), -1);
  76900. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, key), -1);
  76901. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, key), -1);
  76902. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, key), -1);
  76903. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, NULL), -1);
  76904. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, key), 1);
  76905. ExpectIntEQ(ECDSA_do_verify(hash2, sizeof(hash2), ecdsaSig, key), 0);
  76906. ECDSA_SIG_free(ecdsaSig);
  76907. EC_KEY_free(key);
  76908. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP */
  76909. return EXPECT_RESULT();
  76910. }
  76911. static int test_ECDH_compute_key(void)
  76912. {
  76913. EXPECT_DECLS;
  76914. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  76915. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76916. EC_KEY* key1 = NULL;
  76917. EC_KEY* key2 = NULL;
  76918. EC_POINT* pub1 = NULL;
  76919. EC_POINT* pub2 = NULL;
  76920. byte secret1[32];
  76921. byte secret2[32];
  76922. int i;
  76923. ExpectNotNull(key1 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76924. ExpectIntEQ(EC_KEY_generate_key(key1), 1);
  76925. ExpectNotNull(pub1 = wolfSSL_EC_KEY_get0_public_key(key1));
  76926. ExpectNotNull(key2 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76927. ExpectIntEQ(EC_KEY_generate_key(key2), 1);
  76928. ExpectNotNull(pub2 = wolfSSL_EC_KEY_get0_public_key(key2));
  76929. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, NULL, NULL), 0);
  76930. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, NULL, NULL),
  76931. 0);
  76932. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, NULL, NULL), 0);
  76933. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, key1, NULL), 0);
  76934. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, key1, NULL), 0);
  76935. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, key1, NULL),
  76936. 0);
  76937. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, NULL, NULL),
  76938. 0);
  76939. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1) - 16, pub2, key1,
  76940. NULL), 0);
  76941. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, key1, NULL),
  76942. sizeof(secret1));
  76943. ExpectIntEQ(ECDH_compute_key(secret2, sizeof(secret2), pub1, key2, NULL),
  76944. sizeof(secret2));
  76945. for (i = 0; i < (int)sizeof(secret1); i++) {
  76946. ExpectIntEQ(secret1[i], secret2[i]);
  76947. }
  76948. EC_KEY_free(key2);
  76949. EC_KEY_free(key1);
  76950. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP &&
  76951. * !WOLF_CRYPTO_CB_ONLY_ECC */
  76952. return EXPECT_RESULT();
  76953. }
  76954. #endif /* HAVE_ECC && !OPENSSL_NO_PK */
  76955. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  76956. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  76957. !defined(NO_ASN_TIME)
  76958. static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey,
  76959. int expectedDerSz)
  76960. {
  76961. EXPECT_DECLS;
  76962. X509* x509 = NULL;
  76963. BIGNUM* serial_number = NULL;
  76964. X509_NAME* name = NULL;
  76965. time_t epoch_off = 0;
  76966. ASN1_INTEGER* asn1_serial_number;
  76967. long not_before, not_after;
  76968. int derSz;
  76969. ExpectNotNull(x509 = X509_new());
  76970. ExpectIntNE(X509_set_pubkey(x509, pkey), 0);
  76971. ExpectNotNull(serial_number = BN_new());
  76972. ExpectIntNE(BN_pseudo_rand(serial_number, 64, 0, 0), 0);
  76973. ExpectNotNull(asn1_serial_number = X509_get_serialNumber(x509));
  76974. ExpectNotNull(BN_to_ASN1_INTEGER(serial_number, asn1_serial_number));
  76975. /* version 3 */
  76976. ExpectIntNE(X509_set_version(x509, 2L), 0);
  76977. ExpectNotNull(name = X509_NAME_new());
  76978. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
  76979. (unsigned char*)"www.wolfssl.com", -1, -1, 0), 0);
  76980. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_pkcs9_contentType,
  76981. MBSTRING_UTF8,(unsigned char*)"Server", -1, -1, 0), 0);
  76982. ExpectIntNE(X509_set_subject_name(x509, name), 0);
  76983. ExpectIntNE(X509_set_issuer_name(x509, name), 0);
  76984. not_before = (long)wc_Time(NULL);
  76985. not_after = not_before + (365 * 24 * 60 * 60);
  76986. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before,
  76987. &epoch_off));
  76988. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after,
  76989. &epoch_off));
  76990. ExpectIntNE(X509_sign(x509, pkey, EVP_sha256()), 0);
  76991. ExpectNotNull(wolfSSL_X509_get_der(x509, &derSz));
  76992. ExpectIntGE(derSz, expectedDerSz);
  76993. BN_free(serial_number);
  76994. X509_NAME_free(name);
  76995. X509_free(x509);
  76996. return EXPECT_RESULT();
  76997. }
  76998. #endif
  76999. static int test_openssl_generate_key_and_cert(void)
  77000. {
  77001. EXPECT_DECLS;
  77002. #if defined(OPENSSL_EXTRA)
  77003. int expectedDerSz;
  77004. EVP_PKEY* pkey = NULL;
  77005. #ifdef HAVE_ECC
  77006. EC_KEY* ec_key = NULL;
  77007. #endif
  77008. #if !defined(NO_RSA)
  77009. int key_length = 2048;
  77010. BIGNUM* exponent = NULL;
  77011. RSA* rsa = NULL;
  77012. ExpectNotNull(pkey = EVP_PKEY_new());
  77013. ExpectNotNull(exponent = BN_new());
  77014. ExpectNotNull(rsa = RSA_new());
  77015. ExpectIntNE(BN_set_word(exponent, WC_RSA_EXPONENT), 0);
  77016. #ifndef WOLFSSL_KEY_GEN
  77017. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77018. #if defined(USE_CERT_BUFFERS_1024)
  77019. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_1024,
  77020. sizeof_server_key_der_1024, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77021. key_length = 1024;
  77022. #elif defined(USE_CERT_BUFFERS_2048)
  77023. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_2048,
  77024. sizeof_server_key_der_2048, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77025. #else
  77026. RSA_free(rsa);
  77027. rsa = NULL;
  77028. #endif
  77029. #else
  77030. ExpectIntEQ(RSA_generate_key_ex(NULL, key_length, exponent, NULL), 0);
  77031. ExpectIntEQ(RSA_generate_key_ex(rsa, 0, exponent, NULL), 0);
  77032. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, NULL, NULL), 0);
  77033. ExpectIntNE(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77034. #endif
  77035. if (rsa) {
  77036. ExpectIntNE(EVP_PKEY_assign_RSA(pkey, rsa), 0);
  77037. if (EXPECT_FAIL()) {
  77038. RSA_free(rsa);
  77039. }
  77040. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77041. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77042. expectedDerSz = 743;
  77043. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey,
  77044. expectedDerSz), TEST_SUCCESS);
  77045. #endif
  77046. }
  77047. EVP_PKEY_free(pkey);
  77048. pkey = NULL;
  77049. BN_free(exponent);
  77050. #endif /* !NO_RSA */
  77051. #ifdef HAVE_ECC
  77052. ExpectNotNull(pkey = EVP_PKEY_new());
  77053. ExpectNotNull(ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77054. #ifndef NO_WOLFSSL_STUB
  77055. EC_KEY_set_asn1_flag(ec_key, OPENSSL_EC_NAMED_CURVE);
  77056. #endif
  77057. ExpectIntNE(EC_KEY_generate_key(ec_key), 0);
  77058. ExpectIntNE(EVP_PKEY_assign_EC_KEY(pkey, ec_key), 0);
  77059. if (EXPECT_FAIL()) {
  77060. EC_KEY_free(ec_key);
  77061. }
  77062. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77063. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77064. expectedDerSz = 344;
  77065. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey, expectedDerSz),
  77066. TEST_SUCCESS);
  77067. #endif
  77068. EVP_PKEY_free(pkey);
  77069. #endif /* HAVE_ECC */
  77070. (void)pkey;
  77071. (void)expectedDerSz;
  77072. #endif /* OPENSSL_EXTRA */
  77073. return EXPECT_RESULT();
  77074. }
  77075. static int test_stubs_are_stubs(void)
  77076. {
  77077. EXPECT_DECLS;
  77078. #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_STUB) && \
  77079. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77080. WOLFSSL_CTX* ctx = NULL;
  77081. WOLFSSL_CTX* ctxN = NULL;
  77082. #ifndef NO_WOLFSSL_CLIENT
  77083. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77084. #elif !defined(NO_WOLFSSL_SERVER)
  77085. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  77086. #endif
  77087. #define CHECKZERO_RET(x, y, z) ExpectIntEQ((int) x(y), 0); \
  77088. ExpectIntEQ((int) x(z), 0)
  77089. /* test logic, all stubs return same result regardless of ctx being NULL
  77090. * as there are no sanity checks, it's just a stub! If at some
  77091. * point a stub is not a stub it should begin to return BAD_FUNC_ARG
  77092. * if invalid inputs are supplied. Test calling both
  77093. * with and without valid inputs, if a stub functionality remains unchanged.
  77094. */
  77095. CHECKZERO_RET(wolfSSL_CTX_sess_accept, ctx, ctxN);
  77096. CHECKZERO_RET(wolfSSL_CTX_sess_connect, ctx, ctxN);
  77097. CHECKZERO_RET(wolfSSL_CTX_sess_accept_good, ctx, ctxN);
  77098. CHECKZERO_RET(wolfSSL_CTX_sess_connect_good, ctx, ctxN);
  77099. CHECKZERO_RET(wolfSSL_CTX_sess_accept_renegotiate, ctx, ctxN);
  77100. CHECKZERO_RET(wolfSSL_CTX_sess_connect_renegotiate, ctx, ctxN);
  77101. CHECKZERO_RET(wolfSSL_CTX_sess_hits, ctx, ctxN);
  77102. CHECKZERO_RET(wolfSSL_CTX_sess_cb_hits, ctx, ctxN);
  77103. CHECKZERO_RET(wolfSSL_CTX_sess_cache_full, ctx, ctxN);
  77104. CHECKZERO_RET(wolfSSL_CTX_sess_misses, ctx, ctxN);
  77105. CHECKZERO_RET(wolfSSL_CTX_sess_timeouts, ctx, ctxN);
  77106. /* when implemented this should take WOLFSSL object instead, right now
  77107. * always returns 0 */
  77108. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77109. wolfSSL_CTX_free(ctx);
  77110. ctx = NULL;
  77111. ExpectStrEQ(SSL_COMP_get_name(NULL), "not supported");
  77112. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77113. #endif /* OPENSSL_EXTRA && !NO_WOLFSSL_STUB && (!NO_WOLFSSL_CLIENT ||
  77114. * !NO_WOLFSSL_SERVER) */
  77115. return EXPECT_RESULT();
  77116. }
  77117. static int test_CONF_modules_xxx(void)
  77118. {
  77119. int res = TEST_SKIPPED;
  77120. #if defined(OPENSSL_EXTRA)
  77121. CONF_modules_free();
  77122. CONF_modules_unload(0);
  77123. CONF_modules_unload(1);
  77124. CONF_modules_unload(-1);
  77125. res = TEST_SUCCESS;
  77126. #endif /* OPENSSL_EXTRA */
  77127. return res;
  77128. }
  77129. static int test_CRYPTO_set_dynlock_xxx(void)
  77130. {
  77131. int res = TEST_SKIPPED;
  77132. #if defined(OPENSSL_EXTRA)
  77133. CRYPTO_set_dynlock_create_callback(
  77134. (struct CRYPTO_dynlock_value *(*)(const char*, int))NULL);
  77135. CRYPTO_set_dynlock_create_callback(
  77136. (struct CRYPTO_dynlock_value *(*)(const char*, int))1);
  77137. CRYPTO_set_dynlock_destroy_callback(
  77138. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))NULL);
  77139. CRYPTO_set_dynlock_destroy_callback(
  77140. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))1);
  77141. CRYPTO_set_dynlock_lock_callback(
  77142. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))NULL);
  77143. CRYPTO_set_dynlock_lock_callback(
  77144. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))1);
  77145. res = TEST_SUCCESS;
  77146. #endif /* OPENSSL_EXTRA */
  77147. return res;
  77148. }
  77149. static int test_CRYPTO_THREADID_xxx(void)
  77150. {
  77151. EXPECT_DECLS;
  77152. #if defined(OPENSSL_EXTRA)
  77153. CRYPTO_THREADID_current((CRYPTO_THREADID*)NULL);
  77154. CRYPTO_THREADID_current((CRYPTO_THREADID*)1);
  77155. ExpectIntEQ(CRYPTO_THREADID_hash((const CRYPTO_THREADID*)NULL), 0);
  77156. #endif /* OPENSSL_EXTRA */
  77157. return EXPECT_RESULT();
  77158. }
  77159. static int test_ENGINE_cleanup(void)
  77160. {
  77161. int res = TEST_SKIPPED;
  77162. #if defined(OPENSSL_EXTRA)
  77163. ENGINE_cleanup();
  77164. res = TEST_SUCCESS;
  77165. #endif /* OPENSSL_EXTRA */
  77166. return res;
  77167. }
  77168. static int test_wolfSSL_CTX_LoadCRL(void)
  77169. {
  77170. EXPECT_DECLS;
  77171. #if defined(HAVE_CRL) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  77172. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77173. WOLFSSL_CTX* ctx = NULL;
  77174. WOLFSSL* ssl = NULL;
  77175. const char* badPath = "dummypath";
  77176. const char* validPath = "./certs/crl";
  77177. const char* validFilePath = "./certs/crl/cliCrl.pem";
  77178. const char* issuerCert = "./certs/client-cert.pem";
  77179. int derType = WOLFSSL_FILETYPE_ASN1;
  77180. int pemType = WOLFSSL_FILETYPE_PEM;
  77181. #ifdef HAVE_CRL_MONITOR
  77182. int monitor = WOLFSSL_CRL_MONITOR;
  77183. #else
  77184. int monitor = 0;
  77185. #endif
  77186. WOLFSSL_CERT_MANAGER* cm = NULL;
  77187. #define FAIL_T1(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77188. WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  77189. #define FAIL_T2(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77190. WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  77191. #define SUCC_T(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77192. WOLFSSL_SUCCESS)
  77193. #ifndef NO_WOLFSSL_CLIENT
  77194. #define NEW_CTX(ctx) ExpectNotNull( \
  77195. (ctx) = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  77196. #elif !defined(NO_WOLFSSL_SERVER)
  77197. #define NEW_CTX(ctx) ExpectNotNull( \
  77198. (ctx) = wolfSSL_CTX_new(wolfSSLv23_server_method()))
  77199. #else
  77200. #define NEW_CTX(ctx) return
  77201. #endif
  77202. FAIL_T1(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77203. NEW_CTX(ctx);
  77204. #ifndef HAVE_CRL_MONITOR
  77205. FAIL_T2(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, WOLFSSL_CRL_MONITOR);
  77206. wolfSSL_CTX_free(ctx);
  77207. NEW_CTX(ctx);
  77208. #endif
  77209. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77210. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, pemType, monitor);
  77211. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, derType, monitor);
  77212. wolfSSL_CTX_free(ctx);
  77213. ctx = NULL;
  77214. NEW_CTX(ctx);
  77215. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77216. WOLFSSL_SUCCESS);
  77217. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, validFilePath, pemType), WOLFSSL_SUCCESS);
  77218. wolfSSL_CTX_free(ctx);
  77219. ctx = NULL;
  77220. NEW_CTX(ctx);
  77221. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77222. WOLFSSL_SUCCESS);
  77223. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77224. ExpectIntEQ(wolfSSL_LoadCRLFile(ssl, validFilePath, pemType), WOLFSSL_SUCCESS);
  77225. wolfSSL_free(ssl);
  77226. ssl = NULL;
  77227. wolfSSL_CTX_free(ctx);
  77228. ctx = NULL;
  77229. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  77230. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, issuerCert, NULL),
  77231. WOLFSSL_SUCCESS);
  77232. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, validFilePath, pemType),
  77233. WOLFSSL_SUCCESS);
  77234. wolfSSL_CertManagerFree(cm);
  77235. #endif
  77236. return EXPECT_RESULT();
  77237. }
  77238. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77239. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77240. static int test_multiple_crls_same_issuer_ctx_ready(WOLFSSL_CTX* ctx)
  77241. {
  77242. EXPECT_DECLS;
  77243. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  77244. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, "./certs/crl/crl.pem",
  77245. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  77246. return EXPECT_RESULT();
  77247. }
  77248. #endif
  77249. static int test_multiple_crls_same_issuer(void)
  77250. {
  77251. EXPECT_DECLS;
  77252. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77253. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77254. test_ssl_cbf client_cbs, server_cbs;
  77255. struct {
  77256. const char* server_cert;
  77257. const char* server_key;
  77258. } test_params[] = {
  77259. { "./certs/server-cert.pem", "./certs/server-key.pem" },
  77260. { "./certs/server-revoked-cert.pem", "./certs/server-revoked-key.pem" }
  77261. };
  77262. size_t i;
  77263. for (i = 0; i < (sizeof(test_params)/sizeof(*test_params)); i++) {
  77264. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77265. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77266. server_cbs.certPemFile = test_params[i].server_cert;
  77267. server_cbs.keyPemFile = test_params[i].server_key;
  77268. client_cbs.crlPemFile = "./certs/crl/extra-crls/general-server-crl.pem";
  77269. client_cbs.ctx_ready = test_multiple_crls_same_issuer_ctx_ready;
  77270. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  77271. &server_cbs, NULL), TEST_FAIL);
  77272. }
  77273. #endif
  77274. return EXPECT_RESULT();
  77275. }
  77276. static int test_SetTmpEC_DHE_Sz(void)
  77277. {
  77278. EXPECT_DECLS;
  77279. #if defined(HAVE_ECC) && !defined(NO_WOLFSSL_CLIENT)
  77280. WOLFSSL_CTX *ctx = NULL;
  77281. WOLFSSL *ssl = NULL;
  77282. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77283. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpEC_DHE_Sz(ctx, 32));
  77284. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77285. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpEC_DHE_Sz(ssl, 32));
  77286. wolfSSL_free(ssl);
  77287. wolfSSL_CTX_free(ctx);
  77288. #endif
  77289. return EXPECT_RESULT();
  77290. }
  77291. static int test_wolfSSL_CTX_get0_privatekey(void)
  77292. {
  77293. EXPECT_DECLS;
  77294. #ifdef OPENSSL_ALL
  77295. WOLFSSL_CTX* ctx = NULL;
  77296. (void)ctx;
  77297. #ifndef NO_RSA
  77298. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77299. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77300. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  77301. WOLFSSL_FILETYPE_PEM));
  77302. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77303. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  77304. WOLFSSL_FILETYPE_PEM));
  77305. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77306. wolfSSL_CTX_free(ctx);
  77307. ctx = NULL;
  77308. #endif
  77309. #ifdef HAVE_ECC
  77310. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77311. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77312. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  77313. WOLFSSL_FILETYPE_PEM));
  77314. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77315. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  77316. WOLFSSL_FILETYPE_PEM));
  77317. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77318. wolfSSL_CTX_free(ctx);
  77319. #endif
  77320. #endif
  77321. return EXPECT_RESULT();
  77322. }
  77323. static int test_wolfSSL_dtls_set_mtu(void)
  77324. {
  77325. EXPECT_DECLS;
  77326. #if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \
  77327. !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \
  77328. !defined(WOLFSSL_NO_TLS12)
  77329. WOLFSSL_CTX* ctx = NULL;
  77330. WOLFSSL* ssl = NULL;
  77331. const char* testCertFile;
  77332. const char* testKeyFile;
  77333. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  77334. #ifndef NO_RSA
  77335. testCertFile = svrCertFile;
  77336. testKeyFile = svrKeyFile;
  77337. #elif defined(HAVE_ECC)
  77338. testCertFile = eccCertFile;
  77339. testKeyFile = eccKeyFile;
  77340. #endif
  77341. if (testCertFile != NULL && testKeyFile != NULL) {
  77342. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  77343. WOLFSSL_FILETYPE_PEM));
  77344. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  77345. WOLFSSL_FILETYPE_PEM));
  77346. }
  77347. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77348. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77349. ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77350. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77351. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77352. ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77353. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS);
  77354. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS);
  77355. wolfSSL_free(ssl);
  77356. wolfSSL_CTX_free(ctx);
  77357. #endif
  77358. return EXPECT_RESULT();
  77359. }
  77360. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77361. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77362. static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq,
  77363. enum HandShakeType hsType, word16 length)
  77364. {
  77365. size_t idx = 0;
  77366. byte* l;
  77367. /* record layer */
  77368. /* handshake type */
  77369. out[idx++] = handshake;
  77370. /* protocol version */
  77371. out[idx++] = 0xfe;
  77372. out[idx++] = 0xfd; /* DTLS 1.2 */
  77373. /* epoch 0 */
  77374. XMEMSET(out + idx, 0, 2);
  77375. idx += 2;
  77376. /* sequence number */
  77377. XMEMSET(out + idx, 0, 6);
  77378. c32toa(seq, out + idx + 2);
  77379. idx += 6;
  77380. /* length in BE */
  77381. if (length)
  77382. c16toa(length, out + idx);
  77383. else
  77384. c16toa(outSz - idx - 2, out + idx);
  77385. idx += 2;
  77386. /* handshake layer */
  77387. /* handshake type */
  77388. out[idx++] = (byte)hsType;
  77389. /* length */
  77390. l = out + idx;
  77391. idx += 3;
  77392. /* message seq */
  77393. c16toa(0, out + idx);
  77394. idx += 2;
  77395. /* frag offset */
  77396. c32to24(0, out + idx);
  77397. idx += 3;
  77398. /* frag length */
  77399. c32to24((word32)outSz - (word32)idx - 3, l);
  77400. c32to24((word32)outSz - (word32)idx - 3, out + idx);
  77401. idx += 3;
  77402. XMEMSET(out + idx, 0, outSz - idx);
  77403. }
  77404. static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl)
  77405. {
  77406. byte msg[] = "This is a msg for the client";
  77407. byte reply[40];
  77408. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77409. reply[sizeof(reply) - 1] = '\0';
  77410. fprintf(stderr, "Client message: %s\n", reply);
  77411. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77412. }
  77413. static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl)
  77414. {
  77415. byte ch[50];
  77416. int fd = wolfSSL_get_fd(ssl);
  77417. byte msg[] = "This is a msg for the server";
  77418. byte reply[40];
  77419. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0);
  77420. /* Server should ignore this datagram */
  77421. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77422. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000);
  77423. /* Server should ignore this datagram */
  77424. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77425. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77426. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77427. reply[sizeof(reply) - 1] = '\0';
  77428. fprintf(stderr, "Server response: %s\n", reply);
  77429. }
  77430. static int test_wolfSSL_dtls_plaintext(void)
  77431. {
  77432. callback_functions func_cb_client;
  77433. callback_functions func_cb_server;
  77434. size_t i;
  77435. struct test_params {
  77436. method_provider client_meth;
  77437. method_provider server_meth;
  77438. ssl_callback on_result_server;
  77439. ssl_callback on_result_client;
  77440. } params[] = {
  77441. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  77442. test_wolfSSL_dtls_plaintext_server,
  77443. test_wolfSSL_dtls_plaintext_client},
  77444. };
  77445. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  77446. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  77447. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  77448. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  77449. func_cb_server.method = params[i].server_meth;
  77450. func_cb_client.method = params[i].client_meth;
  77451. func_cb_client.on_result = params[i].on_result_client;
  77452. func_cb_server.on_result = params[i].on_result_server;
  77453. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  77454. if (!func_cb_client.return_code)
  77455. return TEST_FAIL;
  77456. if (!func_cb_server.return_code)
  77457. return TEST_FAIL;
  77458. }
  77459. return TEST_RES_CHECK(1);
  77460. }
  77461. #else
  77462. static int test_wolfSSL_dtls_plaintext(void) {
  77463. return TEST_SKIPPED;
  77464. }
  77465. #endif
  77466. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77467. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77468. static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl)
  77469. {
  77470. byte b[1100]; /* buffer for the messages to send */
  77471. size_t idx = 0;
  77472. size_t seq_offset = 0;
  77473. size_t msg_offset = 0;
  77474. int i;
  77475. int fd = wolfSSL_get_fd(ssl);
  77476. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  77477. word32 seq_number = 100; /* start high so server definitely reads this */
  77478. word16 msg_number = 50; /* start high so server has to buffer this */
  77479. AssertIntEQ(ret, 1);
  77480. /* Now let's start spamming the peer with fragments it needs to store */
  77481. XMEMSET(b, -1, sizeof(b));
  77482. /* record layer */
  77483. /* handshake type */
  77484. b[idx++] = 22;
  77485. /* protocol version */
  77486. b[idx++] = 0xfe;
  77487. b[idx++] = 0xfd; /* DTLS 1.2 */
  77488. /* epoch 0 */
  77489. XMEMSET(b + idx, 0, 2);
  77490. idx += 2;
  77491. /* sequence number */
  77492. XMEMSET(b + idx, 0, 6);
  77493. seq_offset = idx + 2; /* increment only the low 32 bits */
  77494. idx += 6;
  77495. /* static length in BE */
  77496. c16toa(42, b + idx);
  77497. idx += 2;
  77498. /* handshake layer */
  77499. /* cert type */
  77500. b[idx++] = 11;
  77501. /* length */
  77502. c32to24(1000, b + idx);
  77503. idx += 3;
  77504. /* message seq */
  77505. c16toa(0, b + idx);
  77506. msg_offset = idx;
  77507. idx += 2;
  77508. /* frag offset */
  77509. c32to24(500, b + idx);
  77510. idx += 3;
  77511. /* frag length */
  77512. c32to24(30, b + idx);
  77513. idx += 3;
  77514. (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */
  77515. for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0;
  77516. seq_number++, msg_number++, i++) {
  77517. struct timespec delay;
  77518. XMEMSET(&delay, 0, sizeof(delay));
  77519. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  77520. c32toa(seq_number, b + seq_offset);
  77521. c16toa(msg_number, b + msg_offset);
  77522. ret = (int)send(fd, b, 55, 0);
  77523. nanosleep(&delay, NULL);
  77524. }
  77525. }
  77526. #ifdef WOLFSSL_DTLS13
  77527. static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
  77528. {
  77529. const word16 sendCountMax = 100;
  77530. byte b[150]; /* buffer for the messages to send */
  77531. size_t idx = 0;
  77532. size_t msg_offset = 0;
  77533. int fd = wolfSSL_get_fd(ssl);
  77534. word16 msg_number = 10; /* start high so server has to buffer this */
  77535. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  77536. AssertIntEQ(ret, 1);
  77537. /* Now let's start spamming the peer with fragments it needs to store */
  77538. XMEMSET(b, -1, sizeof(b));
  77539. /* handshake type */
  77540. b[idx++] = 11;
  77541. /* length */
  77542. c32to24(10000, b + idx);
  77543. idx += 3;
  77544. /* message_seq */
  77545. msg_offset = idx;
  77546. idx += 2;
  77547. /* fragment_offset */
  77548. c32to24(5000, b + idx);
  77549. idx += 3;
  77550. /* fragment_length */
  77551. c32to24(100, b + idx);
  77552. idx += 3;
  77553. /* fragment contents */
  77554. idx += 100;
  77555. for (; ret > 0 && msg_number < sendCountMax; msg_number++) {
  77556. byte sendBuf[150];
  77557. int sendSz = sizeof(sendBuf);
  77558. struct timespec delay;
  77559. XMEMSET(&delay, 0, sizeof(delay));
  77560. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  77561. c16toa(msg_number, b + msg_offset);
  77562. sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
  77563. (int)idx, handshake, 0, 0, 0);
  77564. ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
  77565. nanosleep(&delay, NULL);
  77566. }
  77567. }
  77568. #endif
  77569. static int test_wolfSSL_dtls_fragments(void)
  77570. {
  77571. EXPECT_DECLS;
  77572. callback_functions func_cb_client;
  77573. callback_functions func_cb_server;
  77574. size_t i;
  77575. struct test_params {
  77576. method_provider client_meth;
  77577. method_provider server_meth;
  77578. ssl_callback spammer;
  77579. } params[] = {
  77580. #if !defined(WOLFSSL_NO_TLS12)
  77581. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  77582. test_wolfSSL_dtls12_fragments_spammer},
  77583. #endif
  77584. #ifdef WOLFSSL_DTLS13
  77585. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  77586. test_wolfSSL_dtls13_fragments_spammer},
  77587. #endif
  77588. };
  77589. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  77590. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  77591. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  77592. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  77593. func_cb_server.method = params[i].server_meth;
  77594. func_cb_client.method = params[i].client_meth;
  77595. func_cb_client.ssl_ready = params[i].spammer;
  77596. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  77597. ExpectFalse(func_cb_client.return_code);
  77598. ExpectFalse(func_cb_server.return_code);
  77599. /* The socket should be closed by the server resulting in a
  77600. * socket error, fatal error or reading a close notify alert */
  77601. if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
  77602. func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
  77603. func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
  77604. ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  77605. }
  77606. /* Check the server returned an error indicating the msg buffer
  77607. * was full */
  77608. ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
  77609. if (EXPECT_FAIL())
  77610. break;
  77611. }
  77612. return EXPECT_RESULT();
  77613. }
  77614. static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl)
  77615. {
  77616. int fd, ret;
  77617. byte alert_msg[] = {
  77618. 0x15, /* alert type */
  77619. 0xfe, 0xfd, /* version */
  77620. 0x00, 0x00, /* epoch */
  77621. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */
  77622. 0x00, 0x02, /* length */
  77623. 0x02, /* level: fatal */
  77624. 0x46 /* protocol version */
  77625. };
  77626. fd = wolfSSL_get_fd(ssl);
  77627. ret = (int)send(fd, alert_msg, sizeof(alert_msg), 0);
  77628. AssertIntGT(ret, 0);
  77629. }
  77630. static int _test_wolfSSL_ignore_alert_before_cookie(byte version12)
  77631. {
  77632. callback_functions client_cbs, server_cbs;
  77633. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77634. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77635. client_cbs.doUdp = server_cbs.doUdp = 1;
  77636. if (version12) {
  77637. #if !defined(WOLFSSL_NO_TLS12)
  77638. client_cbs.method = wolfDTLSv1_2_client_method;
  77639. server_cbs.method = wolfDTLSv1_2_server_method;
  77640. #else
  77641. return TEST_SKIPPED;
  77642. #endif
  77643. }
  77644. else
  77645. {
  77646. #ifdef WOLFSSL_DTLS13
  77647. client_cbs.method = wolfDTLSv1_3_client_method;
  77648. server_cbs.method = wolfDTLSv1_3_server_method;
  77649. #else
  77650. return TEST_SKIPPED;
  77651. #endif /* WOLFSSL_DTLS13 */
  77652. }
  77653. client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert;
  77654. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  77655. if (!client_cbs.return_code)
  77656. return TEST_FAIL;
  77657. if (!server_cbs.return_code)
  77658. return TEST_FAIL;
  77659. return TEST_SUCCESS;
  77660. }
  77661. static int test_wolfSSL_ignore_alert_before_cookie(void)
  77662. {
  77663. int ret;
  77664. ret =_test_wolfSSL_ignore_alert_before_cookie(0);
  77665. if (ret != 0)
  77666. return ret;
  77667. ret =_test_wolfSSL_ignore_alert_before_cookie(1);
  77668. if (ret != 0)
  77669. return ret;
  77670. return 0;
  77671. }
  77672. static void test_wolfSSL_send_bad_record(WOLFSSL* ssl)
  77673. {
  77674. int ret;
  77675. int fd;
  77676. byte bad_msg[] = {
  77677. 0x17, /* app data */
  77678. 0xaa, 0xfd, /* bad version */
  77679. 0x00, 0x01, /* epoch 1 */
  77680. 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */
  77681. 0x00, 0x26, /* length: 38 bytes */
  77682. 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57,
  77683. 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1,
  77684. 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f,
  77685. 0x03, 0x18, 0x72
  77686. };
  77687. fd = wolfSSL_get_fd(ssl);
  77688. AssertIntGE(fd, 0);
  77689. ret = (int)send(fd, bad_msg, sizeof(bad_msg), 0);
  77690. AssertIntEQ(ret, sizeof(bad_msg));
  77691. ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest"));
  77692. AssertIntEQ(ret, sizeof("badrecordtest"));
  77693. }
  77694. static void test_wolfSSL_read_string(WOLFSSL* ssl)
  77695. {
  77696. byte buf[100];
  77697. int ret;
  77698. ret = wolfSSL_read(ssl, buf, sizeof(buf));
  77699. AssertIntGT(ret, 0);
  77700. AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0);
  77701. }
  77702. static int _test_wolfSSL_dtls_bad_record(
  77703. method_provider client_method, method_provider server_method)
  77704. {
  77705. callback_functions client_cbs, server_cbs;
  77706. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77707. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77708. client_cbs.doUdp = server_cbs.doUdp = 1;
  77709. client_cbs.method = client_method;
  77710. server_cbs.method = server_method;
  77711. client_cbs.on_result = test_wolfSSL_send_bad_record;
  77712. server_cbs.on_result = test_wolfSSL_read_string;
  77713. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  77714. if (!client_cbs.return_code)
  77715. return TEST_FAIL;
  77716. if (!server_cbs.return_code)
  77717. return TEST_FAIL;
  77718. return TEST_SUCCESS;
  77719. }
  77720. static int test_wolfSSL_dtls_bad_record(void)
  77721. {
  77722. int ret = TEST_SUCCESS;
  77723. #if !defined(WOLFSSL_NO_TLS12)
  77724. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method,
  77725. wolfDTLSv1_2_server_method);
  77726. #endif
  77727. #ifdef WOLFSSL_DTLS13
  77728. if (ret == TEST_SUCCESS) {
  77729. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method,
  77730. wolfDTLSv1_3_server_method);
  77731. }
  77732. #endif /* WOLFSSL_DTLS13 */
  77733. return ret;
  77734. }
  77735. #else
  77736. static int test_wolfSSL_dtls_fragments(void) {
  77737. return TEST_SKIPPED;
  77738. }
  77739. static int test_wolfSSL_ignore_alert_before_cookie(void) {
  77740. return TEST_SKIPPED;
  77741. }
  77742. static int test_wolfSSL_dtls_bad_record(void) {
  77743. return TEST_SKIPPED;
  77744. }
  77745. #endif
  77746. #if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \
  77747. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  77748. defined(HAVE_IO_TESTS_DEPENDENCIES)
  77749. static byte test_AEAD_fail_decryption = 0;
  77750. static byte test_AEAD_seq_num = 0;
  77751. static byte test_AEAD_done = 0;
  77752. static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  77753. {
  77754. int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
  77755. if (ret > 0) {
  77756. if (test_AEAD_fail_decryption) {
  77757. /* Modify the packet to trigger a decryption failure */
  77758. buf[ret/2] ^= 0xFF;
  77759. if (test_AEAD_fail_decryption == 1)
  77760. test_AEAD_fail_decryption = 0;
  77761. }
  77762. }
  77763. (void)ctx;
  77764. return ret;
  77765. }
  77766. static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit,
  77767. w64wrapper* keyUpdateLimit, w64wrapper* sendLimit)
  77768. {
  77769. if (sendLimit)
  77770. w64Zero(sendLimit);
  77771. switch (ssl->specs.bulk_cipher_algorithm) {
  77772. case wolfssl_aes_gcm:
  77773. if (sendLimit)
  77774. *sendLimit = AEAD_AES_LIMIT;
  77775. FALL_THROUGH;
  77776. case wolfssl_chacha:
  77777. if (hardLimit)
  77778. *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT;
  77779. if (keyUpdateLimit)
  77780. *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT;
  77781. break;
  77782. case wolfssl_aes_ccm:
  77783. if (sendLimit)
  77784. *sendLimit = DTLS_AEAD_AES_CCM_LIMIT;
  77785. if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) {
  77786. if (hardLimit)
  77787. *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT;
  77788. if (keyUpdateLimit)
  77789. *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT;
  77790. }
  77791. else {
  77792. if (hardLimit)
  77793. *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT;
  77794. if (keyUpdateLimit)
  77795. *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT;
  77796. }
  77797. break;
  77798. default:
  77799. fprintf(stderr, "Unrecognized bulk cipher");
  77800. AssertFalse(1);
  77801. break;
  77802. }
  77803. }
  77804. static void test_AEAD_limit_client(WOLFSSL* ssl)
  77805. {
  77806. int ret;
  77807. int i;
  77808. int didReKey = 0;
  77809. char msgBuf[20];
  77810. w64wrapper hardLimit;
  77811. w64wrapper keyUpdateLimit;
  77812. w64wrapper counter;
  77813. w64wrapper sendLimit;
  77814. test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit);
  77815. w64Zero(&counter);
  77816. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter));
  77817. wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv);
  77818. for (i = 0; i < 10; i++) {
  77819. /* Test some failed decryptions */
  77820. test_AEAD_fail_decryption = 1;
  77821. w64Increment(&counter);
  77822. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  77823. /* Should succeed since decryption failures are dropped */
  77824. AssertIntGT(ret, 0);
  77825. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter));
  77826. }
  77827. test_AEAD_fail_decryption = 1;
  77828. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit;
  77829. w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  77830. /* 100 read calls should be enough to complete the key update */
  77831. w64Zero(&counter);
  77832. for (i = 0; i < 100; i++) {
  77833. /* Key update should be sent and negotiated */
  77834. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  77835. AssertIntGT(ret, 0);
  77836. /* Epoch after one key update is 4 */
  77837. if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) &&
  77838. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) {
  77839. didReKey = 1;
  77840. break;
  77841. }
  77842. }
  77843. AssertTrue(didReKey);
  77844. if (!w64IsZero(sendLimit)) {
  77845. /* Test the sending limit for AEAD ciphers */
  77846. Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit;
  77847. test_AEAD_seq_num = 1;
  77848. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  77849. AssertIntGT(ret, 0);
  77850. didReKey = 0;
  77851. w64Zero(&counter);
  77852. /* 100 read calls should be enough to complete the key update */
  77853. for (i = 0; i < 100; i++) {
  77854. /* Key update should be sent and negotiated */
  77855. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  77856. AssertIntGT(ret, 0);
  77857. /* Epoch after another key update is 5 */
  77858. if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) &&
  77859. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) {
  77860. didReKey = 1;
  77861. break;
  77862. }
  77863. }
  77864. AssertTrue(didReKey);
  77865. }
  77866. test_AEAD_fail_decryption = 2;
  77867. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit;
  77868. w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  77869. /* Connection should fail with a DECRYPT_ERROR */
  77870. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  77871. AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  77872. AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR));
  77873. test_AEAD_done = 1;
  77874. }
  77875. int counter = 0;
  77876. static void test_AEAD_limit_server(WOLFSSL* ssl)
  77877. {
  77878. char msgBuf[] = "Sending data";
  77879. int ret = WOLFSSL_SUCCESS;
  77880. w64wrapper sendLimit;
  77881. SOCKET_T fd = wolfSSL_get_fd(ssl);
  77882. struct timespec delay;
  77883. XMEMSET(&delay, 0, sizeof(delay));
  77884. delay.tv_nsec = 100000000; /* wait 0.1 seconds */
  77885. tcp_set_nonblocking(&fd); /* So that read doesn't block */
  77886. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  77887. test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit);
  77888. while (!test_AEAD_done && ret > 0) {
  77889. counter++;
  77890. if (test_AEAD_seq_num) {
  77891. /* We need to update the seq number so that we can understand the
  77892. * peer. Otherwise we will incorrectly interpret the seq number. */
  77893. Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch);
  77894. AssertNotNull(e);
  77895. e->nextPeerSeqNumber = sendLimit;
  77896. test_AEAD_seq_num = 0;
  77897. }
  77898. (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  77899. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  77900. nanosleep(&delay, NULL);
  77901. }
  77902. }
  77903. static int test_wolfSSL_dtls_AEAD_limit(void)
  77904. {
  77905. callback_functions func_cb_client;
  77906. callback_functions func_cb_server;
  77907. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  77908. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  77909. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  77910. func_cb_server.method = wolfDTLSv1_3_server_method;
  77911. func_cb_client.method = wolfDTLSv1_3_client_method;
  77912. func_cb_server.on_result = test_AEAD_limit_server;
  77913. func_cb_client.on_result = test_AEAD_limit_client;
  77914. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  77915. if (!func_cb_client.return_code)
  77916. return TEST_FAIL;
  77917. if (!func_cb_server.return_code)
  77918. return TEST_FAIL;
  77919. return TEST_SUCCESS;
  77920. }
  77921. #else
  77922. static int test_wolfSSL_dtls_AEAD_limit(void)
  77923. {
  77924. return TEST_SKIPPED;
  77925. }
  77926. #endif
  77927. #if defined(WOLFSSL_DTLS) && \
  77928. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77929. !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING)
  77930. static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl)
  77931. {
  77932. int fd, ret;
  77933. byte ch_msg[] = {
  77934. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  77935. 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  77936. 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a,
  77937. 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29,
  77938. 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00,
  77939. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  77940. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  77941. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  77942. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  77943. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  77944. 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  77945. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  77946. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  77947. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  77948. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  77949. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17,
  77950. 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3,
  77951. 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6,
  77952. 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a,
  77953. 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43,
  77954. 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3,
  77955. 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d,
  77956. 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7,
  77957. 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e,
  77958. 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59,
  77959. 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0,
  77960. 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c,
  77961. 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6,
  77962. 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef,
  77963. 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45,
  77964. 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b,
  77965. 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83,
  77966. 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7,
  77967. 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2,
  77968. 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98,
  77969. 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a,
  77970. 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8,
  77971. 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d,
  77972. 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02,
  77973. 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33,
  77974. 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f,
  77975. 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3,
  77976. 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20,
  77977. 0x31, 0x68, 0x4c
  77978. };
  77979. fd = wolfSSL_get_fd(ssl);
  77980. ret = (int)send(fd, ch_msg, sizeof(ch_msg), 0);
  77981. AssertIntGT(ret, 0);
  77982. /* consume the HRR otherwise handshake will fail */
  77983. ret = (int)recv(fd, ch_msg, sizeof(ch_msg), 0);
  77984. AssertIntGT(ret, 0);
  77985. }
  77986. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  77987. static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
  77988. {
  77989. int fd, ret;
  77990. byte ch_msh_invalid_cookie[] = {
  77991. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
  77992. 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02,
  77993. 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60,
  77994. 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6,
  77995. 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00,
  77996. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  77997. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  77998. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  77999. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  78000. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  78001. 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  78002. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  78003. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  78004. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45,
  78005. 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78006. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78007. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78008. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78009. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78010. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00,
  78011. 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19,
  78012. 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00,
  78013. 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c,
  78014. 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02,
  78015. 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee,
  78016. 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f,
  78017. 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a,
  78018. 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27,
  78019. 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf,
  78020. 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1,
  78021. 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86,
  78022. 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d,
  78023. 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6,
  78024. 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7,
  78025. 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd,
  78026. 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4,
  78027. 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b,
  78028. 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0,
  78029. 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd,
  78030. 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51,
  78031. 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92,
  78032. 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e,
  78033. 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e,
  78034. 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc,
  78035. 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31,
  78036. 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d,
  78037. 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b,
  78038. 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad,
  78039. 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c,
  78040. 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00,
  78041. 0x23, 0x00, 0x00
  78042. };
  78043. byte alert_reply[50];
  78044. byte expected_alert_reply[] = {
  78045. 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  78046. 0x02, 0x02, 0x2f
  78047. };
  78048. fd = wolfSSL_get_fd(ssl);
  78049. ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
  78050. AssertIntGT(ret, 0);
  78051. /* should reply with an illegal_parameter reply */
  78052. ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
  78053. AssertIntEQ(ret, sizeof(expected_alert_reply));
  78054. AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
  78055. }
  78056. #endif
  78057. static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl)
  78058. {
  78059. #ifndef NO_MD5
  78060. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  78061. #elif !defined(NO_SHA)
  78062. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  78063. #elif !defined(NO_SHA256)
  78064. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  78065. #else
  78066. #error "We need a digest to hash the WOLFSSL object"
  78067. #endif
  78068. byte hashBuf[WC_MAX_DIGEST_SIZE];
  78069. wc_HashAlg hash;
  78070. const TLSX* exts = ssl->extensions;
  78071. WOLFSSL sslCopy; /* Use a copy to omit certain fields */
  78072. HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in
  78073. * InitHandshakeHashes */
  78074. XMEMCPY(&sslCopy, ssl, sizeof(*ssl));
  78075. XMEMSET(hashBuf, 0, sizeof(hashBuf));
  78076. /* Following fields are not important to compare */
  78077. XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78078. sslCopy.buffers.inputBuffer.buffer = NULL;
  78079. sslCopy.buffers.inputBuffer.bufferSize = 0;
  78080. sslCopy.buffers.inputBuffer.dynamicFlag = 0;
  78081. sslCopy.buffers.inputBuffer.offset = 0;
  78082. XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78083. sslCopy.buffers.outputBuffer.buffer = NULL;
  78084. sslCopy.buffers.outputBuffer.bufferSize = 0;
  78085. sslCopy.buffers.outputBuffer.dynamicFlag = 0;
  78086. sslCopy.buffers.outputBuffer.offset = 0;
  78087. sslCopy.error = 0;
  78088. sslCopy.curSize = 0;
  78089. sslCopy.curStartIdx = 0;
  78090. sslCopy.keys.curSeq_lo = 0;
  78091. XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL));
  78092. #ifdef WOLFSSL_DTLS13
  78093. XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq));
  78094. sslCopy.dtls13FastTimeout = 0;
  78095. #endif
  78096. sslCopy.keys.dtls_peer_handshake_number = 0;
  78097. XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history));
  78098. sslCopy.hsHashes = NULL;
  78099. #ifdef WOLFSSL_ASYNC_IO
  78100. #ifdef WOLFSSL_ASYNC_CRYPT
  78101. sslCopy.asyncDev = NULL;
  78102. #endif
  78103. sslCopy.async = NULL;
  78104. #endif
  78105. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  78106. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0);
  78107. /* hash extension list */
  78108. while (exts != NULL) {
  78109. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0);
  78110. exts = exts->next;
  78111. }
  78112. /* Hash suites */
  78113. if (sslCopy.suites != NULL) {
  78114. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites,
  78115. sizeof(struct Suites)), 0);
  78116. }
  78117. /* Hash hsHashes */
  78118. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes,
  78119. sizeof(*hsHashes)), 0);
  78120. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  78121. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  78122. return MakeWordFromHash(hashBuf);
  78123. }
  78124. static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb;
  78125. static int test_wolfSSL_dtls_compare_stateless_cb_call_once;
  78126. static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl,
  78127. char *buf, int sz, void *ctx)
  78128. {
  78129. if (test_wolfSSL_dtls_compare_stateless_cb_call_once) {
  78130. test_wolfSSL_dtls_compare_stateless_cb_call_once = 0;
  78131. return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx);
  78132. }
  78133. else {
  78134. return WOLFSSL_CBIO_ERR_WANT_READ;
  78135. }
  78136. }
  78137. static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl)
  78138. {
  78139. /* Compare the ssl object before and after one ClientHello msg */
  78140. SOCKET_T fd = wolfSSL_get_fd(ssl);
  78141. int res;
  78142. int err;
  78143. word32 initHash;
  78144. test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv;
  78145. test_wolfSSL_dtls_compare_stateless_cb_call_once = 1;
  78146. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  78147. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once;
  78148. initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl);
  78149. (void)initHash;
  78150. res = tcp_select(fd, 5);
  78151. /* We are expecting a msg. A timeout indicates failure. */
  78152. AssertIntEQ(res, TEST_RECV_READY);
  78153. res = wolfSSL_accept(ssl);
  78154. err = wolfSSL_get_error(ssl, res);
  78155. AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78156. AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ);
  78157. AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl));
  78158. wolfSSL_dtls_set_using_nonblock(ssl, 0);
  78159. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb;
  78160. }
  78161. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78162. static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl)
  78163. {
  78164. int ret;
  78165. ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0);
  78166. AssertIntEQ(ret, WOLFSSL_SUCCESS);
  78167. test_wolfSSL_dtls_compare_stateless(ssl);
  78168. }
  78169. #endif
  78170. static int test_wolfSSL_dtls_stateless(void)
  78171. {
  78172. callback_functions client_cbs, server_cbs;
  78173. size_t i;
  78174. struct {
  78175. method_provider client_meth;
  78176. method_provider server_meth;
  78177. ssl_callback client_ssl_ready;
  78178. ssl_callback server_ssl_ready;
  78179. } test_params[] = {
  78180. #if !defined(WOLFSSL_NO_TLS12)
  78181. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78182. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless},
  78183. #endif
  78184. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78185. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78186. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie},
  78187. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78188. test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie},
  78189. #endif
  78190. };
  78191. if (0 == sizeof(test_params)){
  78192. return TEST_SKIPPED;
  78193. }
  78194. for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) {
  78195. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78196. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78197. client_cbs.doUdp = server_cbs.doUdp = 1;
  78198. client_cbs.method = test_params[i].client_meth;
  78199. server_cbs.method = test_params[i].server_meth;
  78200. client_cbs.ssl_ready = test_params[i].client_ssl_ready;
  78201. server_cbs.ssl_ready = test_params[i].server_ssl_ready;
  78202. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78203. if (!client_cbs.return_code)
  78204. return TEST_FAIL;
  78205. if (!server_cbs.return_code)
  78206. return TEST_FAIL;
  78207. }
  78208. return TEST_SUCCESS;
  78209. }
  78210. #else
  78211. static int test_wolfSSL_dtls_stateless(void)
  78212. {
  78213. return TEST_SKIPPED;
  78214. }
  78215. #endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE &&
  78216. * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */
  78217. #ifdef HAVE_CERT_CHAIN_VALIDATION
  78218. static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78219. {
  78220. int ret;
  78221. if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) {
  78222. fprintf(stderr, "loading cert %s failed\n", certA);
  78223. fprintf(stderr, "Error: (%d): %s\n", ret,
  78224. wolfSSL_ERR_reason_error_string(ret));
  78225. return -1;
  78226. }
  78227. return 0;
  78228. }
  78229. static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78230. {
  78231. int ret;
  78232. if ((ret = wolfSSL_CertManagerVerify(cm, certA, WOLFSSL_FILETYPE_PEM))
  78233. != WOLFSSL_SUCCESS) {
  78234. fprintf(stderr, "could not verify the cert: %s\n", certA);
  78235. fprintf(stderr, "Error: (%d): %s\n", ret,
  78236. wolfSSL_ERR_reason_error_string(ret));
  78237. return -1;
  78238. }
  78239. else {
  78240. fprintf(stderr, "successfully verified: %s\n", certA);
  78241. }
  78242. return 0;
  78243. }
  78244. #define LOAD_ONE_CA(a, b, c, d) \
  78245. do { \
  78246. (a) = load_ca_into_cm(c, d); \
  78247. if ((a) != 0) \
  78248. return (b); \
  78249. else \
  78250. (b)--; \
  78251. } while(0)
  78252. #define VERIFY_ONE_CERT(a, b, c, d) \
  78253. do { \
  78254. (a) = verify_cert_with_cm(c, d);\
  78255. if ((a) != 0) \
  78256. return (b); \
  78257. else \
  78258. (b)--; \
  78259. } while(0)
  78260. static int test_chainG(WOLFSSL_CERT_MANAGER* cm)
  78261. {
  78262. int ret;
  78263. int i = -1;
  78264. /* Chain G is a valid chain per RFC 5280 section 4.2.1.9 */
  78265. char chainGArr[9][50] = {"certs/ca-cert.pem",
  78266. "certs/test-pathlen/chainG-ICA7-pathlen100.pem",
  78267. "certs/test-pathlen/chainG-ICA6-pathlen10.pem",
  78268. "certs/test-pathlen/chainG-ICA5-pathlen20.pem",
  78269. "certs/test-pathlen/chainG-ICA4-pathlen5.pem",
  78270. "certs/test-pathlen/chainG-ICA3-pathlen99.pem",
  78271. "certs/test-pathlen/chainG-ICA2-pathlen1.pem",
  78272. "certs/test-pathlen/chainG-ICA1-pathlen0.pem",
  78273. "certs/test-pathlen/chainG-entity.pem"};
  78274. LOAD_ONE_CA(ret, i, cm, chainGArr[0]); /* if failure, i = -1 here */
  78275. LOAD_ONE_CA(ret, i, cm, chainGArr[1]); /* if failure, i = -2 here */
  78276. LOAD_ONE_CA(ret, i, cm, chainGArr[2]); /* if failure, i = -3 here */
  78277. LOAD_ONE_CA(ret, i, cm, chainGArr[3]); /* if failure, i = -4 here */
  78278. LOAD_ONE_CA(ret, i, cm, chainGArr[4]); /* if failure, i = -5 here */
  78279. LOAD_ONE_CA(ret, i, cm, chainGArr[5]); /* if failure, i = -6 here */
  78280. LOAD_ONE_CA(ret, i, cm, chainGArr[6]); /* if failure, i = -7 here */
  78281. LOAD_ONE_CA(ret, i, cm, chainGArr[7]); /* if failure, i = -8 here */
  78282. VERIFY_ONE_CERT(ret, i, cm, chainGArr[1]); /* if failure, i = -9 here */
  78283. VERIFY_ONE_CERT(ret, i, cm, chainGArr[2]); /* if failure, i = -10 here */
  78284. VERIFY_ONE_CERT(ret, i, cm, chainGArr[3]); /* if failure, i = -11 here */
  78285. VERIFY_ONE_CERT(ret, i, cm, chainGArr[4]); /* if failure, i = -12 here */
  78286. VERIFY_ONE_CERT(ret, i, cm, chainGArr[5]); /* if failure, i = -13 here */
  78287. VERIFY_ONE_CERT(ret, i, cm, chainGArr[6]); /* if failure, i = -14 here */
  78288. VERIFY_ONE_CERT(ret, i, cm, chainGArr[7]); /* if failure, i = -15 here */
  78289. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -16 here */
  78290. /* test validating the entity twice, should have no effect on pathLen since
  78291. * entity/leaf cert */
  78292. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -17 here */
  78293. return ret;
  78294. }
  78295. static int test_chainH(WOLFSSL_CERT_MANAGER* cm)
  78296. {
  78297. int ret;
  78298. int i = -1;
  78299. /* Chain H is NOT a valid chain per RFC5280 section 4.2.1.9:
  78300. * ICA4-pathlen of 2 signing ICA3-pathlen of 2 (reduce max path len to 2)
  78301. * ICA3-pathlen of 2 signing ICA2-pathlen of 2 (reduce max path len to 1)
  78302. * ICA2-pathlen of 2 signing ICA1-pathlen of 0 (reduce max path len to 0)
  78303. * ICA1-pathlen of 0 signing entity (pathlen is already 0, ERROR)
  78304. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78305. */
  78306. char chainHArr[6][50] = {"certs/ca-cert.pem",
  78307. "certs/test-pathlen/chainH-ICA4-pathlen2.pem",
  78308. "certs/test-pathlen/chainH-ICA3-pathlen2.pem",
  78309. "certs/test-pathlen/chainH-ICA2-pathlen2.pem",
  78310. "certs/test-pathlen/chainH-ICA1-pathlen0.pem",
  78311. "certs/test-pathlen/chainH-entity.pem"};
  78312. LOAD_ONE_CA(ret, i, cm, chainHArr[0]); /* if failure, i = -1 here */
  78313. LOAD_ONE_CA(ret, i, cm, chainHArr[1]); /* if failure, i = -2 here */
  78314. LOAD_ONE_CA(ret, i, cm, chainHArr[2]); /* if failure, i = -3 here */
  78315. LOAD_ONE_CA(ret, i, cm, chainHArr[3]); /* if failure, i = -4 here */
  78316. LOAD_ONE_CA(ret, i, cm, chainHArr[4]); /* if failure, i = -5 here */
  78317. VERIFY_ONE_CERT(ret, i, cm, chainHArr[1]); /* if failure, i = -6 here */
  78318. VERIFY_ONE_CERT(ret, i, cm, chainHArr[2]); /* if failure, i = -7 here */
  78319. VERIFY_ONE_CERT(ret, i, cm, chainHArr[3]); /* if failure, i = -8 here */
  78320. VERIFY_ONE_CERT(ret, i, cm, chainHArr[4]); /* if failure, i = -9 here */
  78321. VERIFY_ONE_CERT(ret, i, cm, chainHArr[5]); /* if failure, i = -10 here */
  78322. return ret;
  78323. }
  78324. static int test_chainI(WOLFSSL_CERT_MANAGER* cm)
  78325. {
  78326. int ret;
  78327. int i = -1;
  78328. /* Chain I is a valid chain per RFC5280 section 4.2.1.9:
  78329. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 2)
  78330. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 1)
  78331. * ICA1-no_pathlen signing entity (reduce maxPathLen to 0)
  78332. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78333. */
  78334. char chainIArr[5][50] = {"certs/ca-cert.pem",
  78335. "certs/test-pathlen/chainI-ICA3-pathlen2.pem",
  78336. "certs/test-pathlen/chainI-ICA2-no_pathlen.pem",
  78337. "certs/test-pathlen/chainI-ICA1-no_pathlen.pem",
  78338. "certs/test-pathlen/chainI-entity.pem"};
  78339. LOAD_ONE_CA(ret, i, cm, chainIArr[0]); /* if failure, i = -1 here */
  78340. LOAD_ONE_CA(ret, i, cm, chainIArr[1]); /* if failure, i = -2 here */
  78341. LOAD_ONE_CA(ret, i, cm, chainIArr[2]); /* if failure, i = -3 here */
  78342. LOAD_ONE_CA(ret, i, cm, chainIArr[3]); /* if failure, i = -4 here */
  78343. VERIFY_ONE_CERT(ret, i, cm, chainIArr[1]); /* if failure, i = -5 here */
  78344. VERIFY_ONE_CERT(ret, i, cm, chainIArr[2]); /* if failure, i = -6 here */
  78345. VERIFY_ONE_CERT(ret, i, cm, chainIArr[3]); /* if failure, i = -7 here */
  78346. VERIFY_ONE_CERT(ret, i, cm, chainIArr[4]); /* if failure, i = -8 here */
  78347. return ret;
  78348. }
  78349. static int test_chainJ(WOLFSSL_CERT_MANAGER* cm)
  78350. {
  78351. int ret;
  78352. int i = -1;
  78353. /* Chain J is NOT a valid chain per RFC5280 section 4.2.1.9:
  78354. * ICA4-pathlen of 2 signing ICA3 without a pathlen (reduce maxPathLen to 2)
  78355. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 1)
  78356. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 0)
  78357. * ICA1-no_pathlen signing entity (ERROR, pathlen zero and non-leaf cert)
  78358. */
  78359. char chainJArr[6][50] = {"certs/ca-cert.pem",
  78360. "certs/test-pathlen/chainJ-ICA4-pathlen2.pem",
  78361. "certs/test-pathlen/chainJ-ICA3-no_pathlen.pem",
  78362. "certs/test-pathlen/chainJ-ICA2-no_pathlen.pem",
  78363. "certs/test-pathlen/chainJ-ICA1-no_pathlen.pem",
  78364. "certs/test-pathlen/chainJ-entity.pem"};
  78365. LOAD_ONE_CA(ret, i, cm, chainJArr[0]); /* if failure, i = -1 here */
  78366. LOAD_ONE_CA(ret, i, cm, chainJArr[1]); /* if failure, i = -2 here */
  78367. LOAD_ONE_CA(ret, i, cm, chainJArr[2]); /* if failure, i = -3 here */
  78368. LOAD_ONE_CA(ret, i, cm, chainJArr[3]); /* if failure, i = -4 here */
  78369. LOAD_ONE_CA(ret, i, cm, chainJArr[4]); /* if failure, i = -5 here */
  78370. VERIFY_ONE_CERT(ret, i, cm, chainJArr[1]); /* if failure, i = -6 here */
  78371. VERIFY_ONE_CERT(ret, i, cm, chainJArr[2]); /* if failure, i = -7 here */
  78372. VERIFY_ONE_CERT(ret, i, cm, chainJArr[3]); /* if failure, i = -8 here */
  78373. VERIFY_ONE_CERT(ret, i, cm, chainJArr[4]); /* if failure, i = -9 here */
  78374. VERIFY_ONE_CERT(ret, i, cm, chainJArr[5]); /* if failure, i = -10 here */
  78375. return ret;
  78376. }
  78377. static int test_various_pathlen_chains(void)
  78378. {
  78379. EXPECT_DECLS;
  78380. WOLFSSL_CERT_MANAGER* cm = NULL;
  78381. /* Test chain G (large chain with varying pathLens) */
  78382. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78383. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78384. ExpectIntEQ(test_chainG(cm), -1);
  78385. #else
  78386. ExpectIntEQ(test_chainG(cm), 0);
  78387. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78388. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78389. wolfSSL_CertManagerFree(cm);
  78390. /* end test chain G */
  78391. /* Test chain H (5 chain with same pathLens) */
  78392. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78393. ExpectIntLT(test_chainH(cm), 0);
  78394. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78395. wolfSSL_CertManagerFree(cm);
  78396. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78397. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78398. wolfSSL_CertManagerFree(cm);
  78399. /* end test chain H */
  78400. /* Test chain I (only first ICA has pathLen set and it's set to 2,
  78401. * followed by 2 ICA's, should pass) */
  78402. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78403. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78404. ExpectIntEQ(test_chainI(cm), -1);
  78405. #else
  78406. ExpectIntEQ(test_chainI(cm), 0);
  78407. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78408. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78409. wolfSSL_CertManagerFree(cm);
  78410. cm = NULL;
  78411. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78412. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78413. wolfSSL_CertManagerFree(cm);
  78414. cm = NULL;
  78415. /* Test chain J (Again only first ICA has pathLen set and it's set to 2,
  78416. * this time followed by 3 ICA's, should fail */
  78417. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78418. ExpectIntLT(test_chainJ(cm), 0);
  78419. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78420. wolfSSL_CertManagerFree(cm);
  78421. cm = NULL;
  78422. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78423. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78424. wolfSSL_CertManagerFree(cm);
  78425. return EXPECT_RESULT();
  78426. }
  78427. #endif /* !NO_RSA && !NO_SHA && !NO_FILESYSTEM && !NO_CERTS */
  78428. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  78429. static int test_export_keying_material_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  78430. {
  78431. EXPECT_DECLS;
  78432. byte ekm[100] = {0};
  78433. (void)ctx;
  78434. /* Success Cases */
  78435. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78436. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 0), 1);
  78437. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78438. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 1), 1);
  78439. /* Use some random context */
  78440. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78441. "Test label", XSTR_SIZEOF("Test label"), ekm, 10, 1), 1);
  78442. /* Failure cases */
  78443. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78444. "client finished", XSTR_SIZEOF("client finished"), NULL, 0, 0), 0);
  78445. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78446. "server finished", XSTR_SIZEOF("server finished"), NULL, 0, 0), 0);
  78447. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78448. "master secret", XSTR_SIZEOF("master secret"), NULL, 0, 0), 0);
  78449. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78450. "extended master secret", XSTR_SIZEOF("extended master secret"),
  78451. NULL, 0, 0), 0);
  78452. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78453. "key expansion", XSTR_SIZEOF("key expansion"), NULL, 0, 0), 0);
  78454. return EXPECT_RESULT();
  78455. }
  78456. static int test_export_keying_material_ssl_cb(WOLFSSL* ssl)
  78457. {
  78458. wolfSSL_KeepArrays(ssl);
  78459. return TEST_SUCCESS;
  78460. }
  78461. static int test_export_keying_material(void)
  78462. {
  78463. EXPECT_DECLS;
  78464. test_ssl_cbf serverCb;
  78465. test_ssl_cbf clientCb;
  78466. XMEMSET(&serverCb, 0, sizeof(serverCb));
  78467. XMEMSET(&clientCb, 0, sizeof(clientCb));
  78468. clientCb.ssl_ready = test_export_keying_material_ssl_cb;
  78469. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&clientCb,
  78470. &serverCb, test_export_keying_material_cb), TEST_SUCCESS);
  78471. return EXPECT_RESULT();
  78472. }
  78473. #endif /* HAVE_KEYING_MATERIAL */
  78474. static int test_wolfSSL_THREADID_hash(void)
  78475. {
  78476. EXPECT_DECLS;
  78477. #if defined(OPENSSL_EXTRA)
  78478. CRYPTO_THREADID id;
  78479. CRYPTO_THREADID_current(NULL);
  78480. /* Hash result is unsigned long. */
  78481. ExpectTrue(CRYPTO_THREADID_hash(NULL) == 0UL);
  78482. XMEMSET(&id, 0, sizeof(id));
  78483. ExpectTrue(CRYPTO_THREADID_hash(&id) == 0UL);
  78484. #endif /* OPENSSL_EXTRA */
  78485. return EXPECT_RESULT();
  78486. }
  78487. static int test_wolfSSL_set_ecdh_auto(void)
  78488. {
  78489. EXPECT_DECLS;
  78490. #if defined(OPENSSL_EXTRA)
  78491. WOLFSSL* ssl = NULL;
  78492. ExpectIntEQ(SSL_set_ecdh_auto(NULL,0), 1);
  78493. ExpectIntEQ(SSL_set_ecdh_auto(NULL,1), 1);
  78494. ExpectIntEQ(SSL_set_ecdh_auto(ssl,0), 1);
  78495. ExpectIntEQ(SSL_set_ecdh_auto(ssl,1), 1);
  78496. #endif /* OPENSSL_EXTRA */
  78497. return EXPECT_RESULT();
  78498. }
  78499. static int test_wolfSSL_CTX_set_ecdh_auto(void)
  78500. {
  78501. EXPECT_DECLS;
  78502. #if defined(OPENSSL_EXTRA)
  78503. WOLFSSL_CTX* ctx = NULL;
  78504. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,0), 1);
  78505. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,1), 1);
  78506. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,0), 1);
  78507. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,1), 1);
  78508. #endif /* OPENSSL_EXTRA */
  78509. return EXPECT_RESULT();
  78510. }
  78511. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  78512. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  78513. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_server_thread(void* args)
  78514. {
  78515. EXPECT_DECLS;
  78516. callback_functions* callbacks = NULL;
  78517. WOLFSSL_CTX* ctx = NULL;
  78518. WOLFSSL* ssl = NULL;
  78519. SOCKET_T sfd = 0;
  78520. SOCKET_T cfd = 0;
  78521. word16 port;
  78522. char msg[] = "I hear you fa shizzle!";
  78523. int len = (int) XSTRLEN(msg);
  78524. char input[1024];
  78525. int ret = 0;
  78526. int err = 0;
  78527. if (!args)
  78528. WOLFSSL_RETURN_FROM_THREAD(0);
  78529. ((func_args*)args)->return_code = TEST_FAIL;
  78530. callbacks = ((func_args*)args)->callbacks;
  78531. ctx = wolfSSL_CTX_new(callbacks->method());
  78532. #if defined(USE_WINDOWS_API)
  78533. port = ((func_args*)args)->signal->port;
  78534. #else
  78535. /* Let tcp_listen assign port */
  78536. port = 0;
  78537. #endif
  78538. #ifdef WOLFSSL_TIRTOS
  78539. fdOpenSession(Task_self());
  78540. #endif
  78541. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  78542. caCertFile, 0));
  78543. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  78544. svrCertFile, WOLFSSL_FILETYPE_PEM));
  78545. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  78546. svrKeyFile, WOLFSSL_FILETYPE_PEM));
  78547. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  78548. ExpectIntEQ(wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  78549. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  78550. #elif !defined(NO_DH)
  78551. SetDHCtx(ctx); /* will repick suites with DHE, higher priority than PSK */
  78552. #endif
  78553. if (callbacks->ctx_ready)
  78554. callbacks->ctx_ready(ctx);
  78555. ssl = wolfSSL_new(ctx);
  78556. ExpectNotNull(ssl);
  78557. /* listen and accept */
  78558. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  78559. CloseSocket(sfd);
  78560. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  78561. if (callbacks->ssl_ready)
  78562. callbacks->ssl_ready(ssl);
  78563. if (EXPECT_SUCCESS()) {
  78564. do {
  78565. err = 0; /* Reset error */
  78566. ret = wolfSSL_accept(ssl);
  78567. if (ret != WOLFSSL_SUCCESS) {
  78568. err = wolfSSL_get_error(ssl, 0);
  78569. }
  78570. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  78571. }
  78572. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  78573. /* read and write data */
  78574. XMEMSET(input, 0, sizeof(input));
  78575. while (EXPECT_SUCCESS()) {
  78576. ret = wolfSSL_read(ssl, input, sizeof(input));
  78577. if (ret > 0) {
  78578. break;
  78579. }
  78580. else {
  78581. err = wolfSSL_get_error(ssl,ret);
  78582. if (err == WOLFSSL_ERROR_WANT_READ) {
  78583. continue;
  78584. }
  78585. break;
  78586. }
  78587. }
  78588. if (EXPECT_SUCCESS() && (err == WOLFSSL_ERROR_ZERO_RETURN)) {
  78589. do {
  78590. ret = wolfSSL_write(ssl, msg, len);
  78591. if (ret > 0) {
  78592. break;
  78593. }
  78594. } while (ret < 0);
  78595. }
  78596. /* bidirectional shutdown */
  78597. while (EXPECT_SUCCESS()) {
  78598. ret = wolfSSL_shutdown(ssl);
  78599. ExpectIntNE(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78600. if (ret == WOLFSSL_SUCCESS) {
  78601. break;
  78602. }
  78603. }
  78604. if (EXPECT_SUCCESS()) {
  78605. /* wait for the peer to disconnect the tcp connection */
  78606. do {
  78607. ret = wolfSSL_read(ssl, input, sizeof(input));
  78608. err = wolfSSL_get_error(ssl, ret);
  78609. } while (ret > 0 || err != WOLFSSL_ERROR_ZERO_RETURN);
  78610. }
  78611. /* detect TCP disconnect */
  78612. ExpectIntLE(ret,WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78613. ExpectIntEQ(wolfSSL_get_error(ssl, ret), WOLFSSL_ERROR_ZERO_RETURN);
  78614. ((func_args*)args)->return_code = EXPECT_RESULT();
  78615. wolfSSL_free(ssl);
  78616. wolfSSL_CTX_free(ctx);
  78617. CloseSocket(cfd);
  78618. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  78619. wc_ecc_fp_free(); /* free per thread cache */
  78620. #endif
  78621. WOLFSSL_RETURN_FROM_THREAD(0);
  78622. }
  78623. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_client_thread(void* args)
  78624. {
  78625. EXPECT_DECLS;
  78626. callback_functions* callbacks = NULL;
  78627. WOLFSSL_CTX* ctx = NULL;
  78628. WOLFSSL* ssl = NULL;
  78629. SOCKET_T sfd = 0;
  78630. char msg[] = "hello wolfssl server!";
  78631. int len = (int) XSTRLEN(msg);
  78632. char input[1024];
  78633. int idx;
  78634. int ret, err;
  78635. if (!args)
  78636. WOLFSSL_RETURN_FROM_THREAD(0);
  78637. ((func_args*)args)->return_code = TEST_FAIL;
  78638. callbacks = ((func_args*)args)->callbacks;
  78639. ctx = wolfSSL_CTX_new(callbacks->method());
  78640. #ifdef WOLFSSL_TIRTOS
  78641. fdOpenSession(Task_self());
  78642. #endif
  78643. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  78644. caCertFile, 0));
  78645. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  78646. cliCertFile, WOLFSSL_FILETYPE_PEM));
  78647. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  78648. cliKeyFile, WOLFSSL_FILETYPE_PEM));
  78649. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  78650. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, 0, ssl);
  78651. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, sfd));
  78652. if (EXPECT_SUCCESS()) {
  78653. do {
  78654. err = 0; /* Reset error */
  78655. ret = wolfSSL_connect(ssl);
  78656. if (ret != WOLFSSL_SUCCESS) {
  78657. err = wolfSSL_get_error(ssl, 0);
  78658. }
  78659. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  78660. }
  78661. ExpectIntGE(wolfSSL_write(ssl, msg, len), 0);
  78662. if (EXPECT_SUCCESS()) {
  78663. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  78664. input[idx] = 0;
  78665. }
  78666. }
  78667. if (EXPECT_SUCCESS()) {
  78668. ret = wolfSSL_shutdown(ssl);
  78669. if (ret == WOLFSSL_SHUTDOWN_NOT_DONE) {
  78670. ret = wolfSSL_shutdown(ssl);
  78671. }
  78672. }
  78673. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  78674. ((func_args*)args)->return_code = EXPECT_RESULT();
  78675. wolfSSL_free(ssl);
  78676. wolfSSL_CTX_free(ctx);
  78677. CloseSocket(sfd);
  78678. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  78679. wc_ecc_fp_free(); /* free per thread cache */
  78680. #endif
  78681. WOLFSSL_RETURN_FROM_THREAD(0);
  78682. }
  78683. #endif /* OPENSSL_EXTRA && WOLFSSL_ERROR_CODE_OPENSSL &&
  78684. HAVE_IO_TESTS_DEPENDENCIES && !WOLFSSL_NO_TLS12 */
  78685. /* This test is to check wolfSSL_read behaves as same as
  78686. * openSSL when it is called after SSL_shutdown completes.
  78687. */
  78688. static int test_wolfSSL_read_detect_TCP_disconnect(void)
  78689. {
  78690. EXPECT_DECLS;
  78691. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  78692. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  78693. tcp_ready ready;
  78694. func_args client_args;
  78695. func_args server_args;
  78696. THREAD_TYPE serverThread;
  78697. THREAD_TYPE clientThread;
  78698. callback_functions server_cbf;
  78699. callback_functions client_cbf;
  78700. #ifdef WOLFSSL_TIRTOS
  78701. fdOpenSession(Task_self());
  78702. #endif
  78703. StartTCP();
  78704. InitTcpReady(&ready);
  78705. #if defined(USE_WINDOWS_API)
  78706. /* use RNG to get random port if using windows */
  78707. ready.port = GetRandomPort();
  78708. #endif
  78709. XMEMSET(&client_args, 0, sizeof(func_args));
  78710. XMEMSET(&server_args, 0, sizeof(func_args));
  78711. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  78712. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  78713. server_cbf.method = wolfTLSv1_2_server_method;
  78714. client_cbf.method = wolfTLSv1_2_client_method;
  78715. server_args.callbacks = &server_cbf;
  78716. client_args.callbacks = &client_cbf;
  78717. server_args.signal = &ready;
  78718. client_args.signal = &ready;
  78719. start_thread(SSL_read_test_server_thread, &server_args, &serverThread);
  78720. wait_tcp_ready(&server_args);
  78721. start_thread(SSL_read_test_client_thread, &client_args, &clientThread);
  78722. join_thread(clientThread);
  78723. join_thread(serverThread);
  78724. ExpectTrue(client_args.return_code);
  78725. ExpectTrue(server_args.return_code);
  78726. FreeTcpReady(&ready);
  78727. #endif
  78728. return EXPECT_RESULT();
  78729. }
  78730. static int test_wolfSSL_CTX_get_min_proto_version(void)
  78731. {
  78732. EXPECT_DECLS;
  78733. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  78734. WOLFSSL_CTX *ctx = NULL;
  78735. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78736. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  78737. WOLFSSL_SUCCESS);
  78738. #ifdef WOLFSSL_ALLOW_SSLV3
  78739. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  78740. #else
  78741. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  78742. #endif
  78743. wolfSSL_CTX_free(ctx);
  78744. ctx = NULL;
  78745. #ifndef NO_OLD_TLS
  78746. #ifdef WOLFSSL_ALLOW_TLSV10
  78747. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_method()));
  78748. #else
  78749. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78750. #endif
  78751. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_VERSION),
  78752. WOLFSSL_SUCCESS);
  78753. #ifdef WOLFSSL_ALLOW_TLSV10
  78754. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  78755. #else
  78756. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  78757. #endif
  78758. wolfSSL_CTX_free(ctx);
  78759. ctx = NULL;
  78760. #endif
  78761. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78762. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION),
  78763. WOLFSSL_SUCCESS);
  78764. #ifndef NO_OLD_TLS
  78765. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  78766. #else
  78767. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  78768. #endif
  78769. wolfSSL_CTX_free(ctx);
  78770. ctx = NULL;
  78771. #ifndef WOLFSSL_NO_TLS12
  78772. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_method()));
  78773. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION),
  78774. WOLFSSL_SUCCESS);
  78775. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  78776. wolfSSL_CTX_free(ctx);
  78777. ctx = NULL;
  78778. #endif
  78779. #ifdef WOLFSSL_TLS13
  78780. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_method()));
  78781. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION),
  78782. WOLFSSL_SUCCESS);
  78783. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_3_VERSION);
  78784. wolfSSL_CTX_free(ctx);
  78785. ctx = NULL;
  78786. #endif
  78787. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  78788. return EXPECT_RESULT();
  78789. }
  78790. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  78791. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  78792. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  78793. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  78794. static int test_wolfSSL_set_SSL_CTX(void)
  78795. {
  78796. EXPECT_DECLS;
  78797. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) \
  78798. && !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_TLS13) && \
  78799. !defined(NO_RSA)
  78800. WOLFSSL_CTX *ctx1 = NULL;
  78801. WOLFSSL_CTX *ctx2 = NULL;
  78802. WOLFSSL *ssl = NULL;
  78803. const byte *session_id1 = (const byte *)"CTX1";
  78804. const byte *session_id2 = (const byte *)"CTX2";
  78805. ExpectNotNull(ctx1 = wolfSSL_CTX_new(wolfTLS_server_method()));
  78806. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx1, svrCertFile,
  78807. WOLFSSL_FILETYPE_PEM));
  78808. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx1, svrKeyFile,
  78809. WOLFSSL_FILETYPE_PEM));
  78810. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx1, TLS1_2_VERSION),
  78811. WOLFSSL_SUCCESS);
  78812. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx1), TLS1_2_VERSION);
  78813. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx1), TLS1_3_VERSION);
  78814. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx1, session_id1, 4),
  78815. WOLFSSL_SUCCESS);
  78816. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfTLS_server_method()));
  78817. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx2, svrCertFile,
  78818. WOLFSSL_FILETYPE_PEM));
  78819. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx2, svrKeyFile,
  78820. WOLFSSL_FILETYPE_PEM));
  78821. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx2, TLS1_2_VERSION),
  78822. WOLFSSL_SUCCESS);
  78823. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx2, TLS1_2_VERSION),
  78824. WOLFSSL_SUCCESS);
  78825. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx2), TLS1_2_VERSION);
  78826. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx2), TLS1_2_VERSION);
  78827. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx2, session_id2, 4),
  78828. WOLFSSL_SUCCESS);
  78829. #ifdef HAVE_SESSION_TICKET
  78830. ExpectIntEQ((wolfSSL_CTX_get_options(ctx1) & SSL_OP_NO_TICKET), 0);
  78831. wolfSSL_CTX_set_options(ctx2, SSL_OP_NO_TICKET);
  78832. ExpectIntNE((wolfSSL_CTX_get_options(ctx2) & SSL_OP_NO_TICKET), 0);
  78833. #endif
  78834. ExpectNotNull(ssl = wolfSSL_new(ctx2));
  78835. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  78836. #ifdef WOLFSSL_INT_H
  78837. #ifdef WOLFSSL_SESSION_ID_CTX
  78838. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id2, 4), 0);
  78839. #endif
  78840. #ifdef WOLFSSL_COPY_CERT
  78841. if (ctx2 != NULL && ctx2->certificate != NULL) {
  78842. ExpectFalse(ssl->buffers.certificate == ctx2->certificate);
  78843. }
  78844. if (ctx2 != NULL && ctx2->certChain != NULL) {
  78845. ExpectFalse(ssl->buffers.certChain == ctx2->certChain);
  78846. }
  78847. #else
  78848. ExpectTrue(ssl->buffers.certificate == ctx2->certificate);
  78849. ExpectTrue(ssl->buffers.certChain == ctx2->certChain);
  78850. #endif
  78851. #endif
  78852. #ifdef HAVE_SESSION_TICKET
  78853. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  78854. #endif
  78855. /* Set the ctx1 that has TLSv1.3 as max proto version */
  78856. ExpectNotNull(wolfSSL_set_SSL_CTX(ssl, ctx1));
  78857. /* MUST not change proto versions of ssl */
  78858. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  78859. #ifdef HAVE_SESSION_TICKET
  78860. /* MUST not change */
  78861. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  78862. #endif
  78863. /* MUST change */
  78864. #ifdef WOLFSSL_INT_H
  78865. #ifdef WOLFSSL_COPY_CERT
  78866. if (ctx1 != NULL && ctx1->certificate != NULL) {
  78867. ExpectFalse(ssl->buffers.certificate == ctx1->certificate);
  78868. }
  78869. if (ctx1 != NULL && ctx1->certChain != NULL) {
  78870. ExpectFalse(ssl->buffers.certChain == ctx1->certChain);
  78871. }
  78872. #else
  78873. ExpectTrue(ssl->buffers.certificate == ctx1->certificate);
  78874. ExpectTrue(ssl->buffers.certChain == ctx1->certChain);
  78875. #endif
  78876. #ifdef WOLFSSL_SESSION_ID_CTX
  78877. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id1, 4), 0);
  78878. #endif
  78879. #endif
  78880. wolfSSL_free(ssl);
  78881. wolfSSL_CTX_free(ctx1);
  78882. wolfSSL_CTX_free(ctx2);
  78883. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  78884. return EXPECT_RESULT();
  78885. }
  78886. #endif /* defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  78887. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  78888. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  78889. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))) */
  78890. static int test_wolfSSL_security_level(void)
  78891. {
  78892. EXPECT_DECLS;
  78893. #if defined(OPENSSL_EXTRA)
  78894. SSL_CTX *ctx = NULL;
  78895. #ifdef WOLFSSL_TLS13
  78896. #ifdef NO_WOLFSSL_SERVER
  78897. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  78898. #else
  78899. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  78900. #endif
  78901. SSL_CTX_set_security_level(NULL, 1);
  78902. SSL_CTX_set_security_level(ctx, 1);
  78903. ExpectIntEQ(SSL_CTX_get_security_level(NULL), 0);
  78904. /* Stub so nothing happens. */
  78905. ExpectIntEQ(SSL_CTX_get_security_level(ctx), 0);
  78906. SSL_CTX_free(ctx);
  78907. #else
  78908. (void)ctx;
  78909. #endif
  78910. #endif
  78911. return EXPECT_RESULT();
  78912. }
  78913. static int test_wolfSSL_SSL_in_init(void)
  78914. {
  78915. EXPECT_DECLS;
  78916. #if defined(OPENSSL_ALL) && !defined(NO_BIO)
  78917. SSL_CTX* ctx = NULL;
  78918. SSL* ssl = NULL;
  78919. const char* testCertFile;
  78920. const char* testKeyFile;
  78921. #ifdef WOLFSSL_TLS13
  78922. #ifdef NO_WOLFSSL_SERVER
  78923. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  78924. #else
  78925. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  78926. #endif
  78927. #else
  78928. #ifdef NO_WOLFSSL_SERVER
  78929. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  78930. #else
  78931. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  78932. #endif
  78933. #endif
  78934. #ifndef NO_RSA
  78935. testCertFile = svrCertFile;
  78936. testKeyFile = svrKeyFile;
  78937. #elif defined(HAVE_ECC)
  78938. testCertFile = eccCertFile;
  78939. testKeyFile = eccKeyFile;
  78940. #else
  78941. testCertFile = NULL;
  78942. testKeyFile = NULL;
  78943. #endif
  78944. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  78945. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  78946. SSL_FILETYPE_PEM));
  78947. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  78948. SSL_FILETYPE_PEM));
  78949. }
  78950. ExpectNotNull(ssl = SSL_new(ctx));
  78951. ExpectIntEQ(SSL_in_init(ssl), 1);
  78952. SSL_CTX_free(ctx);
  78953. SSL_free(ssl);
  78954. #endif
  78955. return EXPECT_RESULT();
  78956. }
  78957. static int test_wolfSSL_CTX_set_timeout(void)
  78958. {
  78959. EXPECT_DECLS;
  78960. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_SESSION_CACHE)
  78961. int timeout;
  78962. WOLFSSL_CTX* ctx = NULL;
  78963. (void)timeout;
  78964. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  78965. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  78966. /* in WOLFSSL_ERROR_CODE_OPENSSL macro guard,
  78967. * wolfSSL_CTX_set_timeout returns previous timeout value on success.
  78968. */
  78969. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78970. /* giving 0 as timeout value sets default timeout */
  78971. timeout = wolfSSL_CTX_set_timeout(ctx, 0);
  78972. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 20), timeout);
  78973. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 30), 20);
  78974. #else
  78975. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78976. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 100), 1);
  78977. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 0), 1);
  78978. #endif
  78979. wolfSSL_CTX_free(ctx);
  78980. #endif /* !NO_WOLFSSL_SERVER && !NO_SESSION_CACHE*/
  78981. return EXPECT_RESULT();
  78982. }
  78983. static int test_wolfSSL_OpenSSL_version(void)
  78984. {
  78985. EXPECT_DECLS;
  78986. #if defined(OPENSSL_EXTRA)
  78987. const char* ver;
  78988. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  78989. ExpectNotNull(ver = OpenSSL_version(0));
  78990. #else
  78991. ExpectNotNull(ver = OpenSSL_version());
  78992. #endif
  78993. ExpectIntEQ(XMEMCMP(ver, "wolfSSL " LIBWOLFSSL_VERSION_STRING,
  78994. XSTRLEN("wolfSSL " LIBWOLFSSL_VERSION_STRING)), 0);
  78995. #endif
  78996. return EXPECT_RESULT();
  78997. }
  78998. static int test_CONF_CTX_CMDLINE(void)
  78999. {
  79000. EXPECT_DECLS;
  79001. #if defined(OPENSSL_ALL)
  79002. SSL_CTX* ctx = NULL;
  79003. SSL_CONF_CTX* cctx = NULL;
  79004. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79005. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79006. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79007. /* set flags */
  79008. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CMDLINE),
  79009. WOLFSSL_CONF_FLAG_CMDLINE);
  79010. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79011. WOLFSSL_CONF_FLAG_CMDLINE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79012. /* cmd invalid command */
  79013. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79014. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79015. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79016. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79017. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79018. /* cmd Certificate and Private Key*/
  79019. {
  79020. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79021. const char* ourCert = svrCertFile;
  79022. const char* ourKey = svrKeyFile;
  79023. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", NULL), -3);
  79024. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", ourCert), WOLFSSL_SUCCESS);
  79025. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", NULL), -3);
  79026. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", ourKey), WOLFSSL_SUCCESS);
  79027. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79028. #endif
  79029. }
  79030. /* cmd curves */
  79031. {
  79032. #if defined(HAVE_ECC)
  79033. const char* curve = "secp256r1";
  79034. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", NULL), -3);
  79035. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", curve), WOLFSSL_SUCCESS);
  79036. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79037. #endif
  79038. }
  79039. /* cmd CipherString */
  79040. {
  79041. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79042. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", NULL), -3);
  79043. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", cipher), WOLFSSL_SUCCESS);
  79044. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79045. }
  79046. /* cmd DH parameter */
  79047. {
  79048. #if !defined(NO_DH) && !defined(NO_BIO)
  79049. const char* ourdhcert = "./certs/dh2048.pem";
  79050. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", NULL), -3);
  79051. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", ourdhcert), WOLFSSL_SUCCESS);
  79052. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79053. #endif
  79054. }
  79055. SSL_CTX_free(ctx);
  79056. SSL_CONF_CTX_free(cctx);
  79057. #endif /* OPENSSL_EXTRA */
  79058. return EXPECT_RESULT();
  79059. }
  79060. static int test_CONF_CTX_FILE(void)
  79061. {
  79062. EXPECT_DECLS;
  79063. #if defined(OPENSSL_ALL)
  79064. SSL_CTX* ctx = NULL;
  79065. SSL_CONF_CTX* cctx = NULL;
  79066. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79067. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79068. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79069. /* set flags */
  79070. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_FILE),
  79071. WOLFSSL_CONF_FLAG_FILE);
  79072. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79073. WOLFSSL_CONF_FLAG_FILE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79074. /* sanity check */
  79075. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79076. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79077. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79078. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79079. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79080. /* cmd Certificate and Private Key*/
  79081. {
  79082. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79083. const char* ourCert = svrCertFile;
  79084. const char* ourKey = svrKeyFile;
  79085. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", NULL), -3);
  79086. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", NULL), -3);
  79087. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", ourCert),
  79088. WOLFSSL_SUCCESS);
  79089. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", ourKey), WOLFSSL_SUCCESS);
  79090. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79091. #endif
  79092. }
  79093. /* cmd curves */
  79094. {
  79095. #if defined(HAVE_ECC)
  79096. const char* curve = "secp256r1";
  79097. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", NULL), -3);
  79098. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", curve), WOLFSSL_SUCCESS);
  79099. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79100. #endif
  79101. }
  79102. /* cmd CipherString */
  79103. {
  79104. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79105. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", NULL), -3);
  79106. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", cipher),
  79107. WOLFSSL_SUCCESS);
  79108. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79109. }
  79110. /* cmd DH parameter */
  79111. {
  79112. #if !defined(NO_DH) && !defined(NO_BIO) && defined(HAVE_FFDHE_3072)
  79113. const char* ourdhcert = "./certs/dh3072.pem";
  79114. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", NULL), -3);
  79115. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", ourdhcert),
  79116. WOLFSSL_SUCCESS);
  79117. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79118. #endif
  79119. }
  79120. SSL_CTX_free(ctx);
  79121. SSL_CONF_CTX_free(cctx);
  79122. #endif /* OPENSSL_EXTRA */
  79123. return EXPECT_RESULT();
  79124. }
  79125. static int test_wolfSSL_CRYPTO_get_ex_new_index(void)
  79126. {
  79127. EXPECT_DECLS;
  79128. #ifdef HAVE_EX_DATA
  79129. int idx1, idx2;
  79130. /* test for unsupported class index */
  79131. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509_STORE,
  79132. 0,NULL, NULL, NULL, NULL ), -1);
  79133. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(
  79134. WOLF_CRYPTO_EX_INDEX_X509_STORE_CTX,
  79135. 0,NULL, NULL, NULL, NULL ), -1);
  79136. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DH,
  79137. 0,NULL, NULL, NULL, NULL ), -1);
  79138. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DSA,
  79139. 0,NULL, NULL, NULL, NULL ), -1);
  79140. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_EC_KEY,
  79141. 0,NULL, NULL, NULL, NULL ), -1);
  79142. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_RSA,
  79143. 0,NULL, NULL, NULL, NULL ), -1);
  79144. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_ENGINE,
  79145. 0,NULL, NULL, NULL, NULL ), -1);
  79146. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI,
  79147. 0,NULL, NULL, NULL, NULL ), -1);
  79148. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_BIO,
  79149. 0,NULL, NULL, NULL, NULL ), -1);
  79150. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_APP,
  79151. 0,NULL, NULL, NULL, NULL ), -1);
  79152. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI_METHOD,
  79153. 0,NULL, NULL, NULL, NULL ), -1);
  79154. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DRBG,
  79155. 0,NULL, NULL, NULL, NULL ), -1);
  79156. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(20,
  79157. 0,NULL, NULL, NULL, NULL ), -1);
  79158. /* test for supported class index */
  79159. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79160. 0,NULL, NULL, NULL, NULL );
  79161. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79162. 0,NULL, NULL, NULL, NULL );
  79163. ExpectIntNE(idx1, -1);
  79164. ExpectIntNE(idx2, -1);
  79165. ExpectIntNE(idx1, idx2);
  79166. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79167. 0,NULL, NULL, NULL, NULL );
  79168. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79169. 0,NULL, NULL, NULL, NULL );
  79170. ExpectIntNE(idx1, -1);
  79171. ExpectIntNE(idx2, -1);
  79172. ExpectIntNE(idx1, idx2);
  79173. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79174. 0,NULL, NULL, NULL, NULL );
  79175. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79176. 0,NULL, NULL, NULL, NULL );
  79177. ExpectIntNE(idx1, -1);
  79178. ExpectIntNE(idx2, -1);
  79179. ExpectIntNE(idx1, idx2);
  79180. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79181. 0,NULL, NULL, NULL, NULL );
  79182. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79183. 0,NULL, NULL, NULL, NULL );
  79184. ExpectIntNE(idx1, -1);
  79185. ExpectIntNE(idx2, -1);
  79186. ExpectIntNE(idx1, idx2);
  79187. #endif /* HAVE_EX_DATA */
  79188. return EXPECT_RESULT();
  79189. }
  79190. #if defined(HAVE_EX_DATA) && defined(HAVE_EXT_CACHE) && \
  79191. (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79192. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79193. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79194. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))))
  79195. #define SESSION_NEW_IDX_LONG 0xDEADBEEF
  79196. #define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD)
  79197. #define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE)
  79198. #define SESSION_NEW_IDX_PTR "Testing"
  79199. static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr,
  79200. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79201. {
  79202. AssertNotNull(p);
  79203. AssertNull(ptr);
  79204. AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS);
  79205. AssertIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79206. AssertStrEQ(arg, SESSION_NEW_IDX_PTR);
  79207. }
  79208. static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out,
  79209. const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV,
  79210. void* arg)
  79211. {
  79212. EXPECT_DECLS;
  79213. ExpectNotNull(out);
  79214. ExpectNotNull(in);
  79215. ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL);
  79216. ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL);
  79217. ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL);
  79218. ExpectIntEQ(argV, SESSION_NEW_IDX_LONG);
  79219. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79220. *(void**)inPtr = SESSION_DUP_IDX_VAL;
  79221. if (EXPECT_SUCCESS()) {
  79222. return SSL_SUCCESS;
  79223. }
  79224. else {
  79225. return SSL_FAILURE;
  79226. }
  79227. }
  79228. static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0;
  79229. static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr,
  79230. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79231. {
  79232. EXPECT_DECLS;
  79233. ExpectNotNull(p);
  79234. ExpectNull(ptr);
  79235. ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0);
  79236. ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79237. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79238. if (EXPECT_SUCCESS()) {
  79239. test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++;
  79240. }
  79241. }
  79242. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79243. {
  79244. EXPECT_DECLS;
  79245. int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG,
  79246. (void*)SESSION_NEW_IDX_PTR,
  79247. test_wolfSSL_SESSION_get_ex_new_index_new_cb,
  79248. test_wolfSSL_SESSION_get_ex_new_index_dup_cb,
  79249. test_wolfSSL_SESSION_get_ex_new_index_free_cb);
  79250. SSL_SESSION* s = SSL_SESSION_new();
  79251. SSL_SESSION* d = NULL;
  79252. ExpectNotNull(s);
  79253. ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL);
  79254. ExpectNotNull(d = SSL_SESSION_dup(s));
  79255. ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL);
  79256. SSL_SESSION_free(s);
  79257. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1);
  79258. SSL_SESSION_free(d);
  79259. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2);
  79260. crypto_ex_cb_free(crypto_ex_cb_ctx_session);
  79261. crypto_ex_cb_ctx_session = NULL;
  79262. return EXPECT_RESULT();
  79263. }
  79264. #else
  79265. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79266. {
  79267. return TEST_SKIPPED;
  79268. }
  79269. #endif
  79270. static int test_wolfSSL_set_psk_use_session_callback(void)
  79271. {
  79272. EXPECT_DECLS;
  79273. #if defined(OPENSSL_EXTRA) && !defined(NO_PSK)
  79274. SSL_CTX* ctx = NULL;
  79275. SSL* ssl = NULL;
  79276. const char* testCertFile;
  79277. const char* testKeyFile;
  79278. #ifdef WOLFSSL_TLS13
  79279. #ifdef NO_WOLFSSL_SERVER
  79280. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79281. #else
  79282. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79283. #endif
  79284. #else
  79285. #ifdef NO_WOLFSSL_SERVER
  79286. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79287. #else
  79288. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79289. #endif
  79290. #endif
  79291. #ifndef NO_RSA
  79292. testCertFile = svrCertFile;
  79293. testKeyFile = svrKeyFile;
  79294. #elif defined(HAVE_ECC)
  79295. testCertFile = eccCertFile;
  79296. testKeyFile = eccKeyFile;
  79297. #else
  79298. testCertFile = NULL;
  79299. testKeyFile = NULL;
  79300. #endif
  79301. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  79302. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79303. SSL_FILETYPE_PEM));
  79304. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79305. SSL_FILETYPE_PEM));
  79306. }
  79307. ExpectNotNull(ssl = SSL_new(ctx));
  79308. SSL_set_psk_use_session_callback(ssl, my_psk_use_session_cb);
  79309. SSL_CTX_free(ctx);
  79310. SSL_free(ssl);
  79311. #endif
  79312. return EXPECT_RESULT();
  79313. }
  79314. /* similar to error_test() in wolfcrypt/test/test.c, but adding error codes from
  79315. * TLS layer.
  79316. */
  79317. static int error_test(void)
  79318. {
  79319. EXPECT_DECLS;
  79320. const char* errStr;
  79321. const char* unknownStr = wc_GetErrorString(0);
  79322. #ifdef NO_ERROR_STRINGS
  79323. /* Ensure a valid error code's string matches an invalid code's.
  79324. * The string is that error strings are not available.
  79325. */
  79326. errStr = wc_GetErrorString(OPEN_RAN_E);
  79327. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79328. if (EXPECT_FAIL())
  79329. return OPEN_RAN_E;
  79330. #else
  79331. int i;
  79332. int j = 0;
  79333. /* Values that are not or no longer error codes. */
  79334. static const struct {
  79335. int first;
  79336. int last;
  79337. } missing[] = {
  79338. #ifndef OPENSSL_EXTRA
  79339. { 0, 0 },
  79340. #endif
  79341. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  79342. defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)
  79343. { -11, -12 },
  79344. { -15, -17 },
  79345. { -19, -19 },
  79346. { -26, -27 },
  79347. { -30, WC_FIRST_E+1 },
  79348. #else
  79349. { -9, WC_FIRST_E+1 },
  79350. #endif
  79351. { -124, -124 },
  79352. { -166, -169 },
  79353. { -300, -300 },
  79354. { -334, -336 },
  79355. { -346, -349 },
  79356. { -356, -356 },
  79357. { -358, -358 },
  79358. { -372, -372 },
  79359. { -384, -384 },
  79360. { -466, -499 },
  79361. { WOLFSSL_LAST_E-1, WOLFSSL_LAST_E-1 }
  79362. };
  79363. /* Check that all errors have a string and it's the same through the two
  79364. * APIs. Check that the values that are not errors map to the unknown
  79365. * string.
  79366. */
  79367. for (i = 0; i >= WOLFSSL_LAST_E-1; i--) {
  79368. int this_missing = 0;
  79369. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  79370. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  79371. this_missing = 1;
  79372. break;
  79373. }
  79374. }
  79375. errStr = wolfSSL_ERR_reason_error_string(i);
  79376. if (! this_missing) {
  79377. ExpectIntNE(XSTRCMP(errStr, unknownStr), 0);
  79378. if (EXPECT_FAIL()) {
  79379. return i;
  79380. }
  79381. ExpectTrue(XSTRLEN(errStr) < WOLFSSL_MAX_ERROR_SZ);
  79382. if (EXPECT_FAIL()) {
  79383. return i;
  79384. }
  79385. }
  79386. else {
  79387. j++;
  79388. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79389. if (EXPECT_FAIL()) {
  79390. return i;
  79391. }
  79392. }
  79393. }
  79394. #endif
  79395. return 1;
  79396. }
  79397. static int test_wolfSSL_ERR_strings(void)
  79398. {
  79399. EXPECT_DECLS;
  79400. #if !defined(NO_ERROR_STRINGS)
  79401. const char* err1 = "unsupported cipher suite";
  79402. const char* err2 = "wolfSSL PEM routines";
  79403. const char* err = NULL;
  79404. (void)err;
  79405. (void)err1;
  79406. (void)err2;
  79407. #if defined(OPENSSL_EXTRA)
  79408. ExpectNotNull(err = ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79409. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79410. ExpectNotNull(err = ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79411. ExpectIntEQ((*err == '\0'), 1);
  79412. ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD));
  79413. ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
  79414. #else
  79415. ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79416. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79417. ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79418. ExpectIntEQ((*err == '\0'), 1);
  79419. /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */
  79420. ExpectNotNull(err = wolfSSL_ERR_lib_error_string(-MIN_CODE_E+2));
  79421. ExpectIntEQ((*err == '\0'), 1);
  79422. #endif
  79423. #endif
  79424. ExpectIntEQ(error_test(), 1);
  79425. return EXPECT_RESULT();
  79426. }
  79427. static int test_wolfSSL_EVP_shake128(void)
  79428. {
  79429. EXPECT_DECLS;
  79430. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79431. defined(WOLFSSL_SHAKE128)
  79432. const EVP_MD* md = NULL;
  79433. ExpectNotNull(md = EVP_shake128());
  79434. ExpectIntEQ(XSTRNCMP(md, "SHAKE128", XSTRLEN("SHAKE128")), 0);
  79435. #endif
  79436. return EXPECT_RESULT();
  79437. }
  79438. static int test_wolfSSL_EVP_shake256(void)
  79439. {
  79440. EXPECT_DECLS;
  79441. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79442. defined(WOLFSSL_SHAKE256)
  79443. const EVP_MD* md = NULL;
  79444. ExpectNotNull(md = EVP_shake256());
  79445. ExpectIntEQ(XSTRNCMP(md, "SHAKE256", XSTRLEN("SHAKE256")), 0);
  79446. #endif
  79447. return EXPECT_RESULT();
  79448. }
  79449. /*
  79450. * Testing EVP digest API with SM3
  79451. */
  79452. static int test_wolfSSL_EVP_sm3(void)
  79453. {
  79454. int res = TEST_SKIPPED;
  79455. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM3)
  79456. EXPECT_DECLS;
  79457. const EVP_MD* md = NULL;
  79458. EVP_MD_CTX* mdCtx = NULL;
  79459. byte data[WC_SM3_BLOCK_SIZE * 4];
  79460. byte hash[WC_SM3_DIGEST_SIZE];
  79461. byte calcHash[WC_SM3_DIGEST_SIZE];
  79462. byte expHash[WC_SM3_DIGEST_SIZE] = {
  79463. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  79464. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  79465. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  79466. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  79467. };
  79468. word32 chunk;
  79469. word32 i;
  79470. unsigned int sz;
  79471. int ret;
  79472. XMEMSET(data, 0, sizeof(data));
  79473. md = EVP_sm3();
  79474. ExpectTrue(md != NULL);
  79475. ExpectIntEQ(XSTRNCMP(md, "SM3", XSTRLEN("SM3")), 0);
  79476. mdCtx = EVP_MD_CTX_new();
  79477. ExpectTrue(mdCtx != NULL);
  79478. /* Invalid Parameters */
  79479. ExpectIntEQ(EVP_DigestInit(NULL, md), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79480. /* Valid Parameters */
  79481. ExpectIntEQ(EVP_DigestInit(mdCtx, md), WOLFSSL_SUCCESS);
  79482. ExpectIntEQ(EVP_DigestUpdate(NULL, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79483. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79484. ExpectIntEQ(EVP_DigestUpdate(NULL, data, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79485. /* Valid Parameters */
  79486. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 0), WOLFSSL_SUCCESS);
  79487. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79488. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79489. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE),
  79490. WOLFSSL_SUCCESS);
  79491. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE - 2),
  79492. WOLFSSL_SUCCESS);
  79493. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE * 2),
  79494. WOLFSSL_SUCCESS);
  79495. /* Ensure too many bytes for lengths. */
  79496. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_PAD_SIZE),
  79497. WOLFSSL_SUCCESS);
  79498. /* Invalid Parameters */
  79499. ExpectIntEQ(EVP_DigestFinal(NULL, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79500. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79501. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79502. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79503. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79504. /* Valid Parameters */
  79505. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  79506. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  79507. /* Chunk tests. */
  79508. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, sizeof(data)), WOLFSSL_SUCCESS);
  79509. ExpectIntEQ(EVP_DigestFinal(mdCtx, calcHash, &sz), WOLFSSL_SUCCESS);
  79510. ExpectIntEQ(sz, WC_SM3_DIGEST_SIZE);
  79511. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  79512. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  79513. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i, chunk),
  79514. WOLFSSL_SUCCESS);
  79515. }
  79516. if (i < (word32)sizeof(data)) {
  79517. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i,
  79518. (word32)sizeof(data) - i), WOLFSSL_SUCCESS);
  79519. }
  79520. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  79521. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  79522. }
  79523. /* Not testing when the low 32-bit length overflows. */
  79524. ret = EVP_MD_CTX_cleanup(mdCtx);
  79525. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79526. wolfSSL_EVP_MD_CTX_free(mdCtx);
  79527. res = EXPECT_RESULT();
  79528. #endif
  79529. return res;
  79530. } /* END test_EVP_sm3 */
  79531. static int test_EVP_blake2(void)
  79532. {
  79533. EXPECT_DECLS;
  79534. #if defined(OPENSSL_EXTRA) && (defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S))
  79535. const EVP_MD* md = NULL;
  79536. (void)md;
  79537. #if defined(HAVE_BLAKE2)
  79538. ExpectNotNull(md = EVP_blake2b512());
  79539. ExpectIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
  79540. #endif
  79541. #if defined(HAVE_BLAKE2S)
  79542. ExpectNotNull(md = EVP_blake2s256());
  79543. ExpectIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
  79544. #endif
  79545. #endif
  79546. return EXPECT_RESULT();
  79547. }
  79548. #if defined(OPENSSL_EXTRA)
  79549. static void list_md_fn(const EVP_MD* m, const char* from,
  79550. const char* to, void* arg)
  79551. {
  79552. const char* mn;
  79553. BIO *bio;
  79554. (void) from;
  79555. (void) to;
  79556. (void) arg;
  79557. (void) mn;
  79558. (void) bio;
  79559. if (!m) {
  79560. /* alias */
  79561. AssertNull(m);
  79562. AssertNotNull(to);
  79563. }
  79564. else {
  79565. AssertNotNull(m);
  79566. AssertNull(to);
  79567. }
  79568. AssertNotNull(from);
  79569. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  79570. mn = EVP_get_digestbyname(from);
  79571. /* print to stderr */
  79572. AssertNotNull(arg);
  79573. bio = BIO_new(BIO_s_file());
  79574. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  79575. BIO_printf(bio, "Use %s message digest algorithm\n", mn);
  79576. BIO_free(bio);
  79577. #endif
  79578. }
  79579. #endif
  79580. static int test_EVP_MD_do_all(void)
  79581. {
  79582. int res = TEST_SKIPPED;
  79583. #if defined(OPENSSL_EXTRA)
  79584. EVP_MD_do_all(NULL, stderr);
  79585. EVP_MD_do_all(list_md_fn, stderr);
  79586. res = TEST_SUCCESS;
  79587. #endif
  79588. return res;
  79589. }
  79590. #if defined(OPENSSL_EXTRA)
  79591. static void obj_name_t(const OBJ_NAME* nm, void* arg)
  79592. {
  79593. (void)arg;
  79594. (void)nm;
  79595. AssertIntGT(nm->type, OBJ_NAME_TYPE_UNDEF);
  79596. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  79597. /* print to stderr */
  79598. AssertNotNull(arg);
  79599. BIO *bio = BIO_new(BIO_s_file());
  79600. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  79601. BIO_printf(bio, "%s\n", nm);
  79602. BIO_free(bio);
  79603. #endif
  79604. }
  79605. #endif
  79606. static int test_OBJ_NAME_do_all(void)
  79607. {
  79608. int res = TEST_SKIPPED;
  79609. #if defined(OPENSSL_EXTRA)
  79610. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, NULL, NULL);
  79611. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, NULL, stderr);
  79612. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, obj_name_t, stderr);
  79613. OBJ_NAME_do_all(OBJ_NAME_TYPE_PKEY_METH, obj_name_t, stderr);
  79614. OBJ_NAME_do_all(OBJ_NAME_TYPE_COMP_METH, obj_name_t, stderr);
  79615. OBJ_NAME_do_all(OBJ_NAME_TYPE_NUM, obj_name_t, stderr);
  79616. OBJ_NAME_do_all(OBJ_NAME_TYPE_UNDEF, obj_name_t, stderr);
  79617. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, obj_name_t, stderr);
  79618. OBJ_NAME_do_all(-1, obj_name_t, stderr);
  79619. res = TEST_SUCCESS;
  79620. #endif
  79621. return res;
  79622. }
  79623. static int test_SSL_CIPHER_get_xxx(void)
  79624. {
  79625. EXPECT_DECLS;
  79626. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  79627. !defined(NO_FILESYSTEM)
  79628. const SSL_CIPHER* cipher = NULL;
  79629. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  79630. int i, numCiphers = 0;
  79631. SSL_CTX* ctx = NULL;
  79632. SSL* ssl = NULL;
  79633. const char* testCertFile;
  79634. const char* testKeyFile;
  79635. char buf[256] = {0};
  79636. const char* cipher_id = NULL;
  79637. int expect_nid1 = NID_undef;
  79638. int expect_nid2 = NID_undef;
  79639. int expect_nid3 = NID_undef;
  79640. int expect_nid4 = NID_undef;
  79641. int expect_nid5 = 0;
  79642. const char* cipher_id2 = NULL;
  79643. int expect_nid21 = NID_undef;
  79644. int expect_nid22 = NID_undef;
  79645. int expect_nid23 = NID_undef;
  79646. int expect_nid24 = NID_undef;
  79647. int expect_nid25 = 0;
  79648. (void)cipher;
  79649. (void)supportedCiphers;
  79650. (void)i;
  79651. (void)numCiphers;
  79652. (void)ctx;
  79653. (void)ssl;
  79654. (void)testCertFile;
  79655. (void)testKeyFile;
  79656. #if defined(WOLFSSL_TLS13)
  79657. cipher_id = "TLS13-AES128-GCM-SHA256";
  79658. expect_nid1 = NID_auth_rsa;
  79659. expect_nid2 = NID_aes_128_gcm;
  79660. expect_nid3 = NID_sha256;
  79661. expect_nid4 = NID_kx_any;
  79662. expect_nid5 = 1;
  79663. #if !defined(WOLFSSL_NO_TLS12)
  79664. cipher_id2 = "ECDHE-RSA-AES256-GCM-SHA384";
  79665. expect_nid21 = NID_auth_rsa;
  79666. expect_nid22 = NID_aes_256_gcm;
  79667. expect_nid23 = NID_sha384;
  79668. expect_nid24 = NID_kx_ecdhe;
  79669. expect_nid25 = 1;
  79670. #endif
  79671. #endif
  79672. #ifdef NO_WOLFSSL_SERVER
  79673. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79674. #else
  79675. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79676. #endif
  79677. if (cipher_id) {
  79678. #ifndef NO_RSA
  79679. testCertFile = svrCertFile;
  79680. testKeyFile = svrKeyFile;
  79681. #elif defined(HAVE_ECC)
  79682. testCertFile = eccCertFile;
  79683. testKeyFile = eccKeyFile;
  79684. #else
  79685. testCertFile = NULL;
  79686. testKeyFile = NULL;
  79687. #endif
  79688. if (testCertFile != NULL && testKeyFile != NULL) {
  79689. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79690. SSL_FILETYPE_PEM));
  79691. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79692. SSL_FILETYPE_PEM));
  79693. }
  79694. ExpectNotNull(ssl = SSL_new(ctx));
  79695. ExpectIntEQ(SSL_in_init(ssl), 1);
  79696. supportedCiphers = SSL_get_ciphers(ssl);
  79697. numCiphers = sk_num(supportedCiphers);
  79698. for (i = 0; i < numCiphers; ++i) {
  79699. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  79700. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  79701. }
  79702. if (XMEMCMP(cipher_id, buf, XSTRLEN(cipher_id)) == 0) {
  79703. break;
  79704. }
  79705. }
  79706. /* test case for */
  79707. if (i != numCiphers) {
  79708. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid1);
  79709. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid2);
  79710. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid3);
  79711. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid4);
  79712. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid5);
  79713. }
  79714. if (cipher_id2) {
  79715. for (i = 0; i < numCiphers; ++i) {
  79716. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  79717. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  79718. }
  79719. if (XMEMCMP(cipher_id2, buf, XSTRLEN(cipher_id2)) == 0) {
  79720. break;
  79721. }
  79722. }
  79723. /* test case for */
  79724. if (i != numCiphers) {
  79725. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid21);
  79726. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid22);
  79727. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid23);
  79728. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid24);
  79729. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid25);
  79730. }
  79731. }
  79732. }
  79733. SSL_CTX_free(ctx);
  79734. SSL_free(ssl);
  79735. #endif
  79736. return EXPECT_RESULT();
  79737. }
  79738. #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  79739. static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
  79740. int* keyFormat)
  79741. {
  79742. int ret;
  79743. byte* key_buf = NULL;
  79744. size_t key_sz = 0;
  79745. EncryptedInfo encInfo;
  79746. XMEMSET(&encInfo, 0, sizeof(encInfo));
  79747. ret = load_file(privKeyFile, &key_buf, &key_sz);
  79748. if (ret == 0) {
  79749. ret = wc_PemToDer(key_buf, key_sz, PRIVATEKEY_TYPE, pDer,
  79750. NULL, &encInfo, keyFormat);
  79751. }
  79752. if (key_buf != NULL) {
  79753. free(key_buf); key_buf = NULL;
  79754. }
  79755. (void)encInfo; /* not used in this test */
  79756. #ifdef DEBUG_WOLFSSL
  79757. fprintf(stderr, "%s (%d): Loading PEM %s (len %d) to DER (len %d)\n",
  79758. (ret == 0) ? "Success" : "Failure", ret, privKeyFile, (int)key_sz,
  79759. (*pDer)->length);
  79760. #endif
  79761. return ret;
  79762. }
  79763. static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
  79764. {
  79765. int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  79766. const char* privKeyFile = (const char*)ctx;
  79767. DerBuffer* pDer = NULL;
  79768. int keyFormat = 0;
  79769. if (info->algo_type == WC_ALGO_TYPE_PK) {
  79770. #ifdef DEBUG_WOLFSSL
  79771. fprintf(stderr, "test_CryptoCb_Func: Pk Type %d\n", info->pk.type);
  79772. #endif
  79773. #ifndef NO_RSA
  79774. if (info->pk.type == WC_PK_TYPE_RSA) {
  79775. switch (info->pk.rsa.type) {
  79776. case RSA_PUBLIC_ENCRYPT:
  79777. case RSA_PUBLIC_DECRYPT:
  79778. /* perform software based RSA public op */
  79779. ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); /* fallback to software */
  79780. break;
  79781. case RSA_PRIVATE_ENCRYPT:
  79782. case RSA_PRIVATE_DECRYPT:
  79783. {
  79784. RsaKey key;
  79785. /* perform software based RSA private op */
  79786. #ifdef DEBUG_WOLFSSL
  79787. fprintf(stderr, "test_CryptoCb_Func: RSA Priv\n");
  79788. #endif
  79789. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  79790. &keyFormat);
  79791. if (ret != 0) {
  79792. return ret;
  79793. }
  79794. ret = wc_InitRsaKey(&key, HEAP_HINT);
  79795. if (ret == 0) {
  79796. word32 keyIdx = 0;
  79797. /* load RSA private key and perform private transform */
  79798. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  79799. &key, pDer->length);
  79800. if (ret == 0) {
  79801. ret = wc_RsaFunction(
  79802. info->pk.rsa.in, info->pk.rsa.inLen,
  79803. info->pk.rsa.out, info->pk.rsa.outLen,
  79804. info->pk.rsa.type, &key, info->pk.rsa.rng);
  79805. }
  79806. else {
  79807. /* if decode fails, then fall-back to software based crypto */
  79808. fprintf(stderr, "test_CryptoCb_Func: RSA private "
  79809. "key decode failed %d, falling back to "
  79810. "software\n", ret);
  79811. ret = CRYPTOCB_UNAVAILABLE;
  79812. }
  79813. wc_FreeRsaKey(&key);
  79814. }
  79815. wc_FreeDer(&pDer); pDer = NULL;
  79816. break;
  79817. }
  79818. }
  79819. #ifdef DEBUG_WOLFSSL
  79820. fprintf(stderr, "test_CryptoCb_Func: RSA Type %d, Ret %d, Out %d\n",
  79821. info->pk.rsa.type, ret, *info->pk.rsa.outLen);
  79822. #endif
  79823. }
  79824. #ifdef WOLF_CRYPTO_CB_RSA_PAD
  79825. else if (info->pk.type == WC_PK_TYPE_RSA_PKCS ||
  79826. info->pk.type == WC_PK_TYPE_RSA_PSS ||
  79827. info->pk.type == WC_PK_TYPE_RSA_OAEP) {
  79828. RsaKey key;
  79829. if (info->pk.rsa.type == RSA_PUBLIC_ENCRYPT ||
  79830. info->pk.rsa.type == RSA_PUBLIC_DECRYPT) {
  79831. /* Have all public key ops fall back to SW */
  79832. return CRYPTOCB_UNAVAILABLE;
  79833. }
  79834. if (info->pk.rsa.padding == NULL) {
  79835. return BAD_FUNC_ARG;
  79836. }
  79837. /* Initialize key */
  79838. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  79839. &keyFormat);
  79840. if (ret != 0) {
  79841. return ret;
  79842. }
  79843. ret = wc_InitRsaKey(&key, HEAP_HINT);
  79844. if (ret == 0) {
  79845. word32 keyIdx = 0;
  79846. /* load RSA private key and perform private transform */
  79847. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  79848. &key, pDer->length);
  79849. }
  79850. /* Perform RSA operation */
  79851. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PKCS)) {
  79852. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  79853. ret = wc_RsaSSL_Sign(info->pk.rsa.in, info->pk.rsa.inLen,
  79854. info->pk.rsa.out, *info->pk.rsa.outLen, &key,
  79855. info->pk.rsa.rng);
  79856. #else
  79857. ret = CRYPTOCB_UNAVAILABLE;
  79858. #endif
  79859. }
  79860. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PSS)) {
  79861. #ifdef WC_RSA_PSS
  79862. ret = wc_RsaPSS_Sign_ex(info->pk.rsa.in, info->pk.rsa.inLen,
  79863. info->pk.rsa.out, *info->pk.rsa.outLen,
  79864. info->pk.rsa.padding->hash, info->pk.rsa.padding->mgf,
  79865. info->pk.rsa.padding->saltLen, &key, info->pk.rsa.rng);
  79866. #else
  79867. ret = CRYPTOCB_UNAVAILABLE;
  79868. #endif
  79869. }
  79870. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_OAEP)) {
  79871. #if !defined(WC_NO_RSA_OAEP) || defined(WC_RSA_NO_PADDING)
  79872. ret = wc_RsaPrivateDecrypt_ex(
  79873. info->pk.rsa.in, info->pk.rsa.inLen,
  79874. info->pk.rsa.out, *info->pk.rsa.outLen,
  79875. &key, WC_RSA_OAEP_PAD, info->pk.rsa.padding->hash,
  79876. info->pk.rsa.padding->mgf, info->pk.rsa.padding->label,
  79877. info->pk.rsa.padding->labelSz);
  79878. #else
  79879. ret = CRYPTOCB_UNAVAILABLE;
  79880. #endif
  79881. }
  79882. if (ret > 0) {
  79883. *info->pk.rsa.outLen = ret;
  79884. }
  79885. wc_FreeRsaKey(&key);
  79886. wc_FreeDer(&pDer); pDer = NULL;
  79887. }
  79888. #endif /* ifdef WOLF_CRYPTO_CB_RSA_PAD */
  79889. #endif /* !NO_RSA */
  79890. #ifdef HAVE_ECC
  79891. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  79892. /* mark this key as ephemeral */
  79893. if (info->pk.eckg.key != NULL) {
  79894. XSTRNCPY(info->pk.eckg.key->label, "ephemeral",
  79895. sizeof(info->pk.eckg.key->label));
  79896. info->pk.eckg.key->labelLen = (int)XSTRLEN(info->pk.eckg.key->label);
  79897. }
  79898. }
  79899. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  79900. ecc_key key;
  79901. /* perform software based ECC sign */
  79902. #ifdef DEBUG_WOLFSSL
  79903. fprintf(stderr, "test_CryptoCb_Func: ECC Sign\n");
  79904. #endif
  79905. if (info->pk.eccsign.key != NULL &&
  79906. XSTRCMP(info->pk.eccsign.key->label, "ephemeral") == 0) {
  79907. /* this is an empheral key */
  79908. #ifdef DEBUG_WOLFSSL
  79909. fprintf(stderr, "test_CryptoCb_Func: skipping signing op on "
  79910. "ephemeral key\n");
  79911. #endif
  79912. return CRYPTOCB_UNAVAILABLE;
  79913. }
  79914. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  79915. if (ret != 0) {
  79916. return ret;
  79917. }
  79918. ret = wc_ecc_init(&key);
  79919. if (ret == 0) {
  79920. word32 keyIdx = 0;
  79921. /* load ECC private key and perform private transform */
  79922. ret = wc_EccPrivateKeyDecode(pDer->buffer, &keyIdx,
  79923. &key, pDer->length);
  79924. if (ret == 0) {
  79925. ret = wc_ecc_sign_hash(
  79926. info->pk.eccsign.in, info->pk.eccsign.inlen,
  79927. info->pk.eccsign.out, info->pk.eccsign.outlen,
  79928. info->pk.eccsign.rng, &key);
  79929. }
  79930. else {
  79931. /* if decode fails, then fall-back to software based crypto */
  79932. fprintf(stderr, "test_CryptoCb_Func: ECC private key "
  79933. "decode failed %d, falling back to software\n", ret);
  79934. ret = CRYPTOCB_UNAVAILABLE;
  79935. }
  79936. wc_ecc_free(&key);
  79937. }
  79938. wc_FreeDer(&pDer); pDer = NULL;
  79939. #ifdef DEBUG_WOLFSSL
  79940. fprintf(stderr, "test_CryptoCb_Func: ECC Ret %d, Out %d\n",
  79941. ret, *info->pk.eccsign.outlen);
  79942. #endif
  79943. }
  79944. #endif /* HAVE_ECC */
  79945. #ifdef HAVE_ED25519
  79946. if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  79947. ed25519_key key;
  79948. /* perform software based ED25519 sign */
  79949. #ifdef DEBUG_WOLFSSL
  79950. fprintf(stderr, "test_CryptoCb_Func: ED25519 Sign\n");
  79951. #endif
  79952. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  79953. if (ret != 0) {
  79954. return ret;
  79955. }
  79956. ret = wc_ed25519_init(&key);
  79957. if (ret == 0) {
  79958. word32 keyIdx = 0;
  79959. /* load ED25519 private key and perform private transform */
  79960. ret = wc_Ed25519PrivateKeyDecode(pDer->buffer, &keyIdx,
  79961. &key, pDer->length);
  79962. if (ret == 0) {
  79963. /* calculate public key */
  79964. ret = wc_ed25519_make_public(&key, key.p, ED25519_PUB_KEY_SIZE);
  79965. if (ret == 0) {
  79966. key.pubKeySet = 1;
  79967. ret = wc_ed25519_sign_msg_ex(
  79968. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  79969. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  79970. &key, info->pk.ed25519sign.type,
  79971. info->pk.ed25519sign.context,
  79972. info->pk.ed25519sign.contextLen);
  79973. }
  79974. }
  79975. else {
  79976. /* if decode fails, then fall-back to software based crypto */
  79977. fprintf(stderr, "test_CryptoCb_Func: ED25519 private key "
  79978. "decode failed %d, falling back to software\n", ret);
  79979. ret = CRYPTOCB_UNAVAILABLE;
  79980. }
  79981. wc_ed25519_free(&key);
  79982. }
  79983. wc_FreeDer(&pDer); pDer = NULL;
  79984. #ifdef DEBUG_WOLFSSL
  79985. fprintf(stderr, "test_CryptoCb_Func: ED25519 Ret %d, Out %d\n",
  79986. ret, *info->pk.ed25519sign.outLen);
  79987. #endif
  79988. }
  79989. #endif /* HAVE_ED25519 */
  79990. }
  79991. (void)thisDevId;
  79992. (void)keyFormat;
  79993. return ret;
  79994. }
  79995. /* tlsVer: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  79996. static int test_wc_CryptoCb_TLS(int tlsVer,
  79997. const char* cliCaPemFile, const char* cliCertPemFile,
  79998. const char* cliPrivKeyPemFile, const char* cliPubKeyPemFile,
  79999. const char* svrCaPemFile, const char* svrCertPemFile,
  80000. const char* svrPrivKeyPemFile, const char* svrPubKeyPemFile)
  80001. {
  80002. EXPECT_DECLS;
  80003. callback_functions client_cbf;
  80004. callback_functions server_cbf;
  80005. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80006. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80007. if (tlsVer == WOLFSSL_TLSV1_3) {
  80008. #ifdef WOLFSSL_TLS13
  80009. server_cbf.method = wolfTLSv1_3_server_method;
  80010. client_cbf.method = wolfTLSv1_3_client_method;
  80011. #endif
  80012. }
  80013. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80014. #ifndef WOLFSSL_NO_TLS12
  80015. server_cbf.method = wolfTLSv1_2_server_method;
  80016. client_cbf.method = wolfTLSv1_2_client_method;
  80017. #endif
  80018. }
  80019. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80020. #ifndef NO_OLD_TLS
  80021. server_cbf.method = wolfTLSv1_1_server_method;
  80022. client_cbf.method = wolfTLSv1_1_client_method;
  80023. #endif
  80024. }
  80025. else if (tlsVer == WOLFSSL_TLSV1) {
  80026. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80027. server_cbf.method = wolfTLSv1_server_method;
  80028. client_cbf.method = wolfTLSv1_client_method;
  80029. #endif
  80030. }
  80031. else if (tlsVer == WOLFSSL_SSLV3) {
  80032. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80033. defined(WOLFSSL_STATIC_RSA)
  80034. server_cbf.method = wolfSSLv3_server_method;
  80035. client_cbf.method = wolfSSLv3_client_method;
  80036. #endif
  80037. }
  80038. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80039. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80040. server_cbf.method = wolfDTLSv1_2_server_method;
  80041. client_cbf.method = wolfDTLSv1_2_client_method;
  80042. #endif
  80043. }
  80044. else if (tlsVer == WOLFSSL_DTLSV1) {
  80045. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80046. server_cbf.method = wolfDTLSv1_server_method;
  80047. client_cbf.method = wolfDTLSv1_client_method;
  80048. #endif
  80049. }
  80050. if (server_cbf.method == NULL) {
  80051. /* not enabled */
  80052. return TEST_SUCCESS;
  80053. }
  80054. /* Setup the keys for the TLS test */
  80055. client_cbf.certPemFile = cliCertPemFile;
  80056. client_cbf.keyPemFile = cliPubKeyPemFile;
  80057. client_cbf.caPemFile = cliCaPemFile;
  80058. server_cbf.certPemFile = svrCertPemFile;
  80059. server_cbf.keyPemFile = svrPubKeyPemFile;
  80060. server_cbf.caPemFile = svrCaPemFile;
  80061. /* Setup a crypto callback with pointer to private key file for testing */
  80062. client_cbf.devId = 1;
  80063. wc_CryptoCb_RegisterDevice(client_cbf.devId, test_CryptoCb_Func,
  80064. (void*)cliPrivKeyPemFile);
  80065. server_cbf.devId = 2;
  80066. wc_CryptoCb_RegisterDevice(server_cbf.devId, test_CryptoCb_Func,
  80067. (void*)svrPrivKeyPemFile);
  80068. /* Perform TLS server and client test */
  80069. /* First test is at WOLFSSL_CTX level */
  80070. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80071. /* Check for success */
  80072. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80073. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80074. if (EXPECT_SUCCESS()) {
  80075. /* Second test is a WOLFSSL object level */
  80076. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80077. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80078. }
  80079. /* Check for success */
  80080. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80081. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80082. /* Un register the devId's */
  80083. wc_CryptoCb_UnRegisterDevice(client_cbf.devId);
  80084. client_cbf.devId = INVALID_DEVID;
  80085. wc_CryptoCb_UnRegisterDevice(server_cbf.devId);
  80086. server_cbf.devId = INVALID_DEVID;
  80087. return EXPECT_RESULT();
  80088. }
  80089. #endif /* WOLF_CRYPTO_CB && HAVE_IO_TESTS_DEPENDENCIES */
  80090. static int test_wc_CryptoCb(void)
  80091. {
  80092. EXPECT_DECLS;
  80093. #ifdef WOLF_CRYPTO_CB
  80094. /* TODO: Add crypto callback API tests */
  80095. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80096. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80097. int tlsVer;
  80098. #endif
  80099. #ifndef NO_RSA
  80100. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80101. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80102. svrCertFile, cliCertFile, cliKeyFile, cliKeyPubFile,
  80103. cliCertFile, svrCertFile, svrKeyFile, svrKeyPubFile),
  80104. TEST_SUCCESS);
  80105. }
  80106. #endif
  80107. #ifdef HAVE_ECC
  80108. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80109. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80110. caEccCertFile, cliEccCertFile, cliEccKeyFile, cliEccKeyPubFile,
  80111. cliEccCertFile, eccCertFile, eccKeyFile, eccKeyPubFile),
  80112. TEST_SUCCESS);
  80113. }
  80114. #endif
  80115. #ifdef HAVE_ED25519
  80116. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80117. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80118. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80119. caEdCertFile, cliEdCertFile, cliEdKeyFile, cliEdKeyPubFile,
  80120. cliEdCertFile, edCertFile, edKeyFile, edKeyPubFile),
  80121. TEST_SUCCESS);
  80122. }
  80123. #endif
  80124. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80125. #endif /* WOLF_CRYPTO_CB */
  80126. return EXPECT_RESULT();
  80127. }
  80128. #if defined(WOLFSSL_STATIC_MEMORY) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  80129. /* tlsVer: Example: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  80130. static int test_wolfSSL_CTX_StaticMemory_TLS(int tlsVer,
  80131. const char* cliCaPemFile, const char* cliCertPemFile,
  80132. const char* cliPrivKeyPemFile,
  80133. const char* svrCaPemFile, const char* svrCertPemFile,
  80134. const char* svrPrivKeyPemFile,
  80135. byte* cliMem, word32 cliMemSz, byte* svrMem, word32 svrMemSz)
  80136. {
  80137. EXPECT_DECLS;
  80138. callback_functions client_cbf;
  80139. callback_functions server_cbf;
  80140. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80141. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80142. if (tlsVer == WOLFSSL_TLSV1_3) {
  80143. #ifdef WOLFSSL_TLS13
  80144. server_cbf.method_ex = wolfTLSv1_3_server_method_ex;
  80145. client_cbf.method_ex = wolfTLSv1_3_client_method_ex;
  80146. #endif
  80147. }
  80148. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80149. #ifndef WOLFSSL_NO_TLS12
  80150. server_cbf.method_ex = wolfTLSv1_2_server_method_ex;
  80151. client_cbf.method_ex = wolfTLSv1_2_client_method_ex;
  80152. #endif
  80153. }
  80154. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80155. #ifndef NO_OLD_TLS
  80156. server_cbf.method_ex = wolfTLSv1_1_server_method_ex;
  80157. client_cbf.method_ex = wolfTLSv1_1_client_method_ex;
  80158. #endif
  80159. }
  80160. else if (tlsVer == WOLFSSL_TLSV1) {
  80161. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80162. server_cbf.method_ex = wolfTLSv1_server_method_ex;
  80163. client_cbf.method_ex = wolfTLSv1_client_method_ex;
  80164. #endif
  80165. }
  80166. else if (tlsVer == WOLFSSL_SSLV3) {
  80167. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80168. defined(WOLFSSL_STATIC_RSA)
  80169. server_cbf.method_ex = wolfSSLv3_server_method_ex;
  80170. client_cbf.method_ex = wolfSSLv3_client_method_ex;
  80171. #endif
  80172. }
  80173. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80174. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80175. server_cbf.method_ex = wolfDTLSv1_2_server_method_ex;
  80176. client_cbf.method_ex = wolfDTLSv1_2_client_method_ex;
  80177. #endif
  80178. }
  80179. else if (tlsVer == WOLFSSL_DTLSV1) {
  80180. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80181. server_cbf.method_ex = wolfDTLSv1_server_method_ex;
  80182. client_cbf.method_ex = wolfDTLSv1_client_method_ex;
  80183. #endif
  80184. }
  80185. if (server_cbf.method_ex == NULL) {
  80186. /* not enabled */
  80187. return TEST_SUCCESS;
  80188. }
  80189. /* Setup the keys for the TLS test */
  80190. client_cbf.certPemFile = cliCertPemFile;
  80191. client_cbf.keyPemFile = cliPrivKeyPemFile;
  80192. client_cbf.caPemFile = cliCaPemFile;
  80193. server_cbf.certPemFile = svrCertPemFile;
  80194. server_cbf.keyPemFile = svrPrivKeyPemFile;
  80195. server_cbf.caPemFile = svrCaPemFile;
  80196. client_cbf.mem = cliMem;
  80197. client_cbf.memSz = cliMemSz;
  80198. server_cbf.mem = svrMem;
  80199. server_cbf.memSz = svrMemSz;
  80200. client_cbf.devId = INVALID_DEVID;
  80201. server_cbf.devId = INVALID_DEVID;
  80202. /* Perform TLS server and client test */
  80203. /* First test is at WOLFSSL_CTX level */
  80204. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80205. /* Check for success */
  80206. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80207. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80208. if (EXPECT_SUCCESS()) {
  80209. /* Second test is a WOLFSSL object level */
  80210. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80211. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80212. }
  80213. /* Check for success */
  80214. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80215. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80216. return EXPECT_RESULT();
  80217. }
  80218. #endif /* WOLFSSL_STATIC_MEMORY && HAVE_IO_TESTS_DEPENDENCIES */
  80219. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80220. static int test_wolfSSL_CTX_StaticMemory_SSL(WOLFSSL_CTX* ctx)
  80221. {
  80222. EXPECT_DECLS;
  80223. WOLFSSL *ssl1 = NULL, *ssl2 = NULL, *ssl3 = NULL;
  80224. WOLFSSL_MEM_STATS mem_stats;
  80225. WOLFSSL_MEM_CONN_STATS ssl_stats;
  80226. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  80227. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  80228. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80229. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  80230. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80231. #endif
  80232. ExpectNotNull((ssl1 = wolfSSL_new(ctx)));
  80233. ExpectNotNull((ssl2 = wolfSSL_new(ctx)));
  80234. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  80235. /* this should fail because kMaxCtxClients == 2 */
  80236. ExpectNull((ssl3 = wolfSSL_new(ctx)));
  80237. #else
  80238. (void)ssl3;
  80239. #endif
  80240. if (wolfSSL_is_static_memory(ssl1, &ssl_stats) == 1) {
  80241. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80242. wolfSSL_PrintStatsConn(&ssl_stats);
  80243. #endif
  80244. (void)ssl_stats;
  80245. }
  80246. /* display collected statistics */
  80247. if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) == 1) {
  80248. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80249. wolfSSL_PrintStats(&mem_stats);
  80250. #endif
  80251. (void)mem_stats;
  80252. }
  80253. wolfSSL_free(ssl1);
  80254. wolfSSL_free(ssl2);
  80255. return EXPECT_RESULT();
  80256. }
  80257. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80258. static int test_wolfSSL_CTX_StaticMemory(void)
  80259. {
  80260. EXPECT_DECLS;
  80261. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80262. wolfSSL_method_func method_func;
  80263. WOLFSSL_CTX* ctx;
  80264. const int kMaxCtxClients = 2;
  80265. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80266. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80267. int tlsVer;
  80268. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  80269. #endif
  80270. #endif
  80271. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  80272. #ifndef NO_WOLFSSL_SERVER
  80273. #ifndef WOLFSSL_NO_TLS12
  80274. method_func = wolfTLSv1_2_server_method_ex;
  80275. #else
  80276. method_func = wolfTLSv1_3_server_method_ex;
  80277. #endif
  80278. #else
  80279. #ifndef WOLFSSL_NO_TLS12
  80280. method_func = wolfTLSv1_2_client_method_ex;
  80281. #else
  80282. method_func = wolfTLSv1_3_client_method_ex;
  80283. #endif
  80284. #endif
  80285. /* Test creating CTX directly from static memory pool */
  80286. ctx = NULL;
  80287. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, method_func, svrMem,
  80288. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80289. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80290. wolfSSL_CTX_free(ctx);
  80291. ctx = NULL;
  80292. /* Test for heap allocated CTX, then assigning static pool to it */
  80293. ExpectNotNull(ctx = wolfSSL_CTX_new(method_func(NULL)));
  80294. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, NULL, svrMem,
  80295. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80296. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80297. wolfSSL_CTX_free(ctx);
  80298. /* TLS Level Tests using static memory */
  80299. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80300. #ifndef NO_RSA
  80301. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80302. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80303. svrCertFile, cliCertFile, cliKeyFile,
  80304. cliCertFile, svrCertFile, svrKeyFile,
  80305. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80306. TEST_SUCCESS);
  80307. }
  80308. #endif
  80309. #ifdef HAVE_ECC
  80310. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80311. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80312. caEccCertFile, cliEccCertFile, cliEccKeyFile,
  80313. cliEccCertFile, eccCertFile, eccKeyFile,
  80314. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80315. TEST_SUCCESS);
  80316. }
  80317. #endif
  80318. #ifdef HAVE_ED25519
  80319. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80320. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80321. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80322. caEdCertFile, cliEdCertFile, cliEdKeyFile,
  80323. cliEdCertFile, edCertFile, edKeyFile,
  80324. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80325. TEST_SUCCESS);
  80326. }
  80327. #endif
  80328. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80329. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80330. return EXPECT_RESULT();
  80331. }
  80332. static int test_openssl_FIPS_drbg(void)
  80333. {
  80334. EXPECT_DECLS;
  80335. #if defined(OPENSSL_EXTRA) && !defined(WC_NO_RNG) && defined(HAVE_HASHDRBG)
  80336. DRBG_CTX* dctx = NULL;
  80337. byte data1[32], data2[32], zeroData[32];
  80338. byte testSeed[16];
  80339. size_t dlen = sizeof(data1);
  80340. int i;
  80341. XMEMSET(data1, 0, dlen);
  80342. XMEMSET(data2, 0, dlen);
  80343. XMEMSET(zeroData, 0, sizeof(zeroData));
  80344. for (i = 0; i < (int)sizeof(testSeed); i++) {
  80345. testSeed[i] = (byte)i;
  80346. }
  80347. ExpectNotNull(dctx = FIPS_get_default_drbg());
  80348. ExpectIntEQ(FIPS_drbg_init(dctx, 0, 0), WOLFSSL_SUCCESS);
  80349. ExpectIntEQ(FIPS_drbg_set_callbacks(dctx, NULL, NULL, 20, NULL, NULL),
  80350. WOLFSSL_SUCCESS);
  80351. ExpectIntEQ(FIPS_drbg_instantiate(dctx, NULL, 0), WOLFSSL_SUCCESS);
  80352. ExpectIntEQ(FIPS_drbg_generate(dctx, data1, dlen, 0, NULL, 0),
  80353. WOLFSSL_SUCCESS);
  80354. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80355. ExpectIntEQ(FIPS_drbg_reseed(dctx, testSeed, sizeof(testSeed)),
  80356. WOLFSSL_SUCCESS);
  80357. ExpectIntEQ(FIPS_drbg_generate(dctx, data2, dlen, 0, NULL, 0),
  80358. WOLFSSL_SUCCESS);
  80359. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80360. ExpectIntNE(XMEMCMP(data1, data2, dlen), 0);
  80361. ExpectIntEQ(FIPS_drbg_uninstantiate(dctx), WOLFSSL_SUCCESS);
  80362. #ifndef HAVE_GLOBAL_RNG
  80363. /* gets freed by wolfSSL_Cleanup() when HAVE_GLOBAL_RNG defined */
  80364. wolfSSL_FIPS_drbg_free(dctx);
  80365. #endif
  80366. #endif
  80367. return EXPECT_RESULT();
  80368. }
  80369. static int test_wolfSSL_FIPS_mode(void)
  80370. {
  80371. EXPECT_DECLS;
  80372. #if defined(OPENSSL_ALL)
  80373. #ifdef HAVE_FIPS
  80374. ExpectIntEQ(wolfSSL_FIPS_mode(), 1);
  80375. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80376. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WOLFSSL_SUCCESS);
  80377. #else
  80378. ExpectIntEQ(wolfSSL_FIPS_mode(), 0);
  80379. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WOLFSSL_SUCCESS);
  80380. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80381. #endif
  80382. #endif
  80383. return EXPECT_RESULT();
  80384. }
  80385. #ifdef WOLFSSL_DTLS
  80386. /* Prints out the current window */
  80387. static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) {
  80388. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80389. int i;
  80390. for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) {
  80391. word32 b = w[i];
  80392. int j;
  80393. /* Prints out a 32 bit binary number in big endian order */
  80394. for (j = 0; j < 32; j++, b <<= 1) {
  80395. if (b & (((word32)1) << 31))
  80396. fprintf(stderr, "1");
  80397. else
  80398. fprintf(stderr, "0");
  80399. }
  80400. fprintf(stderr, " ");
  80401. }
  80402. fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l);
  80403. #else
  80404. (void)h;
  80405. (void)l;
  80406. (void)w;
  80407. #endif
  80408. }
  80409. /* a - cur_hi
  80410. * b - cur_lo
  80411. * c - next_hi
  80412. * d - next_lo
  80413. * e - window
  80414. * f - expected next_hi
  80415. * g - expected next_lo
  80416. * h - expected window[1]
  80417. * i - expected window[0]
  80418. */
  80419. #define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \
  80420. ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \
  80421. DUW_TEST_print_window_binary((a), (b), (e)); \
  80422. ExpectIntEQ((c), (f)); \
  80423. ExpectIntEQ((d), (g)); \
  80424. ExpectIntEQ((e)[1], (h)); \
  80425. ExpectIntEQ((e)[0], (i)); \
  80426. } while (0)
  80427. static int test_wolfSSL_DtlsUpdateWindow(void)
  80428. {
  80429. EXPECT_DECLS;
  80430. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  80431. word32 next_lo = 0;
  80432. word16 next_hi = 0;
  80433. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80434. fprintf(stderr, "\n");
  80435. #endif
  80436. XMEMSET(window, 0, sizeof window);
  80437. DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01);
  80438. DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03);
  80439. DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31);
  80440. DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33);
  80441. DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01);
  80442. DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03);
  80443. DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01);
  80444. DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01);
  80445. DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01);
  80446. DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01);
  80447. DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05);
  80448. DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07);
  80449. DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71);
  80450. DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79);
  80451. DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01);
  80452. DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11);
  80453. DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19);
  80454. DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001);
  80455. DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005);
  80456. DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015);
  80457. DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151);
  80458. DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80459. DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80460. DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01);
  80461. DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11);
  80462. DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80463. DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80464. DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80465. DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80466. DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80467. DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01);
  80468. DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01);
  80469. return EXPECT_RESULT();
  80470. }
  80471. #endif /* WOLFSSL_DTLS */
  80472. #ifdef WOLFSSL_DTLS
  80473. static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset,
  80474. word32 f_len, word32 f_count, byte ready, word32 bytesReceived)
  80475. {
  80476. DtlsMsg* cur;
  80477. static byte msg[100];
  80478. static byte msgInit = 0;
  80479. if (!msgInit) {
  80480. int i;
  80481. for (i = 0; i < 100; i++)
  80482. msg[i] = i + 1;
  80483. msgInit = 1;
  80484. }
  80485. /* Sanitize test parameters */
  80486. if (len > sizeof(msg))
  80487. return -1;
  80488. if (f_offset + f_len > sizeof(msg))
  80489. return -1;
  80490. DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL);
  80491. if (ssl->dtls_rx_msg_list == NULL)
  80492. return -100;
  80493. if ((cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)) == NULL)
  80494. return -200;
  80495. if (cur->fragBucketListCount != f_count)
  80496. return -300;
  80497. if (cur->ready != ready)
  80498. return -400;
  80499. if (cur->bytesReceived != bytesReceived)
  80500. return -500;
  80501. if (ready) {
  80502. if (cur->fragBucketList != NULL)
  80503. return -600;
  80504. if (XMEMCMP(cur->fullMsg, msg, cur->sz) != 0)
  80505. return -700;
  80506. }
  80507. else {
  80508. DtlsFragBucket* fb;
  80509. if (cur->fragBucketList == NULL)
  80510. return -800;
  80511. for (fb = cur->fragBucketList; fb != NULL; fb = fb->m.m.next) {
  80512. if (XMEMCMP(fb->buf, msg + fb->m.m.offset, fb->m.m.sz) != 0)
  80513. return -900;
  80514. }
  80515. }
  80516. return 0;
  80517. }
  80518. static int test_wolfSSL_DTLS_fragment_buckets(void)
  80519. {
  80520. EXPECT_DECLS;
  80521. WOLFSSL ssl[1];
  80522. XMEMSET(ssl, 0, sizeof(*ssl));
  80523. ExpectIntEQ(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100), 0); /* 0-100 */
  80524. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  80525. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40), 0); /* 20-40 */
  80526. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60), 0); /* 40-60 */
  80527. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80), 0); /* 60-80 */
  80528. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100), 0); /* 80-100 */
  80529. /* Test all permutations of 3 regions */
  80530. /* 1 2 3 */
  80531. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  80532. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60), 0); /* 30-60 */
  80533. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  80534. /* 1 3 2 */
  80535. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  80536. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70), 0); /* 60-100 */
  80537. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  80538. /* 2 1 3 */
  80539. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  80540. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60), 0); /* 0-30 */
  80541. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  80542. /* 2 3 1 */
  80543. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  80544. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70), 0); /* 60-100 */
  80545. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  80546. /* 3 1 2 */
  80547. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  80548. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70), 0); /* 0-30 */
  80549. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  80550. /* 3 2 1 */
  80551. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  80552. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70), 0); /* 30-60 */
  80553. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  80554. /* Test overlapping regions */
  80555. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  80556. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30), 0); /* 20-30 */
  80557. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40), 0); /* 70-80 */
  80558. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60), 0); /* 20-50 */
  80559. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100), 0); /* 40-100 */
  80560. /* Test overlapping multiple regions */
  80561. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  80562. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25), 0); /* 30-35 */
  80563. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30), 0); /* 40-45 */
  80564. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35), 0); /* 50-55 */
  80565. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40), 0); /* 60-65 */
  80566. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45), 0); /* 70-75 */
  80567. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55), 0); /* 30-55 */
  80568. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65), 0); /* 55-70 */
  80569. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90), 0); /* 75-100 */
  80570. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100), 0); /* 10-35 */
  80571. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  80572. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 30, 20, 2, 0, 40), 0); /* 30-50 */
  80573. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 40, 1, 0, 50), 0); /* 0-40 */
  80574. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 50, 50, 0, 1, 100), 0); /* 10-35 */
  80575. DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap);
  80576. ssl->dtls_rx_msg_list = NULL;
  80577. ssl->dtls_rx_msg_list_sz = 0;
  80578. return EXPECT_RESULT();
  80579. }
  80580. #endif
  80581. #if !defined(NO_FILESYSTEM) && \
  80582. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  80583. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  80584. static int test_wolfSSL_dtls_stateless2(void)
  80585. {
  80586. EXPECT_DECLS;
  80587. WOLFSSL *ssl_c = NULL;
  80588. WOLFSSL *ssl_c2 = NULL;
  80589. WOLFSSL *ssl_s = NULL;
  80590. struct test_memio_ctx test_ctx;
  80591. WOLFSSL_CTX *ctx_c = NULL;
  80592. WOLFSSL_CTX *ctx_s = NULL;
  80593. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80594. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80595. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80596. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  80597. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  80598. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  80599. /* send CH */
  80600. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80601. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  80602. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80603. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80604. ExpectIntNE(test_ctx.c_len, 0);
  80605. /* consume HRR */
  80606. test_ctx.c_len = 0;
  80607. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  80608. wolfSSL_free(ssl_c2);
  80609. wolfSSL_free(ssl_c);
  80610. wolfSSL_free(ssl_s);
  80611. wolfSSL_CTX_free(ctx_c);
  80612. wolfSSL_CTX_free(ctx_s);
  80613. return EXPECT_RESULT();
  80614. }
  80615. #ifdef HAVE_MAX_FRAGMENT
  80616. static int test_wolfSSL_dtls_stateless_maxfrag(void)
  80617. {
  80618. EXPECT_DECLS;
  80619. WOLFSSL *ssl_c = NULL;
  80620. WOLFSSL *ssl_c2 = NULL;
  80621. WOLFSSL *ssl_s = NULL;
  80622. struct test_memio_ctx test_ctx;
  80623. WOLFSSL_CTX *ctx_c = NULL;
  80624. WOLFSSL_CTX *ctx_s = NULL;
  80625. word16 max_fragment = 0;
  80626. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80627. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80628. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80629. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  80630. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8),
  80631. WOLFSSL_SUCCESS);
  80632. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  80633. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  80634. if (ssl_s != NULL) {
  80635. max_fragment = ssl_s->max_fragment;
  80636. }
  80637. /* send CH */
  80638. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80639. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  80640. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80641. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80642. /* CH without cookie shouldn't change state */
  80643. ExpectIntEQ(ssl_s->max_fragment, max_fragment);
  80644. ExpectIntNE(test_ctx.c_len, 0);
  80645. /* consume HRR from buffer */
  80646. test_ctx.c_len = 0;
  80647. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  80648. wolfSSL_free(ssl_c2);
  80649. wolfSSL_free(ssl_c);
  80650. wolfSSL_free(ssl_s);
  80651. wolfSSL_CTX_free(ctx_c);
  80652. wolfSSL_CTX_free(ctx_s);
  80653. return EXPECT_RESULT();
  80654. }
  80655. #endif /* HAVE_MAX_FRAGMENT */
  80656. #if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME)
  80657. #define ROUNDS_WITH_HVR 4
  80658. #define ROUNDS_WITHOUT_HVR 2
  80659. #define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ
  80660. static int buf_is_hvr(const byte *data, int len)
  80661. {
  80662. if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ)
  80663. return 0;
  80664. return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request;
  80665. }
  80666. static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad)
  80667. {
  80668. EXPECT_DECLS;
  80669. struct test_memio_ctx test_ctx;
  80670. WOLFSSL_CTX *ctx_c = NULL;
  80671. WOLFSSL_CTX *ctx_s = NULL;
  80672. WOLFSSL *ssl_c = NULL;
  80673. WOLFSSL *ssl_s = NULL;
  80674. WOLFSSL_SESSION *sess = NULL;
  80675. int round_trips;
  80676. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80677. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  80678. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80679. #ifdef HAVE_SESSION_TICKET
  80680. if (useticket) {
  80681. ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS);
  80682. }
  80683. #endif
  80684. round_trips = ROUNDS_WITH_HVR;
  80685. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips,
  80686. &round_trips), 0);
  80687. ExpectIntEQ(round_trips, ROUNDS_WITH_HVR);
  80688. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  80689. wolfSSL_shutdown(ssl_c);
  80690. wolfSSL_shutdown(ssl_s);
  80691. wolfSSL_free(ssl_c);
  80692. ssl_c = NULL;
  80693. wolfSSL_free(ssl_s);
  80694. ssl_s = NULL;
  80695. test_ctx.c_len = test_ctx.s_len = 0;
  80696. /* make resumption invalid */
  80697. if (bad && (sess != NULL)) {
  80698. if (useticket) {
  80699. #ifdef HAVE_SESSION_TICKET
  80700. if (sess->ticket != NULL) {
  80701. sess->ticket[0] = !sess->ticket[0];
  80702. }
  80703. #endif /* HAVE_SESSION_TICKET */
  80704. }
  80705. else {
  80706. sess->sessionID[0] = !sess->sessionID[0];
  80707. }
  80708. }
  80709. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  80710. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  80711. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  80712. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  80713. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  80714. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  80715. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  80716. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80717. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  80718. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80719. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80720. ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  80721. ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  80722. if (!useticket) {
  80723. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0);
  80724. ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1);
  80725. ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1);
  80726. }
  80727. wolfSSL_SESSION_free(sess);
  80728. wolfSSL_free(ssl_c);
  80729. wolfSSL_free(ssl_s);
  80730. wolfSSL_CTX_free(ctx_c);
  80731. wolfSSL_CTX_free(ctx_s);
  80732. return EXPECT_RESULT();
  80733. }
  80734. static int test_wolfSSL_dtls_stateless_resume(void)
  80735. {
  80736. EXPECT_DECLS;
  80737. #ifdef HAVE_SESSION_TICKET
  80738. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS);
  80739. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS);
  80740. #endif /* HAVE_SESION_TICKET */
  80741. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS);
  80742. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS);
  80743. return EXPECT_RESULT();
  80744. }
  80745. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  80746. #if !defined(NO_OLD_TLS)
  80747. static int test_wolfSSL_dtls_stateless_downgrade(void)
  80748. {
  80749. EXPECT_DECLS;
  80750. WOLFSSL_CTX *ctx_c = NULL;
  80751. WOLFSSL_CTX *ctx_c2 = NULL;
  80752. WOLFSSL_CTX *ctx_s = NULL;
  80753. WOLFSSL *ssl_c = NULL;
  80754. WOLFSSL *ssl_c2 = NULL;
  80755. WOLFSSL *ssl_s = NULL;
  80756. struct test_memio_ctx test_ctx;
  80757. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80758. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80759. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80760. ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1),
  80761. WOLFSSL_SUCCESS);
  80762. ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method()));
  80763. wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb);
  80764. wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb);
  80765. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2));
  80766. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  80767. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  80768. /* send CH */
  80769. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80770. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  80771. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80772. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80773. ExpectIntNE(test_ctx.c_len, 0);
  80774. /* consume HRR */
  80775. test_ctx.c_len = 0;
  80776. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  80777. wolfSSL_free(ssl_c2);
  80778. wolfSSL_free(ssl_c);
  80779. wolfSSL_free(ssl_s);
  80780. wolfSSL_CTX_free(ctx_c);
  80781. wolfSSL_CTX_free(ctx_c2);
  80782. wolfSSL_CTX_free(ctx_s);
  80783. return EXPECT_RESULT();
  80784. }
  80785. #endif /* !defined(NO_OLD_TLS) */
  80786. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  80787. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/
  80788. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  80789. !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  80790. static int test_WOLFSSL_dtls_version_alert(void)
  80791. {
  80792. EXPECT_DECLS;
  80793. struct test_memio_ctx test_ctx;
  80794. WOLFSSL_CTX *ctx_c = NULL;
  80795. WOLFSSL_CTX *ctx_s = NULL;
  80796. WOLFSSL *ssl_c = NULL;
  80797. WOLFSSL *ssl_s = NULL;
  80798. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80799. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80800. wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0);
  80801. /* client hello */
  80802. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80803. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  80804. /* hrr */
  80805. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80806. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80807. /* client hello 1 */
  80808. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80809. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  80810. /* server hello */
  80811. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80812. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80813. /* should fail */
  80814. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80815. (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR)));
  80816. /* shuould fail */
  80817. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80818. (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR)));
  80819. wolfSSL_free(ssl_c);
  80820. wolfSSL_free(ssl_s);
  80821. wolfSSL_CTX_free(ctx_c);
  80822. wolfSSL_CTX_free(ctx_s);
  80823. return EXPECT_RESULT();
  80824. }
  80825. #else
  80826. static int test_WOLFSSL_dtls_version_alert(void)
  80827. {
  80828. return TEST_SKIPPED;
  80829. }
  80830. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) &&
  80831. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) &&
  80832. * !defined(NO_OLD_TLS) && !defined(NO_RSA)
  80833. */
  80834. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  80835. && defined(WOLFSSL_TLS13) && \
  80836. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))\
  80837. && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  80838. static int send_new_session_ticket(WOLFSSL *ssl, byte nonceLength, byte filler)
  80839. {
  80840. struct test_memio_ctx *test_ctx;
  80841. byte buf[2048];
  80842. int idx, sz;
  80843. word32 tmp;
  80844. int ret;
  80845. idx = 5; /* space for record header */
  80846. buf[idx] = session_ticket; /* type */
  80847. idx++;
  80848. tmp = OPAQUE32_LEN +
  80849. OPAQUE32_LEN +
  80850. OPAQUE8_LEN + nonceLength +
  80851. OPAQUE16_LEN + OPAQUE8_LEN + OPAQUE16_LEN;
  80852. c32to24(tmp, buf + idx);
  80853. idx += OPAQUE24_LEN;
  80854. c32toa((word32)12345, buf+idx); /* lifetime */
  80855. idx += OPAQUE32_LEN;
  80856. c32toa((word32)12345, buf+idx); /* add */
  80857. idx += OPAQUE32_LEN;
  80858. buf[idx] = nonceLength; /* nonce length */
  80859. idx++;
  80860. XMEMSET(&buf[idx], filler, nonceLength); /* nonce */
  80861. idx += nonceLength;
  80862. tmp = 1; /* ticket len */
  80863. c16toa((word16)tmp, buf+idx);
  80864. idx += 2;
  80865. buf[idx] = 0xFF; /* ticket */
  80866. idx++;
  80867. tmp = 0; /* ext len */
  80868. c16toa((word16)tmp, buf+idx);
  80869. idx += 2;
  80870. sz = BuildTls13Message(ssl, buf, 2048, buf+5, idx - 5,
  80871. handshake, 0, 0, 0);
  80872. AssertIntGT(sz, 0);
  80873. test_ctx = (struct test_memio_ctx*)wolfSSL_GetIOWriteCtx(ssl);
  80874. AssertNotNull(test_ctx);
  80875. ret = test_memio_write_cb(ssl, (char*)buf, sz, test_ctx);
  80876. return !(ret == sz);
  80877. }
  80878. static int test_ticket_nonce_check(WOLFSSL_SESSION *sess, byte len)
  80879. {
  80880. int ret = 0;
  80881. if ((sess == NULL) || (sess->ticketNonce.len != len)) {
  80882. ret = -1;
  80883. }
  80884. else {
  80885. int i;
  80886. for (i = 0; i < len; i++) {
  80887. if (sess->ticketNonce.data[i] != len) {
  80888. ret = -1;
  80889. break;
  80890. }
  80891. }
  80892. }
  80893. return ret;
  80894. }
  80895. static int test_ticket_nonce_malloc_do(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  80896. {
  80897. EXPECT_DECLS;
  80898. char *buf[1024];
  80899. ExpectIntEQ(send_new_session_ticket(ssl_s, len, len), 0);
  80900. ExpectTrue((wolfSSL_recv(ssl_c, buf, 1024, 0) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80901. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  80902. ExpectIntEQ(test_ticket_nonce_check(ssl_c->session, len), 0);
  80903. return EXPECT_RESULT();
  80904. }
  80905. static int test_ticket_nonce_cache(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  80906. {
  80907. EXPECT_DECLS;
  80908. WOLFSSL_SESSION *sess = NULL;
  80909. WOLFSSL_SESSION *cached = NULL;
  80910. WOLFSSL_CTX *ctx = ssl_c->ctx;
  80911. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, len), TEST_SUCCESS);
  80912. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  80913. ExpectIntEQ(AddSessionToCache(ctx, sess, sess->sessionID, sess->sessionIDSz,
  80914. NULL, ssl_c->options.side, 1,NULL), 0);
  80915. ExpectNotNull(cached = wolfSSL_SESSION_new());
  80916. ExpectIntEQ(wolfSSL_GetSessionFromCache(ssl_c, cached), WOLFSSL_SUCCESS);
  80917. ExpectIntEQ(test_ticket_nonce_check(cached, len), 0);
  80918. wolfSSL_SESSION_free(cached);
  80919. wolfSSL_SESSION_free(sess);
  80920. return EXPECT_RESULT();
  80921. }
  80922. static int test_ticket_nonce_malloc(void)
  80923. {
  80924. EXPECT_DECLS;
  80925. struct test_memio_ctx test_ctx;
  80926. WOLFSSL_CTX *ctx_c = NULL;
  80927. WOLFSSL_CTX *ctx_s = NULL;
  80928. WOLFSSL *ssl_c = NULL;
  80929. WOLFSSL *ssl_s = NULL;
  80930. byte small;
  80931. byte medium;
  80932. byte big;
  80933. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80934. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80935. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  80936. /* will send ticket manually */
  80937. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(ssl_s), 0);
  80938. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  80939. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  80940. while (EXPECT_SUCCESS() && (ssl_c->options.handShakeDone == 0) &&
  80941. (ssl_s->options.handShakeDone == 0)) {
  80942. ExpectTrue((wolfSSL_connect(ssl_c) == WOLFSSL_SUCCESS) ||
  80943. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  80944. ExpectTrue((wolfSSL_accept(ssl_s) == WOLFSSL_SUCCESS) ||
  80945. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80946. }
  80947. small = TLS13_TICKET_NONCE_STATIC_SZ;
  80948. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 <= 255
  80949. medium = small + 20;
  80950. #else
  80951. medium = 255;
  80952. #endif
  80953. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 + 20 <= 255
  80954. big = small + 20;
  80955. #else
  80956. big = 255;
  80957. #endif
  80958. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  80959. ExpectPtrEq(ssl_c->session->ticketNonce.data,
  80960. ssl_c->session->ticketNonce.dataStatic);
  80961. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  80962. TEST_SUCCESS);
  80963. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, big), TEST_SUCCESS);
  80964. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  80965. TEST_SUCCESS);
  80966. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  80967. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  80968. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  80969. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, big), TEST_SUCCESS);
  80970. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  80971. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  80972. wolfSSL_free(ssl_c);
  80973. wolfSSL_free(ssl_s);
  80974. wolfSSL_CTX_free(ctx_c);
  80975. wolfSSL_CTX_free(ctx_s);
  80976. return EXPECT_RESULT();
  80977. }
  80978. #endif /* WOLFSSL_TICKET_NONCE_MALLOC */
  80979. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_TLS12) && \
  80980. !defined(WOLFSSL_TICKET_DECRYPT_NO_CREATE) && \
  80981. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  80982. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_RSA) && \
  80983. defined(HAVE_ECC) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  80984. static int test_ticket_ret_create(void)
  80985. {
  80986. EXPECT_DECLS;
  80987. WOLFSSL_CTX *ctx_c = NULL;
  80988. WOLFSSL_CTX *ctx_s = NULL;
  80989. WOLFSSL *ssl_c = NULL;
  80990. WOLFSSL *ssl_s = NULL;
  80991. byte ticket[SESSION_TICKET_LEN];
  80992. struct test_memio_ctx test_ctx;
  80993. WOLFSSL_SESSION *sess = NULL;
  80994. word16 ticketLen = 0;
  80995. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80996. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80997. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  80998. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  80999. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  81000. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx_c), WOLFSSL_SUCCESS);
  81001. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81002. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81003. ExpectIntLE(sess->ticketLen, SESSION_TICKET_LEN);
  81004. if (sess != NULL) {
  81005. ticketLen = sess->ticketLen;
  81006. XMEMCPY(ticket, sess->ticket, sess->ticketLen);
  81007. }
  81008. wolfSSL_free(ssl_c);
  81009. ssl_c = NULL;
  81010. wolfSSL_free(ssl_s);
  81011. ssl_s = NULL;
  81012. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  81013. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  81014. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  81015. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  81016. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  81017. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  81018. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  81019. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81020. ExpectIntLE(ssl_c->session->ticketLen, SESSION_TICKET_LEN);
  81021. ExpectIntEQ(ssl_c->session->ticketLen, ticketLen);
  81022. ExpectTrue(XMEMCMP(ssl_c->session->ticket, ticket, ticketLen) != 0);
  81023. wolfSSL_SESSION_free(sess);
  81024. wolfSSL_free(ssl_c);
  81025. wolfSSL_free(ssl_s);
  81026. wolfSSL_CTX_free(ctx_c);
  81027. wolfSSL_CTX_free(ctx_s);
  81028. return EXPECT_RESULT();
  81029. }
  81030. #else
  81031. static int test_ticket_ret_create(void)
  81032. {
  81033. return TEST_SKIPPED;
  81034. }
  81035. #endif
  81036. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
  81037. defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  81038. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81039. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81040. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81041. static void test_ticket_and_psk_mixing_on_result(WOLFSSL* ssl)
  81042. {
  81043. int ret;
  81044. WOLFSSL_SESSION* session = NULL;
  81045. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81046. if (!wolfSSL_is_server(ssl)) {
  81047. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81048. AssertNotNull(session);
  81049. }
  81050. do {
  81051. ret = wolfSSL_shutdown(ssl);
  81052. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81053. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81054. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81055. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81056. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81057. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81058. #endif
  81059. if (!wolfSSL_is_server(ssl)) {
  81060. /* client */
  81061. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81062. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81063. wolfSSL_set_session(ssl, session);
  81064. wolfSSL_SESSION_free(session);
  81065. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81066. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81067. }
  81068. else {
  81069. /* server */
  81070. /* Different ciphersuite so that the ticket will be invalidated based on
  81071. * the ciphersuite */
  81072. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"),
  81073. WOLFSSL_SUCCESS);
  81074. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  81075. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81076. }
  81077. }
  81078. static void test_ticket_and_psk_mixing_ssl_ready(WOLFSSL* ssl)
  81079. {
  81080. AssertIntEQ(wolfSSL_UseSessionTicket(ssl), WOLFSSL_SUCCESS);
  81081. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81082. WOLFSSL_SUCCESS);
  81083. }
  81084. static int test_ticket_and_psk_mixing(void)
  81085. {
  81086. EXPECT_DECLS;
  81087. /* Test mixing tickets and regular PSK */
  81088. callback_functions client_cbs, server_cbs;
  81089. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81090. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81091. client_cbs.method = wolfTLSv1_3_client_method;
  81092. server_cbs.method = wolfTLSv1_3_server_method;
  81093. client_cbs.ssl_ready = test_ticket_and_psk_mixing_ssl_ready;
  81094. client_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81095. server_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81096. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81097. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81098. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81099. return EXPECT_RESULT();
  81100. }
  81101. #else
  81102. static int test_ticket_and_psk_mixing(void)
  81103. {
  81104. return TEST_SKIPPED;
  81105. }
  81106. #endif
  81107. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && defined(HAVE_SESSION_TICKET) \
  81108. && defined(OPENSSL_EXTRA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  81109. defined(HAVE_AESGCM) && !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81110. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81111. static int test_prioritize_psk_cb_called = FALSE;
  81112. static unsigned int test_prioritize_psk_cb(WOLFSSL* ssl,
  81113. const char* identity, unsigned char* key, unsigned int key_max_len,
  81114. const char** ciphersuite)
  81115. {
  81116. test_prioritize_psk_cb_called = TRUE;
  81117. return my_psk_server_tls13_cb(ssl, identity, key, key_max_len, ciphersuite);
  81118. }
  81119. static void test_prioritize_psk_on_result(WOLFSSL* ssl)
  81120. {
  81121. int ret;
  81122. WOLFSSL_SESSION* session = NULL;
  81123. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81124. if (!wolfSSL_is_server(ssl)) {
  81125. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81126. AssertNotNull(session);
  81127. }
  81128. do {
  81129. ret = wolfSSL_shutdown(ssl);
  81130. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81131. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81132. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81133. /* Previous connection was made with TLS13-AES128-GCM-SHA256. Order is
  81134. * important. */
  81135. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81136. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81137. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81138. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81139. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81140. #endif
  81141. if (!wolfSSL_is_server(ssl)) {
  81142. /* client */
  81143. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81144. wolfSSL_set_session(ssl, session);
  81145. wolfSSL_SESSION_free(session);
  81146. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81147. }
  81148. else {
  81149. /* server */
  81150. wolfSSL_set_psk_server_tls13_callback(ssl, test_prioritize_psk_cb);
  81151. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81152. #ifdef WOLFSSL_PRIORITIZE_PSK
  81153. /* The ticket should be first tried with all ciphersuites and chosen */
  81154. AssertFalse(test_prioritize_psk_cb_called);
  81155. #else
  81156. /* Ciphersuites should be tried with each PSK. This triggers the PSK
  81157. * callback that sets this var. */
  81158. AssertTrue(test_prioritize_psk_cb_called);
  81159. #endif
  81160. }
  81161. }
  81162. static void test_prioritize_psk_ssl_ready(WOLFSSL* ssl)
  81163. {
  81164. if (!wolfSSL_is_server(ssl))
  81165. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81166. WOLFSSL_SUCCESS);
  81167. else
  81168. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81169. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81170. }
  81171. static int test_prioritize_psk(void)
  81172. {
  81173. EXPECT_DECLS;
  81174. /* We always send the ticket first. With WOLFSSL_PRIORITIZE_PSK the order
  81175. * of the PSK's will be followed instead of the ciphersuite. */
  81176. callback_functions client_cbs, server_cbs;
  81177. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81178. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81179. client_cbs.method = wolfTLSv1_3_client_method;
  81180. server_cbs.method = wolfTLSv1_3_server_method;
  81181. client_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81182. server_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81183. client_cbs.on_result = test_prioritize_psk_on_result;
  81184. server_cbs.on_result = test_prioritize_psk_on_result;
  81185. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81186. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81187. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81188. return EXPECT_RESULT();
  81189. }
  81190. #else
  81191. static int test_prioritize_psk(void)
  81192. {
  81193. return TEST_SKIPPED;
  81194. }
  81195. #endif
  81196. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  81197. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81198. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81199. !defined(WOLFSSL_NO_TLS12)
  81200. static int test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server(WOLFSSL_CTX* ctx)
  81201. {
  81202. EXPECT_DECLS;
  81203. ExpectTrue(SSL_CTX_set_cipher_list(ctx, "DEFAULT"));
  81204. /* Set TLS 1.3 specific suite */
  81205. ExpectTrue(SSL_CTX_set_ciphersuites(ctx, "TLS13-AES128-GCM-SHA256"));
  81206. return EXPECT_RESULT();
  81207. }
  81208. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81209. {
  81210. EXPECT_DECLS;
  81211. /* Test using SSL_CTX_set_cipher_list and SSL_CTX_set_ciphersuites and then
  81212. * do a 1.2 connection. */
  81213. test_ssl_cbf client_cbs, server_cbs;
  81214. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81215. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81216. client_cbs.method = wolfTLSv1_2_client_method;
  81217. server_cbs.method = wolfTLS_server_method; /* Allow downgrade */
  81218. server_cbs.ctx_ready = test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server;
  81219. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81220. &server_cbs, NULL), TEST_SUCCESS);
  81221. return EXPECT_RESULT();
  81222. }
  81223. #else
  81224. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81225. {
  81226. return TEST_SKIPPED;
  81227. }
  81228. #endif
  81229. #if defined(HAVE_CRL) && defined(WOLFSSL_CHECK_ALERT_ON_ERR) && \
  81230. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  81231. static int test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready(WOLFSSL_CTX* ctx)
  81232. {
  81233. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  81234. return TEST_SUCCESS;
  81235. }
  81236. static int test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup(WOLFSSL* ssl)
  81237. {
  81238. EXPECT_DECLS;
  81239. WOLFSSL_ALERT_HISTORY h;
  81240. ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  81241. ExpectIntEQ(h.last_rx.level, alert_fatal);
  81242. ExpectIntEQ(h.last_rx.code, certificate_revoked);
  81243. return EXPECT_RESULT();
  81244. }
  81245. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81246. {
  81247. EXPECT_DECLS;
  81248. test_ssl_cbf client_cbs, server_cbs;
  81249. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81250. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81251. server_cbs.certPemFile = "./certs/server-revoked-cert.pem";
  81252. server_cbs.keyPemFile = "./certs/server-revoked-key.pem";
  81253. client_cbs.crlPemFile = "./certs/crl/crl.revoked";
  81254. client_cbs.ctx_ready = test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready;
  81255. server_cbs.on_cleanup = test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup;
  81256. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81257. &server_cbs, NULL), TEST_FAIL);
  81258. return EXPECT_RESULT();
  81259. }
  81260. #else
  81261. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81262. {
  81263. return TEST_SKIPPED;
  81264. }
  81265. #endif
  81266. #if defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET) \
  81267. && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81268. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81269. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  81270. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  81271. static WOLFSSL_CTX* test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81272. static WOLFSSL_SESSION* test_TLS_13_ticket_different_ciphers_session = NULL;
  81273. static int test_TLS_13_ticket_different_ciphers_run = 0;
  81274. static int test_TLS_13_ticket_different_ciphers_ssl_ready(WOLFSSL* ssl)
  81275. {
  81276. EXPECT_DECLS;
  81277. switch (test_TLS_13_ticket_different_ciphers_run) {
  81278. case 0:
  81279. /* First run */
  81280. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81281. WOLFSSL_SUCCESS);
  81282. if (wolfSSL_is_server(ssl)) {
  81283. ExpectNotNull(test_TLS_13_ticket_different_ciphers_ctx =
  81284. wolfSSL_get_SSL_CTX(ssl));
  81285. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_up_ref(
  81286. test_TLS_13_ticket_different_ciphers_ctx));
  81287. }
  81288. break;
  81289. case 1:
  81290. /* Second run */
  81291. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81292. "TLS13-AES128-GCM-SHA256"),
  81293. WOLFSSL_SUCCESS);
  81294. if (!wolfSSL_is_server(ssl)) {
  81295. ExpectIntEQ(wolfSSL_set_session(ssl,
  81296. test_TLS_13_ticket_different_ciphers_session),
  81297. WOLFSSL_SUCCESS);
  81298. }
  81299. break;
  81300. default:
  81301. /* Bad state? */
  81302. Fail(("Should not enter here"), ("Should not enter here"));
  81303. }
  81304. return EXPECT_RESULT();
  81305. }
  81306. static int test_TLS_13_ticket_different_ciphers_on_result(WOLFSSL* ssl)
  81307. {
  81308. EXPECT_DECLS;
  81309. switch (test_TLS_13_ticket_different_ciphers_run) {
  81310. case 0:
  81311. /* First run */
  81312. ExpectNotNull(test_TLS_13_ticket_different_ciphers_session =
  81313. wolfSSL_get1_session(ssl));
  81314. break;
  81315. case 1:
  81316. /* Second run */
  81317. ExpectTrue(wolfSSL_session_reused(ssl));
  81318. break;
  81319. default:
  81320. /* Bad state? */
  81321. Fail(("Should not enter here"), ("Should not enter here"));
  81322. }
  81323. return EXPECT_RESULT();
  81324. }
  81325. static int test_TLS_13_ticket_different_ciphers(void)
  81326. {
  81327. EXPECT_DECLS;
  81328. /* Check that we handle the connection when the ticket doesn't match
  81329. * the first ciphersuite. */
  81330. test_ssl_cbf client_cbs, server_cbs;
  81331. struct test_params {
  81332. method_provider client_meth;
  81333. method_provider server_meth;
  81334. int doUdp;
  81335. } params[] = {
  81336. #ifdef WOLFSSL_DTLS13
  81337. /* Test that the stateless code handles sessions correctly */
  81338. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, 1},
  81339. #endif
  81340. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, 0},
  81341. };
  81342. size_t i;
  81343. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  81344. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81345. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81346. test_TLS_13_ticket_different_ciphers_run = 0;
  81347. client_cbs.doUdp = server_cbs.doUdp = params[i].doUdp;
  81348. client_cbs.method = params[i].client_meth;
  81349. server_cbs.method = params[i].server_meth;
  81350. client_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81351. server_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81352. client_cbs.on_result = test_TLS_13_ticket_different_ciphers_on_result;
  81353. server_cbs.ticNoInit = 1;
  81354. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81355. &server_cbs, NULL), TEST_SUCCESS);
  81356. test_TLS_13_ticket_different_ciphers_run++;
  81357. server_cbs.ctx = test_TLS_13_ticket_different_ciphers_ctx;
  81358. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81359. &server_cbs, NULL), TEST_SUCCESS);
  81360. wolfSSL_SESSION_free(test_TLS_13_ticket_different_ciphers_session);
  81361. test_TLS_13_ticket_different_ciphers_session = NULL;
  81362. wolfSSL_CTX_free(test_TLS_13_ticket_different_ciphers_ctx);
  81363. test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81364. }
  81365. return EXPECT_RESULT();
  81366. }
  81367. #else
  81368. static int test_TLS_13_ticket_different_ciphers(void)
  81369. {
  81370. return TEST_SKIPPED;
  81371. }
  81372. #endif
  81373. #if defined(WOLFSSL_EXTRA_ALERTS) && !defined(WOLFSSL_NO_TLS12) && \
  81374. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81375. #define TEST_WRONG_CS_CLIENT "DHE-RSA-AES128-SHA"
  81376. /* AKA TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
  81377. byte test_extra_alerts_wrong_cs_sh[] = {
  81378. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0xef,
  81379. 0x0c, 0x30, 0x98, 0xa2, 0xac, 0xfa, 0x68, 0xe9, 0x3e, 0xaa, 0x5c, 0xcf,
  81380. 0xa7, 0x42, 0x72, 0xaf, 0xa0, 0xe8, 0x39, 0x2b, 0x3e, 0x81, 0xa7, 0x7a,
  81381. 0xa5, 0x62, 0x8a, 0x0e, 0x41, 0xba, 0xda, 0x20, 0x18, 0x9f, 0xe1, 0x8c,
  81382. 0x1d, 0xc0, 0x37, 0x9c, 0xf4, 0x90, 0x5d, 0x8d, 0xa0, 0x79, 0xa7, 0x4b,
  81383. 0xa8, 0x79, 0xdf, 0xcd, 0x8d, 0xf5, 0xb5, 0x50, 0x5f, 0xf1, 0xdb, 0x4d,
  81384. 0xbb, 0x07, 0x54, 0x1c,
  81385. 0x00, 0x02, /* TLS_RSA_WITH_NULL_SHA */
  81386. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81387. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81388. };
  81389. static int test_extra_alerts_wrong_cs(void)
  81390. {
  81391. EXPECT_DECLS;
  81392. #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  81393. struct test_memio_ctx test_ctx;
  81394. WOLFSSL_CTX *ctx_c = NULL;
  81395. WOLFSSL_ALERT_HISTORY h;
  81396. WOLFSSL *ssl_c = NULL;
  81397. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81398. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81399. wolfTLSv1_2_client_method, NULL), 0);
  81400. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_WRONG_CS_CLIENT),
  81401. WOLFSSL_SUCCESS);
  81402. /* CH */
  81403. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81404. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81405. WOLFSSL_ERROR_WANT_READ);
  81406. /* consume CH */
  81407. test_ctx.s_len = 0;
  81408. /* inject SH */
  81409. XMEMCPY(test_ctx.c_buff, test_extra_alerts_wrong_cs_sh,
  81410. sizeof(test_extra_alerts_wrong_cs_sh));
  81411. test_ctx.c_len = sizeof(test_extra_alerts_wrong_cs_sh);
  81412. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81413. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81414. WOLFSSL_ERROR_WANT_READ);
  81415. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81416. ExpectIntEQ(h.last_tx.code, handshake_failure);
  81417. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81418. wolfSSL_free(ssl_c);
  81419. wolfSSL_CTX_free(ctx_c);
  81420. #endif
  81421. return EXPECT_RESULT();
  81422. }
  81423. #else
  81424. static int test_extra_alerts_wrong_cs(void)
  81425. {
  81426. return TEST_SKIPPED;
  81427. }
  81428. #endif
  81429. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  81430. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81431. #define TEST_CS_DOWNGRADE_CLIENT "ECDHE-RSA-AES256-GCM-SHA384"
  81432. byte test_wrong_cs_downgrade_sh[] = {
  81433. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0x10,
  81434. 0x2c, 0x88, 0xd9, 0x7a, 0x23, 0xc9, 0xbd, 0x11, 0x3b, 0x64, 0x24, 0xab,
  81435. 0x5b, 0x45, 0x33, 0xf6, 0x2c, 0x34, 0xe4, 0xcf, 0xf4, 0x78, 0xc8, 0x62,
  81436. 0x06, 0xc7, 0xe5, 0x30, 0x39, 0xbf, 0xa1, 0x20, 0xa3, 0x06, 0x74, 0xc3,
  81437. 0xa9, 0x74, 0x52, 0x8a, 0xfb, 0xae, 0xf0, 0xd8, 0x6f, 0xb2, 0x9d, 0xfe,
  81438. 0x78, 0xf0, 0x3f, 0x51, 0x8f, 0x9c, 0xcf, 0xbe, 0x61, 0x43, 0x9d, 0xf8,
  81439. 0x85, 0xe5, 0x2f, 0x54,
  81440. 0xc0, 0x2f, /* ECDHE-RSA-AES128-GCM-SHA256 */
  81441. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81442. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81443. };
  81444. static int test_wrong_cs_downgrade(void)
  81445. {
  81446. EXPECT_DECLS;
  81447. #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  81448. struct test_memio_ctx test_ctx;
  81449. WOLFSSL_CTX *ctx_c = NULL;
  81450. WOLFSSL *ssl_c = NULL;
  81451. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81452. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81453. wolfSSLv23_client_method, NULL), 0);
  81454. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_CS_DOWNGRADE_CLIENT),
  81455. WOLFSSL_SUCCESS);
  81456. /* CH */
  81457. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81458. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81459. WOLFSSL_ERROR_WANT_READ);
  81460. /* consume CH */
  81461. test_ctx.s_len = 0;
  81462. /* inject SH */
  81463. XMEMCPY(test_ctx.c_buff, test_wrong_cs_downgrade_sh,
  81464. sizeof(test_wrong_cs_downgrade_sh));
  81465. test_ctx.c_len = sizeof(test_wrong_cs_downgrade_sh);
  81466. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81467. #ifdef OPENSSL_EXTRA
  81468. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81469. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL));
  81470. #else
  81471. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81472. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR));
  81473. #endif /* OPENSSL_EXTRA */
  81474. wolfSSL_free(ssl_c);
  81475. wolfSSL_CTX_free(ctx_c);
  81476. #endif
  81477. return EXPECT_RESULT();
  81478. }
  81479. #else
  81480. static int test_wrong_cs_downgrade(void)
  81481. {
  81482. return TEST_SKIPPED;
  81483. }
  81484. #endif
  81485. #if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_EXTRA_ALERTS) && \
  81486. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_SP_MATH)
  81487. static void test_remove_msg(byte *msg, int tail_len, int *len, int msg_length)
  81488. {
  81489. tail_len -= msg_length;
  81490. XMEMMOVE(msg, msg + msg_length, tail_len);
  81491. *len = *len - msg_length;
  81492. }
  81493. static int test_remove_hs_msg_from_buffer(byte *buf, int *len, byte type,
  81494. byte *found)
  81495. {
  81496. const unsigned int _HANDSHAKE_HEADER_SZ = 4;
  81497. const unsigned int _RECORD_HEADER_SZ = 5;
  81498. const int _change_cipher_hs = 55;
  81499. const int _change_cipher = 20;
  81500. const int _handshake = 22;
  81501. unsigned int tail_len;
  81502. byte *idx, *curr;
  81503. word8 currType;
  81504. word16 rLength;
  81505. word32 hLength;
  81506. idx = buf;
  81507. tail_len = (unsigned int)*len;
  81508. *found = 0;
  81509. while (tail_len > _RECORD_HEADER_SZ) {
  81510. curr = idx;
  81511. currType = *idx;
  81512. ato16(idx + 3, &rLength);
  81513. idx += _RECORD_HEADER_SZ;
  81514. tail_len -= _RECORD_HEADER_SZ;
  81515. if (tail_len < rLength)
  81516. return -1;
  81517. if (type == _change_cipher_hs && currType == _change_cipher) {
  81518. if (rLength != 1)
  81519. return -1;
  81520. /* match */
  81521. test_remove_msg(curr, *len - (int)(curr - buf),
  81522. len, _RECORD_HEADER_SZ + 1);
  81523. *found = 1;
  81524. return 0;
  81525. }
  81526. if (currType != _handshake) {
  81527. idx += rLength;
  81528. tail_len -= rLength;
  81529. continue;
  81530. }
  81531. if (rLength < _HANDSHAKE_HEADER_SZ)
  81532. return -1;
  81533. currType = *idx;
  81534. ato24(idx+1, &hLength);
  81535. hLength += _HANDSHAKE_HEADER_SZ;
  81536. if (tail_len < hLength)
  81537. return -1;
  81538. if (currType != type) {
  81539. idx += hLength;
  81540. tail_len -= hLength;
  81541. continue;
  81542. }
  81543. /* match */
  81544. test_remove_msg(curr, *len - (int)(curr - buf), len,
  81545. hLength + _RECORD_HEADER_SZ);
  81546. *found = 1;
  81547. return 0;
  81548. }
  81549. /* not found */
  81550. return 0;
  81551. }
  81552. static int test_remove_hs_message(byte hs_message_type,
  81553. int extra_round, byte alert_type)
  81554. {
  81555. EXPECT_DECLS;
  81556. WOLFSSL_CTX *ctx_c = NULL;
  81557. WOLFSSL_CTX *ctx_s = NULL;
  81558. WOLFSSL *ssl_c = NULL;
  81559. WOLFSSL *ssl_s = NULL;
  81560. struct test_memio_ctx test_ctx;
  81561. WOLFSSL_ALERT_HISTORY h;
  81562. byte found = 0;
  81563. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81564. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81565. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81566. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81567. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81568. WOLFSSL_ERROR_WANT_READ);
  81569. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  81570. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81571. WOLFSSL_ERROR_WANT_READ);
  81572. if (extra_round) {
  81573. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81574. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81575. WOLFSSL_ERROR_WANT_READ);
  81576. /* this will complete handshake from server side */
  81577. ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  81578. }
  81579. ExpectIntEQ(test_remove_hs_msg_from_buffer(test_ctx.c_buff,
  81580. &test_ctx.c_len, hs_message_type, &found), 0);
  81581. if (!found) {
  81582. wolfSSL_free(ssl_c);
  81583. wolfSSL_CTX_free(ctx_c);
  81584. wolfSSL_free(ssl_s);
  81585. wolfSSL_CTX_free(ctx_s);
  81586. return TEST_SKIPPED;
  81587. }
  81588. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81589. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81590. WOLFSSL_ERROR_WANT_READ);
  81591. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81592. ExpectTrue(alert_type == 0xff || h.last_tx.code == alert_type);
  81593. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81594. wolfSSL_free(ssl_c);
  81595. wolfSSL_CTX_free(ctx_c);
  81596. wolfSSL_free(ssl_s);
  81597. wolfSSL_CTX_free(ctx_s);
  81598. return EXPECT_RESULT();
  81599. }
  81600. static int test_extra_alerts_skip_hs(void)
  81601. {
  81602. EXPECT_DECLS;
  81603. const byte _server_key_exchange = 12;
  81604. const byte _server_hello = 2;
  81605. const byte _certificate = 11;
  81606. /* server_hello */
  81607. ExpectIntNE(test_remove_hs_message(_server_hello, 0,
  81608. unexpected_message), TEST_FAIL);
  81609. ExpectIntNE(test_remove_hs_message(_certificate, 0,
  81610. 0xff), TEST_FAIL);
  81611. ExpectIntNE(test_remove_hs_message(_server_key_exchange, 0,
  81612. unexpected_message), TEST_FAIL);
  81613. return EXPECT_RESULT();
  81614. }
  81615. #else
  81616. static int test_extra_alerts_skip_hs(void)
  81617. {
  81618. return TEST_SKIPPED;
  81619. }
  81620. #endif
  81621. #if !defined(WOLFSSL_NO_TLS12) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  81622. && defined(WOLFSSL_EXTRA_ALERTS) && !defined(NO_PSK) && !defined(NO_DH)
  81623. static unsigned int test_server_psk_cb(WOLFSSL* ssl, const char* id,
  81624. unsigned char* key, unsigned int key_max_len)
  81625. {
  81626. (void)ssl;
  81627. (void)id;
  81628. (void)key_max_len;
  81629. /* zero means error */
  81630. key[0] = 0x10;
  81631. return 1;
  81632. }
  81633. static int test_extra_alerts_bad_psk(void)
  81634. {
  81635. EXPECT_DECLS;
  81636. WOLFSSL_CTX *ctx_c = NULL;
  81637. WOLFSSL_CTX *ctx_s = NULL;
  81638. WOLFSSL *ssl_c = NULL;
  81639. WOLFSSL *ssl_s = NULL;
  81640. struct test_memio_ctx test_ctx;
  81641. WOLFSSL_ALERT_HISTORY h;
  81642. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81643. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81644. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81645. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "DHE-PSK-AES128-GCM-SHA256"),
  81646. WOLFSSL_SUCCESS);
  81647. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "DHE-PSK-AES128-GCM-SHA256"),
  81648. WOLFSSL_SUCCESS);
  81649. wolfSSL_set_psk_server_callback(ssl_s, test_server_psk_cb);
  81650. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81651. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81652. WOLFSSL_ERROR_WANT_READ);
  81653. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  81654. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81655. WOLFSSL_ERROR_WANT_READ);
  81656. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81657. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81658. WOLFSSL_ERROR_WANT_READ);
  81659. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81660. ExpectIntEQ(h.last_tx.code, handshake_failure);
  81661. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81662. wolfSSL_free(ssl_c);
  81663. wolfSSL_CTX_free(ctx_c);
  81664. wolfSSL_free(ssl_s);
  81665. wolfSSL_CTX_free(ctx_s);
  81666. return EXPECT_RESULT();
  81667. }
  81668. #else
  81669. static int test_extra_alerts_bad_psk(void)
  81670. {
  81671. return TEST_SKIPPED;
  81672. }
  81673. #endif
  81674. #if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  81675. /*
  81676. * Emulates wolfSSL_shutdown that goes on EAGAIN,
  81677. * by returning on output WOLFSSL_ERROR_WANT_WRITE.*/
  81678. static int custom_wolfSSL_shutdown(WOLFSSL *ssl, char *buf,
  81679. int sz, void *ctx)
  81680. {
  81681. (void)ssl;
  81682. (void)buf;
  81683. (void)ctx;
  81684. (void)sz;
  81685. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  81686. }
  81687. static int test_multiple_alerts_EAGAIN(void)
  81688. {
  81689. EXPECT_DECLS;
  81690. size_t size_of_last_packet = 0;
  81691. /* declare wolfSSL objects */
  81692. struct test_memio_ctx test_ctx;
  81693. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  81694. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  81695. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81696. /* Create and initialize WOLFSSL_CTX and WOLFSSL objects */
  81697. #ifdef USE_TLSV13
  81698. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81699. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  81700. #else
  81701. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81702. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81703. #endif
  81704. ExpectNotNull(ctx_c);
  81705. ExpectNotNull(ssl_c);
  81706. ExpectNotNull(ctx_s);
  81707. ExpectNotNull(ssl_s);
  81708. /* Load client certificates into WOLFSSL_CTX */
  81709. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c, "./certs/ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  81710. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81711. /*
  81712. * We set the custom callback for the IO to emulate multiple EAGAINs
  81713. * on shutdown, so we can check that we don't send multiple packets.
  81714. * */
  81715. wolfSSL_SSLSetIOSend(ssl_c, custom_wolfSSL_shutdown);
  81716. /*
  81717. * We call wolfSSL_shutdown multiple times to reproduce the behaviour,
  81718. * to check that it doesn't add the CLOSE_NOTIFY packet multiple times
  81719. * on the output buffer.
  81720. * */
  81721. wolfSSL_shutdown(ssl_c);
  81722. wolfSSL_shutdown(ssl_c);
  81723. if (ssl_c != NULL) {
  81724. size_of_last_packet = ssl_c->buffers.outputBuffer.length;
  81725. }
  81726. wolfSSL_shutdown(ssl_c);
  81727. /*
  81728. * Finally we check the length of the output buffer.
  81729. * */
  81730. ExpectIntEQ((ssl_c->buffers.outputBuffer.length - size_of_last_packet), 0);
  81731. /* Cleanup and return */
  81732. wolfSSL_CTX_free(ctx_c);
  81733. wolfSSL_free(ssl_c);
  81734. wolfSSL_CTX_free(ctx_s);
  81735. wolfSSL_free(ssl_s);
  81736. return EXPECT_RESULT();
  81737. }
  81738. #else
  81739. static int test_multiple_alerts_EAGAIN(void)
  81740. {
  81741. return TEST_SKIPPED;
  81742. }
  81743. #endif
  81744. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  81745. && !defined(NO_PSK)
  81746. static unsigned int test_tls13_bad_psk_binder_client_cb(WOLFSSL* ssl,
  81747. const char* hint, char* identity, unsigned int id_max_len,
  81748. unsigned char* key, unsigned int key_max_len)
  81749. {
  81750. (void)ssl;
  81751. (void)hint;
  81752. (void)key_max_len;
  81753. /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
  81754. XSTRNCPY(identity, "Client_identity", id_max_len);
  81755. key[0] = 0x20;
  81756. return 1;
  81757. }
  81758. static unsigned int test_tls13_bad_psk_binder_server_cb(WOLFSSL* ssl,
  81759. const char* id, unsigned char* key, unsigned int key_max_len)
  81760. {
  81761. (void)ssl;
  81762. (void)id;
  81763. (void)key_max_len;
  81764. /* zero means error */
  81765. key[0] = 0x10;
  81766. return 1;
  81767. }
  81768. #endif
  81769. static int test_tls13_bad_psk_binder(void)
  81770. {
  81771. EXPECT_DECLS;
  81772. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  81773. && !defined(NO_PSK)
  81774. WOLFSSL_CTX *ctx_c = NULL;
  81775. WOLFSSL_CTX *ctx_s = NULL;
  81776. WOLFSSL *ssl_c = NULL;
  81777. WOLFSSL *ssl_s = NULL;
  81778. struct test_memio_ctx test_ctx;
  81779. WOLFSSL_ALERT_HISTORY h;
  81780. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81781. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81782. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  81783. wolfSSL_set_psk_client_callback(ssl_c, test_tls13_bad_psk_binder_client_cb);
  81784. wolfSSL_set_psk_server_callback(ssl_s, test_tls13_bad_psk_binder_server_cb);
  81785. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81786. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81787. WOLFSSL_ERROR_WANT_READ);
  81788. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  81789. ExpectIntEQ( wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81790. WC_NO_ERR_TRACE(BAD_BINDER));
  81791. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81792. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81793. WC_NO_ERR_TRACE(FATAL_ERROR));
  81794. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81795. ExpectIntEQ(h.last_rx.code, illegal_parameter);
  81796. ExpectIntEQ(h.last_rx.level, alert_fatal);
  81797. wolfSSL_free(ssl_c);
  81798. wolfSSL_CTX_free(ctx_c);
  81799. wolfSSL_free(ssl_s);
  81800. wolfSSL_CTX_free(ctx_s);
  81801. #endif
  81802. return EXPECT_RESULT();
  81803. }
  81804. #if defined(WOLFSSL_HARDEN_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  81805. defined(HAVE_IO_TESTS_DEPENDENCIES)
  81806. static int test_harden_no_secure_renegotiation_io_cb(WOLFSSL *ssl, char *buf,
  81807. int sz, void *ctx)
  81808. {
  81809. static int sentServerHello = FALSE;
  81810. if (!sentServerHello) {
  81811. byte renegExt[] = { 0xFF, 0x01, 0x00, 0x01, 0x00 };
  81812. size_t i;
  81813. if (sz < (int)sizeof(renegExt))
  81814. return WOLFSSL_CBIO_ERR_GENERAL;
  81815. /* Remove SCR from ServerHello */
  81816. for (i = 0; i < sz - sizeof(renegExt); i++) {
  81817. if (XMEMCMP(buf + i, renegExt, sizeof(renegExt)) == 0) {
  81818. /* Found the extension. Change it to something unrecognized. */
  81819. buf[i+1] = 0x11;
  81820. break;
  81821. }
  81822. }
  81823. sentServerHello = TRUE;
  81824. }
  81825. return EmbedSend(ssl, buf, sz, ctx);
  81826. }
  81827. static void test_harden_no_secure_renegotiation_ssl_ready(WOLFSSL* ssl)
  81828. {
  81829. wolfSSL_SSLSetIOSend(ssl, test_harden_no_secure_renegotiation_io_cb);
  81830. }
  81831. static void test_harden_no_secure_renegotiation_on_cleanup(WOLFSSL* ssl)
  81832. {
  81833. WOLFSSL_ALERT_HISTORY h;
  81834. AssertIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  81835. AssertIntEQ(h.last_rx.code, handshake_failure);
  81836. AssertIntEQ(h.last_rx.level, alert_fatal);
  81837. }
  81838. static int test_harden_no_secure_renegotiation(void)
  81839. {
  81840. EXPECT_DECLS;
  81841. callback_functions client_cbs, server_cbs;
  81842. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81843. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81844. client_cbs.method = wolfTLSv1_2_client_method;
  81845. server_cbs.method = wolfTLSv1_2_server_method;
  81846. server_cbs.ssl_ready = test_harden_no_secure_renegotiation_ssl_ready;
  81847. server_cbs.on_cleanup = test_harden_no_secure_renegotiation_on_cleanup;
  81848. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81849. ExpectIntEQ(client_cbs.return_code, TEST_FAIL);
  81850. ExpectIntEQ(client_cbs.last_err, WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E));
  81851. ExpectIntEQ(server_cbs.return_code, TEST_FAIL);
  81852. ExpectTrue(server_cbs.last_err == WC_NO_ERR_TRACE(SOCKET_ERROR_E) ||
  81853. server_cbs.last_err == WC_NO_ERR_TRACE(FATAL_ERROR));
  81854. return EXPECT_RESULT();
  81855. }
  81856. #else
  81857. static int test_harden_no_secure_renegotiation(void)
  81858. {
  81859. return TEST_SKIPPED;
  81860. }
  81861. #endif
  81862. #if defined(HAVE_OCSP) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  81863. static int test_override_alt_cert_chain_cert_cb(int preverify,
  81864. WOLFSSL_X509_STORE_CTX* store)
  81865. {
  81866. fprintf(stderr, "preverify: %d\n", preverify);
  81867. fprintf(stderr, "store->error: %d\n", store->error);
  81868. fprintf(stderr, "error reason: %s\n", wolfSSL_ERR_reason_error_string(store->error));
  81869. if (store->error == WC_NO_ERR_TRACE(OCSP_INVALID_STATUS)) {
  81870. fprintf(stderr, "Overriding OCSP error\n");
  81871. return 1;
  81872. }
  81873. #ifndef WOLFSSL_ALT_CERT_CHAINS
  81874. else if ((store->error == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E) ||
  81875. store->error == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)
  81876. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  81877. defined(HAVE_WEBSERVER)
  81878. || store->error == WOLFSSL_X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
  81879. #endif
  81880. ) && store->error_depth == store->totalCerts - 1) {
  81881. fprintf(stderr, "Overriding no signer error only for root cert\n");
  81882. return 1;
  81883. }
  81884. #endif
  81885. else
  81886. return preverify;
  81887. }
  81888. static int test_override_alt_cert_chain_ocsp_cb(void* ioCtx, const char* url,
  81889. int urlSz, unsigned char* request, int requestSz,
  81890. unsigned char** response)
  81891. {
  81892. (void)ioCtx;
  81893. (void)url;
  81894. (void)urlSz;
  81895. (void)request;
  81896. (void)requestSz;
  81897. (void)response;
  81898. return -1;
  81899. }
  81900. static int test_override_alt_cert_chain_client_ctx_ready(WOLFSSL_CTX* ctx)
  81901. {
  81902. EXPECT_DECLS;
  81903. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER,
  81904. test_override_alt_cert_chain_cert_cb);
  81905. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  81906. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  81907. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  81908. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  81909. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  81910. WOLFSSL_SUCCESS);
  81911. return EXPECT_RESULT();
  81912. }
  81913. static int test_override_alt_cert_chain_client_ctx_ready2(WOLFSSL_CTX* ctx)
  81914. {
  81915. EXPECT_DECLS;
  81916. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  81917. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  81918. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  81919. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  81920. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  81921. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  81922. WOLFSSL_SUCCESS);
  81923. return EXPECT_RESULT();
  81924. }
  81925. static int test_override_alt_cert_chain_server_ctx_ready(WOLFSSL_CTX* ctx)
  81926. {
  81927. EXPECT_DECLS;
  81928. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  81929. "./certs/intermediate/server-chain-alt.pem"), WOLFSSL_SUCCESS);
  81930. return EXPECT_RESULT();
  81931. }
  81932. static int test_override_alt_cert_chain(void)
  81933. {
  81934. EXPECT_DECLS;
  81935. size_t i;
  81936. struct test_params {
  81937. ctx_cb client_ctx_cb;
  81938. ctx_cb server_ctx_cb;
  81939. int result;
  81940. } params[] = {
  81941. {test_override_alt_cert_chain_client_ctx_ready,
  81942. test_override_alt_cert_chain_server_ctx_ready, TEST_SUCCESS},
  81943. {test_override_alt_cert_chain_client_ctx_ready2,
  81944. test_override_alt_cert_chain_server_ctx_ready, TEST_FAIL},
  81945. };
  81946. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  81947. test_ssl_cbf client_cbs, server_cbs;
  81948. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81949. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81950. fprintf(stderr, "test config: %d\n", (int)i);
  81951. client_cbs.ctx_ready = params[i].client_ctx_cb;
  81952. server_cbs.ctx_ready = params[i].server_ctx_cb;
  81953. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81954. &server_cbs, NULL), params[i].result);
  81955. ExpectIntEQ(client_cbs.return_code, params[i].result);
  81956. ExpectIntEQ(server_cbs.return_code, params[i].result);
  81957. }
  81958. return EXPECT_RESULT();
  81959. }
  81960. #else
  81961. static int test_override_alt_cert_chain(void)
  81962. {
  81963. return TEST_SKIPPED;
  81964. }
  81965. #endif
  81966. #if defined(HAVE_RPK)
  81967. #define svrRpkCertFile "./certs/rpk/server-cert-rpk.der"
  81968. #define clntRpkCertFile "./certs/rpk/client-cert-rpk.der"
  81969. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  81970. static int MyRpkVerifyCb(int mode, WOLFSSL_X509_STORE_CTX* strctx)
  81971. {
  81972. int ret = WOLFSSL_SUCCESS;
  81973. (void)mode;
  81974. (void)strctx;
  81975. WOLFSSL_ENTER("MyRpkVerifyCb");
  81976. return ret;
  81977. }
  81978. #endif /* WOLFSSL_ALWAYS_VERIFY_CB && WOLFSSL_TLS13 */
  81979. static WC_INLINE int test_rpk_memio_setup(
  81980. struct test_memio_ctx *ctx,
  81981. WOLFSSL_CTX **ctx_c,
  81982. WOLFSSL_CTX **ctx_s,
  81983. WOLFSSL **ssl_c,
  81984. WOLFSSL **ssl_s,
  81985. method_provider method_c,
  81986. method_provider method_s,
  81987. const char* certfile_c, int fmt_cc, /* client cert file path and format */
  81988. const char* certfile_s, int fmt_cs, /* server cert file path and format */
  81989. const char* pkey_c, int fmt_kc, /* client private key and format */
  81990. const char* pkey_s, int fmt_ks /* server private key and format */
  81991. )
  81992. {
  81993. int ret;
  81994. if (ctx_c != NULL && *ctx_c == NULL) {
  81995. *ctx_c = wolfSSL_CTX_new(method_c());
  81996. if (*ctx_c == NULL) {
  81997. return -1;
  81998. }
  81999. wolfSSL_CTX_set_verify(*ctx_c, WOLFSSL_VERIFY_PEER, NULL);
  82000. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  82001. if (ret != WOLFSSL_SUCCESS) {
  82002. return -1;
  82003. }
  82004. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  82005. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  82006. ret = wolfSSL_CTX_use_certificate_file(*ctx_c, certfile_c, fmt_cc);
  82007. if (ret != WOLFSSL_SUCCESS) {
  82008. return -1;
  82009. }
  82010. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_c, pkey_c, fmt_kc);
  82011. if (ret != WOLFSSL_SUCCESS) {
  82012. return -1;
  82013. }
  82014. }
  82015. if (ctx_s != NULL && *ctx_s == NULL) {
  82016. *ctx_s = wolfSSL_CTX_new(method_s());
  82017. if (*ctx_s == NULL) {
  82018. return -1;
  82019. }
  82020. wolfSSL_CTX_set_verify(*ctx_s, WOLFSSL_VERIFY_PEER, NULL);
  82021. ret = wolfSSL_CTX_load_verify_locations(*ctx_s, cliCertFile, 0);
  82022. if (ret != WOLFSSL_SUCCESS) {
  82023. return -1;
  82024. }
  82025. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, pkey_s, fmt_ks);
  82026. if (ret != WOLFSSL_SUCCESS) {
  82027. return -1;
  82028. }
  82029. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, certfile_s, fmt_cs);
  82030. if (ret != WOLFSSL_SUCCESS) {
  82031. return -1;
  82032. }
  82033. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  82034. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  82035. if (ctx->s_ciphers != NULL) {
  82036. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  82037. if (ret != WOLFSSL_SUCCESS) {
  82038. return -1;
  82039. }
  82040. }
  82041. }
  82042. if (ctx_c != NULL && ssl_c != NULL) {
  82043. *ssl_c = wolfSSL_new(*ctx_c);
  82044. if (*ssl_c == NULL) {
  82045. return -1;
  82046. }
  82047. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  82048. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  82049. }
  82050. if (ctx_s != NULL && ssl_s != NULL) {
  82051. *ssl_s = wolfSSL_new(*ctx_s);
  82052. if (*ssl_s == NULL) {
  82053. return -1;
  82054. }
  82055. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  82056. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  82057. #if !defined(NO_DH)
  82058. SetDH(*ssl_s);
  82059. #endif
  82060. }
  82061. return 0;
  82062. }
  82063. #endif /* HAVE_RPK */
  82064. static int test_rpk_set_xxx_cert_type(void)
  82065. {
  82066. EXPECT_DECLS;
  82067. #if defined(HAVE_RPK)
  82068. char ctype[MAX_CLIENT_CERT_TYPE_CNT + 1]; /* prepare bigger buffer */
  82069. WOLFSSL_CTX* ctx = NULL;
  82070. WOLFSSL* ssl = NULL;
  82071. int tp;
  82072. ctx = wolfSSL_CTX_new(wolfTLS_client_method());
  82073. ExpectNotNull(ctx);
  82074. ssl = wolfSSL_new(ctx);
  82075. ExpectNotNull(ssl);
  82076. /*--------------------------------------------*/
  82077. /* tests for wolfSSL_CTX_set_client_cert_type */
  82078. /*--------------------------------------------*/
  82079. /* illegal parameter test caces */
  82080. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(NULL, ctype,
  82081. MAX_CLIENT_CERT_TYPE_CNT),
  82082. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82083. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82084. sizeof(ctype)),
  82085. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82086. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82087. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82088. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82089. MAX_CLIENT_CERT_TYPE_CNT),
  82090. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82091. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82092. ctype[1] = 10; /* set unknown cert type */
  82093. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82094. MAX_CLIENT_CERT_TYPE_CNT),
  82095. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82096. /* pass larger type count */
  82097. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82098. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82099. ctype[2] = 1; /* pass unacceptable type count */
  82100. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82101. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82102. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82103. /* should accept NULL for type buffer */
  82104. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, NULL,
  82105. MAX_CLIENT_CERT_TYPE_CNT),
  82106. WOLFSSL_SUCCESS);
  82107. /* should accept zero for type count */
  82108. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82109. 0),
  82110. WOLFSSL_SUCCESS);
  82111. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82112. MAX_CLIENT_CERT_TYPE_CNT),
  82113. WOLFSSL_SUCCESS);
  82114. /*--------------------------------------------*/
  82115. /* tests for wolfSSL_CTX_set_server_cert_type */
  82116. /*--------------------------------------------*/
  82117. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(NULL, ctype,
  82118. MAX_SERVER_CERT_TYPE_CNT),
  82119. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82120. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82121. sizeof(ctype)),
  82122. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82123. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82124. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82125. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82126. MAX_SERVER_CERT_TYPE_CNT),
  82127. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82128. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82129. ctype[1] = 10; /* set unknown cert type */
  82130. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82131. MAX_SERVER_CERT_TYPE_CNT),
  82132. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82133. /* pass larger type count */
  82134. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82135. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82136. ctype[2] = 1; /* pass unacceptable type count */
  82137. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82138. MAX_SERVER_CERT_TYPE_CNT + 1),
  82139. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82140. /* should accept NULL for type buffer */
  82141. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, NULL,
  82142. MAX_SERVER_CERT_TYPE_CNT),
  82143. WOLFSSL_SUCCESS);
  82144. /* should accept zero for type count */
  82145. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82146. 0),
  82147. WOLFSSL_SUCCESS);
  82148. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82149. MAX_CLIENT_CERT_TYPE_CNT),
  82150. WOLFSSL_SUCCESS);
  82151. /*--------------------------------------------*/
  82152. /* tests for wolfSSL_set_client_cert_type */
  82153. /*--------------------------------------------*/
  82154. ExpectIntEQ(wolfSSL_set_client_cert_type(NULL, ctype,
  82155. MAX_CLIENT_CERT_TYPE_CNT),
  82156. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82157. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82158. sizeof(ctype)),
  82159. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82160. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82161. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82162. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82163. MAX_CLIENT_CERT_TYPE_CNT),
  82164. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82165. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82166. ctype[1] = 10; /* set unknown cert type */
  82167. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82168. MAX_CLIENT_CERT_TYPE_CNT),
  82169. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82170. /* pass larger type count */
  82171. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82172. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82173. ctype[2] = 1; /* pass unacceptable type count */
  82174. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82175. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82176. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82177. /* should accept NULL for type buffer */
  82178. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, NULL,
  82179. MAX_CLIENT_CERT_TYPE_CNT),
  82180. WOLFSSL_SUCCESS);
  82181. /* should accept zero for type count */
  82182. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82183. 0),
  82184. WOLFSSL_SUCCESS);
  82185. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82186. MAX_CLIENT_CERT_TYPE_CNT),
  82187. WOLFSSL_SUCCESS);
  82188. /*--------------------------------------------*/
  82189. /* tests for wolfSSL_CTX_set_server_cert_type */
  82190. /*--------------------------------------------*/
  82191. ExpectIntEQ(wolfSSL_set_server_cert_type(NULL, ctype,
  82192. MAX_SERVER_CERT_TYPE_CNT),
  82193. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82194. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82195. sizeof(ctype)),
  82196. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82197. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82198. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82199. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82200. MAX_SERVER_CERT_TYPE_CNT),
  82201. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82202. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82203. ctype[1] = 10; /* set unknown cert type */
  82204. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82205. MAX_SERVER_CERT_TYPE_CNT),
  82206. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82207. /* pass larger type count */
  82208. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82209. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82210. ctype[2] = 1; /* pass unacceptable type count */
  82211. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82212. MAX_SERVER_CERT_TYPE_CNT + 1),
  82213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82214. /* should accept NULL for type buffer */
  82215. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, NULL,
  82216. MAX_SERVER_CERT_TYPE_CNT),
  82217. WOLFSSL_SUCCESS);
  82218. /* should accept zero for type count */
  82219. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82220. 0),
  82221. WOLFSSL_SUCCESS);
  82222. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82223. MAX_SERVER_CERT_TYPE_CNT),
  82224. WOLFSSL_SUCCESS);
  82225. /*------------------------------------------------*/
  82226. /* tests for wolfSSL_get_negotiated_xxx_cert_type */
  82227. /*------------------------------------------------*/
  82228. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(NULL, &tp),
  82229. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82230. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl, NULL),
  82231. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82232. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(NULL, &tp),
  82233. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82234. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl, NULL),
  82235. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82236. /* clean up */
  82237. wolfSSL_free(ssl);
  82238. wolfSSL_CTX_free(ctx);
  82239. #endif
  82240. return EXPECT_RESULT();
  82241. }
  82242. static int test_tls13_rpk_handshake(void)
  82243. {
  82244. EXPECT_DECLS;
  82245. #if defined(HAVE_RPK) && (!defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13))
  82246. #ifdef WOLFSSL_TLS13
  82247. int ret = 0;
  82248. #endif
  82249. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  82250. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  82251. struct test_memio_ctx test_ctx;
  82252. int err;
  82253. char certType_c[MAX_CLIENT_CERT_TYPE_CNT];
  82254. char certType_s[MAX_CLIENT_CERT_TYPE_CNT];
  82255. int typeCnt_c;
  82256. int typeCnt_s;
  82257. int tp = 0;
  82258. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  82259. int isServer;
  82260. #endif
  82261. (void)err;
  82262. (void)typeCnt_c;
  82263. (void)typeCnt_s;
  82264. (void)certType_c;
  82265. (void)certType_s;
  82266. #ifndef WOLFSSL_NO_TLS12
  82267. /* TLS1.2
  82268. * Both client and server load x509 cert and start handshaking.
  82269. * Check no negotiation occurred.
  82270. */
  82271. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82272. ExpectIntEQ(
  82273. test_rpk_memio_setup(
  82274. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82275. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82276. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82277. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82278. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82279. svrKeyFile, WOLFSSL_FILETYPE_PEM)
  82280. , 0);
  82281. /* set client certificate type in client end */
  82282. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82283. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82284. typeCnt_c = 2;
  82285. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82286. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82287. typeCnt_s = 2;
  82288. /* both client and server do not call client/server_cert_type APIs,
  82289. * expecting default settings works and no negotiation performed.
  82290. */
  82291. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82292. return TEST_FAIL;
  82293. /* confirm no negotiation occurred */
  82294. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82295. WOLFSSL_SUCCESS);
  82296. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82297. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82298. WOLFSSL_SUCCESS);
  82299. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82300. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82301. WOLFSSL_SUCCESS);
  82302. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82303. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82304. WOLFSSL_SUCCESS);
  82305. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82306. (void)typeCnt_c;
  82307. (void)typeCnt_s;
  82308. wolfSSL_free(ssl_c);
  82309. wolfSSL_CTX_free(ctx_c);
  82310. wolfSSL_free(ssl_s);
  82311. wolfSSL_CTX_free(ctx_s);
  82312. ssl_c = ssl_s = NULL;
  82313. ctx_c = ctx_s = NULL;
  82314. #endif
  82315. #ifdef WOLFSSL_TLS13
  82316. /* Both client and server load x509 cert and start handshaking.
  82317. * Check no negotiation occurred.
  82318. */
  82319. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82320. ExpectIntEQ(
  82321. test_rpk_memio_setup(
  82322. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82323. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82324. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82325. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82326. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82327. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82328. , 0);
  82329. /* set client certificate type in client end */
  82330. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82331. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82332. typeCnt_c = 2;
  82333. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82334. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82335. typeCnt_s = 2;
  82336. /* both client and server do not call client/server_cert_type APIs,
  82337. * expecting default settings works and no negotiation performed.
  82338. */
  82339. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82340. return TEST_FAIL;
  82341. /* confirm no negotiation occurred */
  82342. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82343. WOLFSSL_SUCCESS);
  82344. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82345. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82346. WOLFSSL_SUCCESS);
  82347. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82348. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82349. WOLFSSL_SUCCESS);
  82350. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82351. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82352. WOLFSSL_SUCCESS);
  82353. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82354. (void)typeCnt_c;
  82355. (void)typeCnt_s;
  82356. wolfSSL_free(ssl_c);
  82357. wolfSSL_CTX_free(ctx_c);
  82358. wolfSSL_free(ssl_s);
  82359. wolfSSL_CTX_free(ctx_s);
  82360. ssl_c = ssl_s = NULL;
  82361. ctx_c = ctx_s = NULL;
  82362. /* Both client and server load RPK cert and start handshaking.
  82363. * Confirm negotiated cert types match as expected.
  82364. */
  82365. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82366. ExpectIntEQ(
  82367. test_rpk_memio_setup(
  82368. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82369. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82370. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82371. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82372. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82373. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82374. , 0);
  82375. /* set client certificate type in client end */
  82376. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82377. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82378. typeCnt_c = 2;
  82379. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82380. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82381. typeCnt_s = 2;
  82382. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82383. WOLFSSL_SUCCESS);
  82384. /* set server certificate type in client end */
  82385. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82386. WOLFSSL_SUCCESS);
  82387. /* set client certificate type in server end */
  82388. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82389. WOLFSSL_SUCCESS);
  82390. /* set server certificate type in server end */
  82391. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82392. WOLFSSL_SUCCESS);
  82393. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82394. return TEST_FAIL;
  82395. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82396. WOLFSSL_SUCCESS);
  82397. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82398. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82399. WOLFSSL_SUCCESS);
  82400. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82401. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82402. WOLFSSL_SUCCESS);
  82403. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82404. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82405. WOLFSSL_SUCCESS);
  82406. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82407. wolfSSL_free(ssl_c);
  82408. wolfSSL_CTX_free(ctx_c);
  82409. wolfSSL_free(ssl_s);
  82410. wolfSSL_CTX_free(ctx_s);
  82411. ssl_c = ssl_s = NULL;
  82412. ctx_c = ctx_s = NULL;
  82413. #endif
  82414. #ifndef WOLFSSL_NO_TLS12
  82415. /* TLS1.2
  82416. * Both client and server load RPK cert and start handshaking.
  82417. * Confirm negotiated cert types match as expected.
  82418. */
  82419. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82420. ExpectIntEQ(
  82421. test_rpk_memio_setup(
  82422. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82423. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82424. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82425. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82426. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82427. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82428. , 0);
  82429. /* set client certificate type in client end */
  82430. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82431. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82432. typeCnt_c = 2;
  82433. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82434. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82435. typeCnt_s = 2;
  82436. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82437. WOLFSSL_SUCCESS);
  82438. /* set server certificate type in client end */
  82439. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82440. WOLFSSL_SUCCESS);
  82441. /* set client certificate type in server end */
  82442. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82443. WOLFSSL_SUCCESS);
  82444. /* set server certificate type in server end */
  82445. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82446. WOLFSSL_SUCCESS);
  82447. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82448. return TEST_FAIL;
  82449. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82450. WOLFSSL_SUCCESS);
  82451. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82452. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82453. WOLFSSL_SUCCESS);
  82454. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82455. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82456. WOLFSSL_SUCCESS);
  82457. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82458. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82459. WOLFSSL_SUCCESS);
  82460. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82461. wolfSSL_free(ssl_c);
  82462. wolfSSL_CTX_free(ctx_c);
  82463. wolfSSL_free(ssl_s);
  82464. wolfSSL_CTX_free(ctx_s);
  82465. ssl_c = ssl_s = NULL;
  82466. ctx_c = ctx_s = NULL;
  82467. #endif
  82468. #ifdef WOLFSSL_TLS13
  82469. /* Both client and server load x509 cert.
  82470. * Have client call set_client_cert_type with both RPK and x509.
  82471. * This doesn't makes client add client cert type extension to ClientHello,
  82472. * since it does not load RPK cert actually.
  82473. */
  82474. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82475. ExpectIntEQ(
  82476. test_rpk_memio_setup(
  82477. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82478. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82479. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82480. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82481. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82482. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82483. , 0);
  82484. /* set client certificate type in client end
  82485. *
  82486. * client indicates both RPK and x509 certs are available but loaded RPK
  82487. * cert only. It does not have client add client-cert-type extension in CH.
  82488. */
  82489. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82490. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82491. typeCnt_c = 2;
  82492. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82493. WOLFSSL_SUCCESS);
  82494. /* client indicates both RPK and x509 certs are acceptable */
  82495. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82496. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82497. typeCnt_s = 2;
  82498. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82499. WOLFSSL_SUCCESS);
  82500. /* server indicates both RPK and x509 certs are acceptable */
  82501. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82502. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82503. typeCnt_c = 2;
  82504. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82505. WOLFSSL_SUCCESS);
  82506. /* server should indicate only RPK cert is available */
  82507. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82508. certType_s[1] = -1;
  82509. typeCnt_s = 1;
  82510. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82511. WOLFSSL_SUCCESS);
  82512. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82513. return TEST_FAIL;
  82514. /* Negotiation for client-cert-type should NOT happen. Therefore -1 should
  82515. * be returned as cert type.
  82516. */
  82517. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82518. WOLFSSL_SUCCESS);
  82519. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82520. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82521. WOLFSSL_SUCCESS);
  82522. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82523. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82524. WOLFSSL_SUCCESS);
  82525. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82526. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82527. WOLFSSL_SUCCESS);
  82528. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82529. wolfSSL_free(ssl_c);
  82530. wolfSSL_CTX_free(ctx_c);
  82531. wolfSSL_free(ssl_s);
  82532. wolfSSL_CTX_free(ctx_s);
  82533. ssl_c = ssl_s = NULL;
  82534. ctx_c = ctx_s = NULL;
  82535. /* Have client load RPK cert and have server load x509 cert.
  82536. * Check the negotiation result from both ends.
  82537. */
  82538. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82539. ExpectIntEQ(
  82540. test_rpk_memio_setup(
  82541. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82542. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82543. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82544. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82545. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82546. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82547. , 0);
  82548. /* have client tell to use RPK cert */
  82549. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82550. certType_c[1] = -1;
  82551. typeCnt_c = 1;
  82552. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82553. WOLFSSL_SUCCESS);
  82554. /* have client tell to accept both RPK and x509 cert */
  82555. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82556. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  82557. typeCnt_s = 2;
  82558. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82559. WOLFSSL_SUCCESS);
  82560. /* have server accept to both RPK and x509 cert */
  82561. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  82562. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  82563. typeCnt_c = 2;
  82564. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82565. WOLFSSL_SUCCESS);
  82566. /* does not call wolfSSL_set_server_cert_type intentionally in sesrver
  82567. * end, expecting the default setting works.
  82568. */
  82569. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82570. return TEST_FAIL;
  82571. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82572. WOLFSSL_SUCCESS);
  82573. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82574. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82575. WOLFSSL_SUCCESS);
  82576. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82577. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82578. WOLFSSL_SUCCESS);
  82579. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82580. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82581. WOLFSSL_SUCCESS);
  82582. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82583. wolfSSL_free(ssl_c);
  82584. wolfSSL_CTX_free(ctx_c);
  82585. wolfSSL_free(ssl_s);
  82586. wolfSSL_CTX_free(ctx_s);
  82587. ssl_c = ssl_s = NULL;
  82588. ctx_c = ctx_s = NULL;
  82589. /* Have both client and server load RPK cert, however, have server
  82590. * indicate its cert type x509.
  82591. * Client is expected to detect the cert type mismatch then to send alert
  82592. * with "unsupported_certificate".
  82593. */
  82594. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82595. ExpectIntEQ(
  82596. test_rpk_memio_setup(
  82597. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82598. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82599. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82600. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1, /* server sends RPK cert */
  82601. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82602. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82603. , 0);
  82604. /* have client tell to use RPK cert */
  82605. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82606. certType_c[1] = -1;
  82607. typeCnt_c = 1;
  82608. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82609. WOLFSSL_SUCCESS);
  82610. /* have client tell to accept both RPK and x509 cert */
  82611. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82612. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  82613. typeCnt_s = 2;
  82614. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82615. WOLFSSL_SUCCESS);
  82616. /* have server accept to both RPK and x509 cert */
  82617. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  82618. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  82619. typeCnt_c = 2;
  82620. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82621. WOLFSSL_SUCCESS);
  82622. /* have server tell to use x509 cert intentionally. This will bring
  82623. * certificate type mismatch in client side.
  82624. */
  82625. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82626. certType_s[1] = -1;
  82627. typeCnt_s = 1;
  82628. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82629. WOLFSSL_SUCCESS);
  82630. /* expect client detect cert type mismatch then send Alert */
  82631. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  82632. if (ret != -1)
  82633. return TEST_FAIL;
  82634. ExpectIntEQ(wolfSSL_get_error(ssl_c, ret), WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  82635. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82636. WOLFSSL_SUCCESS);
  82637. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82638. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82639. WOLFSSL_SUCCESS);
  82640. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82641. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82642. WOLFSSL_SUCCESS);
  82643. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82644. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82645. WOLFSSL_SUCCESS);
  82646. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82647. wolfSSL_free(ssl_c);
  82648. wolfSSL_CTX_free(ctx_c);
  82649. wolfSSL_free(ssl_s);
  82650. wolfSSL_CTX_free(ctx_s);
  82651. ssl_c = ssl_s = NULL;
  82652. ctx_c = ctx_s = NULL;
  82653. /* Have client load x509 cert and server load RPK cert,
  82654. * however, have client indicate its cert type RPK.
  82655. * Server is expected to detect the cert type mismatch then to send alert
  82656. * with "unsupported_certificate".
  82657. */
  82658. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82659. ExpectIntEQ(
  82660. test_rpk_memio_setup(
  82661. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82662. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82663. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82664. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82665. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82666. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82667. , 0);
  82668. /* have client tell to use RPK cert intentionally */
  82669. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82670. certType_c[1] = -1;
  82671. typeCnt_c = 1;
  82672. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82673. WOLFSSL_SUCCESS);
  82674. /* have client tell to accept both RPK and x509 cert */
  82675. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82676. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  82677. typeCnt_s = 2;
  82678. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82679. WOLFSSL_SUCCESS);
  82680. /* have server accept to both RPK and x509 cert */
  82681. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  82682. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  82683. typeCnt_c = 2;
  82684. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82685. WOLFSSL_SUCCESS);
  82686. /* have server tell to use x509 cert intentionally. This will bring
  82687. * certificate type mismatch in client side.
  82688. */
  82689. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82690. certType_s[1] = -1;
  82691. typeCnt_s = 1;
  82692. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82693. WOLFSSL_SUCCESS);
  82694. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  82695. /* expect server detect cert type mismatch then send Alert */
  82696. ExpectIntNE(ret, 0);
  82697. err = wolfSSL_get_error(ssl_c, ret);
  82698. ExpectIntEQ(err, WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  82699. /* client did not load RPK cert actually, so negotiation did not happen */
  82700. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82701. WOLFSSL_SUCCESS);
  82702. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82703. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82704. WOLFSSL_SUCCESS);
  82705. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82706. /* client did not load RPK cert actually, so negotiation did not happen */
  82707. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82708. WOLFSSL_SUCCESS);
  82709. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82710. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82711. WOLFSSL_SUCCESS);
  82712. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82713. wolfSSL_free(ssl_c);
  82714. wolfSSL_CTX_free(ctx_c);
  82715. wolfSSL_free(ssl_s);
  82716. wolfSSL_CTX_free(ctx_s);
  82717. ssl_c = ssl_s = NULL;
  82718. ctx_c = ctx_s = NULL;
  82719. #if defined(WOLFSSL_ALWAYS_VERIFY_CB)
  82720. /* Both client and server load RPK cert and set certificate verify
  82721. * callbacks then start handshaking.
  82722. * Confirm both side can refer the peer's cert.
  82723. */
  82724. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82725. ExpectIntEQ(
  82726. test_rpk_memio_setup(
  82727. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82728. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82729. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82730. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82731. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82732. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82733. , 0);
  82734. /* set client certificate type in client end */
  82735. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82736. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82737. typeCnt_c = 2;
  82738. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82739. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82740. typeCnt_s = 2;
  82741. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82742. WOLFSSL_SUCCESS);
  82743. /* set server certificate type in client end */
  82744. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82745. WOLFSSL_SUCCESS);
  82746. /* set client certificate type in server end */
  82747. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82748. WOLFSSL_SUCCESS);
  82749. /* set server certificate type in server end */
  82750. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82751. WOLFSSL_SUCCESS);
  82752. /* set certificate verify callback to both client and server */
  82753. isServer = 0;
  82754. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  82755. wolfSSL_set_verify(ssl_c, SSL_VERIFY_PEER, MyRpkVerifyCb);
  82756. isServer = 1;
  82757. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  82758. wolfSSL_set_verify(ssl_s, SSL_VERIFY_PEER, MyRpkVerifyCb);
  82759. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  82760. if (ret != 0)
  82761. return TEST_FAIL;
  82762. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82763. WOLFSSL_SUCCESS);
  82764. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82765. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82766. WOLFSSL_SUCCESS);
  82767. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82768. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82769. WOLFSSL_SUCCESS);
  82770. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82771. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82772. WOLFSSL_SUCCESS);
  82773. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82774. wolfSSL_free(ssl_c);
  82775. wolfSSL_CTX_free(ctx_c);
  82776. wolfSSL_free(ssl_s);
  82777. wolfSSL_CTX_free(ctx_s);
  82778. ssl_c = ssl_s = NULL;
  82779. ctx_c = ctx_s = NULL;
  82780. #endif /* WOLFSSL_ALWAYS_VERIFY_CB */
  82781. #endif /* WOLFSSL_TLS13 */
  82782. #endif /* HAVE_RPK && (!WOLFSSL_NO_TLS12 || WOLFSSL_TLS13) */
  82783. return EXPECT_RESULT();
  82784. }
  82785. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  82786. static int test_dtls13_bad_epoch_ch(void)
  82787. {
  82788. EXPECT_DECLS;
  82789. WOLFSSL_CTX *ctx_c = NULL;
  82790. WOLFSSL_CTX *ctx_s = NULL;
  82791. WOLFSSL *ssl_c = NULL;
  82792. WOLFSSL *ssl_s = NULL;
  82793. struct test_memio_ctx test_ctx;
  82794. const int EPOCH_OFF = 3;
  82795. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82796. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82797. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  82798. /* disable hrr cookie so we can later check msgsReceived.got_client_hello
  82799. * with just one message */
  82800. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  82801. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82802. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82803. WOLFSSL_ERROR_WANT_READ);
  82804. ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2);
  82805. /* first CH should use epoch 0x0 */
  82806. ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) &&
  82807. (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0));
  82808. /* change epoch to 2 */
  82809. test_ctx.s_buff[EPOCH_OFF + 1] = 0x2;
  82810. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82811. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82812. WOLFSSL_ERROR_WANT_READ);
  82813. ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1);
  82814. /* resend the CH */
  82815. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  82816. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82817. wolfSSL_free(ssl_c);
  82818. wolfSSL_CTX_free(ctx_c);
  82819. wolfSSL_free(ssl_s);
  82820. wolfSSL_CTX_free(ctx_s);
  82821. return EXPECT_RESULT();
  82822. }
  82823. #else
  82824. static int test_dtls13_bad_epoch_ch(void)
  82825. {
  82826. return TEST_SKIPPED;
  82827. }
  82828. #endif
  82829. #if ((defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  82830. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  82831. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)) || \
  82832. (!defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  82833. !defined(NO_DES3))) || !defined(WOLFSSL_NO_TLS12)) && \
  82834. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  82835. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE)
  82836. static int test_short_session_id_ssl_ready(WOLFSSL* ssl)
  82837. {
  82838. EXPECT_DECLS;
  82839. WOLFSSL_SESSION *sess = NULL;
  82840. /* Setup the session to avoid errors */
  82841. ssl->session->timeout = -1;
  82842. ssl->session->side = WOLFSSL_CLIENT_END;
  82843. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  82844. defined(HAVE_SESSION_TICKET))
  82845. ssl->session->version = ssl->version;
  82846. #endif
  82847. /* Force a short session ID to be sent */
  82848. ssl->session->sessionIDSz = 4;
  82849. #ifndef NO_SESSION_CACHE_REF
  82850. /* Allow the client cache to be used */
  82851. ssl->session->idLen = 4;
  82852. #endif
  82853. ssl->session->isSetup = 1;
  82854. ExpectNotNull(sess = wolfSSL_get_session(ssl));
  82855. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  82856. return EXPECT_RESULT();
  82857. }
  82858. static int test_short_session_id(void)
  82859. {
  82860. EXPECT_DECLS;
  82861. test_ssl_cbf client_cbf;
  82862. test_ssl_cbf server_cbf;
  82863. size_t i;
  82864. struct {
  82865. method_provider client_meth;
  82866. method_provider server_meth;
  82867. const char* tls_version;
  82868. } params[] = {
  82869. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  82870. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  82871. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  82872. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  82873. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  82874. #ifdef WOLFSSL_DTLS13
  82875. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  82876. #endif
  82877. #endif
  82878. #ifndef WOLFSSL_NO_TLS12
  82879. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  82880. #ifdef WOLFSSL_DTLS
  82881. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  82882. #endif
  82883. #endif
  82884. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  82885. !defined(NO_DES3))
  82886. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  82887. #ifdef WOLFSSL_DTLS
  82888. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  82889. #endif
  82890. #endif
  82891. };
  82892. fprintf(stderr, "\n");
  82893. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  82894. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  82895. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  82896. fprintf(stderr, "\tTesting short ID with %s\n", params[i].tls_version);
  82897. client_cbf.ssl_ready = test_short_session_id_ssl_ready;
  82898. client_cbf.method = params[i].client_meth;
  82899. server_cbf.method = params[i].server_meth;
  82900. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  82901. &server_cbf, NULL), TEST_SUCCESS);
  82902. }
  82903. return EXPECT_RESULT();
  82904. }
  82905. #else
  82906. static int test_short_session_id(void)
  82907. {
  82908. return TEST_SKIPPED;
  82909. }
  82910. #endif
  82911. #if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \
  82912. && defined(WOLFSSL_DTLS13)
  82913. static byte* test_find_string(const char *string,
  82914. byte *buf, int buf_size)
  82915. {
  82916. int string_size, i;
  82917. string_size = (int)XSTRLEN(string);
  82918. for (i = 0; i < buf_size - string_size - 1; i++) {
  82919. if (XSTRCMP((char*)&buf[i], string) == 0)
  82920. return &buf[i];
  82921. }
  82922. return NULL;
  82923. }
  82924. static int test_wolfSSL_dtls13_null_cipher(void)
  82925. {
  82926. EXPECT_DECLS;
  82927. WOLFSSL_CTX *ctx_c = NULL;
  82928. WOLFSSL_CTX *ctx_s = NULL;
  82929. WOLFSSL *ssl_c = NULL;
  82930. WOLFSSL *ssl_s = NULL;
  82931. struct test_memio_ctx test_ctx;
  82932. const char *test_str = "test";
  82933. int test_str_size;
  82934. byte buf[255], *ptr = NULL;
  82935. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82936. test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
  82937. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82938. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  82939. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82940. test_str_size = XSTRLEN("test") + 1;
  82941. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  82942. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  82943. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  82944. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  82945. /* check that the packet was sent cleartext */
  82946. ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff,
  82947. test_ctx.s_len));
  82948. if (ptr != NULL) {
  82949. /* modify the message */
  82950. *ptr = 'H';
  82951. /* bad messages should be ignored in DTLS */
  82952. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1);
  82953. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ));
  82954. }
  82955. wolfSSL_free(ssl_c);
  82956. wolfSSL_free(ssl_s);
  82957. wolfSSL_CTX_free(ctx_c);
  82958. wolfSSL_CTX_free(ctx_s);
  82959. return TEST_SUCCESS;
  82960. }
  82961. #else
  82962. static int test_wolfSSL_dtls13_null_cipher(void)
  82963. {
  82964. return TEST_SKIPPED;
  82965. }
  82966. #endif
  82967. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  82968. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  82969. !defined(SINGLE_THREADED) && !defined(NO_RSA)
  82970. static int test_dtls_msg_get_connected_port(int fd, word16 *port)
  82971. {
  82972. SOCKADDR_S peer;
  82973. XSOCKLENT len;
  82974. int ret;
  82975. XMEMSET((byte*)&peer, 0, sizeof(peer));
  82976. len = sizeof(peer);
  82977. ret = getpeername(fd, (SOCKADDR*)&peer, &len);
  82978. if (ret != 0 || len > (XSOCKLENT)sizeof(peer))
  82979. return -1;
  82980. switch (peer.ss_family) {
  82981. #ifdef WOLFSSL_IPV6
  82982. case WOLFSSL_IP6: {
  82983. *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port);
  82984. break;
  82985. }
  82986. #endif /* WOLFSSL_IPV6 */
  82987. case WOLFSSL_IP4:
  82988. *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port);
  82989. break;
  82990. default:
  82991. return -1;
  82992. }
  82993. return 0;
  82994. }
  82995. static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  82996. {
  82997. char buf[1] = {'t'};
  82998. SOCKADDR_IN_T addr;
  82999. int sock_fd;
  83000. word16 port;
  83001. int err;
  83002. (void)ssl;
  83003. (void)ctx;
  83004. if (ssl == NULL)
  83005. return -1;
  83006. err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port);
  83007. if (err != 0)
  83008. return -1;
  83009. sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0);
  83010. if (sock_fd == -1)
  83011. return -1;
  83012. build_addr(&addr, wolfSSLIP, port, 1, 0);
  83013. /* send a packet to the server. Being another socket, the kernel will ensure
  83014. * the source port will be different. */
  83015. err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr,
  83016. sizeof(addr));
  83017. close(sock_fd);
  83018. if (err == -1)
  83019. return -1;
  83020. return 0;
  83021. }
  83022. /* setup a SSL session but just after the handshake send a packet to the server
  83023. * with a source address different than the one of the connected client. The I/O
  83024. * callback EmbedRecvFrom should just ignore the packet. Sending of the packet
  83025. * is done in test_dtls_msg_from_other_peer_cb */
  83026. static int test_dtls_msg_from_other_peer(void)
  83027. {
  83028. EXPECT_DECLS;
  83029. callback_functions client_cbs;
  83030. callback_functions server_cbs;
  83031. XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs));
  83032. XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs));
  83033. client_cbs.method = wolfDTLSv1_2_client_method;
  83034. server_cbs.method = wolfDTLSv1_2_server_method;
  83035. client_cbs.doUdp = 1;
  83036. server_cbs.doUdp = 1;
  83037. test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs,
  83038. test_dtls_msg_from_other_peer_cb);
  83039. ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS);
  83040. ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS);
  83041. return EXPECT_RESULT();
  83042. }
  83043. #else
  83044. static int test_dtls_msg_from_other_peer(void)
  83045. {
  83046. return TEST_SKIPPED;
  83047. }
  83048. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83049. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83050. * !defined(SINGLE_THREADED) && !defined(NO_RSA) */
  83051. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
  83052. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83053. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83054. static int test_dtls_ipv6_check(void)
  83055. {
  83056. EXPECT_DECLS;
  83057. WOLFSSL_CTX *ctx_c = NULL;
  83058. WOLFSSL_CTX *ctx_s = NULL;
  83059. WOLFSSL *ssl_c = NULL;
  83060. WOLFSSL *ssl_s = NULL;
  83061. SOCKADDR_IN fake_addr6;
  83062. int sockfd = -1;
  83063. ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  83064. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  83065. ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  83066. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile,
  83067. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83068. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile,
  83069. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83070. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  83071. XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6));
  83072. /* mimic a sockaddr_in6 struct, this way we can't test without
  83073. * WOLFSSL_IPV6 */
  83074. fake_addr6.sin_family = WOLFSSL_IP6;
  83075. ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1);
  83076. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83077. /* can't return error here, as the peer is opaque for wolfssl library at
  83078. * this point */
  83079. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)),
  83080. WOLFSSL_SUCCESS);
  83081. ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1);
  83082. wolfSSL_dtls_set_using_nonblock(ssl_c, 1);
  83083. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83084. ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83085. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)),
  83086. WOLFSSL_SUCCESS);
  83087. /* reuse the socket */
  83088. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83089. wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
  83090. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83091. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83092. if (sockfd != -1)
  83093. close(sockfd);
  83094. wolfSSL_free(ssl_c);
  83095. wolfSSL_CTX_free(ctx_c);
  83096. wolfSSL_free(ssl_s);
  83097. wolfSSL_CTX_free(ctx_s);
  83098. return EXPECT_RESULT();
  83099. }
  83100. #else
  83101. static int test_dtls_ipv6_check(void)
  83102. {
  83103. return TEST_SKIPPED;
  83104. }
  83105. #endif
  83106. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83107. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83108. static WOLFSSL_SESSION* test_wolfSSL_SCR_after_resumption_session = NULL;
  83109. static void test_wolfSSL_SCR_after_resumption_ctx_ready(WOLFSSL_CTX* ctx)
  83110. {
  83111. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83112. }
  83113. static void test_wolfSSL_SCR_after_resumption_on_result(WOLFSSL* ssl)
  83114. {
  83115. if (test_wolfSSL_SCR_after_resumption_session == NULL) {
  83116. test_wolfSSL_SCR_after_resumption_session = wolfSSL_get1_session(ssl);
  83117. AssertNotNull(test_wolfSSL_SCR_after_resumption_session);
  83118. }
  83119. else {
  83120. char testMsg[] = "Message after SCR";
  83121. char msgBuf[sizeof(testMsg)];
  83122. int ret;
  83123. if (!wolfSSL_is_server(ssl)) {
  83124. AssertIntEQ(WOLFSSL_SUCCESS,
  83125. wolfSSL_set_session(ssl,
  83126. test_wolfSSL_SCR_after_resumption_session));
  83127. }
  83128. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83129. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83130. sizeof(testMsg));
  83131. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83132. if (ret != sizeof(msgBuf)) /* Possibly APP_DATA_READY error. Retry. */
  83133. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83134. AssertIntEQ(ret, sizeof(msgBuf));
  83135. }
  83136. }
  83137. static void test_wolfSSL_SCR_after_resumption_ssl_ready(WOLFSSL* ssl)
  83138. {
  83139. AssertIntEQ(WOLFSSL_SUCCESS,
  83140. wolfSSL_set_session(ssl, test_wolfSSL_SCR_after_resumption_session));
  83141. }
  83142. static int test_wolfSSL_SCR_after_resumption(void)
  83143. {
  83144. EXPECT_DECLS;
  83145. callback_functions func_cb_client;
  83146. callback_functions func_cb_server;
  83147. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83148. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83149. func_cb_client.method = wolfTLSv1_2_client_method;
  83150. func_cb_client.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83151. func_cb_client.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83152. func_cb_server.method = wolfTLSv1_2_server_method;
  83153. func_cb_server.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83154. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83155. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83156. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83157. func_cb_client.ssl_ready = test_wolfSSL_SCR_after_resumption_ssl_ready;
  83158. func_cb_server.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83159. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83160. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83161. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83162. wolfSSL_SESSION_free(test_wolfSSL_SCR_after_resumption_session);
  83163. return EXPECT_RESULT();
  83164. }
  83165. #else
  83166. static int test_wolfSSL_SCR_after_resumption(void)
  83167. {
  83168. return TEST_SKIPPED;
  83169. }
  83170. #endif
  83171. static int test_wolfSSL_configure_args(void)
  83172. {
  83173. EXPECT_DECLS;
  83174. #if defined(LIBWOLFSSL_CONFIGURE_ARGS) && defined(HAVE_WC_INTROSPECTION)
  83175. ExpectNotNull(wolfSSL_configure_args());
  83176. #endif
  83177. return EXPECT_RESULT();
  83178. }
  83179. static int test_dtls_no_extensions(void)
  83180. {
  83181. EXPECT_DECLS;
  83182. #if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  83183. !defined(WOLFSSL_NO_TLS12)
  83184. WOLFSSL *ssl_s = NULL;
  83185. WOLFSSL_CTX *ctx_s = NULL;
  83186. struct test_memio_ctx test_ctx;
  83187. const byte chNoExtensions[] = {
  83188. /* Handshake type */
  83189. 0x16,
  83190. /* Version */
  83191. 0xfe, 0xff,
  83192. /* Epoch */
  83193. 0x00, 0x00,
  83194. /* Seq number */
  83195. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83196. /* Length */
  83197. 0x00, 0x40,
  83198. /* CH type */
  83199. 0x01,
  83200. /* Length */
  83201. 0x00, 0x00, 0x34,
  83202. /* Msg Seq */
  83203. 0x00, 0x00,
  83204. /* Frag offset */
  83205. 0x00, 0x00, 0x00,
  83206. /* Frag length */
  83207. 0x00, 0x00, 0x34,
  83208. /* Version */
  83209. 0xfe, 0xff,
  83210. /* Random */
  83211. 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37,
  83212. 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b,
  83213. 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d,
  83214. /* Session Length */
  83215. 0x00,
  83216. /* Cookie Length */
  83217. 0x00,
  83218. /* CS Length */
  83219. 0x00, 0x0c,
  83220. /* CS */
  83221. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33,
  83222. /* Comp Meths Length */
  83223. 0x01,
  83224. /* Comp Meths */
  83225. 0x00
  83226. /* And finally... no extensions */
  83227. };
  83228. int i;
  83229. #ifdef OPENSSL_EXTRA
  83230. int repeats = 2;
  83231. #else
  83232. int repeats = 1;
  83233. #endif
  83234. for (i = 0; i < repeats; i++) {
  83235. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83236. ssl_s = NULL;
  83237. ctx_s = NULL;
  83238. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  83239. NULL, wolfDTLS_server_method), 0);
  83240. XMEMCPY(test_ctx.s_buff, chNoExtensions, sizeof(chNoExtensions));
  83241. test_ctx.s_len = sizeof(chNoExtensions);
  83242. #ifdef OPENSSL_EXTRA
  83243. if (i > 0) {
  83244. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION),
  83245. WOLFSSL_SUCCESS);
  83246. }
  83247. #endif
  83248. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  83249. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83250. /* Expecting a handshake msg. Either HVR or SH. */
  83251. ExpectIntGT(test_ctx.c_len, 0);
  83252. ExpectIntEQ(test_ctx.c_buff[0], 0x16);
  83253. wolfSSL_free(ssl_s);
  83254. wolfSSL_CTX_free(ctx_s);
  83255. }
  83256. #endif
  83257. return EXPECT_RESULT();
  83258. }
  83259. static int test_tls_alert_no_server_hello(void)
  83260. {
  83261. EXPECT_DECLS;
  83262. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83263. WOLFSSL *ssl_c = NULL;
  83264. WOLFSSL_CTX *ctx_c = NULL;
  83265. struct test_memio_ctx test_ctx;
  83266. unsigned char alert_msg[] = { 0x15, 0x03, 0x01, 0x00, 0x02, 0x02, 0x28 };
  83267. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83268. ssl_c = NULL;
  83269. ctx_c = NULL;
  83270. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83271. wolfTLSv1_2_client_method, NULL), 0);
  83272. XMEMCPY(test_ctx.c_buff, alert_msg, sizeof(alert_msg));
  83273. test_ctx.c_len = sizeof(alert_msg);
  83274. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83275. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(FATAL_ERROR));
  83276. wolfSSL_free(ssl_c);
  83277. wolfSSL_CTX_free(ctx_c);
  83278. #endif
  83279. return EXPECT_RESULT();
  83280. }
  83281. static int test_TLSX_CA_NAMES_bad_extension(void)
  83282. {
  83283. EXPECT_DECLS;
  83284. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83285. !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
  83286. defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA384) && \
  83287. defined(HAVE_NULL_CIPHER)
  83288. /* This test should only fail (with BUFFER_ERROR) when we actually try to
  83289. * parse the CA Names extension. Otherwise it will return other non-related
  83290. * errors. If CA Names will be parsed in more configurations, that should
  83291. * be reflected in the macro guard above. */
  83292. WOLFSSL *ssl_c = NULL;
  83293. WOLFSSL_CTX *ctx_c = NULL;
  83294. struct test_memio_ctx test_ctx;
  83295. /* HRR + SH using TLS_DHE_PSK_WITH_NULL_SHA384 */
  83296. const byte shBadCaNamesExt[] = {
  83297. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83298. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83299. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83300. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83301. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83302. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83303. 0x5c, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x03, 0xcf, 0x21, 0xad, 0x74,
  83304. 0x00, 0x00, 0x83, 0x3f, 0x3b, 0x80, 0x01, 0xac, 0x65, 0x8c, 0x19, 0x2a,
  83305. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x02, 0x00, 0x9e, 0x09, 0x1c, 0xe8,
  83306. 0xa8, 0x09, 0x9c, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83307. 0x03, 0x3f, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x13, 0x05,
  83308. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00,
  83309. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
  83310. 0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
  83311. };
  83312. const byte shBadCaNamesExt2[] = {
  83313. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83314. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83315. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83316. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83317. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83318. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83319. 0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
  83320. 0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
  83321. 0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
  83322. 0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83323. 0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
  83324. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
  83325. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
  83326. 0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
  83327. };
  83328. int i = 0;
  83329. for (i = 0; i < 2; i++) {
  83330. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83331. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83332. wolfTLSv1_3_client_method, NULL), 0);
  83333. switch (i) {
  83334. case 0:
  83335. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
  83336. sizeof(shBadCaNamesExt));
  83337. test_ctx.c_len = sizeof(shBadCaNamesExt);
  83338. break;
  83339. case 1:
  83340. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
  83341. sizeof(shBadCaNamesExt2));
  83342. test_ctx.c_len = sizeof(shBadCaNamesExt2);
  83343. break;
  83344. }
  83345. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83346. #ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
  83347. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(OUT_OF_ORDER_E));
  83348. #else
  83349. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(BUFFER_ERROR));
  83350. #endif
  83351. wolfSSL_free(ssl_c);
  83352. ssl_c = NULL;
  83353. wolfSSL_CTX_free(ctx_c);
  83354. ctx_c = NULL;
  83355. }
  83356. #endif
  83357. return EXPECT_RESULT();
  83358. }
  83359. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83360. defined(HAVE_IO_TESTS_DEPENDENCIES)
  83361. static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  83362. {
  83363. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83364. WOLFSSL_SUCCESS);
  83365. }
  83366. static int test_dtls_1_0_hvr_downgrade(void)
  83367. {
  83368. EXPECT_DECLS;
  83369. callback_functions func_cb_client;
  83370. callback_functions func_cb_server;
  83371. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83372. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83373. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83374. func_cb_client.method = wolfDTLS_client_method;
  83375. func_cb_server.method = wolfDTLSv1_2_server_method;
  83376. func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready;
  83377. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83378. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83379. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83380. return EXPECT_RESULT();
  83381. }
  83382. #else
  83383. static int test_dtls_1_0_hvr_downgrade(void)
  83384. {
  83385. EXPECT_DECLS;
  83386. return EXPECT_RESULT();
  83387. }
  83388. #endif
  83389. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \
  83390. defined(HAVE_SESSION_TICKET)
  83391. static WOLFSSL_SESSION* test_session_ticket_no_id_session = NULL;
  83392. static void test_session_ticket_no_id_on_result(WOLFSSL* ssl)
  83393. {
  83394. test_session_ticket_no_id_session = wolfSSL_get1_session(ssl);
  83395. AssertNotNull(test_session_ticket_no_id_session);
  83396. }
  83397. static void test_session_ticket_no_id_ctx_ready(WOLFSSL_CTX* ctx)
  83398. {
  83399. AssertIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  83400. }
  83401. static void test_session_ticket_no_id_ssl_ready(WOLFSSL* ssl)
  83402. {
  83403. test_session_ticket_no_id_session->sessionIDSz = 0;
  83404. AssertIntEQ(WOLFSSL_SUCCESS,
  83405. wolfSSL_set_session(ssl, test_session_ticket_no_id_session));
  83406. }
  83407. static int test_session_ticket_no_id(void)
  83408. {
  83409. /* We are testing an expired (invalid crypto context in out case since the
  83410. * ctx changes) session ticket being sent with the session ID being 0
  83411. * length. */
  83412. EXPECT_DECLS;
  83413. callback_functions func_cb_client;
  83414. callback_functions func_cb_server;
  83415. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83416. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83417. func_cb_client.method = wolfTLSv1_2_client_method;
  83418. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83419. func_cb_client.on_result = test_session_ticket_no_id_on_result;
  83420. func_cb_server.method = wolfTLSv1_2_server_method;
  83421. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83422. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83423. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83424. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83425. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83426. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83427. func_cb_client.method = wolfTLSv1_2_client_method;
  83428. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83429. func_cb_client.ssl_ready = test_session_ticket_no_id_ssl_ready;
  83430. func_cb_server.method = wolfTLSv1_2_server_method;
  83431. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83432. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83433. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83434. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83435. wolfSSL_SESSION_free(test_session_ticket_no_id_session);
  83436. return EXPECT_RESULT();
  83437. }
  83438. #else
  83439. static int test_session_ticket_no_id(void)
  83440. {
  83441. EXPECT_DECLS;
  83442. return EXPECT_RESULT();
  83443. }
  83444. #endif
  83445. static int test_session_ticket_hs_update(void)
  83446. {
  83447. EXPECT_DECLS;
  83448. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83449. defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  83450. struct test_memio_ctx test_ctx;
  83451. struct test_memio_ctx test_ctx2;
  83452. struct test_memio_ctx test_ctx3;
  83453. WOLFSSL_CTX *ctx_c = NULL;
  83454. WOLFSSL_CTX *ctx_s = NULL;
  83455. WOLFSSL *ssl_c = NULL;
  83456. WOLFSSL *ssl_c2 = NULL;
  83457. WOLFSSL *ssl_c3 = NULL;
  83458. WOLFSSL *ssl_s = NULL;
  83459. WOLFSSL *ssl_s2 = NULL;
  83460. WOLFSSL *ssl_s3 = NULL;
  83461. WOLFSSL_SESSION *sess = NULL;
  83462. byte read_data[1];
  83463. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83464. XMEMSET(&test_ctx2, 0, sizeof(test_ctx2));
  83465. XMEMSET(&test_ctx3, 0, sizeof(test_ctx3));
  83466. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83467. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83468. /* Generate tickets */
  83469. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83470. wolfSSL_SetLoggingPrefix("client");
  83471. /* Read the ticket msg */
  83472. ExpectIntEQ(wolfSSL_read(ssl_c, read_data, sizeof(read_data)),
  83473. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83474. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83475. WOLFSSL_ERROR_WANT_READ);
  83476. wolfSSL_SetLoggingPrefix(NULL);
  83477. ExpectIntEQ(test_memio_setup(&test_ctx2, &ctx_c, &ctx_s, &ssl_c2, &ssl_s2,
  83478. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83479. ExpectIntEQ(test_memio_setup(&test_ctx3, &ctx_c, &ctx_s, &ssl_c3, &ssl_s3,
  83480. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83481. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  83482. ExpectIntEQ(wolfSSL_set_session(ssl_c2, sess), WOLFSSL_SUCCESS);
  83483. ExpectIntEQ(wolfSSL_set_session(ssl_c3, sess), WOLFSSL_SUCCESS);
  83484. wolfSSL_SetLoggingPrefix("client");
  83485. /* Exchange initial flights for the second connection */
  83486. ExpectIntEQ(wolfSSL_connect(ssl_c2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83487. ExpectIntEQ(wolfSSL_get_error(ssl_c2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83488. WOLFSSL_ERROR_WANT_READ);
  83489. wolfSSL_SetLoggingPrefix(NULL);
  83490. wolfSSL_SetLoggingPrefix("server");
  83491. ExpectIntEQ(wolfSSL_accept(ssl_s2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83492. ExpectIntEQ(wolfSSL_get_error(ssl_s2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83493. WOLFSSL_ERROR_WANT_READ);
  83494. wolfSSL_SetLoggingPrefix(NULL);
  83495. /* Complete third connection so that new tickets are exchanged */
  83496. ExpectIntEQ(test_memio_do_handshake(ssl_c3, ssl_s3, 10, NULL), 0);
  83497. /* Read the ticket msg */
  83498. wolfSSL_SetLoggingPrefix("client");
  83499. ExpectIntEQ(wolfSSL_read(ssl_c3, read_data, sizeof(read_data)),
  83500. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83501. ExpectIntEQ(wolfSSL_get_error(ssl_c3, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83502. WOLFSSL_ERROR_WANT_READ);
  83503. wolfSSL_SetLoggingPrefix(NULL);
  83504. /* Complete second connection */
  83505. ExpectIntEQ(test_memio_do_handshake(ssl_c2, ssl_s2, 10, NULL), 0);
  83506. ExpectIntEQ(wolfSSL_session_reused(ssl_c2), 1);
  83507. ExpectIntEQ(wolfSSL_session_reused(ssl_c3), 1);
  83508. wolfSSL_free(ssl_c);
  83509. wolfSSL_free(ssl_c2);
  83510. wolfSSL_free(ssl_c3);
  83511. wolfSSL_free(ssl_s);
  83512. wolfSSL_free(ssl_s2);
  83513. wolfSSL_free(ssl_s3);
  83514. wolfSSL_CTX_free(ctx_c);
  83515. wolfSSL_CTX_free(ctx_s);
  83516. wolfSSL_SESSION_free(sess);
  83517. #endif
  83518. return EXPECT_RESULT();
  83519. }
  83520. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83521. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83522. static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
  83523. {
  83524. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83525. WOLFSSL_SUCCESS);
  83526. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83527. }
  83528. static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx)
  83529. {
  83530. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83531. }
  83532. static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl)
  83533. {
  83534. char testMsg[] = "Message after SCR";
  83535. char msgBuf[sizeof(testMsg)];
  83536. if (wolfSSL_is_server(ssl)) {
  83537. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83538. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  83539. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83540. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83541. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83542. sizeof(testMsg));
  83543. }
  83544. else {
  83545. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83546. sizeof(testMsg));
  83547. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83548. }
  83549. }
  83550. static int test_dtls_downgrade_scr_server(void)
  83551. {
  83552. EXPECT_DECLS;
  83553. callback_functions func_cb_client;
  83554. callback_functions func_cb_server;
  83555. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83556. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83557. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83558. func_cb_client.method = wolfDTLSv1_2_client_method;
  83559. func_cb_server.method = wolfDTLS_server_method;
  83560. func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready;
  83561. func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server;
  83562. func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result;
  83563. func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result;
  83564. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83565. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83566. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83567. return EXPECT_RESULT();
  83568. }
  83569. #else
  83570. static int test_dtls_downgrade_scr_server(void)
  83571. {
  83572. EXPECT_DECLS;
  83573. return EXPECT_RESULT();
  83574. }
  83575. #endif
  83576. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83577. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83578. static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx)
  83579. {
  83580. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83581. WOLFSSL_SUCCESS);
  83582. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83583. }
  83584. static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl)
  83585. {
  83586. char testMsg[] = "Message after SCR";
  83587. char msgBuf[sizeof(testMsg)];
  83588. if (wolfSSL_is_server(ssl)) {
  83589. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83590. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  83591. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83592. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83593. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83594. sizeof(testMsg));
  83595. }
  83596. else {
  83597. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83598. sizeof(testMsg));
  83599. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83600. }
  83601. }
  83602. static int test_dtls_downgrade_scr(void)
  83603. {
  83604. EXPECT_DECLS;
  83605. callback_functions func_cb_client;
  83606. callback_functions func_cb_server;
  83607. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83608. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83609. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83610. func_cb_client.method = wolfDTLS_client_method;
  83611. func_cb_server.method = wolfDTLSv1_2_server_method;
  83612. func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready;
  83613. func_cb_client.on_result = test_dtls_downgrade_scr_on_result;
  83614. func_cb_server.on_result = test_dtls_downgrade_scr_on_result;
  83615. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83616. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83617. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83618. return EXPECT_RESULT();
  83619. }
  83620. #else
  83621. static int test_dtls_downgrade_scr(void)
  83622. {
  83623. EXPECT_DECLS;
  83624. return EXPECT_RESULT();
  83625. }
  83626. #endif
  83627. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  83628. && !defined(WOLFSSL_NO_TLS12)
  83629. static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl,
  83630. char *data, int sz, void *ctx)
  83631. {
  83632. static int call_counter = 0;
  83633. call_counter++;
  83634. (void)ssl;
  83635. (void)data;
  83636. (void)sz;
  83637. (void)ctx;
  83638. switch (call_counter) {
  83639. case 1:
  83640. case 2:
  83641. return WOLFSSL_CBIO_ERR_TIMEOUT;
  83642. case 3:
  83643. return WOLFSSL_CBIO_ERR_WANT_READ;
  83644. default:
  83645. AssertIntLE(call_counter, 3);
  83646. return -1;
  83647. }
  83648. }
  83649. #endif
  83650. /* Make sure we don't send acks before getting a server hello */
  83651. static int test_dtls_client_hello_timeout_downgrade(void)
  83652. {
  83653. EXPECT_DECLS;
  83654. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  83655. && !defined(WOLFSSL_NO_TLS12)
  83656. WOLFSSL_CTX *ctx_c = NULL;
  83657. WOLFSSL_CTX *ctx_s = NULL;
  83658. WOLFSSL *ssl_c = NULL;
  83659. WOLFSSL *ssl_s = NULL;
  83660. struct test_memio_ctx test_ctx;
  83661. DtlsRecordLayerHeader* dtlsRH;
  83662. size_t len;
  83663. byte sequence_number[8];
  83664. int i;
  83665. for (i = 0; i < 2; i++) {
  83666. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83667. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83668. wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0);
  83669. if (i == 0) {
  83670. /* First time simulate timeout in IO layer */
  83671. /* CH1 */
  83672. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83673. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83674. /* HVR */
  83675. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83676. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83677. /* CH2 */
  83678. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83679. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83680. /* SH flight */
  83681. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83682. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83683. /* Drop the SH */
  83684. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  83685. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83686. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  83687. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  83688. (sizeof(DtlsRecordLayerHeader) + len));
  83689. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  83690. /* Read the remainder of the flight */
  83691. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83692. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83693. wolfSSL_SSLSetIORecv(ssl_c,
  83694. test_dtls_client_hello_timeout_downgrade_read_cb);
  83695. /* CH3 */
  83696. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83697. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83698. wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb);
  83699. }
  83700. else {
  83701. /* Second time call wolfSSL_dtls_got_timeout */
  83702. /* CH1 */
  83703. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83704. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83705. /* HVR */
  83706. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83707. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83708. /* CH2 */
  83709. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83710. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83711. /* SH flight */
  83712. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83713. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83714. /* Drop the SH */
  83715. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  83716. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83717. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  83718. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  83719. (sizeof(DtlsRecordLayerHeader) + len));
  83720. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  83721. /* Read the remainder of the flight */
  83722. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83723. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83724. /* Quick timeout should be set as we received at least one msg */
  83725. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1);
  83726. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83727. /* Quick timeout should be cleared after a quick timeout */
  83728. /* CH3 */
  83729. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0);
  83730. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83731. }
  83732. /* Parse out to make sure we got exactly one ClientHello message */
  83733. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  83734. /* Second ClientHello after HVR */
  83735. sequence_number[7] = 2;
  83736. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  83737. ExpectIntEQ(dtlsRH->type, handshake);
  83738. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  83739. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  83740. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  83741. sizeof(sequence_number)), 0);
  83742. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83743. ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  83744. /* Connection should be able to continue */
  83745. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83746. wolfSSL_free(ssl_c);
  83747. wolfSSL_free(ssl_s);
  83748. wolfSSL_CTX_free(ctx_c);
  83749. wolfSSL_CTX_free(ctx_s);
  83750. ssl_c = NULL;
  83751. ssl_s = NULL;
  83752. ctx_c = NULL;
  83753. ctx_s = NULL;
  83754. if (!EXPECT_SUCCESS())
  83755. break;
  83756. }
  83757. #endif
  83758. return EXPECT_RESULT();
  83759. }
  83760. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  83761. static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data,
  83762. int sz, void *ctx)
  83763. {
  83764. static int call_counter = 0;
  83765. call_counter++;
  83766. (void)ssl;
  83767. (void)data;
  83768. (void)sz;
  83769. (void)ctx;
  83770. switch (call_counter) {
  83771. case 1:
  83772. return WOLFSSL_CBIO_ERR_TIMEOUT;
  83773. case 2:
  83774. return WOLFSSL_CBIO_ERR_WANT_READ;
  83775. default:
  83776. AssertIntLE(call_counter, 2);
  83777. return -1;
  83778. }
  83779. }
  83780. #endif
  83781. /* Make sure we don't send acks before getting a server hello */
  83782. static int test_dtls_client_hello_timeout(void)
  83783. {
  83784. EXPECT_DECLS;
  83785. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  83786. WOLFSSL *ssl_c = NULL;
  83787. WOLFSSL_CTX *ctx_c = NULL;
  83788. struct test_memio_ctx test_ctx;
  83789. DtlsRecordLayerHeader* dtlsRH;
  83790. size_t idx;
  83791. size_t len;
  83792. byte sequence_number[8];
  83793. int i;
  83794. for (i = 0; i < 2; i++) {
  83795. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83796. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83797. wolfDTLSv1_3_client_method, NULL), 0);
  83798. if (i == 0) {
  83799. /* First time simulate timeout in IO layer */
  83800. wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb);
  83801. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83802. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83803. }
  83804. else {
  83805. /* Second time call wolfSSL_dtls_got_timeout */
  83806. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83807. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83808. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83809. }
  83810. /* Parse out to make sure we got exactly two ClientHello messages */
  83811. idx = 0;
  83812. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  83813. /* First ClientHello */
  83814. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  83815. ExpectIntEQ(dtlsRH->type, handshake);
  83816. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  83817. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  83818. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  83819. sizeof(sequence_number)), 0);
  83820. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83821. ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  83822. idx += sizeof(DtlsRecordLayerHeader) + len;
  83823. /* Second ClientHello */
  83824. sequence_number[7] = 1;
  83825. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  83826. ExpectIntEQ(dtlsRH->type, handshake);
  83827. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  83828. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  83829. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  83830. sizeof(sequence_number)), 0);
  83831. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83832. ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  83833. wolfSSL_free(ssl_c);
  83834. wolfSSL_CTX_free(ctx_c);
  83835. ssl_c = NULL;
  83836. ctx_c = NULL;
  83837. if (!EXPECT_SUCCESS())
  83838. break;
  83839. }
  83840. #endif
  83841. return EXPECT_RESULT();
  83842. }
  83843. /* DTLS test when dropping the changed cipher spec message */
  83844. static int test_dtls_dropped_ccs(void)
  83845. {
  83846. EXPECT_DECLS;
  83847. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  83848. && !defined(WOLFSSL_NO_TLS12)
  83849. WOLFSSL_CTX *ctx_c = NULL;
  83850. WOLFSSL_CTX *ctx_s = NULL;
  83851. WOLFSSL *ssl_c = NULL;
  83852. WOLFSSL *ssl_s = NULL;
  83853. struct test_memio_ctx test_ctx;
  83854. DtlsRecordLayerHeader* dtlsRH;
  83855. size_t len;
  83856. byte data[1];
  83857. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83858. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83859. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  83860. /* CH1 */
  83861. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83862. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83863. /* HVR */
  83864. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83865. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83866. /* CH2 */
  83867. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83868. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83869. /* Server first flight */
  83870. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83871. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83872. /* Client flight */
  83873. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83874. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83875. /* Server ccs + finished */
  83876. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  83877. /* Drop the ccs */
  83878. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  83879. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83880. ExpectIntEQ(len, 1);
  83881. ExpectIntEQ(dtlsRH->type, change_cipher_spec);
  83882. if (EXPECT_SUCCESS()) {
  83883. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  83884. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  83885. (sizeof(DtlsRecordLayerHeader) + len));
  83886. }
  83887. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  83888. /* Client rtx flight */
  83889. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83890. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83891. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83892. /* Server ccs + finished rtx */
  83893. ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1);
  83894. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83895. /* Client processes finished */
  83896. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  83897. wolfSSL_free(ssl_c);
  83898. wolfSSL_free(ssl_s);
  83899. wolfSSL_CTX_free(ctx_c);
  83900. wolfSSL_CTX_free(ctx_s);
  83901. #endif
  83902. return EXPECT_RESULT();
  83903. }
  83904. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  83905. && !defined(WOLFSSL_NO_TLS12)
  83906. static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen,
  83907. byte seq_num)
  83908. {
  83909. EXPECT_DECLS;
  83910. DtlsRecordLayerHeader* dtlsRH;
  83911. byte sequence_number[8];
  83912. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  83913. ExpectIntGE(ioBufLen, sizeof(*dtlsRH));
  83914. dtlsRH = (DtlsRecordLayerHeader*)ioBuf;
  83915. ExpectIntEQ(dtlsRH->type, handshake);
  83916. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  83917. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  83918. sequence_number[7] = seq_num;
  83919. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  83920. sizeof(sequence_number)), 0);
  83921. return EXPECT_RESULT();
  83922. }
  83923. #endif
  83924. /*
  83925. * Make sure that we send the correct sequence number after a HelloVerifyRequest
  83926. * and after a HelloRetryRequest. This is testing the server side as it is
  83927. * operating statelessly and should copy the sequence number of the ClientHello.
  83928. */
  83929. static int test_dtls_seq_num_downgrade(void)
  83930. {
  83931. EXPECT_DECLS;
  83932. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  83933. && !defined(WOLFSSL_NO_TLS12)
  83934. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  83935. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  83936. struct test_memio_ctx test_ctx;
  83937. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83938. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83939. wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0);
  83940. /* CH1 */
  83941. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83942. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83943. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  83944. test_ctx.s_len, 0), TEST_SUCCESS);
  83945. /* HVR */
  83946. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83947. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83948. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  83949. test_ctx.c_len, 0), TEST_SUCCESS);
  83950. /* CH2 */
  83951. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83952. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83953. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  83954. test_ctx.s_len, 1), TEST_SUCCESS);
  83955. /* Server first flight */
  83956. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83957. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83958. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  83959. test_ctx.c_len, 1), TEST_SUCCESS);
  83960. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83961. wolfSSL_free(ssl_c);
  83962. wolfSSL_CTX_free(ctx_c);
  83963. wolfSSL_free(ssl_s);
  83964. wolfSSL_CTX_free(ctx_s);
  83965. #endif
  83966. return EXPECT_RESULT();
  83967. }
  83968. /**
  83969. * Make sure we don't send RSA Signature Hash Algorithms in the
  83970. * CertificateRequest when we don't have any such ciphers set.
  83971. * @return EXPECT_RESULT()
  83972. */
  83973. static int test_certreq_sighash_algos(void)
  83974. {
  83975. EXPECT_DECLS;
  83976. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  83977. !defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \
  83978. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  83979. defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_TLS12)
  83980. WOLFSSL_CTX *ctx_c = NULL;
  83981. WOLFSSL_CTX *ctx_s = NULL;
  83982. WOLFSSL *ssl_c = NULL;
  83983. WOLFSSL *ssl_s = NULL;
  83984. struct test_memio_ctx test_ctx;
  83985. int idx = 0;
  83986. int maxIdx = 0;
  83987. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83988. test_ctx.c_ciphers = test_ctx.s_ciphers =
  83989. "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA384";
  83990. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83991. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  83992. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c,
  83993. "./certs/ca-ecc-cert.pem", NULL), WOLFSSL_SUCCESS);
  83994. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL);
  83995. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_s, "./certs/ecc-key.pem",
  83996. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83997. ExpectIntEQ(wolfSSL_use_certificate_file(ssl_s, "./certs/server-ecc.pem",
  83998. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83999. ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84000. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84001. WOLFSSL_ERROR_WANT_READ);
  84002. ExpectIntEQ(wolfSSL_accept(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84003. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84004. WOLFSSL_ERROR_WANT_READ);
  84005. /* Find the CertificateRequest message */
  84006. for (idx = 0; idx < test_ctx.c_len && EXPECT_SUCCESS();) {
  84007. word16 len;
  84008. ExpectIntEQ(test_ctx.c_buff[idx++], handshake);
  84009. ExpectIntEQ(test_ctx.c_buff[idx++], SSLv3_MAJOR);
  84010. ExpectIntEQ(test_ctx.c_buff[idx++], TLSv1_2_MINOR);
  84011. ato16(test_ctx.c_buff + idx, &len);
  84012. idx += OPAQUE16_LEN;
  84013. if (test_ctx.c_buff[idx] == certificate_request) {
  84014. idx++;
  84015. /* length */
  84016. idx += OPAQUE24_LEN;
  84017. /* cert types */
  84018. idx += 1 + test_ctx.c_buff[idx];
  84019. /* Sig algos */
  84020. ato16(test_ctx.c_buff + idx, &len);
  84021. idx += OPAQUE16_LEN;
  84022. maxIdx = idx + (int)len;
  84023. for (; idx < maxIdx && EXPECT_SUCCESS(); idx += OPAQUE16_LEN) {
  84024. if (test_ctx.c_buff[idx+1] == ED25519_SA_MINOR ||
  84025. test_ctx.c_buff[idx+1] == ED448_SA_MINOR)
  84026. ExpectIntEQ(test_ctx.c_buff[idx], NEW_SA_MAJOR);
  84027. else
  84028. ExpectIntEQ(test_ctx.c_buff[idx+1], ecc_dsa_sa_algo);
  84029. }
  84030. break;
  84031. }
  84032. else {
  84033. idx += (int)len;
  84034. }
  84035. }
  84036. ExpectIntLT(idx, test_ctx.c_len);
  84037. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84038. wolfSSL_free(ssl_c);
  84039. wolfSSL_free(ssl_s);
  84040. wolfSSL_CTX_free(ctx_c);
  84041. wolfSSL_CTX_free(ctx_s);
  84042. #endif
  84043. return EXPECT_RESULT();
  84044. }
  84045. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84046. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84047. static int test_revoked_loaded_int_cert_ctx_ready1(WOLFSSL_CTX* ctx)
  84048. {
  84049. EXPECT_DECLS;
  84050. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84051. myVerifyAction = VERIFY_USE_PREVERFIY;
  84052. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84053. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84054. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84055. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84056. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84057. WOLFSSL_SUCCESS);
  84058. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84059. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84060. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84061. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84062. "./certs/crl/ca-int.pem",
  84063. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84064. return EXPECT_RESULT();
  84065. }
  84066. static int test_revoked_loaded_int_cert_ctx_ready2(WOLFSSL_CTX* ctx)
  84067. {
  84068. EXPECT_DECLS;
  84069. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84070. myVerifyAction = VERIFY_USE_PREVERFIY;
  84071. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84072. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84073. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84074. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84075. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84076. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84077. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84078. WOLFSSL_SUCCESS);
  84079. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84080. "./certs/crl/ca-int2.pem",
  84081. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84082. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84083. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84084. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84085. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84086. "./certs/crl/ca-int.pem",
  84087. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84088. return EXPECT_RESULT();
  84089. }
  84090. #endif
  84091. static int test_revoked_loaded_int_cert(void)
  84092. {
  84093. EXPECT_DECLS;
  84094. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84095. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84096. test_ssl_cbf client_cbf;
  84097. test_ssl_cbf server_cbf;
  84098. struct {
  84099. const char* certPemFile;
  84100. const char* keyPemFile;
  84101. ctx_cb client_ctx_ready;
  84102. } test_params[] = {
  84103. {"./certs/intermediate/ca-int2-cert.pem",
  84104. "./certs/intermediate/ca-int2-key.pem",
  84105. test_revoked_loaded_int_cert_ctx_ready1},
  84106. {"./certs/intermediate/server-chain.pem",
  84107. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84108. {"./certs/intermediate/server-chain-short.pem",
  84109. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84110. };
  84111. size_t i;
  84112. printf("\n");
  84113. for (i = 0; i < XELEM_CNT(test_params); i++) {
  84114. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84115. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84116. printf("\tTesting with %s...\n", test_params[i].certPemFile);
  84117. server_cbf.certPemFile = test_params[i].certPemFile;
  84118. server_cbf.keyPemFile = test_params[i].keyPemFile;
  84119. client_cbf.ctx_ready = test_params[i].client_ctx_ready;
  84120. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84121. &server_cbf, NULL), TEST_FAIL);
  84122. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  84123. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  84124. if (!EXPECT_SUCCESS())
  84125. break;
  84126. printf("\t%s passed\n", test_params[i].certPemFile);
  84127. }
  84128. #endif
  84129. return EXPECT_RESULT();
  84130. }
  84131. static int test_dtls13_frag_ch_pq(void)
  84132. {
  84133. EXPECT_DECLS;
  84134. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84135. && defined(WOLFSSL_DTLS_CH_FRAG) && defined(HAVE_LIBOQS)
  84136. WOLFSSL_CTX *ctx_c = NULL;
  84137. WOLFSSL_CTX *ctx_s = NULL;
  84138. WOLFSSL *ssl_c = NULL;
  84139. WOLFSSL *ssl_s = NULL;
  84140. struct test_memio_ctx test_ctx;
  84141. const char *test_str = "test";
  84142. int test_str_size;
  84143. byte buf[255];
  84144. int group = WOLFSSL_KYBER_LEVEL5;
  84145. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84146. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84147. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84148. /* Add in a large post-quantum key share to make the CH long. */
  84149. ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS);
  84150. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS);
  84151. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84152. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84153. ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "KYBER_LEVEL5");
  84154. ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "KYBER_LEVEL5");
  84155. test_str_size = XSTRLEN("test") + 1;
  84156. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84157. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  84158. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  84159. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84160. wolfSSL_free(ssl_c);
  84161. wolfSSL_free(ssl_s);
  84162. wolfSSL_CTX_free(ctx_c);
  84163. wolfSSL_CTX_free(ctx_s);
  84164. #endif
  84165. return EXPECT_RESULT();
  84166. }
  84167. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84168. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84169. static int test_dtls_frag_ch_count_records(byte* b, int len)
  84170. {
  84171. DtlsRecordLayerHeader* dtlsRH;
  84172. int records = 0;
  84173. size_t recordLen;
  84174. while (len > 0) {
  84175. records++;
  84176. dtlsRH = (DtlsRecordLayerHeader*)b;
  84177. recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1];
  84178. b += sizeof(DtlsRecordLayerHeader) + recordLen;
  84179. len -= sizeof(DtlsRecordLayerHeader) + recordLen;
  84180. }
  84181. return records;
  84182. }
  84183. #endif
  84184. static int test_dtls_frag_ch(void)
  84185. {
  84186. EXPECT_DECLS;
  84187. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84188. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84189. WOLFSSL_CTX *ctx_c = NULL;
  84190. WOLFSSL_CTX *ctx_s = NULL;
  84191. WOLFSSL *ssl_c = NULL;
  84192. WOLFSSL *ssl_s = NULL;
  84193. struct test_memio_ctx test_ctx;
  84194. static unsigned int DUMMY_MTU = 256;
  84195. unsigned char four_frag_CH[] = {
  84196. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84197. 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84198. 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1,
  84199. 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85,
  84200. 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00,
  84201. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84202. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84203. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84204. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84205. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02,
  84206. 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  84207. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  84208. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  84209. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  84210. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  84211. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17,
  84212. 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1,
  84213. 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19,
  84214. 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9,
  84215. 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84216. 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00,
  84217. 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f,
  84218. 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e,
  84219. 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61,
  84220. 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6,
  84221. 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b,
  84222. 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2,
  84223. 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b,
  84224. 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28,
  84225. 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86,
  84226. 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf,
  84227. 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c,
  84228. 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f,
  84229. 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06,
  84230. 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78,
  84231. 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8,
  84232. 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b,
  84233. 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6,
  84234. 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00,
  84235. 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00,
  84236. 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46,
  84237. 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96,
  84238. 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50,
  84239. 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80,
  84240. 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7,
  84241. 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5,
  84242. 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4,
  84243. 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d,
  84244. 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3,
  84245. 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e,
  84246. 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc,
  84247. 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72,
  84248. 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4,
  84249. 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4,
  84250. 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb,
  84251. 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17,
  84252. 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b,
  84253. 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd,
  84254. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00,
  84255. 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66,
  84256. 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c,
  84257. 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50,
  84258. 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4,
  84259. 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99,
  84260. 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3,
  84261. 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43,
  84262. 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13,
  84263. 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb,
  84264. 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87,
  84265. 0xa5, 0xcb, 0x68, 0xf3
  84266. };
  84267. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84268. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84269. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84270. /* Fragment msgs */
  84271. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS);
  84272. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS);
  84273. /* Add in some key shares to make the CH long */
  84274. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1),
  84275. WOLFSSL_SUCCESS);
  84276. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1),
  84277. WOLFSSL_SUCCESS);
  84278. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1),
  84279. WOLFSSL_SUCCESS);
  84280. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048),
  84281. WOLFSSL_SUCCESS);
  84282. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84283. /* Reject fragmented first CH */
  84284. ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH,
  84285. sizeof(four_frag_CH)), 4);
  84286. XMEMCPY(test_ctx.s_buff, four_frag_CH, sizeof(four_frag_CH));
  84287. test_ctx.s_len = sizeof(four_frag_CH);
  84288. while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) {
  84289. int s_len = test_ctx.s_len;
  84290. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84291. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84292. /* Fail if we didn't advance the buffer to avoid infinite loops */
  84293. ExpectIntLT(test_ctx.s_len, s_len);
  84294. }
  84295. /* Expect all fragments read */
  84296. ExpectIntEQ(test_ctx.s_len, 0);
  84297. /* Expect quietly dropping fragmented first CH */
  84298. ExpectIntEQ(test_ctx.c_len, 0);
  84299. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
  84300. /* Disable ECH as it pushes it over our MTU */
  84301. wolfSSL_SetEchEnable(ssl_c, 0);
  84302. #endif
  84303. /* Limit options to make the CH a fixed length */
  84304. /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2
  84305. * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */
  84306. ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384"
  84307. #ifdef OPENSSL_EXTRA
  84308. ":DHE-RSA-AES256-GCM-SHA384"
  84309. #endif
  84310. ));
  84311. /* CH1 */
  84312. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84313. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84314. /* Count records. Expect 1 unfragmented CH */
  84315. ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84316. test_ctx.s_len), 1);
  84317. /* HRR */
  84318. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84319. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84320. /* CH2 */
  84321. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84322. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84323. /* Count records. Expect fragmented CH */
  84324. ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84325. test_ctx.s_len), 1);
  84326. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84327. wolfSSL_free(ssl_c);
  84328. wolfSSL_free(ssl_s);
  84329. wolfSSL_CTX_free(ctx_c);
  84330. wolfSSL_CTX_free(ctx_s);
  84331. ssl_c = ssl_s = NULL;
  84332. ctx_c = ctx_s = NULL;
  84333. #endif
  84334. return EXPECT_RESULT();
  84335. }
  84336. static int test_dtls_empty_keyshare_with_cookie(void)
  84337. {
  84338. EXPECT_DECLS;
  84339. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84340. WOLFSSL_CTX *ctx_s = NULL;
  84341. WOLFSSL *ssl_s = NULL;
  84342. struct test_memio_ctx test_ctx;
  84343. unsigned char ch_empty_keyshare_with_cookie[] = {
  84344. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  84345. 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  84346. 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3,
  84347. 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9,
  84348. 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00,
  84349. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84350. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84351. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84352. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84353. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00,
  84354. 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47,
  84355. 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf,
  84356. 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f,
  84357. 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13,
  84358. 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d,
  84359. 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5,
  84360. 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00,
  84361. 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02,
  84362. 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08,
  84363. 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06,
  84364. 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00,
  84365. 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01,
  84366. 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f,
  84367. 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00
  84368. };
  84369. DtlsRecordLayerHeader* dtlsRH;
  84370. byte sequence_number[8];
  84371. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84372. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84373. XMEMCPY(test_ctx.s_buff, ch_empty_keyshare_with_cookie,
  84374. sizeof(ch_empty_keyshare_with_cookie));
  84375. test_ctx.s_len = sizeof(ch_empty_keyshare_with_cookie);
  84376. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  84377. NULL, wolfDTLSv1_3_server_method), 0);
  84378. /* CH1 */
  84379. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84380. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84381. /* Expect an alert. A plaintext alert should be exactly 15 bytes. */
  84382. ExpectIntEQ(test_ctx.c_len, 15);
  84383. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  84384. ExpectIntEQ(dtlsRH->type, alert);
  84385. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84386. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84387. sequence_number[7] = 1;
  84388. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84389. sizeof(sequence_number)), 0);
  84390. ExpectIntEQ(dtlsRH->length[0], 0);
  84391. ExpectIntEQ(dtlsRH->length[1], 2);
  84392. ExpectIntEQ(test_ctx.c_buff[13], alert_fatal);
  84393. ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter);
  84394. wolfSSL_free(ssl_s);
  84395. wolfSSL_CTX_free(ctx_s);
  84396. #endif
  84397. return EXPECT_RESULT();
  84398. }
  84399. static int test_dtls_old_seq_number(void)
  84400. {
  84401. EXPECT_DECLS;
  84402. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  84403. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84404. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84405. struct test_memio_ctx test_ctx;
  84406. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84407. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84408. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  84409. /* CH1 */
  84410. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84411. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84412. /* HVR */
  84413. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84414. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84415. /* CH2 */
  84416. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84417. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84418. /* Server first flight */
  84419. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84420. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84421. /* Client second flight */
  84422. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84423. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84424. /* Modify the sequence number */
  84425. {
  84426. DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  84427. XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number));
  84428. }
  84429. /* Server second flight */
  84430. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84431. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84432. /* Server should not do anything as a pkt was dropped */
  84433. ExpectIntEQ(test_ctx.c_len, 0);
  84434. ExpectIntEQ(test_ctx.s_len, 0);
  84435. /* Trigger rtx */
  84436. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84437. /* Complete connection */
  84438. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84439. wolfSSL_free(ssl_c);
  84440. wolfSSL_CTX_free(ctx_c);
  84441. wolfSSL_free(ssl_s);
  84442. wolfSSL_CTX_free(ctx_s);
  84443. #endif
  84444. return EXPECT_RESULT();
  84445. }
  84446. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84447. defined(HAVE_LIBOQS)
  84448. static void test_tls13_pq_groups_ctx_ready(WOLFSSL_CTX* ctx)
  84449. {
  84450. int group = WOLFSSL_KYBER_LEVEL5;
  84451. AssertIntEQ(wolfSSL_CTX_set_groups(ctx, &group, 1), WOLFSSL_SUCCESS);
  84452. }
  84453. static void test_tls13_pq_groups_on_result(WOLFSSL* ssl)
  84454. {
  84455. AssertStrEQ(wolfSSL_get_curve_name(ssl), "KYBER_LEVEL5");
  84456. }
  84457. #endif
  84458. static int test_tls13_pq_groups(void)
  84459. {
  84460. EXPECT_DECLS;
  84461. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84462. defined(HAVE_LIBOQS)
  84463. callback_functions func_cb_client;
  84464. callback_functions func_cb_server;
  84465. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84466. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84467. func_cb_client.method = wolfTLSv1_3_client_method;
  84468. func_cb_server.method = wolfTLSv1_3_server_method;
  84469. func_cb_client.ctx_ready = test_tls13_pq_groups_ctx_ready;
  84470. func_cb_client.on_result = test_tls13_pq_groups_on_result;
  84471. func_cb_server.on_result = test_tls13_pq_groups_on_result;
  84472. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84473. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84474. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84475. #endif
  84476. return EXPECT_RESULT();
  84477. }
  84478. static int test_tls13_early_data(void)
  84479. {
  84480. EXPECT_DECLS;
  84481. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  84482. defined(WOLFSSL_EARLY_DATA) && defined(HAVE_SESSION_TICKET)
  84483. int written = 0;
  84484. int read = 0;
  84485. size_t i;
  84486. int splitEarlyData;
  84487. char msg[] = "This is early data";
  84488. char msg2[] = "This is client data";
  84489. char msg3[] = "This is server data";
  84490. char msg4[] = "This is server immediate data";
  84491. char msgBuf[50];
  84492. struct {
  84493. method_provider client_meth;
  84494. method_provider server_meth;
  84495. const char* tls_version;
  84496. int isUdp;
  84497. } params[] = {
  84498. #ifdef WOLFSSL_TLS13
  84499. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84500. "TLS 1.3", 0 },
  84501. #endif
  84502. #ifdef WOLFSSL_DTLS13
  84503. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  84504. "DTLS 1.3", 1 },
  84505. #endif
  84506. };
  84507. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  84508. for (splitEarlyData = 0; splitEarlyData < 2; splitEarlyData++) {
  84509. struct test_memio_ctx test_ctx;
  84510. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84511. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84512. WOLFSSL_SESSION *sess = NULL;
  84513. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84514. fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
  84515. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  84516. &ssl_s, params[i].client_meth, params[i].server_meth), 0);
  84517. /* Get a ticket so that we can do 0-RTT on the next connection */
  84518. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84519. /* Make sure we read the ticket */
  84520. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
  84521. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84522. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  84523. wolfSSL_free(ssl_c);
  84524. ssl_c = NULL;
  84525. wolfSSL_free(ssl_s);
  84526. ssl_s = NULL;
  84527. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84528. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84529. params[i].client_meth, params[i].server_meth), 0);
  84530. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  84531. #ifdef WOLFSSL_DTLS13
  84532. if (params[i].isUdp) {
  84533. #ifdef WOLFSSL_DTLS13_NO_HRR_ON_RESUME
  84534. ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1), WOLFSSL_SUCCESS);
  84535. #else
  84536. /* Let's test this but we generally don't recommend turning off the
  84537. * cookie exchange */
  84538. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  84539. #endif
  84540. }
  84541. #endif
  84542. /* Test 0-RTT data */
  84543. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  84544. &written), sizeof(msg));
  84545. ExpectIntEQ(written, sizeof(msg));
  84546. if (splitEarlyData) {
  84547. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  84548. &written), sizeof(msg));
  84549. ExpectIntEQ(written, sizeof(msg));
  84550. }
  84551. /* Read first 0-RTT data (if split otherwise entire data) */
  84552. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84553. &read), sizeof(msg));
  84554. ExpectIntEQ(read, sizeof(msg));
  84555. ExpectStrEQ(msg, msgBuf);
  84556. /* Test 0.5-RTT data */
  84557. ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
  84558. if (splitEarlyData) {
  84559. /* Read second 0-RTT data */
  84560. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84561. &read), sizeof(msg));
  84562. ExpectIntEQ(read, sizeof(msg));
  84563. ExpectStrEQ(msg, msgBuf);
  84564. }
  84565. if (params[i].isUdp) {
  84566. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84567. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84568. /* Read server 0.5-RTT data */
  84569. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  84570. ExpectStrEQ(msg4, msgBuf);
  84571. /* Complete handshake */
  84572. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84573. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84574. /* Use wolfSSL_is_init_finished to check if handshake is complete. Normally
  84575. * a user would loop until it is true but here we control both sides so we
  84576. * just assert the expected value. wolfSSL_read_early_data does not provide
  84577. * handshake status to us with non-blocking IO and we can't use
  84578. * wolfSSL_accept as TLS layer may return ZERO_RETURN due to early data
  84579. * parsing logic. */
  84580. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  84581. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84582. &read), 0);
  84583. ExpectIntEQ(read, 0);
  84584. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  84585. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84586. }
  84587. else {
  84588. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84589. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  84590. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84591. &read), 0);
  84592. ExpectIntEQ(read, 0);
  84593. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  84594. /* Read server 0.5-RTT data */
  84595. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  84596. ExpectStrEQ(msg4, msgBuf);
  84597. }
  84598. /* Test bi-directional write */
  84599. ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
  84600. ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)), sizeof(msg2));
  84601. ExpectStrEQ(msg2, msgBuf);
  84602. ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
  84603. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg3));
  84604. ExpectStrEQ(msg3, msgBuf);
  84605. ExpectTrue(wolfSSL_session_reused(ssl_c));
  84606. ExpectTrue(wolfSSL_session_reused(ssl_s));
  84607. wolfSSL_SESSION_free(sess);
  84608. wolfSSL_free(ssl_c);
  84609. wolfSSL_free(ssl_s);
  84610. wolfSSL_CTX_free(ctx_c);
  84611. wolfSSL_CTX_free(ctx_s);
  84612. }
  84613. }
  84614. #endif
  84615. return EXPECT_RESULT();
  84616. }
  84617. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  84618. static int test_self_signed_stapling_client_v1_ctx_ready(WOLFSSL_CTX* ctx)
  84619. {
  84620. EXPECT_DECLS;
  84621. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84622. ExpectIntEQ(wolfSSL_CTX_UseOCSPStapling(ctx, WOLFSSL_CSR_OCSP,
  84623. WOLFSSL_CSR_OCSP_USE_NONCE), 1);
  84624. return EXPECT_RESULT();
  84625. }
  84626. #endif
  84627. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  84628. static int test_self_signed_stapling_client_v2_ctx_ready(WOLFSSL_CTX* ctx)
  84629. {
  84630. EXPECT_DECLS;
  84631. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84632. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP,
  84633. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  84634. return EXPECT_RESULT();
  84635. }
  84636. static int test_self_signed_stapling_client_v2_multi_ctx_ready(WOLFSSL_CTX* ctx)
  84637. {
  84638. EXPECT_DECLS;
  84639. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84640. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP_MULTI,
  84641. 0), 1);
  84642. return EXPECT_RESULT();
  84643. }
  84644. #endif
  84645. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  84646. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  84647. static int test_self_signed_stapling_server_ctx_ready(WOLFSSL_CTX* ctx)
  84648. {
  84649. EXPECT_DECLS;
  84650. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84651. return EXPECT_RESULT();
  84652. }
  84653. #endif
  84654. static int test_self_signed_stapling(void)
  84655. {
  84656. EXPECT_DECLS;
  84657. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  84658. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  84659. test_ssl_cbf client_cbf;
  84660. test_ssl_cbf server_cbf;
  84661. size_t i;
  84662. struct {
  84663. method_provider client_meth;
  84664. method_provider server_meth;
  84665. ctx_cb client_ctx;
  84666. const char* tls_version;
  84667. } params[] = {
  84668. #if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
  84669. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84670. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_3 v1" },
  84671. #endif
  84672. #ifndef WOLFSSL_NO_TLS12
  84673. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  84674. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  84675. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_2 v1" },
  84676. #endif
  84677. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  84678. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  84679. test_self_signed_stapling_client_v2_ctx_ready, "TLSv1_2 v2" },
  84680. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  84681. test_self_signed_stapling_client_v2_multi_ctx_ready,
  84682. "TLSv1_2 v2 multi" },
  84683. #endif
  84684. #endif
  84685. };
  84686. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  84687. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84688. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84689. printf("\nTesting self-signed cert with status request: %s\n",
  84690. params[i].tls_version);
  84691. client_cbf.method = params[i].client_meth;
  84692. client_cbf.ctx_ready = params[i].client_ctx;
  84693. server_cbf.method = params[i].server_meth;
  84694. server_cbf.certPemFile = "certs/ca-cert.pem";
  84695. server_cbf.keyPemFile = "certs/ca-key.pem";
  84696. server_cbf.ctx_ready = test_self_signed_stapling_server_ctx_ready;
  84697. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84698. &server_cbf, NULL), TEST_SUCCESS);
  84699. }
  84700. #endif
  84701. return EXPECT_RESULT();
  84702. }
  84703. static int test_tls_multi_handshakes_one_record(void)
  84704. {
  84705. EXPECT_DECLS;
  84706. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  84707. struct test_memio_ctx test_ctx;
  84708. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84709. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84710. RecordLayerHeader* rh = NULL;
  84711. byte *len ;
  84712. int newRecIdx = RECORD_HEADER_SZ;
  84713. int idx = 0;
  84714. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84715. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84716. wolfTLS_client_method, wolfTLSv1_2_server_method), 0);
  84717. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84718. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84719. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  84720. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84721. /* Combine server handshake msgs into one record */
  84722. while (idx < test_ctx.c_len) {
  84723. word16 recLen;
  84724. rh = (RecordLayerHeader*)(test_ctx.c_buff + idx);
  84725. len = &rh->length[0];
  84726. ato16((const byte*)len, &recLen);
  84727. idx += RECORD_HEADER_SZ;
  84728. XMEMMOVE(test_ctx.c_buff + newRecIdx, test_ctx.c_buff + idx,
  84729. (size_t)recLen);
  84730. newRecIdx += recLen;
  84731. idx += recLen;
  84732. }
  84733. rh = (RecordLayerHeader*)(test_ctx.c_buff);
  84734. len = &rh->length[0];
  84735. c16toa(newRecIdx - RECORD_HEADER_SZ, len);
  84736. test_ctx.c_len = newRecIdx;
  84737. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84738. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84739. wolfSSL_free(ssl_c);
  84740. wolfSSL_free(ssl_s);
  84741. wolfSSL_CTX_free(ctx_c);
  84742. wolfSSL_CTX_free(ctx_s);
  84743. #endif
  84744. return EXPECT_RESULT();
  84745. }
  84746. static int test_write_dup(void)
  84747. {
  84748. EXPECT_DECLS;
  84749. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
  84750. size_t i, j;
  84751. char hiWorld[] = "dup message";
  84752. char readData[sizeof(hiWorld) + 5];
  84753. struct {
  84754. method_provider client_meth;
  84755. method_provider server_meth;
  84756. const char* version_name;
  84757. int version;
  84758. } methods[] = {
  84759. #ifndef WOLFSSL_NO_TLS12
  84760. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
  84761. #endif
  84762. #ifdef WOLFSSL_TLS13
  84763. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
  84764. #endif
  84765. };
  84766. struct {
  84767. const char* cipher;
  84768. int version;
  84769. } ciphers[] = {
  84770. /* For simplicity the macros are copied from internal.h */
  84771. /* TLS 1.2 */
  84772. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  84773. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  84774. #ifndef NO_RSA
  84775. {"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  84776. #endif
  84777. #endif
  84778. #if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
  84779. {"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  84780. #endif
  84781. #endif
  84782. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  84783. !defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
  84784. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  84785. {"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  84786. #endif
  84787. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  84788. {"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  84789. #endif
  84790. #endif
  84791. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  84792. && !defined(NO_TLS) && !defined(NO_AES)
  84793. #ifdef HAVE_AESGCM
  84794. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  84795. #ifndef NO_RSA
  84796. {"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  84797. #endif
  84798. #endif
  84799. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  84800. #ifndef NO_RSA
  84801. {"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  84802. #endif
  84803. #endif
  84804. #endif
  84805. #endif
  84806. /* TLS 1.3 */
  84807. #ifdef WOLFSSL_TLS13
  84808. #ifdef HAVE_AESGCM
  84809. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  84810. {"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
  84811. #endif
  84812. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  84813. {"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
  84814. #endif
  84815. #endif
  84816. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  84817. #ifndef NO_SHA256
  84818. {"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
  84819. #endif
  84820. #endif
  84821. #ifdef HAVE_AESCCM
  84822. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  84823. {"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
  84824. #endif
  84825. #endif
  84826. #endif
  84827. };
  84828. for (i = 0; i < XELEM_CNT(methods); i++) {
  84829. for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
  84830. struct test_memio_ctx test_ctx;
  84831. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84832. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84833. WOLFSSL *ssl_c2 = NULL;
  84834. if (methods[i].version != ciphers[j].version)
  84835. continue;
  84836. if (i == 0 && j == 0)
  84837. printf("\n");
  84838. printf("Testing %s with %s... ", methods[i].version_name,
  84839. ciphers[j].cipher);
  84840. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84841. test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
  84842. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84843. methods[i].client_meth, methods[i].server_meth), 0);
  84844. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84845. ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
  84846. ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
  84847. WC_NO_ERR_TRACE(WRITE_DUP_WRITE_E));
  84848. ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
  84849. sizeof(hiWorld));
  84850. ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
  84851. sizeof(hiWorld));
  84852. ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
  84853. sizeof(hiWorld));
  84854. ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
  84855. WC_NO_ERR_TRACE(WRITE_DUP_READ_E));
  84856. ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
  84857. sizeof(hiWorld));
  84858. if (EXPECT_SUCCESS())
  84859. printf("ok\n");
  84860. else
  84861. printf("failed\n");
  84862. wolfSSL_free(ssl_c);
  84863. wolfSSL_free(ssl_c2);
  84864. wolfSSL_free(ssl_s);
  84865. wolfSSL_CTX_free(ctx_c);
  84866. wolfSSL_CTX_free(ctx_s);
  84867. }
  84868. }
  84869. #endif
  84870. return EXPECT_RESULT();
  84871. }
  84872. static int test_read_write_hs(void)
  84873. {
  84874. EXPECT_DECLS;
  84875. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  84876. WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
  84877. WOLFSSL *ssl_s = NULL, *ssl_c = NULL;
  84878. struct test_memio_ctx test_ctx;
  84879. byte test_buffer[16];
  84880. unsigned int test;
  84881. /* test == 0 : client writes, server reads */
  84882. /* test == 1 : server writes, client reads */
  84883. for (test = 0; test < 2; test++) {
  84884. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84885. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84886. wolfTLSv1_2_client_method,
  84887. wolfTLSv1_2_server_method), 0);
  84888. ExpectIntEQ(wolfSSL_set_group_messages(ssl_s), WOLFSSL_SUCCESS);
  84889. /* CH -> */
  84890. if (test == 0) {
  84891. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  84892. } else {
  84893. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  84894. sizeof(test_buffer)), -1);
  84895. }
  84896. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84897. /* <- SH + SKE + SHD */
  84898. if (test == 0) {
  84899. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  84900. sizeof(test_buffer)), -1);
  84901. } else {
  84902. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  84903. }
  84904. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84905. /* -> CKE + CLIENT FINISHED */
  84906. if (test == 0) {
  84907. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  84908. } else {
  84909. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  84910. sizeof(test_buffer)), -1);
  84911. }
  84912. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84913. /* abide clang static analyzer */
  84914. if (ssl_s != NULL) {
  84915. /* disable group message to separate sending of ChangeCipherspec
  84916. * from Finished */
  84917. ssl_s->options.groupMessages = 0;
  84918. }
  84919. /* allow writing of CS, but not FINISHED */
  84920. test_ctx.c_len = TEST_MEMIO_BUF_SZ - 6;
  84921. /* <- CS */
  84922. if (test == 0) {
  84923. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  84924. sizeof(test_buffer)), -1);
  84925. } else {
  84926. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  84927. }
  84928. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE);
  84929. /* move CS message where the client can read it */
  84930. memmove(test_ctx.c_buff,
  84931. (test_ctx.c_buff + TEST_MEMIO_BUF_SZ - 6), 6);
  84932. test_ctx.c_len = 6;
  84933. /* read CS */
  84934. if (test == 0) {
  84935. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  84936. } else {
  84937. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  84938. sizeof(test_buffer)), -1);
  84939. }
  84940. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84941. ExpectIntEQ(test_ctx.c_len, 0);
  84942. if (test == 0) {
  84943. /* send SERVER FINISHED */
  84944. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  84945. sizeof(test_buffer)), -1);
  84946. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
  84947. WOLFSSL_ERROR_WANT_READ);
  84948. } else {
  84949. /* send SERVER FINISHED + App Data */
  84950. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), 5);
  84951. }
  84952. ExpectIntGT(test_ctx.c_len, 0);
  84953. /* Send and receive the data */
  84954. if (test == 0) {
  84955. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), 5);
  84956. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  84957. sizeof(test_buffer)), 5);
  84958. } else {
  84959. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  84960. sizeof(test_buffer)), 5);
  84961. }
  84962. ExpectBufEQ(test_buffer, "hello", 5);
  84963. wolfSSL_free(ssl_c);
  84964. wolfSSL_free(ssl_s);
  84965. wolfSSL_CTX_free(ctx_c);
  84966. wolfSSL_CTX_free(ctx_s);
  84967. ssl_c = ssl_s = NULL;
  84968. ctx_c = ctx_s = NULL;
  84969. }
  84970. #endif
  84971. return EXPECT_RESULT();
  84972. }
  84973. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  84974. static const char* test_get_signature_nid_siglag;
  84975. static int test_get_signature_nid_sig;
  84976. static int test_get_signature_nid_hash;
  84977. static int test_get_signature_nid_ssl_ready(WOLFSSL* ssl)
  84978. {
  84979. EXPECT_DECLS;
  84980. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "ALL"), WOLFSSL_SUCCESS);
  84981. if (!wolfSSL_is_server(ssl)) {
  84982. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  84983. test_get_signature_nid_siglag), WOLFSSL_SUCCESS);
  84984. }
  84985. return EXPECT_RESULT();
  84986. }
  84987. static int test_get_signature_nid_on_hs_client(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  84988. {
  84989. EXPECT_DECLS;
  84990. int nid = 0;
  84991. (void)ctx;
  84992. if (XSTRSTR(wolfSSL_get_cipher(*ssl), "TLS_RSA_") == NULL) {
  84993. ExpectIntEQ(SSL_get_peer_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  84994. ExpectIntEQ(nid, test_get_signature_nid_sig);
  84995. ExpectIntEQ(SSL_get_peer_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  84996. ExpectIntEQ(nid, test_get_signature_nid_hash);
  84997. }
  84998. else /* No sigalg info on static ciphersuite */
  84999. return TEST_SUCCESS;
  85000. return EXPECT_RESULT();
  85001. }
  85002. static int test_get_signature_nid_on_hs_server(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85003. {
  85004. EXPECT_DECLS;
  85005. int nid = 0;
  85006. (void)ctx;
  85007. ExpectIntEQ(SSL_get_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85008. ExpectIntEQ(nid, test_get_signature_nid_sig);
  85009. ExpectIntEQ(SSL_get_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85010. ExpectIntEQ(nid, test_get_signature_nid_hash);
  85011. return EXPECT_RESULT();
  85012. }
  85013. #endif
  85014. static int test_get_signature_nid(void)
  85015. {
  85016. EXPECT_DECLS;
  85017. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  85018. test_ssl_cbf client_cbf;
  85019. test_ssl_cbf server_cbf;
  85020. size_t i;
  85021. #define TGSN_TLS12_RSA(sigalg, sig_nid, hash_nid) \
  85022. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, svrCertFile, svrKeyFile, \
  85023. caCertFile }
  85024. #define TGSN_TLS12_ECDSA(sigalg, sig_nid, hash_nid) \
  85025. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, eccCertFile, eccKeyFile, \
  85026. caEccCertFile }
  85027. #define TGSN_TLS13_RSA(sigalg, sig_nid, hash_nid) \
  85028. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, svrCertFile, svrKeyFile, \
  85029. caCertFile }
  85030. #define TGSN_TLS13_ECDSA(sigalg, sig_nid, hash_nid) \
  85031. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, eccCertFile, eccKeyFile, \
  85032. caEccCertFile }
  85033. #define TGSN_TLS13_ED25519(sigalg, sig_nid, hash_nid) \
  85034. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, edCertFile, edKeyFile, \
  85035. caEdCertFile }
  85036. #define TGSN_TLS13_ED448(sigalg, sig_nid, hash_nid) \
  85037. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, ed448CertFile, ed448KeyFile, \
  85038. caEd448CertFile }
  85039. struct {
  85040. const char* siglag;
  85041. int sig_nid;
  85042. int hash_nid;
  85043. int tls_ver;
  85044. const char* server_cert;
  85045. const char* server_key;
  85046. const char* client_ca;
  85047. } params[] = {
  85048. #ifndef NO_RSA
  85049. #ifndef NO_SHA256
  85050. TGSN_TLS12_RSA("RSA+SHA256", NID_rsaEncryption, NID_sha256),
  85051. #ifdef WC_RSA_PSS
  85052. TGSN_TLS12_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85053. TGSN_TLS13_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85054. #endif
  85055. #endif
  85056. #ifdef WOLFSSL_SHA512
  85057. TGSN_TLS12_RSA("RSA+SHA512", NID_rsaEncryption, NID_sha512),
  85058. #ifdef WC_RSA_PSS
  85059. TGSN_TLS12_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85060. TGSN_TLS13_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85061. #endif
  85062. #endif
  85063. #endif
  85064. #ifdef HAVE_ECC
  85065. #ifndef NO_SHA256
  85066. TGSN_TLS12_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85067. TGSN_TLS13_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85068. #endif
  85069. #endif
  85070. #ifdef HAVE_ED25519
  85071. TGSN_TLS13_ED25519("ED25519", NID_ED25519, NID_sha512),
  85072. #endif
  85073. #ifdef HAVE_ED448
  85074. TGSN_TLS13_ED448("ED448", NID_ED448, NID_sha512),
  85075. #endif
  85076. };
  85077. printf("\n");
  85078. for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
  85079. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85080. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85081. printf("Testing %s with %s...", tls_desc[params[i].tls_ver],
  85082. params[i].siglag);
  85083. switch (params[i].tls_ver) {
  85084. #ifndef WOLFSSL_NO_TLS12
  85085. case WOLFSSL_TLSV1_2:
  85086. client_cbf.method = wolfTLSv1_2_client_method;
  85087. server_cbf.method = wolfTLSv1_2_server_method;
  85088. break;
  85089. #endif
  85090. #ifdef WOLFSSL_TLS13
  85091. case WOLFSSL_TLSV1_3:
  85092. client_cbf.method = wolfTLSv1_3_client_method;
  85093. server_cbf.method = wolfTLSv1_3_server_method;
  85094. break;
  85095. #endif
  85096. default:
  85097. printf("skipping\n");
  85098. continue;
  85099. }
  85100. test_get_signature_nid_siglag = params[i].siglag;
  85101. test_get_signature_nid_sig = params[i].sig_nid;
  85102. test_get_signature_nid_hash = params[i].hash_nid;
  85103. client_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85104. server_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85105. client_cbf.on_handshake = test_get_signature_nid_on_hs_client;
  85106. server_cbf.on_handshake = test_get_signature_nid_on_hs_server;
  85107. server_cbf.certPemFile = params[i].server_cert;
  85108. server_cbf.keyPemFile = params[i].server_key;
  85109. client_cbf.caPemFile = params[i].client_ca;
  85110. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85111. &server_cbf, NULL), TEST_SUCCESS);
  85112. if (EXPECT_SUCCESS())
  85113. printf("passed\n");
  85114. }
  85115. #endif
  85116. return EXPECT_RESULT();
  85117. }
  85118. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85119. static word32 test_tls_cert_store_unchanged_HashCaTable(Signer** caTable)
  85120. {
  85121. #ifndef NO_MD5
  85122. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  85123. #elif !defined(NO_SHA)
  85124. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  85125. #elif !defined(NO_SHA256)
  85126. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  85127. #else
  85128. #error "We need a digest to hash the Signer object"
  85129. #endif
  85130. byte hashBuf[WC_MAX_DIGEST_SIZE];
  85131. wc_HashAlg hash;
  85132. size_t i;
  85133. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  85134. for (i = 0; i < CA_TABLE_SIZE; i++) {
  85135. Signer* cur;
  85136. for (cur = caTable[i]; cur != NULL; cur = cur->next)
  85137. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)cur,
  85138. sizeof(*cur)), 0);
  85139. }
  85140. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  85141. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  85142. return MakeWordFromHash(hashBuf);
  85143. }
  85144. static word32 test_tls_cert_store_unchanged_before_hashes[2];
  85145. static size_t test_tls_cert_store_unchanged_before_hashes_idx;
  85146. static word32 test_tls_cert_store_unchanged_after_hashes[2];
  85147. static size_t test_tls_cert_store_unchanged_after_hashes_idx;
  85148. static int test_tls_cert_store_unchanged_ctx_ready(WOLFSSL_CTX* ctx)
  85149. {
  85150. EXPECT_DECLS;
  85151. ExpectIntNE(test_tls_cert_store_unchanged_before_hashes
  85152. [test_tls_cert_store_unchanged_before_hashes_idx++] =
  85153. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85154. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER |
  85155. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  85156. return EXPECT_RESULT();
  85157. }
  85158. static int test_tls_cert_store_unchanged_ctx_cleanup(WOLFSSL_CTX* ctx)
  85159. {
  85160. EXPECT_DECLS;
  85161. ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(ctx), WOLFSSL_SUCCESS);
  85162. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85163. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85164. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85165. return EXPECT_RESULT();
  85166. }
  85167. static int test_tls_cert_store_unchanged_on_hs(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85168. {
  85169. EXPECT_DECLS;
  85170. WOLFSSL_CERT_MANAGER* cm;
  85171. (void)ssl;
  85172. /* WARNING: this approach bypasses the reference counter check in
  85173. * wolfSSL_CTX_UnloadIntermediateCerts. It is not recommended as it may
  85174. * cause unexpected behaviour when other active connections try accessing
  85175. * the caTable. */
  85176. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(*ctx));
  85177. ExpectIntEQ(wolfSSL_CertManagerUnloadIntermediateCerts(cm),
  85178. WOLFSSL_SUCCESS);
  85179. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85180. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85181. test_tls_cert_store_unchanged_HashCaTable((*ctx)->cm->caTable), 0);
  85182. return EXPECT_RESULT();
  85183. }
  85184. static int test_tls_cert_store_unchanged_ssl_ready(WOLFSSL* ssl)
  85185. {
  85186. EXPECT_DECLS;
  85187. WOLFSSL_CTX* ctx;
  85188. ExpectNotNull(ctx = wolfSSL_get_SSL_CTX(ssl));
  85189. return EXPECT_RESULT();
  85190. }
  85191. #endif
  85192. static int test_tls_cert_store_unchanged(void)
  85193. {
  85194. EXPECT_DECLS;
  85195. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85196. test_ssl_cbf client_cbf;
  85197. test_ssl_cbf server_cbf;
  85198. int i;
  85199. for (i = 0; i < 2; i++) {
  85200. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85201. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85202. test_tls_cert_store_unchanged_before_hashes_idx = 0;
  85203. XMEMSET(test_tls_cert_store_unchanged_before_hashes, 0,
  85204. sizeof(test_tls_cert_store_unchanged_before_hashes));
  85205. test_tls_cert_store_unchanged_after_hashes_idx = 0;
  85206. XMEMSET(test_tls_cert_store_unchanged_after_hashes, 0,
  85207. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85208. client_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85209. server_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85210. client_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85211. server_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85212. switch (i) {
  85213. case 0:
  85214. client_cbf.on_ctx_cleanup =
  85215. test_tls_cert_store_unchanged_ctx_cleanup;
  85216. server_cbf.on_ctx_cleanup =
  85217. test_tls_cert_store_unchanged_ctx_cleanup;
  85218. break;
  85219. case 1:
  85220. client_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85221. server_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85222. break;
  85223. default:
  85224. Fail(("Should not enter here"), ("Entered here"));
  85225. }
  85226. client_cbf.certPemFile = "certs/intermediate/client-chain.pem";
  85227. server_cbf.certPemFile = "certs/intermediate/server-chain.pem";
  85228. server_cbf.caPemFile = caCertFile;
  85229. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85230. &server_cbf, NULL), TEST_SUCCESS);
  85231. ExpectBufEQ(test_tls_cert_store_unchanged_before_hashes,
  85232. test_tls_cert_store_unchanged_after_hashes,
  85233. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85234. }
  85235. #endif
  85236. return EXPECT_RESULT();
  85237. }
  85238. static int test_wolfSSL_SendUserCanceled(void)
  85239. {
  85240. EXPECT_DECLS;
  85241. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  85242. size_t i;
  85243. struct {
  85244. method_provider client_meth;
  85245. method_provider server_meth;
  85246. const char* tls_version;
  85247. } params[] = {
  85248. #if defined(WOLFSSL_TLS13)
  85249. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  85250. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  85251. #ifdef WOLFSSL_DTLS13
  85252. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  85253. #endif
  85254. #endif
  85255. #ifndef WOLFSSL_NO_TLS12
  85256. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  85257. #ifdef WOLFSSL_DTLS
  85258. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  85259. #endif
  85260. #endif
  85261. #if !defined(NO_OLD_TLS)
  85262. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  85263. #ifdef WOLFSSL_DTLS
  85264. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  85265. #endif
  85266. #endif
  85267. };
  85268. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85269. WOLFSSL_CTX *ctx_c = NULL;
  85270. WOLFSSL_CTX *ctx_s = NULL;
  85271. WOLFSSL *ssl_c = NULL;
  85272. WOLFSSL *ssl_s = NULL;
  85273. struct test_memio_ctx test_ctx;
  85274. WOLFSSL_ALERT_HISTORY h;
  85275. printf("Testing %s\n", params[i].tls_version);
  85276. XMEMSET(&h, 0, sizeof(h));
  85277. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85278. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85279. params[i].client_meth, params[i].server_meth), 0);
  85280. /* CH1 */
  85281. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85282. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85283. ExpectIntEQ(wolfSSL_SendUserCanceled(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  85284. /* Alert closed connection */
  85285. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85286. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_ZERO_RETURN);
  85287. /* Last alert will be close notify because user_canceled should be
  85288. * followed by a close_notify */
  85289. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  85290. ExpectIntEQ(h.last_rx.code, close_notify);
  85291. ExpectIntEQ(h.last_rx.level, alert_warning);
  85292. wolfSSL_free(ssl_c);
  85293. wolfSSL_free(ssl_s);
  85294. wolfSSL_CTX_free(ctx_c);
  85295. wolfSSL_CTX_free(ctx_s);
  85296. }
  85297. #endif
  85298. return EXPECT_RESULT();
  85299. }
  85300. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85301. defined(HAVE_OCSP) && \
  85302. defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  85303. !defined(WOLFSSL_NO_TLS12)
  85304. static int test_ocsp_callback_fails_cb(void* ctx, const char* url, int urlSz,
  85305. byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
  85306. {
  85307. (void)ctx;
  85308. (void)url;
  85309. (void)urlSz;
  85310. (void)ocspReqBuf;
  85311. (void)ocspReqSz;
  85312. (void)ocspRespBuf;
  85313. return -1;
  85314. }
  85315. static int test_ocsp_callback_fails(void)
  85316. {
  85317. WOLFSSL_CTX *ctx_c = NULL;
  85318. WOLFSSL_CTX *ctx_s = NULL;
  85319. WOLFSSL *ssl_c = NULL;
  85320. WOLFSSL *ssl_s = NULL;
  85321. struct test_memio_ctx test_ctx;
  85322. EXPECT_DECLS;
  85323. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85324. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85325. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  85326. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_c), WOLFSSL_SUCCESS);
  85327. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_s), WOLFSSL_SUCCESS);
  85328. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl_c, WOLFSSL_CSR_OCSP,0), WOLFSSL_SUCCESS);
  85329. /* override URL to avoid exing from SendCertificateStatus because of no AuthInfo on the certificate */
  85330. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx_s, "http://dummy.test"), WOLFSSL_SUCCESS);
  85331. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx_s, WOLFSSL_OCSP_NO_NONCE | WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  85332. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, caCertFile, 0), WOLFSSL_SUCCESS);
  85333. ExpectIntEQ(wolfSSL_SetOCSP_Cb(ssl_s, test_ocsp_callback_fails_cb, NULL, NULL), WOLFSSL_SUCCESS);
  85334. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), -1);
  85335. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WC_NO_ERR_TRACE(OCSP_INVALID_STATUS));
  85336. wolfSSL_free(ssl_c);
  85337. wolfSSL_free(ssl_s);
  85338. wolfSSL_CTX_free(ctx_c);
  85339. wolfSSL_CTX_free(ctx_s);
  85340. return EXPECT_RESULT();
  85341. }
  85342. #else
  85343. static int test_ocsp_callback_fails(void)
  85344. {
  85345. return TEST_SKIPPED;
  85346. }
  85347. #endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85348. defined(HAVE_OCSP) && \
  85349. defined(HAVE_CERTIFICATE_STATUS_REQUEST) */
  85350. /*----------------------------------------------------------------------------*
  85351. | Main
  85352. *----------------------------------------------------------------------------*/
  85353. typedef int (*TEST_FUNC)(void);
  85354. typedef struct {
  85355. const char *name;
  85356. TEST_FUNC func;
  85357. byte run:1;
  85358. byte fail:1;
  85359. } TEST_CASE;
  85360. #define TEST_DECL(func) { #func, func, 0, 0 }
  85361. int testAll = 1;
  85362. TEST_CASE testCases[] = {
  85363. TEST_DECL(test_fileAccess),
  85364. /*********************************
  85365. * wolfcrypt
  85366. *********************************/
  85367. TEST_DECL(test_ForceZero),
  85368. TEST_DECL(test_wolfCrypt_Init),
  85369. TEST_DECL(test_wc_LoadStaticMemory_ex),
  85370. /* Locking with Compat Mutex */
  85371. TEST_DECL(test_wc_SetMutexCb),
  85372. TEST_DECL(test_wc_LockMutex_ex),
  85373. /* Digests */
  85374. TEST_DECL(test_wc_InitMd5),
  85375. TEST_DECL(test_wc_Md5Update),
  85376. TEST_DECL(test_wc_Md5Final),
  85377. TEST_DECL(test_wc_InitSha),
  85378. TEST_DECL(test_wc_ShaUpdate),
  85379. TEST_DECL(test_wc_ShaFinal),
  85380. TEST_DECL(test_wc_InitSha256),
  85381. TEST_DECL(test_wc_Sha256Update),
  85382. TEST_DECL(test_wc_Sha256Final),
  85383. TEST_DECL(test_wc_Sha256FinalRaw),
  85384. TEST_DECL(test_wc_Sha256GetFlags),
  85385. TEST_DECL(test_wc_Sha256Free),
  85386. TEST_DECL(test_wc_Sha256GetHash),
  85387. TEST_DECL(test_wc_Sha256Copy),
  85388. TEST_DECL(test_wc_InitSha224),
  85389. TEST_DECL(test_wc_Sha224Update),
  85390. TEST_DECL(test_wc_Sha224Final),
  85391. TEST_DECL(test_wc_Sha224SetFlags),
  85392. TEST_DECL(test_wc_Sha224GetFlags),
  85393. TEST_DECL(test_wc_Sha224Free),
  85394. TEST_DECL(test_wc_Sha224GetHash),
  85395. TEST_DECL(test_wc_Sha224Copy),
  85396. TEST_DECL(test_wc_InitSha512),
  85397. TEST_DECL(test_wc_Sha512Update),
  85398. TEST_DECL(test_wc_Sha512Final),
  85399. TEST_DECL(test_wc_Sha512GetFlags),
  85400. TEST_DECL(test_wc_Sha512FinalRaw),
  85401. TEST_DECL(test_wc_Sha512Free),
  85402. TEST_DECL(test_wc_Sha512GetHash),
  85403. TEST_DECL(test_wc_Sha512Copy),
  85404. TEST_DECL(test_wc_InitSha512_224),
  85405. TEST_DECL(test_wc_Sha512_224Update),
  85406. TEST_DECL(test_wc_Sha512_224Final),
  85407. TEST_DECL(test_wc_Sha512_224GetFlags),
  85408. TEST_DECL(test_wc_Sha512_224FinalRaw),
  85409. TEST_DECL(test_wc_Sha512_224Free),
  85410. TEST_DECL(test_wc_Sha512_224GetHash),
  85411. TEST_DECL(test_wc_Sha512_224Copy),
  85412. TEST_DECL(test_wc_InitSha512_256),
  85413. TEST_DECL(test_wc_Sha512_256Update),
  85414. TEST_DECL(test_wc_Sha512_256Final),
  85415. TEST_DECL(test_wc_Sha512_256GetFlags),
  85416. TEST_DECL(test_wc_Sha512_256FinalRaw),
  85417. TEST_DECL(test_wc_Sha512_256Free),
  85418. TEST_DECL(test_wc_Sha512_256GetHash),
  85419. TEST_DECL(test_wc_Sha512_256Copy),
  85420. TEST_DECL(test_wc_InitSha384),
  85421. TEST_DECL(test_wc_Sha384Update),
  85422. TEST_DECL(test_wc_Sha384Final),
  85423. TEST_DECL(test_wc_Sha384GetFlags),
  85424. TEST_DECL(test_wc_Sha384FinalRaw),
  85425. TEST_DECL(test_wc_Sha384Free),
  85426. TEST_DECL(test_wc_Sha384GetHash),
  85427. TEST_DECL(test_wc_Sha384Copy),
  85428. TEST_DECL(test_wc_InitBlake2b),
  85429. TEST_DECL(test_wc_InitBlake2b_WithKey),
  85430. TEST_DECL(test_wc_InitBlake2s_WithKey),
  85431. TEST_DECL(test_wc_InitRipeMd),
  85432. TEST_DECL(test_wc_RipeMdUpdate),
  85433. TEST_DECL(test_wc_RipeMdFinal),
  85434. TEST_DECL(test_wc_InitSha3),
  85435. TEST_DECL(testing_wc_Sha3_Update),
  85436. TEST_DECL(test_wc_Sha3_224_Final),
  85437. TEST_DECL(test_wc_Sha3_256_Final),
  85438. TEST_DECL(test_wc_Sha3_384_Final),
  85439. TEST_DECL(test_wc_Sha3_512_Final),
  85440. TEST_DECL(test_wc_Sha3_224_Copy),
  85441. TEST_DECL(test_wc_Sha3_256_Copy),
  85442. TEST_DECL(test_wc_Sha3_384_Copy),
  85443. TEST_DECL(test_wc_Sha3_512_Copy),
  85444. TEST_DECL(test_wc_Sha3_GetFlags),
  85445. TEST_DECL(test_wc_InitShake256),
  85446. TEST_DECL(testing_wc_Shake256_Update),
  85447. TEST_DECL(test_wc_Shake256_Final),
  85448. TEST_DECL(test_wc_Shake256_Copy),
  85449. TEST_DECL(test_wc_Shake256Hash),
  85450. /* SM3 Digest */
  85451. TEST_DECL(test_wc_InitSm3Free),
  85452. TEST_DECL(test_wc_Sm3UpdateFinal),
  85453. TEST_DECL(test_wc_Sm3GetHash),
  85454. TEST_DECL(test_wc_Sm3Copy),
  85455. TEST_DECL(test_wc_Sm3FinalRaw),
  85456. TEST_DECL(test_wc_Sm3GetSetFlags),
  85457. TEST_DECL(test_wc_Sm3Hash),
  85458. TEST_DECL(test_wc_HashInit),
  85459. TEST_DECL(test_wc_HashSetFlags),
  85460. TEST_DECL(test_wc_HashGetFlags),
  85461. /* HMAC */
  85462. TEST_DECL(test_wc_Md5HmacSetKey),
  85463. TEST_DECL(test_wc_Md5HmacUpdate),
  85464. TEST_DECL(test_wc_Md5HmacFinal),
  85465. TEST_DECL(test_wc_ShaHmacSetKey),
  85466. TEST_DECL(test_wc_ShaHmacUpdate),
  85467. TEST_DECL(test_wc_ShaHmacFinal),
  85468. TEST_DECL(test_wc_Sha224HmacSetKey),
  85469. TEST_DECL(test_wc_Sha224HmacUpdate),
  85470. TEST_DECL(test_wc_Sha224HmacFinal),
  85471. TEST_DECL(test_wc_Sha256HmacSetKey),
  85472. TEST_DECL(test_wc_Sha256HmacUpdate),
  85473. TEST_DECL(test_wc_Sha256HmacFinal),
  85474. TEST_DECL(test_wc_Sha384HmacSetKey),
  85475. TEST_DECL(test_wc_Sha384HmacUpdate),
  85476. TEST_DECL(test_wc_Sha384HmacFinal),
  85477. /* CMAC */
  85478. TEST_DECL(test_wc_InitCmac),
  85479. TEST_DECL(test_wc_CmacUpdate),
  85480. TEST_DECL(test_wc_CmacFinal),
  85481. TEST_DECL(test_wc_AesCmacGenerate),
  85482. /* Cipher */
  85483. TEST_DECL(test_wc_AesGcmStream),
  85484. TEST_DECL(test_wc_Des3_SetIV),
  85485. TEST_DECL(test_wc_Des3_SetKey),
  85486. TEST_DECL(test_wc_Des3_CbcEncryptDecrypt),
  85487. TEST_DECL(test_wc_Des3_CbcEncryptDecryptWithKey),
  85488. TEST_DECL(test_wc_Des3_EcbEncrypt),
  85489. TEST_DECL(test_wc_Chacha_SetKey),
  85490. TEST_DECL(test_wc_Chacha_Process),
  85491. TEST_DECL(test_wc_ChaCha20Poly1305_aead),
  85492. TEST_DECL(test_wc_Poly1305SetKey),
  85493. TEST_DECL(test_wc_CamelliaSetKey),
  85494. TEST_DECL(test_wc_CamelliaSetIV),
  85495. TEST_DECL(test_wc_CamelliaEncryptDecryptDirect),
  85496. TEST_DECL(test_wc_CamelliaCbcEncryptDecrypt),
  85497. TEST_DECL(test_wc_Arc4SetKey),
  85498. TEST_DECL(test_wc_Arc4Process),
  85499. TEST_DECL(test_wc_Rc2SetKey),
  85500. TEST_DECL(test_wc_Rc2SetIV),
  85501. TEST_DECL(test_wc_Rc2EcbEncryptDecrypt),
  85502. TEST_DECL(test_wc_Rc2CbcEncryptDecrypt),
  85503. /* AES cipher and GMAC. */
  85504. TEST_DECL(test_wc_AesSetKey),
  85505. TEST_DECL(test_wc_AesSetIV),
  85506. TEST_DECL(test_wc_AesCbcEncryptDecrypt),
  85507. TEST_DECL(test_wc_AesCtrEncryptDecrypt),
  85508. TEST_DECL(test_wc_AesGcmSetKey),
  85509. TEST_DECL(test_wc_AesGcmEncryptDecrypt),
  85510. TEST_DECL(test_wc_AesGcmMixedEncDecLongIV),
  85511. TEST_DECL(test_wc_GmacSetKey),
  85512. TEST_DECL(test_wc_GmacUpdate),
  85513. TEST_DECL(test_wc_AesCcmSetKey),
  85514. TEST_DECL(test_wc_AesCcmEncryptDecrypt),
  85515. #if defined(WOLFSSL_AES_EAX) && \
  85516. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  85517. TEST_DECL(test_wc_AesEaxVectors),
  85518. TEST_DECL(test_wc_AesEaxEncryptAuth),
  85519. TEST_DECL(test_wc_AesEaxDecryptAuth),
  85520. #endif /* WOLFSSL_AES_EAX */
  85521. /* SM4 cipher */
  85522. TEST_DECL(test_wc_Sm4),
  85523. TEST_DECL(test_wc_Sm4Ecb),
  85524. TEST_DECL(test_wc_Sm4Cbc),
  85525. TEST_DECL(test_wc_Sm4Ctr),
  85526. TEST_DECL(test_wc_Sm4Gcm),
  85527. TEST_DECL(test_wc_Sm4Ccm),
  85528. /* RNG tests */
  85529. #ifdef HAVE_HASHDRBG
  85530. #ifdef TEST_RESEED_INTERVAL
  85531. TEST_DECL(test_wc_RNG_GenerateBlock_Reseed),
  85532. #endif
  85533. TEST_DECL(test_wc_RNG_GenerateBlock),
  85534. #endif
  85535. TEST_DECL(test_get_rand_digit),
  85536. TEST_DECL(test_wc_InitRngNonce),
  85537. TEST_DECL(test_wc_InitRngNonce_ex),
  85538. /* MP API tests */
  85539. TEST_DECL(test_get_digit_count),
  85540. TEST_DECL(test_mp_cond_copy),
  85541. TEST_DECL(test_mp_rand),
  85542. TEST_DECL(test_get_digit),
  85543. TEST_DECL(test_wc_export_int),
  85544. /* RSA */
  85545. TEST_DECL(test_wc_InitRsaKey),
  85546. TEST_DECL(test_wc_RsaPrivateKeyDecode),
  85547. TEST_DECL(test_wc_RsaPublicKeyDecode),
  85548. TEST_DECL(test_wc_RsaPublicKeyDecodeRaw),
  85549. TEST_DECL(test_wc_RsaPrivateKeyDecodeRaw),
  85550. TEST_DECL(test_wc_MakeRsaKey),
  85551. TEST_DECL(test_wc_CheckProbablePrime),
  85552. TEST_DECL(test_wc_RsaPSS_Verify),
  85553. TEST_DECL(test_wc_RsaPSS_VerifyCheck),
  85554. TEST_DECL(test_wc_RsaPSS_VerifyCheckInline),
  85555. TEST_DECL(test_wc_RsaKeyToDer),
  85556. TEST_DECL(test_wc_RsaKeyToPublicDer),
  85557. TEST_DECL(test_wc_RsaPublicEncryptDecrypt),
  85558. TEST_DECL(test_wc_RsaPublicEncryptDecrypt_ex),
  85559. TEST_DECL(test_wc_RsaEncryptSize),
  85560. TEST_DECL(test_wc_RsaSSL_SignVerify),
  85561. TEST_DECL(test_wc_RsaFlattenPublicKey),
  85562. TEST_DECL(test_RsaDecryptBoundsCheck),
  85563. /* DSA */
  85564. TEST_DECL(test_wc_InitDsaKey),
  85565. TEST_DECL(test_wc_DsaSignVerify),
  85566. TEST_DECL(test_wc_DsaPublicPrivateKeyDecode),
  85567. TEST_DECL(test_wc_MakeDsaKey),
  85568. TEST_DECL(test_wc_DsaKeyToDer),
  85569. TEST_DECL(test_wc_DsaKeyToPublicDer),
  85570. TEST_DECL(test_wc_DsaImportParamsRaw),
  85571. TEST_DECL(test_wc_DsaImportParamsRawCheck),
  85572. TEST_DECL(test_wc_DsaExportParamsRaw),
  85573. TEST_DECL(test_wc_DsaExportKeyRaw),
  85574. /* DH */
  85575. TEST_DECL(test_wc_DhPublicKeyDecode),
  85576. /* wolfCrypt ECC tests */
  85577. TEST_DECL(test_wc_ecc_get_curve_size_from_name),
  85578. TEST_DECL(test_wc_ecc_get_curve_id_from_name),
  85579. TEST_DECL(test_wc_ecc_get_curve_id_from_params),
  85580. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  85581. !defined(HAVE_SELFTEST) && \
  85582. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  85583. TEST_DECL(test_wc_ecc_get_curve_id_from_dp_params),
  85584. #endif
  85585. TEST_DECL(test_wc_ecc_make_key),
  85586. TEST_DECL(test_wc_ecc_init),
  85587. TEST_DECL(test_wc_ecc_check_key),
  85588. TEST_DECL(test_wc_ecc_get_generator),
  85589. TEST_DECL(test_wc_ecc_size),
  85590. TEST_DECL(test_wc_ecc_params),
  85591. TEST_DECL(test_wc_ecc_signVerify_hash),
  85592. TEST_DECL(test_wc_ecc_shared_secret),
  85593. TEST_DECL(test_wc_ecc_export_x963),
  85594. TEST_DECL(test_wc_ecc_export_x963_ex),
  85595. TEST_DECL(test_wc_ecc_import_x963),
  85596. TEST_DECL(test_wc_ecc_import_private_key),
  85597. TEST_DECL(test_wc_ecc_export_private_only),
  85598. TEST_DECL(test_wc_ecc_rs_to_sig),
  85599. TEST_DECL(test_wc_ecc_import_raw),
  85600. TEST_DECL(test_wc_ecc_import_unsigned),
  85601. TEST_DECL(test_wc_ecc_sig_size),
  85602. TEST_DECL(test_wc_ecc_ctx_new),
  85603. TEST_DECL(test_wc_ecc_ctx_reset),
  85604. TEST_DECL(test_wc_ecc_ctx_set_peer_salt),
  85605. TEST_DECL(test_wc_ecc_ctx_set_info),
  85606. TEST_DECL(test_wc_ecc_encryptDecrypt),
  85607. TEST_DECL(test_wc_ecc_del_point),
  85608. TEST_DECL(test_wc_ecc_pointFns),
  85609. TEST_DECL(test_wc_ecc_shared_secret_ssh),
  85610. TEST_DECL(test_wc_ecc_verify_hash_ex),
  85611. TEST_DECL(test_wc_ecc_mulmod),
  85612. TEST_DECL(test_wc_ecc_is_valid_idx),
  85613. TEST_DECL(test_wc_ecc_get_curve_id_from_oid),
  85614. TEST_DECL(test_wc_ecc_sig_size_calc),
  85615. TEST_DECL(test_wc_EccPrivateKeyToDer),
  85616. /* SM2 elliptic curve */
  85617. TEST_DECL(test_wc_ecc_sm2_make_key),
  85618. TEST_DECL(test_wc_ecc_sm2_shared_secret),
  85619. TEST_DECL(test_wc_ecc_sm2_create_digest),
  85620. TEST_DECL(test_wc_ecc_sm2_verify_hash_ex),
  85621. TEST_DECL(test_wc_ecc_sm2_verify_hash),
  85622. TEST_DECL(test_wc_ecc_sm2_sign_hash_ex),
  85623. TEST_DECL(test_wc_ecc_sm2_sign_hash),
  85624. /* Curve25519 */
  85625. TEST_DECL(test_wc_curve25519_init),
  85626. TEST_DECL(test_wc_curve25519_size),
  85627. TEST_DECL(test_wc_curve25519_export_key_raw),
  85628. TEST_DECL(test_wc_curve25519_export_key_raw_ex),
  85629. TEST_DECL(test_wc_curve25519_make_key),
  85630. TEST_DECL(test_wc_curve25519_shared_secret_ex),
  85631. TEST_DECL(test_wc_curve25519_make_pub),
  85632. TEST_DECL(test_wc_curve25519_export_public_ex),
  85633. TEST_DECL(test_wc_curve25519_export_private_raw_ex),
  85634. TEST_DECL(test_wc_curve25519_import_private_raw_ex),
  85635. TEST_DECL(test_wc_curve25519_import_private),
  85636. /* ED25519 */
  85637. TEST_DECL(test_wc_ed25519_make_key),
  85638. TEST_DECL(test_wc_ed25519_init),
  85639. TEST_DECL(test_wc_ed25519_sign_msg),
  85640. TEST_DECL(test_wc_ed25519_import_public),
  85641. TEST_DECL(test_wc_ed25519_import_private_key),
  85642. TEST_DECL(test_wc_ed25519_export),
  85643. TEST_DECL(test_wc_ed25519_size),
  85644. TEST_DECL(test_wc_ed25519_exportKey),
  85645. TEST_DECL(test_wc_Ed25519PublicKeyToDer),
  85646. TEST_DECL(test_wc_Ed25519KeyToDer),
  85647. TEST_DECL(test_wc_Ed25519PrivateKeyToDer),
  85648. /* Curve448 */
  85649. TEST_DECL(test_wc_curve448_make_key),
  85650. TEST_DECL(test_wc_curve448_shared_secret_ex),
  85651. TEST_DECL(test_wc_curve448_export_public_ex),
  85652. TEST_DECL(test_wc_curve448_export_private_raw_ex),
  85653. TEST_DECL(test_wc_curve448_export_key_raw),
  85654. TEST_DECL(test_wc_curve448_import_private_raw_ex),
  85655. TEST_DECL(test_wc_curve448_import_private),
  85656. TEST_DECL(test_wc_curve448_init),
  85657. TEST_DECL(test_wc_curve448_size),
  85658. /* Ed448 */
  85659. TEST_DECL(test_wc_ed448_make_key),
  85660. TEST_DECL(test_wc_ed448_init),
  85661. TEST_DECL(test_wc_ed448_sign_msg),
  85662. TEST_DECL(test_wc_ed448_import_public),
  85663. TEST_DECL(test_wc_ed448_import_private_key),
  85664. TEST_DECL(test_wc_ed448_export),
  85665. TEST_DECL(test_wc_ed448_size),
  85666. TEST_DECL(test_wc_ed448_exportKey),
  85667. TEST_DECL(test_wc_Ed448PublicKeyToDer),
  85668. TEST_DECL(test_wc_Ed448KeyToDer),
  85669. TEST_DECL(test_wc_Ed448PrivateKeyToDer),
  85670. TEST_DECL(test_wc_Curve448PrivateKeyToDer),
  85671. /* Kyber */
  85672. TEST_DECL(test_wc_kyber_make_key_kats),
  85673. TEST_DECL(test_wc_kyber_encapsulate_kats),
  85674. TEST_DECL(test_wc_kyber_decapsulate_kats),
  85675. /* Dilithium */
  85676. TEST_DECL(test_wc_dilithium),
  85677. TEST_DECL(test_wc_dilithium_make_key),
  85678. TEST_DECL(test_wc_dilithium_sign),
  85679. TEST_DECL(test_wc_dilithium_verify),
  85680. TEST_DECL(test_wc_dilithium_sign_vfy),
  85681. TEST_DECL(test_wc_dilithium_check_key),
  85682. TEST_DECL(test_wc_dilithium_public_der_decode),
  85683. TEST_DECL(test_wc_dilithium_der),
  85684. TEST_DECL(test_wc_dilithium_make_key_from_seed),
  85685. TEST_DECL(test_wc_dilithium_sig_kats),
  85686. TEST_DECL(test_wc_dilithium_verify_kats),
  85687. /* Signature API */
  85688. TEST_DECL(test_wc_SignatureGetSize_ecc),
  85689. TEST_DECL(test_wc_SignatureGetSize_rsa),
  85690. /* PEM and DER APIs. */
  85691. TEST_DECL(test_wc_PemToDer),
  85692. TEST_DECL(test_wc_AllocDer),
  85693. TEST_DECL(test_wc_CertPemToDer),
  85694. TEST_DECL(test_wc_KeyPemToDer),
  85695. TEST_DECL(test_wc_PubKeyPemToDer),
  85696. TEST_DECL(test_wc_PemPubKeyToDer),
  85697. TEST_DECL(test_wc_GetPubKeyDerFromCert),
  85698. TEST_DECL(test_wc_CheckCertSigPubKey),
  85699. /* wolfCrypt ASN tests */
  85700. TEST_DECL(test_ToTraditional),
  85701. TEST_DECL(test_wc_CreateEncryptedPKCS8Key),
  85702. TEST_DECL(test_wc_GetPkcs8TraditionalOffset),
  85703. /* Certificate */
  85704. TEST_DECL(test_wc_SetSubjectRaw),
  85705. TEST_DECL(test_wc_GetSubjectRaw),
  85706. TEST_DECL(test_wc_SetIssuerRaw),
  85707. TEST_DECL(test_wc_SetIssueBuffer),
  85708. TEST_DECL(test_wc_SetSubjectKeyId),
  85709. TEST_DECL(test_wc_SetSubject),
  85710. TEST_DECL(test_CheckCertSignature),
  85711. TEST_DECL(test_wc_ParseCert),
  85712. TEST_DECL(test_wc_ParseCert_Error),
  85713. TEST_DECL(test_MakeCertWithPathLen),
  85714. TEST_DECL(test_MakeCertWith0Ser),
  85715. TEST_DECL(test_MakeCertWithCaFalse),
  85716. TEST_DECL(test_wc_SetKeyUsage),
  85717. TEST_DECL(test_wc_SetAuthKeyIdFromPublicKey_ex),
  85718. TEST_DECL(test_wc_SetSubjectBuffer),
  85719. TEST_DECL(test_wc_SetSubjectKeyIdFromPublicKey_ex),
  85720. /* wolfcrypt PKCS#7 */
  85721. TEST_DECL(test_wc_PKCS7_New),
  85722. TEST_DECL(test_wc_PKCS7_Init),
  85723. TEST_DECL(test_wc_PKCS7_InitWithCert),
  85724. TEST_DECL(test_wc_PKCS7_EncodeData),
  85725. TEST_DECL(test_wc_PKCS7_EncodeSignedData),
  85726. TEST_DECL(test_wc_PKCS7_EncodeSignedData_ex),
  85727. TEST_DECL(test_wc_PKCS7_VerifySignedData_RSA),
  85728. TEST_DECL(test_wc_PKCS7_VerifySignedData_ECC),
  85729. TEST_DECL(test_wc_PKCS7_EncodeDecodeEnvelopedData),
  85730. TEST_DECL(test_wc_PKCS7_EncodeEncryptedData),
  85731. TEST_DECL(test_wc_PKCS7_Degenerate),
  85732. TEST_DECL(test_wc_PKCS7_BER),
  85733. TEST_DECL(test_wc_PKCS7_signed_enveloped),
  85734. TEST_DECL(test_wc_PKCS7_NoDefaultSignedAttribs),
  85735. TEST_DECL(test_wc_PKCS7_SetOriEncryptCtx),
  85736. TEST_DECL(test_wc_PKCS7_SetOriDecryptCtx),
  85737. TEST_DECL(test_wc_PKCS7_DecodeCompressedData),
  85738. /* wolfCrypt PKCS#12 */
  85739. TEST_DECL(test_wc_i2d_PKCS12),
  85740. /*
  85741. * test_wolfCrypt_Cleanup needs to come after the above wolfCrypt tests to
  85742. * avoid memory leaks.
  85743. */
  85744. TEST_DECL(test_wolfCrypt_Cleanup),
  85745. TEST_DECL(test_wolfSSL_Init),
  85746. TEST_DECL(test_dual_alg_support),
  85747. /*********************************
  85748. * OpenSSL compatibility API tests
  85749. *********************************/
  85750. /* If at some point a stub get implemented this test should fail indicating
  85751. * a need to implement a new test case
  85752. */
  85753. TEST_DECL(test_stubs_are_stubs),
  85754. /* ASN.1 compatibility API tests */
  85755. TEST_DECL(test_wolfSSL_ASN1_BIT_STRING),
  85756. TEST_DECL(test_wolfSSL_ASN1_INTEGER),
  85757. TEST_DECL(test_wolfSSL_ASN1_INTEGER_cmp),
  85758. TEST_DECL(test_wolfSSL_ASN1_INTEGER_BN),
  85759. TEST_DECL(test_wolfSSL_ASN1_INTEGER_get_set),
  85760. TEST_DECL(test_wolfSSL_d2i_ASN1_INTEGER),
  85761. TEST_DECL(test_wolfSSL_a2i_ASN1_INTEGER),
  85762. TEST_DECL(test_wolfSSL_i2c_ASN1_INTEGER),
  85763. TEST_DECL(test_wolfSSL_ASN1_OBJECT),
  85764. TEST_DECL(test_wolfSSL_ASN1_get_object),
  85765. TEST_DECL(test_wolfSSL_i2a_ASN1_OBJECT),
  85766. TEST_DECL(test_wolfSSL_i2t_ASN1_OBJECT),
  85767. TEST_DECL(test_wolfSSL_sk_ASN1_OBJECT),
  85768. TEST_DECL(test_wolfSSL_ASN1_STRING),
  85769. TEST_DECL(test_wolfSSL_ASN1_STRING_to_UTF8),
  85770. TEST_DECL(test_wolfSSL_i2s_ASN1_STRING),
  85771. TEST_DECL(test_wolfSSL_ASN1_STRING_canon),
  85772. TEST_DECL(test_wolfSSL_ASN1_STRING_print),
  85773. TEST_DECL(test_wolfSSL_ASN1_STRING_print_ex),
  85774. TEST_DECL(test_wolfSSL_ASN1_UNIVERSALSTRING_to_string),
  85775. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_free),
  85776. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_print),
  85777. TEST_DECL(test_wolfSSL_ASN1_TIME),
  85778. TEST_DECL(test_wolfSSL_ASN1_TIME_to_string),
  85779. TEST_DECL(test_wolfSSL_ASN1_TIME_diff_compare),
  85780. TEST_DECL(test_wolfSSL_ASN1_TIME_adj),
  85781. TEST_DECL(test_wolfSSL_ASN1_TIME_to_tm),
  85782. TEST_DECL(test_wolfSSL_ASN1_TIME_to_generalizedtime),
  85783. TEST_DECL(test_wolfSSL_ASN1_TIME_print),
  85784. TEST_DECL(test_wolfSSL_ASN1_UTCTIME_print),
  85785. TEST_DECL(test_wolfSSL_ASN1_TYPE),
  85786. TEST_DECL(test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS),
  85787. TEST_DECL(test_wolfSSL_i2d_ASN1_TYPE),
  85788. TEST_DECL(test_wolfSSL_i2d_ASN1_SEQUENCE),
  85789. TEST_DECL(test_ASN1_strings),
  85790. TEST_DECL(test_wolfSSL_lhash),
  85791. TEST_DECL(test_wolfSSL_certs),
  85792. TEST_DECL(test_wolfSSL_private_keys),
  85793. TEST_DECL(test_wolfSSL_PEM_def_callback),
  85794. TEST_DECL(test_wolfSSL_PEM_read_PrivateKey),
  85795. TEST_DECL(test_wolfSSL_PEM_read_RSA_PUBKEY),
  85796. TEST_DECL(test_wolfSSL_PEM_read_PUBKEY),
  85797. TEST_DECL(test_wolfSSL_PEM_PrivateKey_rsa),
  85798. TEST_DECL(test_wolfSSL_PEM_PrivateKey_ecc),
  85799. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dsa),
  85800. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dh),
  85801. TEST_DECL(test_wolfSSL_PEM_PrivateKey),
  85802. TEST_DECL(test_wolfSSL_PEM_file_RSAKey),
  85803. TEST_DECL(test_wolfSSL_PEM_file_RSAPrivateKey),
  85804. #ifndef NO_BIO
  85805. TEST_DECL(test_wolfSSL_BIO),
  85806. TEST_DECL(test_wolfSSL_BIO_BIO_ring_read),
  85807. TEST_DECL(test_wolfSSL_PEM_read_bio),
  85808. TEST_DECL(test_wolfSSL_PEM_bio_RSAKey),
  85809. TEST_DECL(test_wolfSSL_PEM_bio_DSAKey),
  85810. TEST_DECL(test_wolfSSL_PEM_bio_ECKey),
  85811. TEST_DECL(test_wolfSSL_PEM_bio_RSAPrivateKey),
  85812. TEST_DECL(test_wolfSSL_PEM_PUBKEY),
  85813. #endif
  85814. /* EVP API testing */
  85815. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_new),
  85816. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_free),
  85817. TEST_DECL(test_wolfSSL_EVP_EncodeInit),
  85818. TEST_DECL(test_wolfSSL_EVP_EncodeUpdate),
  85819. TEST_DECL(test_wolfSSL_EVP_EncodeFinal),
  85820. TEST_DECL(test_wolfSSL_EVP_DecodeInit),
  85821. TEST_DECL(test_wolfSSL_EVP_DecodeUpdate),
  85822. TEST_DECL(test_wolfSSL_EVP_DecodeFinal),
  85823. TEST_DECL(test_wolfSSL_EVP_shake128),
  85824. TEST_DECL(test_wolfSSL_EVP_shake256),
  85825. TEST_DECL(test_wolfSSL_EVP_sm3),
  85826. TEST_DECL(test_EVP_blake2),
  85827. #ifdef OPENSSL_ALL
  85828. TEST_DECL(test_wolfSSL_EVP_md4),
  85829. TEST_DECL(test_wolfSSL_EVP_ripemd160),
  85830. TEST_DECL(test_wolfSSL_EVP_get_digestbynid),
  85831. TEST_DECL(test_wolfSSL_EVP_MD_nid),
  85832. TEST_DECL(test_wolfSSL_EVP_DigestFinal_ex),
  85833. #endif
  85834. TEST_DECL(test_EVP_MD_do_all),
  85835. TEST_DECL(test_wolfSSL_EVP_MD_size),
  85836. TEST_DECL(test_wolfSSL_EVP_MD_pkey_type),
  85837. TEST_DECL(test_wolfSSL_EVP_Digest),
  85838. TEST_DECL(test_wolfSSL_EVP_Digest_all),
  85839. TEST_DECL(test_wolfSSL_EVP_MD_hmac_signing),
  85840. TEST_DECL(test_wolfSSL_EVP_MD_rsa_signing),
  85841. TEST_DECL(test_wolfSSL_EVP_MD_ecc_signing),
  85842. TEST_DECL(test_wolfssl_EVP_aes_gcm),
  85843. TEST_DECL(test_wolfssl_EVP_aes_gcm_AAD_2_parts),
  85844. TEST_DECL(test_wolfssl_EVP_aes_gcm_zeroLen),
  85845. TEST_DECL(test_wolfssl_EVP_aes_ccm),
  85846. TEST_DECL(test_wolfssl_EVP_aes_ccm_zeroLen),
  85847. TEST_DECL(test_wolfssl_EVP_chacha20),
  85848. TEST_DECL(test_wolfssl_EVP_chacha20_poly1305),
  85849. TEST_DECL(test_wolfssl_EVP_sm4_ecb),
  85850. TEST_DECL(test_wolfssl_EVP_sm4_cbc),
  85851. TEST_DECL(test_wolfssl_EVP_sm4_ctr),
  85852. TEST_DECL(test_wolfssl_EVP_sm4_gcm_zeroLen),
  85853. TEST_DECL(test_wolfssl_EVP_sm4_gcm),
  85854. TEST_DECL(test_wolfssl_EVP_sm4_ccm_zeroLen),
  85855. TEST_DECL(test_wolfssl_EVP_sm4_ccm),
  85856. #ifdef OPENSSL_ALL
  85857. TEST_DECL(test_wolfSSL_EVP_aes_256_gcm),
  85858. TEST_DECL(test_wolfSSL_EVP_aes_192_gcm),
  85859. TEST_DECL(test_wolfSSL_EVP_aes_256_ccm),
  85860. TEST_DECL(test_wolfSSL_EVP_aes_192_ccm),
  85861. TEST_DECL(test_wolfSSL_EVP_aes_128_ccm),
  85862. TEST_DECL(test_wolfSSL_EVP_rc4),
  85863. TEST_DECL(test_wolfSSL_EVP_enc_null),
  85864. TEST_DECL(test_wolfSSL_EVP_rc2_cbc),
  85865. TEST_DECL(test_wolfSSL_EVP_mdc2),
  85866. TEST_DECL(test_evp_cipher_aes_gcm),
  85867. #endif
  85868. TEST_DECL(test_wolfssl_EVP_aria_gcm),
  85869. TEST_DECL(test_wolfSSL_EVP_Cipher_extra),
  85870. #ifdef OPENSSL_EXTRA
  85871. TEST_DECL(test_wolfSSL_EVP_get_cipherbynid),
  85872. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX),
  85873. #endif
  85874. #ifdef OPENSSL_ALL
  85875. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_iv_length),
  85876. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_key_length),
  85877. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_set_iv),
  85878. TEST_DECL(test_wolfSSL_EVP_CIPHER_block_size),
  85879. TEST_DECL(test_wolfSSL_EVP_CIPHER_iv_length),
  85880. TEST_DECL(test_wolfSSL_EVP_X_STATE),
  85881. TEST_DECL(test_wolfSSL_EVP_X_STATE_LEN),
  85882. TEST_DECL(test_wolfSSL_EVP_BytesToKey),
  85883. #endif
  85884. TEST_DECL(test_wolfSSL_EVP_PKEY_print_public),
  85885. TEST_DECL(test_wolfSSL_EVP_PKEY_new_mac_key),
  85886. TEST_DECL(test_wolfSSL_EVP_PKEY_new_CMAC_key),
  85887. TEST_DECL(test_wolfSSL_EVP_PKEY_up_ref),
  85888. TEST_DECL(test_wolfSSL_EVP_PKEY_hkdf),
  85889. TEST_DECL(test_wolfSSL_EVP_PKEY_derive),
  85890. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey),
  85891. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey_ecc),
  85892. #ifndef NO_BIO
  85893. TEST_DECL(test_wolfSSL_d2i_PUBKEY),
  85894. #endif
  85895. TEST_DECL(test_wolfSSL_d2i_and_i2d_DSAparams),
  85896. TEST_DECL(test_wolfSSL_i2d_PrivateKey),
  85897. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  85898. #ifndef NO_BIO
  85899. TEST_DECL(test_wolfSSL_d2i_PrivateKeys_bio),
  85900. #endif /* !NO_BIO */
  85901. #endif
  85902. #ifdef OPENSSL_ALL
  85903. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DSA),
  85904. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY),
  85905. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DH),
  85906. TEST_DECL(test_wolfSSL_EVP_PKEY_assign),
  85907. TEST_DECL(test_wolfSSL_EVP_PKEY_assign_DH),
  85908. TEST_DECL(test_wolfSSL_EVP_PKEY_base_id),
  85909. TEST_DECL(test_wolfSSL_EVP_PKEY_id),
  85910. TEST_DECL(test_wolfSSL_EVP_PKEY_paramgen),
  85911. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen),
  85912. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen_init),
  85913. TEST_DECL(test_wolfSSL_EVP_PKEY_missing_parameters),
  85914. TEST_DECL(test_wolfSSL_EVP_PKEY_copy_parameters),
  85915. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits),
  85916. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_new_id),
  85917. TEST_DECL(test_wolfSSL_EVP_PKEY_get0_EC_KEY),
  85918. #endif
  85919. TEST_DECL(test_EVP_PKEY_rsa),
  85920. TEST_DECL(test_EVP_PKEY_ec),
  85921. TEST_DECL(test_wolfSSL_EVP_PKEY_encrypt),
  85922. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_rsa),
  85923. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_dsa),
  85924. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_ec),
  85925. TEST_DECL(test_EVP_PKEY_cmp),
  85926. #ifdef OPENSSL_ALL
  85927. TEST_DECL(test_wolfSSL_EVP_SignInit_ex),
  85928. TEST_DECL(test_wolfSSL_EVP_PKEY_param_check),
  85929. TEST_DECL(test_wolfSSL_QT_EVP_PKEY_CTX_free),
  85930. #endif
  85931. TEST_DECL(test_wolfSSL_EVP_PBE_scrypt),
  85932. TEST_DECL(test_wolfSSL_CTX_add_extra_chain_cert),
  85933. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  85934. TEST_DECL(test_wolfSSL_ERR_peek_last_error_line),
  85935. #endif
  85936. #ifndef NO_BIO
  85937. TEST_DECL(test_wolfSSL_ERR_print_errors_cb),
  85938. TEST_DECL(test_wolfSSL_GetLoggingCb),
  85939. TEST_DECL(test_WOLFSSL_ERROR_MSG),
  85940. TEST_DECL(test_wc_ERR_remove_state),
  85941. TEST_DECL(test_wc_ERR_print_errors_fp),
  85942. #endif
  85943. TEST_DECL(test_wolfSSL_configure_args),
  85944. TEST_DECL(test_wolfSSL_sk_SSL_CIPHER),
  85945. TEST_DECL(test_wolfSSL_set1_curves_list),
  85946. TEST_DECL(test_wolfSSL_curves_mismatch),
  85947. TEST_DECL(test_wolfSSL_set1_sigalgs_list),
  85948. TEST_DECL(test_wolfSSL_OtherName),
  85949. TEST_DECL(test_wolfSSL_FPKI),
  85950. TEST_DECL(test_wolfSSL_URI),
  85951. TEST_DECL(test_wolfSSL_TBS),
  85952. TEST_DECL(test_wolfSSL_X509_STORE_CTX),
  85953. TEST_DECL(test_X509_STORE_untrusted),
  85954. TEST_DECL(test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup),
  85955. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_current_issuer),
  85956. TEST_DECL(test_wolfSSL_X509_STORE_set_flags),
  85957. TEST_DECL(test_wolfSSL_X509_LOOKUP_load_file),
  85958. TEST_DECL(test_wolfSSL_X509_Name_canon),
  85959. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_file),
  85960. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_hash_dir),
  85961. TEST_DECL(test_wolfSSL_X509_NID),
  85962. TEST_DECL(test_wolfSSL_X509_STORE_CTX_set_time),
  85963. TEST_DECL(test_wolfSSL_get0_param),
  85964. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_host),
  85965. TEST_DECL(test_wolfSSL_set1_host),
  85966. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_ip),
  85967. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_store),
  85968. TEST_DECL(test_wolfSSL_X509_STORE),
  85969. TEST_DECL(test_wolfSSL_X509_STORE_load_locations),
  85970. TEST_DECL(test_X509_STORE_get0_objects),
  85971. TEST_DECL(test_wolfSSL_X509_load_crl_file),
  85972. TEST_DECL(test_wolfSSL_X509_STORE_get1_certs),
  85973. TEST_DECL(test_wolfSSL_X509_STORE_set_get_crl),
  85974. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY_get_object),
  85975. TEST_DECL(test_wolfSSL_X509_cmp_time),
  85976. TEST_DECL(test_wolfSSL_X509_time_adj),
  85977. /* X509 tests */
  85978. TEST_DECL(test_wolfSSL_X509_subject_name_hash),
  85979. TEST_DECL(test_wolfSSL_X509_issuer_name_hash),
  85980. TEST_DECL(test_wolfSSL_X509_check_host),
  85981. TEST_DECL(test_wolfSSL_X509_check_email),
  85982. TEST_DECL(test_wolfSSL_X509_check_private_key),
  85983. TEST_DECL(test_wolfSSL_X509),
  85984. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM),
  85985. TEST_DECL(test_wolfSSL_X509_sign),
  85986. TEST_DECL(test_wolfSSL_X509_sign2),
  85987. TEST_DECL(test_wolfSSL_X509_verify),
  85988. TEST_DECL(test_wolfSSL_X509_get0_tbs_sigalg),
  85989. TEST_DECL(test_wolfSSL_X509_ALGOR_get0),
  85990. TEST_DECL(test_wolfSSL_X509_get_X509_PUBKEY),
  85991. TEST_DECL(test_wolfSSL_X509_PUBKEY_RSA),
  85992. TEST_DECL(test_wolfSSL_X509_PUBKEY_EC),
  85993. TEST_DECL(test_wolfSSL_X509_PUBKEY_DSA),
  85994. TEST_DECL(test_wolfSSL_PEM_write_bio_X509),
  85995. TEST_DECL(test_wolfSSL_X509_NAME_get_entry),
  85996. TEST_DECL(test_wolfSSL_X509_NAME),
  85997. TEST_DECL(test_wolfSSL_X509_NAME_hash),
  85998. TEST_DECL(test_wolfSSL_X509_NAME_print_ex),
  85999. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY),
  86000. TEST_DECL(test_wolfSSL_X509_set_name),
  86001. TEST_DECL(test_wolfSSL_X509_set_notAfter),
  86002. TEST_DECL(test_wolfSSL_X509_set_notBefore),
  86003. TEST_DECL(test_wolfSSL_X509_set_version),
  86004. TEST_DECL(test_wolfSSL_X509_get_serialNumber),
  86005. TEST_DECL(test_wolfSSL_X509_CRL),
  86006. TEST_DECL(test_wolfSSL_i2d_X509),
  86007. TEST_DECL(test_wolfSSL_d2i_X509_REQ),
  86008. TEST_DECL(test_wolfSSL_PEM_read_X509),
  86009. TEST_DECL(test_wolfSSL_X509_check_ca),
  86010. TEST_DECL(test_wolfSSL_X509_check_ip_asc),
  86011. TEST_DECL(test_wolfSSL_X509_bad_altname),
  86012. TEST_DECL(test_wolfSSL_X509_name_match),
  86013. TEST_DECL(test_wolfSSL_X509_name_match2),
  86014. TEST_DECL(test_wolfSSL_X509_name_match3),
  86015. TEST_DECL(test_wolfSSL_X509_max_altnames),
  86016. TEST_DECL(test_wolfSSL_X509_max_name_constraints),
  86017. TEST_DECL(test_wolfSSL_make_cert),
  86018. #ifndef NO_BIO
  86019. TEST_DECL(test_wolfSSL_X509_INFO_multiple_info),
  86020. TEST_DECL(test_wolfSSL_X509_INFO),
  86021. TEST_DECL(test_wolfSSL_PEM_X509_INFO_read_bio),
  86022. #endif
  86023. #ifdef OPENSSL_ALL
  86024. TEST_DECL(test_wolfSSL_X509_PUBKEY_get),
  86025. #endif
  86026. TEST_DECL(test_wolfSSL_X509_CA_num),
  86027. TEST_DECL(test_x509_get_key_id),
  86028. TEST_DECL(test_wolfSSL_X509_get_version),
  86029. #ifndef NO_BIO
  86030. TEST_DECL(test_wolfSSL_X509_print),
  86031. TEST_DECL(test_wolfSSL_X509_CRL_print),
  86032. #endif
  86033. TEST_DECL(test_X509_get_signature_nid),
  86034. /* X509 extension testing. */
  86035. TEST_DECL(test_wolfSSL_X509_get_extension_flags),
  86036. TEST_DECL(test_wolfSSL_X509_get_ext),
  86037. TEST_DECL(test_wolfSSL_X509_get_ext_by_NID),
  86038. TEST_DECL(test_wolfSSL_X509_get_ext_subj_alt_name),
  86039. TEST_DECL(test_wolfSSL_X509_get_ext_count),
  86040. TEST_DECL(test_wolfSSL_X509_EXTENSION_new),
  86041. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_object),
  86042. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_data),
  86043. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_critical),
  86044. TEST_DECL(test_wolfSSL_X509V3_EXT_get),
  86045. TEST_DECL(test_wolfSSL_X509V3_EXT_nconf),
  86046. TEST_DECL(test_wolfSSL_X509V3_EXT),
  86047. TEST_DECL(test_wolfSSL_X509V3_EXT_print),
  86048. TEST_DECL(test_wolfSSL_X509_cmp),
  86049. TEST_DECL(test_GENERAL_NAME_set0_othername),
  86050. TEST_DECL(test_othername_and_SID_ext),
  86051. TEST_DECL(test_wolfSSL_dup_CA_list),
  86052. /* OpenSSL sk_X509 API test */
  86053. TEST_DECL(test_sk_X509),
  86054. /* OpenSSL sk_X509_CRL API test */
  86055. TEST_DECL(test_sk_X509_CRL),
  86056. /* OpenSSL X509 REQ API test */
  86057. TEST_DECL(test_X509_REQ),
  86058. /* OpenSSL compatibility outside SSL context w/ CRL lookup directory */
  86059. TEST_DECL(test_X509_STORE_No_SSL_CTX),
  86060. TEST_DECL(test_X509_LOOKUP_add_dir),
  86061. /* RAND compatibility API */
  86062. TEST_DECL(test_wolfSSL_RAND_set_rand_method),
  86063. TEST_DECL(test_wolfSSL_RAND_bytes),
  86064. TEST_DECL(test_wolfSSL_RAND),
  86065. /* BN compatibility API */
  86066. TEST_DECL(test_wolfSSL_BN_CTX),
  86067. TEST_DECL(test_wolfSSL_BN),
  86068. TEST_DECL(test_wolfSSL_BN_init),
  86069. TEST_DECL(test_wolfSSL_BN_enc_dec),
  86070. TEST_DECL(test_wolfSSL_BN_word),
  86071. TEST_DECL(test_wolfSSL_BN_bits),
  86072. TEST_DECL(test_wolfSSL_BN_shift),
  86073. TEST_DECL(test_wolfSSL_BN_math),
  86074. TEST_DECL(test_wolfSSL_BN_math_mod),
  86075. TEST_DECL(test_wolfSSL_BN_math_other),
  86076. TEST_DECL(test_wolfSSL_BN_rand),
  86077. TEST_DECL(test_wolfSSL_BN_prime),
  86078. /* OpenSSL PKCS5 API test */
  86079. TEST_DECL(test_wolfSSL_PKCS5),
  86080. /* OpenSSL PKCS8 API test */
  86081. TEST_DECL(test_wolfSSL_PKCS8_Compat),
  86082. TEST_DECL(test_wolfSSL_PKCS8_d2i),
  86083. /* OpenSSL PKCS7 API test */
  86084. TEST_DECL(test_wolfssl_PKCS7),
  86085. TEST_DECL(test_wolfSSL_PKCS7_certs),
  86086. TEST_DECL(test_wolfSSL_PKCS7_sign),
  86087. TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
  86088. #ifndef NO_BIO
  86089. TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
  86090. #ifdef HAVE_SMIME
  86091. TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
  86092. TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
  86093. #endif /* HAVE_SMIME */
  86094. #endif /* !NO_BIO */
  86095. /* OpenSSL PKCS12 API test */
  86096. TEST_DECL(test_wolfSSL_PKCS12),
  86097. /* Can't memory test as callbacks use Assert. */
  86098. TEST_DECL(test_error_queue_per_thread),
  86099. TEST_DECL(test_wolfSSL_ERR_put_error),
  86100. TEST_DECL(test_wolfSSL_ERR_get_error_order),
  86101. #ifndef NO_BIO
  86102. TEST_DECL(test_wolfSSL_ERR_print_errors),
  86103. #endif
  86104. TEST_DECL(test_OBJ_NAME_do_all),
  86105. TEST_DECL(test_wolfSSL_OBJ),
  86106. TEST_DECL(test_wolfSSL_OBJ_cmp),
  86107. TEST_DECL(test_wolfSSL_OBJ_txt2nid),
  86108. TEST_DECL(test_wolfSSL_OBJ_txt2obj),
  86109. #ifdef OPENSSL_ALL
  86110. TEST_DECL(test_wolfSSL_OBJ_ln),
  86111. TEST_DECL(test_wolfSSL_OBJ_sn),
  86112. #endif
  86113. #ifndef NO_BIO
  86114. TEST_DECL(test_wolfSSL_BIO_gets),
  86115. TEST_DECL(test_wolfSSL_BIO_puts),
  86116. TEST_DECL(test_wolfSSL_BIO_dump),
  86117. /* Can't memory test as server hangs. */
  86118. TEST_DECL(test_wolfSSL_BIO_should_retry),
  86119. TEST_DECL(test_wolfSSL_BIO_write),
  86120. TEST_DECL(test_wolfSSL_BIO_printf),
  86121. TEST_DECL(test_wolfSSL_BIO_f_md),
  86122. TEST_DECL(test_wolfSSL_BIO_up_ref),
  86123. TEST_DECL(test_wolfSSL_BIO_reset),
  86124. TEST_DECL(test_wolfSSL_BIO_get_len),
  86125. #endif
  86126. TEST_DECL(test_wolfSSL_check_domain),
  86127. TEST_DECL(test_wolfSSL_cert_cb),
  86128. TEST_DECL(test_wolfSSL_cert_cb_dyn_ciphers),
  86129. TEST_DECL(test_wolfSSL_ciphersuite_auth),
  86130. TEST_DECL(test_wolfSSL_sigalg_info),
  86131. /* Can't memory test as tcp_connect aborts. */
  86132. TEST_DECL(test_wolfSSL_SESSION),
  86133. TEST_DECL(test_wolfSSL_SESSION_expire_downgrade),
  86134. TEST_DECL(test_wolfSSL_CTX_sess_set_remove_cb),
  86135. TEST_DECL(test_wolfSSL_ticket_keys),
  86136. TEST_DECL(test_wolfSSL_sk_GENERAL_NAME),
  86137. TEST_DECL(test_wolfSSL_GENERAL_NAME_print),
  86138. TEST_DECL(test_wolfSSL_sk_DIST_POINT),
  86139. TEST_DECL(test_wolfSSL_verify_mode),
  86140. TEST_DECL(test_wolfSSL_verify_depth),
  86141. TEST_DECL(test_wolfSSL_verify_result),
  86142. TEST_DECL(test_wolfSSL_msg_callback),
  86143. TEST_DECL(test_wolfSSL_OCSP_id_get0_info),
  86144. TEST_DECL(test_wolfSSL_i2d_OCSP_CERTID),
  86145. TEST_DECL(test_wolfSSL_d2i_OCSP_CERTID),
  86146. TEST_DECL(test_wolfSSL_OCSP_id_cmp),
  86147. TEST_DECL(test_wolfSSL_OCSP_SINGLERESP_get0_id),
  86148. TEST_DECL(test_wolfSSL_OCSP_single_get0_status),
  86149. TEST_DECL(test_wolfSSL_OCSP_resp_count),
  86150. TEST_DECL(test_wolfSSL_OCSP_resp_get0),
  86151. TEST_DECL(test_wolfSSL_OCSP_parse_url),
  86152. TEST_DECL(test_wolfSSL_OCSP_REQ_CTX),
  86153. TEST_DECL(test_wolfSSL_PEM_read),
  86154. TEST_DECL(test_wolfSSL_OpenSSL_version),
  86155. TEST_DECL(test_wolfSSL_OpenSSL_add_all_algorithms),
  86156. TEST_DECL(test_wolfSSL_OPENSSL_hexstr2buf),
  86157. TEST_DECL(test_CONF_modules_xxx),
  86158. #ifdef OPENSSL_ALL
  86159. TEST_DECL(test_wolfSSL_TXT_DB),
  86160. TEST_DECL(test_wolfSSL_NCONF),
  86161. #endif
  86162. TEST_DECL(test_wolfSSL_CRYPTO_memcmp),
  86163. TEST_DECL(test_wolfSSL_CRYPTO_get_ex_new_index),
  86164. TEST_DECL(test_wolfSSL_SESSION_get_ex_new_index),
  86165. TEST_DECL(test_CRYPTO_set_dynlock_xxx),
  86166. TEST_DECL(test_CRYPTO_THREADID_xxx),
  86167. TEST_DECL(test_ENGINE_cleanup),
  86168. /* test the no op functions for compatibility */
  86169. TEST_DECL(test_no_op_functions),
  86170. /* OpenSSL error API tests */
  86171. TEST_DECL(test_ERR_load_crypto_strings),
  86172. #ifdef OPENSSL_ALL
  86173. TEST_DECL(test_wolfSSL_sk_CIPHER_description),
  86174. TEST_DECL(test_wolfSSL_get_ciphers_compat),
  86175. TEST_DECL(test_wolfSSL_CTX_ctrl),
  86176. #endif /* OPENSSL_ALL */
  86177. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  86178. TEST_DECL(test_wolfSSL_CTX_use_certificate_ASN1),
  86179. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  86180. /*********************************
  86181. * Crypto API tests
  86182. *********************************/
  86183. TEST_DECL(test_wolfSSL_MD4),
  86184. TEST_DECL(test_wolfSSL_MD5),
  86185. TEST_DECL(test_wolfSSL_MD5_Transform),
  86186. TEST_DECL(test_wolfSSL_SHA),
  86187. TEST_DECL(test_wolfSSL_SHA_Transform),
  86188. TEST_DECL(test_wolfSSL_SHA224),
  86189. TEST_DECL(test_wolfSSL_SHA256),
  86190. TEST_DECL(test_wolfSSL_SHA256_Transform),
  86191. TEST_DECL(test_wolfSSL_SHA512_Transform),
  86192. TEST_DECL(test_wolfSSL_SHA512_224_Transform),
  86193. TEST_DECL(test_wolfSSL_SHA512_256_Transform),
  86194. TEST_DECL(test_wolfSSL_HMAC_CTX),
  86195. TEST_DECL(test_wolfSSL_HMAC),
  86196. TEST_DECL(test_wolfSSL_CMAC),
  86197. TEST_DECL(test_wolfSSL_DES),
  86198. TEST_DECL(test_wolfSSL_DES_ncbc),
  86199. TEST_DECL(test_wolfSSL_DES_ecb_encrypt),
  86200. TEST_DECL(test_wolfSSL_DES_ede3_cbc_encrypt),
  86201. TEST_DECL(test_wolfSSL_AES_encrypt),
  86202. TEST_DECL(test_wolfSSL_AES_ecb_encrypt),
  86203. TEST_DECL(test_wolfSSL_AES_cbc_encrypt),
  86204. TEST_DECL(test_wolfSSL_AES_cfb128_encrypt),
  86205. TEST_DECL(test_wolfSSL_CRYPTO_cts128),
  86206. TEST_DECL(test_wolfSSL_RC4),
  86207. TEST_DECL(test_wolfSSL_RSA),
  86208. TEST_DECL(test_wolfSSL_RSA_DER),
  86209. TEST_DECL(test_wolfSSL_RSA_print),
  86210. TEST_DECL(test_wolfSSL_RSA_padding_add_PKCS1_PSS),
  86211. TEST_DECL(test_wolfSSL_RSA_sign_sha3),
  86212. TEST_DECL(test_wolfSSL_RSA_get0_key),
  86213. TEST_DECL(test_wolfSSL_RSA_meth),
  86214. TEST_DECL(test_wolfSSL_RSA_verify),
  86215. TEST_DECL(test_wolfSSL_RSA_sign),
  86216. TEST_DECL(test_wolfSSL_RSA_sign_ex),
  86217. TEST_DECL(test_wolfSSL_RSA_public_decrypt),
  86218. TEST_DECL(test_wolfSSL_RSA_private_encrypt),
  86219. TEST_DECL(test_wolfSSL_RSA_public_encrypt),
  86220. TEST_DECL(test_wolfSSL_RSA_private_decrypt),
  86221. TEST_DECL(test_wolfSSL_RSA_GenAdd),
  86222. TEST_DECL(test_wolfSSL_RSA_blinding_on),
  86223. TEST_DECL(test_wolfSSL_RSA_ex_data),
  86224. TEST_DECL(test_wolfSSL_RSA_LoadDer),
  86225. TEST_DECL(test_wolfSSL_RSA_To_Der),
  86226. TEST_DECL(test_wolfSSL_PEM_read_RSAPublicKey),
  86227. TEST_DECL(test_wolfSSL_PEM_write_RSA_PUBKEY),
  86228. TEST_DECL(test_wolfSSL_PEM_write_RSAPrivateKey),
  86229. TEST_DECL(test_wolfSSL_PEM_write_mem_RSAPrivateKey),
  86230. TEST_DECL(test_wolfSSL_DH),
  86231. TEST_DECL(test_wolfSSL_DH_dup),
  86232. TEST_DECL(test_wolfSSL_DH_check),
  86233. TEST_DECL(test_wolfSSL_DH_prime),
  86234. TEST_DECL(test_wolfSSL_DH_1536_prime),
  86235. TEST_DECL(test_wolfSSL_DH_get_2048_256),
  86236. TEST_DECL(test_wolfSSL_PEM_write_DHparams),
  86237. TEST_DECL(test_wolfSSL_PEM_read_DHparams),
  86238. TEST_DECL(test_wolfSSL_d2i_DHparams),
  86239. TEST_DECL(test_wolfSSL_DH_LoadDer),
  86240. TEST_DECL(test_wolfSSL_i2d_DHparams),
  86241. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  86242. TEST_DECL(test_wolfSSL_EC_GROUP),
  86243. TEST_DECL(test_wolfSSL_PEM_read_bio_ECPKParameters),
  86244. TEST_DECL(test_wolfSSL_EC_POINT),
  86245. TEST_DECL(test_wolfSSL_SPAKE),
  86246. TEST_DECL(test_wolfSSL_EC_KEY_generate),
  86247. TEST_DECL(test_EC_i2d),
  86248. TEST_DECL(test_wolfSSL_EC_curve),
  86249. TEST_DECL(test_wolfSSL_EC_KEY_dup),
  86250. TEST_DECL(test_wolfSSL_EC_KEY_set_group),
  86251. TEST_DECL(test_wolfSSL_EC_KEY_set_conv_form),
  86252. TEST_DECL(test_wolfSSL_EC_KEY_private_key),
  86253. TEST_DECL(test_wolfSSL_EC_KEY_public_key),
  86254. TEST_DECL(test_wolfSSL_EC_KEY_print_fp),
  86255. TEST_DECL(test_wolfSSL_EC_get_builtin_curves),
  86256. TEST_DECL(test_wolfSSL_ECDSA_SIG),
  86257. TEST_DECL(test_ECDSA_size_sign),
  86258. TEST_DECL(test_ECDH_compute_key),
  86259. #endif
  86260. #ifdef OPENSSL_EXTRA
  86261. TEST_DECL(test_EC25519),
  86262. TEST_DECL(test_ED25519),
  86263. TEST_DECL(test_EC448),
  86264. TEST_DECL(test_ED448),
  86265. #endif
  86266. TEST_DECL(test_DSA_do_sign_verify),
  86267. #ifdef OPENSSL_ALL
  86268. TEST_DECL(test_wolfSSL_DSA_generate_parameters),
  86269. TEST_DECL(test_wolfSSL_DSA_SIG),
  86270. #endif
  86271. TEST_DECL(test_openssl_generate_key_and_cert),
  86272. TEST_DECL(test_wolfSSL_FIPS_mode),
  86273. TEST_DECL(test_openssl_FIPS_drbg),
  86274. /*********************************
  86275. * CertManager API tests
  86276. *********************************/
  86277. TEST_DECL(test_wolfSSL_CertManagerAPI),
  86278. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer),
  86279. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer_ex),
  86280. TEST_DECL(test_wolfSSL_CertManagerGetCerts),
  86281. TEST_DECL(test_wolfSSL_CertManagerSetVerify),
  86282. TEST_DECL(test_wolfSSL_CertManagerNameConstraint),
  86283. TEST_DECL(test_wolfSSL_CertManagerNameConstraint2),
  86284. TEST_DECL(test_wolfSSL_CertManagerNameConstraint3),
  86285. TEST_DECL(test_wolfSSL_CertManagerNameConstraint4),
  86286. TEST_DECL(test_wolfSSL_CertManagerNameConstraint5),
  86287. TEST_DECL(test_wolfSSL_CertManagerCRL),
  86288. TEST_DECL(test_wolfSSL_CertManagerCheckOCSPResponse),
  86289. TEST_DECL(test_wolfSSL_CheckOCSPResponse),
  86290. #ifdef HAVE_CERT_CHAIN_VALIDATION
  86291. TEST_DECL(test_various_pathlen_chains),
  86292. #endif
  86293. /*********************************
  86294. * SSL/TLS API tests
  86295. *********************************/
  86296. TEST_DECL(test_wolfSSL_Method_Allocators),
  86297. #ifndef NO_WOLFSSL_SERVER
  86298. TEST_DECL(test_wolfSSL_CTX_new),
  86299. #endif
  86300. TEST_DECL(test_server_wolfSSL_new),
  86301. TEST_DECL(test_client_wolfSSL_new),
  86302. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  86303. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  86304. TEST_DECL(test_for_double_Free),
  86305. #endif
  86306. TEST_DECL(test_wolfSSL_set_options),
  86307. #ifdef WOLFSSL_TLS13
  86308. /* TLS v1.3 API tests */
  86309. TEST_DECL(test_tls13_apis),
  86310. TEST_DECL(test_tls13_cipher_suites),
  86311. #endif
  86312. TEST_DECL(test_wolfSSL_tmp_dh),
  86313. TEST_DECL(test_wolfSSL_ctrl),
  86314. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  86315. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  86316. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  86317. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  86318. TEST_DECL(test_wolfSSL_set_SSL_CTX),
  86319. #endif
  86320. TEST_DECL(test_wolfSSL_CTX_get_min_proto_version),
  86321. TEST_DECL(test_wolfSSL_security_level),
  86322. TEST_DECL(test_wolfSSL_SSL_in_init),
  86323. TEST_DECL(test_wolfSSL_CTX_set_timeout),
  86324. TEST_DECL(test_wolfSSL_set_psk_use_session_callback),
  86325. TEST_DECL(test_CONF_CTX_FILE),
  86326. TEST_DECL(test_CONF_CTX_CMDLINE),
  86327. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  86328. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  86329. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  86330. /* Bad certificate signature tests */
  86331. TEST_DECL(test_EccSigFailure_cm),
  86332. TEST_DECL(test_RsaSigFailure_cm),
  86333. #endif /* NO_CERTS */
  86334. /* PKCS8 testing */
  86335. TEST_DECL(test_wolfSSL_no_password_cb),
  86336. TEST_DECL(test_wolfSSL_PKCS8),
  86337. TEST_DECL(test_wolfSSL_PKCS8_ED25519),
  86338. TEST_DECL(test_wolfSSL_PKCS8_ED448),
  86339. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  86340. TEST_DECL(test_wolfSSL_get_finished),
  86341. /* Uses Assert in handshake callback. */
  86342. TEST_DECL(test_wolfSSL_CTX_add_session),
  86343. /* Large number of memory allocations. */
  86344. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls13),
  86345. /* Large number of memory allocations. */
  86346. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls13),
  86347. /* Large number of memory allocations. */
  86348. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls12),
  86349. /* Large number of memory allocations. */
  86350. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls12),
  86351. /* Large number of memory allocations. */
  86352. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls11),
  86353. /* Large number of memory allocations. */
  86354. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls1),
  86355. #endif
  86356. TEST_DECL(test_SSL_CIPHER_get_xxx),
  86357. TEST_DECL(test_wolfSSL_ERR_strings),
  86358. TEST_DECL(test_wolfSSL_CTX_set_cipher_list_bytes),
  86359. TEST_DECL(test_wolfSSL_CTX_use_certificate),
  86360. TEST_DECL(test_wolfSSL_CTX_use_certificate_file),
  86361. TEST_DECL(test_wolfSSL_CTX_use_certificate_buffer),
  86362. TEST_DECL(test_wolfSSL_use_certificate_buffer),
  86363. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey_file),
  86364. TEST_DECL(test_wolfSSL_CTX_use_RSAPrivateKey_file),
  86365. TEST_DECL(test_wolfSSL_use_RSAPrivateKey_file),
  86366. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey),
  86367. TEST_DECL(test_wolfSSL_CTX_load_verify_locations),
  86368. /* Large number of memory allocations. */
  86369. TEST_DECL(test_wolfSSL_CTX_load_system_CA_certs),
  86370. #ifdef HAVE_CERT_CHAIN_VALIDATION
  86371. TEST_DECL(test_wolfSSL_CertRsaPss),
  86372. #endif
  86373. TEST_DECL(test_wolfSSL_CTX_load_verify_locations_ex),
  86374. TEST_DECL(test_wolfSSL_CTX_load_verify_buffer_ex),
  86375. TEST_DECL(test_wolfSSL_CTX_load_verify_chain_buffer_format),
  86376. TEST_DECL(test_wolfSSL_CTX_add1_chain_cert),
  86377. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_buffer_format),
  86378. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_file_format),
  86379. TEST_DECL(test_wolfSSL_use_certificate_chain_file),
  86380. TEST_DECL(test_wolfSSL_CTX_trust_peer_cert),
  86381. TEST_DECL(test_wolfSSL_CTX_LoadCRL),
  86382. TEST_DECL(test_multiple_crls_same_issuer),
  86383. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_file),
  86384. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_buffer),
  86385. TEST_DECL(test_wolfSSL_CTX_SetMinMaxDhKey_Sz),
  86386. TEST_DECL(test_wolfSSL_CTX_der_load_verify_locations),
  86387. TEST_DECL(test_wolfSSL_CTX_enable_disable),
  86388. TEST_DECL(test_wolfSSL_CTX_ticket_API),
  86389. TEST_DECL(test_wolfSSL_SetTmpDH_file),
  86390. TEST_DECL(test_wolfSSL_SetTmpDH_buffer),
  86391. TEST_DECL(test_wolfSSL_SetMinMaxDhKey_Sz),
  86392. TEST_DECL(test_SetTmpEC_DHE_Sz),
  86393. TEST_DECL(test_wolfSSL_CTX_get0_privatekey),
  86394. #ifdef WOLFSSL_DTLS
  86395. TEST_DECL(test_wolfSSL_DtlsUpdateWindow),
  86396. TEST_DECL(test_wolfSSL_DTLS_fragment_buckets),
  86397. #endif
  86398. TEST_DECL(test_wolfSSL_dtls_set_mtu),
  86399. /* Uses Assert in handshake callback. */
  86400. TEST_DECL(test_wolfSSL_dtls_plaintext),
  86401. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  86402. defined(HAVE_IO_TESTS_DEPENDENCIES)
  86403. TEST_DECL(test_wolfSSL_read_write),
  86404. /* Can't memory test as server hangs if client fails before second connect.
  86405. */
  86406. TEST_DECL(test_wolfSSL_reuse_WOLFSSLobj),
  86407. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_1),
  86408. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_2),
  86409. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_3),
  86410. TEST_DECL(test_wolfSSL_CTX_set_cipher_list),
  86411. /* Can't memory test as server hangs. */
  86412. TEST_DECL(test_wolfSSL_dtls_export),
  86413. /* Uses Assert in handshake callback. */
  86414. TEST_DECL(test_wolfSSL_tls_export),
  86415. #endif
  86416. TEST_DECL(test_wolfSSL_dtls_export_peers),
  86417. TEST_DECL(test_wolfSSL_SetMinVersion),
  86418. TEST_DECL(test_wolfSSL_CTX_SetMinVersion),
  86419. /* wolfSSL handshake APIs. */
  86420. TEST_DECL(test_wolfSSL_CTX_get0_set1_param),
  86421. TEST_DECL(test_wolfSSL_a2i_IPADDRESS),
  86422. TEST_DECL(test_wolfSSL_BUF),
  86423. TEST_DECL(test_wolfSSL_set_tlsext_status_type),
  86424. /* Can't memory test as server hangs. */
  86425. TEST_DECL(test_wolfSSL_CTX_set_client_CA_list),
  86426. TEST_DECL(test_wolfSSL_CTX_add_client_CA),
  86427. TEST_DECL(test_wolfSSL_CTX_set_srp_username),
  86428. TEST_DECL(test_wolfSSL_CTX_set_srp_password),
  86429. TEST_DECL(test_wolfSSL_CTX_set_keylog_callback),
  86430. TEST_DECL(test_wolfSSL_CTX_get_keylog_callback),
  86431. TEST_DECL(test_wolfSSL_Tls12_Key_Logging_test),
  86432. /* Can't memory test as server hangs. */
  86433. TEST_DECL(test_wolfSSL_Tls13_Key_Logging_test),
  86434. TEST_DECL(test_wolfSSL_Tls13_postauth),
  86435. TEST_DECL(test_wolfSSL_set_ecdh_auto),
  86436. TEST_DECL(test_wolfSSL_CTX_set_ecdh_auto),
  86437. TEST_DECL(test_wolfSSL_set_minmax_proto_version),
  86438. TEST_DECL(test_wolfSSL_CTX_set_max_proto_version),
  86439. TEST_DECL(test_wolfSSL_THREADID_hash),
  86440. /* TLS extensions tests */
  86441. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  86442. #ifdef HAVE_SNI
  86443. TEST_DECL(test_wolfSSL_UseSNI_params),
  86444. /* Uses Assert in handshake callback. */
  86445. TEST_DECL(test_wolfSSL_UseSNI_connection),
  86446. TEST_DECL(test_wolfSSL_SNI_GetFromBuffer),
  86447. #endif /* HAVE_SNI */
  86448. #endif
  86449. TEST_DECL(test_wolfSSL_UseTrustedCA),
  86450. TEST_DECL(test_wolfSSL_UseMaxFragment),
  86451. TEST_DECL(test_wolfSSL_UseTruncatedHMAC),
  86452. TEST_DECL(test_wolfSSL_UseSupportedCurve),
  86453. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  86454. /* Uses Assert in handshake callback. */
  86455. TEST_DECL(test_wolfSSL_UseALPN_connection),
  86456. TEST_DECL(test_wolfSSL_UseALPN_params),
  86457. #endif
  86458. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  86459. /* Uses Assert in handshake callback. */
  86460. TEST_DECL(test_wolfSSL_set_alpn_protos),
  86461. #endif
  86462. TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
  86463. TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
  86464. TEST_DECL(test_wolfSSL_SCR_Reconnect),
  86465. TEST_DECL(test_tls_ext_duplicate),
  86466. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  86467. defined(HAVE_IO_TESTS_DEPENDENCIES)
  86468. TEST_DECL(test_wolfSSL_Tls13_ECH_params),
  86469. /* Uses Assert in handshake callback. */
  86470. TEST_DECL(test_wolfSSL_Tls13_ECH),
  86471. #endif
  86472. TEST_DECL(test_wolfSSL_X509_TLS_version_test_1),
  86473. TEST_DECL(test_wolfSSL_X509_TLS_version_test_2),
  86474. /* OCSP Stapling */
  86475. TEST_DECL(test_wolfSSL_UseOCSPStapling),
  86476. TEST_DECL(test_wolfSSL_UseOCSPStaplingV2),
  86477. TEST_DECL(test_self_signed_stapling),
  86478. TEST_DECL(test_ocsp_callback_fails),
  86479. /* Multicast */
  86480. TEST_DECL(test_wolfSSL_mcast),
  86481. TEST_DECL(test_wolfSSL_read_detect_TCP_disconnect),
  86482. TEST_DECL(test_wolfSSL_msgCb),
  86483. TEST_DECL(test_wolfSSL_either_side),
  86484. TEST_DECL(test_wolfSSL_DTLS_either_side),
  86485. /* Uses Assert in handshake callback. */
  86486. TEST_DECL(test_wolfSSL_dtls_fragments),
  86487. /* Uses Assert in handshake callback. */
  86488. TEST_DECL(test_wolfSSL_dtls_AEAD_limit),
  86489. /* Uses Assert in handshake callback. */
  86490. TEST_DECL(test_wolfSSL_ignore_alert_before_cookie),
  86491. /* Uses Assert in handshake callback. */
  86492. TEST_DECL(test_wolfSSL_dtls_bad_record),
  86493. /* Uses Assert in handshake callback. */
  86494. TEST_DECL(test_wolfSSL_dtls_stateless),
  86495. TEST_DECL(test_generate_cookie),
  86496. #ifndef NO_BIO
  86497. /* Can't memory test as server hangs. */
  86498. TEST_DECL(test_wolfSSL_BIO_connect),
  86499. /* Can't memory test as server Asserts in thread. */
  86500. TEST_DECL(test_wolfSSL_BIO_accept),
  86501. TEST_DECL(test_wolfSSL_BIO_tls),
  86502. TEST_DECL(test_wolfSSL_BIO_datagram),
  86503. #endif
  86504. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  86505. TEST_DECL(test_DhCallbacks),
  86506. #endif
  86507. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  86508. TEST_DECL(test_export_keying_material),
  86509. #endif
  86510. /* Can't memory test as client/server Asserts in thread. */
  86511. TEST_DECL(test_ticket_and_psk_mixing),
  86512. /* Can't memory test as client/server Asserts in thread. */
  86513. TEST_DECL(test_prioritize_psk),
  86514. /* Can't memory test as client/server hangs. */
  86515. TEST_DECL(test_wc_CryptoCb),
  86516. /* Can't memory test as client/server hangs. */
  86517. TEST_DECL(test_wolfSSL_CTX_StaticMemory),
  86518. #if !defined(NO_FILESYSTEM) && \
  86519. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  86520. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  86521. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  86522. TEST_DECL(test_wolfSSL_dtls_stateless_resume),
  86523. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  86524. #ifdef HAVE_MAX_FRAGMENT
  86525. TEST_DECL(test_wolfSSL_dtls_stateless_maxfrag),
  86526. #endif /* HAVE_MAX_FRAGMENT */
  86527. #ifndef NO_RSA
  86528. TEST_DECL(test_wolfSSL_dtls_stateless2),
  86529. #if !defined(NO_OLD_TLS)
  86530. TEST_DECL(test_wolfSSL_dtls_stateless_downgrade),
  86531. #endif /* !defined(NO_OLD_TLS) */
  86532. #endif /* ! NO_RSA */
  86533. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  86534. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) */
  86535. TEST_DECL(test_wolfSSL_CTX_set_ciphersuites),
  86536. TEST_DECL(test_wolfSSL_CRL_CERT_REVOKED_alert),
  86537. TEST_DECL(test_TLS_13_ticket_different_ciphers),
  86538. TEST_DECL(test_WOLFSSL_dtls_version_alert),
  86539. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  86540. && defined(WOLFSSL_TLS13) && \
  86541. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  86542. TEST_DECL(test_ticket_nonce_malloc),
  86543. #endif
  86544. TEST_DECL(test_ticket_ret_create),
  86545. TEST_DECL(test_wrong_cs_downgrade),
  86546. TEST_DECL(test_extra_alerts_wrong_cs),
  86547. TEST_DECL(test_extra_alerts_skip_hs),
  86548. TEST_DECL(test_extra_alerts_bad_psk),
  86549. TEST_DECL(test_multiple_alerts_EAGAIN),
  86550. TEST_DECL(test_tls13_bad_psk_binder),
  86551. /* Can't memory test as client/server Asserts. */
  86552. TEST_DECL(test_harden_no_secure_renegotiation),
  86553. TEST_DECL(test_override_alt_cert_chain),
  86554. TEST_DECL(test_rpk_set_xxx_cert_type),
  86555. TEST_DECL(test_tls13_rpk_handshake),
  86556. TEST_DECL(test_dtls13_bad_epoch_ch),
  86557. TEST_DECL(test_short_session_id),
  86558. TEST_DECL(test_wolfSSL_dtls13_null_cipher),
  86559. /* Can't memory test as client/server hangs. */
  86560. TEST_DECL(test_dtls_msg_from_other_peer),
  86561. TEST_DECL(test_dtls_ipv6_check),
  86562. TEST_DECL(test_wolfSSL_SCR_after_resumption),
  86563. TEST_DECL(test_dtls_no_extensions),
  86564. TEST_DECL(test_tls_alert_no_server_hello),
  86565. TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
  86566. TEST_DECL(test_dtls_1_0_hvr_downgrade),
  86567. TEST_DECL(test_session_ticket_no_id),
  86568. TEST_DECL(test_session_ticket_hs_update),
  86569. TEST_DECL(test_dtls_downgrade_scr_server),
  86570. TEST_DECL(test_dtls_downgrade_scr),
  86571. TEST_DECL(test_dtls_client_hello_timeout_downgrade),
  86572. TEST_DECL(test_dtls_client_hello_timeout),
  86573. TEST_DECL(test_dtls_dropped_ccs),
  86574. TEST_DECL(test_dtls_seq_num_downgrade),
  86575. TEST_DECL(test_certreq_sighash_algos),
  86576. TEST_DECL(test_revoked_loaded_int_cert),
  86577. TEST_DECL(test_dtls_frag_ch),
  86578. TEST_DECL(test_dtls13_frag_ch_pq),
  86579. TEST_DECL(test_dtls_empty_keyshare_with_cookie),
  86580. TEST_DECL(test_dtls_old_seq_number),
  86581. TEST_DECL(test_tls13_pq_groups),
  86582. TEST_DECL(test_tls13_early_data),
  86583. TEST_DECL(test_tls_multi_handshakes_one_record),
  86584. TEST_DECL(test_write_dup),
  86585. TEST_DECL(test_read_write_hs),
  86586. TEST_DECL(test_get_signature_nid),
  86587. TEST_DECL(test_tls_cert_store_unchanged),
  86588. TEST_DECL(test_wolfSSL_SendUserCanceled),
  86589. /* This test needs to stay at the end to clean up any caches allocated. */
  86590. TEST_DECL(test_wolfSSL_Cleanup)
  86591. };
  86592. #define TEST_CASE_CNT (int)(sizeof(testCases) / sizeof(*testCases))
  86593. static void TestSetup(void)
  86594. {
  86595. /* Stub, for now. Add common test setup code here. */
  86596. }
  86597. static void TestCleanup(void)
  86598. {
  86599. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  86600. /* Clear any errors added to the error queue during the test run. */
  86601. wolfSSL_ERR_clear_error();
  86602. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  86603. }
  86604. /* Print out all API test cases with numeric identifier.
  86605. */
  86606. void ApiTest_PrintTestCases(void)
  86607. {
  86608. int i;
  86609. printf("All Test Cases:\n");
  86610. for (i = 0; i < TEST_CASE_CNT; i++) {
  86611. printf("%3d: %s\n", i + 1, testCases[i].name);
  86612. }
  86613. }
  86614. /* Add test case with index to the list to run.
  86615. *
  86616. * @param [in] idx Index of test case to run starting at 1.
  86617. * @return 0 on success.
  86618. * @return BAD_FUNC_ARG when index is out of range of test case identifiers.
  86619. */
  86620. int ApiTest_RunIdx(int idx)
  86621. {
  86622. if (idx < 1 || idx > TEST_CASE_CNT) {
  86623. printf("Index out of range (1 - %d): %d\n", TEST_CASE_CNT, idx);
  86624. return BAD_FUNC_ARG;
  86625. }
  86626. testAll = 0;
  86627. testCases[idx-1].run = 1;
  86628. return 0;
  86629. }
  86630. /* Add test case with name to the list to run.
  86631. *
  86632. * @param [in] name Name of test case to run.
  86633. * @return 0 on success.
  86634. * @return BAD_FUNC_ARG when name is not a known test case name.
  86635. */
  86636. int ApiTest_RunName(char* name)
  86637. {
  86638. int i;
  86639. for (i = 0; i < TEST_CASE_CNT; i++) {
  86640. if (XSTRCMP(testCases[i].name, name) == 0) {
  86641. testAll = 0;
  86642. testCases[i].run = 1;
  86643. return 0;
  86644. }
  86645. }
  86646. printf("Test case name not found: %s\n", name);
  86647. printf("Use --list to see all test case names.\n");
  86648. return BAD_FUNC_ARG;
  86649. }
  86650. /* Converts the result code to a string.
  86651. *
  86652. * @param [in] res Test result code.
  86653. * @return String describing test result.
  86654. */
  86655. static const char* apitest_res_string(int res)
  86656. {
  86657. const char* str = "invalid result";
  86658. switch (res) {
  86659. case TEST_SUCCESS:
  86660. str = "passed";
  86661. break;
  86662. case TEST_FAIL:
  86663. str = "failed";
  86664. break;
  86665. case TEST_SKIPPED:
  86666. str = "skipped";
  86667. break;
  86668. }
  86669. return str;
  86670. }
  86671. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86672. static double gettime_secs(void)
  86673. #if defined(_MSC_VER) && defined(_WIN32)
  86674. {
  86675. /* there's no gettimeofday for Windows, so we'll use system time */
  86676. #define EPOCH_DIFF 11644473600LL
  86677. FILETIME currentFileTime;
  86678. GetSystemTimePreciseAsFileTime(&currentFileTime);
  86679. ULARGE_INTEGER uli = { 0, 0 };
  86680. uli.LowPart = currentFileTime.dwLowDateTime;
  86681. uli.HighPart = currentFileTime.dwHighDateTime;
  86682. /* Convert to seconds since Unix epoch */
  86683. return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
  86684. }
  86685. #else
  86686. {
  86687. struct timeval tv;
  86688. LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
  86689. return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  86690. }
  86691. #endif
  86692. #endif
  86693. int ApiTest(void)
  86694. {
  86695. int i;
  86696. int ret;
  86697. int res = 0;
  86698. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86699. double timeDiff;
  86700. #endif
  86701. printf(" Begin API Tests\n");
  86702. fflush(stdout);
  86703. /* we must perform init and cleanup if not all tests are running */
  86704. if (!testAll) {
  86705. #ifdef WOLFCRYPT_ONLY
  86706. if (wolfCrypt_Init() != 0) {
  86707. printf("wolfCrypt Initialization failed\n");
  86708. res = 1;
  86709. }
  86710. #else
  86711. if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
  86712. printf("wolfSSL Initialization failed\n");
  86713. res = 1;
  86714. }
  86715. #endif
  86716. }
  86717. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  86718. if (res == 0) {
  86719. if (create_tmp_dir(tmpDirName, sizeof(tmpDirName) - 1) == NULL) {
  86720. printf("failed to create tmp dir\n");
  86721. res = 1;
  86722. }
  86723. else {
  86724. tmpDirNameSet = 1;
  86725. }
  86726. }
  86727. #endif
  86728. if (res == 0) {
  86729. for (i = 0; i < TEST_CASE_CNT; ++i) {
  86730. EXPECT_DECLS;
  86731. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  86732. currentTestName = testCases[i].name;
  86733. #endif
  86734. /* When not testing all cases then skip if not marked for running.
  86735. */
  86736. if (!testAll && !testCases[i].run) {
  86737. continue;
  86738. }
  86739. TestSetup();
  86740. printf(" %3d: %-52s:", i + 1, testCases[i].name);
  86741. fflush(stdout);
  86742. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86743. timeDiff = gettime_secs();
  86744. #endif
  86745. ret = testCases[i].func();
  86746. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86747. timeDiff = gettime_secs() - timeDiff;
  86748. #endif
  86749. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86750. if (ret != TEST_SKIPPED) {
  86751. printf(" %s (%9.5lf)\n", apitest_res_string(ret), timeDiff);
  86752. }
  86753. else
  86754. #endif
  86755. {
  86756. printf(" %s\n", apitest_res_string(ret));
  86757. }
  86758. fflush(stdout);
  86759. /* if return code is < 0 and not skipped then assert error */
  86760. Expect((ret > 0 || ret == TEST_SKIPPED),
  86761. ("Test failed\n"),
  86762. ("ret %d", ret));
  86763. testCases[i].fail = ((ret <= 0) && (ret != TEST_SKIPPED));
  86764. res |= ((ret <= 0) && (ret != TEST_SKIPPED));
  86765. TestCleanup();
  86766. }
  86767. }
  86768. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  86769. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  86770. wc_ecc_fp_free(); /* free per thread cache */
  86771. #endif
  86772. if (!testAll) {
  86773. #ifdef WOLFCRYPT_ONLY
  86774. wolfCrypt_Cleanup();
  86775. #else
  86776. wolfSSL_Cleanup();
  86777. #endif
  86778. }
  86779. (void)testDevId;
  86780. if (res != 0) {
  86781. printf("\nFAILURES:\n");
  86782. for (i = 0; i < TEST_CASE_CNT; ++i) {
  86783. if (testCases[i].fail) {
  86784. printf(" %3d: %s\n", i + 1, testCases[i].name);
  86785. }
  86786. }
  86787. printf("\n");
  86788. fflush(stdout);
  86789. }
  86790. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  86791. if (tmpDirNameSet) {
  86792. printf("\nBinary dumps of the memio streams can be found in the\n"
  86793. "%s directory. This can be imported into\n"
  86794. "Wireshark by transforming the file with\n"
  86795. "\tod -Ax -tx1 -v stream.dump > stream.dump.hex\n"
  86796. "And then loading test_output.dump.hex into Wireshark using\n"
  86797. "the \"Import from Hex Dump...\" option and selecting the\n"
  86798. "TCP encapsulation option.\n", tmpDirName);
  86799. }
  86800. #endif
  86801. printf(" End API Tests\n");
  86802. fflush(stdout);
  86803. return res;
  86804. }